Implemented JoystickDevice events.

Added GameWindow interface to JoystickDevices.
Added HID support to Tests/InputLogger.
This commit is contained in:
the_fiddler 2009-03-01 00:28:31 +00:00
parent 6118f4fdec
commit 2eeb1a7bd9
4 changed files with 558 additions and 45 deletions

View file

@ -60,9 +60,32 @@
this.ChooseMouse = new System.Windows.Forms.ComboBox();
this.HID = new System.Windows.Forms.TabPage();
this.PollTimer = new System.Windows.Forms.Timer(this.components);
this.comboBoxActiveJoystick = new System.Windows.Forms.ComboBox();
this.textBoxAxis1 = new System.Windows.Forms.TextBox();
this.textBoxAxis2 = new System.Windows.Forms.TextBox();
this.textBoxAxis3 = new System.Windows.Forms.TextBox();
this.textBoxAxis4 = new System.Windows.Forms.TextBox();
this.textBoxAxis5 = new System.Windows.Forms.TextBox();
this.textBoxAxis6 = new System.Windows.Forms.TextBox();
this.textBoxAxis7 = new System.Windows.Forms.TextBox();
this.textBoxAxis8 = new System.Windows.Forms.TextBox();
this.textBoxAxis9 = new System.Windows.Forms.TextBox();
this.textBoxAxis10 = new System.Windows.Forms.TextBox();
this.labelAxis1 = new System.Windows.Forms.Label();
this.labelAxis2 = new System.Windows.Forms.Label();
this.labelAxis3 = new System.Windows.Forms.Label();
this.labelAxis4 = new System.Windows.Forms.Label();
this.labelAxis5 = new System.Windows.Forms.Label();
this.labelAxis6 = new System.Windows.Forms.Label();
this.labelAxis7 = new System.Windows.Forms.Label();
this.labelAxis8 = new System.Windows.Forms.Label();
this.labelAxis9 = new System.Windows.Forms.Label();
this.labelAxis10 = new System.Windows.Forms.Label();
this.JoystickButtonsBox = new System.Windows.Forms.ListBox();
this.tabControl.SuspendLayout();
this.Keyboard.SuspendLayout();
this.Mouse.SuspendLayout();
this.HID.SuspendLayout();
this.SuspendLayout();
//
// tabControl
@ -74,7 +97,7 @@
this.tabControl.Location = new System.Drawing.Point(0, 0);
this.tabControl.Name = "tabControl";
this.tabControl.SelectedIndex = 0;
this.tabControl.Size = new System.Drawing.Size(432, 378);
this.tabControl.Size = new System.Drawing.Size(432, 379);
this.tabControl.TabIndex = 0;
//
// Keyboard
@ -100,7 +123,7 @@
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(207, 180);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(61, 13);
this.label4.Size = new System.Drawing.Size(64, 13);
this.label4.TabIndex = 7;
this.label4.Text = "Keyboard 4";
//
@ -109,7 +132,7 @@
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(6, 180);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(61, 13);
this.label3.Size = new System.Drawing.Size(64, 13);
this.label3.TabIndex = 6;
this.label3.Text = "Keyboard 3";
//
@ -118,7 +141,7 @@
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(207, 3);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(61, 13);
this.label2.Size = new System.Drawing.Size(64, 13);
this.label2.TabIndex = 5;
this.label2.Text = "Keyboard 2";
//
@ -127,7 +150,7 @@
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(8, 3);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(61, 13);
this.label1.Size = new System.Drawing.Size(64, 13);
this.label1.TabIndex = 4;
this.label1.Text = "Keyboard 1";
//
@ -187,7 +210,7 @@
this.Mouse.Location = new System.Drawing.Point(4, 22);
this.Mouse.Name = "Mouse";
this.Mouse.Padding = new System.Windows.Forms.Padding(3);
this.Mouse.Size = new System.Drawing.Size(424, 352);
this.Mouse.Size = new System.Drawing.Size(424, 353);
this.Mouse.TabIndex = 1;
this.Mouse.Text = "Mouse";
//
@ -196,7 +219,7 @@
this.WindowY.AutoSize = true;
this.WindowY.Location = new System.Drawing.Point(4, 239);
this.WindowY.Name = "WindowY";
this.WindowY.Size = new System.Drawing.Size(59, 13);
this.WindowY.Size = new System.Drawing.Size(62, 13);
this.WindowY.TabIndex = 17;
this.WindowY.Text = "Window Y:";
//
@ -205,7 +228,7 @@
this.WindowX.AutoSize = true;
this.WindowX.Location = new System.Drawing.Point(4, 212);
this.WindowX.Name = "WindowX";
this.WindowX.Size = new System.Drawing.Size(59, 13);
this.WindowX.Size = new System.Drawing.Size(63, 13);
this.WindowX.TabIndex = 16;
this.WindowX.Text = "Window X:";
//
@ -214,7 +237,7 @@
this.MouseYWindow.Location = new System.Drawing.Point(80, 232);
this.MouseYWindow.Name = "MouseYWindow";
this.MouseYWindow.ReadOnly = true;
this.MouseYWindow.Size = new System.Drawing.Size(73, 20);
this.MouseYWindow.Size = new System.Drawing.Size(73, 22);
this.MouseYWindow.TabIndex = 15;
//
// MouseXWindow
@ -222,7 +245,7 @@
this.MouseXWindow.Location = new System.Drawing.Point(80, 205);
this.MouseXWindow.Name = "MouseXWindow";
this.MouseXWindow.ReadOnly = true;
this.MouseXWindow.Size = new System.Drawing.Size(73, 20);
this.MouseXWindow.Size = new System.Drawing.Size(73, 22);
this.MouseXWindow.TabIndex = 14;
//
// MouseWheelDelta
@ -230,7 +253,7 @@
this.MouseWheelDelta.Location = new System.Drawing.Point(80, 178);
this.MouseWheelDelta.Name = "MouseWheelDelta";
this.MouseWheelDelta.ReadOnly = true;
this.MouseWheelDelta.Size = new System.Drawing.Size(73, 20);
this.MouseWheelDelta.Size = new System.Drawing.Size(73, 22);
this.MouseWheelDelta.TabIndex = 13;
//
// WheelDelta
@ -238,7 +261,7 @@
this.WheelDelta.AutoSize = true;
this.WheelDelta.Location = new System.Drawing.Point(4, 185);
this.WheelDelta.Name = "WheelDelta";
this.WheelDelta.Size = new System.Drawing.Size(69, 13);
this.WheelDelta.Size = new System.Drawing.Size(73, 13);
this.WheelDelta.TabIndex = 12;
this.WheelDelta.Text = "Wheel Delta:";
//
@ -247,7 +270,7 @@
this.MouseWheelText.Location = new System.Drawing.Point(80, 152);
this.MouseWheelText.Name = "MouseWheelText";
this.MouseWheelText.ReadOnly = true;
this.MouseWheelText.Size = new System.Drawing.Size(73, 20);
this.MouseWheelText.Size = new System.Drawing.Size(73, 22);
this.MouseWheelText.TabIndex = 11;
//
// MouseWheelLabel
@ -255,7 +278,7 @@
this.MouseWheelLabel.AutoSize = true;
this.MouseWheelLabel.Location = new System.Drawing.Point(4, 159);
this.MouseWheelLabel.Name = "MouseWheelLabel";
this.MouseWheelLabel.Size = new System.Drawing.Size(41, 13);
this.MouseWheelLabel.Size = new System.Drawing.Size(43, 13);
this.MouseWheelLabel.TabIndex = 10;
this.MouseWheelLabel.Text = "Wheel:";
//
@ -273,7 +296,7 @@
this.MouseDeltaX.AutoSize = true;
this.MouseDeltaX.Location = new System.Drawing.Point(4, 105);
this.MouseDeltaX.Name = "MouseDeltaX";
this.MouseDeltaX.Size = new System.Drawing.Size(45, 13);
this.MouseDeltaX.Size = new System.Drawing.Size(46, 13);
this.MouseDeltaX.TabIndex = 8;
this.MouseDeltaX.Text = "Delta X:";
//
@ -282,7 +305,7 @@
this.MouseY.AutoSize = true;
this.MouseY.Location = new System.Drawing.Point(4, 78);
this.MouseY.Name = "MouseY";
this.MouseY.Size = new System.Drawing.Size(57, 13);
this.MouseY.Size = new System.Drawing.Size(60, 13);
this.MouseY.TabIndex = 7;
this.MouseY.Text = "Position Y:";
//
@ -291,7 +314,7 @@
this.MouseX.AutoSize = true;
this.MouseX.Location = new System.Drawing.Point(4, 51);
this.MouseX.Name = "MouseX";
this.MouseX.Size = new System.Drawing.Size(57, 13);
this.MouseX.Size = new System.Drawing.Size(61, 13);
this.MouseX.TabIndex = 6;
this.MouseX.Text = "Position X:";
//
@ -300,7 +323,7 @@
this.MouseDYText.Location = new System.Drawing.Point(80, 125);
this.MouseDYText.Name = "MouseDYText";
this.MouseDYText.ReadOnly = true;
this.MouseDYText.Size = new System.Drawing.Size(73, 20);
this.MouseDYText.Size = new System.Drawing.Size(73, 22);
this.MouseDYText.TabIndex = 5;
//
// MouseDXText
@ -308,7 +331,7 @@
this.MouseDXText.Location = new System.Drawing.Point(80, 98);
this.MouseDXText.Name = "MouseDXText";
this.MouseDXText.ReadOnly = true;
this.MouseDXText.Size = new System.Drawing.Size(73, 20);
this.MouseDXText.Size = new System.Drawing.Size(73, 22);
this.MouseDXText.TabIndex = 4;
//
// MouseYText
@ -316,7 +339,7 @@
this.MouseYText.Location = new System.Drawing.Point(80, 71);
this.MouseYText.Name = "MouseYText";
this.MouseYText.ReadOnly = true;
this.MouseYText.Size = new System.Drawing.Size(73, 20);
this.MouseYText.Size = new System.Drawing.Size(73, 22);
this.MouseYText.TabIndex = 3;
//
// MouseXText
@ -324,7 +347,7 @@
this.MouseXText.Location = new System.Drawing.Point(80, 44);
this.MouseXText.Name = "MouseXText";
this.MouseXText.ReadOnly = true;
this.MouseXText.Size = new System.Drawing.Size(73, 20);
this.MouseXText.Size = new System.Drawing.Size(73, 22);
this.MouseXText.TabIndex = 2;
//
// MouseButtonsBox
@ -352,10 +375,32 @@
//
// HID
//
this.HID.Controls.Add(this.labelAxis10);
this.HID.Controls.Add(this.labelAxis9);
this.HID.Controls.Add(this.labelAxis8);
this.HID.Controls.Add(this.labelAxis7);
this.HID.Controls.Add(this.labelAxis6);
this.HID.Controls.Add(this.labelAxis5);
this.HID.Controls.Add(this.labelAxis4);
this.HID.Controls.Add(this.labelAxis3);
this.HID.Controls.Add(this.labelAxis2);
this.HID.Controls.Add(this.labelAxis1);
this.HID.Controls.Add(this.textBoxAxis10);
this.HID.Controls.Add(this.textBoxAxis9);
this.HID.Controls.Add(this.textBoxAxis8);
this.HID.Controls.Add(this.textBoxAxis7);
this.HID.Controls.Add(this.textBoxAxis6);
this.HID.Controls.Add(this.textBoxAxis5);
this.HID.Controls.Add(this.textBoxAxis4);
this.HID.Controls.Add(this.textBoxAxis3);
this.HID.Controls.Add(this.textBoxAxis2);
this.HID.Controls.Add(this.textBoxAxis1);
this.HID.Controls.Add(this.JoystickButtonsBox);
this.HID.Controls.Add(this.comboBoxActiveJoystick);
this.HID.Location = new System.Drawing.Point(4, 22);
this.HID.Name = "HID";
this.HID.Padding = new System.Windows.Forms.Padding(3);
this.HID.Size = new System.Drawing.Size(424, 352);
this.HID.Size = new System.Drawing.Size(424, 353);
this.HID.TabIndex = 2;
this.HID.Text = "HID";
this.HID.UseVisualStyleBackColor = true;
@ -364,12 +409,205 @@
//
this.PollTimer.Interval = 10;
//
// comboBoxActiveJoystick
//
this.comboBoxActiveJoystick.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.comboBoxActiveJoystick.FormattingEnabled = true;
this.comboBoxActiveJoystick.Location = new System.Drawing.Point(7, 7);
this.comboBoxActiveJoystick.Name = "comboBoxActiveJoystick";
this.comboBoxActiveJoystick.Size = new System.Drawing.Size(409, 21);
this.comboBoxActiveJoystick.TabIndex = 0;
//
// textBoxAxis1
//
this.textBoxAxis1.Location = new System.Drawing.Point(55, 43);
this.textBoxAxis1.Name = "textBoxAxis1";
this.textBoxAxis1.ReadOnly = true;
this.textBoxAxis1.Size = new System.Drawing.Size(129, 22);
this.textBoxAxis1.TabIndex = 2;
//
// textBoxAxis2
//
this.textBoxAxis2.Location = new System.Drawing.Point(55, 72);
this.textBoxAxis2.Name = "textBoxAxis2";
this.textBoxAxis2.ReadOnly = true;
this.textBoxAxis2.Size = new System.Drawing.Size(129, 22);
this.textBoxAxis2.TabIndex = 3;
//
// textBoxAxis3
//
this.textBoxAxis3.Location = new System.Drawing.Point(55, 101);
this.textBoxAxis3.Name = "textBoxAxis3";
this.textBoxAxis3.ReadOnly = true;
this.textBoxAxis3.Size = new System.Drawing.Size(129, 22);
this.textBoxAxis3.TabIndex = 4;
//
// textBoxAxis4
//
this.textBoxAxis4.Location = new System.Drawing.Point(55, 130);
this.textBoxAxis4.Name = "textBoxAxis4";
this.textBoxAxis4.ReadOnly = true;
this.textBoxAxis4.Size = new System.Drawing.Size(129, 22);
this.textBoxAxis4.TabIndex = 5;
//
// textBoxAxis5
//
this.textBoxAxis5.Location = new System.Drawing.Point(55, 158);
this.textBoxAxis5.Name = "textBoxAxis5";
this.textBoxAxis5.ReadOnly = true;
this.textBoxAxis5.Size = new System.Drawing.Size(129, 22);
this.textBoxAxis5.TabIndex = 6;
//
// textBoxAxis6
//
this.textBoxAxis6.Location = new System.Drawing.Point(55, 186);
this.textBoxAxis6.Name = "textBoxAxis6";
this.textBoxAxis6.ReadOnly = true;
this.textBoxAxis6.Size = new System.Drawing.Size(129, 22);
this.textBoxAxis6.TabIndex = 7;
//
// textBoxAxis7
//
this.textBoxAxis7.Location = new System.Drawing.Point(55, 214);
this.textBoxAxis7.Name = "textBoxAxis7";
this.textBoxAxis7.ReadOnly = true;
this.textBoxAxis7.Size = new System.Drawing.Size(129, 22);
this.textBoxAxis7.TabIndex = 8;
//
// textBoxAxis8
//
this.textBoxAxis8.Location = new System.Drawing.Point(55, 242);
this.textBoxAxis8.Name = "textBoxAxis8";
this.textBoxAxis8.ReadOnly = true;
this.textBoxAxis8.Size = new System.Drawing.Size(129, 22);
this.textBoxAxis8.TabIndex = 9;
//
// textBoxAxis9
//
this.textBoxAxis9.Location = new System.Drawing.Point(55, 270);
this.textBoxAxis9.Name = "textBoxAxis9";
this.textBoxAxis9.ReadOnly = true;
this.textBoxAxis9.Size = new System.Drawing.Size(129, 22);
this.textBoxAxis9.TabIndex = 10;
//
// textBoxAxis10
//
this.textBoxAxis10.Location = new System.Drawing.Point(55, 298);
this.textBoxAxis10.Name = "textBoxAxis10";
this.textBoxAxis10.ReadOnly = true;
this.textBoxAxis10.Size = new System.Drawing.Size(129, 22);
this.textBoxAxis10.TabIndex = 11;
//
// labelAxis1
//
this.labelAxis1.AutoSize = true;
this.labelAxis1.Location = new System.Drawing.Point(4, 46);
this.labelAxis1.Name = "labelAxis1";
this.labelAxis1.Size = new System.Drawing.Size(39, 13);
this.labelAxis1.TabIndex = 12;
this.labelAxis1.Text = "Axis 1:";
//
// labelAxis2
//
this.labelAxis2.AutoSize = true;
this.labelAxis2.Location = new System.Drawing.Point(4, 75);
this.labelAxis2.Name = "labelAxis2";
this.labelAxis2.Size = new System.Drawing.Size(39, 13);
this.labelAxis2.TabIndex = 13;
this.labelAxis2.Text = "Axis 2:";
//
// labelAxis3
//
this.labelAxis3.AutoSize = true;
this.labelAxis3.Location = new System.Drawing.Point(4, 104);
this.labelAxis3.Name = "labelAxis3";
this.labelAxis3.Size = new System.Drawing.Size(39, 13);
this.labelAxis3.TabIndex = 14;
this.labelAxis3.Text = "Axis 3:";
//
// labelAxis4
//
this.labelAxis4.AutoSize = true;
this.labelAxis4.Location = new System.Drawing.Point(4, 133);
this.labelAxis4.Name = "labelAxis4";
this.labelAxis4.Size = new System.Drawing.Size(39, 13);
this.labelAxis4.TabIndex = 15;
this.labelAxis4.Text = "Axis 4:";
//
// labelAxis5
//
this.labelAxis5.AutoSize = true;
this.labelAxis5.Location = new System.Drawing.Point(4, 161);
this.labelAxis5.Name = "labelAxis5";
this.labelAxis5.Size = new System.Drawing.Size(39, 13);
this.labelAxis5.TabIndex = 16;
this.labelAxis5.Text = "Axis 5:";
//
// labelAxis6
//
this.labelAxis6.AutoSize = true;
this.labelAxis6.Location = new System.Drawing.Point(4, 189);
this.labelAxis6.Name = "labelAxis6";
this.labelAxis6.Size = new System.Drawing.Size(39, 13);
this.labelAxis6.TabIndex = 17;
this.labelAxis6.Text = "Axis 6:";
//
// labelAxis7
//
this.labelAxis7.AutoSize = true;
this.labelAxis7.Location = new System.Drawing.Point(4, 217);
this.labelAxis7.Name = "labelAxis7";
this.labelAxis7.Size = new System.Drawing.Size(39, 13);
this.labelAxis7.TabIndex = 18;
this.labelAxis7.Text = "Axis 7:";
//
// labelAxis8
//
this.labelAxis8.AutoSize = true;
this.labelAxis8.Location = new System.Drawing.Point(4, 245);
this.labelAxis8.Name = "labelAxis8";
this.labelAxis8.Size = new System.Drawing.Size(39, 13);
this.labelAxis8.TabIndex = 18;
this.labelAxis8.Text = "Axis 8:";
//
// labelAxis9
//
this.labelAxis9.AutoSize = true;
this.labelAxis9.Location = new System.Drawing.Point(4, 273);
this.labelAxis9.Name = "labelAxis9";
this.labelAxis9.Size = new System.Drawing.Size(39, 13);
this.labelAxis9.TabIndex = 19;
this.labelAxis9.Text = "Axis 9:";
//
// labelAxis10
//
this.labelAxis10.AutoSize = true;
this.labelAxis10.Location = new System.Drawing.Point(4, 301);
this.labelAxis10.Name = "labelAxis10";
this.labelAxis10.Size = new System.Drawing.Size(45, 13);
this.labelAxis10.TabIndex = 20;
this.labelAxis10.Text = "Axis 10:";
//
// JoystickButtonsBox
//
this.JoystickButtonsBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.JoystickButtonsBox.FormattingEnabled = true;
this.JoystickButtonsBox.Location = new System.Drawing.Point(190, 43);
this.JoystickButtonsBox.Name = "JoystickButtonsBox";
this.JoystickButtonsBox.Size = new System.Drawing.Size(226, 303);
this.JoystickButtonsBox.TabIndex = 1;
//
// InputLogger
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(432, 378);
this.ClientSize = new System.Drawing.Size(432, 379);
this.Controls.Add(this.tabControl);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.MaximizeBox = false;
this.Name = "InputLogger";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "S04: Input Logger";
@ -378,6 +616,8 @@
this.Keyboard.PerformLayout();
this.Mouse.ResumeLayout(false);
this.Mouse.PerformLayout();
this.HID.ResumeLayout(false);
this.HID.PerformLayout();
this.ResumeLayout(false);
}
@ -415,6 +655,28 @@
private System.Windows.Forms.Label WindowY;
private System.Windows.Forms.Label WindowX;
private System.Windows.Forms.TextBox MouseYWindow;
private System.Windows.Forms.ComboBox comboBoxActiveJoystick;
private System.Windows.Forms.Label labelAxis10;
private System.Windows.Forms.Label labelAxis9;
private System.Windows.Forms.Label labelAxis8;
private System.Windows.Forms.Label labelAxis7;
private System.Windows.Forms.Label labelAxis6;
private System.Windows.Forms.Label labelAxis5;
private System.Windows.Forms.Label labelAxis4;
private System.Windows.Forms.Label labelAxis3;
private System.Windows.Forms.Label labelAxis2;
private System.Windows.Forms.Label labelAxis1;
private System.Windows.Forms.TextBox textBoxAxis10;
private System.Windows.Forms.TextBox textBoxAxis9;
private System.Windows.Forms.TextBox textBoxAxis8;
private System.Windows.Forms.TextBox textBoxAxis7;
private System.Windows.Forms.TextBox textBoxAxis6;
private System.Windows.Forms.TextBox textBoxAxis5;
private System.Windows.Forms.TextBox textBoxAxis4;
private System.Windows.Forms.TextBox textBoxAxis3;
private System.Windows.Forms.TextBox textBoxAxis2;
private System.Windows.Forms.TextBox textBoxAxis1;
private System.Windows.Forms.ListBox JoystickButtonsBox;
}
}

