Start an Analog Range config widget in preparation of adding the ability for the user to select the N64 controller range on individual controllers

This commit is contained in:
adelikat 2014-05-17 03:13:02 +00:00
parent 8ba683f6bd
commit 738c5b5bcc
6 changed files with 564 additions and 0 deletions

View File

@ -164,6 +164,18 @@
<Compile Include="BizBox.Designer.cs">
<DependentUpon>BizBox.cs</DependentUpon>
</Compile>
<Compile Include="config\AnalogRangeConfig.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="config\AnalogRangeConfig.Designer.cs">
<DependentUpon>AnalogRangeConfig.cs</DependentUpon>
</Compile>
<Compile Include="config\AnalogRangeConfigControl.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="config\AnalogRangeConfigControl.Designer.cs">
<DependentUpon>AnalogRangeConfigControl.cs</DependentUpon>
</Compile>
<Compile Include="config\AutofireConfig.cs">
<SubType>Form</SubType>
</Compile>
@ -986,6 +998,9 @@
<EmbeddedResource Include="AVOut\VideoWriterChooserForm.resx">
<DependentUpon>VideoWriterChooserForm.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="config\AnalogRangeConfigControl.resx">
<DependentUpon>AnalogRangeConfigControl.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="config\ControllerConfig.resx">
<DependentUpon>ControllerConfig.cs</DependentUpon>
</EmbeddedResource>

View File

@ -0,0 +1,36 @@
namespace BizHawk.Client.EmuHawk
{
partial class AnalogRangeConfig
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
components = new System.ComponentModel.Container();
}
#endregion
}
}

View File

@ -0,0 +1,196 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace BizHawk.Client.EmuHawk
{
public partial class AnalogRangeConfig : Panel
{
private const int ScaleFactor = 4;
private const int _3DPadding = 5;
private readonly Pen _blackPen;
private readonly Pen _bluePen;
private int _maxX = 127;
private int _maxY = 127;
private bool _radial = false;
public int MaxX
{
get
{
return _maxX;
}
set
{
_maxX = value;
Refresh();
Changed();
}
}
public int MaxY
{
get
{
return _maxY;
}
set
{
_maxY = value;
Refresh();
Changed();
}
}
public bool Radial
{
get
{
return _radial;
}
set
{
_radial = value;
Refresh();
Changed();
}
}
private int ScaledX
{
get { return MaxX / ScaleFactor; }
}
private int ScaledY
{
get { return MaxY / ScaleFactor; }
}
private Point TopLeft
{
get
{
var centerX = Size.Width / 2;
var centerY = Size.Height / 2;
return new Point(centerX - ScaledX, centerY - ScaledY);
}
}
public AnalogRangeConfig()
{
MaxX = 127;
MaxY = 127;
Size = new Size(65, 65);
SetStyle(ControlStyles.AllPaintingInWmPaint, true);
SetStyle(ControlStyles.UserPaint, true);
SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
SetStyle(ControlStyles.SupportsTransparentBackColor, true);
SetStyle(ControlStyles.Opaque, true);
BackColor = Color.Gray;
BorderStyle = BorderStyle.Fixed3D;
_blackPen = new Pen(Brushes.Black);
_bluePen = new Pen(Brushes.Cyan);
InitializeComponent();
}
protected override void OnPaint(PaintEventArgs e)
{
e.Graphics.FillRectangle(SystemBrushes.Control, 0, 0, Width, Height);
e.Graphics.FillEllipse(Brushes.White, 0, 0, Width - _3DPadding, Height - _3DPadding);
e.Graphics.DrawEllipse(_blackPen, 0, 0, Width - _3DPadding, Height - _3DPadding);
if (Radial)
{
e.Graphics.DrawEllipse(
_bluePen,
TopLeft.X,
TopLeft.Y,
ScaledX * 2 - 4,
ScaledY * 2 - 4);
}
else
{
e.Graphics.DrawRectangle(
_bluePen,
TopLeft.X,
TopLeft.Y,
ScaledX * 2 - 3,
ScaledY * 2 - 3);
}
base.OnPaint(e);
}
private bool _isDragging = false;
protected override void OnMouseDown(MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
_isDragging = true;
DoDrag(e.X, e.Y);
}
else if (e.Button == MouseButtons.Right)
{
Radial ^= true;
}
base.OnMouseDown(e);
}
protected override void OnMouseUp(MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
_isDragging = false;
}
base.OnMouseUp(e);
}
private void DoDrag(int x, int y)
{
if (_isDragging)
{
var centerX = Size.Width / 2;
var centerY = Size.Height / 2;
var offsetx = Math.Abs(centerX - x) * ScaleFactor;
var offsety = Math.Abs(centerY - y) * ScaleFactor;
MaxX = Math.Min(offsetx, sbyte.MaxValue);
MaxY = Math.Min(offsety, sbyte.MaxValue);
}
}
protected override void OnMouseMove(MouseEventArgs e)
{
DoDrag(e.X, e.Y);
base.OnMouseMove(e);
}
public Action ChangeCallback { get; set; }
private void Changed()
{
if (ChangeCallback != null)
{
ChangeCallback();
}
}
}
}

