2013-04-28 13:56:29 +00:00
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
|
|
|
|
namespace BizHawk.MultiClient
|
|
|
|
|
{
|
2013-05-04 19:04:23 +00:00
|
|
|
|
public sealed class AnalogControlPanel : Panel
|
2013-04-28 13:56:29 +00:00
|
|
|
|
{
|
2013-06-09 23:54:19 +00:00
|
|
|
|
public int X = 0;
|
|
|
|
|
public int Y = 0;
|
2013-05-04 19:04:23 +00:00
|
|
|
|
|
|
|
|
|
private readonly Brush WhiteBrush = Brushes.White;
|
|
|
|
|
private readonly Brush BlackBrush = Brushes.Black;
|
|
|
|
|
private readonly Brush GrayBrush = Brushes.LightGray;
|
|
|
|
|
private readonly Brush RedBrush = Brushes.Red;
|
|
|
|
|
private readonly Brush BlueBrush = Brushes.DarkBlue;
|
|
|
|
|
private readonly Pen _white_pen;
|
|
|
|
|
private readonly Pen BlackPen;
|
|
|
|
|
private readonly Pen GrayPen;
|
|
|
|
|
private readonly Pen RedPen;
|
|
|
|
|
private readonly Pen BluePen;
|
|
|
|
|
|
2013-06-09 23:54:19 +00:00
|
|
|
|
private Bitmap dot = new Bitmap(7, 7);
|
2013-04-28 13:56:29 +00:00
|
|
|
|
|
|
|
|
|
public AnalogControlPanel()
|
|
|
|
|
{
|
2013-05-04 19:04:23 +00:00
|
|
|
|
Size = new Size(129, 129);
|
2013-04-28 13:56:29 +00:00
|
|
|
|
SetStyle(ControlStyles.AllPaintingInWmPaint, true);
|
|
|
|
|
SetStyle(ControlStyles.UserPaint, true);
|
|
|
|
|
SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
|
|
|
|
|
SetStyle(ControlStyles.SupportsTransparentBackColor, true);
|
|
|
|
|
SetStyle(ControlStyles.Opaque, true);
|
2013-05-04 19:04:23 +00:00
|
|
|
|
BackColor = Color.Gray;
|
2013-04-28 13:56:29 +00:00
|
|
|
|
Paint += AnalogControlPanel_Paint;
|
2013-05-04 19:04:23 +00:00
|
|
|
|
MouseClick += Event_MouseClick;
|
|
|
|
|
MouseMove += Event_MouseMove;
|
|
|
|
|
_white_pen = new Pen(WhiteBrush);
|
|
|
|
|
BlackPen = new Pen(BlackBrush);
|
|
|
|
|
GrayPen = new Pen(GrayBrush);
|
|
|
|
|
RedPen = new Pen(RedBrush);
|
|
|
|
|
BluePen = new Pen(BlueBrush);
|
|
|
|
|
BorderStyle = BorderStyle.Fixed3D;
|
2013-06-09 23:54:19 +00:00
|
|
|
|
|
|
|
|
|
// Draw the dot into a bitmap
|
|
|
|
|
Graphics g = Graphics.FromImage(dot);
|
|
|
|
|
g.Clear(Color.Transparent);
|
|
|
|
|
g.FillRectangle(RedBrush, 2, 0, 3, 7);
|
|
|
|
|
g.FillRectangle(RedBrush, 1, 1, 5, 5);
|
|
|
|
|
g.FillRectangle(RedBrush, 0, 2, 7, 3);
|
2013-05-04 19:04:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private int RealToGFX(int val)
|
|
|
|
|
{
|
|
|
|
|
return (val + 128)/2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private int GFXToReal(int val)
|
|
|
|
|
{
|
2013-06-09 23:54:19 +00:00
|
|
|
|
int ret = (val * 2);
|
2013-05-10 23:25:31 +00:00
|
|
|
|
if (ret > 127) ret = 127;
|
|
|
|
|
if (ret < -128) ret = -128;
|
|
|
|
|
return ret;
|
2013-04-28 13:56:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void AnalogControlPanel_Paint(object sender, PaintEventArgs e)
|
|
|
|
|
{
|
2013-05-04 19:04:23 +00:00
|
|
|
|
unchecked
|
|
|
|
|
{
|
|
|
|
|
//Background
|
|
|
|
|
e.Graphics.FillRectangle(GrayBrush, 0, 0, 128, 128);
|
|
|
|
|
e.Graphics.FillEllipse(WhiteBrush, 0, 0, 127, 127);
|
|
|
|
|
e.Graphics.DrawEllipse(BlackPen, 0, 0, 127, 127);
|
2013-06-09 23:54:19 +00:00
|
|
|
|
e.Graphics.DrawLine(BlackPen, 64, 0, 64, 127);
|
|
|
|
|
e.Graphics.DrawLine(BlackPen, 0, 63, 127, 63);
|
2013-05-04 19:04:23 +00:00
|
|
|
|
|
|
|
|
|
//Line
|
2013-06-09 23:54:19 +00:00
|
|
|
|
e.Graphics.DrawLine(BluePen, 64, 63, RealToGFX(X), 127 - RealToGFX(Y));
|
|
|
|
|
e.Graphics.DrawImage(dot, RealToGFX(X) - 3, 127 - RealToGFX(Y) - 3);
|
|
|
|
|
|
2013-05-04 19:04:23 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Event_MouseClick(object sender, MouseEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (e.Button == MouseButtons.Left)
|
|
|
|
|
{
|
2013-06-09 23:54:19 +00:00
|
|
|
|
X = GFXToReal(e.X - 64);
|
|
|
|
|
Y = GFXToReal(-(e.Y - 63));
|
2013-05-04 19:04:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Refresh();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Event_MouseMove(object sender, MouseEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (e.Button == MouseButtons.Left)
|
|
|
|
|
{
|
2013-06-09 23:54:19 +00:00
|
|
|
|
X = GFXToReal(e.X - 64);
|
|
|
|
|
Y = GFXToReal(-(e.Y - 63));
|
2013-05-04 19:04:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Refresh();
|
2013-04-28 13:56:29 +00:00
|
|
|
|
}
|
2013-05-20 01:53:02 +00:00
|
|
|
|
|
|
|
|
|
public void SetPosition(int Xval, int Yval)
|
|
|
|
|
{
|
|
|
|
|
X = Xval;
|
|
|
|
|
Y = Yval;
|
|
|
|
|
|
|
|
|
|
Refresh();
|
|
|
|
|
}
|
2013-08-03 13:22:54 +00:00
|
|
|
|
|
|
|
|
|
public static int Max = 127;
|
|
|
|
|
public static int Min = -127;
|
2013-04-28 13:56:29 +00:00
|
|
|
|
}
|
|
|
|
|
}
|