#region License Information
/* HeuristicLab
* Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
*
* This file is part of HeuristicLab.
*
* HeuristicLab is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* HeuristicLab is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with HeuristicLab. If not, see .
*/
#endregion
using System;
using System.Linq;
using System.Reflection;
using System.Windows.Forms;
namespace HeuristicLab.PluginInfrastructure.UI {
public partial class SplashScreen : Form {
private const int FADE_INTERVAL = 50;
private Timer fadeTimer;
private int initialInterval;
private SplashScreen() {
InitializeComponent();
}
public SplashScreen(string initialText, int initialInterval)
: this() {
this.initialInterval = initialInterval;
var entryAssembly = Assembly.GetEntryAssembly();
// RegisterPluginManagerEventHandlers();
versionLabel.Text = "Version " + entryAssembly.GetFileVersion() + " "
+ entryAssembly.GetCustomAttributes().OfType().First().InformationalVersion; // code name
infoLabel.Text = "";
var attr = entryAssembly.GetCustomAttributes().OfType().Single();
copyrightLabel.Text = "Copyright " + attr.Copyright;
fadeTimer = new Timer();
fadeTimer.Tick += fadeTimer_Elapsed;
fadeTimer.Interval = initialInterval;
fadeTimer.Start();
Opacity = 1;
infoLabel.Text = initialText;
}
public void UpdateMessage(string msg) {
try {
if (InvokeRequired) Invoke((Action)UpdateMessage, msg);
else {
ResetFadeTimer();
infoLabel.Text = msg;
}
} catch (ObjectDisposedException) { }
}
// each tick of the timer reduce opacity and restart timer
private void fadeTimer_Elapsed(object sender, EventArgs e) {
// only called from local timer: no need to invoke here
FadeOut();
}
private void ResetFadeTimer() {
// wait initialInterval again for the first tick
fadeTimer.Stop();
fadeTimer.Interval = initialInterval;
fadeTimer.Start();
}
// reduces opacity of the splashscreen one step and restarts the fade-timer
private void FadeOut() {
fadeTimer.Stop();
fadeTimer.Interval = FADE_INTERVAL;
if (this.Opacity > 0) {
Opacity -= 0.1;
fadeTimer.Start();
} else {
Opacity = 0;
fadeTimer.Stop();
Close();
}
}
}
}