Ejemplo n.º 1
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;
        }
Ejemplo n.º 2
0
        private void _mouseListener_MouseWheelMoved(object sender, MouseEventArgs e)
        {
            _scene?.FireScroll(e);
            MouseWheelMoved?.Invoke(sender, e);
#if DEBUG
            Logger.Log("Mouse wheel moved.");
#endif
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Safely invokes the <see cref="MouseWheelMoved"/> event with the given <paramref name="args"/>.
 /// Protects against plugin thrown exceptions.
 /// </summary>
 /// <param name="args">The arguments to invoke the event with</param>
 void InvokeMouseWheelMoved(MouseWheelEventArgs args)
 {
     try
     {
         MouseWheelMoved?.Invoke(args);
     }
     catch (Exception e)
     {
         Urho.IO.Log.Write(LogLevel.Warning,
                           $"There was an unexpected exception during the invocation of {nameof(MouseWheelMoved)}: {e.Message}");
     }
 }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
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;
        }