mirror of
https://github.com/Ryujinx/Opentk.git
synced 2025-06-06 08:38:19 +00:00
Fixed cross-threading calls into Windows.Forms, using delegates and BeginInvoke().
This commit is contained in:
parent
4b51e1c0e6
commit
b51c6f5163
|
@ -20,7 +20,8 @@ using System.Threading;
|
||||||
|
|
||||||
namespace Examples.Tests
|
namespace Examples.Tests
|
||||||
{
|
{
|
||||||
public partial class S04_Input_Logger : Form//, IExample
|
[Example("Input Logger", ExampleCategory.Test, 4)]
|
||||||
|
public partial class S04_Input_Logger : Form
|
||||||
{
|
{
|
||||||
Thread thread;
|
Thread thread;
|
||||||
GameWindow hidden;
|
GameWindow hidden;
|
||||||
|
@ -30,9 +31,6 @@ namespace Examples.Tests
|
||||||
public S04_Input_Logger()
|
public S04_Input_Logger()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
thread = new Thread(LaunchGameWindow);
|
|
||||||
thread.Start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LaunchGameWindow()
|
void LaunchGameWindow()
|
||||||
|
@ -47,14 +45,16 @@ namespace Examples.Tests
|
||||||
start = true;
|
start = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected override void OnLoad(EventArgs e)
|
protected override void OnLoad(EventArgs e)
|
||||||
{
|
{
|
||||||
base.OnLoad(e);
|
base.OnLoad(e);
|
||||||
|
|
||||||
|
thread = new Thread(LaunchGameWindow);
|
||||||
|
thread.Start();
|
||||||
|
|
||||||
while (!start)
|
while (!start)
|
||||||
{
|
|
||||||
Thread.Sleep(100);
|
Thread.Sleep(100);
|
||||||
}
|
|
||||||
|
|
||||||
WindowInfo info = new WindowInfo(this);
|
WindowInfo info = new WindowInfo(this);
|
||||||
|
|
||||||
|
@ -70,62 +70,105 @@ namespace Examples.Tests
|
||||||
|
|
||||||
//Application.Idle += new EventHandler(UpdateDevices);
|
//Application.Idle += new EventHandler(UpdateDevices);
|
||||||
hidden.UpdateFrame += hidden_UpdateFrame;
|
hidden.UpdateFrame += hidden_UpdateFrame;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override void OnClosing(CancelEventArgs e)
|
||||||
|
{
|
||||||
|
base.OnClosing(e);
|
||||||
|
|
||||||
|
hidden.Exit();
|
||||||
|
while (hidden.Exists)
|
||||||
|
Thread.Sleep(100);
|
||||||
|
|
||||||
|
e.Cancel = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
delegate void ControlLogMouseKey(GameWindow input_window, S04_Input_Logger control, MouseDevice sender, MouseButton button);
|
||||||
|
ControlLogMouseKey ControlLogMouseKeyDown = new ControlLogMouseKey(
|
||||||
|
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(
|
||||||
|
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(
|
||||||
|
delegate(GameWindow input_window, S04_Input_Logger control)
|
||||||
|
{
|
||||||
|
// Update mouse coordinates.
|
||||||
|
control.MouseXText.Text = input_window.Mouse.X.ToString();
|
||||||
|
control.MouseYText.Text = input_window.Mouse.Y.ToString();
|
||||||
|
control.MouseDXText.Text = input_window.Mouse.XDelta.ToString();
|
||||||
|
control.MouseDYText.Text = input_window.Mouse.YDelta.ToString();
|
||||||
|
control.MouseWheelText.Text = input_window.Mouse.Wheel.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(
|
||||||
|
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(
|
||||||
|
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)
|
void hidden_UpdateFrame(object sender, UpdateFrameEventArgs e)
|
||||||
{
|
{
|
||||||
//hidden.Poll();
|
this.BeginInvoke(ControlLogMousePositionChanges, hidden, this);
|
||||||
|
|
||||||
// Update mouse coordinates.
|
|
||||||
MouseXText.Text = hidden.Mouse.X.ToString();
|
|
||||||
MouseYText.Text = hidden.Mouse.Y.ToString();
|
|
||||||
MouseDXText.Text = hidden.Mouse.XDelta.ToString();
|
|
||||||
MouseDYText.Text = hidden.Mouse.YDelta.ToString();
|
|
||||||
MouseWheelText.Text = hidden.Mouse.Wheel.ToString();
|
|
||||||
//MouseWheelDelta.Text = driver.Mouse[ChooseMouse.SelectedIndex].WheelDelta.ToString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LogMouseButtonDown(MouseDevice sender, MouseButton button)
|
void LogMouseButtonDown(MouseDevice sender, MouseButton button)
|
||||||
{
|
{
|
||||||
//Trace.WriteLine(String.Format("Mouse button down: {0} on device: {1}", button, sender.DeviceID));
|
this.BeginInvoke(ControlLogMouseKeyDown, hidden, this, sender, button);
|
||||||
if (sender.DeviceID == hidden.Mouse.DeviceID)
|
|
||||||
MouseButtons.Items.Add(button);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LogMouseButtonUp(MouseDevice sender, MouseButton button)
|
void LogMouseButtonUp(MouseDevice sender, MouseButton button)
|
||||||
{
|
{
|
||||||
//Trace.WriteLine(String.Format("Mouse button up: {0} on device: {1}", button, sender.DeviceID));
|
this.BeginInvoke(ControlLogMouseKeyUp, hidden, this, sender, button);
|
||||||
if (sender.DeviceID == hidden.Mouse.DeviceID)
|
|
||||||
MouseButtons.Items.Remove(button);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LogKeyDown(KeyboardDevice sender, Key key)
|
void LogKeyDown(KeyboardDevice sender, Key key)
|
||||||
{
|
{
|
||||||
Trace.WriteLine(String.Format("Key down: {0} on device: {1}", key, (sender as KeyboardDevice).DeviceID));
|
this.BeginInvoke(ControlLogKeyboardDown, hidden, this, sender, key);
|
||||||
keyboardListBoxes[(sender as KeyboardDevice).DeviceID].Items.Add(key);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LogKeyUp(KeyboardDevice sender, Key key)
|
void LogKeyUp(KeyboardDevice sender, Key key)
|
||||||
{
|
{
|
||||||
Trace.WriteLine(String.Format("Key up: {0} on device: {1}", key, (sender as KeyboardDevice).DeviceID));
|
this.BeginInvoke(ControlLogKeyboardUp, hidden, this, sender, key);
|
||||||
keyboardListBoxes[(sender as KeyboardDevice).DeviceID].Items.Remove(key);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#region IExample Members
|
|
||||||
|
|
||||||
public void Launch()
|
|
||||||
{
|
|
||||||
// Empty
|
|
||||||
}
|
|
||||||
|
|
||||||
public static readonly int order = 2;
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
private void ChooseMouse_SelectedIndexChanged(object sender, EventArgs e)
|
private void ChooseMouse_SelectedIndexChanged(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
MouseButtons.Items.Clear();
|
MouseButtons.Items.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#region public static void Main()
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Entry point of this example.
|
||||||
|
/// </summary>
|
||||||
|
[STAThread]
|
||||||
|
public static void Main()
|
||||||
|
{
|
||||||
|
using (S04_Input_Logger example = new S04_Input_Logger())
|
||||||
|
{
|
||||||
|
// Get the title and category of this example using reflection.
|
||||||
|
ExampleAttribute info = ((ExampleAttribute)example.GetType().GetCustomAttributes(false)[0]);
|
||||||
|
example.Text = String.Format("OpenTK | {0} {1}: {2}", info.Category, info.Difficulty, info.Title);
|
||||||
|
example.ShowDialog();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue