Skip to content

Commit a45f0cf

Browse files
committed
Another monster pass on the v2 refactor. WIP
1 parent ba5957c commit a45f0cf

22 files changed

+904
-515
lines changed

Format/BaseIOConfig.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,17 @@ public abstract class BaseIOConfig
3636

3737
public BaseIOConfig() { }
3838

39+
/// <summary>
40+
/// Clone constructor
41+
/// </summary>
42+
/// <param name="config"></param>
43+
public BaseIOConfig(BaseIOConfig config)
44+
{
45+
Flags = config.Flags;
46+
VirtualKey = config.VirtualKey;
47+
Parameter = config.Parameter;
48+
}
49+
3950
/// <summary>
4051
/// Constructor for an InputConfig
4152
/// </summary>

Format/InputConfig.cs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,13 @@ namespace KeyCap.Format
3333
public class InputConfig : BaseIOConfig
3434
{
3535
/// <summary>
36-
/// Flags applied to a given input/output key
36+
/// Copy constructor
37+
/// </summary>
38+
/// <param name="config"></param>
39+
public InputConfig(InputConfig config) : base(config) { }
40+
41+
/// <summary>
42+
/// Flags applied to a given input key (this is the same size as the OutputFlag (32bit)
3743
/// </summary>
3844
public enum InputFlag
3945
{
@@ -49,18 +55,18 @@ public enum InputFlag
4955
/// <param name="byFlags">The flags defining the input</param>
5056
/// <param name="byVirtualKey">The value of the input</param>
5157
/// <param name="eKeyArgs">The input key arguments from user input</param>
52-
public InputConfig(byte byFlags, byte byVirtualKey, KeyEventArgs eKeyArgs)
58+
public InputConfig(int nFlags, byte byVirtualKey, KeyEventArgs eKeyArgs)
5359
{
54-
Flags = byFlags;
60+
Flags = nFlags;
5561
VirtualKey = byVirtualKey;
5662

5763
if (null != eKeyArgs)
5864
{
5965
#warning this is weird to have the flags further defined/or'd with the pkey args (likely only applied to outputs)
60-
Flags |= (byte)(
61-
(eKeyArgs.Shift ? (byte)InputFlag.Shift : (byte)0) |
62-
(eKeyArgs.Alt ? (byte)InputFlag.Alt : (byte)0) |
63-
(eKeyArgs.Control ? (byte)InputFlag.Control : (byte)0));
66+
Flags |= (int)(
67+
(eKeyArgs.Shift ? (int)InputFlag.Shift : (byte)0) |
68+
(eKeyArgs.Alt ? (int)InputFlag.Alt : (byte)0) |
69+
(eKeyArgs.Control ? (int)InputFlag.Control : (byte)0));
6470
}
6571
}
6672

Format/OutputConfig.cs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
using System.IO;
2626
using System.Windows.Forms;
27+
using Support.UI;
2728

2829
namespace KeyCap.Format
2930
{
@@ -32,6 +33,12 @@ namespace KeyCap.Format
3233
/// </summary>
3334
public class OutputConfig : BaseIOConfig
3435
{
36+
/// <summary>
37+
/// Copy constructor
38+
/// </summary>
39+
/// <param name="config"></param>
40+
public OutputConfig(OutputConfig config) : base(config) { }
41+
3542
/// <summary>
3643
/// Flags applied to a given input/output key
3744
/// </summary>
@@ -44,8 +51,8 @@ public enum OutputFlag
4451
MouseOut = 1 << 4, // mouse output -- see MouseButton
4552
Delay = 1 << 5,
4653
Toggle = 1 << 6,
47-
TestFlagOne = 1 << 30,
48-
TestFlagTwo = 1 << 31
54+
Down = 1 << 7,
55+
Up = 1 << 8
4956
//MAX = 1 << 32, // it's an int! (aka if you need 32 you'll need more space)
5057
}
5158

@@ -107,6 +114,7 @@ public override string GetDescription()
107114
{
108115
return "[" +
109116
(MouseButton)VirtualKey +
117+
getOutputDescriptionText("Mouse") +
110118
(IsFlaggedAs(OutputFlag.Toggle) ? "+Toggle" : string.Empty) +
111119
"]";
112120
}
@@ -119,11 +127,21 @@ public override string GetDescription()
119127
// keyboard
120128
return "[" +
121129
(Keys)VirtualKey +
130+
getOutputDescriptionText("Key") +
122131
(IsFlaggedAs(OutputFlag.Shift) ? "+Shift" : string.Empty) +
123132
(IsFlaggedAs(OutputFlag.Alt) ? "+Alt" : string.Empty) +
124133
(IsFlaggedAs(OutputFlag.Control) ? "+Control" : string.Empty)+
125134
(IsFlaggedAs(OutputFlag.Toggle) ? "+Toggle" : string.Empty) +
126135
"]";
127136
}
137+
138+
private string getOutputDescriptionText(string sPrefix)
139+
{
140+
return (IsFlaggedAs(OutputFlag.Down) && IsFlaggedAs(OutputFlag.Up)
141+
? ":Press"
142+
: ((IsFlaggedAs(OutputFlag.Down) ? ":{0}Down".FormatString(sPrefix) : string.Empty) +
143+
(IsFlaggedAs(OutputFlag.Up) ? ":{0}Up".FormatString(sPrefix) : string.Empty))
144+
);
145+
}
128146
}
129147
}

