81 lines
2.5 KiB
C#
81 lines
2.5 KiB
C#
using System;
|
|
using System.Drawing;
|
|
using System.Windows.Forms;
|
|
|
|
namespace Mitria_Minecraft_Launcher
|
|
{
|
|
public partial class LoadingScreen : UserControl
|
|
{
|
|
private readonly Bitmap _bitmap;
|
|
private Size imageSize;
|
|
private int LocationX;
|
|
private int LocationY;
|
|
|
|
public LoadingScreen(Bitmap bitmap)
|
|
{
|
|
this.SetStyle(ControlStyles.DoubleBuffer, true);
|
|
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
|
|
this.SetStyle(ControlStyles.UserPaint, true);
|
|
|
|
|
|
_bitmap = bitmap;
|
|
|
|
imageSize = ResizeCalculator(this.Size.Width, this.Size.Height, _bitmap.Width, _bitmap.Height);
|
|
LocationChange();
|
|
this.TabStop = false;
|
|
InitializeComponent();
|
|
}
|
|
|
|
protected override void OnLoad(EventArgs e)
|
|
{
|
|
ImageAnimator.Animate(_bitmap, new EventHandler(this.OnFrameChanged));
|
|
base.OnLoad(e);
|
|
}
|
|
|
|
protected override void OnPaint(PaintEventArgs e)
|
|
{
|
|
ImageAnimator.UpdateFrames();
|
|
|
|
e.Graphics.DrawImage(this._bitmap, LocationX, LocationY, imageSize.Width, imageSize.Height);
|
|
|
|
base.OnPaint(e);
|
|
|
|
}
|
|
|
|
private void OnFrameChanged(object sender, EventArgs e)
|
|
{
|
|
this.Invalidate();
|
|
}
|
|
|
|
private Size ResizeCalculator(int paletteWidth, int paletteHeight, int imageWidth, int imageHeigh)
|
|
{
|
|
double ratioX = paletteWidth / (double)imageWidth;
|
|
double ratioY = paletteHeight / (double)imageHeigh;
|
|
|
|
double ratio = Math.Min(ratioX, ratioY);
|
|
|
|
int newWidth = (int)(imageWidth * ratio);
|
|
int newHeight = (int)(imageHeigh * ratio);
|
|
Size newSize = new Size(newWidth, newHeight);
|
|
return newSize;
|
|
}
|
|
|
|
private void LocationChange()
|
|
{
|
|
// 로케이션 계산
|
|
int needx = imageSize.Width / 2;
|
|
int needy = imageSize.Height / 2;
|
|
int locationXCenter = this.Size.Width / 2;
|
|
int locationYCenter = this.Size.Height / 2;
|
|
|
|
LocationX = locationXCenter - needx;
|
|
LocationY = locationYCenter - needy;
|
|
}
|
|
|
|
private void LoadingScreen_SizeChanged(object sender, EventArgs e)
|
|
{
|
|
imageSize = ResizeCalculator(this.Size.Width, this.Size.Height, _bitmap.Width, _bitmap.Height);
|
|
LocationChange();
|
|
}
|
|
}
|
|
} |