Free cookie consent management tool by TermsFeed Policy Generator

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

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

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

File size: 3.1 KB
RevLine 
[2]1#region License Information
2/* HeuristicLab
[12012]3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[2]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;
[4068]23using System.Linq;
24using System.Reflection;
[2]25using System.Windows.Forms;
26
[13338]27namespace HeuristicLab.PluginInfrastructure.UI {
[13389]28  public partial class SplashScreen : Form {
[595]29    private const int FADE_INTERVAL = 50;
[2505]30    private Timer fadeTimer;
[596]31    private int initialInterval;
[3777]32
[13389]33    private SplashScreen() {
[2]34      InitializeComponent();
[2481]35    }
[2]36
[13389]37    public SplashScreen(string initialText, int initialInterval)
[2481]38      : this() {
39      this.initialInterval = initialInterval;
[2505]40
[13353]41      var entryAssembly = Assembly.GetEntryAssembly();
[13389]42      // RegisterPluginManagerEventHandlers();
[2]43
[13389]44      versionLabel.Text = "Version " + entryAssembly.GetFileVersion() + " "
[13353]45        + entryAssembly.GetCustomAttributes().OfType<AssemblyInformationalVersionAttribute>().First().InformationalVersion; // code name
[2]46      infoLabel.Text = "";
47
[13353]48      var attr = entryAssembly.GetCustomAttributes().OfType<AssemblyCopyrightAttribute>().Single();
[2505]49      copyrightLabel.Text = "Copyright " + attr.Copyright;
[2]50
[2505]51      fadeTimer = new Timer();
52      fadeTimer.Tick += fadeTimer_Elapsed;
53      fadeTimer.Interval = initialInterval;
[13389]54      fadeTimer.Start();
[2]55
[13389]56      Opacity = 1;
57      infoLabel.Text = initialText;
[2922]58
59    }
60
[13389]61    public void UpdateMessage(string msg) {
[4515]62      try {
[13389]63        if (InvokeRequired) Invoke((Action<string>)UpdateMessage, msg);
64        else {
65          ResetFadeTimer();
66          infoLabel.Text = msg;
67        }
[13353]68      } catch (ObjectDisposedException) { }
[4515]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
[3113]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() {
[2505]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();
[13389]94        Close();
[2439]95      }
96    }
[2]97  }
98}
Note: See TracBrowser for help on using the repository browser.