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

Diff of /trunk/EmuXPortal/Form1.cs

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

--- trunk/EmuXPortal/Form1.cs	2014/08/04 08:29:17	182
+++ trunk/EmuXPortal/Form1.cs	2014/08/04 09:46:22	183
@@ -1,4 +1,5 @@
 #define DISABLE_CURSOR_HIDE // when this is present, the cursor will not be hidden
+//#define DISABLE_PROGRESS_PERCENTAGE_MESSASGE // when this is present, no progress percent message will be shown on any progressbar
 using System;
 using System.Collections.Generic;
 using System.ComponentModel;
@@ -12,11 +13,15 @@
 using System.Diagnostics;
 using System.Reflection;
 using System.Threading;
+using Utilities.TransparentControls;
 
 namespace EmuXPortal
 {
     public partial class Form1 : Form
     {
+        const float PROGRESS_BAR_FONT_SIZE = 24;
+        private delegate Font Delegate_GetFormFont();
+        private delegate Font Delegate_ResizeFont(Font font, float size);
         IEmuConfig CurrentSelectedRom = null;
         PlatformControl CurrentPlatformControl = null;
         GameControl CurrentGameControl = null;
@@ -61,7 +66,7 @@
 
             int changeAmount = 0;
             int currentPosition = 0;
-            if (e.KeyCode == Keys.F && e.Modifiers.HasFlag(Keys.Control))
+            if (e.KeyCode == Keys.F && (e.Modifiers & Keys.Control) == Keys.Control)
             {
                 IRomConfig config = c.Tag as IRomConfig;
                 if (config == null)
@@ -418,6 +423,30 @@
                 return this.Width;
             }
         }
+        private Font GetFormFont()
+        {
+            if (this.InvokeRequired)
+            {
+                return (this.Invoke(new Delegate_GetFormFont(GetFormFont)) as Font);
+            }
+            else
+            {
+                return this.Font;
+            }
+        }
+
+        private Font ResizeFont(Font font, float size)
+        {
+            if (this.InvokeRequired)
+            {
+                 return (this.Invoke(new Delegate_ResizeFont(ResizeFont), new object[] { font, size })as Font);
+            }
+            else
+            {
+                return new Font(font.FontFamily, size);
+            }
+        }
+
         //private void AddPlatformControl(Control c)
         //{          
         //    if (platform_flow.InvokeRequired) { platform_flow.Invoke((MethodInvoker)delegate() { AddPlatformControl(c); }); }
@@ -452,25 +481,25 @@
             Stopwatch t = e.Argument as Stopwatch;
             RomParser parser = new RomParser(log, CurrentSelectedRom);
 
-            ProgressBar bar = new ProgressBar();
-            if (rom_flow.InvokeRequired) { rom_flow.Invoke((MethodInvoker)delegate() { rom_flow.Controls.Add(bar); }); }
-            else { rom_flow.Controls.Add(bar); }
-            //UpdateGameControls();
-            //Application.DoEvents();
-            //Thread.Sleep(10);
-            bar.Invoke(new MethodInvoker(delegate
-            {
-                //bar.Message = "Please Wait...";
-                //bar.ShowPercentageLabel = true;
-                bar.Margin = new System.Windows.Forms.Padding(0);
-                bar.Size = new Size(GetFormWidth() - 25, 100);
-            }));
+            CustomProgressBar bar = new CustomProgressBar();
+            bar.Font = ResizeFont(GetFormFont(), PROGRESS_BAR_FONT_SIZE);
+#if DISABLE_PROGRESS_PERCENTAGE_MESSASGE
+            bar.ShowPercentageLabel = false;
+#endif
+            bar.ProgressColor = Color.LimeGreen;
+            bar.Dock = DockStyle.Top;
+
+            if (this.InvokeRequired) { this.Invoke((MethodInvoker)delegate() { this.Controls.Add(bar); }); }
+            else { this.Controls.Add(bar); }
+            bar.Invoke(new MethodInvoker(delegate { bar.Margin = new System.Windows.Forms.Padding(0); bar.Size = new Size(GetFormWidth() - 25, 100); }));
             
             double count = 0;
             double total_count = parser.Roms.Count;
             foreach (IRomConfig config in parser.Roms)
             {
+                bar.Invoke(new MethodInvoker(delegate { bar.Value = (int)(100.0 * (count / total_count)); }));
                 GameControl game_ctrl = new GameControl();
+                game_ctrl.Font = GetFormFont();
                 game_ctrl.Dock = DockStyle.Top;
                 game_ctrl.Width = this.Width - 10;
                 game_ctrl.Tag = config;
@@ -494,22 +523,16 @@
                 else
                 {
                     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);
                 if (rom_flow.InvokeRequired) { rom_flow.Invoke((MethodInvoker)delegate() { 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));
-                }));
                 count++;
             }
