コード例 #1
0
        public static MouseState GetState()
        {
#if MONOMAC
            //We need to maintain precision...
            State.ScrollWheelValue = (int)ScrollWheelValue;
#elif WINDOWS || LINUX
            // maybe someone is tring to get mouse before initialize
            if (_mouse == null)
            {
                return(State);
            }

#if WINDOWS
            var p = new POINT();
            GetCursorPos(out p);
            var pc = Window.PointToClient(p.ToPoint());
            State.X = pc.X;
            State.Y = pc.Y;
#endif

            State.LeftButton   = _mouse[OpenTK.Input.MouseButton.Left] ? ButtonState.Pressed : ButtonState.Released;
            State.RightButton  = _mouse[OpenTK.Input.MouseButton.Right] ? ButtonState.Pressed : ButtonState.Released;
            State.MiddleButton = _mouse[OpenTK.Input.MouseButton.Middle] ? ButtonState.Pressed : ButtonState.Released;;

            // WheelPrecise is divided by 120 (WHEEL_DELTA) in OpenTK (WinGLNative.cs)
            // We need to counteract it to get the same value XNA provides
            State.ScrollWheelValue = (int)(_mouse.WheelPrecise * 120);
#endif

            return(State);
        }
コード例 #2
0
        private void UpdateImGuiInput(OpenTK.GameWindow wnd)
        {
            ImGuiIOPtr io = ImGui.GetIO();

            MouseState    MouseState    = Mouse.GetCursorState();
            KeyboardState KeyboardState = Keyboard.GetState();

            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       = wnd.PointToClient(screenPoint);

            io.MousePos = new System.Numerics.Vector2(point.X, point.Y);

            io.MouseWheel  = MouseState.Scroll.Y - PrevMouseState.Scroll.Y;
            io.MouseWheelH = MouseState.Scroll.X - PrevMouseState.Scroll.X;

            foreach (Key key in Enum.GetValues(typeof(Key)))
            {
                io.KeysDown[(int)key] = KeyboardState.IsKeyDown(key);
            }

            foreach (var c in PressedChars)
            {
                io.AddInputCharacter(c);
            }
            PressedChars.Clear();

            io.KeyCtrl  = KeyboardState.IsKeyDown(Key.ControlLeft) || KeyboardState.IsKeyDown(Key.ControlRight);
            io.KeyAlt   = KeyboardState.IsKeyDown(Key.AltLeft) || KeyboardState.IsKeyDown(Key.AltRight);
            io.KeyShift = KeyboardState.IsKeyDown(Key.ShiftLeft) || KeyboardState.IsKeyDown(Key.ShiftRight);
            io.KeySuper = KeyboardState.IsKeyDown(Key.WinLeft) || KeyboardState.IsKeyDown(Key.WinRight);

            PrevMouseState    = MouseState;
            PrevKeyboardState = KeyboardState;
        }