public static void Init(Sdl2Window window) { ResetKeys(); window.KeyDown += KeyDown; window.KeyUp += KeyUp; window.DragDrop += DragDrop; window.MouseWheel += (MouseWheelEventArgs e) => { if (e.WheelDelta > 0 && mSpeed < 1 || e.WheelDelta < 0 && mSpeed > 0.05) { mSpeed += e.WheelDelta * 0.05f; } }; window.MouseMove += (MouseMoveEventArgs mouseEvent) => { if (mouseEvent.State.IsButtonDown(0) && !ImGui.GetIO().WantCaptureMouse) { window.SetMousePosition(Program.window.Width / 2, Program.window.Height / 2); window.CursorVisible = false; if (mouseDown) { MouseMove(mouseEvent.MousePosition - new Vector2(Program.window.Width / 2, Program.window.Height / 2)); } } else { window.CursorVisible = true; } mouseDown = mouseEvent.State.IsButtonDown(0); };//*/ }
public static void UpdateFrameInput(Sdl2Window window, InputSnapshot snapshot) { FrameSnapshot = snapshot; _newKeysThisFrame.Clear(); _newMouseButtonsThisFrame.Clear(); window.CursorVisible = !LockMouse; if (LockMouse) { window.SetMousePosition(window.Width / 2, window.Height / 2); MousePosition = new Vector2(window.Width / 2, window.Height / 2); MouseDelta = snapshot.MousePosition - MousePosition; } else { var newPosition = snapshot.MousePosition; MouseDelta = newPosition - MousePosition; MousePosition = newPosition; } for (int i = 0; i < snapshot.KeyEvents.Count; i++) { KeyEvent ke = snapshot.KeyEvents[i]; if (ke.Down) { KeyDown(ke.Key); } else { KeyUp(ke.Key); } } for (int i = 0; i < snapshot.MouseEvents.Count; i++) { MouseEvent me = snapshot.MouseEvents[i]; if (me.Down) { MouseDown(me.MouseButton); } else { MouseUp(me.MouseButton); } } }