Fixed data marshaling to winforms thread.

This commit is contained in:
the_fiddler 2008-01-06 02:18:58 +00:00
parent ab4e1b6a0f
commit 8476ff2c08
2 changed files with 104 additions and 32 deletions

View file

@ -40,6 +40,8 @@
this.listBox2 = new System.Windows.Forms.ListBox();
this.listBox1 = new System.Windows.Forms.ListBox();
this.Mouse = new System.Windows.Forms.TabPage();
this.MouseWheelDelta = new System.Windows.Forms.TextBox();
this.WheelDelta = new System.Windows.Forms.Label();
this.MouseWheelText = new System.Windows.Forms.TextBox();
this.MouseWheel = new System.Windows.Forms.Label();
this.MouseDeltaY = new System.Windows.Forms.Label();
@ -53,9 +55,11 @@
this.MouseButtons = new System.Windows.Forms.ListBox();
this.ChooseMouse = new System.Windows.Forms.ComboBox();
this.HID = new System.Windows.Forms.TabPage();
this.WheelDelta = new System.Windows.Forms.Label();
this.MouseWheelDelta = new System.Windows.Forms.TextBox();
this.PollTimer = new System.Windows.Forms.Timer(this.components);
this.MouseXWindow = new System.Windows.Forms.TextBox();
this.MouseYWindow = new System.Windows.Forms.TextBox();
this.WindowX = new System.Windows.Forms.Label();
this.WindowY = new System.Windows.Forms.Label();
this.tabControl.SuspendLayout();
this.Keyboard.SuspendLayout();
this.Mouse.SuspendLayout();
@ -162,6 +166,10 @@
// Mouse
//
this.Mouse.BackColor = System.Drawing.SystemColors.ControlLight;
this.Mouse.Controls.Add(this.WindowY);
this.Mouse.Controls.Add(this.WindowX);
this.Mouse.Controls.Add(this.MouseYWindow);
this.Mouse.Controls.Add(this.MouseXWindow);
this.Mouse.Controls.Add(this.MouseWheelDelta);
this.Mouse.Controls.Add(this.WheelDelta);
this.Mouse.Controls.Add(this.MouseWheelText);
@ -183,6 +191,23 @@
this.Mouse.TabIndex = 1;
this.Mouse.Text = "Mouse";
//
// MouseWheelDelta
//
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.TabIndex = 13;
//
// WheelDelta
//
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.TabIndex = 12;
this.WheelDelta.Text = "Wheel Delta:";
//
// MouseWheelText
//
this.MouseWheelText.Location = new System.Drawing.Point(80, 152);
@ -196,9 +221,9 @@
this.MouseWheel.AutoSize = true;
this.MouseWheel.Location = new System.Drawing.Point(4, 159);
this.MouseWheel.Name = "MouseWheel";
this.MouseWheel.Size = new System.Drawing.Size(38, 13);
this.MouseWheel.Size = new System.Drawing.Size(41, 13);
this.MouseWheel.TabIndex = 10;
this.MouseWheel.Text = "Wheel";
this.MouseWheel.Text = "Wheel:";
//
// MouseDeltaY
//
@ -296,27 +321,44 @@
this.HID.Text = "HID";
this.HID.UseVisualStyleBackColor = true;
//
// WheelDelta
//
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.TabIndex = 12;
this.WheelDelta.Text = "Wheel Delta:";
//
// MouseWheelDelta
//
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.TabIndex = 13;
//
// PollTimer
//
this.PollTimer.Interval = 10;
//
// MouseXWindow
//
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.TabIndex = 14;
//
// MouseYWindow
//
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.TabIndex = 15;
//
// WindowX
//
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.TabIndex = 16;
this.WindowX.Text = "Window X:";
//
// WindowY
//
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.TabIndex = 17;
this.WindowY.Text = "Window Y:";
//
// S04_Input_Logger
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@ -364,6 +406,10 @@
private System.Windows.Forms.TextBox MouseWheelDelta;
private System.Windows.Forms.Label WheelDelta;
private System.Windows.Forms.Timer PollTimer;
private System.Windows.Forms.TextBox MouseXWindow;
private System.Windows.Forms.Label WindowY;
private System.Windows.Forms.Label WindowX;
private System.Windows.Forms.TextBox MouseYWindow;
}
}

View file

