Exemplo n.º 1
0
        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;
        }
        internal override 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 (_previousState.X != _currentState.X || _previousState.Y != _currentState.Y)
            {
                MouseMoved.Raise(this, new MouseEventArgs(gameTime.TotalGameTime, _previousState, _currentState));
            }

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

            _previousState = _currentState;
        }
Exemplo n.º 3
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));
            }
Exemplo n.º 4
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));
                    }
                }
            }
        }
Exemplo n.º 5
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;
        }
Exemplo n.º 6
0
 private void OnMouseMoved(float x, float y)
 {
     if (Contains(x, y))
     {
         MouseMoved?.Invoke(x, y);
     }
 }
Exemplo n.º 7
0
 /// <summary>
 /// Handles the MouseMoved event of the <see cref="GameBase.RenderWindow"/>.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">The <see cref="SFML.Window.MouseMoveEventArgs"/> instance containing the event data.</param>
 void rw_MouseMoved(object sender, MouseMoveEventArgs e)
 {
     if (MouseMoved != null)
     {
         MouseMoved.Raise(this, e);
     }
 }
Exemplo n.º 8
0
        protected void OnMouseMoved()
        {
            MouseMoveEvent args = new MouseMoveEvent();

            args.X = mousePosition.X;
            args.Y = mousePosition.Y;
            MouseMoved?.Invoke(this, args);
        }
Exemplo n.º 9
0
 private void OnMouseMoved(MouseMoveEventArgs args)
 {
     MouseMoved?.Invoke(args);
     if (!_blocked)
     {
         BlockableMouseMoved?.Invoke(args);
     }
 }
Exemplo n.º 10
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));
 }
Exemplo n.º 11
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);
     };
 }
Exemplo n.º 12
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));
        }
        public EditorInputListener()
        {
            _mouseEventMap = new Dictionary <EventType, List <Action> >();

            AddMouseHandler(EventType.MouseDown, () => MouseDown.InvokeSafe(new EditorMouseEvent()));
            AddMouseHandler(EventType.MouseUp, () => MouseUp.InvokeSafe(new EditorMouseEvent()));
            AddMouseHandler(EventType.MouseDrag, () => MouseDragged.InvokeSafe(new EditorMouseEvent()));
            AddMouseHandler(EventType.MouseMove, () => MouseMoved.InvokeSafe(new EditorMouseEvent()));
            AddMouseHandler(EventType.ContextClick, () => ContextClicked.InvokeSafe());
        }
Exemplo n.º 14
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);
            }
        }
Exemplo n.º 15
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);
 }
Exemplo n.º 16
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)));
     }
 }
Exemplo n.º 17
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);
        }
Exemplo n.º 19
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));
             }
         }
     }
 }
        public virtual void Handle(MouseMoved @event)
        {
            bool contains = Shape?.GetGlobalBounds().Contains(@event.Mouse.X, @event.Mouse.Y) ?? false;

            if (contains != ContainsCursor)
            {
                ContainsCursor = contains;
                if (contains)
                {
                    OnMouseEnter(@event.Mouse);
                }
                else
                {
                    OnMouseLeave(@event.Mouse);
                }
            }
        }
Exemplo n.º 21
0
        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);
                }
            }
        }
Exemplo n.º 22
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);
                }
            }
        }
Exemplo n.º 23
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);
     }
 }
Exemplo n.º 24
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));
 }
Exemplo n.º 25
0
        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));
        }
Exemplo n.º 26
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);
        }
Exemplo n.º 27
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);
        }
Exemplo n.º 28
0
        private void mouseMoved(object sender, MouseEventArgs e)
        {
            MouseMoved mv = new MouseMoved();

            mv.Type = "mouseMoved";
            mv.Name = App.name;
            mv.Code = App.code % sc.mode;
            mv.X    = e.GetPosition(this).X - lastPoint.X;
            mv.Y    = e.GetPosition(this).Y - lastPoint.Y;
            if (sc.mode != 0)
            {
                mv.Code = App.code % sc.mode;
            }
            Send(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(mv)));
            lastPoint = e.GetPosition(this);

            if (e.GetPosition(this).X <= 1 || e.GetPosition(this).X >= this.Width - 1 || e.GetPosition(this).Y <= 1 || e.GetPosition(this).Y >= this.Height - 1)
            {
                lastPoint = new Point((int)Width / 2, (int)Height / 2);
                SetCursorPos((int)Width / 2, (int)Height / 2);
            }
        }
Exemplo n.º 29
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;
        }
Exemplo n.º 30
0
        private void refreshTimer_Elapsed(object sender, ElapsedEventArgs e)
        {
            try
            {
                //Position changed (0,0 set if screensaver activated)
                if (_oldPosition != Cursor.Position && Cursor.Position != new Point(0, 0))
                {
                    _oldPosition = Cursor.Position;
                    MouseMoved.RaiseEvent(this, new EventArgs());
                }

                //Restart timer
                _refreshTimer.Start();
            }
            catch (Exception ex)
            {
                ExceptionOccured.RaiseEvent(this, new ExceptionEventArgs
                {
                    Methode = MethodBase.GetCurrentMethod(),
                    Error   = ex
                });
            }
        }