public override bool Initialize(GameHost host) { host.InputThread.Scheduler.Add(scheduled = new ScheduledDelegate(delegate { if (host.Window.WindowState == WindowState.Minimized) { return; } var state = OpenTK.Input.Mouse.GetCursorState(); if (state.Equals(lastState)) { return; } lastState = state; Point point = host.Window.PointToClient(new Point(state.X, state.Y)); Vector2 pos = new Vector2(point.X, point.Y); PendingStates.Enqueue(new InputState { Mouse = new TkMouseState(state, pos, host.IsActive) }); FrameStatistics.Increment(StatisticsCounterType.MouseEvents); }, 0, 0)); return(true); }
private void handleState(MouseState state) { PendingStates.Enqueue(new InputState { Mouse = state }); FrameStatistics.Increment(StatisticsCounterType.MouseEvents); }
public override bool Initialize(BasicGameHost host) { host.InputScheduler.Add(new ScheduledDelegate(delegate { OpenTK.Input.MouseState state = OpenTK.Input.Mouse.GetCursorState(); Point point = host.Window.PointToClient(new Point(state.X, state.Y)); //todo: reimplement if necessary //Vector2 pos = Vector2.Multiply(point, Vector2.Divide(host.DrawSize, this.Size)); Vector2 pos = new Vector2(point.X, point.Y); var tkState = new TkMouseState(state, pos); if (!host.IsActive) { tkState.ButtonStates.ForEach(s => s.State = false); tkState.Wheel = tkState.LastState?.Wheel ?? 0; } PendingStates.Enqueue(new InputState { Mouse = tkState }); }, 0, 0)); return(true); }
public void MoveMouseTo(Vector2 position) { PendingStates.Enqueue(new InputState { Mouse = new MouseState { Position = position } }); lastMousePosition = position; }
public void EnqueueState(InputState state) { if (state.Mouse is MouseState ms) { lastMouseState = ms; } PendingStates.Enqueue(state); }
public void PressKey(Key key) { pressedKeys.Add(key); PendingStates.Enqueue(new InputState { Keyboard = new Framework.Input.KeyboardState { Keys = pressedKeys } }); }
private void handleState(MouseState state) { // combine wheel values to avoid discrepancy between sources. state = (MouseState)state.Clone(); state.Wheel = (lastEventState?.Wheel ?? 0) + (lastPollState?.Wheel ?? 0); PendingStates.Enqueue(new InputState { Mouse = state }); FrameStatistics.Increment(StatisticsCounterType.MouseEvents); }
private void handleState(MouseState state) { // combine wheel values to avoid discrepancy between sources. state = (MouseState)state.Clone(); state.Scroll = (lastUnfocusedState?.Scroll ?? Vector2.Zero) + (lastRawState?.Scroll ?? Vector2.Zero); PendingStates.Enqueue(new InputState { Mouse = state }); FrameStatistics.Increment(StatisticsCounterType.MouseEvents); }
public override bool Initialize(BasicGameHost host) { host.InputThread.Scheduler.Add(new ScheduledDelegate(delegate { PendingStates.Enqueue(new InputState { Keyboard = new TkKeyboardState(host.IsActive ? OpenTK.Input.Keyboard.GetState() : new OpenTK.Input.KeyboardState()) }); }, 0, 0)); return(true); }
public void ReleaseKey(Key key) { if (!pressedKeys.Remove(key)) { return; } PendingStates.Enqueue(new InputState { Keyboard = new Framework.Input.KeyboardState { Keys = pressedKeys } }); }
public void ScrollBy(int delta) { PendingStates.Enqueue(new InputState { Mouse = new MouseState { Position = lastMousePosition, Wheel = lastWheel + delta } }); lastWheel += delta; }
public override bool Initialize(GameHost host) { host.InputThread.Scheduler.Add(scheduled = new ScheduledDelegate(delegate { PendingStates.Enqueue(new InputState { Keyboard = new TkKeyboardState(host.IsActive ? OpenTK.Input.Keyboard.GetState() : new OpenTK.Input.KeyboardState()) }); FrameStatistics.Increment(StatisticsCounterType.KeyEvents); }, 0, 0)); return(true); }
private void handleState(object sender, KeyboardKeyEventArgs e) { var state = e.Keyboard; if (state.Equals(lastState)) { return; } lastState = state; PendingStates.Enqueue(new InputState { Keyboard = new TkKeyboardState(state) }); FrameStatistics.Increment(StatisticsCounterType.KeyEvents); }
public void Click(MouseButton button) { var mouseState = new MouseState { Position = lastMousePosition }; mouseState.SetPressed(button, true); PendingStates.Enqueue(new InputState { Mouse = mouseState }); mouseState = (MouseState)mouseState.Clone(); mouseState.SetPressed(button, false); PendingStates.Enqueue(new InputState { Mouse = mouseState }); }
private void handleTouches(object sender, View.TouchEventArgs e) { var basicState = new Framework.Input.MouseState { Position = new Vector2(e.Event.GetX(), e.Event.GetY()) }; switch (e.Event.ActionMasked) { case MotionEventActions.Down: case MotionEventActions.Move: basicState.SetPressed(MouseButton.Left, true); PendingStates.Enqueue(new InputState { Mouse = basicState }); break; case MotionEventActions.Up: PendingStates.Enqueue(new InputState { Mouse = basicState }); break; } /* Multi-touch? * * var pointerIndex = e.Event.ActionIndex; * * var pointerId = e.Event.GetPointerId(pointerIndex); * * switch (e.Event.ActionMasked) * { * case MotionEventActions.Down: * case MotionEventActions.PointerDown: * * break; * case MotionEventActions.Up: * case MotionEventActions.PointerUp: * * break; * }*/ }
public override bool Initialize(GameHost host) { Enabled.ValueChanged += enabled => { if (enabled) { host.InputThread.Scheduler.Add(scheduled = new ScheduledDelegate(delegate { refreshDevices(); foreach (var device in devices) { if (device.State.Equals(device.LastState)) { continue; } if (device.LastState != null) { PendingStates.Enqueue(new InputState { Joystick = new OpenTKJoystickState(device) }); FrameStatistics.Increment(StatisticsCounterType.JoystickEvents); } } }, 0, 0)); } else { scheduled?.Cancel(); devices.Clear(); } }; Enabled.TriggerChange(); return(true); }
public override bool Initialize(GameHost host) { host.InputThread.Scheduler.Add(scheduled = new ScheduledDelegate(delegate { OpenTK.Input.MouseState state = OpenTK.Input.Mouse.GetCursorState(); Point point = host.Window.PointToClient(new Point(state.X, state.Y)); //todo: reimplement if necessary //Vector2 pos = Vector2.Multiply(point, Vector2.Divide(host.DrawSize, this.Size)); Vector2 pos = new Vector2(point.X, point.Y); var tkState = new TkMouseState(state, pos, host.IsActive); PendingStates.Enqueue(new InputState { Mouse = tkState }); FrameStatistics.Increment(StatisticsCounterType.MouseEvents); }, 0, 0)); return(true); }
public override bool Initialize(GameHost host) { host.InputThread.Scheduler.Add(scheduled = new ScheduledDelegate(delegate { if (!host.Window.Visible) { return; } var state = OpenTK.Input.Mouse.GetCursorState(); if (state.Equals(lastState)) { return; } lastState = state; Point point = host.Window.PointToClient(new Point(state.X, state.Y)); Vector2 pos = new Vector2(point.X, point.Y); // While not focused, let's silently ignore everything but position. if (!host.Window.Focused) { state = new OpenTK.Input.MouseState(); } PendingStates.Enqueue(new InputState { Mouse = new TkMouseState(state, pos, host.IsActive) }); FrameStatistics.Increment(StatisticsCounterType.MouseEvents); }, 0, 0)); return(true); }
public override bool Initialize(GameHost host) { host.Window.MouseEnter += window_MouseEnter; host.Window.MouseLeave += window_MouseLeave; mouseInWindow = host.Window.CursorInWindow; // Get the bindables we need to determine whether to confine the mouse to window or not DesktopGameWindow desktopWindow = host.Window as DesktopGameWindow; if (desktopWindow != null) { confineMode.BindTo(desktopWindow.ConfineMouseMode); windowMode.BindTo(desktopWindow.WindowMode); } Enabled.ValueChanged += enabled => { if (enabled) { host.InputThread.Scheduler.Add(scheduled = new ScheduledDelegate(delegate { if (!host.Window.Visible) { return; } bool useRawInput = mouseInWindow && host.Window.Focused; var state = useRawInput ? OpenTK.Input.Mouse.GetState() : OpenTK.Input.Mouse.GetCursorState(); if (state.Equals(lastState)) { return; } if (useRawInput) { if (!lastState.HasValue) { // when we return from being outside of the window, we want to set the new position of our game cursor // to where the OS cursor is, just once. var cursorState = OpenTK.Input.Mouse.GetCursorState(); var screenPoint = host.Window.PointToClient(new Point(cursorState.X, cursorState.Y)); currentPosition = new Vector2(screenPoint.X, screenPoint.Y); } else { currentPosition += new Vector2(state.X - lastState.Value.X, state.Y - lastState.Value.Y) * (float)sensitivity.Value; // When confining, clamp to the window size. if (confineMode.Value == ConfineMouseMode.Always || confineMode.Value == ConfineMouseMode.Fullscreen && windowMode.Value == WindowMode.Fullscreen) { currentPosition = Vector2.Clamp(currentPosition, Vector2.Zero, new Vector2(host.Window.Width, host.Window.Height)); } // update the windows cursor to match our raw cursor position. // this is important when sensitivity is decreased below 1.0, where we need to ensure the cursor stays withing the window. var screenPoint = host.Window.PointToScreen(new Point((int)currentPosition.X, (int)currentPosition.Y)); OpenTK.Input.Mouse.SetPosition(screenPoint.X, screenPoint.Y); } } else { var screenPoint = host.Window.PointToClient(new Point(state.X, state.Y)); currentPosition = new Vector2(screenPoint.X, screenPoint.Y); } IMouseState newState; // While not focused, let's silently ignore everything but position. if (host.IsActive) { lastState = state; newState = new OpenTKPollMouseState(state, host.IsActive, currentPosition); } else { lastState = null; newState = new UnfocusedMouseState(new OpenTK.Input.MouseState(), host.IsActive, currentPosition); } PendingStates.Enqueue(new InputState { Mouse = newState }); FrameStatistics.Increment(StatisticsCounterType.MouseEvents); }, 0, 0)); } else { scheduled?.Cancel(); lastState = null; } }; Enabled.TriggerChange(); return(true); }
public override bool Initialize(GameHost host) { host.Window.MouseEnter += window_MouseEnter; host.Window.MouseLeave += window_MouseLeave; this.host = host; mouseInWindow = host.Window.CursorInWindow; // Get the bindables we need to determine whether to confine the mouse to window or not if (host.Window is DesktopGameWindow desktopWindow) { confineMode.BindTo(desktopWindow.ConfineMouseMode); windowMode.BindTo(desktopWindow.WindowMode); mapAbsoluteInputToWindow.BindTo(desktopWindow.MapAbsoluteInputToWindow); } Enabled.ValueChanged += enabled => { if (enabled) { host.InputThread.Scheduler.Add(scheduled = new ScheduledDelegate(delegate { if (!host.Window.Visible || host.Window.WindowState == WindowState.Minimized) { return; } if ((mouseInWindow || lastStates.Any(s => s.HasAnyButtonPressed)) && host.Window.Focused) { var newStates = new List <OpenTK.Input.MouseState>(mostSeenStates + 1); for (int i = 0; i <= mostSeenStates + 1; i++) { var s = OpenTK.Input.Mouse.GetState(i); if (s.IsConnected || i < mostSeenStates) { newStates.Add(s); mostSeenStates = i; } } while (lastStates.Count < newStates.Count) { lastStates.Add(null); } for (int i = 0; i < newStates.Count; i++) { if (newStates[i].IsConnected != true) { lastStates[i] = null; continue; } var state = newStates[i]; var lastState = lastStates[i]; if (lastState != null && state.Equals(lastState.RawState)) { continue; } var newState = new OpenTKPollMouseState(state, host.IsActive, getUpdatedPosition(state, lastState)); lastStates[i] = newState; if (lastState != null) { PendingStates.Enqueue(new InputState { Mouse = newState }); FrameStatistics.Increment(StatisticsCounterType.MouseEvents); } } } else { var state = OpenTK.Input.Mouse.GetCursorState(); var screenPoint = host.Window.PointToClient(new Point(state.X, state.Y)); PendingStates.Enqueue(new InputState { Mouse = new UnfocusedMouseState(new OpenTK.Input.MouseState(), host.IsActive, new Vector2(screenPoint.X, screenPoint.Y)) }); FrameStatistics.Increment(StatisticsCounterType.MouseEvents); lastStates.Clear(); } }, 0, 0)); } else { scheduled?.Cancel(); lastStates.Clear(); } }; Enabled.TriggerChange(); return(true); }