@ -20,6 +20,18 @@ using System.Threading;
namespace Examples.Tests
{
[System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Sequential)]
struct TryMouse
{
ushort usFlags;
ushort usButtonFlags;
ushort usButtonData;
uint ulRawButtons;
int lLastX;
int lLastY;
uint ulExtraInformation;
}
[Example("Input Logger", ExampleCategory.Test, 4)]
public partial class S04_Input_Logger : Form
{
@ -30,6 +42,8 @@ namespace Examples.Tests
public S04_Input_Logger()
{
//Console.WriteLine(sizeof(TryMouse));
Console.WriteLine(System.Runtime.InteropServices.Marshal.SizeOf(typeof(TryMouse)));
InitializeComponent();
}
@ -37,14 +51,22 @@ namespace Examples.Tests
{
hidden = new GameWindow(new DisplayMode(30, 30), "OpenTK | Hidden input window");
hidden.Load += hidden_Load;
hidden.Unload += hidden_Unload;
hidden.Run(60.0, 1.0);
}
void hidden_Load(object sender, EventArgs e)
void hidden_Load(GameWindow sender, EventArgs e)
{
start = true;
}
void hidden_Unload(GameWindow sender, EventArgs e)
{
this.BeginInvoke(on_hidden_unload, sender, e, this);
}
delegate void CloseTrigger(GameWindow sender, EventArgs e, Form f);
CloseTrigger on_hidden_unload = delegate(GameWindow sender, EventArgs e, Form f) { f.Close(); };
protected override void OnLoad(EventArgs e)
{
@ -84,21 +106,21 @@ namespace Examples.Tests
}
delegate void ControlLogMouseKey(GameWindow input_window, S04_Input_Logger control, MouseDevice sender, MouseButton button);
ControlLogMouseKey ControlLogMouseKeyDown = new ControlLogMouseKey(
ControlLogMouseKey ControlLogMouseKeyDown =
delegate(GameWindow input_window, S04_Input_Logger control, MouseDevice sender, MouseButton button)
{
if (sender.DeviceID == input_window.Mouse.DeviceID)
control.MouseButtons.Items.Add(button);
});
ControlLogMouseKey ControlLogMouseKeyUp = new ControlLogMouseKey(
};
ControlLogMouseKey ControlLogMouseKeyUp =
delegate(GameWindow input_window, S04_Input_Logger control, MouseDevice sender, MouseButton button)
{
if (sender.DeviceID == input_window.Mouse.DeviceID)
control.MouseButtons.Items.Remove(button);
});
};
delegate void ControlLogMousePosition(GameWindow input_window, S04_Input_Logger control);
ControlLogMousePosition ControlLogMousePositionChanges = new ControlLogMousePosition(
ControlLogMousePosition ControlLogMousePositionChanges =
delegate(GameWindow input_window, S04_Input_Logger control)
{
// Update mouse coordinates.
@ -107,20 +129,24 @@ namespace Examples.Tests
control.MouseDXText.Text = input_window.Mouse.XDelta.ToString();
control.MouseDYText.Text = input_window.Mouse.YDelta.ToString();
control.MouseWheelText.Text = input_window.Mouse.Wheel.ToString();
//System.Drawing.Point p = input_window.PointToClient(input_window.Mouse.Position);
//System.Drawing.Point p = control.PointToClient(input_window.Mouse.Position);
//control.MouseXWindow.Text = p.X.ToString();
//control.MouseYWindow.Text = p.Y.ToString();
//MouseWheelDelta.Text = driver.Mouse[ChooseMouse.SelectedIndex].WheelDelta.ToString();
});
};
delegate void ControlLogKeyboard(GameWindow input_window, S04_Input_Logger control, KeyboardDevice sender, Key key);
ControlLogKeyboard ControlLogKeyboardDown = new ControlLogKeyboard(
ControlLogKeyboard ControlLogKeyboardDown =
delegate(GameWindow input_window, S04_Input_Logger control, KeyboardDevice sender, Key key)
{
control.keyboardListBoxes[(sender as KeyboardDevice).DeviceID].Items.Add(key);
});
ControlLogKeyboard ControlLogKeyboardUp = new ControlLogKeyboard(
};
ControlLogKeyboard ControlLogKeyboardUp =
delegate(GameWindow input_window, S04_Input_Logger control, KeyboardDevice sender, Key key)
{
control.keyboardListBoxes[(sender as KeyboardDevice).DeviceID].Items.Remove(key);
});
};
void hidden_UpdateFrame(object sender, UpdateFrameEventArgs e)
{