summaryrefslogtreecommitdiff
path: root/Native/EmuKeyboardDesigner/MainForm.cs
diff options
context:
space:
mode:
authorIan C <ianc@noddybox.co.uk>2012-04-27 16:24:53 +0000
committerIan C <ianc@noddybox.co.uk>2012-04-27 16:24:53 +0000
commit0191a758903099bdd39dddb2ef456333eee04fe3 (patch)
tree31e8285ef1c2707e3f2df26a12a4187146e8f007 /Native/EmuKeyboardDesigner/MainForm.cs
parent3b85ea1b69b1747caf944af6ce301c165e3b56cb (diff)
Added basic logic of UI. Still to add key overlay to image control.
Diffstat (limited to 'Native/EmuKeyboardDesigner/MainForm.cs')
-rw-r--r--Native/EmuKeyboardDesigner/MainForm.cs127
1 files changed, 127 insertions, 0 deletions
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);
+ }
+ }
}
}