Forms/KeyCaptureConfig.cs

Lines changed: 51 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,17 @@ private void KeyCaptureConfig_Load(object sender, EventArgs e)
8282
IniManager.RestoreState(this, m_zIniManager.GetValue(Name));
8383

8484
// setup the various mouse output options
85-
comboBoxMouseOut.Items.Add("No Action");
85+
comboBoxOutMouse.Items.Add("No Action");
8686
foreach (OutputConfig.MouseButton sName in Enum.GetValues(typeof(OutputConfig.MouseButton)))
8787
{
88-
comboBoxMouseOut.Items.Add(sName);
88+
comboBoxOutMouse.Items.Add(sName);
8989
}
90-
comboBoxMouseOut.SelectedIndex = 0;
90+
comboBoxOutMouse.SelectedIndex = 0;
91+
92+
// toggle: mouse buttons, Key
93+
// action: mouse buttons down/up, Key down/up
94+
95+
9196

9297
// set the notification icon accordingly
9398
notifyIcon.Icon = Resources.KeyCapIdle;
@@ -106,8 +111,10 @@ private void KeyCaptureConfig_Load(object sender, EventArgs e)
106111
// initialize capture from command line specified file
107112
if (0 != m_sLoadedFile.Length)
108113
{
114+
#if false
109115
btnStart_Click(sender, new EventArgs());
110116
new Thread(MinimizeThread) { Name = "MinimizeThread" }.Start();
117+
#endif
111118
}
112119
}
113120

@@ -183,9 +190,9 @@ private void KeyCaptureConfig_Resize(object sender, EventArgs e)
183190
}
184191
}
185192

186-
#endregion
193+
#endregion
187194

188-
#region Text Capture Handling
195+
#region Text Capture Handling
189196

190197
#warning Need to make an input and output version of this
191198
private void txtKeyIn_KeyDown(object sender, KeyEventArgs e)
@@ -217,9 +224,9 @@ private void txtKey_Leave(object sender, EventArgs e)
217224
((TextBox)sender).BackColor = SystemColors.Control;
218225
}
219226

220-
#endregion
227+
#endregion
221228

222-
#region AbstractDirtyForm overrides
229+
#region AbstractDirtyForm overrides
223230

224231
protected override bool SaveFormData(string sFileName)
225232
{
@@ -260,9 +267,9 @@ protected override bool OpenFormData(string sFileName)
260267
return true;
261268
}
262269

263-
#endregion
270+
#endregion
264271

265-
#region Menu Events
272+
#region Menu Events
266273

267274
private void loadToolStripMenuItem_Click(object sender, EventArgs e)
268275
{
@@ -301,9 +308,9 @@ private void recentConfiguration_Click(object sender, EventArgs e)
301308
InitOpen(zItem.Text);
302309
}
303310

304-
#endregion
311+
#endregion
305312

306-
#region Control Events
313+
#region Control Events
307314

308315
private void listViewKeys_SelectedIndexChanged(object sender, EventArgs e)
309316
{
@@ -317,13 +324,13 @@ private void listViewKeys_Resize(object sender, EventArgs e)
317324
ListViewAssist.ResizeColumnHeaders(listViewKeys);
318325
}
319326

