BizHawk/BizHawk.Client.EmuHawk/tools/VirtualPads/controls/VirtualPadButton.cs

128 lines
2.2 KiB
C#
Raw Normal View History

using System;
using System.Windows.Forms;
using System.Drawing;
using BizHawk.Client.Common;
2014-06-24 16:36:19 +00:00
using BizHawk.Emulation.Common;
namespace BizHawk.Client.EmuHawk
{
2014-06-22 15:05:37 +00:00
public class VirtualPadButton : CheckBox, IVirtualPadControl
{
private bool _rightClicked = false;
public VirtualPadButton()
{
SetStyle(ControlStyles.AllPaintingInWmPaint, true);
SetStyle(ControlStyles.UserPaint, true);
SetStyle(ControlStyles.DoubleBuffer, true);
Appearance = Appearance.Button;
AutoSize = true;
ForeColor = SystemColors.ControlText;
}
protected override void WndProc(ref Message m)
{
switch (m.Msg)
{
2014-06-22 15:05:37 +00:00
case 0x0204: // WM_RBUTTONDOWN
2014-06-24 16:36:19 +00:00
RightClicked = true;
Checked ^= true;
return;
2014-06-22 15:05:37 +00:00
case 0x0205: // WM_RBUTTONUP
return;
2014-06-22 15:05:37 +00:00
case 0x0206: // WM_RBUTTONDBLCLK
return;
}
base.WndProc(ref m);
}
2014-06-24 16:36:19 +00:00
public bool RightClicked
{
get
{
return _rightClicked;
}
set
{
_rightClicked = value;
if (_rightClicked)
{
ForeColor = SystemColors.HotTrack;
}
else
{
ForeColor = SystemColors.ControlText;
}
}
}
private void SetSticky()
{
Global.StickyXORAdapter.SetSticky(Name, Checked);
if (Checked == false)
{
Clear();
}
}
2014-06-24 16:36:19 +00:00
private void SetAutofireSticky()
{
Global.AutofireStickyXORAdapter.SetSticky(Name, Checked);
if (Checked == false)
{
Clear();
}
}
protected override void OnCheckedChanged(EventArgs e)
{
2014-06-24 16:36:19 +00:00
if (RightClicked)
{
SetAutofireSticky();
}
else
{
SetSticky();
}
base.OnCheckedChanged(e);
}
protected override void OnMouseClick(MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
2014-06-24 16:36:19 +00:00
RightClicked = false;
}
base.OnMouseClick(e);
}
public void Clear()
{
2014-06-24 16:36:19 +00:00
RightClicked = false;
Checked = false;
Global.AutofireStickyXORAdapter.SetSticky(Name, false);
Global.StickyXORAdapter.SetSticky(Name, false);
}
2014-06-24 16:36:19 +00:00
public void Set(IController controller)
{
var newVal = controller.IsPressed(Name);
var changed = newVal != Checked;
Checked = newVal;
if (changed)
{
Refresh();
}
}
}
}