Exemple #1
0
        /// <summary>
        /// Mouse move
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void DxContainer_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            if (selectedBoard == null)
            {
                return;
            }

            lock (this)
            {
                Point realPosition = new Point(e.X, e.Y);

                if (VirtualToPhysical(selectedBoard.Mouse.X, selectedBoard.CenterPoint.X, selectedBoard.hScroll, 0) != realPosition.X ||
                    VirtualToPhysical(selectedBoard.Mouse.Y, selectedBoard.CenterPoint.Y, selectedBoard.vScroll, 0) != realPosition.Y)
                {
                    Point oldPos = new Point(selectedBoard.Mouse.X, selectedBoard.Mouse.Y);
                    Point newPos = new Point(PhysicalToVirtual(realPosition.X, selectedBoard.CenterPoint.X, selectedBoard.hScroll, 0), PhysicalToVirtual(realPosition.Y, selectedBoard.CenterPoint.Y, selectedBoard.vScroll, 0));
                    selectedBoard.Mouse.Move(newPos.X, newPos.Y);

                    if (MouseMoved != null)
                    {
                        MouseMoved.Invoke(selectedBoard, oldPos, newPos, new Point(realPosition.X, realPosition.Y));
                    }
                }
            }
        }
Exemple #2
0
            private IntPtr MouseHookDelegate(int code, IntPtr wParam, IntPtr lParam)
            {
                if (code < 0)
                {
                    return(WindowsHookHelper.CallNextHookEx(_mouseHandle, code, wParam, lParam));
                }


                switch (wParam.ToInt32())
                {
                case WM_LBUTTONDOWN:
                    LmbDown?.Invoke(this, new EventArgs());
                    break;

                case WM_LBUTTONUP:
                    LmbUp?.Invoke(this, new EventArgs());
                    break;

                default:
                    MouseMoved?.Invoke(this, new EventArgs());
                    break;
                }

                return(WindowsHookHelper.CallNextHookEx(_mouseHandle, code, wParam, lParam));
            }
Exemple #3
0
        public override void Update(GameTime gameTime)
        {
            _gameTime = gameTime;

            CheckButtonPressed(s => s.LeftButton, MouseButton.Left);
            CheckButtonPressed(s => s.MiddleButton, MouseButton.Middle);
            CheckButtonPressed(s => s.RightButton, MouseButton.Right);

            CheckButtonReleased(s => s.LeftButton, MouseButton.Left);
            CheckButtonReleased(s => s.MiddleButton, MouseButton.Middle);
            CheckButtonReleased(s => s.RightButton, MouseButton.Right);

            // Check for any sort of mouse movement.
            if (HasMouseMoved)
            {
                MouseMoved?.Invoke(this,
                                   new MouseEventArgs(gameTime.TotalGameTime, _previousState, MouseState));

                CheckMouseDragged(s => s.LeftButton, MouseButton.Left);
                CheckMouseDragged(s => s.MiddleButton, MouseButton.Middle);
                CheckMouseDragged(s => s.RightButton, MouseButton.Right);
            }

            // Handle mouse wheel events.
            if (_previousState.ScrollWheelValue != MouseState.ScrollWheelValue)
            {
                MouseWheelMoved?.Invoke(this,
                                        new MouseEventArgs(gameTime.TotalGameTime, _previousState, MouseState));
            }

            _previousState = MouseState;
        }
        private unsafe void MouseEvent(OpenToolkit.GraphicsLibraryFramework.Window *window1, double x, double y)
        {
            Vector2 newMouse = new Vector2((float)x, (float)y);

            MouseMoved?.Invoke(_mousePos - newMouse);
            _mousePos = newMouse;
        }
Exemple #5
0
 private void OnMouseMoved(float x, float y)
 {
     if (Contains(x, y))
     {
         MouseMoved?.Invoke(x, y);
     }
 }
Exemple #6
0
        protected void OnMouseMoved()
        {
            MouseMoveEvent args = new MouseMoveEvent();

            args.X = mousePosition.X;
            args.Y = mousePosition.Y;
            MouseMoved?.Invoke(this, args);
        }
Exemple #7
0
 private void OnMouseMoved(MouseMoveEventArgs args)
 {
     MouseMoved?.Invoke(args);
     if (!_blocked)
     {
         BlockableMouseMoved?.Invoke(args);
     }
 }
Exemple #8
0
 private IntPtr MouseCallBack(int code, IntPtr wParam, IntPtr lParam)
 {
     if (code < 0)
     {
         return(WindowsNativeMethods.CallNextHookEx(MouseHandle, code, wParam, lParam));
     }
     MouseMoved?.Invoke(this, new EventArgs());
     return(WindowsNativeMethods.CallNextHookEx(MouseHandle, code, wParam, lParam));
 }
