/[EmuXPortal]/trunk/EmuXPortal/Form1.cs
ViewVC logotype

Diff of /trunk/EmuXPortal/Form1.cs

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 181 by william, Mon Aug 4 08:10:19 2014 UTC revision 183 by william, Mon Aug 4 09:46:22 2014 UTC
# Line 1  Line 1 
1  #define DISABLE_CURSOR_HIDE // when this is present, the cursor will not be hidden  #define DISABLE_CURSOR_HIDE // when this is present, the cursor will not be hidden
2    //#define DISABLE_PROGRESS_PERCENTAGE_MESSASGE // when this is present, no progress percent message will be shown on any progressbar
3  using System;  using System;
4  using System.Collections.Generic;  using System.Collections.Generic;
5  using System.ComponentModel;  using System.ComponentModel;
# Line 12  using EmuXPortal.Logging; Line 13  using EmuXPortal.Logging;
13  using System.Diagnostics;  using System.Diagnostics;
14  using System.Reflection;  using System.Reflection;
15  using System.Threading;  using System.Threading;
16    using Utilities.TransparentControls;
17    
18  namespace EmuXPortal  namespace EmuXPortal
19  {  {
20      public partial class Form1 : Form      public partial class Form1 : Form
21      {      {
22            const float PROGRESS_BAR_FONT_SIZE = 24;
23            private delegate Font Delegate_GetFormFont();
24            private delegate Font Delegate_ResizeFont(Font font, float size);
25          IEmuConfig CurrentSelectedRom = null;          IEmuConfig CurrentSelectedRom = null;
26          PlatformControl CurrentPlatformControl = null;          PlatformControl CurrentPlatformControl = null;
27          GameControl CurrentGameControl = null;          GameControl CurrentGameControl = null;
# Line 61  namespace EmuXPortal Line 66  namespace EmuXPortal
66    
67              int changeAmount = 0;              int changeAmount = 0;
68              int currentPosition = 0;              int currentPosition = 0;
69              if (e.KeyCode == Keys.F && e.Modifiers.HasFlag(Keys.Control))              if (e.KeyCode == Keys.F && (e.Modifiers & Keys.Control) == Keys.Control)
70              {              {
71                  IRomConfig config = c.Tag as IRomConfig;                  IRomConfig config = c.Tag as IRomConfig;
72                  if (config == null)                  if (config == null)
# Line 418  namespace EmuXPortal Line 423  namespace EmuXPortal
423                  return this.Width;                  return this.Width;
424              }              }
425          }          }
426            private Font GetFormFont()
427            {
428                if (this.InvokeRequired)
429                {
430                    return (this.Invoke(new Delegate_GetFormFont(GetFormFont)) as Font);
431                }
432                else
433                {
434                    return this.Font;
435                }
436            }
437    
438            private Font ResizeFont(Font font, float size)
439            {
440                if (this.InvokeRequired)
441                {
442                     return (this.Invoke(new Delegate_ResizeFont(ResizeFont), new object[] { font, size })as Font);
443                }
444                else
445                {
446                    return new Font(font.FontFamily, size);
447                }
448            }
449    
450          //private void AddPlatformControl(Control c)          //private void AddPlatformControl(Control c)
451          //{                    //{          
452          //    if (platform_flow.InvokeRequired) { platform_flow.Invoke((MethodInvoker)delegate() { AddPlatformControl(c); }); }          //    if (platform_flow.InvokeRequired) { platform_flow.Invoke((MethodInvoker)delegate() { AddPlatformControl(c); }); }
# Line 452  namespace EmuXPortal Line 481  namespace EmuXPortal
481              Stopwatch t = e.Argument as Stopwatch;              Stopwatch t = e.Argument as Stopwatch;
482              RomParser parser = new RomParser(log, CurrentSelectedRom);              RomParser parser = new RomParser(log, CurrentSelectedRom);
483    
484              ProgressBar bar = new ProgressBar();              CustomProgressBar bar = new CustomProgressBar();
485              if (rom_flow.InvokeRequired) { rom_flow.Invoke((MethodInvoker)delegate() { rom_flow.Controls.Add(bar); }); }              bar.Font = ResizeFont(GetFormFont(), PROGRESS_BAR_FONT_SIZE);
486              else { rom_flow.Controls.Add(bar); }  #if DISABLE_PROGRESS_PERCENTAGE_MESSASGE
487              //UpdateGameControls();              bar.ShowPercentageLabel = false;
488              //Application.DoEvents();  #endif
489              //Thread.Sleep(10);              bar.ProgressColor = Color.LimeGreen;
490              bar.Invoke(new MethodInvoker(delegate              bar.Dock = DockStyle.Top;
491              {  
492                  //bar.Message = "Please Wait...";              if (this.InvokeRequired) { this.Invoke((MethodInvoker)delegate() { this.Controls.Add(bar); }); }
493                  //bar.ShowPercentageLabel = true;              else { this.Controls.Add(bar); }
494                  bar.Margin = new System.Windows.Forms.Padding(0);              bar.Invoke(new MethodInvoker(delegate { bar.Margin = new System.Windows.Forms.Padding(0); bar.Size = new Size(GetFormWidth() - 25, 100); }));
                 bar.Size = new Size(GetFormWidth() - 25, 100);  
             }));  
495                            
496              double count = 0;              double count = 0;
497              double total_count = parser.Roms.Count;              double total_count = parser.Roms.Count;
498              foreach (IRomConfig config in parser.Roms)              foreach (IRomConfig config in parser.Roms)
499              {              {
500                    bar.Invoke(new MethodInvoker(delegate { bar.Value = (int)(100.0 * (count / total_count)); }));
501                  GameControl game_ctrl = new GameControl();                  GameControl game_ctrl = new GameControl();
502                    game_ctrl.Font = GetFormFont();
503                  game_ctrl.Dock = DockStyle.Top;                  game_ctrl.Dock = DockStyle.Top;
504                  game_ctrl.Width = this.Width - 10;                  game_ctrl.Width = this.Width - 10;
505                  game_ctrl.Tag = config;                  game_ctrl.Tag = config;
# Line 494  namespace EmuXPortal Line 523  namespace EmuXPortal
523                  else                  else
524                  {                  {
525                      game_ctrl.GameName = config.RomTitle;                      game_ctrl.GameName = config.RomTitle;
526                  }                                  }      
527                  game_ctrl.PreviewKeyDown += new PreviewKeyDownEventHandler(game_ctrl_PreviewKeyDown);                  game_ctrl.PreviewKeyDown += new PreviewKeyDownEventHandler(game_ctrl_PreviewKeyDown);
528                  game_ctrl.GotFocus += new EventHandler(game_ctrl_GotFocus);                  game_ctrl.GotFocus += new EventHandler(game_ctrl_GotFocus);
529                  game_ctrl.LostFocus += new EventHandler(game_ctrl_LostFocus);                  game_ctrl.LostFocus += new EventHandler(game_ctrl_LostFocus);
530                  if (rom_flow.InvokeRequired) { rom_flow.Invoke((MethodInvoker)delegate() { rom_flow.Controls.Add(game_ctrl); }); }                  if (rom_flow.InvokeRequired) { rom_flow.Invoke((MethodInvoker)delegate() { rom_flow.Controls.Add(game_ctrl); }); }
531                  else { rom_flow.Controls.Add(game_ctrl); }                  else { rom_flow.Controls.Add(game_ctrl); }
                 //UpdateGameControls();  
                 //Application.DoEvents();  
                 //int percent = (int)(100.0 * (count / total_count));  
                 //log.WriteLine("gameWorker_DoWork(): count={0} total={1} percent={2}", count, total_count, (int)(100.0 * (count / total_count)));  
                 bar.Invoke(new MethodInvoker(delegate  
                 {  
                     bar.Value = (int)(100.0 * (count / total_count));  
                 }));  
532                  count++;                  count++;
533              }              }
534                bar.Invoke(new MethodInvoker(delegate { bar.Value = 1; bar.Update(); }));
535                if (this.InvokeRequired) { this.Invoke((MethodInvoker)delegate() { this.Controls.Remove(bar); }); } else { this.Controls.Remove(bar); }
536              e.Result = t;              e.Result = t;
537              parser.Dispose();              parser.Dispose();
538          }          }
# Line 533  namespace EmuXPortal Line 556  namespace EmuXPortal
556              PlatformParser parser = new PlatformParser(log, Config.RomPath);              PlatformParser parser = new PlatformParser(log, Config.RomPath);
557              double count = 0;              double count = 0;
558              double total_count = parser.Platforms.Count;              double total_count = parser.Platforms.Count;
559              ProgressBar bar = new ProgressBar();              CustomProgressBar bar = new CustomProgressBar();
560              if (platform_flow.InvokeRequired) { platform_flow.Invoke((MethodInvoker)delegate() { platform_flow.Controls.Add(bar); }); }              bar.Font = ResizeFont(GetFormFont(), PROGRESS_BAR_FONT_SIZE);
561              else { platform_flow.Controls.Add(bar); }    #if DISABLE_PROGRESS_PERCENTAGE_MESSASGE
562              //UpdatePlatformControls();              bar.ShowPercentageLabel = false;
563              //Application.DoEvents();  #endif
564              //Thread.Sleep(10);              bar.ProgressColor = Color.LimeGreen;
565              bar.Invoke(new MethodInvoker(delegate              bar.Dock = DockStyle.Top;
566              {              if (this.InvokeRequired) { this.Invoke((MethodInvoker)delegate() { this.Controls.Add(bar); }); }
567                  bar.Margin = new System.Windows.Forms.Padding(0);              else { this.Controls.Add(bar); }
568                  bar.Size = new Size(GetFormWidth() - 25, 100);              bar.Invoke(new MethodInvoker(delegate { bar.Margin = new System.Windows.Forms.Padding(0); bar.Size = new Size(GetFormWidth() - 25, 100); }));
             }));  
