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

Contents of /trunk/EmuXPortal/Form1.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 25 - (show annotations) (download)
Wed Apr 4 03:12:17 2012 UTC (8 years, 4 months ago) by william
File size: 5663 byte(s)
+ add support when displaying platforms: if user pressed backspace, exit application

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 }
61
62 private void platform_flow_VisibleChanged(object sender, EventArgs e)
63 {
64 if (!platform_flow.Visible) return;
65 platform_flow.Controls.Clear();
66 platform_flow.BringToFront();
67 PlatformParser parser = new PlatformParser(Config.RomPath);
68 foreach (IEmuConfig config in parser.Platforms)
69 {
70 PlatformControl platform_ctrl = new PlatformControl();
71 platform_ctrl.Dock = DockStyle.Top;
72 platform_ctrl.Width = this.Width - 10;
73 platform_ctrl.Tag = config;
74 platform_ctrl.PlatformImage = config.PlatformImage;
75 platform_ctrl.PlatformName = config.PlatformNameLong;
76 platform_ctrl.PreviewKeyDown += new PreviewKeyDownEventHandler(platform_ctrl_PreviewKeyDown);
77 platform_flow.Controls.Add(platform_ctrl);
78 //platform_flow.SetFlowBreak(platform_ctrl, true);
79 platform_ctrl.GotFocus += new EventHandler(platform_ctrl_GotFocus);
80 platform_ctrl.LostFocus += new EventHandler(platform_ctrl_LostFocus);
81 //CurrentPlatformControl = platform_flow.Controls[0] as PlatformControl;
82 }
83 platform_flow.Controls[0].Select();
84 (platform_flow.Controls[0] as PlatformControl).BorderStyle = BorderStyle.FixedSingle;
85
86 }
87
88 private void rom_flow_VisibleChanged(object sender, EventArgs e)
89 {
90 if (!rom_flow.Visible) return;
91 rom_flow.Controls.Clear();
92 rom_flow.BringToFront();
93 RomParser parser = new RomParser(string.Format(@"{0}\{1}", CurrentSelectedRom.EmuRomPath, "Roms"), CurrentSelectedRom.Extenstions);
94 foreach (IRomConfig config in parser.Roms)
95 {
96 GameControl game_ctrl = new GameControl();
97 game_ctrl.Dock = DockStyle.Top;
98 game_ctrl.Width = this.Width - 10;
99 game_ctrl.Tag = config;
100 game_ctrl.GameImage = config.RomImage;
101 game_ctrl.GameName = config.RomTitle;
102 game_ctrl.PreviewKeyDown += new PreviewKeyDownEventHandler(game_ctrl_PreviewKeyDown);
103 rom_flow.Controls.Add(game_ctrl);
104 //rom_flow.SetFlowBreak(game_ctrl, true);
105 game_ctrl.GotFocus += new EventHandler(game_ctrl_GotFocus);
106 game_ctrl.LostFocus += new EventHandler(game_ctrl_LostFocus);
107 }
108 rom_flow.Controls[0].Select();
109 (rom_flow.Controls[0] as GameControl).BorderStyle = BorderStyle.FixedSingle;
110 }
111
112 void game_ctrl_LostFocus(object sender, EventArgs e)
113 {
114 GameControl c = sender as GameControl;
115 c.BorderStyle = BorderStyle.None;
116 }
117
118 void game_ctrl_GotFocus(object sender, EventArgs e)
119 {
120 GameControl c = sender as GameControl;
121 c.BorderStyle = BorderStyle.FixedSingle;
122 }
123
124 void game_ctrl_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
125 {
126 GameControl c = sender as GameControl;
127 if (e.KeyCode == Keys.Enter)
128 {
129 IRomConfig config = c.Tag as IRomConfig;
130
131 Process p = new Process();
132 p.StartInfo.FileName = config.Config.EmuPath;
133 p.StartInfo.Arguments = EmuConfigLoader.GetEMUOptions(config);
134 p.Start();
135 }
136 if (e.KeyCode == Keys.Back)
137 {
138 rom_flow.Visible = false;
139 platform_flow.Visible = true;
140 }
141 }
142 }
143 }

  ViewVC Help
Powered by ViewVC 1.1.22