Input Widget - use SysColors.Window when exiting the widget, not SysColors.Control, also clean up some code in that file while I'm at it

This commit is contained in:
adelikat 2013-11-27 23:52:21 +00:00
parent c353af5f82
commit ad39eb36f4
1 changed files with 43 additions and 68 deletions

View File

@ -1,23 +1,21 @@
using System; using System;
using System.Drawing; using System.Drawing;
using System.Linq; using System.Linq;
using System.Collections.Generic;
using System.Windows.Forms; using System.Windows.Forms;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text;
namespace BizHawk.Client.EmuHawk 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 //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 readonly int _maxBind = 4; //Max number of bindings allowed
private int pos = 0; //Which mapping the widget will listen for private int _pos; //Which mapping the widget will listen for
private Timer timer = new Timer(); private readonly Timer _timer = new Timer();
private string[] _bindings = new string[4]; private readonly string[] _bindings = new string[4];
private string wasPressed = String.Empty; private string _wasPressed = String.Empty;
private ToolTip tooltip1 = new ToolTip(); private readonly ToolTip _tooltip1 = new ToolTip();
public bool AutoTab = true; public bool AutoTab = true;
public string WidgetName; public string WidgetName;
@ -27,32 +25,32 @@ namespace BizHawk.Client.EmuHawk
public InputWidget() public InputWidget()
{ {
this.ContextMenu = new ContextMenu(); ContextMenu = new ContextMenu();
this.timer.Tick += new System.EventHandler(this.Timer_Tick); _timer.Tick += Timer_Tick;
ClearBindings(); ClearBindings();
tooltip1.AutoPopDelay = 2000; _tooltip1.AutoPopDelay = 2000;
} }
public InputWidget(int maxBindings, bool autotab) public InputWidget(int maxBindings, bool autotab)
{ {
this.AutoTab = autotab; AutoTab = autotab;
this.ContextMenu = new ContextMenu(); ContextMenu = new ContextMenu();
this.timer.Tick += new System.EventHandler(this.Timer_Tick); _timer.Tick += Timer_Tick;
MaxBind = maxBindings; _maxBind = maxBindings;
_bindings = new string[MaxBind]; _bindings = new string[_maxBind];
ClearBindings(); ClearBindings();
tooltip1.AutoPopDelay = 2000; _tooltip1.AutoPopDelay = 2000;
} }
protected override void OnMouseClick(MouseEventArgs e) protected override void OnMouseClick(MouseEventArgs e)
{ {
HideCaret(this.Handle); HideCaret(Handle);
base.OnMouseClick(e); base.OnMouseClick(e);
} }
private void ClearBindings() private void ClearBindings()
{ {
for (int i = 0; i < MaxBind; i++) for (int i = 0; i < _maxBind; i++)
{ {
_bindings[i] = String.Empty; _bindings[i] = String.Empty;
} }
@ -60,18 +58,18 @@ namespace BizHawk.Client.EmuHawk
protected override void OnEnter(EventArgs e) protected override void OnEnter(EventArgs e)
{ {
pos = 0; _pos = 0;
timer.Start(); _timer.Start();
wasPressed = Input.Instance.GetNextBindEvent(); _wasPressed = Input.Instance.GetNextBindEvent();
BackColor = Color.LightCyan; BackColor = Color.LightCyan;
} }
protected override void OnLeave(EventArgs e) protected override void OnLeave(EventArgs e)
{ {
timer.Stop(); _timer.Stop();
UpdateLabel(); UpdateLabel();
BackColor = SystemColors.Control; BackColor = SystemColors.Window;
base.OnLeave(e); base.OnLeave(e);
} }
@ -90,8 +88,8 @@ namespace BizHawk.Client.EmuHawk
private void ReadKeys() private void ReadKeys()
{ {
Input.Instance.Update(); Input.Instance.Update();
string TempBindingStr = Input.Instance.GetNextBindEvent(); var TempBindingStr = Input.Instance.GetNextBindEvent();
if (!String.IsNullOrEmpty(wasPressed) && TempBindingStr == wasPressed) if (!String.IsNullOrEmpty(_wasPressed) && TempBindingStr == _wasPressed)
{ {
return; return;
} }
@ -110,9 +108,9 @@ namespace BizHawk.Client.EmuHawk
if (!IsDuplicate(TempBindingStr)) if (!IsDuplicate(TempBindingStr))
{ {
_bindings[pos] = TempBindingStr; _bindings[_pos] = TempBindingStr;
} }
wasPressed = TempBindingStr; _wasPressed = TempBindingStr;
UpdateLabel(); UpdateLabel();
Increment(); Increment();
@ -131,7 +129,7 @@ namespace BizHawk.Client.EmuHawk
base.OnKeyUp(e); base.OnKeyUp(e);
} }
wasPressed = String.Empty; _wasPressed = String.Empty;
} }
protected override void OnKeyDown(KeyEventArgs e) protected override void OnKeyDown(KeyEventArgs e)
@ -150,17 +148,17 @@ namespace BizHawk.Client.EmuHawk
{ {
if (AutoTab) if (AutoTab)
{ {
this.Parent.SelectNextControl(this, true, true, true, true); Parent.SelectNextControl(this, true, true, true, true);
} }
else else
{ {
if (pos < MaxBind) if (_pos < _maxBind)
{ {
pos++; _pos++;
} }
else else
{ {
pos = 0; _pos = 0;
} }
} }
} }
@ -169,17 +167,17 @@ namespace BizHawk.Client.EmuHawk
{ {
if (AutoTab) if (AutoTab)
{ {
this.Parent.SelectNextControl(this, false, true, true, true); Parent.SelectNextControl(this, false, true, true, true);
} }
else else
{ {
if (pos == 0) if (_pos == 0)
{ {
pos = MaxBind - 1; _pos = _maxBind - 1;
} }
else else
{ {
pos--; _pos--;
} }
} }
} }
@ -197,26 +195,15 @@ namespace BizHawk.Client.EmuHawk
} }
set set
{ {
Text = String.Empty;
ClearBindings(); ClearBindings();
string str = value.Trim(); var newBindings = value.Trim().Split(',');
int x; for (int i = 0; i < _maxBind; i++)
for (int i = 0; i < MaxBind; i++)
{ {
str = str.Trim(); if (i < newBindings.Length)
x = str.IndexOf(',');
if (x < 0)
{ {
_bindings[i] = str; _bindings[i] = newBindings[i];
str = String.Empty;
}
else
{
_bindings[i] = str.Substring(0, x);
str = str.Substring(x + 1, str.Length - x - 1);
} }
} }
UpdateLabel(); UpdateLabel();
} }
} }
@ -232,13 +219,9 @@ namespace BizHawk.Client.EmuHawk
{ {
case 0x0201: //WM_LBUTTONDOWN case 0x0201: //WM_LBUTTONDOWN
{ {
this.Focus(); Focus();
return; return;
} }
//case 0x0202://WM_LBUTTONUP
//{
// return;
//}
case 0x0203://WM_LBUTTONDBLCLK case 0x0203://WM_LBUTTONDBLCLK
{ {
return; return;
@ -275,20 +258,12 @@ namespace BizHawk.Client.EmuHawk
protected override void OnGotFocus(EventArgs e) protected override void OnGotFocus(EventArgs e)
{ {
HideCaret(this.Handle); HideCaret(Handle);
}
protected override void OnLostFocus(EventArgs e)
{
base.OnLostFocus(e);
} }
protected override bool ProcessCmdKey(ref Message msg, Keys keyData) protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{ {
if (keyData.ToString() == "F4" || keyData.ToString().Contains("Alt")) return !(keyData.ToString() == "F4" || keyData.ToString().Contains("Alt"));
return false;
else
return true;
} }
} }
} }