Exemple #9
0
        private void JoystickAxisLeft(double Angle)
        {
            Vertex V = new Vertex(0, 300);

            V = V.RotateZ(Angle);
            Point P = V.ToPoint();

            MouseMoved.Invoke(null, new MouseEventArgs(MouseButtons.None, 0, -P.X + GLD.Width / 2, -P.Y + GLD.Height / 2, 0));
        }
Exemple #10
0
 private LambdaMouseMonitor(IMouseDataSource other, Func <Point, Point> lambda)
 {
     this.other        = other;
     other.MouseMoved += (s, e) =>
     {
         e.TransformedPoint = lambda(e.TransformedPoint);
         MouseMoved?.Invoke(s, e);
     };
 }
Exemple #11
0
        private void TileMouseMove(object sender, System.Windows.Input.MouseEventArgs e)
        {
            var eargs = new TileEventArgs(this);

            MouseMoved?.Invoke(sender, eargs);
            if (e.LeftButton == System.Windows.Input.MouseButtonState.Pressed)
            {
                MouseClick?.Invoke(sender, eargs);
            }
        }
Exemple #12
0
 public WindowWrapperInput(Window window)
 {
     _window                     = window;
     window.TextEntered         += (sender, args) => TextEntered?.Invoke(args);
     window.KeyPressed          += (sender, args) => KeyPressed?.Invoke(args);
     window.MouseButtonPressed  += (sender, args) => MouseButtonDown?.Invoke(args);
     window.MouseButtonReleased += (sender, args) => MouseButtonUp?.Invoke(args);
     window.MouseMoved          += (sender, args) => MouseMoved?.Invoke(args);
     window.MouseWheelScrolled  += (sender, args) => MouseWheelScrolled?.Invoke(args);
 }
Exemple #13
0
 /// <summary>
 /// Updates the mouse state, as the Stardew Valley Modding API mishandles zoom and other portions of the mouse state tracking.
 /// </summary>
 /// <param name="arguments"></param>
 internal static void HandleState(EventArgsMouseStateChanged arguments)
 {
     UpdateState(arguments);
     CheckForClick();
     if (_lastMouseState.X != _currentMouseState.X || _lastMouseState.Y != _currentMouseState.Y)
     {
         MouseMoved?.Invoke(new MouseMoveEventArguments(new Point(_lastMouseState.X, _lastMouseState.Y),
                                                        new Point(_currentMouseState.X, _currentMouseState.Y)));
     }
 }
Exemple #14
0
        private IntPtr MouseHookDelegate(Int32 code, IntPtr wParam, IntPtr lParam)
        {
            if (code < 0)
            {
                return(WindowsHookHelper.CallNextHookEx(mouseHandle, code, wParam, lParam));
            }

            MouseMoved?.Invoke(this, new EventArgs());

            return(WindowsHookHelper.CallNextHookEx(mouseHandle, code, wParam, lParam));
        }
        public bool PreFilterMessage(ref Message m)
        {
            if (m.Msg == WM_MOUSEMOVE)
            {
                Point mousePosition = Control.MousePosition;

                MouseMoved?.Invoke(null, new MouseEventArgs(MouseButtons.None, 0, mousePosition.X, mousePosition.Y, 0));
            }

            // Always allow message to continue to the next filter control
            return(false);
        }
Exemple #16
0
 private void DxContainer_MouseMove(object sender, MouseEventArgs e)
 {
     lock (this)
     {
         System.Drawing.Point mouse = PointToClient(Cursor.Position);
         if (VirtualToPhysical(selectedBoard.Mouse.X, selectedBoard.CenterPoint.X, selectedBoard.hScroll, 0) != mouse.X || VirtualToPhysical(selectedBoard.Mouse.Y, selectedBoard.CenterPoint.Y, selectedBoard.vScroll, 0) != mouse.Y)
         {
             Point oldPos = new Point(selectedBoard.Mouse.X, selectedBoard.Mouse.Y);
             Point newPos = new Point(PhysicalToVirtual(mouse.X, selectedBoard.CenterPoint.X, selectedBoard.hScroll, 0), PhysicalToVirtual(mouse.Y, selectedBoard.CenterPoint.Y, selectedBoard.vScroll, 0));
             selectedBoard.Mouse.Move(newPos.X, newPos.Y);
             if (MouseMoved != null)
             {
                 MouseMoved.Invoke(selectedBoard, oldPos, newPos, new Point(mouse.X, mouse.Y));
             }
         }
     }
 }
