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

Contents of /trunk/EmuXPortal/Form1.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 37 - (show annotations) (download)
Wed Apr 4 07:21:54 2012 UTC (8 years, 4 months ago) by william
File size: 9318 byte(s)
use stopwatches to check performance

1 using System;
2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Data;
5 using System.Drawing;
6 using System.Linq;
7 using System.Text;
8 using System.Windows.Forms;
9 using EmuXPortal.Api;
10 using EmuXPortal.Logging;
11 using System.Diagnostics;
12
13 namespace EmuXPortal
14 {
15 public partial class Form1 : Form
16 {
17 IEmuConfig CurrentSelectedRom = null;
18 PlatformControl CurrentPlatformControl = null;
19 GameControl CurrentGameControl = null;
20 public Form1()
21 {
22 InitializeComponent();
23 platform_flow.Dock = DockStyle.Fill;
24 rom_flow.Dock = DockStyle.Fill;
25
26 }
27
28 private void Form1_Load(object sender, EventArgs e)
29 {
30 Config.LoadConfig();
31 Config.InitializePresentationForm(this);
32 }
33 private void Form1_Shown(object sender, EventArgs e) { platform_flow.Visible = true; }
34 void platform_ctrl_LostFocus(object sender, EventArgs e)
35 {
36 PlatformControl c = sender as PlatformControl;
37 c.BorderStyle = BorderStyle.None;
38 }
39
40 void platform_ctrl_GotFocus(object sender, EventArgs e)
41 {
42 PlatformControl c = sender as PlatformControl;
43 c.BorderStyle = BorderStyle.FixedSingle;
44 CurrentPlatformControl = c;
45 }
46
47 void platform_ctrl_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
48 {
49 PlatformControl c = sender as PlatformControl;
50 if (e.KeyCode == Keys.Enter)
51 {
52 // load this platform
53 platform_flow.Visible = false;
54 CurrentSelectedRom = c.Tag as IEmuConfig;
55 rom_flow.Visible = true;
56 rom_flow.BringToFront();
57 }
58 if (e.KeyCode == Keys.Back)
59 {
60 this.Close();
61 }
62 if ((e.KeyCode >= Keys.A && e.KeyCode <= Keys.Z) ||
63 (e.KeyCode >= Keys.D0 && e.KeyCode <= Keys.D9))
64 {
65 char t = (char)e.KeyCode;
66 PlatformControl ctrl = (platform_flow.GetNextControl(CurrentPlatformControl, true) as PlatformControl);
67 if (ctrl == null) { ctrl = (platform_flow.GetNextControl(platform_flow.Controls[0], true) as PlatformControl); }
68 bool found = false;
69 PlatformControl pc = CurrentPlatformControl;
70 bool wrapped = false;
71 bool not_found = true;
72 while (!found)
73 {
74 if (wrapped)
75 {
76 foreach (Control ctl in platform_flow.Controls)
77 {
78 PlatformControl p_ctl = ctl as PlatformControl; if (p_ctl.PlatformName.ToLower().StartsWith(t.ToString().ToLower())) { not_found = false; }
79 }
80 if (not_found) { found = true; }
81 }
82 ctrl = (platform_flow.GetNextControl(pc, true) as PlatformControl);
83 if (ctrl == null)
84 {
85 ctrl = platform_flow.Controls[0] as PlatformControl;
86 wrapped = true;
87 }
88 if (ctrl.PlatformName.ToLower().StartsWith(t.ToString().ToLower()))
89 {
90 platform_flow.ScrollControlIntoView(ctrl);
91 ctrl.Select();
92 found = true;
93 }
94 pc = ctrl;
95 }
96 }
97 }
98
99 private void platform_flow_VisibleChanged(object sender, EventArgs e)
100 {
101 if (!platform_flow.Visible) return;
102 platform_flow.Controls.Clear();
103 platform_flow.BringToFront();
104 Stopwatch t = new Stopwatch();
105 t.Start();
106 PlatformParser parser = new PlatformParser(Config.RomPath);
107 foreach (IEmuConfig config in parser.Platforms)
108 {
109 PlatformControl platform_ctrl = new PlatformControl();
110 platform_ctrl.Dock = DockStyle.Top;
111 platform_ctrl.Width = this.Width - 10;
112 platform_ctrl.Tag = config;
113 platform_ctrl.PlatformImage = config.PlatformImage;
114 platform_ctrl.PlatformName = config.ToString();
115 platform_ctrl.PreviewKeyDown += new PreviewKeyDownEventHandler(platform_ctrl_PreviewKeyDown);
116 platform_ctrl.GotFocus += new EventHandler(platform_ctrl_GotFocus);
117 platform_ctrl.LostFocus += new EventHandler(platform_ctrl_LostFocus);
118 platform_flow.Controls.Add(platform_ctrl);
119
120 }
121 platform_flow.Controls[0].Select();
122 (platform_flow.Controls[0] as PlatformControl).BorderStyle = BorderStyle.FixedSingle;
123 logger.WriteLine("PlatformParser took: {0}s to parse platforms", (int)t.Elapsed.TotalSeconds);
124 }
125
126 private void rom_flow_VisibleChanged(object sender, EventArgs e)
127 {
128 if (!rom_flow.Visible) return;
129 rom_flow.Controls.Clear();
130 rom_flow.BringToFront();
131 Stopwatch t = new Stopwatch();
132 t.Start();
133 RomParser parser = new RomParser(CurrentSelectedRom);
134 foreach (IRomConfig config in parser.Roms)
135 {
136 GameControl game_ctrl = new GameControl();
137 game_ctrl.Dock = DockStyle.Top;
138 game_ctrl.Width = this.Width - 10;
139 game_ctrl.Tag = config;
140 game_ctrl.GameImage = config.RomImage;
141 game_ctrl.GameName = config.RomTitle;
142 game_ctrl.PreviewKeyDown += new PreviewKeyDownEventHandler(game_ctrl_PreviewKeyDown);
143 game_ctrl.GotFocus += new EventHandler(game_ctrl_GotFocus);
144 game_ctrl.LostFocus += new EventHandler(game_ctrl_LostFocus);
145 rom_flow.Controls.Add(game_ctrl);
146 rom_flow.Update();
147 }
148 rom_flow.Controls[0].Select();
149 (rom_flow.Controls[0] as GameControl).BorderStyle = BorderStyle.FixedSingle;
150 t.Stop();
151 logger.WriteLine("RomParser took: {0}s to parse roms", (int)t.Elapsed.TotalSeconds);
152 }
153
154 void game_ctrl_LostFocus(object sender, EventArgs e)
155 {
156 GameControl c = sender as GameControl;
157 c.BorderStyle = BorderStyle.None;
158 }
159
160 void game_ctrl_GotFocus(object sender, EventArgs e)
161 {
162 GameControl c = sender as GameControl;
163 c.BorderStyle = BorderStyle.FixedSingle;
164 CurrentGameControl = c;
165 }
166
167 void game_ctrl_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
168 {
169 GameControl c = sender as GameControl;
170 if (e.KeyCode == Keys.Enter)
171 {
172 IRomConfig config = c.Tag as IRomConfig;
173
174 Process p = new Process();
175 p.StartInfo.FileName = config.Config.EmuPath;
176 p.StartInfo.Arguments = EmuConfigLoader.GetEMUOptions(config);
177 p.Start();
178 }
179 if (e.KeyCode == Keys.Back)
180 {
181 rom_flow.Visible = false;
182 platform_flow.Visible = true;
183 }
184
185 if ( (e.KeyCode >= Keys.A && e.KeyCode <= Keys.Z) ||
186 (e.KeyCode >= Keys.D0 && e.KeyCode <= Keys.D9))
187 {
188 char t = (char)e.KeyCode;
189 GameControl ctrl = (rom_flow.GetNextControl(CurrentPlatformControl, true) as GameControl);
190 if (ctrl == null) { ctrl = (rom_flow.GetNextControl(rom_flow.Controls[0], true) as GameControl); }
191 bool found = false;
192 GameControl pc = CurrentGameControl;
193 bool wrapped = false;
194 bool not_found = true;
195 while (!found)
196 {
197 if (wrapped)
198 {
199 foreach (Control ctl in rom_flow.Controls)
200 {
201 GameControl p_ctl = ctl as GameControl; if (p_ctl.GameName.ToLower().StartsWith(t.ToString().ToLower())) { not_found = false; }
202 }
203 if (not_found) { found = true; }
204 }
205 ctrl = (rom_flow.GetNextControl(pc, true) as GameControl);
206 if (ctrl == null)
207 {
208 ctrl = rom_flow.Controls[0] as GameControl;
209 wrapped = true;
210 }
211 if (ctrl.GameName.ToLower().StartsWith(t.ToString().ToLower()))
212 {
213 rom_flow.ScrollControlIntoView(ctrl);
214 ctrl.Select();
215 found = true;
216 }
217 pc = ctrl;
218 }
219 }
220 }
221 }
222 }

  ViewVC Help
Powered by ViewVC 1.1.22