allow n64 virtualpad analog widget to release input by rightclicking

This commit is contained in:
zeromus 2013-08-26 21:35:50 +00:00
parent 089ce7f48a
commit 7d0eca7906
3 changed files with 59 additions and 17 deletions

View File

@ -201,9 +201,11 @@ namespace BizHawk.MultiClient
// if SetFloat() is called (typically virtual pads), then that float will entirely override the Source input
// otherwise, the source is passed thru.
WorkingDictionary<string,float?> FloatSet = new WorkingDictionary<string,float?>();
public void SetFloat(string name, float value)
public void SetFloat(string name, float? value)
{
FloatSet[name] = value;
if (value.HasValue)
FloatSet[name] = value;
else FloatSet.Remove(name);
}
public float GetFloat(string name)
{

View File

@ -8,6 +8,8 @@ namespace BizHawk.MultiClient
public int X = 0;
public int Y = 0;
public bool HasValue { get; private set; }
private readonly Brush WhiteBrush = Brushes.White;
private readonly Brush BlackBrush = Brushes.Black;
private readonly Brush GrayBrush = Brushes.LightGray;
@ -31,8 +33,6 @@ namespace BizHawk.MultiClient
SetStyle(ControlStyles.Opaque, true);
BackColor = Color.Gray;
Paint += AnalogControlPanel_Paint;
MouseClick += Event_MouseClick;
MouseMove += Event_MouseMove;
_white_pen = new Pen(WhiteBrush);
BlackPen = new Pen(BlackBrush);
GrayPen = new Pen(GrayBrush);
@ -73,38 +73,76 @@ namespace BizHawk.MultiClient
e.Graphics.DrawLine(BlackPen, 0, 63, 127, 63);
//Line
e.Graphics.DrawLine(BluePen, 64, 63, RealToGFX(X), 127 - RealToGFX(Y));
e.Graphics.DrawImage(dot, RealToGFX(X) - 3, 127 - RealToGFX(Y) - 3);
if (HasValue)
{
e.Graphics.DrawLine(BluePen, 64, 63, RealToGFX(X), 127 - RealToGFX(Y));
e.Graphics.DrawImage(dot, RealToGFX(X) - 3, 127 - RealToGFX(Y) - 3);
}
}
}
private void Event_MouseClick(object sender, MouseEventArgs e)
protected override void OnMouseMove(MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
X = GFXToReal(e.X - 64);
Y = GFXToReal(-(e.Y - 63));
HasValue = true;
}
if (e.Button == System.Windows.Forms.MouseButtons.Right)
{
Clear();
}
Refresh();
}
private void Event_MouseMove(object sender, MouseEventArgs e)
protected override void OnMouseUp(MouseEventArgs e)
{
base.OnMouseUp(e);
if (Capture)
Capture = false;
}
protected override void WndProc(ref Message m)
{
if (m.Msg == 0x007B) //WM_CONTEXTMENU
{
//dont let parent controls get this.. we handle the right mouse button ourselves
return;
}
base.WndProc(ref m);
}
protected override void OnMouseDown(MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
X = GFXToReal(e.X - 64);
Y = GFXToReal(-(e.Y - 63));
HasValue = true;
}
if (e.Button == System.Windows.Forms.MouseButtons.Right)
{
Clear();
}
Refresh();
}
void Clear()
{
X = Y = 0;
HasValue = false;
}
public void SetPosition(int Xval, int Yval)
{
X = Xval;
Y = Yval;
HasValue = true;
Refresh();
}

View File

@ -121,7 +121,7 @@ namespace BizHawk.MultiClient
{
y = Int32.Parse(buttons.Substring(19, 4));
}
set_analog(x, y);
set_analog(true, x, y);
}
public string GetMnemonic()
@ -217,30 +217,32 @@ namespace BizHawk.MultiClient
private void AnalogControl1_MouseClick(object sender, MouseEventArgs e)
{
set_analog(AnalogControl1.X, AnalogControl1.Y);
set_analog(AnalogControl1.HasValue, AnalogControl1.X, AnalogControl1.Y);
}
private void AnalogControl1_MouseMove(object sender, MouseEventArgs e)
{
set_analog(AnalogControl1.X, AnalogControl1.Y);
set_analog(AnalogControl1.HasValue, AnalogControl1.X, AnalogControl1.Y);
}
private void ManualX_ValueChanged(object sender, EventArgs e)
{
if (ManualX.Value != old_X)
set_analog((int)ManualX.Value, old_Y);
set_analog(AnalogControl1.HasValue, (int)ManualX.Value, old_Y);
}
private void ManualY_ValueChanged(object sender, EventArgs e)
{
if (ManualY.Value != old_Y)
set_analog(old_X, (int)ManualY.Value);
set_analog(AnalogControl1.HasValue, old_X, (int)ManualY.Value);
}
public void set_analog(int X, int Y)
public void set_analog(bool hasValue, int X, int Y)
{
Global.StickyXORAdapter.SetFloat(Controller + " X Axis", X);
Global.StickyXORAdapter.SetFloat(Controller + " Y Axis", Y);
int? x = hasValue ? X : (int?)null;
int? y = hasValue ? Y : (int?)null;
Global.StickyXORAdapter.SetFloat(Controller + " X Axis", x);
Global.StickyXORAdapter.SetFloat(Controller + " Y Axis", y);
AnalogControl1.X = X;
AnalogControl1.Y = Y;