View file

@ -26,34 +26,44 @@ namespace Examples.Tests
[Example("Input Logger", ExampleCategory.Test)]
public partial class InputLogger : Form
{
#region Fields
Thread thread;
GameWindow hidden;
bool start;
Dictionary<IntPtr, ListBox> keyboardListBoxes = new Dictionary<IntPtr, ListBox>(4);
#endregion
#region Constructors
public InputLogger()
{
InitializeComponent();
}
#endregion
#region GameWindow
void LaunchGameWindow()
{
hidden = new GameWindow(320, 240, GraphicsMode.Default, "OpenTK | Hidden input window");
hidden.Load += hidden_Load;
hidden.Unload += hidden_Unload;
hidden.RenderFrame += new OpenTK.RenderFrameEvent(hidden_RenderFrame);
hidden.Run(60.0, 10.0);
hidden.Run(60.0, 0.0);
}
void hidden_RenderFrame(GameWindow sender, RenderFrameEventArgs e)
{
GL.Clear(ClearBufferMask.ColorBufferBit);
sender.SwapBuffers();
//Thread.Sleep(1);
}
void hidden_Load(GameWindow sender, EventArgs e)
{
hidden.VSync = VSyncMode.On;
start = true;
GL.ClearColor(Color.Black);
}
@ -66,6 +76,10 @@ namespace Examples.Tests
delegate void CloseTrigger(GameWindow sender, EventArgs e, Form f);
CloseTrigger on_hidden_unload = delegate(GameWindow sender, EventArgs e, Form f) { f.Close(); };
#endregion
#region Protected Members
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
@ -89,6 +103,26 @@ namespace Examples.Tests
hidden.Keyboard.KeyDown += LogKeyDown;
hidden.Keyboard.KeyUp += LogKeyUp;
#region Joysticks
foreach (JoystickDevice joystick in hidden.Joysticks)
{
joystick.Move += delegate(object sender, JoystickMoveEventArgs args)
{
this.BeginInvoke(ControlLogJoystickMoved);
};
joystick.ButtonDown += delegate(object sender, JoystickButtonEventArgs args)
{
this.BeginInvoke(ControlLogJoystickButtonDown);
};
joystick.ButtonUp += delegate(object sender, JoystickButtonEventArgs args)
{
this.BeginInvoke(ControlLogJoystickButtonUp);
};
}
#endregion
}
protected override void OnClosing(CancelEventArgs e)
@ -103,8 +137,21 @@ namespace Examples.Tests
e.Cancel = false;
}
#endregion
#region Private Members
private void ChooseMouse_SelectedIndexChanged(object sender, EventArgs e)
{
MouseButtonsBox.Items.Clear();
}
#endregion
#region Logging Delegates
#region Mice
delegate void ControlLogMouseKey(GameWindow input_window, InputLogger control, object sender, MouseButtonEventArgs e);
ControlLogMouseKey ControlLogMouseKeyDown =
delegate(GameWindow input_window, InputLogger control, object sender, MouseButtonEventArgs e)
@ -140,6 +187,10 @@ namespace Examples.Tests
control.MouseWheelText.Text = e.Value.ToString();
};
#endregion
#region Keyboards
delegate void ControlLogKeyboard(GameWindow input_window, InputLogger control, OpenTK.Input.KeyboardDevice sender, Key key);
ControlLogKeyboard ControlLogKeyboardDown =
delegate(GameWindow input_window, InputLogger control, KeyboardDevice sender, Key key)
@ -154,6 +205,52 @@ namespace Examples.Tests
#endregion
#region Joysticks
delegate void ControlLogJoystickMove(GameWindow input_window, InputLogger control, OpenTK.Input.JoystickDevice sender, JoystickMoveEventArgs e);
ControlLogJoystickMove ControlLogJoystickMoved =
delegate(GameWindow input_window, InputLogger control, OpenTK.Input.JoystickDevice sender, JoystickMoveEventArgs e)
{
// Yes, there are things such as arrays. Tell that to the visual studio designer!
switch (e.Index)
{
case 1: control.textBoxAxis1.Text = e.Value.ToString(); break;
case 2: control.textBoxAxis2.Text = e.Value.ToString(); break;
case 3: control.textBoxAxis3.Text = e.Value.ToString(); break;
case 4: control.textBoxAxis4.Text = e.Value.ToString(); break;
case 5: control.textBoxAxis5.Text = e.Value.ToString(); break;
case 6: control.textBoxAxis6.Text = e.Value.ToString(); break;
case 7: control.textBoxAxis7.Text = e.Value.ToString(); break;
case 8: control.textBoxAxis8.Text = e.Value.ToString(); break;
case 9: control.textBoxAxis9.Text = e.Value.ToString(); break;
case 10: control.textBoxAxis10.Text = e.Value.ToString(); break;
}
};
delegate void ControlLogJoystickButton(InputLogger control, JoystickDevice sender, JoystickButtonEventArgs e);
ControlLogJoystickButton ControlLogJoystickButtonDown =
delegate(InputLogger control, JoystickDevice sender, JoystickButtonEventArgs e)
{
if ((sender as JoystickDevice).Description == control.comboBoxActiveJoystick.Text)
{
control.JoystickButtonsBox.Items.Add(e.Button);
System.Diagnostics.Debug.Print("Joystick button down: {0}", e.Button);
}
};
ControlLogJoystickButton ControlLogJoystickButtonUp =
delegate(InputLogger control, JoystickDevice sender, JoystickButtonEventArgs e)
{
if ((sender as JoystickDevice).Description == control.comboBoxActiveJoystick.Text)
{
control.JoystickButtonsBox.Items.Remove(e.Button);
System.Diagnostics.Debug.Print("Joystick button down: {0}", e.Button);
}
};
#endregion
#endregion
#region Input Event Handlers
void LogMouseMove(object sender, MouseMoveEventArgs e)
@ -188,11 +285,6 @@ namespace Examples.Tests
#endregion
private void ChooseMouse_SelectedIndexChanged(object sender, EventArgs e)
{
MouseButtonsBox.Items.Clear();
}
#region public static void Main()
/// <summary>

