Implement read-only for VirtualPadButton

This commit is contained in:
adelikat 2014-06-25 20:40:20 +00:00
parent 9c601da269
commit 4d9f46c6a1
5 changed files with 103 additions and 45 deletions

View File

@ -51,7 +51,8 @@ namespace BizHawk.Client.EmuHawk
Name = button.Name,
Text = button.DisplayName,
Location = button.Location,
Image = button.Icon
Image = button.Icon,
ReadOnly = true
});
break;
case PadSchema.PadInputType.AnalogStick:
@ -88,7 +89,12 @@ namespace BizHawk.Client.EmuHawk
public void Clear()
{
Pads.ForEach(c => c.Clear());
Pads.ForEach(p => p.Clear());
}
public void ToggleReadOnly()
{
Pads.ForEach(p => p.ReadOnly ^= true);
}
public void Set(IController controller)

View File

@ -45,6 +45,7 @@
this.PadsSubMenu = new System.Windows.Forms.ToolStripMenuItem();
this.ClearAllMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.StickyMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.DebugReadonlyButton = new System.Windows.Forms.Button();
this.PadMenu.SuspendLayout();
this.SuspendLayout();
//
@ -188,11 +189,22 @@
this.StickyMenuItem.Text = "Sticky";
this.StickyMenuItem.Click += new System.EventHandler(this.StickyMenuItem_Click);
//
// DebugReadonlyButton
//
this.DebugReadonlyButton.Location = new System.Drawing.Point(265, 26);
this.DebugReadonlyButton.Name = "DebugReadonlyButton";
this.DebugReadonlyButton.Size = new System.Drawing.Size(175, 23);
this.DebugReadonlyButton.TabIndex = 12;
this.DebugReadonlyButton.Text = "ReadOnlyToggle delete me";
this.DebugReadonlyButton.UseVisualStyleBackColor = true;
this.DebugReadonlyButton.Click += new System.EventHandler(this.DebugReadonlyButton_Click);
//
// VirtualpadTool
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(452, 312);
this.Controls.Add(this.DebugReadonlyButton);
this.Controls.Add(this.ControllerBox);
this.Controls.Add(this.StickyBox);
this.Controls.Add(this.ClearButton);
@ -226,5 +238,6 @@
private System.Windows.Forms.ToolStripMenuItem ClearAllMenuItem;
private System.Windows.Forms.GroupBox ControllerBox;
private System.Windows.Forms.ToolStripMenuItem StickyMenuItem;
private System.Windows.Forms.Button DebugReadonlyButton;
}
}

View File

@ -200,6 +200,11 @@ namespace BizHawk.Client.EmuHawk
#endregion
private void DebugReadonlyButton_Click(object sender, EventArgs e)
{
Pads.ForEach(p => p.ToggleReadOnly());
}
#endregion
}
}

View File

@ -10,6 +10,7 @@ namespace BizHawk.Client.EmuHawk
public class VirtualPadButton : CheckBox, IVirtualPadControl
{
private bool _rightClicked = false;
private bool _readonly = false;
public VirtualPadButton()
{
@ -26,10 +27,13 @@ namespace BizHawk.Client.EmuHawk
public void Clear()
{
RightClicked = false;
Checked = false;
Global.AutofireStickyXORAdapter.SetSticky(Name, false);
Global.StickyXORAdapter.SetSticky(Name, false);
if (!ReadOnly)
{
RightClicked = false;
Checked = false;
Global.AutofireStickyXORAdapter.SetSticky(Name, false);
Global.StickyXORAdapter.SetSticky(Name, false);
}
}
public void Set(IController controller)
@ -46,7 +50,22 @@ namespace BizHawk.Client.EmuHawk
public bool ReadOnly
{
get; set; // TODO
get
{
return _readonly;
}
set
{
var changed = _readonly != value;
RightClicked = false;
Checked = false;
_readonly = value;
if (changed)
{
Refresh();
}
}
}
#endregion
@ -56,8 +75,11 @@ namespace BizHawk.Client.EmuHawk
switch (m.Msg)
{
case 0x0204: // WM_RBUTTONDOWN
RightClicked = true;
Checked ^= true;
if (!ReadOnly)
{
RightClicked = true;
Checked ^= true;
}
return;
case 0x0205: // WM_RBUTTONUP
return;
@ -71,7 +93,15 @@ namespace BizHawk.Client.EmuHawk
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
if (RightClicked)
if (ReadOnly)
{
ControlPaint.DrawBorder(e.Graphics, ClientRectangle,
SystemColors.ControlDark, 1, ButtonBorderStyle.Inset,
SystemColors.ControlDark, 1, ButtonBorderStyle.Inset,
SystemColors.ControlDark, 1, ButtonBorderStyle.Inset,
SystemColors.ControlDark, 1, ButtonBorderStyle.Inset);
}
else if (RightClicked)
{
ControlPaint.DrawBorder(e.Graphics, ClientRectangle,
SystemColors.HotTrack, 1, ButtonBorderStyle.Inset,
@ -85,40 +115,23 @@ namespace BizHawk.Client.EmuHawk
{
get
{
return _rightClicked;
return !ReadOnly && _rightClicked;
}
set
{
_rightClicked = value;
if (_rightClicked)
if (!ReadOnly)
{
ForeColor = SystemColors.HotTrack;
_rightClicked = value;
if (_rightClicked)
{
ForeColor = SystemColors.HotTrack;
}
else
{
ForeColor = SystemColors.ControlText;
}
}
else
{
ForeColor = SystemColors.ControlText;
}
}
}
private void SetSticky()
{
Global.StickyXORAdapter.SetSticky(Name, Checked);
if (Checked == false)
{
Clear();
}
}
private void SetAutofireSticky()
{
Global.AutofireStickyXORAdapter.SetSticky(Name, Checked);
if (Checked == false)
{
Clear();
}
}
@ -126,11 +139,21 @@ namespace BizHawk.Client.EmuHawk
{
if (RightClicked)
{
SetAutofireSticky();
Global.AutofireStickyXORAdapter.SetSticky(Name, Checked);
if (Checked == false)
{
Clear();
}
}
else
{
SetSticky();
Global.StickyXORAdapter.SetSticky(Name, Checked);
if (Checked == false)
{
Clear();
}
}
base.OnCheckedChanged(e);
@ -138,12 +161,23 @@ namespace BizHawk.Client.EmuHawk
protected override void OnMouseClick(MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
if (!ReadOnly)
{
RightClicked = false;
}
if (e.Button == MouseButtons.Left)
{
RightClicked = false;
}
base.OnMouseClick(e);
base.OnMouseClick(e);
}
}
protected override void OnClick(EventArgs e)
{
if (!ReadOnly)
{
base.OnClick(e);
}
}
}
}

View File

@ -17,7 +17,7 @@ namespace BizHawk.Client.EmuHawk
{
if (ss.Controllers[i].IsConnected)
{
yield return new VirtualPad(StandardController(i));
yield return new VirtualPad(StandardController(i + 1));
}
}
}