2011-02-16 16:35:51 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
2014-07-03 16:00:57 +00:00
|
|
|
|
using BizHawk.Common.StringExtensions;
|
2013-10-25 00:57:23 +00:00
|
|
|
|
|
2013-11-03 03:54:37 +00:00
|
|
|
|
namespace BizHawk.Client.EmuHawk
|
2011-02-16 16:35:51 +00:00
|
|
|
|
{
|
2012-06-09 22:04:09 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// A simple form that prompts the user for a single line of input
|
|
|
|
|
/// </summary>
|
|
|
|
|
public partial class InputPrompt : Form
|
|
|
|
|
{
|
|
|
|
|
public InputPrompt()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2014-02-25 02:56:32 +00:00
|
|
|
|
StartLocation = new Point(-1, -1);
|
2012-06-09 22:04:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-02-25 02:56:32 +00:00
|
|
|
|
public enum InputType { Hex, Unsigned, Signed, Text }
|
2014-07-28 02:40:30 +00:00
|
|
|
|
|
2014-02-25 02:56:32 +00:00
|
|
|
|
public Point StartLocation { get; set; }
|
|
|
|
|
public InputType TextInputType { get; set; }
|
|
|
|
|
|
2014-07-28 02:40:30 +00:00
|
|
|
|
public string Message
|
2012-06-09 22:04:09 +00:00
|
|
|
|
{
|
2014-07-28 02:40:30 +00:00
|
|
|
|
get { return PromptLabel.Text; }
|
|
|
|
|
set { PromptLabel.Text = value ?? string.Empty; }
|
2012-06-09 22:04:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-07-28 02:40:30 +00:00
|
|
|
|
public string InitialValue
|
2012-06-09 22:45:24 +00:00
|
|
|
|
{
|
2014-07-28 02:40:30 +00:00
|
|
|
|
get { return PromptBox.Text; }
|
|
|
|
|
set { PromptBox.Text = value ?? string.Empty; }
|
2012-06-09 22:45:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-07-28 02:40:30 +00:00
|
|
|
|
public string PromptText
|
2012-08-17 03:04:35 +00:00
|
|
|
|
{
|
2014-07-28 02:40:30 +00:00
|
|
|
|
get { return PromptBox.Text ?? string.Empty; }
|
2012-08-17 03:04:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-06-09 22:04:09 +00:00
|
|
|
|
private void InputPrompt_Load(object sender, EventArgs e)
|
|
|
|
|
{
|
2014-02-25 02:56:32 +00:00
|
|
|
|
if (StartLocation.X > 0 && StartLocation.Y > 0)
|
2012-10-02 03:16:28 +00:00
|
|
|
|
{
|
2014-02-25 02:56:32 +00:00
|
|
|
|
Location = StartLocation;
|
2012-10-02 03:16:28 +00:00
|
|
|
|
}
|
2012-06-09 22:04:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-02-25 02:56:32 +00:00
|
|
|
|
private void Ok_Click(object sender, EventArgs e)
|
2012-06-09 22:04:09 +00:00
|
|
|
|
{
|
2014-07-15 23:43:17 +00:00
|
|
|
|
DialogResult = DialogResult.OK;
|
2013-04-14 23:56:45 +00:00
|
|
|
|
Close();
|
2012-06-09 22:04:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Cancel_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2014-07-15 23:43:17 +00:00
|
|
|
|
DialogResult = DialogResult.Cancel;
|
2013-04-14 23:56:45 +00:00
|
|
|
|
Close();
|
2012-06-09 22:04:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void PromptBox_KeyPress(object sender, KeyPressEventArgs e)
|
|
|
|
|
{
|
2014-02-25 02:56:32 +00:00
|
|
|
|
switch (TextInputType)
|
2012-06-09 22:04:09 +00:00
|
|
|
|
{
|
2012-08-17 03:04:35 +00:00
|
|
|
|
default:
|
2014-02-25 02:56:32 +00:00
|
|
|
|
case InputType.Text:
|
2012-08-17 03:04:35 +00:00
|
|
|
|
break;
|
2014-02-25 02:56:32 +00:00
|
|
|
|
case InputType.Hex:
|
2012-09-30 13:38:37 +00:00
|
|
|
|
if (e.KeyChar == '\b' || e.KeyChar == 22 || e.KeyChar == 1 || e.KeyChar == 3)
|
2012-08-17 03:04:35 +00:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2014-02-25 02:56:32 +00:00
|
|
|
|
|
2014-07-03 16:00:57 +00:00
|
|
|
|
if (!e.KeyChar.IsHex())
|
2012-08-17 03:04:35 +00:00
|
|
|
|
{
|
|
|
|
|
e.Handled = true;
|
|
|
|
|
}
|
2014-02-25 02:56:32 +00:00
|
|
|
|
|
2012-08-17 03:04:35 +00:00
|
|
|
|
break;
|
2014-02-25 02:56:32 +00:00
|
|
|
|
case InputType.Signed:
|
2012-09-30 13:38:37 +00:00
|
|
|
|
if (e.KeyChar == '\b' || e.KeyChar == 22 || e.KeyChar == 1 || e.KeyChar == 3)
|
2012-08-17 03:04:35 +00:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2014-02-25 02:56:32 +00:00
|
|
|
|
|
2015-07-25 08:20:16 +00:00
|
|
|
|
if (!e.KeyChar.IsSigned())
|
2012-08-17 03:04:35 +00:00
|
|
|
|
{
|
|
|
|
|
e.Handled = true;
|
|
|
|
|
}
|
2014-02-25 02:56:32 +00:00
|
|
|
|
|
2012-08-17 03:04:35 +00:00
|
|
|
|
break;
|
2014-02-25 02:56:32 +00:00
|
|
|
|
case InputType.Unsigned:
|
2012-09-30 13:38:37 +00:00
|
|
|
|
if (e.KeyChar == '\b' || e.KeyChar == 22 || e.KeyChar == 1 || e.KeyChar == 3)
|
2012-08-17 03:04:35 +00:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2015-07-25 08:20:16 +00:00
|
|
|
|
|
|
|
|
|
if (!e.KeyChar.IsUnsigned())
|
2012-08-17 03:04:35 +00:00
|
|
|
|
{
|
|
|
|
|
e.Handled = true;
|
|
|
|
|
}
|
2014-02-25 02:56:32 +00:00
|
|
|
|
|
2012-08-17 03:04:35 +00:00
|
|
|
|
break;
|
2012-06-09 22:04:09 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-02-16 16:35:51 +00:00
|
|
|
|
}
|