From 2f12dcf3e6e9c3f4ee91d04cf8176322f60f2b8d Mon Sep 17 00:00:00 2001 From: Ian C Date: Tue, 8 May 2012 22:53:35 +0000 Subject: Added ops dialog to allow easier mass editing. --- Native/EmuKeyboardDesigner/MainForm.cs | 87 +++++++++++++++++++++++++++++++--- 1 file changed, 81 insertions(+), 6 deletions(-) (limited to 'Native/EmuKeyboardDesigner/MainForm.cs') diff --git a/Native/EmuKeyboardDesigner/MainForm.cs b/Native/EmuKeyboardDesigner/MainForm.cs index 33ebd22..d0d0b6c 100644 --- a/Native/EmuKeyboardDesigner/MainForm.cs +++ b/Native/EmuKeyboardDesigner/MainForm.cs @@ -36,6 +36,8 @@ namespace EmuKeyboardDesigner InitializeComponent(); } + private bool RunningOps {get; set;} + private void SetKey(bool select, bool allowNew) { string sym = keysymTextBox.Text; @@ -82,6 +84,28 @@ namespace EmuKeyboardDesigner SetKey(true, true); } + private void OnMoveUp(object sender, EventArgs e) + { + if (keyList.SelectedIndex > 0) + { + object o = keyList.Items[keyList.SelectedIndex-1]; + keyList.Items[keyList.SelectedIndex - 1] = keyList.Items[keyList.SelectedIndex]; + keyList.Items[keyList.SelectedIndex] = o; + keyList.SelectedIndex--; + } + } + + private void OnMoveDown(object sender, EventArgs e) + { + if (keyList.SelectedIndex > -1 && keyList.SelectedIndex < keyList.Items.Count - 1) + { + object o = keyList.Items[keyList.SelectedIndex]; + keyList.Items[keyList.SelectedIndex] = keyList.Items[keyList.SelectedIndex + 1]; + keyList.Items[keyList.SelectedIndex+1] = o; + keyList.SelectedIndex++; + } + } + private void OnLoad(object sender, EventArgs e) { OpenFileDialog fsel = new OpenFileDialog(); @@ -150,14 +174,10 @@ namespace EmuKeyboardDesigner } } - private void OnKeySelected(object sender, EventArgs e) + private void LoadKey(KeyboardKey key) { - if (keyList.SelectedIndex > -1) + if (key != null) { - SetKey(false, false); - - KeyboardKey key = (KeyboardKey)keyList.SelectedItem; - keysymTextBox.Text = key.KeySymbol; imageControl.KeyX = key.X; imageControl.KeyY = key.Y; @@ -167,6 +187,19 @@ namespace EmuKeyboardDesigner } } + private void OnKeySelected(object sender, EventArgs e) + { + if (keyList.SelectedIndex > -1) + { + if (!RunningOps) + { + SetKey(false, false); + } + + LoadKey((KeyboardKey)keyList.SelectedItem); + } + } + private void OnRemoveKey(object sender, EventArgs e) { if (keyList.SelectedIndex > -1) @@ -186,5 +219,47 @@ namespace EmuKeyboardDesigner } } } + + private void OnOps(object sender, EventArgs e) + { + OpsForm f = new OpsForm(); + + if (f.ShowDialog() == DialogResult.OK) + { + RunningOps = true; + + SetKey(false, false); + + int index = keyList.SelectedIndex; + + List l = new List(); + + foreach (KeyboardKey k in keyList.Items) + { + // I know -- these blocks are *real* lazy + // + try {if (f.RemoveFront > 0) k.KeySymbol = k.KeySymbol.Remove(0, f.RemoveFront);} catch {} + try {if (f.RemoveRear > 0) k.KeySymbol = k.KeySymbol.Remove(k.KeySymbol.Length - f.RemoveRear);} catch {} + + k.KeySymbol = f.Prefix + k.KeySymbol; + k.KeySymbol = k.KeySymbol + f.Suffix; + + k.X = Math.Max(0, k.X + f.AdjustX); + k.Y = Math.Max(0, k.Y + f.AdjustY); + k.Width = Math.Max(0, k.Width + f.AdjustWidth); + k.Height = Math.Max(0, k.Height + f.AdjustHeight); + + l.Add(k); + } + + keyList.BeginUpdate(); + keyList.Items.Clear(); + keyList.Items.AddRange(l.ToArray()); + keyList.EndUpdate(); + + keyList.SelectedIndex = index; + RunningOps = false; + } + } } } -- cgit v1.2.3