Exemple #17
0
        /// <summary>
        /// Update the input details for this frame (should be called every frame)
        /// </summary>
        public static void Update()
        {
            // Update keyboard states
            previousKeyboardState = currentKeyboardState;
            currentKeyboardState  = Keyboard.GetState();

            // If keyboard state has changed, loop around the button enums & see if the related
            // value in "KeyMappings" has been changed; if it has, use the "ButtonPressed" event to
            // notify subscribers
            if (previousKeyboardState != currentKeyboardState)
            {
                foreach (Buttons button in buttonEnums)
                {
                    if (KeyMappings.ContainsKey(button))
                    {
                        Keys key = KeyMappings[button];
                        if (currentKeyboardState.IsKeyDown(key) &&
                            !(previousKeyboardState.IsKeyDown(key)))
                        {
                            ButtonPressed?.Invoke(button);
                        }
                    }
                }
            }

            if (MouseEnabled)
            {
                // Update mouse states
                previousMouseState = currentMouseState;
                currentMouseState  = Mouse.GetState();

                // Update if the mouse has moved
                if (currentMouseState.X != previousMouseState.X ||
                    currentMouseState.Y != previousMouseState.Y)
                {
                    MouseMoved?.Invoke(currentMouseState.Position);
                }

                // If lmb pressed, act as if confirm button pressed
                if (currentMouseState.LeftButton == ButtonState.Pressed &&
                    previousMouseState.LeftButton != ButtonState.Pressed)
                {
                    ButtonPressed?.Invoke(Buttons.Swap);
                }
            }
        }
        private async Task CheckAndRaiseEventsAsync(CancellationToken token)
        {
            while (!token.IsCancellationRequested)
            {
                await Task.Delay(IntervalMillisec);

                int x = _mouseHook.X;
                int y = _mouseHook.Y;

                if (X != x || Y != y)
                {
                    X = x;
                    Y = y;
                    MouseMoved?.Invoke(this, EventArgs.Empty);
                }
            }
        }
Exemple #19
0
 protected virtual void OnMouseMoved(float x, float y)
 {
     if (!MenuVisible)
     {
         if (Contains(x, y))
         {
             Color = parent.HoverColor;
         }
         else
         {
             Color = parent.BaseColor;
         }
     }
     else
     {
         MouseMoved?.Invoke(x, y);
     }
 }
Exemple #20
0
 private IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam)
 {
     if (watchForMouseButtonOnly)
     {
         if (nCode >= 0 && wParam == (IntPtr)0x20b)
         {
             MouseMoved?.Invoke();
         }
     }
     else
     {
         if (nCode >= 0 && wParam == (IntPtr)WM_MOUSEMOVE)
         {
             MouseMoved?.Invoke();
         }
     }
     return(NativeMethods.CallNextHookEx(_hookID, nCode, wParam, lParam));
 }
        internal static IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam)
        {
            if (nCode >= 0 && MouseMessages.WM_MOUSEMOVE == (MouseMessages)wParam)
            {
                MSLLHOOKSTRUCT hookStruct = (MSLLHOOKSTRUCT)Marshal.PtrToStructure(lParam, typeof(MSLLHOOKSTRUCT));

                MouseMoved?.Invoke(new Point(hookStruct.pt.x, hookStruct.pt.y));
            }
            else if (nCode >= 0 && MouseMessages.WM_LBUTTONUP == (MouseMessages)wParam)
            {
                LMouseUp?.Invoke();
                if (DisableLMouseUp)
                {
                    return((IntPtr)(-1));
                }
            }
            else if (nCode >= 0 && MouseMessages.WM_LBUTTONDOWN == (MouseMessages)wParam)
            {
                LMouseDown?.Invoke();
                if (DisableLMouseDown)
                {
                    return((IntPtr)(-1));
                }
            }
            else if (nCode >= 0 && MouseMessages.WM_RBUTTONUP == (MouseMessages)wParam)
            {
                RMouseUp?.Invoke();
                if (DisableRMouseUp)
                {
                    return((IntPtr)(-1));
                }
            }
            else if (nCode >= 0 && MouseMessages.WM_RBUTTONDOWN == (MouseMessages)wParam)
            {
                RMouseDown?.Invoke();
                if (DisableRMouseDown)
                {
                    return((IntPtr)(-1));
                }
            }
            return(CallNextHookEx(_hookID, nCode, wParam, lParam));
        }
Exemple #22
0
        public InputEvents(RenderWindow window)
        {
            // if dummy don't attach events
            if (window == null)
            {
                return;
            }

            _window = window;

            _window.KeyPressed          += (sender, args) => KeyPressed?.Invoke(sender, args);
            _window.KeyReleased         += (sender, args) => KeyReleased?.Invoke(sender, args);
            _window.MouseButtonPressed  += (sender, args) => MouseButtonPressed?.Invoke(sender, args);
            _window.MouseButtonReleased += (sender, args) => MouseButtonReleased?.Invoke(sender, args);
            _window.MouseMoved          += (sender, args) => MouseMoved?.Invoke(sender, args);
            _window.MouseWheelMoved     += (sender, args) => MouseWheelMoved?.Invoke(sender, args);
            _window.MouseEntered        += (sender, args) => MouseEntered?.Invoke(sender, args);
            _window.MouseLeft           += (sender, args) => MouseLeft?.Invoke(sender, args);
            _window.TextEntered         += (sender, args) => TextEntered?.Invoke(sender, args);
        }
Exemple #23
0
        public InputEvents(CluwneWindow window)
        {
            // if dummy don't attach events
            if (window == null)
            {
                return;
            }

            SFML.Graphics.RenderWindow SWindow = window.SFMLWindow;

            SWindow.KeyPressed          += (sender, args) => KeyPressed?.Invoke(sender, (KeyEventArgs)args);
            SWindow.KeyReleased         += (sender, args) => KeyReleased?.Invoke(sender, (KeyEventArgs)args);
            SWindow.MouseButtonPressed  += (sender, args) => MouseButtonPressed?.Invoke(sender, (MouseButtonEventArgs)args);
            SWindow.MouseButtonReleased += (sender, args) => MouseButtonReleased?.Invoke(sender, (MouseButtonEventArgs)args);
            SWindow.MouseMoved          += (sender, args) => MouseMoved?.Invoke(sender, (MouseMoveEventArgs)args);
            SWindow.MouseWheelScrolled  += (sender, args) => MouseWheelMoved?.Invoke(sender, (MouseWheelScrollEventArgs)args);
            SWindow.MouseEntered        += (sender, args) => MouseEntered?.Invoke(sender, args);
            SWindow.MouseLeft           += (sender, args) => MouseLeft?.Invoke(sender, args);
            SWindow.TextEntered         += (sender, args) => TextEntered?.Invoke(sender, (TextEventArgs)args);
        }
