/
frmSplash.cs
337 lines (290 loc) · 9.83 KB
/
frmSplash.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
// Copyright © 2011-2013 Yanick Castonguay
//
// This file is part of MPfm.
//
// MPfm 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.
//
// MPfm 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 MPfm. If not, see <http://www.gnu.org/licenses/>.
using System;
using System.Diagnostics;
using System.Drawing;
using System.Threading;
using System.Reflection;
using System.Windows.Forms;
using MPfm.MVP.Views;
namespace MPfm.Windows.Classes.Forms
{
/// <summary>
/// Splash screen window. This is where the MPfm logo is displayed with the copyright notices and
/// credits. This is used for the unskippable splash screen at the start of the application and for
/// the About screen.
/// </summary>
public partial class frmSplash : BaseForm, ISplashView
{
// Private variables
private static frmSplash windowSplash = null;
private static Thread thread = null;
private bool fadingIn = true;
private bool fadingOut = false;
private bool closeFormAfterFadeOut = false;
private Rectangle rectLink = new Rectangle(320, 260, 90, 10);
private string status = "";
private string error = "";
private bool InitDone { get; set; }
public frmSplash(Action<IBaseView> onViewReady) : base (onViewReady)
{
InitDone = false;
InitializeComponent();
lblVersion.Text = Assembly.GetExecutingAssembly().GetName().Version.ToString();
Console.WriteLine("End of frmSplash ctor");
ViewIsReady();
}
/// <summary>
/// Returns a random number (for displaying a random background image).
/// </summary>
/// <returns>Random number</returns>
private int RandomNumber()
{
Random random = new Random();
return random.Next(100);
}
#region Static Methods
/// <summary>
/// Shows the form.
/// </summary>
private static void ShowForm()
{
//windowSplash = new frmSplash(true);
//Application.Run(windowSplash);
}
/// <summary>
/// Closes the form without fade out.
/// </summary>
public static void CloseFormWithFadeOut()
{
// Invoke UI updates
MethodInvoker methodUIUpdate = delegate
{
windowSplash.closeFormAfterFadeOut = true;
windowSplash.fadingIn = false;
windowSplash.fadingOut = true;
};
// Check if invoking is necessary
if (windowSplash.InvokeRequired)
{
windowSplash.BeginInvoke(methodUIUpdate);
}
else
{
methodUIUpdate.Invoke();
}
}
/// <summary>
/// Closes the form with fade out.
/// </summary>
public static void CloseForm()
{
// Invoke UI updates
MethodInvoker methodUIUpdate = delegate
{
windowSplash.Close();
};
// Check if invoking is necessary
if (windowSplash.InvokeRequired)
{
windowSplash.BeginInvoke(methodUIUpdate);
}
else
{
methodUIUpdate.Invoke();
}
}
/// <summary>
/// Shows the splash screen.
/// </summary>
public static void ShowSplash()
{
// Make sure it is only launched once.
if (windowSplash != null)
{
return;
}
// Run splash in another thread
thread = new Thread(new ThreadStart(frmSplash.ShowForm));
thread.IsBackground = true;
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
}
/// <summary>
/// Hides the splash screen.
/// </summary>
public static void HideSplash()
{
// Make sure window already exists
if (windowSplash == null)
{
return;
}
windowSplash.fadingIn = false;
windowSplash.fadingOut = true;
}
/// <summary>
/// Sets the status message of the splash screen.
/// </summary>
/// <param name="status">Status Message</param>
public static void SetStatus(string status)
{
windowSplash.status = status;
}
/// <summary>
/// Sets an error message on the splash screen.
/// </summary>
/// <param name="error">Error Message</param>
public static void SetError(string error)
{
windowSplash.error = error;
}
#endregion
#region Background Picture Box Events
/// <summary>
/// Occurs when the user clicks on the background picture. Closes the
/// form if in "About" mode. Opens a browser to the MPfm web site if the
/// user clicks on the web site link.
/// </summary>
/// <param name="sender">Event sender</param>
/// <param name="e">Event arguments</param>
private void pictureBackground_Click(object sender, EventArgs e)
{
// Check if the user clicks the link
// 320, 260
// 410, 270
Point pt = this.PointToClient(System.Windows.Forms.Control.MousePosition);
if (pt.X >= rectLink.X &&
pt.X <= rectLink.X + rectLink.Width &&
pt.Y >= rectLink.Y &&
pt.Y <= rectLink.Y + rectLink.Height)
{
Process.Start("http://www.mp4m.org");
return;
}
// The splash screen can be hidden only if the initialization is done
if (InitDone && !fadingIn)
{
closeFormAfterFadeOut = true;
fadingOut = true;
}
}
/// <summary>
/// Occus when the mouse cursor is over the background picture. Displays a hand
/// cursor when the cursor is in front of the mp4m.org website link.
/// </summary>
/// <param name="sender">Event sender</param>
/// <param name="e">Event arguments</param>
private void pictureBackground_MouseMove(object sender, MouseEventArgs e)
{
Point pt = this.PointToClient(System.Windows.Forms.Control.MousePosition);
if (pt.X >= rectLink.X &&
pt.X <= rectLink.X + rectLink.Width &&
pt.Y >= rectLink.Y &&
pt.Y <= rectLink.Y + rectLink.Height)
{
if (Cursor.Current == Cursors.Default)
{
Cursor.Current = Cursors.Hand;
}
}
else
{
if (Cursor.Current == Cursors.Hand)
{
Cursor.Current = Cursors.Default;
}
}
}
#endregion
#region Timer Events
/// <summary>
/// This timer updates the status message.
/// </summary>
/// <param name="sender">Event sender</param>
/// <param name="e">Event arguments</param>
private void timerUpdateGUI_Tick(object sender, EventArgs e)
{
// Display new status
if (lblStatus.Text != status)
{
lblStatus.Text = status;
}
//// Display error
//if (lblError.Text != error)
//{
// lblError.Visible = true;
// lblError.Text = error;
//}
}
/// <summary>
/// This timer updates the fade in/fade out.
/// </summary>
/// <param name="sender">Event sender</param>
/// <param name="e">Event arguments</param>
private void timerFading_Tick(object sender, EventArgs e)
{
if (fadingIn)
{
this.Opacity = this.Opacity + 0.05;
if (this.Opacity == 1)
{
fadingIn = false;
return;
}
}
if (fadingOut)
{
this.Opacity = this.Opacity - 0.05;
if (this.Opacity == 0)
{
fadingOut = false;
if (closeFormAfterFadeOut)
{
this.Close();
}
//windowSplash.Hide();
}
}
}
#endregion
#region ISplashView implementation
public Action<IBaseView> OnViewDestroy { get; set; }
public void ShowView(bool shown)
{
}
public void RefreshStatus(string message)
{
MethodInvoker methodUIUpdate = delegate {
lblStatus.Text = message;
};
if (InvokeRequired)
BeginInvoke(methodUIUpdate);
else
methodUIUpdate.Invoke();
}
void ISplashView.InitDone(bool isAppFirstStart)
{
MethodInvoker methodUIUpdate = Close;
if (InvokeRequired)
BeginInvoke(methodUIUpdate);
else
methodUIUpdate.Invoke();
}
#endregion
}
}