mirror of
https://github.com/terrymacdonald/DisplayMagician.git
synced 2024-08-30 18:32:20 +00:00
Renamed app to HeliosPlus namespace so that the updated changes don't interfere with HeliosDisplayManagement if that is also installed. The fact that I've changed so much of the app means that my changes would be unlikely to be accepted by Soroush, so I'm best to release this work in a similar way to other projects like Notepad++, by keeping the same root name, and adding a plus. I've also changed the Shortcut form to put all the games in a single list to reduce the number of clicks a user has to do in order for them to create a shortcut. I have begun to prepare the form so that it will support multiple game libraries, but now I am at a point that I need to fix the Steam and Uplay game detection mechanisms so that they report the correct information for the lv_games list view.
234 lines
7.2 KiB
C#
234 lines
7.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Windows.Forms;
|
|
using HeliosPlus.Resources;
|
|
using WinFormAnimation;
|
|
|
|
namespace HeliosPlus.UIForms
|
|
{
|
|
public sealed partial class SplashForm : Form
|
|
{
|
|
private readonly Action _job;
|
|
private readonly Bitmap _progressImage;
|
|
private readonly List<Point> _progressPositions = new List<Point>();
|
|
private int _countdownCounter;
|
|
private bool _isClosing;
|
|
private int _startCounter;
|
|
|
|
public SplashForm()
|
|
{
|
|
InitializeComponent();
|
|
_progressImage = new Bitmap(progressPanel.Width, progressPanel.Height);
|
|
Controls.Remove(progressPanel);
|
|
progressPanel.BackColor = BackColor;
|
|
progressBar.Invalidated += (sender, args) => Invalidate();
|
|
progressPanel.Invalidated += (sender, args) => Invalidate();
|
|
}
|
|
|
|
public SplashForm(Action job, int cancellationTimeout = 0, int countdown = 0) : this()
|
|
{
|
|
_job = job;
|
|
_startCounter = cancellationTimeout;
|
|
_countdownCounter = countdown;
|
|
}
|
|
|
|
public string CancellationMessage { get; set; } = Language.Starting_in;
|
|
public string CountdownMessage { get; set; } = Language.Please_wait;
|
|
|
|
protected override void OnKeyDown(KeyEventArgs e)
|
|
{
|
|
e.Handled = true;
|
|
}
|
|
|
|
protected override void OnPaint(PaintEventArgs e)
|
|
{
|
|
lock (_progressPositions)
|
|
{
|
|
progressPanel.DrawToBitmap(_progressImage, new Rectangle(Point.Empty, progressPanel.Size));
|
|
|
|
foreach (var position in _progressPositions)
|
|
{
|
|
e.Graphics.DrawImage(_progressImage, new Rectangle(position, progressPanel.Size));
|
|
}
|
|
}
|
|
|
|
base.OnPaint(e);
|
|
}
|
|
|
|
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
|
|
{
|
|
if (keyData != Keys.Escape)
|
|
{
|
|
return base.ProcessCmdKey(ref msg, keyData);
|
|
}
|
|
|
|
if (t_start.Enabled)
|
|
{
|
|
t_start.Stop();
|
|
t_countdown.Stop();
|
|
DialogResult = DialogResult.Cancel;
|
|
Close();
|
|
|
|
return true;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
private void DoJob()
|
|
{
|
|
lbl_message.Text = CountdownMessage;
|
|
progressBar.ProgressColor = Color.OrangeRed;
|
|
|
|
if (_countdownCounter > 0)
|
|
{
|
|
progressBar.Text = (progressBar.Value = progressBar.Maximum = _countdownCounter).ToString();
|
|
t_countdown.Start();
|
|
_job?.Invoke();
|
|
}
|
|
else
|
|
{
|
|
progressBar.Style = ProgressBarStyle.Marquee;
|
|
progressBar.Text = "";
|
|
progressBar.Maximum = 100;
|
|
progressBar.Value = 50;
|
|
progressBar.Style = ProgressBarStyle.Marquee;
|
|
_job?.Invoke();
|
|
DialogResult = DialogResult.OK;
|
|
Close();
|
|
}
|
|
}
|
|
|
|
private void DoTimeout()
|
|
{
|
|
lbl_message.Text = CancellationMessage;
|
|
progressBar.ProgressColor = Color.DodgerBlue;
|
|
|
|
if (_startCounter > 0)
|
|
{
|
|
progressBar.Text = (progressBar.Value = progressBar.Maximum = _startCounter).ToString();
|
|
t_start.Start();
|
|
}
|
|
else
|
|
{
|
|
DoJob();
|
|
}
|
|
}
|
|
|
|
private void Reposition()
|
|
{
|
|
lock (_progressPositions)
|
|
{
|
|
var screens = Screen.AllScreens;
|
|
var minX = screens.Select(screen => screen.Bounds.X).Concat(new[] {0}).Min();
|
|
var maxX = screens.Select(screen => screen.Bounds.Width + screen.Bounds.X).Concat(new[] {0}).Max();
|
|
var minY = screens.Select(screen => screen.Bounds.Y).Concat(new[] {0}).Min();
|
|
var maxY = screens.Select(screen => screen.Bounds.Height + screen.Bounds.Y).Concat(new[] {0}).Max();
|
|
|
|
#if !DEBUG
|
|
Size = new Size(maxX + Math.Abs(minX), maxY + Math.Abs(minY));
|
|
Location = new Point(minX, minY);
|
|
#else
|
|
Size = new Size((int)((maxX + Math.Abs(minX)) * 0.8d), (int)((maxY + Math.Abs(minY)) * 0.8d));
|
|
Location = new Point(minX + (int)(Size.Width / 8d), minY + (int)(Size.Height / 8d));
|
|
#endif
|
|
|
|
_progressPositions.Clear();
|
|
_progressPositions.AddRange(
|
|
screens.Select(
|
|
screen =>
|
|
new Point(screen.Bounds.X - minX + (screen.Bounds.Width - progressPanel.Width) / 2,
|
|
screen.Bounds.Y - minY + (screen.Bounds.Height - progressPanel.Height) / 2)));
|
|
}
|
|
#if !DEBUG
|
|
TopMost = true;
|
|
Activate();
|
|
#endif
|
|
Invalidate();
|
|
}
|
|
|
|
private void SplashForm_FormClosing(object sender, FormClosingEventArgs e)
|
|
{
|
|
if (_isClosing)
|
|
{
|
|
return;
|
|
}
|
|
|
|
_isClosing = true;
|
|
e.Cancel = true;
|
|
var dialogResult = DialogResult;
|
|
new Animator(new Path((float) Opacity, 0, 200))
|
|
.Play(new SafeInvoker<float>(f =>
|
|
{
|
|
try
|
|
{
|
|
Opacity = f;
|
|
}
|
|
catch
|
|
{
|
|
// ignored
|
|
}
|
|
}, this), new SafeInvoker(() =>
|
|
{
|
|
DialogResult = dialogResult;
|
|
Close();
|
|
}, this));
|
|
}
|
|
|
|
private void SplashForm_Reposition(object sender, EventArgs e)
|
|
{
|
|
Reposition();
|
|
}
|
|
|
|
private void SplashForm_Shown(object sender, EventArgs e)
|
|
{
|
|
new Animator(new Path((float) Opacity, 0.97f, 200))
|
|
.Play(new SafeInvoker<float>(f =>
|
|
{
|
|
try
|
|
{
|
|
Opacity = f;
|
|
}
|
|
catch
|
|
{
|
|
// ignored
|
|
}
|
|
}, this), new SafeInvoker(DoTimeout, this));
|
|
}
|
|
|
|
private void t_countdown_Tick(object sender, EventArgs e)
|
|
{
|
|
if (_countdownCounter < 0)
|
|
{
|
|
t_countdown.Stop();
|
|
DialogResult = DialogResult.OK;
|
|
Close();
|
|
|
|
return;
|
|
}
|
|
|
|
progressBar.Value = _countdownCounter;
|
|
progressBar.Text = progressBar.Value.ToString();
|
|
_countdownCounter--;
|
|
Reposition();
|
|
}
|
|
|
|
private void t_start_Tick(object sender, EventArgs e)
|
|
{
|
|
if (_startCounter < 0)
|
|
{
|
|
t_start.Stop();
|
|
DoJob();
|
|
|
|
return;
|
|
}
|
|
|
|
progressBar.Value = _startCounter;
|
|
progressBar.Text = progressBar.Value.ToString();
|
|
_startCounter--;
|
|
Reposition();
|
|
}
|
|
}
|
|
} |