Virtualpad Analog stick - refactor to be variable size instead of a hardcoded 127, Implement Genesis mouse as a 255 analog stick. Note: some positioning bugginess is present in this check in, and probably some things got broken

This commit is contained in:
adelikat 2014-07-06 16:44:50 +00:00
parent 1df9f49f37
commit 2225811743
5 changed files with 53 additions and 22 deletions

View File

@ -68,7 +68,9 @@ namespace BizHawk.Client.EmuHawk
PadBox.Controls.Add(new VirtualPadAnalogStick
{
Name = button.Name,
Location = button.Location
Location = button.Location,
RangeX = button.MaxValue,
RangeY = button.MaxValue // TODO ability to pass in a different Y max
});
break;
case PadSchema.PadInputType.TargetedPair:

View File

@ -44,6 +44,7 @@
//
// XLabel
//
this.XLabel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.XLabel.AutoSize = true;
this.XLabel.Location = new System.Drawing.Point(138, 7);
this.XLabel.Name = "XLabel";
@ -53,6 +54,7 @@
//
// ManualX
//
this.ManualX.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.ManualX.Location = new System.Drawing.Point(156, 3);
this.ManualX.Maximum = new decimal(new int[] {
127,
@ -72,6 +74,7 @@
//
// YLabel
//
this.YLabel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.YLabel.AutoSize = true;
this.YLabel.Location = new System.Drawing.Point(138, 33);
this.YLabel.Name = "YLabel";
@ -81,6 +84,7 @@
//
// ManualY
//
this.ManualY.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.ManualY.Location = new System.Drawing.Point(156, 29);
this.ManualY.Maximum = new decimal(new int[] {
127,
@ -101,6 +105,7 @@
//
// MaxLabel
//
this.MaxLabel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.MaxLabel.AutoSize = true;
this.MaxLabel.Location = new System.Drawing.Point(138, 72);
this.MaxLabel.Name = "MaxLabel";
@ -110,6 +115,7 @@
//
// MaxXNumeric
//
this.MaxXNumeric.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.MaxXNumeric.Location = new System.Drawing.Point(138, 89);
this.MaxXNumeric.Maximum = new decimal(new int[] {
127,
@ -129,6 +135,7 @@
//
// MaxYNumeric
//
this.MaxYNumeric.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.MaxYNumeric.Location = new System.Drawing.Point(138, 112);
this.MaxYNumeric.Maximum = new decimal(new int[] {
127,
@ -149,14 +156,20 @@
//
// AnalogStick
//
this.AnalogStick.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.AnalogStick.BackColor = System.Drawing.Color.Gray;
this.AnalogStick.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.AnalogStick.Location = new System.Drawing.Point(3, 3);
this.AnalogStick.MaxX = 127;
this.AnalogStick.MaxY = 127;
this.AnalogStick.Name = "AnalogStick";
this.AnalogStick.ReadOnly = false;
this.AnalogStick.Size = new System.Drawing.Size(129, 129);
this.AnalogStick.TabIndex = 0;
this.AnalogStick.X = 0;
this.AnalogStick.Y = 0;
this.AnalogStick.MouseDown += new System.Windows.Forms.MouseEventHandler(this.AnalogStick_MouseDown);
this.AnalogStick.MouseMove += new System.Windows.Forms.MouseEventHandler(this.AnalogStick_MouseMove);
//

View File

@ -1,7 +1,9 @@
using System;
using System.Drawing;
using System.Windows.Forms;
using BizHawk.Emulation.Common;
using System.Windows;
namespace BizHawk.Client.EmuHawk
{
@ -13,13 +15,21 @@ namespace BizHawk.Client.EmuHawk
public VirtualPadAnalogStick()
{
InitializeComponent();
RangeX = 127;
RangeY = 127;
}
public int RangeX { get; set; }
public int RangeY { get; set; }
private void VirtualPadAnalogStick_Load(object sender, EventArgs e)
{
this.Size = new System.Drawing.Size(204 + (RangeX - 127), 136 + (RangeY - 127));
AnalogStick.Name = Name;
AnalogStick.XName = Name;
AnalogStick.YName = Name.Replace("X", "Y"); // TODO: allow schema to dictate this but this is a convenient default
AnalogStick.MaxX = RangeX;
AnalogStick.MaxY = RangeY;
ManualX.Minimum = AnalogStick.MinX;
ManualX.Maximum = AnalogStick.MaxX;
@ -27,8 +37,11 @@ namespace BizHawk.Client.EmuHawk
ManualY.Minimum = AnalogStick.MinY;
ManualY.Maximum = AnalogStick.MaxY;
MaxXNumeric.Value = 127;
MaxYNumeric.Value = 127; // Note: these trigger change events that change the analog stick too
MaxXNumeric.Maximum = RangeX;
MaxXNumeric.Value = RangeX;
MaxYNumeric.Maximum = RangeY;
MaxYNumeric.Value = RangeY; // Note: these trigger change events that change the analog stick too
}
#region IVirtualPadControl Implementation

View File

@ -87,7 +87,7 @@ namespace BizHawk.Client.EmuHawk
public AnalogStickPanel()
{
Size = new Size(129, 129);
Size = new Size(MaxX + 1, MaxY + 1);
SetStyle(ControlStyles.AllPaintingInWmPaint, true);
SetStyle(ControlStyles.UserPaint, true);
SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
@ -111,9 +111,9 @@ namespace BizHawk.Client.EmuHawk
gg.FillRectangle(Brushes.Gray, 0, 2, 7, 3);
}
private static int RealToGfx(int val)
private int RealToGfx(int val)
{
return (val + 128) / 2;
return (val + MaxX) / 2;
}
private int GfxToReal(int val, bool isX) // isX is a hack
@ -150,31 +150,33 @@ namespace BizHawk.Client.EmuHawk
Refresh();
}
private int MidX { get { return (int)((MaxX + 0.5) / 2); } }
private int MidY { get { return (int)((MaxY + 0.5) / 2); } }
private void AnalogControlPanel_Paint(object sender, PaintEventArgs e)
{
unchecked
{
// Background
e.Graphics.FillRectangle(GrayBrush, 0, 0, 128, 128);
e.Graphics.FillEllipse(ReadOnly ? OffWhiteBrush : WhiteBrush, 0, 0, 127, 127);
e.Graphics.DrawEllipse(BlackPen, 0, 0, 127, 127);
e.Graphics.DrawLine(BlackPen, 64, 0, 64, 127);
e.Graphics.DrawLine(BlackPen, 0, 63, 127, 63);
e.Graphics.FillRectangle(GrayBrush, 0, 0, MaxX, MaxY);
e.Graphics.FillEllipse(ReadOnly ? OffWhiteBrush : WhiteBrush, 0, 0, MaxX - 3, MaxY - 3);
e.Graphics.DrawEllipse(BlackPen, 0, 0, MaxX - 3, MaxY - 3);
e.Graphics.DrawLine(BlackPen, MidX, 0, MidX, MaxY);
e.Graphics.DrawLine(BlackPen, 0, MidY, MaxX, MidY);
// Previous frame
if (_previous != null)
{
var pX = (int)_previous.GetFloat(XName);
var pY = (int)_previous.GetFloat(YName);
e.Graphics.DrawLine(GrayPen, 64, 63, RealToGfx(pX), 127 - RealToGfx(pY));
e.Graphics.DrawImage(GrayDot, RealToGfx(pX) - 3, 127 - RealToGfx(pY) - 3);
e.Graphics.DrawLine(GrayPen, MidX, MidY, RealToGfx(pX), MaxY - RealToGfx(pY));
e.Graphics.DrawImage(GrayDot, RealToGfx(pX) - 3, MaxY - RealToGfx(pY) - 3);
}
// Line
if (HasValue)
{
e.Graphics.DrawLine(BluePen, 64, 63, RealToGfx(X), 127 - RealToGfx(Y));
e.Graphics.DrawImage(ReadOnly ? GrayDot : Dot, RealToGfx(X) - 3, 127 - RealToGfx(Y) - 3);
e.Graphics.DrawLine(BluePen, MidX, MidY, RealToGfx(X), MaxY - RealToGfx(Y));
e.Graphics.DrawImage(ReadOnly ? GrayDot : Dot, RealToGfx(X) - 3, MaxY - RealToGfx(Y) - 3);
}
}
}
@ -185,8 +187,8 @@ namespace BizHawk.Client.EmuHawk
{
if (e.Button == MouseButtons.Left)
{
X = GfxToReal(e.X - 64, true);
Y = GfxToReal(-(e.Y - 63), false);
X = GfxToReal(e.X - MidX, true);
Y = GfxToReal(-(e.Y - MidY), false);
HasValue = true;
SetAnalog();
}
@ -223,8 +225,8 @@ namespace BizHawk.Client.EmuHawk
{
if (e.Button == MouseButtons.Left)
{
X = GfxToReal(e.X - 64, true);
Y = GfxToReal(-(e.Y - 63), false);
X = GfxToReal(e.X - MidX, true);
Y = GfxToReal(-(e.Y - MidY), false);
HasValue = true;
}
if (e.Button == MouseButtons.Right)

View File

@ -258,15 +258,16 @@ namespace BizHawk.Client.EmuHawk
{
DisplayName = "Mouse",
IsConsole = false,
DefaultSize = new Size(400, 290),
DefaultSize = new Size(550, 290),
Buttons = new[]
{
new PadSchema.ButtonScema
{
Name = "P" + controller + " Mouse X",
Location = new Point(14, 17),
Type = PadSchema.PadInputType.TargetedPair,
TargetSize = new Size(320, 270),
Type = PadSchema.PadInputType.AnalogStick,
MaxValue = 255,
TargetSize = new Size(520, 570),
SecondaryNames = new []
{
"P" + controller + " Mouse Y",