2014-06-22 13:58:12 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
2014-12-28 23:58:45 +00:00
|
|
|
|
using BizHawk.Client.Common;
|
2014-06-22 13:58:12 +00:00
|
|
|
|
using BizHawk.Emulation.Common;
|
2014-07-06 17:02:35 +00:00
|
|
|
|
using System.Drawing;
|
2014-06-22 13:58:12 +00:00
|
|
|
|
|
|
|
|
|
namespace BizHawk.Client.EmuHawk
|
|
|
|
|
{
|
2014-06-24 16:36:19 +00:00
|
|
|
|
public partial class VirtualPad : UserControl
|
2014-06-22 13:58:12 +00:00
|
|
|
|
{
|
2014-06-29 03:14:40 +00:00
|
|
|
|
private readonly PadSchema _schema;
|
|
|
|
|
private bool _readOnly;
|
2014-06-22 13:58:12 +00:00
|
|
|
|
|
2014-07-26 17:11:47 +00:00
|
|
|
|
public void UpdateValues()
|
|
|
|
|
{
|
|
|
|
|
PadControls.ForEach(c => c.UpdateValues());
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-26 20:36:33 +00:00
|
|
|
|
private List<IVirtualPadControl> PadControls
|
2014-06-24 16:36:19 +00:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2014-06-25 00:11:59 +00:00
|
|
|
|
return PadBox.Controls
|
2014-06-24 16:36:19 +00:00
|
|
|
|
.OfType<IVirtualPadControl>()
|
|
|
|
|
.ToList();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-19 03:24:48 +00:00
|
|
|
|
public string PadSchemaDisplayName { get { return _schema.DisplayName; } }
|
|
|
|
|
|
2014-06-26 20:36:33 +00:00
|
|
|
|
public bool ReadOnly
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2014-06-27 01:45:30 +00:00
|
|
|
|
return _readOnly;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
_readOnly = value;
|
|
|
|
|
PadControls.ForEach(c => c.ReadOnly = value);
|
2014-06-26 20:36:33 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-22 15:05:37 +00:00
|
|
|
|
public VirtualPad(PadSchema schema)
|
2014-06-22 13:58:12 +00:00
|
|
|
|
{
|
|
|
|
|
SetStyle(ControlStyles.AllPaintingInWmPaint, true);
|
|
|
|
|
SetStyle(ControlStyles.UserPaint, true);
|
|
|
|
|
SetStyle(ControlStyles.DoubleBuffer, true);
|
|
|
|
|
InitializeComponent();
|
2014-06-24 23:32:30 +00:00
|
|
|
|
Dock = DockStyle.Top | DockStyle.Left;
|
2014-06-22 13:58:12 +00:00
|
|
|
|
_schema = schema;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void VirtualPadControl_Load(object sender, EventArgs e)
|
|
|
|
|
{
|
2014-12-28 23:58:45 +00:00
|
|
|
|
Size = UIHelper.Scale(_schema.DefaultSize);
|
|
|
|
|
MaximumSize = UIHelper.Scale(_schema.MaxSize ?? _schema.DefaultSize);
|
2014-06-24 23:32:30 +00:00
|
|
|
|
PadBox.Text = _schema.DisplayName;
|
2014-06-22 13:58:12 +00:00
|
|
|
|
foreach (var button in _schema.Buttons)
|
|
|
|
|
{
|
|
|
|
|
switch (button.Type)
|
|
|
|
|
{
|
|
|
|
|
case PadSchema.PadInputType.Boolean:
|
2014-12-28 23:58:45 +00:00
|
|
|
|
var buttonControl = new VirtualPadButton
|
2014-06-22 13:58:12 +00:00
|
|
|
|
{
|
|
|
|
|
Name = button.Name,
|
|
|
|
|
Text = button.DisplayName,
|
2014-12-28 23:58:45 +00:00
|
|
|
|
Location = UIHelper.Scale(button.Location),
|
2014-06-25 20:40:20 +00:00
|
|
|
|
Image = button.Icon,
|
2014-12-28 23:58:45 +00:00
|
|
|
|
};
|
|
|
|
|
if (button.Icon != null && UIHelper.AutoScaleFactorX > 1F && UIHelper.AutoScaleFactorY > 1F)
|
|
|
|
|
{
|
|
|
|
|
// When scaling up, unfortunately the icon will look too small, but at least we can make the rest of the button bigger
|
|
|
|
|
buttonControl.AutoSize = false;
|
2015-01-01 22:14:03 +00:00
|
|
|
|
buttonControl.Size = UIHelper.Scale(button.Icon.Size) + new Size(6, 6);
|
2014-12-28 23:58:45 +00:00
|
|
|
|
}
|
|
|
|
|
PadBox.Controls.Add(buttonControl);
|
2014-06-22 13:58:12 +00:00
|
|
|
|
break;
|
2014-06-22 15:43:45 +00:00
|
|
|
|
case PadSchema.PadInputType.AnalogStick:
|
2014-06-24 23:32:30 +00:00
|
|
|
|
PadBox.Controls.Add(new VirtualPadAnalogStick
|
2014-06-22 15:43:45 +00:00
|
|
|
|
{
|
|
|
|
|
Name = button.Name,
|
2014-12-28 23:58:45 +00:00
|
|
|
|
Location = UIHelper.Scale(button.Location),
|
2015-07-20 02:45:51 +00:00
|
|
|
|
Size = UIHelper.Scale(new Size(127 + 79, 127 + 9)),
|
|
|
|
|
RangeX = new float[] { button.MinValue, button.MidValue, button.MaxValue },
|
|
|
|
|
RangeY = new float[] { button.MinValueSec, button.MidValueSec, button.MaxValueSec },
|
2014-06-22 15:43:45 +00:00
|
|
|
|
});
|
2014-06-22 13:58:12 +00:00
|
|
|
|
break;
|
2014-06-22 21:50:27 +00:00
|
|
|
|
case PadSchema.PadInputType.TargetedPair:
|
2014-06-24 23:32:30 +00:00
|
|
|
|
PadBox.Controls.Add(new VirtualPadTargetScreen
|
2014-06-22 21:50:27 +00:00
|
|
|
|
{
|
|
|
|
|
Name = button.Name,
|
2014-12-28 23:58:45 +00:00
|
|
|
|
Location = UIHelper.Scale(button.Location),
|
2015-01-01 22:14:03 +00:00
|
|
|
|
TargetSize = button.TargetSize,
|
2014-06-22 21:50:27 +00:00
|
|
|
|
XName = button.Name,
|
|
|
|
|
YName = button.SecondaryNames[0],
|
2014-07-04 00:04:18 +00:00
|
|
|
|
RangeX = button.MaxValue,
|
|
|
|
|
RangeY = button.MaxValue // TODO: ability to have a different Y than X
|
2014-06-24 12:58:08 +00:00
|
|
|
|
});
|
|
|
|
|
break;
|
|
|
|
|
case PadSchema.PadInputType.FloatSingle:
|
2014-06-24 23:32:30 +00:00
|
|
|
|
PadBox.Controls.Add(new VirtualPadAnalogButton
|
2014-06-24 12:58:08 +00:00
|
|
|
|
{
|
|
|
|
|
Name = button.Name,
|
|
|
|
|
DisplayName = button.DisplayName,
|
2014-12-28 23:58:45 +00:00
|
|
|
|
Location = UIHelper.Scale(button.Location),
|
2014-12-31 05:34:21 +00:00
|
|
|
|
Size = UIHelper.Scale(button.TargetSize),
|
2014-12-16 03:15:27 +00:00
|
|
|
|
MinValue = button.MinValue,
|
2014-06-24 12:58:08 +00:00
|
|
|
|
MaxValue = button.MaxValue
|
2014-06-22 21:50:27 +00:00
|
|
|
|
});
|
|
|
|
|
break;
|
2014-12-19 03:24:48 +00:00
|
|
|
|
case PadSchema.PadInputType.DiscManager:
|
|
|
|
|
PadBox.Controls.Add(new VirtualPadDiscManager(button.SecondaryNames)
|
|
|
|
|
{
|
|
|
|
|
Name = button.Name,
|
|
|
|
|
//DisplayName = button.DisplayName,
|
2014-12-28 23:58:45 +00:00
|
|
|
|
Location = UIHelper.Scale(button.Location),
|
2014-12-31 05:34:21 +00:00
|
|
|
|
Size = UIHelper.Scale(button.TargetSize),
|
2014-12-19 03:24:48 +00:00
|
|
|
|
OwnerEmulator = button.OwnerEmulator
|
|
|
|
|
});
|
|
|
|
|
break;
|
2014-06-22 13:58:12 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Clear()
|
|
|
|
|
{
|
2014-06-26 20:36:33 +00:00
|
|
|
|
PadControls.ForEach(p => p.Clear());
|
2014-06-25 20:40:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-07-27 12:39:56 +00:00
|
|
|
|
public void ClearBoolean()
|
|
|
|
|
{
|
|
|
|
|
PadControls
|
|
|
|
|
.OfType<VirtualPadButton>()
|
|
|
|
|
.ToList()
|
|
|
|
|
.ForEach(p => p.Clear());
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-22 13:58:12 +00:00
|
|
|
|
public void Set(IController controller)
|
|
|
|
|
{
|
2014-06-26 20:36:33 +00:00
|
|
|
|
PadControls.ForEach(c => c.Set(controller));
|
2014-06-22 13:58:12 +00:00
|
|
|
|
}
|
2014-06-29 14:42:20 +00:00
|
|
|
|
|
|
|
|
|
public void SetPrevious(IController previous)
|
|
|
|
|
{
|
|
|
|
|
PadControls
|
|
|
|
|
.OfType<VirtualPadAnalogStick>()
|
|
|
|
|
.ToList()
|
|
|
|
|
.ForEach(c => c.SetPrevious(previous));
|
|
|
|
|
}
|
2014-06-29 23:43:31 +00:00
|
|
|
|
|
|
|
|
|
public void BumpAnalog(int? x, int? y)
|
|
|
|
|
{
|
|
|
|
|
PadControls
|
|
|
|
|
.OfType<VirtualPadAnalogStick>()
|
|
|
|
|
.ToList()
|
|
|
|
|
.ForEach(a => a.Bump(x, y));
|
|
|
|
|
|
|
|
|
|
PadControls
|
|
|
|
|
.OfType<VirtualPadAnalogButton>()
|
|
|
|
|
.ToList()
|
|
|
|
|
.ForEach(a => a.Bump(x));
|
|
|
|
|
|
|
|
|
|
PadControls
|
|
|
|
|
.OfType<VirtualPadTargetScreen>()
|
|
|
|
|
.ToList()
|
|
|
|
|
.ForEach(a => a.Bump(x, y));
|
|
|
|
|
}
|
2014-06-22 13:58:12 +00:00
|
|
|
|
}
|
|
|
|
|
}
|