Lua forms - make lua textboxes that are set to signed/unsigned/hex types increment/decrement with up/down arrows
This commit is contained in:
parent
91063b7ffd
commit
1723f9dc92
BizHawk.Client.EmuHawk/tools/Lua
|
@ -1,5 +1,8 @@
|
|||
using System.Windows.Forms;
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Windows.Forms;
|
||||
|
||||
using BizHawk.Common;
|
||||
using BizHawk.Client.Common;
|
||||
|
||||
namespace BizHawk.Client.EmuHawk
|
||||
|
@ -28,6 +31,109 @@ namespace BizHawk.Client.EmuHawk
|
|||
base.OnKeyPress(e);
|
||||
}
|
||||
|
||||
protected override void OnKeyDown(KeyEventArgs e)
|
||||
{
|
||||
|
||||
if (e.KeyCode == Keys.Up)
|
||||
{
|
||||
switch (_boxType)
|
||||
{
|
||||
default:
|
||||
case BoxType.All:
|
||||
base.OnKeyDown(e);
|
||||
break;
|
||||
case BoxType.Hex:
|
||||
case BoxType.Signed:
|
||||
case BoxType.Unsigned:
|
||||
Increment();
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (e.KeyCode == Keys.Down)
|
||||
{
|
||||
switch (_boxType)
|
||||
{
|
||||
default:
|
||||
case BoxType.All:
|
||||
base.OnKeyDown(e);
|
||||
break;
|
||||
case BoxType.Hex:
|
||||
case BoxType.Signed:
|
||||
case BoxType.Unsigned:
|
||||
Decrement();
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
base.OnKeyDown(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void Increment()
|
||||
{
|
||||
string text = String.IsNullOrWhiteSpace(Text) ? "0" : Text;
|
||||
switch (_boxType)
|
||||
{
|
||||
case BoxType.Hex:
|
||||
var hval = uint.Parse(text, NumberStyles.HexNumber);
|
||||
if (hval < uint.MaxValue)
|
||||
{
|
||||
hval++;
|
||||
Text = hval.ToString("X");
|
||||
}
|
||||
break;
|
||||
case BoxType.Signed:
|
||||
var sval = int.Parse(text);
|
||||
if (sval < int.MaxValue)
|
||||
{
|
||||
sval++;
|
||||
Text = sval.ToString();
|
||||
}
|
||||
break;
|
||||
case BoxType.Unsigned:
|
||||
var uval = uint.Parse(text);
|
||||
if (uval < uint.MaxValue)
|
||||
{
|
||||
uval++;
|
||||
Text = uval.ToString();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void Decrement()
|
||||
{
|
||||
string text = String.IsNullOrWhiteSpace(Text) ? "0" : Text;
|
||||
switch (_boxType)
|
||||
{
|
||||
case BoxType.Hex:
|
||||
var hval = uint.Parse(text, NumberStyles.HexNumber);
|
||||
if (hval < uint.MaxValue)
|
||||
{
|
||||
hval--;
|
||||
Text = hval.ToString("X");
|
||||
}
|
||||
break;
|
||||
case BoxType.Signed:
|
||||
var sval = int.Parse(text);
|
||||
if (sval < int.MaxValue)
|
||||
{
|
||||
sval--;
|
||||
Text = sval.ToString();
|
||||
}
|
||||
break;
|
||||
case BoxType.Unsigned:
|
||||
var uval = uint.Parse(text);
|
||||
if (uval < uint.MaxValue)
|
||||
{
|
||||
uval--;
|
||||
Text = uval.ToString();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void SpecificValueBox_KeyPress(object sender, KeyPressEventArgs e)
|
||||
{
|
||||
if (e.KeyChar == '\b') return;
|
||||
|
|
Loading…
Reference in New Issue