FireWalletCosmos/FireWalletLite/SplashScreen.cs

104 lines
2.5 KiB
C#
Raw Normal View History

2023-07-05 16:44:34 +10:00
using System.Diagnostics;
using System.Drawing.Imaging;
2023-07-15 22:17:49 +10:00
namespace FireWallet;
2023-07-05 16:44:34 +10:00
2023-07-15 22:17:49 +10:00
public partial class SplashScreen : Form
2023-07-05 16:44:34 +10:00
{
2023-07-15 22:17:49 +10:00
private bool close;
private float opacity;
private Bitmap splash;
public SplashScreen(bool timer)
{
InitializeComponent();
close = false;
IsClosed = false;
}
public bool IsClosed { get; set; }
private void SplashScreen_FormClosing(object sender, FormClosingEventArgs e)
{
if (!close) e.Cancel = true;
}
public void CloseSplash()
{
close = true;
// Fade out
timerIn.Stop();
timerOut.Start();
}
private void label2_Click(object sender, EventArgs e)
2023-07-05 16:44:34 +10:00
{
2023-07-15 22:17:49 +10:00
var psi = new ProcessStartInfo
2023-07-05 16:44:34 +10:00
{
2023-07-15 22:17:49 +10:00
FileName = "https://nathan.woodburn.au",
UseShellExecute = true
};
Process.Start(psi);
}
//new Bitmap(Properties.Resources.FWSplash);
private void SplashScreen_Load(object sender, EventArgs e)
{
splash = pictureBoxNew.Image as Bitmap;
pictureBoxNew.Visible = true;
TransparencyKey = Color.FromArgb(0, 0, 0);
pictureBoxNew.Invalidate();
}
public Image SetImageOpacity(Image image, float opacity)
{
try
2023-07-05 16:44:34 +10:00
{
2023-07-15 22:17:49 +10:00
var bmp = new Bitmap(image.Width, image.Height);
using (var gfx = Graphics.FromImage(bmp))
2023-07-05 16:44:34 +10:00
{
2023-07-15 22:17:49 +10:00
var matrix = new ColorMatrix();
matrix.Matrix33 = opacity;
var attributes = new ImageAttributes();
attributes.SetColorMatrix(matrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
gfx.DrawImage(image, new Rectangle(0, 0, bmp.Width, bmp.Height), 0, 0, image.Width, image.Height,
GraphicsUnit.Pixel, attributes);
2023-07-05 16:44:34 +10:00
}
2023-07-15 22:17:49 +10:00
return bmp;
2023-07-05 16:44:34 +10:00
}
2023-07-15 22:17:49 +10:00
catch
2023-07-05 16:44:34 +10:00
{
2023-07-15 22:17:49 +10:00
return null;
2023-07-05 16:44:34 +10:00
}
2023-07-15 22:17:49 +10:00
}
private void timerIn_Tick(object sender, EventArgs e)
{
if (opacity >= 1)
2023-07-05 16:44:34 +10:00
{
2023-07-15 22:17:49 +10:00
timerIn.Stop();
return;
2023-07-05 16:44:34 +10:00
}
2023-07-15 22:17:49 +10:00
opacity += 0.05f;
pictureBoxNew.Image = SetImageOpacity(splash, opacity);
pictureBoxNew.Invalidate();
}
private void timerOut_Tick(object sender, EventArgs e)
{
if (opacity <= 0)
2023-07-05 16:44:34 +10:00
{
2023-07-15 22:17:49 +10:00
timerOut.Stop();
IsClosed = true;
Close();
return;
2023-07-05 16:44:34 +10:00
}
2023-07-15 22:17:49 +10:00
opacity -= 0.05f;
pictureBoxNew.Image = SetImageOpacity(splash, opacity);
pictureBoxNew.Invalidate();
2023-07-05 16:44:34 +10:00
}
2023-07-15 22:17:49 +10:00
}