View file

@ -828,12 +828,6 @@ namespace OpenTK
{
get
{
if (disposed) throw new ObjectDisposedException("GameWindow");
//if (input_driver.Keyboard.Count > 0)
// return input_driver.Keyboard[0];
//else
// return null;
if (glWindow.InputDriver.Keyboard.Count > 0)
return glWindow.InputDriver.Keyboard[0];
else
@ -852,12 +846,6 @@ namespace OpenTK
{
get
{
if (disposed) throw new ObjectDisposedException("GameWindow");
//if (input_driver.Mouse.Count > 0)
// return input_driver.Mouse[0];
//else
// return null;
if (glWindow.InputDriver.Mouse.Count > 0)
return glWindow.InputDriver.Mouse[0];
else
@ -867,6 +855,18 @@ namespace OpenTK
#endregion
#region public IList<JoystickDevice> Joysticks
/// <summary>
/// Gets a readonly IList containing all available OpenTK.Input.JoystickDevices.
/// </summary>
public IList<JoystickDevice> Joysticks
{
get { return glWindow.InputDriver.Joysticks; }
}
#endregion
#region public VSyncMode VSync
/// <summary>

View file

@ -30,6 +30,9 @@ using System.Collections.Generic;
namespace OpenTK.Input
{
/// <summary>
/// Represents a joystick device and provides methods to query its status.
/// </summary>
public abstract class JoystickDevice : IInputDevice
{
#region Fields
@ -40,6 +43,8 @@ namespace OpenTK.Input
List<bool> button = new List<bool>();
IList<float> axis_readonly;
IList<bool> button_readonly;
JoystickMoveEventArgs move_args = new JoystickMoveEventArgs(0, 0, 0);
JoystickButtonEventArgs button_args = new JoystickButtonEventArgs(0, false);
#endregion
@ -65,20 +70,32 @@ namespace OpenTK.Input
#region Public Members
/// <summary>
/// Gets a readonly IList containing the state of each axis on this instance. Values are normalized in the [-1, 1] range.
/// </summary>
public IList<float> Axis { get { return axis_readonly; } }
/// <summary>
/// Gets a readonly IList containing the state of each button on this instance. True indicates that the button is pressed.
/// </summary>
public IList<bool> Button { get { return button_readonly; } }
#endregion
#region IInputDevice Members
/// <summary>
/// Gets a System.String containing a unique description for this instance.
/// </summary>
public string Description
{
get { return description; }
internal set { description = value; }
}
/// <summary>
/// Gets a value indicating the InputDeviceType of this InputDevice.
/// </summary>
public InputDeviceType DeviceType
{
get { return InputDeviceType.Hid; }
@ -86,6 +103,28 @@ namespace OpenTK.Input
#endregion
#region Events
/// <summary>
/// Occurs when an axis of this JoystickDevice instance is moved.
/// </summary>
public EventHandler<JoystickMoveEventArgs> Move =
delegate(object sender, JoystickMoveEventArgs e) { };
/// <summary>
/// Occurs when a button of this JoystickDevice instance is pressed.
/// </summary>
public EventHandler<JoystickButtonEventArgs> ButtonDown =
delegate(object sender, JoystickButtonEventArgs e) { };
/// <summary>
/// Occurs when a button of this JoystickDevice is released.
/// </summary>
public EventHandler<JoystickButtonEventArgs> ButtonUp =
delegate(object sender, JoystickButtonEventArgs e) { };
#endregion
#region Internal Members
internal int Id
@ -96,17 +135,30 @@ namespace OpenTK.Input
internal void SetAxis(int num, float @value)
{
axis[num] = @value;
move_args.Index = num;
move_args.Delta = move_args.Value - @value;
axis[num] = move_args.Value = @value;
Move(this, move_args);
}
internal void SetButton(int num, bool @value)
{
button[num] = @value;
if (button[num] != @value)
{
button_args.Button = num;
button[num] = button_args.Pressed = @value;
if (@value)
ButtonDown(this, button_args);
else
ButtonUp(this, button_args);
}
}
#endregion
}
#region JoystickDevice<TDetail> : JoystickDevice
// Provides platform-specific information about the relevant JoystickDevice.
internal sealed class JoystickDevice<TDetail> : JoystickDevice
{
@ -118,4 +170,111 @@ namespace OpenTK.Input
internal TDetail Details { get { return details; } set { details = value; } }
}
#endregion
#region Event Arguments
/// <summary>
/// The base class for JoystickDevice event arguments.
/// </summary>
public class JoystickEventArgs : EventArgs
{
}
/// <summary>
/// Provides data for the <see cref="JoystickDevice.ButtonDown"/> and <see cref="JoystickDevice.ButtonUp"/> events.
/// This class is cached for performance reasons - avoid storing references outside the scope of the event.
/// </summary>
public class JoystickButtonEventArgs : EventArgs
{
#region Fields
int button;
bool pressed;
#endregion
#region Constructors
/// <summary>
/// Initializes a new instance of the <see cref="JoystickButtonEventArgs"/> class.
/// </summary>
/// <param name="button">The index of the joystick button for the event.</param>
/// <param name="pressed">The current state of the button.</param>
internal JoystickButtonEventArgs(int button, bool pressed)
{
this.button = button;
this.pressed = pressed;
}
#endregion
#region Public Members
/// <summary>
/// The index of the joystick button for the event.
/// </summary>
public int Button { get { return this.button; } internal set { this.button = value; } }
/// <summary>
/// Gets a System.Boolean representing the state of the button for the event.
/// </summary>
public bool Pressed { get { return pressed; } internal set { this.pressed = value; } }
#endregion
}
/// <summary>
/// Provides data for the <see cref="JoystickDevice.Move"/> event.
/// This class is cached for performance reasons - avoid storing references outside the scope of the event.
/// </summary>
public class JoystickMoveEventArgs : JoystickEventArgs
{
#region Fields
int index;
float value;
float delta;
#endregion
#region Constructors
/// <summary>
/// Initializes a new instance of the <see cref="JoystickMoveEventArgs"/> class.
/// </summary>
/// <param name="index">The index of the joystick axis that was moved.</param>
/// <param name="value">The absolute value of the joystick axis.</param>
/// <param name="delta">The relative change in value of the joystick axis.</param>
public JoystickMoveEventArgs(int index, float value, float delta)
{
this.index = index;
this.value = value;
this.delta = delta;
}
#endregion
#region Public Members
/// <summary>
/// Gets a System.Int32 representing the index of the axis that was moved.
/// </summary>
public int Index { get { return index; } internal set { this.index = value; } }
/// <summary>
/// Gets a System.Single representing the absolute position of the axis.
/// </summary>
public float Value { get { return value; } internal set { this.value = value; } }
/// <summary>
/// Gets a System.Single representing the relative change in the position of the axis.
/// </summary>
public float Delta { get { return delta; } internal set { this.delta = delta; } }
#endregion
}
#endregion
}