From 0191a758903099bdd39dddb2ef456333eee04fe3 Mon Sep 17 00:00:00 2001 From: Ian C Date: Fri, 27 Apr 2012 16:24:53 +0000 Subject: Added basic logic of UI. Still to add key overlay to image control. --- Native/EmuKeyboardDesigner/MainForm.cs | 127 +++++++++++++++++++++++++++++++++ 1 file changed, 127 insertions(+) (limited to 'Native/EmuKeyboardDesigner/MainForm.cs') diff --git a/Native/EmuKeyboardDesigner/MainForm.cs b/Native/EmuKeyboardDesigner/MainForm.cs index 8ea1502..56887ba 100644 --- a/Native/EmuKeyboardDesigner/MainForm.cs +++ b/Native/EmuKeyboardDesigner/MainForm.cs @@ -16,6 +16,7 @@ // Copyright (c) 2012 Ian Cowburn // using System; +using System.IO; using System.Collections.Generic; using System.ComponentModel; using System.Data; @@ -23,6 +24,8 @@ using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; +using Noddybox.Emulation.Keyboard.Schema; +using System.Xml; namespace EmuKeyboardDesigner { @@ -32,5 +35,129 @@ namespace EmuKeyboardDesigner { InitializeComponent(); } + + private void OnSetKey(object sender, EventArgs e) + { + string sym = keysymTextBox.Text; + + if (!String.IsNullOrWhiteSpace(sym)) + { + int index = keyList.FindStringExact(sym); + + if (index > -1) + { + KeyboardKey key = (KeyboardKey)keyList.Items[index]; + + key.X = imageControl.KeyX; + key.Y = imageControl.KeyY; + key.Width = imageControl.KeyWidth; + key.Height = imageControl.KeyHeight; + key.Sticky = stickyCheckBox.Checked; + + keyList.SelectedItem = key; + } + else + { + KeyboardKey key = new KeyboardKey() + { + KeySymbol = sym, + X = imageControl.KeyX, + Y = imageControl.KeyY, + Width = imageControl.KeyWidth, + Height = imageControl.KeyHeight, + Sticky = stickyCheckBox.Checked + }; + + keyList.Items.Add(key); + keyList.SelectedItem = key; + } + } + } + + private void OnLoad(object sender, EventArgs e) + { + OpenFileDialog fsel = new OpenFileDialog(); + + fsel.Filter = "XML Files(*.XML)|*.XML"; + + if (fsel.ShowDialog() == DialogResult.OK) + { + try + { + XmlDocument xml = new XmlDocument(); + + xml.Load(fsel.FileName); + + KeyboardDefinition def = KeyboardDefinition.CreateFromXML(xml); + + keyList.Items.Clear(); + + foreach (KeyboardKey k in def.Definitions) + { + keyList.Items.Add(k); + } + + if (keyList.Items.Count > 0) + { + keyList.SelectedIndex = 0; + } + } + catch (Exception ex) + { + MessageBox.Show("Failed to load " + fsel.FileName + "\n\n" + ex.Message, ex.GetType().ToString(), MessageBoxButtons.OK); + } + } + } + + private void OnSave(object sender, EventArgs e) + { + SaveFileDialog fsel = new SaveFileDialog(); + + fsel.Filter = "XML Files(*.XML)|*.XML"; + + if (fsel.ShowDialog() == DialogResult.OK) + { + try + { + KeyboardDefinition def = new KeyboardDefinition(); + + foreach (KeyboardKey k in keyList.Items) + { + def.Definitions.Add(k); + } + + XmlDocument doc = def.CreateXML(); + + doc.Save(fsel.FileName); + } + catch (Exception ex) + { + MessageBox.Show("Failed to save " + fsel.FileName + "\n\n" + ex.Message, ex.GetType().ToString(), MessageBoxButtons.OK); + } + } + } + + private void OnKeySelected(object sender, EventArgs e) + { + if (keyList.SelectedIndex > -1) + { + KeyboardKey key = (KeyboardKey)keyList.SelectedItem; + + keysymTextBox.Text = key.KeySymbol; + imageControl.KeyX = key.X; + imageControl.KeyY = key.Y; + imageControl.KeyWidth = key.Width; + imageControl.KeyHeight = key.Height; + stickyCheckBox.Checked = key.Sticky; + } + } + + private void OnRemoveKey(object sender, EventArgs e) + { + if (keyList.SelectedIndex > -1) + { + keyList.Items.RemoveAt(keyList.SelectedIndex); + } + } } } -- cgit v1.2.3