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

Contents of /trunk/EmuXPortal/Form1.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 30 - (show annotations) (download)
Wed Apr 4 04:27:01 2012 UTC (8 years, 4 months ago) by william
File size: 6885 byte(s)
+ add support pressing a letter or number to jump to that entry

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 public Form1()
20 {
21 InitializeComponent();
22 platform_flow.Dock = DockStyle.Fill;
23 rom_flow.Dock = DockStyle.Fill;
24
25 Config.LoadConfig();
26 }
27
28 private void Form1_Load(object sender, EventArgs e)
29 {
30 Config.InitializePresentationForm(this);
31 }
32 private void Form1_Shown(object sender, EventArgs e) { platform_flow.Visible = true; }
33 void platform_ctrl_LostFocus(object sender, EventArgs e)
34 {
35 PlatformControl c = sender as PlatformControl;
36 c.BorderStyle = BorderStyle.None;
37 }
38
39 void platform_ctrl_GotFocus(object sender, EventArgs e)
40 {
41 PlatformControl c = sender as PlatformControl;
42 c.BorderStyle = BorderStyle.FixedSingle;
43 }
44
45 void platform_ctrl_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
46 {
47 PlatformControl c = sender as PlatformControl;
48 if (e.KeyCode == Keys.Enter)
49 {
50 // load this platform
51 platform_flow.Visible = false;
52 CurrentSelectedRom = c.Tag as IEmuConfig;
53 rom_flow.Visible = true;
54 rom_flow.BringToFront();
55 }
56 if (e.KeyCode == Keys.Back)
57 {
58 this.Close();
59 }
60 if ((e.KeyCode >= Keys.A && e.KeyCode <= Keys.Z) ||
61 (e.KeyCode >= Keys.D0 && e.KeyCode <= Keys.D9))
62 {
63 char t = (char)e.KeyCode;
64 foreach (Control cc in platform_flow.Controls)
65 {
66 PlatformControl gc = cc as PlatformControl;
67 if (gc.PlatformName.ToLower().StartsWith(t.ToString().ToLower()))
68 {
69 platform_flow.ScrollControlIntoView(gc);
70 gc.Select();
71 break;
72 }
73 }
74 }
75 }
76
77 private void platform_flow_VisibleChanged(object sender, EventArgs e)
78 {
79 if (!platform_flow.Visible) return;
80 platform_flow.Controls.Clear();
81 platform_flow.BringToFront();
82 PlatformParser parser = new PlatformParser(Config.RomPath);
83 foreach (IEmuConfig config in parser.Platforms)
84 {
85 PlatformControl platform_ctrl = new PlatformControl();
86 platform_ctrl.Dock = DockStyle.Top;
87 platform_ctrl.Width = this.Width - 10;
88 platform_ctrl.Tag = config;
89 platform_ctrl.PlatformImage = config.PlatformImage;
90 platform_ctrl.PlatformName = config.PlatformNameLong;
91 platform_ctrl.PreviewKeyDown += new PreviewKeyDownEventHandler(platform_ctrl_PreviewKeyDown);
92 platform_flow.Controls.Add(platform_ctrl);
93 //platform_flow.SetFlowBreak(platform_ctrl, true);
94 platform_ctrl.GotFocus += new EventHandler(platform_ctrl_GotFocus);
95 platform_ctrl.LostFocus += new EventHandler(platform_ctrl_LostFocus);
96 //CurrentPlatformControl = platform_flow.Controls[0] as PlatformControl;
97 }
98 platform_flow.Controls[0].Select();
99 (platform_flow.Controls[0] as PlatformControl).BorderStyle = BorderStyle.FixedSingle;
100
101 }
102
103 private void rom_flow_VisibleChanged(object sender, EventArgs e)
104 {
105 if (!rom_flow.Visible) return;
106 rom_flow.Controls.Clear();
107 rom_flow.BringToFront();
108 RomParser parser = new RomParser(CurrentSelectedRom);
109 foreach (IRomConfig config in parser.Roms)
110 {
111 GameControl game_ctrl = new GameControl();
112 game_ctrl.Dock = DockStyle.Top;
113 game_ctrl.Width = this.Width - 10;
114 game_ctrl.Tag = config;
115 game_ctrl.GameImage = config.RomImage;
116 game_ctrl.GameName = config.RomTitle;
117 game_ctrl.PreviewKeyDown += new PreviewKeyDownEventHandler(game_ctrl_PreviewKeyDown);
118 rom_flow.Controls.Add(game_ctrl);
119 //rom_flow.SetFlowBreak(game_ctrl, true);
120 game_ctrl.GotFocus += new EventHandler(game_ctrl_GotFocus);
121 game_ctrl.LostFocus += new EventHandler(game_ctrl_LostFocus);
122 }
123 rom_flow.Controls[0].Select();
124 (rom_flow.Controls[0] as GameControl).BorderStyle = BorderStyle.FixedSingle;
125 }
126
127 void game_ctrl_LostFocus(object sender, EventArgs e)
128 {
129 GameControl c = sender as GameControl;
130 c.BorderStyle = BorderStyle.None;
131 }
132
133 void game_ctrl_GotFocus(object sender, EventArgs e)
134 {
135 GameControl c = sender as GameControl;
136 c.BorderStyle = BorderStyle.FixedSingle;
137 }
138
139 void game_ctrl_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
140 {
141 GameControl c = sender as GameControl;
142 if (e.KeyCode == Keys.Enter)
143 {
144 IRomConfig config = c.Tag as IRomConfig;
145
146 Process p = new Process();
147 p.StartInfo.FileName = config.Config.EmuPath;
148 p.StartInfo.Arguments = EmuConfigLoader.GetEMUOptions(config);
149 p.Start();
150 }
151 if (e.KeyCode == Keys.Back)
152 {
153 rom_flow.Visible = false;
154 platform_flow.Visible = true;
155 }
156
157 if ( (e.KeyCode >= Keys.A && e.KeyCode <= Keys.Z) ||
158 (e.KeyCode >= Keys.D0 && e.KeyCode <= Keys.D9))
159 {
160 char t = (char)e.KeyCode;
161 foreach (Control cc in rom_flow.Controls)
162 {
163 GameControl gc = cc as GameControl;
164 if (gc.GameName.ToLower().StartsWith(t.ToString().ToLower()))
165 {
166 rom_flow.ScrollControlIntoView(gc);
167 gc.Select();
168 break;
169 }
170 }
171 }
172 }
173 }
174 }

  ViewVC Help
Powered by ViewVC 1.1.22