569              foreach (IEmuConfig config in parser.Platforms)              foreach (IEmuConfig config in parser.Platforms)
570              {              {
571                    bar.Invoke(new MethodInvoker(delegate { bar.Value = (int)(100.0 * (count / total_count)); }));
572                    
573                  PlatformControl platform_ctrl = new PlatformControl();                  PlatformControl platform_ctrl = new PlatformControl();
574                    platform_ctrl.Font = GetFormFont();
575                  platform_ctrl.Dock = DockStyle.Top;                  platform_ctrl.Dock = DockStyle.Top;
576                  platform_ctrl.Width = this.Width - 10;                  platform_ctrl.Width = this.Width - 10;
577                  platform_ctrl.Tag = config;                  platform_ctrl.Tag = config;
# Line 567  namespace EmuXPortal Line 592  namespace EmuXPortal
592                  platform_ctrl.GotFocus += new EventHandler(platform_ctrl_GotFocus);                  platform_ctrl.GotFocus += new EventHandler(platform_ctrl_GotFocus);
593                  platform_ctrl.LostFocus += new EventHandler(platform_ctrl_LostFocus);                  platform_ctrl.LostFocus += new EventHandler(platform_ctrl_LostFocus);
594                  if (platform_flow.InvokeRequired) { platform_flow.Invoke((MethodInvoker)delegate() { platform_flow.Controls.Add(platform_ctrl); }); }                  if (platform_flow.InvokeRequired) { platform_flow.Invoke((MethodInvoker)delegate() { platform_flow.Controls.Add(platform_ctrl); }); }
595                  else { platform_flow.Controls.Add(platform_ctrl); }                    else { platform_flow.Controls.Add(platform_ctrl); }                  
                 //Application.DoEvents();  
                 //int percent = (int)(100.0 * (count / total_count));  
                 //log.WriteLine("platformWorker_DoWork(): count={0} total={1} percent={2}", count, total_count, (int)(100.0 * (count / total_count)));  
                 bar.Invoke(new MethodInvoker(delegate  
                 {  
                     bar.Value = (int)(100.0 * (count / total_count));  
                 }));  
596                  count++;                  count++;
597              }              }
598                bar.Invoke(new MethodInvoker(delegate { bar.Value = 1; bar.Update(); }));
599                if (this.InvokeRequired) { this.Invoke((MethodInvoker)delegate() { this.Controls.Remove(bar); }); } else { this.Controls.Remove(bar); }
600              e.Result = t;              e.Result = t;
601              parser.Dispose();              parser.Dispose();
602          }          }
# Line 584  namespace EmuXPortal Line 604  namespace EmuXPortal
604          private void platformWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)          private void platformWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
605          {          {
606              Stopwatch t = e.Result as Stopwatch;              Stopwatch t = e.Result as Stopwatch;
             platform_flow.Controls.RemoveAt(0);  
607              platform_flow.Controls[0].Select();              platform_flow.Controls[0].Select();
             (platform_flow.Controls[0] as PlatformControl).BorderStyle = BorderStyle.FixedSingle;  
608              log.WriteLine("PlatformParser took: {0}s to parse platforms", (int)t.Elapsed.TotalSeconds);              log.WriteLine("PlatformParser took: {0}s to parse platforms", (int)t.Elapsed.TotalSeconds);
609          }          }
610          #endregion          #endregion

Legend:
Removed from v.181  
changed lines
  Added in v.183

  ViewVC Help
Powered by ViewVC 1.1.22