Skip to content

Commit

Permalink
Input Widget - use SysColors.Window when exiting the widget, not SysC…
Browse files Browse the repository at this point in the history
…olors.Control, also clean up some code in that file while I'm at it
  • Loading branch information
adelikat committed Nov 27, 2013
1 parent c353af5 commit ad39eb3
Showing 1 changed file with 43 additions and 68 deletions.
111 changes: 43 additions & 68 deletions BizHawk.Client.EmuHawk/config/InputWidget.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
using System;
using System.Drawing;
using System.Linq;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Text;

namespace BizHawk.Client.EmuHawk
{
public class InputWidget : TextBox
public sealed class InputWidget : TextBox
{
//TODO: when binding, make sure that the new key combo is not in one of the other bindings

private int MaxBind = 4; //Max number of bindings allowed
private int pos = 0; //Which mapping the widget will listen for
private Timer timer = new Timer();
private string[] _bindings = new string[4];
private string wasPressed = String.Empty;
private ToolTip tooltip1 = new ToolTip();
private readonly int _maxBind = 4; //Max number of bindings allowed
private int _pos; //Which mapping the widget will listen for
private readonly Timer _timer = new Timer();
private readonly string[] _bindings = new string[4];
private string _wasPressed = String.Empty;
private readonly ToolTip _tooltip1 = new ToolTip();

public bool AutoTab = true;
public string WidgetName;
Expand All @@ -27,51 +25,51 @@ public class InputWidget : TextBox

public InputWidget()
{
this.ContextMenu = new ContextMenu();
this.timer.Tick += new System.EventHandler(this.Timer_Tick);
ContextMenu = new ContextMenu();
_timer.Tick += Timer_Tick;
ClearBindings();
tooltip1.AutoPopDelay = 2000;
_tooltip1.AutoPopDelay = 2000;
}

public InputWidget(int maxBindings, bool autotab)
{
this.AutoTab = autotab;
this.ContextMenu = new ContextMenu();
this.timer.Tick += new System.EventHandler(this.Timer_Tick);
MaxBind = maxBindings;
_bindings = new string[MaxBind];
AutoTab = autotab;
ContextMenu = new ContextMenu();
_timer.Tick += Timer_Tick;
_maxBind = maxBindings;
_bindings = new string[_maxBind];
ClearBindings();
tooltip1.AutoPopDelay = 2000;
_tooltip1.AutoPopDelay = 2000;
}

protected override void OnMouseClick(MouseEventArgs e)
{
HideCaret(this.Handle);
HideCaret(Handle);
base.OnMouseClick(e);
}

private void ClearBindings()
{
for (int i = 0; i < MaxBind; i++)
for (int i = 0; i < _maxBind; i++)
{
_bindings[i] = String.Empty;
}
}

protected override void OnEnter(EventArgs e)
{
pos = 0;
timer.Start();
_pos = 0;
_timer.Start();

wasPressed = Input.Instance.GetNextBindEvent();
_wasPressed = Input.Instance.GetNextBindEvent();
BackColor = Color.LightCyan;
}

protected override void OnLeave(EventArgs e)
{
timer.Stop();
_timer.Stop();
UpdateLabel();
BackColor = SystemColors.Control;
BackColor = SystemColors.Window;
base.OnLeave(e);

}
Expand All @@ -90,8 +88,8 @@ public void EraseMappings()
private void ReadKeys()
{
Input.Instance.Update();
string TempBindingStr = Input.Instance.GetNextBindEvent();
if (!String.IsNullOrEmpty(wasPressed) && TempBindingStr == wasPressed)
var TempBindingStr = Input.Instance.GetNextBindEvent();
if (!String.IsNullOrEmpty(_wasPressed) && TempBindingStr == _wasPressed)
{
return;
}
Expand All @@ -110,9 +108,9 @@ private void ReadKeys()

if (!IsDuplicate(TempBindingStr))
{
_bindings[pos] = TempBindingStr;
_bindings[_pos] = TempBindingStr;
}
wasPressed = TempBindingStr;
_wasPressed = TempBindingStr;

UpdateLabel();
Increment();
Expand All @@ -131,7 +129,7 @@ protected override void OnKeyUp(KeyEventArgs e)
base.OnKeyUp(e);
}

wasPressed = String.Empty;
_wasPressed = String.Empty;
}

protected override void OnKeyDown(KeyEventArgs e)
Expand All @@ -150,17 +148,17 @@ public void Increment()
{
if (AutoTab)
{
this.Parent.SelectNextControl(this, true, true, true, true);
Parent.SelectNextControl(this, true, true, true, true);
}
else
{
if (pos < MaxBind)
if (_pos < _maxBind)
{
pos++;
_pos++;
}
else
{
pos = 0;
_pos = 0;
}
}
}
Expand All @@ -169,17 +167,17 @@ public void Decrement()
{
if (AutoTab)
{
this.Parent.SelectNextControl(this, false, true, true, true);
Parent.SelectNextControl(this, false, true, true, true);
}
else
{
if (pos == 0)
if (_pos == 0)
{
pos = MaxBind - 1;
_pos = _maxBind - 1;
}
else
{
pos--;
_pos--;
}
}
}
Expand All @@ -197,26 +195,15 @@ public string Bindings
}
set
{
Text = String.Empty;
ClearBindings();
string str = value.Trim();
int x;
for (int i = 0; i < MaxBind; i++)
var newBindings = value.Trim().Split(',');
for (int i = 0; i < _maxBind; i++)
{
str = str.Trim();
x = str.IndexOf(',');
if (x < 0)
if (i < newBindings.Length)
{
_bindings[i] = str;
str = String.Empty;
}
else
{
_bindings[i] = str.Substring(0, x);
str = str.Substring(x + 1, str.Length - x - 1);
_bindings[i] = newBindings[i];
}
}

UpdateLabel();
}
}
Expand All @@ -232,13 +219,9 @@ protected override void WndProc(ref Message m)
{
case 0x0201: //WM_LBUTTONDOWN
{
this.Focus();
Focus();
return;
}
//case 0x0202://WM_LBUTTONUP
//{
// return;
//}
case 0x0203://WM_LBUTTONDBLCLK
{
return;
Expand Down Expand Up @@ -275,20 +258,12 @@ protected override void OnMouseWheel(MouseEventArgs e)

protected override void OnGotFocus(EventArgs e)
{
HideCaret(this.Handle);
}

protected override void OnLostFocus(EventArgs e)
{
base.OnLostFocus(e);
HideCaret(Handle);
}

protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
if (keyData.ToString() == "F4" || keyData.ToString().Contains("Alt"))
return false;
else
return true;
return !(keyData.ToString() == "F4" || keyData.ToString().Contains("Alt"));
}
}
}

0 comments on commit ad39eb3

Please sign in to comment.