2011-01-30 23:06:43 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Drawing;
|
2013-08-04 20:21:58 +00:00
|
|
|
|
using System.Linq;
|
2011-01-30 23:06:43 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Windows.Forms;
|
2011-07-09 21:55:14 +00:00
|
|
|
|
using System.Runtime.InteropServices;
|
2012-09-10 17:49:33 +00:00
|
|
|
|
using System.Text;
|
2011-01-30 23:06:43 +00:00
|
|
|
|
|
|
|
|
|
namespace BizHawk.MultiClient
|
|
|
|
|
{
|
2011-06-19 02:17:27 +00:00
|
|
|
|
public class InputWidget : TextBox
|
|
|
|
|
{
|
2011-07-09 17:50:52 +00:00
|
|
|
|
//TODO: when binding, make sure that the new key combo is not in one of the other bindings
|
|
|
|
|
|
2013-08-04 20:21:58 +00:00
|
|
|
|
private int MaxBind = 4; //Max number of bindings allowed
|
|
|
|
|
private int pos = 0; //Which mapping the widget will listen for
|
2011-07-09 16:12:56 +00:00
|
|
|
|
private Timer timer = new Timer();
|
2013-08-04 20:21:58 +00:00
|
|
|
|
private string[] _bindings = new string[4];
|
|
|
|
|
private string wasPressed = "";
|
|
|
|
|
private ToolTip tooltip1 = new ToolTip();
|
|
|
|
|
private Color _highlight_color = Color.LightCyan;
|
|
|
|
|
private Color _no_highlight_color = SystemColors.Window;
|
|
|
|
|
private bool conflicted = false;
|
|
|
|
|
|
2011-07-09 16:12:56 +00:00
|
|
|
|
public bool AutoTab = true;
|
2013-08-04 16:47:54 +00:00
|
|
|
|
public string WidgetName;
|
2012-09-10 17:49:33 +00:00
|
|
|
|
|
2012-12-04 21:47:07 +00:00
|
|
|
|
public bool Conflicted
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return conflicted;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
conflicted = value;
|
|
|
|
|
if (conflicted)
|
|
|
|
|
{
|
|
|
|
|
_no_highlight_color = Color.LightCoral;
|
|
|
|
|
_highlight_color = Color.Violet;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_highlight_color = Color.LightCyan;
|
|
|
|
|
_no_highlight_color = SystemColors.Window;
|
|
|
|
|
}
|
2012-12-04 23:12:04 +00:00
|
|
|
|
|
|
|
|
|
if (Focused)
|
|
|
|
|
{
|
|
|
|
|
Highlight();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
UnHighlight();
|
|
|
|
|
}
|
2012-12-04 21:47:07 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-10 17:49:33 +00:00
|
|
|
|
private void Highlight()
|
|
|
|
|
{
|
|
|
|
|
BackColor = _highlight_color;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UnHighlight()
|
|
|
|
|
{
|
|
|
|
|
BackColor = _no_highlight_color;
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-09 21:55:14 +00:00
|
|
|
|
[DllImport("user32")]
|
|
|
|
|
private static extern bool HideCaret(IntPtr hWnd);
|
|
|
|
|
|
2011-07-09 16:12:56 +00:00
|
|
|
|
public InputWidget()
|
2011-06-19 02:17:27 +00:00
|
|
|
|
{
|
|
|
|
|
this.ContextMenu = new ContextMenu();
|
2011-07-09 16:12:56 +00:00
|
|
|
|
this.timer.Tick += new System.EventHandler(this.Timer_Tick);
|
2013-08-04 20:21:58 +00:00
|
|
|
|
_clearBindings();
|
2011-07-09 23:03:42 +00:00
|
|
|
|
tooltip1.AutoPopDelay = 2000;
|
2011-06-19 02:17:27 +00:00
|
|
|
|
}
|
2011-01-30 23:06:43 +00:00
|
|
|
|
|
2013-07-28 21:54:42 +00:00
|
|
|
|
public InputWidget(int maxBindings, bool autotab)
|
2011-07-09 23:03:42 +00:00
|
|
|
|
{
|
2013-07-28 21:54:42 +00:00
|
|
|
|
this.AutoTab = autotab;
|
2012-09-10 17:49:33 +00:00
|
|
|
|
this.ContextMenu = new ContextMenu();
|
|
|
|
|
this.timer.Tick += new System.EventHandler(this.Timer_Tick);
|
|
|
|
|
MaxBind = maxBindings;
|
2013-08-04 20:21:58 +00:00
|
|
|
|
_bindings = new string[MaxBind];
|
|
|
|
|
_clearBindings();
|
2012-09-10 17:49:33 +00:00
|
|
|
|
tooltip1.AutoPopDelay = 2000;
|
2011-07-09 23:03:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnMouseClick(MouseEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
HideCaret(this.Handle);
|
|
|
|
|
base.OnMouseClick(e);
|
2011-07-09 16:12:56 +00:00
|
|
|
|
}
|
2011-01-30 23:06:43 +00:00
|
|
|
|
|
2013-08-04 20:21:58 +00:00
|
|
|
|
private void _clearBindings()
|
2011-07-09 16:12:56 +00:00
|
|
|
|
{
|
2013-08-04 20:21:58 +00:00
|
|
|
|
for (int i = 0; i < MaxBind; i++)
|
2011-07-09 16:12:56 +00:00
|
|
|
|
{
|
2013-08-04 20:21:58 +00:00
|
|
|
|
_bindings[i] = "";
|
2011-07-09 16:12:56 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2011-07-07 16:48:29 +00:00
|
|
|
|
|
2011-07-09 16:12:56 +00:00
|
|
|
|
protected override void OnEnter(EventArgs e)
|
|
|
|
|
{
|
2011-07-09 17:50:52 +00:00
|
|
|
|
pos = 0;
|
2011-07-09 16:12:56 +00:00
|
|
|
|
timer.Start();
|
2011-07-09 22:09:39 +00:00
|
|
|
|
//Input.Update();
|
|
|
|
|
|
|
|
|
|
//zero: ??? what is this all about ???
|
2012-11-09 20:03:59 +00:00
|
|
|
|
wasPressed = Input.Instance.GetNextBindEvent();
|
2011-07-09 16:12:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnLeave(EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
timer.Stop();
|
|
|
|
|
UpdateLabel();
|
|
|
|
|
base.OnLeave(e);
|
|
|
|
|
}
|
2011-07-07 16:48:29 +00:00
|
|
|
|
|
2011-07-09 16:12:56 +00:00
|
|
|
|
private void Timer_Tick(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
ReadKeys();
|
|
|
|
|
}
|
2011-07-07 16:48:29 +00:00
|
|
|
|
|
2012-09-17 22:43:42 +00:00
|
|
|
|
public void EraseMappings()
|
|
|
|
|
{
|
2013-08-04 20:21:58 +00:00
|
|
|
|
_clearBindings();
|
2013-07-29 20:18:38 +00:00
|
|
|
|
Conflicted = false;
|
2012-09-17 22:43:42 +00:00
|
|
|
|
Text = "";
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-09 16:12:56 +00:00
|
|
|
|
private void ReadKeys()
|
2011-06-19 02:17:27 +00:00
|
|
|
|
{
|
2011-07-09 22:09:39 +00:00
|
|
|
|
Input.Instance.Update();
|
2012-11-09 20:03:59 +00:00
|
|
|
|
string TempBindingStr = Input.Instance.GetNextBindEvent();
|
2012-10-01 01:55:08 +00:00
|
|
|
|
if (wasPressed != "" && TempBindingStr == wasPressed)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
else if (TempBindingStr != null)
|
2011-06-19 02:17:27 +00:00
|
|
|
|
{
|
2011-07-09 16:12:56 +00:00
|
|
|
|
if (TempBindingStr == "Escape")
|
|
|
|
|
{
|
2013-08-04 20:21:58 +00:00
|
|
|
|
_clearBindings();
|
2013-07-29 20:18:38 +00:00
|
|
|
|
Conflicted = false;
|
2011-07-09 16:12:56 +00:00
|
|
|
|
Increment();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (TempBindingStr == "Alt+F4")
|
|
|
|
|
return;
|
|
|
|
|
|
2011-07-09 18:24:53 +00:00
|
|
|
|
if (!IsDuplicate(TempBindingStr))
|
|
|
|
|
{
|
2013-08-04 20:21:58 +00:00
|
|
|
|
_bindings[pos] = TempBindingStr;
|
2011-07-09 18:24:53 +00:00
|
|
|
|
}
|
2011-07-09 21:55:14 +00:00
|
|
|
|
wasPressed = TempBindingStr;
|
2012-09-10 17:49:33 +00:00
|
|
|
|
|
2011-07-09 21:55:14 +00:00
|
|
|
|
UpdateLabel();
|
|
|
|
|
Increment();
|
2011-07-09 18:24:53 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-10 17:49:33 +00:00
|
|
|
|
//Checks if the key is already mapped to this widget
|
|
|
|
|
private bool IsDuplicate(string binding)
|
2011-07-09 18:24:53 +00:00
|
|
|
|
{
|
2013-08-04 20:21:58 +00:00
|
|
|
|
return _bindings.FirstOrDefault(x => x == binding) != null;
|
2011-07-09 16:12:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnKeyUp(KeyEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (e.KeyCode == Keys.F4 && e.Modifiers == Keys.Alt)
|
2011-06-19 02:17:27 +00:00
|
|
|
|
{
|
2011-07-09 16:12:56 +00:00
|
|
|
|
base.OnKeyUp(e);
|
2011-06-19 02:17:27 +00:00
|
|
|
|
}
|
2011-07-09 16:12:56 +00:00
|
|
|
|
wasPressed = "";
|
2011-06-19 02:17:27 +00:00
|
|
|
|
}
|
2011-01-30 23:06:43 +00:00
|
|
|
|
|
2011-06-19 02:17:27 +00:00
|
|
|
|
protected override void OnKeyDown(KeyEventArgs e)
|
|
|
|
|
{
|
2011-07-09 16:12:56 +00:00
|
|
|
|
if (e.KeyCode == Keys.F4 && e.Modifiers == Keys.Alt)
|
2011-06-19 02:17:27 +00:00
|
|
|
|
{
|
2011-07-09 16:12:56 +00:00
|
|
|
|
base.OnKeyDown(e);
|
2012-01-08 23:01:14 +00:00
|
|
|
|
return;
|
2011-06-19 02:17:27 +00:00
|
|
|
|
}
|
2011-07-09 16:12:56 +00:00
|
|
|
|
e.Handled = true;
|
|
|
|
|
}
|
2011-07-05 01:48:48 +00:00
|
|
|
|
|
2011-07-09 16:12:56 +00:00
|
|
|
|
// Advances to the next widget or the next binding depending on the autotab setting
|
2011-07-09 22:22:45 +00:00
|
|
|
|
public void Increment()
|
2011-07-09 16:12:56 +00:00
|
|
|
|
{
|
2011-07-04 23:02:37 +00:00
|
|
|
|
if (AutoTab)
|
|
|
|
|
this.Parent.SelectNextControl(this, true, true, true, true);
|
2011-07-09 17:50:52 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (pos == MaxBind - 1)
|
2011-07-09 22:22:45 +00:00
|
|
|
|
pos = 0;
|
2011-07-09 17:50:52 +00:00
|
|
|
|
else
|
2011-07-09 22:22:45 +00:00
|
|
|
|
pos++;
|
2011-07-23 19:43:08 +00:00
|
|
|
|
UpdateLabel();
|
2011-07-09 22:22:45 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Decrement()
|
|
|
|
|
{
|
|
|
|
|
if (AutoTab)
|
|
|
|
|
this.Parent.SelectNextControl(this, false, true, true, true);
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (pos == 0)
|
|
|
|
|
pos = MaxBind - 1;
|
|
|
|
|
else
|
|
|
|
|
pos--;
|
2011-07-09 17:50:52 +00:00
|
|
|
|
}
|
2011-06-19 02:17:27 +00:00
|
|
|
|
}
|
2011-01-30 23:06:43 +00:00
|
|
|
|
|
2011-07-09 16:12:56 +00:00
|
|
|
|
public void UpdateLabel()
|
|
|
|
|
{
|
|
|
|
|
Text = "";
|
|
|
|
|
for (int x = 0; x < MaxBind; x++)
|
2011-06-19 03:35:57 +00:00
|
|
|
|
{
|
2013-08-04 20:21:58 +00:00
|
|
|
|
if (_bindings[x].Length > 0)
|
2011-06-19 03:35:57 +00:00
|
|
|
|
{
|
2013-08-04 20:21:58 +00:00
|
|
|
|
Text += _bindings[x];
|
|
|
|
|
if (x < MaxBind - 1 && _bindings[x+1].Length > 0)
|
2011-07-09 16:12:56 +00:00
|
|
|
|
Text += ", ";
|
2011-06-19 03:35:57 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2011-07-09 16:12:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-08-04 20:21:58 +00:00
|
|
|
|
public string Bindings
|
2011-07-09 16:12:56 +00:00
|
|
|
|
{
|
2013-08-04 20:21:58 +00:00
|
|
|
|
get
|
2011-06-19 03:35:57 +00:00
|
|
|
|
{
|
2013-08-04 20:21:58 +00:00
|
|
|
|
return Text;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
Text = "";
|
|
|
|
|
_clearBindings();
|
|
|
|
|
string str = value.Trim();
|
|
|
|
|
int x;
|
|
|
|
|
for (int i = 0; i < MaxBind; i++)
|
2011-06-19 03:35:57 +00:00
|
|
|
|
{
|
2013-08-04 20:21:58 +00:00
|
|
|
|
str = str.Trim();
|
|
|
|
|
x = str.IndexOf(',');
|
|
|
|
|
if (x < 0)
|
|
|
|
|
{
|
|
|
|
|
_bindings[i] = str;
|
|
|
|
|
str = "";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_bindings[i] = str.Substring(0, x);
|
|
|
|
|
str = str.Substring(x + 1, str.Length - x - 1);
|
|
|
|
|
}
|
2011-06-19 03:35:57 +00:00
|
|
|
|
}
|
2013-08-04 20:21:58 +00:00
|
|
|
|
|
|
|
|
|
UpdateLabel();
|
2011-06-19 03:35:57 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-06-19 02:17:27 +00:00
|
|
|
|
protected override void OnKeyPress(KeyPressEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
e.Handled = true;
|
|
|
|
|
}
|
2011-01-30 23:06:43 +00:00
|
|
|
|
|
2011-07-09 22:07:13 +00:00
|
|
|
|
protected override void WndProc(ref Message m)
|
|
|
|
|
{
|
|
|
|
|
switch (m.Msg)
|
|
|
|
|
{
|
|
|
|
|
case 0x0201: //WM_LBUTTONDOWN
|
|
|
|
|
{
|
|
|
|
|
this.Focus();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
//case 0x0202://WM_LBUTTONUP
|
|
|
|
|
//{
|
|
|
|
|
// return;
|
|
|
|
|
//}
|
|
|
|
|
case 0x0203://WM_LBUTTONDBLCLK
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
case 0x0204://WM_RBUTTONDOWN
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
case 0x0205://WM_RBUTTONUP
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
case 0x0206://WM_RBUTTONDBLCLK
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
base.WndProc(ref m);
|
2011-07-09 22:22:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnMouseWheel(MouseEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (e.Delta > 0)
|
|
|
|
|
Decrement();
|
|
|
|
|
else
|
|
|
|
|
Increment();
|
|
|
|
|
base.OnMouseWheel(e);
|
|
|
|
|
}
|
2011-07-09 22:07:13 +00:00
|
|
|
|
|
2011-06-19 02:17:27 +00:00
|
|
|
|
protected override void OnGotFocus(EventArgs e)
|
|
|
|
|
{
|
2011-07-09 21:55:14 +00:00
|
|
|
|
//base.OnGotFocus(e);
|
|
|
|
|
HideCaret(this.Handle);
|
2012-09-10 17:49:33 +00:00
|
|
|
|
Highlight();
|
2011-06-19 02:17:27 +00:00
|
|
|
|
}
|
2011-01-30 23:06:43 +00:00
|
|
|
|
|
2011-06-19 02:17:27 +00:00
|
|
|
|
protected override void OnLostFocus(EventArgs e)
|
|
|
|
|
{
|
2012-09-10 17:49:33 +00:00
|
|
|
|
UnHighlight();
|
2011-06-19 02:17:27 +00:00
|
|
|
|
base.OnLostFocus(e);
|
|
|
|
|
}
|
2011-02-23 21:30:11 +00:00
|
|
|
|
|
2011-06-19 02:17:27 +00:00
|
|
|
|
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
|
|
|
|
|
{
|
2012-01-08 23:01:14 +00:00
|
|
|
|
if (keyData.ToString() == "F4" || keyData.ToString().Contains("Alt"))
|
|
|
|
|
return false;
|
|
|
|
|
else
|
|
|
|
|
return true;
|
2011-06-19 02:17:27 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2011-01-30 23:06:43 +00:00
|
|
|
|
}
|