Free cookie consent management tool by TermsFeed Policy Generator

source: branches/RefactorPluginInfrastructure-2522/HeuristicLab.PluginInfrastructure.UI/SplashScreen.cs @ 15194

Last change on this file since 15194 was 13389, checked in by gkronber, 9 years ago

#2522: removed Starter form and instead init plugin discovery and launch of application from Startup project (.exe)

File size: 3.1 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.Linq;
24using System.Reflection;
25using System.Windows.Forms;
26
27namespace HeuristicLab.PluginInfrastructure.UI {
28  public partial class SplashScreen : Form {
29    private const int FADE_INTERVAL = 50;
30    private Timer fadeTimer;
31    private int initialInterval;
32
33    private SplashScreen() {
34      InitializeComponent();
35    }
36
37    public SplashScreen(string initialText, int initialInterval)
38      : this() {
39      this.initialInterval = initialInterval;
40
41      var entryAssembly = Assembly.GetEntryAssembly();
42      // RegisterPluginManagerEventHandlers();
43
44      versionLabel.Text = "Version " + entryAssembly.GetFileVersion() + " "
45        + entryAssembly.GetCustomAttributes().OfType<AssemblyInformationalVersionAttribute>().First().InformationalVersion; // code name
46      infoLabel.Text = "";
47
48      var attr = entryAssembly.GetCustomAttributes().OfType<AssemblyCopyrightAttribute>().Single();
49      copyrightLabel.Text = "Copyright " + attr.Copyright;
50
51      fadeTimer = new Timer();
52      fadeTimer.Tick += fadeTimer_Elapsed;
53      fadeTimer.Interval = initialInterval;
54      fadeTimer.Start();
55
56      Opacity = 1;
57      infoLabel.Text = initialText;
58
59    }
60
61    public void UpdateMessage(string msg) {
62      try {
63        if (InvokeRequired) Invoke((Action<string>)UpdateMessage, msg);
64        else {
65          ResetFadeTimer();
66          infoLabel.Text = msg;
67        }
68      } catch (ObjectDisposedException) { }
69    }
70
71    // each tick of the timer reduce opacity and restart timer
72    private void fadeTimer_Elapsed(object sender, EventArgs e) {
73      // only called from local timer: no need to invoke here
74      FadeOut();
75    }
76
77    private void ResetFadeTimer() {
78      // wait initialInterval again for the first tick
79      fadeTimer.Stop();
80      fadeTimer.Interval = initialInterval;
81      fadeTimer.Start();
82    }
83
84    // reduces opacity of the splashscreen one step and restarts the fade-timer
85    private void FadeOut() {
86      fadeTimer.Stop();
87      fadeTimer.Interval = FADE_INTERVAL;
88      if (this.Opacity > 0) {
89        Opacity -= 0.1;
90        fadeTimer.Start();
91      } else {
92        Opacity = 0;
93        fadeTimer.Stop();
94        Close();
95      }
96    }
97  }
98}
Note: See TracBrowser for help on using the repository browser.