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:
parent
c353af5f82
commit
ad39eb36f4
|
@ -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;
|
||||
|
@ -27,32 +25,32 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
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;
|
||||
}
|
||||
|
@ -60,18 +58,18 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
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);
|
||||
|
||||
}
|
||||
|
@ -90,8 +88,8 @@ namespace BizHawk.Client.EmuHawk
|
|||
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;
|
||||
}
|
||||
|
@ -110,9 +108,9 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
if (!IsDuplicate(TempBindingStr))
|
||||
{
|
||||
_bindings[pos] = TempBindingStr;
|
||||
_bindings[_pos] = TempBindingStr;
|
||||
}
|
||||
wasPressed = TempBindingStr;
|
||||
_wasPressed = TempBindingStr;
|
||||
|
||||
UpdateLabel();
|
||||
Increment();
|
||||
|
@ -131,7 +129,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
base.OnKeyUp(e);
|
||||
}
|
||||
|
||||
wasPressed = String.Empty;
|
||||
_wasPressed = String.Empty;
|
||||
}
|
||||
|
||||
protected override void OnKeyDown(KeyEventArgs e)
|
||||
|
@ -150,17 +148,17 @@ namespace BizHawk.Client.EmuHawk
|
|||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -169,17 +167,17 @@ namespace BizHawk.Client.EmuHawk
|
|||
{
|
||||
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--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -197,26 +195,15 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
@ -232,13 +219,9 @@ namespace BizHawk.Client.EmuHawk
|
|||
{
|
||||
case 0x0201: //WM_LBUTTONDOWN
|
||||
{
|
||||
this.Focus();
|
||||
Focus();
|
||||
return;
|
||||
}
|
||||
//case 0x0202://WM_LBUTTONUP
|
||||
//{
|
||||
// return;
|
||||
//}
|
||||
case 0x0203://WM_LBUTTONDBLCLK
|
||||
{
|
||||
return;
|
||||
|
@ -275,20 +258,12 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
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"));
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue