9 |
using EmuXPortal.Api; |
using EmuXPortal.Api; |
10 |
using EmuXPortal.Logging; |
using EmuXPortal.Logging; |
11 |
using System.Diagnostics; |
using System.Diagnostics; |
12 |
|
using System.Reflection; |
13 |
|
using System.Threading; |
14 |
|
|
15 |
namespace EmuXPortal |
namespace EmuXPortal |
16 |
{ |
{ |
32 |
Config.LoadConfig(); |
Config.LoadConfig(); |
33 |
Config.InitializePresentationForm(this); |
Config.InitializePresentationForm(this); |
34 |
} |
} |
35 |
private void Form1_Shown(object sender, EventArgs e) { platform_flow.Visible = true; } |
private void Form1_Shown(object sender, EventArgs e) { platform_flow.Visible = true; Cursor.Hide(); } |
36 |
void platform_ctrl_LostFocus(object sender, EventArgs e) |
void platform_ctrl_LostFocus(object sender, EventArgs e) |
37 |
{ |
{ |
38 |
PlatformControl c = sender as PlatformControl; |
PlatformControl c = sender as PlatformControl; |
49 |
void platform_ctrl_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e) |
void platform_ctrl_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e) |
50 |
{ |
{ |
51 |
PlatformControl c = sender as PlatformControl; |
PlatformControl c = sender as PlatformControl; |
52 |
|
int changeAmount = 0; |
53 |
|
int currentPosition = 0; |
54 |
|
if (e.KeyCode == Keys.Home) |
55 |
|
{ |
56 |
|
platform_flow.Controls[0].Select(); |
57 |
|
platform_flow.ScrollControlIntoView(platform_flow.Controls[0]); |
58 |
|
} |
59 |
|
if (e.KeyCode == Keys.End) |
60 |
|
{ |
61 |
|
platform_flow.Controls[platform_flow.Controls.Count -1].Select(); |
62 |
|
platform_flow.ScrollControlIntoView(platform_flow.Controls[platform_flow.Controls.Count - 1]); |
63 |
|
} |
64 |
|
if (e.KeyCode == Keys.PageUp) |
65 |
|
{ |
66 |
|
|
67 |
|
|
68 |
|
changeAmount = platform_flow.VerticalScroll.LargeChange; |
69 |
|
currentPosition = platform_flow.VerticalScroll.Value; |
70 |
|
if ((currentPosition - changeAmount) > platform_flow.VerticalScroll.Minimum) |
71 |
|
{ |
72 |
|
platform_flow.VerticalScroll.Value -= changeAmount; |
73 |
|
} |
74 |
|
else |
75 |
|
{ |
76 |
|
platform_flow.VerticalScroll.Value = platform_flow.VerticalScroll.Minimum; |
77 |
|
} |
78 |
|
PlatformControl s = platform_ctrl_get_last_visible(); |
79 |
|
s.Select(); |
80 |
|
platform_flow.ScrollControlIntoView(s); |
81 |
|
platform_flow.PerformLayout(); |
82 |
|
} |
83 |
|
if (e.KeyCode == Keys.PageDown) |
84 |
|
{ |
85 |
|
changeAmount = platform_flow.VerticalScroll.LargeChange; |
86 |
|
currentPosition = platform_flow.VerticalScroll.Value; |
87 |
|
if ((currentPosition - changeAmount) < platform_flow.VerticalScroll.Maximum) |
88 |
|
{ |
89 |
|
try |
90 |
|
{ |
91 |
|
platform_flow.VerticalScroll.Value += changeAmount; |
92 |
|
} |
93 |
|
catch |
94 |
|
{ |
95 |
|
platform_flow.Controls[0].Select(); |
96 |
|
platform_flow.ScrollControlIntoView(platform_flow.Controls[0]); |
97 |
|
rom_flow.PerformLayout(); |
98 |
|
return; |
99 |
|
} |
100 |
|
} |
101 |
|
else |
102 |
|
{ |
103 |
|
platform_flow.Controls[0].Select(); |
104 |
|
platform_flow.ScrollControlIntoView(platform_flow.Controls[0]); |
105 |
|
} |
106 |
|
PlatformControl s = platform_ctrl_get_last_visible(); |
107 |
|
s.Select(); |
108 |
|
platform_flow.ScrollControlIntoView(s); |
109 |
|
platform_flow.PerformLayout(); |
110 |
|
} |
111 |
if (e.KeyCode == Keys.Enter) |
if (e.KeyCode == Keys.Enter) |
112 |
{ |
{ |
113 |
// load this platform |
// load this platform |
164 |
platform_flow.BringToFront(); |
platform_flow.BringToFront(); |
165 |
Stopwatch t = new Stopwatch(); |
Stopwatch t = new Stopwatch(); |
166 |
t.Start(); |
t.Start(); |
167 |
PlatformParser parser = new PlatformParser(Config.RomPath); |
platformWorker.RunWorkerAsync(t); |
|
foreach (IEmuConfig config in parser.Platforms) |
|
|
{ |
|
|
PlatformControl platform_ctrl = new PlatformControl(); |
|
|
platform_ctrl.Dock = DockStyle.Top; |
|
|
platform_ctrl.Width = this.Width - 10; |
|
|
platform_ctrl.Tag = config; |
|
|
platform_ctrl.PlatformImage = config.PlatformImage; |
|
|
platform_ctrl.PlatformName = config.ToString(); |
|
|
platform_ctrl.PreviewKeyDown += new PreviewKeyDownEventHandler(platform_ctrl_PreviewKeyDown); |
|
|
platform_ctrl.GotFocus += new EventHandler(platform_ctrl_GotFocus); |
|
|
platform_ctrl.LostFocus += new EventHandler(platform_ctrl_LostFocus); |
|
|
platform_flow.Controls.Add(platform_ctrl); |
|
|
|
|
|
} |
|
|
platform_flow.Controls[0].Select(); |
|
|
(platform_flow.Controls[0] as PlatformControl).BorderStyle = BorderStyle.FixedSingle; |
|
|
logger.WriteLine("PlatformParser took: {0}s to parse platforms", (int)t.Elapsed.TotalSeconds); |
|
168 |
} |
} |
169 |
|
|
170 |
private void rom_flow_VisibleChanged(object sender, EventArgs e) |
private void rom_flow_VisibleChanged(object sender, EventArgs e) |
174 |
rom_flow.BringToFront(); |
rom_flow.BringToFront(); |
175 |
Stopwatch t = new Stopwatch(); |
Stopwatch t = new Stopwatch(); |
176 |
t.Start(); |
t.Start(); |
177 |
RomParser parser = new RomParser(CurrentSelectedRom); |
gameWorker.RunWorkerAsync(t); |
|
foreach (IRomConfig config in parser.Roms) |
|
|
{ |
|
|
GameControl game_ctrl = new GameControl(); |
|
|
game_ctrl.Dock = DockStyle.Top; |
|
|
game_ctrl.Width = this.Width - 10; |
|
|
game_ctrl.Tag = config; |
|
|
game_ctrl.GameImage = config.RomImage; |
|
|
game_ctrl.GameName = config.RomTitle; |
|
|
game_ctrl.PreviewKeyDown += new PreviewKeyDownEventHandler(game_ctrl_PreviewKeyDown); |
|
|
game_ctrl.GotFocus += new EventHandler(game_ctrl_GotFocus); |
|
|
game_ctrl.LostFocus += new EventHandler(game_ctrl_LostFocus); |
|
|
rom_flow.Controls.Add(game_ctrl); |
|
|
rom_flow.Update(); |
|
|
} |
|
|
rom_flow.Controls[0].Select(); |
|
|
(rom_flow.Controls[0] as GameControl).BorderStyle = BorderStyle.FixedSingle; |
|
|
t.Stop(); |
|
|
logger.WriteLine("RomParser took: {0}s to parse roms", (int)t.Elapsed.TotalSeconds); |
|
178 |
} |
} |
179 |
|
|
180 |
void game_ctrl_LostFocus(object sender, EventArgs e) |
void game_ctrl_LostFocus(object sender, EventArgs e) |
190 |
CurrentGameControl = c; |
CurrentGameControl = c; |
191 |
} |
} |
192 |
|
|
193 |
|
private GameControl game_ctrl_get_last_visible() |
194 |
|
{ |
195 |
|
GameControl s = new GameControl(); |
196 |
|
foreach (GameControl c in rom_flow.Controls) |
197 |
|
{ |
198 |
|
if (c.Bounds.IntersectsWith(rom_flow.Bounds)) |
199 |
|
s = c; |
200 |
|
} |
201 |
|
return s; |
202 |
|
} |
203 |
|
private PlatformControl platform_ctrl_get_last_visible() |
204 |
|
{ |
205 |
|
PlatformControl s = new PlatformControl(); |
206 |
|
foreach (PlatformControl c in platform_flow.Controls) |
207 |
|
{ |
208 |
|
if (c.Bounds.IntersectsWith(platform_flow.Bounds)) |
209 |
|
s = c; |
210 |
|
} |
211 |
|
return s; |
212 |
|
} |
213 |
void game_ctrl_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e) |
void game_ctrl_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e) |
214 |
{ |
{ |
215 |
GameControl c = sender as GameControl; |
GameControl c = sender as GameControl; |
216 |
|
|
217 |
|
int changeAmount = 0; |
218 |
|
int currentPosition = 0; |
219 |
|
if (e.KeyCode == Keys.Home) |
220 |
|
{ |
221 |
|
rom_flow.Controls[0].Select(); |
222 |
|
rom_flow.ScrollControlIntoView(rom_flow.Controls[0]); |
223 |
|
} |
224 |
|
if (e.KeyCode == Keys.End) |
225 |
|
{ |
226 |
|
rom_flow.Controls[rom_flow.Controls.Count - 1].Select(); |
227 |
|
rom_flow.ScrollControlIntoView(rom_flow.Controls[rom_flow.Controls.Count - 1]); |
228 |
|
} |
229 |
|
if (e.KeyCode == Keys.PageUp) |
230 |
|
{ |
231 |
|
changeAmount = rom_flow.VerticalScroll.LargeChange; |
232 |
|
currentPosition = rom_flow.VerticalScroll.Value; |
233 |
|
if ((currentPosition - changeAmount) > rom_flow.VerticalScroll.Minimum) |
234 |
|
{ |
235 |
|
try |
236 |
|
{ |
237 |
|
rom_flow.VerticalScroll.Value += changeAmount; |
238 |
|
} |
239 |
|
catch |
240 |
|
{ |
241 |
|
rom_flow.Controls[0].Select(); |
242 |
|
rom_flow.ScrollControlIntoView(platform_flow.Controls[0]); |
243 |
|
rom_flow.PerformLayout(); |
244 |
|
return; |
245 |
|
} |
246 |
|
} |
247 |
|
else |
248 |
|
{ |
249 |
|
rom_flow.Controls[0].Select(); |
250 |
|
rom_flow.ScrollControlIntoView(platform_flow.Controls[0]); |
251 |
|
} |
252 |
|
GameControl s = game_ctrl_get_last_visible(); |
253 |
|
s.Select(); |
254 |
|
rom_flow.ScrollControlIntoView(s); |
255 |
|
rom_flow.PerformLayout(); |
256 |
|
} |
257 |
|
if (e.KeyCode == Keys.PageDown) |
258 |
|
{ |
259 |
|
changeAmount = rom_flow.VerticalScroll.LargeChange; |
260 |
|
currentPosition = rom_flow.VerticalScroll.Value; |
261 |
|
if ((currentPosition - changeAmount) < rom_flow.VerticalScroll.Maximum) |
262 |
|
{ |
263 |
|
rom_flow.VerticalScroll.Value += changeAmount; |
264 |
|
} |
265 |
|
else |
266 |
|
{ |
267 |
|
rom_flow.VerticalScroll.Value = rom_flow.VerticalScroll.Maximum; |
268 |
|
} |
269 |
|
GameControl s = game_ctrl_get_last_visible(); |
270 |
|
s.Select(); |
271 |
|
rom_flow.ScrollControlIntoView(s); |
272 |
|
rom_flow.PerformLayout(); |
273 |
|
} |
274 |
|
|
275 |
if (e.KeyCode == Keys.Enter) |
if (e.KeyCode == Keys.Enter) |
276 |
{ |
{ |
277 |
IRomConfig config = c.Tag as IRomConfig; |
IRomConfig config = c.Tag as IRomConfig; |
322 |
pc = ctrl; |
pc = ctrl; |
323 |
} |
} |
324 |
} |
} |
325 |
} |
} |
326 |
|
|
327 |
|
#region Background Workers |
328 |
|
|
329 |
|
private int GetFormWidth() |
330 |
|
{ |
331 |
|
if (this.InvokeRequired) |
332 |
|
{ |
333 |
|
return Convert.ToInt32(this.Invoke((MethodInvoker)delegate() { GetFormWidth(); })); |
334 |
|
} |
335 |
|
else |
336 |
|
{ |
337 |
|
return this.Width; |
338 |
|
} |
339 |
|
} |
340 |
|
private void AddPlatformControl(Control c) |
341 |
|
{ |
342 |
|
if (platform_flow.InvokeRequired) { platform_flow.Invoke((MethodInvoker)delegate() { AddPlatformControl(c); }); } |
343 |
|
else |
344 |
|
{ |
345 |
|
platform_flow.Controls.Add(c); |
346 |
|
} |
347 |
|
} |
348 |
|
private void UpdatePlatformControls() |
349 |
|
{ |
350 |
|
if (platform_flow.InvokeRequired) { platform_flow.Invoke((MethodInvoker)delegate() { UpdatePlatformControls(); }); } |
351 |
|
else { this.Refresh(); this.Update(); } |
352 |
|
} |
353 |
|
private void AddGameControl(Control c) |
354 |
|
{ |
355 |
|
if (rom_flow.InvokeRequired) { rom_flow.Invoke((MethodInvoker)delegate() { AddGameControl(c); }); } |
356 |
|
else |
357 |
|
{ |
358 |
|
rom_flow.Controls.Add(c); |
359 |
|
} |
360 |
|
} |
361 |
|
private void UpdateGameControls() |
362 |
|
{ |
363 |
|
if (rom_flow.InvokeRequired) { rom_flow.Invoke((MethodInvoker)delegate() { UpdateGameControls(); }); } |
364 |
|
else { this.Refresh(); this.Update(); } |
365 |
|
} |
366 |
|
#region gameWorker |
367 |
|
private void gameWorker_DoWork(object sender, DoWorkEventArgs e) |
368 |
|
{ |
369 |
|
Stopwatch t = e.Argument as Stopwatch; |
370 |
|
RomParser parser = new RomParser(CurrentSelectedRom); |
371 |
|
|
372 |
|
ProgressBar bar = new ProgressBar(); |
373 |
|
AddGameControl(bar); |
374 |
|
UpdateGameControls(); |
375 |
|
Application.DoEvents(); |
376 |
|
Thread.Sleep(10); |
377 |
|
bar.Invoke(new MethodInvoker(delegate |
378 |
|
{ |
379 |
|
//bar.Message = "Please Wait..."; |
380 |
|
//bar.ShowPercentageLabel = true; |
381 |
|
bar.Margin = new System.Windows.Forms.Padding(0); |
382 |
|
bar.Size = new Size(GetFormWidth() - 25, 100); |
383 |
|
})); |
384 |
|
|
385 |
|
double count = 0; |
386 |
|
double total_count = parser.Roms.Count; |
387 |
|
foreach (IRomConfig config in parser.Roms) |
388 |
|
{ |
389 |
|
GameControl game_ctrl = new GameControl(); |
390 |
|
game_ctrl.Dock = DockStyle.Top; |
391 |
|
game_ctrl.Width = this.Width - 10; |
392 |
|
game_ctrl.Tag = config; |
393 |
|
game_ctrl.GameImage = config.RomImage; |
394 |
|
game_ctrl.GameName = config.RomTitle; |
395 |
|
game_ctrl.PreviewKeyDown += new PreviewKeyDownEventHandler(game_ctrl_PreviewKeyDown); |
396 |
|
game_ctrl.GotFocus += new EventHandler(game_ctrl_GotFocus); |
397 |
|
game_ctrl.LostFocus += new EventHandler(game_ctrl_LostFocus); |
398 |
|
AddGameControl(game_ctrl); |
399 |
|
UpdateGameControls(); |
400 |
|
Application.DoEvents(); |
401 |
|
int percent = (int)(100.0 * (count / total_count)); |
402 |
|
logger.WriteLine("gameWorker_DoWork(): count={0} total={1} percent={2}",count,total_count,percent); |
403 |
|
bar.Invoke(new MethodInvoker(delegate |
404 |
|
{ |
405 |
|
bar.Value = percent; |
406 |
|
})); |
407 |
|
count++; |
408 |
|
} |
409 |
|
e.Result = t; |
410 |
|
} |
411 |
|
private void gameWorker_ProgressChanged(object sender, ProgressChangedEventArgs e) { } |
412 |
|
private void gameWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) |
413 |
|
{ |
414 |
|
Stopwatch t = e.Result as Stopwatch; |
415 |
|
rom_flow.Controls.RemoveAt(0); |
416 |
|
rom_flow.Controls[0].Select(); |
417 |
|
(rom_flow.Controls[0] as GameControl).BorderStyle = BorderStyle.FixedSingle; |
418 |
|
t.Stop(); |
419 |
|
logger.WriteLine("RomParser took: {0}s to parse roms", (int)t.Elapsed.TotalSeconds); |
420 |
|
} |
421 |
|
#endregion |
422 |
|
#region platformWorker |
423 |
|
private void platformWorker_DoWork(object sender, DoWorkEventArgs e) |
424 |
|
{ |
425 |
|
Stopwatch t = e.Argument as Stopwatch; |
426 |
|
PlatformParser parser = new PlatformParser(Config.RomPath); |
427 |
|
double count = 0; |
428 |
|
double total_count = parser.Platforms.Count; |
429 |
|
ProgressBar bar = new ProgressBar(); |
430 |
|
AddPlatformControl(bar); |
431 |
|
UpdatePlatformControls(); |
432 |
|
Application.DoEvents(); |
433 |
|
Thread.Sleep(10); |
434 |
|
bar.Invoke(new MethodInvoker(delegate |
435 |
|
{ |
436 |
|
bar.Margin = new System.Windows.Forms.Padding(0); |
437 |
|
bar.Size = new Size(GetFormWidth() - 25, 100); |
438 |
|
})); |
439 |
|
foreach (IEmuConfig config in parser.Platforms) |
440 |
|
{ |
441 |
|
PlatformControl platform_ctrl = new PlatformControl(); |
442 |
|
platform_ctrl.Dock = DockStyle.Top; |
443 |
|
platform_ctrl.Width = this.Width - 10; |
444 |
|
platform_ctrl.Tag = config; |
445 |
|
platform_ctrl.PlatformImage = config.PlatformImage; |
446 |
|
platform_ctrl.PlatformName = config.ToString(); |
447 |
|
platform_ctrl.PreviewKeyDown += new PreviewKeyDownEventHandler(platform_ctrl_PreviewKeyDown); |
448 |
|
platform_ctrl.GotFocus += new EventHandler(platform_ctrl_GotFocus); |
449 |
|
platform_ctrl.LostFocus += new EventHandler(platform_ctrl_LostFocus); |
450 |
|
AddPlatformControl(platform_ctrl); |
451 |
|
Application.DoEvents(); |
452 |
|
int percent = (int)(100.0 * (count / total_count)); |
453 |
|
logger.WriteLine("platformWorker_DoWork(): count={0} total={1} percent={2}", count, total_count, percent); |
454 |
|
bar.Invoke(new MethodInvoker(delegate |
455 |
|
{ |
456 |
|
bar.Value = percent; |
457 |
|
})); |
458 |
|
count++; |
459 |
|
} |
460 |
|
e.Result = t; |
461 |
|
} |
462 |
|
private void platformWorker_ProgressChanged(object sender, ProgressChangedEventArgs e) { } |
463 |
|
private void platformWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) |
464 |
|
{ |
465 |
|
Stopwatch t = e.Result as Stopwatch; |
466 |
|
platform_flow.Controls.RemoveAt(0); |
467 |
|
platform_flow.Controls[0].Select(); |
468 |
|
(platform_flow.Controls[0] as PlatformControl).BorderStyle = BorderStyle.FixedSingle; |
469 |
|
logger.WriteLine("PlatformParser took: {0}s to parse platforms", (int)t.Elapsed.TotalSeconds); |
470 |
|
} |
471 |
|
#endregion |
472 |
|
|
473 |
|
private void Form1_FormClosed(object sender, FormClosedEventArgs e) |
474 |
|
{ |
475 |
|
Cursor.Show(); |
476 |
|
} |
477 |
|
#endregion |
478 |
} |
} |
479 |
} |
} |