+            bar.Invoke(new MethodInvoker(delegate { bar.Value = 1; bar.Update(); }));
+            if (this.InvokeRequired) { this.Invoke((MethodInvoker)delegate() { this.Controls.Remove(bar); }); } else { this.Controls.Remove(bar); }
             e.Result = t;
             parser.Dispose();
         }
@@ -533,20 +556,22 @@
             PlatformParser parser = new PlatformParser(log, Config.RomPath);
             double count = 0;
             double total_count = parser.Platforms.Count;
-            ProgressBar bar = new ProgressBar();
-            if (platform_flow.InvokeRequired) { platform_flow.Invoke((MethodInvoker)delegate() { platform_flow.Controls.Add(bar); }); }
-            else { platform_flow.Controls.Add(bar); }  
-            //UpdatePlatformControls();
-            //Application.DoEvents();
-            //Thread.Sleep(10);
-            bar.Invoke(new MethodInvoker(delegate
-            {
-                bar.Margin = new System.Windows.Forms.Padding(0);
-                bar.Size = new Size(GetFormWidth() - 25, 100);
-            }));
+            CustomProgressBar bar = new CustomProgressBar();
+            bar.Font = ResizeFont(GetFormFont(), PROGRESS_BAR_FONT_SIZE);
+#if DISABLE_PROGRESS_PERCENTAGE_MESSASGE
+            bar.ShowPercentageLabel = false;
+#endif
+            bar.ProgressColor = Color.LimeGreen;
+            bar.Dock = DockStyle.Top;
+            if (this.InvokeRequired) { this.Invoke((MethodInvoker)delegate() { this.Controls.Add(bar); }); }
+            else { this.Controls.Add(bar); }
+            bar.Invoke(new MethodInvoker(delegate { bar.Margin = new System.Windows.Forms.Padding(0); bar.Size = new Size(GetFormWidth() - 25, 100); }));
             foreach (IEmuConfig config in parser.Platforms)
             {
+                bar.Invoke(new MethodInvoker(delegate { bar.Value = (int)(100.0 * (count / total_count)); }));
+                
                 PlatformControl platform_ctrl = new PlatformControl();
+                platform_ctrl.Font = GetFormFont();
                 platform_ctrl.Dock = DockStyle.Top;
                 platform_ctrl.Width = this.Width - 10;
                 platform_ctrl.Tag = config;
@@ -567,16 +592,11 @@
                 platform_ctrl.GotFocus += new EventHandler(platform_ctrl_GotFocus);
                 platform_ctrl.LostFocus += new EventHandler(platform_ctrl_LostFocus);
                 if (platform_flow.InvokeRequired) { platform_flow.Invoke((MethodInvoker)delegate() { 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));
-                }));
+                else { platform_flow.Controls.Add(platform_ctrl); }                  
                 count++;
             }
+            bar.Invoke(new MethodInvoker(delegate { bar.Value = 1; bar.Update(); }));
+            if (this.InvokeRequired) { this.Invoke((MethodInvoker)delegate() { this.Controls.Remove(bar); }); } else { this.Controls.Remove(bar); }
             e.Result = t;
             parser.Dispose();
         }
@@ -584,9 +604,7 @@
         private void platformWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
         {
             Stopwatch t = e.Result as Stopwatch;
-            platform_flow.Controls.RemoveAt(0);
             platform_flow.Controls[0].Select();
-            (platform_flow.Controls[0] as PlatformControl).BorderStyle = BorderStyle.FixedSingle;
             log.WriteLine("PlatformParser took: {0}s to parse platforms", (int)t.Elapsed.TotalSeconds);
         }
         #endregion

 

  ViewVC Help
Powered by ViewVC 1.1.22