public void UpdateMouse() { MouseState cursorState = Mouse.GetCursorState(); MouseState mouseState = Mouse.GetState(); if (window.Focused) { Point windowPoint = window.PointToClient(new Point(cursorState.X, cursorState.Y)); io.MousePosition = new System.Numerics.Vector2(windowPoint.X / io.DisplayFramebufferScale.X, windowPoint.Y / io.DisplayFramebufferScale.Y); } else { io.MousePosition = new System.Numerics.Vector2(-1f, -1f); } io.MouseDown[0] = mouseState.LeftButton == ButtonState.Pressed; io.MouseDown[1] = mouseState.RightButton == ButtonState.Pressed; io.MouseDown[2] = mouseState.MiddleButton == ButtonState.Pressed; float newWheelPos = mouseState.WheelPrecise; float delta = newWheelPos - _wheelPosition; _wheelPosition = newWheelPos; io.MouseWheel = delta; }
public void Update(bool windowIsActive) { if (windowIsActive) { keyboardEvents.Update(); keyboardState.Update(); mouseState.Update(); MousePosition = toVector(nativeWindow.PointToClient( new System.Drawing.Point(mouseState.Current.X, mouseState.Current.Y))); if (!windowWasActiveLastUpdate) { // mouse state is updated in a special way so that scroll delta doesnt jump mouseState.UpdateTo(mouseState.Current); } } else { keyboardState.UpdateToDefault(); } foreach (var gamepad in GamePads) { gamepad.Update(windowIsActive); } windowWasActiveLastUpdate = windowIsActive; }
public bool HandleMouseInput(INativeWindow window, MouseState mouseState) { ImGuiIOPtr io = ImGui.GetIO(); io.MouseDown[0] = mouseState.LeftButton == ButtonState.Pressed; io.MouseDown[1] = mouseState.RightButton == ButtonState.Pressed; io.MouseDown[2] = mouseState.MiddleButton == ButtonState.Pressed; var screenPoint = new System.Drawing.Point(mouseState.X, mouseState.Y); var point = window.PointToClient(screenPoint); io.MousePos = new Vector2(point.X, point.Y); io.MouseWheel = mouseState.Scroll.Y - prevMouseState.Scroll.Y; io.MouseWheelH = mouseState.Scroll.X - prevMouseState.Scroll.X; prevMouseState = mouseState; return(io.WantCaptureMouse); }
/// <summary> /// Transforms the specified point from screen to client coordinates. /// </summary> /// <param name="point"> /// A <see cref="System.Drawing.Point"/> to transform. /// </param> /// <returns> /// The point transformed to client coordinates. /// </returns> public Point PointToClient(Point point) { return(implementation.PointToClient(point)); }