320-
private void comboBoxSpecialOut_SelectedIndexChanged(object sender, EventArgs e)
327+
private void comboBoxMouseOut_SelectedIndexChanged(object sender, EventArgs e)
321328
{
322-
if (0 != comboBoxMouseOut.SelectedIndex) // the first entry does nothing
329+
if (0 != comboBoxOutMouse.SelectedIndex) // the first entry does nothing
323330
{
324331
var zOutputConfig = new OutputConfig(
325332
(byte)OutputConfig.OutputFlag.MouseOut,
326-
(byte)(OutputConfig.MouseButton)comboBoxMouseOut.SelectedItem);
333+
(byte)(OutputConfig.MouseButton)comboBoxOutMouse.SelectedItem);
327334
var zDisplay = txtKeyOut;
328335
zDisplay.Text = zOutputConfig.GetDescription();
329336
zDisplay.Tag = zOutputConfig;
@@ -343,7 +350,7 @@ private void numericUpDownDelay_ValueChanged(object sender, EventArgs e)
343350

344351
private void btnAdd_Click(object sender, EventArgs e)
345352
{
346-
var zInput = (InputConfig)txtKeyIn.Tag;
353+
var zInput = new InputConfig((InputConfig)txtKeyIn.Tag);
347354
var zOutput = getCurrentOutputDefinition();
348355

349356
if (null == zInput || null == zOutput)
@@ -357,6 +364,7 @@ private void btnAdd_Click(object sender, EventArgs e)
357364
var zPairDef = new RemapEntry(zInput, zOutput);
358365

359366
// TODO: is it worth keeping a hashset of these to cut the time from o(n) to o(1)?
367+
// TODO: validation method for this (also need to check that an output actually does something (unless do nothing is selected)
360368
// verify this is not already defined
361369
foreach (ListViewItem zListItem in listViewKeys.Items)
362370
{
@@ -420,12 +428,13 @@ private void btnAppend_Click(object sender, EventArgs e)
420428

421429
private OutputConfig getCurrentOutputDefinition()
422430
{
423-
var zOutput = (OutputConfig)txtKeyOut.Tag;
431+
var zOutput = new OutputConfig((OutputConfig)txtKeyOut.Tag);
424432
if (zOutput == null)
425433
{
426434
return null;
427435
}
428436

437+
#warning Is this necessary? Why not just let the do nothing flag override?
429438
if (checkOutputNone.Checked) // if output is set to none change zOutput keyarg
430439
{
431440
zOutput = new OutputConfig((byte)OutputConfig.OutputFlag.DoNothing, 0x00);
@@ -472,9 +481,9 @@ private void btnStart_Click(object sender, EventArgs e)
472481
}
473482
}
474483

475-
#endregion
484+
#endregion
476485

477-
#region Support Methods
486+
#region Support Methods
478487

479488
/// <summary>
480489
/// Updates the recent loaded file list
@@ -519,8 +528,10 @@ private void UpdateOutputFlags(OutputConfig zOutputConfig)
519528
var bShift = checkOutputShift.Checked;
520529
var bNone = checkOutputNone.Checked;
521530
var bToggle = checkOutputToggle.Checked;
531+
var bDown = checkOutputDown.Checked;
532+
var bUp = checkOutputUp.Checked;
522533

523-
int nFlags = 0;
534+
var nFlags = 0;
524535
#warning Make a new method on the config object to update the flag on a field and eliminate this copy+paste garbage
525536
nFlags = BitUtil.UpdateFlag(nFlags, bShift, OutputConfig.OutputFlag.Shift);
526537
nFlags = BitUtil.UpdateFlag(nFlags, bControl, OutputConfig.OutputFlag.Control);
@@ -531,6 +542,8 @@ private void UpdateOutputFlags(OutputConfig zOutputConfig)
531542

532543
nFlags = BitUtil.UpdateFlag(nFlags, bNone, OutputConfig.OutputFlag.DoNothing);
533544
nFlags = BitUtil.UpdateFlag(nFlags, bToggle, OutputConfig.OutputFlag.Toggle);
545+
nFlags = BitUtil.UpdateFlag(nFlags, bDown, OutputConfig.OutputFlag.Down);
546+
nFlags = BitUtil.UpdateFlag(nFlags, bUp, OutputConfig.OutputFlag.Up);
534547
zOutputConfig.Flags = nFlags;
535548
}
536549

@@ -559,5 +572,24 @@ private void MinimizeThread()
559572
}
560573

561574
#endregion
575+
576+
private void checkOutputToggle_CheckedChanged(object sender, EventArgs e)
577+
{
578+
checkOutputUp.Checked = checkOutputToggle.Checked;
579+
checkOutputDown.Checked = checkOutputToggle.Checked;
580+
checkOutputUp.Enabled = !checkOutputToggle.Checked;
581+
checkOutputDown.Enabled = !checkOutputToggle.Checked;
582+
}
583+
584+
private void checkOutputNone_CheckedChanged(object sender, EventArgs e)
585+
{
586+
comboBoxOutMouse.Enabled = !checkOutputNone.Checked;
587+
checkOutputAlt.Enabled = !checkOutputNone.Checked;
588+
checkOutputShift.Enabled = !checkOutputNone.Checked;
589+
checkOutputControl.Enabled = !checkOutputNone.Checked;
590+
checkOutputUp.Enabled = !checkOutputNone.Checked;
591+
checkOutputDown.Enabled = !checkOutputNone.Checked;
592+
checkOutputToggle.Enabled = !checkOutputNone.Checked;
593+
}
562594
}
563595
}

0 commit comments

Comments
 (0)