// This file is part of the Noddybox.Emulation C# suite. // // Noddybox.Emulation is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // Noddybox.Emulation is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with Noddybox.Emulation. If not, see . // // Copyright (c) 2012 Ian Cowburn // using System; using System.IO; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using Noddybox.Emulation.Keyboard.Schema; using System.Xml; namespace EmuKeyboardDesigner { public partial class MainForm : Form { public MainForm() { 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); } } } }