2014-06-22 13:58:12 +00:00
using System ;
using System.Collections.Generic ;
using System.Linq ;
using System.Windows.Forms ;
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-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 )
{
Size = _schema . DefaultSize ;
2014-06-24 23:32:30 +00:00
MaximumSize = _schema . MaxSize ? ? _schema . DefaultSize ;
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-06-24 23:32:30 +00:00
PadBox . Controls . Add ( new VirtualPadButton
2014-06-22 13:58:12 +00:00
{
Name = button . Name ,
Text = button . DisplayName ,
2014-06-22 15:43:45 +00:00
Location = button . Location ,
2014-06-25 20:40:20 +00:00
Image = button . Icon ,
2014-06-22 15:43:45 +00:00
} ) ;
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-07-06 16:44:50 +00:00
Location = button . Location ,
2014-07-06 17:02:35 +00:00
Size = new Size ( button . MaxValue + 79 , button . MaxValue + 9 ) , // TODO: don't use hardcoded values here, at least make them defaults in the AnalogStick object itself
2014-07-06 16:44:50 +00:00
RangeX = button . MaxValue ,
RangeY = button . MaxValue // TODO ability to pass in a different Y max
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 ,
Location = button . Location ,
XName = button . Name ,
YName = button . SecondaryNames [ 0 ] ,
2014-07-04 00:04:18 +00:00
Size = button . TargetSize ,
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 ,
Location = button . Location ,
Size = button . TargetSize ,
MaxValue = button . MaxValue
2014-06-22 21:50:27 +00:00
} ) ;
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
}
}