Exemple #24
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="gameTime"></param>
        public void Update(GameTime gameTime)
        {
            _gameTime     = gameTime;
            _currentState = Mouse.GetState();

            CheckButtonPressed(s => s.LeftButton, MouseButton.Left);
            CheckButtonPressed(s => s.MiddleButton, MouseButton.Middle);
            CheckButtonPressed(s => s.RightButton, MouseButton.Right);
            CheckButtonPressed(s => s.XButton1, MouseButton.XButton1);
            CheckButtonPressed(s => s.XButton2, MouseButton.XButton2);

            CheckButtonReleased(s => s.LeftButton, MouseButton.Left);
            CheckButtonReleased(s => s.MiddleButton, MouseButton.Middle);
            CheckButtonReleased(s => s.RightButton, MouseButton.Right);
            CheckButtonReleased(s => s.XButton1, MouseButton.XButton1);
            CheckButtonReleased(s => s.XButton2, MouseButton.XButton2);

            // Check for any sort of mouse movement.
            if (HasMouseMoved)
            {
                MouseMoved?.Invoke(this,
                                   new MouseEventArgs(ScreenTransformationMatrixProvider, gameTime.TotalGameTime, _previousState, _currentState));

                CheckMouseDragged(s => s.LeftButton, MouseButton.Left);
                CheckMouseDragged(s => s.MiddleButton, MouseButton.Middle);
                CheckMouseDragged(s => s.RightButton, MouseButton.Right);
                CheckMouseDragged(s => s.XButton1, MouseButton.XButton1);
                CheckMouseDragged(s => s.XButton2, MouseButton.XButton2);
            }

            // Handle mouse wheel events.
            if (_previousState.ScrollWheelValue != _currentState.ScrollWheelValue)
            {
                MouseWheelMoved?.Invoke(this,
                                        new MouseEventArgs(ScreenTransformationMatrixProvider, gameTime.TotalGameTime, _previousState, _currentState));
            }

            _previousState = _currentState;
        }
        public static void InputLoop()
        {
            uint        toRead            = 128;
            var         records           = new INPUT_RECORD[toRead];
            int         prevWidth         = MyConsole.Width;
            int         prevHeight        = MyConsole.Height;
            MouseButton prevMouseState    = MouseButton.None;
            COORD       prevMouseLocation = new COORD();

            while (!MyConsole.Exiting)
            {
                WinApi.ReadConsoleInput(inputHandle, records, toRead, out uint recordLen);

                for (int i = 0; i < recordLen; i++)
                {
                    var record = records[i];

                    switch (record.EventType)
                    {
                    case EventType.Mouse:
                    {
                        var mouseEvent = record.Event.MouseEvent;
                        var button     = mouseEvent.ButtonState;
                        var flags      = mouseEvent.EventFlags;
                        var location   = mouseEvent.MousePosition;

                        bool mousePressed  = prevMouseState == MouseButton.None && button != MouseButton.None;
                        bool mouseReleased = prevMouseState != MouseButton.None && button == MouseButton.None;
                        bool mouseHeld     = prevMouseState != MouseButton.None && button != MouseButton.None;

                        var args = new MouseEventArgs
                        {
                            Button          = button,
                            Location        = location,
                            ControlKeyState = mouseEvent.ControlKeyState
                        };

                        bool sameLocation = location.Equals(prevMouseLocation);

                        if (mousePressed && flags.HasFlag(MouseState.DoubleClick))
                        {
                            MouseDoubleClick?.Invoke(null, args);
                        }
                        else if (mousePressed)
                        {
                            MousePressed?.Invoke(null, args);
                        }
                        else if (mouseReleased)
                        {
                            MouseReleased?.Invoke(null, args);
                        }
                        else if (mouseHeld && flags.HasFlag(MouseState.Moved) && !sameLocation)
                        {
                            MouseDragged?.Invoke(null, args);
                        }
                        else if (flags.HasFlag(MouseState.Moved) && !sameLocation)
                        {
                            MouseMoved?.Invoke(null, args);
                        }

                        prevMouseState    = button;
                        prevMouseLocation = location;
                    }
                    break;

                    case EventType.Key:
                    {
                        var keyEvent = record.Event.KeyEvent;

                        var eventArgs = new KeyEventArgs
                        {
                            Key             = (ConsoleKey)keyEvent.VirtualKeyCode,
                            ControlKeyState = keyEvent.ControlKeyState
                        };

                        bool currState = keyEvent.KeyDown;
                        bool prevState = keyStates[keyEvent.VirtualKeyCode];

                        if (currState && !prevState)
                        {
                            KeyPressed?.Invoke(eventArgs);
                        }
                        else if (prevState && !currState)
                        {
                            KeyReleased?.Invoke(eventArgs);
                        }
                        else if (prevState && currState)
                        {
                            KeyHeld?.Invoke(eventArgs);
                        }

                        keyStates[keyEvent.VirtualKeyCode] = keyEvent.KeyDown;
                    }
                    break;

                    case EventType.Resize:
                    {
                        var clientSize = MyConsole.GetClientSize();
                        var fontSize   = MyConsole.GetFontSize();
                        int w          = clientSize.X / fontSize.X;
                        int h          = clientSize.Y / fontSize.Y;

                        if (prevWidth != w || prevHeight != h)
                        {
                            MyConsole.SetSize(w, h);
                            MyConsole.HideCursor();
                            Drawing.ConsoleRenderer.Resize(w, h);
                            Resized?.Invoke(new ResizedEventArgs
                                {
                                    Width  = w,
                                    Height = h
                                });
                            prevWidth  = w;
                            prevHeight = h;
                        }
                    }
                    break;

                    case EventType.Menu:
                    {
                        var id = record.Event.MenuEvent.dwCommandId;
                        Debug.WriteLine(id);
                    }
                    break;

                    case EventType.Focus:
                    {
                        var focused = record.Event.FocusEvent.bSetFocus;
                    }
                    break;

                    default:
                        Debug.WriteLine("Unhandled event: " + record.EventType);
                        break;
                    }
                }
            }
        }
Exemple #26
0
 protected virtual void OnMouseMoved(EventArgs e)
 {
     MouseMoved?.Invoke(this, e);
 }
Exemple #27
0
 public virtual void OnMouseMoved()
 {
     MouseMoved?.Invoke(this, EventArgs.Empty);
 }
Exemple #28
0
 private static void OnMouseMoved(Screen s, MouseMoveEvent e)
 {
     MouseMoved?.Invoke(s, e);
 }
Exemple #29
0
 public virtual void OnMouseMoved()
 {
     IsMouseInside = true;
     MouseMoved.Invoke(this);
 }
 internal void OnMouseMoved(Point p)
 {
     MouseMoved?.Invoke(this, p);
 }