View File

@ -0,0 +1,140 @@
namespace BizHawk.Client.EmuHawk
{
partial class AnalogRangeConfigControl
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.XNumeric = new System.Windows.Forms.NumericUpDown();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.YNumeric = new System.Windows.Forms.NumericUpDown();
this.RadialCheckbox = new System.Windows.Forms.CheckBox();
this.AnalogRange = new BizHawk.Client.EmuHawk.AnalogRangeConfig();
((System.ComponentModel.ISupportInitialize)(this.XNumeric)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.YNumeric)).BeginInit();
this.SuspendLayout();
//
// XNumeric
//
this.XNumeric.Location = new System.Drawing.Point(86, 5);
this.XNumeric.Maximum = new decimal(new int[] {
127,
0,
0,
0});
this.XNumeric.Name = "XNumeric";
this.XNumeric.Size = new System.Drawing.Size(45, 20);
this.XNumeric.TabIndex = 1;
this.XNumeric.ValueChanged += new System.EventHandler(this.XNumeric_ValueChanged);
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(71, 30);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(14, 13);
this.label1.TabIndex = 3;
this.label1.Text = "Y";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(71, 9);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(14, 13);
this.label2.TabIndex = 4;
this.label2.Text = "X";
//
// YNumeric
//
this.YNumeric.Location = new System.Drawing.Point(86, 26);
this.YNumeric.Maximum = new decimal(new int[] {
127,
0,
0,
0});
this.YNumeric.Name = "YNumeric";
this.YNumeric.Size = new System.Drawing.Size(45, 20);
this.YNumeric.TabIndex = 2;
this.YNumeric.ValueChanged += new System.EventHandler(this.YNumeric_ValueChanged);
//
// RadialCheckbox
//
this.RadialCheckbox.Appearance = System.Windows.Forms.Appearance.Button;
this.RadialCheckbox.AutoSize = true;
this.RadialCheckbox.Location = new System.Drawing.Point(84, 47);
this.RadialCheckbox.Name = "RadialCheckbox";
this.RadialCheckbox.Size = new System.Drawing.Size(47, 23);
this.RadialCheckbox.TabIndex = 5;
this.RadialCheckbox.Text = "Radial";
this.RadialCheckbox.UseVisualStyleBackColor = true;
this.RadialCheckbox.CheckedChanged += new System.EventHandler(this.RadialCheckbox_CheckedChanged);
//
// AnalogRange
//
this.AnalogRange.BackColor = System.Drawing.Color.Gray;
this.AnalogRange.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.AnalogRange.ChangeCallback = null;
this.AnalogRange.Location = new System.Drawing.Point(5, 5);
this.AnalogRange.MaxX = 0;
this.AnalogRange.MaxY = 0;
this.AnalogRange.Name = "AnalogRange";
this.AnalogRange.Radial = false;
this.AnalogRange.Size = new System.Drawing.Size(65, 65);
this.AnalogRange.TabIndex = 0;
//
// AnalogRangeConfigControl
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.RadialCheckbox);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Controls.Add(this.YNumeric);
this.Controls.Add(this.XNumeric);
this.Controls.Add(this.AnalogRange);
this.Name = "AnalogRangeConfigControl";
this.Size = new System.Drawing.Size(135, 76);
this.Load += new System.EventHandler(this.AnalogRangeConfigControl_Load);
((System.ComponentModel.ISupportInitialize)(this.XNumeric)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.YNumeric)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private AnalogRangeConfig AnalogRange;
private System.Windows.Forms.NumericUpDown XNumeric;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.NumericUpDown YNumeric;
private System.Windows.Forms.CheckBox RadialCheckbox;
}
}

View File

@ -0,0 +1,57 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace BizHawk.Client.EmuHawk
{
public partial class AnalogRangeConfigControl : UserControl
{
private bool _supressChange = false;
public AnalogRangeConfigControl()
{
InitializeComponent();
}
private void AnalogRangeConfigControl_Load(object sender, EventArgs e)
{
AnalogRange.ChangeCallback = AnalogControlChanged;
}
private void XNumeric_ValueChanged(object sender, EventArgs e)
{
_supressChange = true;
AnalogRange.MaxX = (int)XNumeric.Value;
_supressChange = false;
}
private void YNumeric_ValueChanged(object sender, EventArgs e)
{
_supressChange = true;
AnalogRange.MaxY = (int)YNumeric.Value;
_supressChange = false;
}
private void RadialCheckbox_CheckedChanged(object sender, EventArgs e)
{
_supressChange = true;
AnalogRange.Radial = RadialCheckbox.Checked;
_supressChange = false;
}
private void AnalogControlChanged()
{
if (!_supressChange)
{
XNumeric.Value = AnalogRange.MaxX;
YNumeric.Value = AnalogRange.MaxY;
RadialCheckbox.Checked = AnalogRange.Radial;
}
}
}
}

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>