Exemple #1
0
 private void OnMouseComponentMove(object sender, MouseMoveEventArgs e)
 {
     foreach (var module in InputModules)
     {
         var input = module as IInputModule;
         if (input != null)
         {
             if (input.MouseMove(GameTime, e))
                 break;
         }
     }
 }
Exemple #2
0
        private void OnMouseComponentMove(object sender, MouseMoveEventArgs e)
        {
            if (MouseCaptured && IsActive)
            {
                var centerX = GraphicsDevice.Viewport.Width / 2;
                var centerY = GraphicsDevice.Viewport.Height / 2;
                Mouse.SetPosition(centerX, centerY);

                var look = new Vector2((centerX - e.X), (centerY - e.Y))
                    * (float)(GameTime.ElapsedGameTime.TotalSeconds * 70);

                Client.Yaw += look.X;
                Client.Pitch += look.Y;
                Client.Yaw %= 360;
                Client.Pitch = Microsoft.Xna.Framework.MathHelper.Clamp(Client.Pitch, -89.9f, 89.9f);

                if (look != Vector2.Zero)
                    UpdateCamera();
            }
        }
Exemple #3
0
        /// <summary>
        /// Processes a change between two states.
        /// </summary>
        /// <param name="newState">The new state.</param>
        /// <param name="oldState">The old state.</param>
        private void Process(MouseState newState, MouseState oldState)
        {
            // Movement.
            if ((newState.X != oldState.X) || (newState.Y != oldState.Y))
            {
                var args = new MouseMoveEventArgs(newState.X, newState.Y, (newState.X - oldState.X), (newState.Y - oldState.Y));
                if (Move != null)
                {
                    Move(this, args);
                }
            }

            // Scrolling.
            if (newState.ScrollWheelValue != oldState.ScrollWheelValue)
            {
                var args = new MouseScrollEventArgs(newState.X, newState.Y, newState.ScrollWheelValue, (newState.ScrollWheelValue - oldState.ScrollWheelValue));
                if (Scroll != null)
                {
                    Scroll(this, args);
                }
            }

            // A bit of code duplication here, shame XNA doesn't expose button state through an enumeration...

            // Left button.
            if (newState.LeftButton != oldState.LeftButton)
            {
                var args = new MouseButtonEventArgs(newState.X, newState.Y, MouseButton.Left, (newState.LeftButton == ButtonState.Pressed));
                if (args.IsPressed)
                {
                    if (ButtonDown != null)
                    {
                        ButtonDown(this, args);
                    }
                }
                else
                {
                    if (ButtonUp != null)
                    {
                        ButtonUp(this, args);
                    }
                }
            }

            // Right button.
            if (newState.RightButton != oldState.RightButton)
            {
                var args = new MouseButtonEventArgs(newState.X, newState.Y, MouseButton.Right, (newState.RightButton == ButtonState.Pressed));
                if (args.IsPressed)
                {
                    if (ButtonDown != null)
                    {
                        ButtonDown(this, args);
                    }
                }
                else
                {
                    if (ButtonUp != null)
                    {
                        ButtonUp(this, args);
                    }
                }
            }

            // Middle button.
            if (newState.MiddleButton != oldState.MiddleButton)
            {
                var args = new MouseButtonEventArgs(newState.X, newState.Y, MouseButton.Middle, (newState.MiddleButton == ButtonState.Pressed));
                if (args.IsPressed)
                {
                    if (ButtonDown != null)
                    {
                        ButtonDown(this, args);
                    }
                }
                else
                {
                    if (ButtonUp != null)
                    {
                        ButtonUp(this, args);
                    }
                }
            }
        }
Exemple #4
0
 public virtual bool MouseMove(GameTime gameTime, MouseMoveEventArgs e)
 {
     return false;
 }
        public override bool MouseMove(GameTime gameTime, MouseMoveEventArgs e)
        {
            if (!Capture)
                return false;
            var centerX = Game.GraphicsDevice.Viewport.Width / 2;
            var centerY = Game.GraphicsDevice.Viewport.Height / 2;
            Mouse.SetPosition(centerX, centerY);

            var look = new Vector2((centerX - e.X), (centerY - e.Y))
                * (float)(gameTime.ElapsedGameTime.TotalSeconds * 30);

            Game.Client.Yaw -= look.X;
            Game.Client.Pitch -= look.Y;
            Game.Client.Yaw %= 360;
            Game.Client.Pitch = MathHelper.Clamp(Game.Client.Pitch, -89.9f, 89.9f);

            return true;
        }
Exemple #6
0
 public override bool MouseMove(GameTime gameTime, MouseMoveEventArgs e)
 {
     if (Game.Client.CurrentWindow != null)
         return true;
     return base.MouseMove(gameTime, e);
 }
Exemple #7
0
        /// <summary>
        /// Processes a change between two states.
        /// </summary>
        /// <param name="newState">The new state.</param>
        /// <param name="oldState">The old state.</param>
        private void Process(MouseState newState, MouseState oldState)
        {
            // Movement.
            if ((newState.X != oldState.X) || (newState.Y != oldState.Y))
            {
                var args = new MouseMoveEventArgs(newState.X, newState.Y, (newState.X - oldState.X), (newState.Y - oldState.Y));
                if (Move != null)
                    Move(this, args);
            }

            // Scrolling.
            if (newState.ScrollWheelValue != oldState.ScrollWheelValue)
            {
                var args = new MouseScrollEventArgs(newState.X, newState.Y, newState.ScrollWheelValue, (newState.ScrollWheelValue - oldState.ScrollWheelValue));
                if (Scroll != null)
                    Scroll(this, args);
            }

            // A bit of code duplication here, shame XNA doesn't expose button state through an enumeration...

            // Left button.
            if (newState.LeftButton != oldState.LeftButton)
            {
                var args = new MouseButtonEventArgs(newState.X, newState.Y, MouseButton.Left, (newState.LeftButton == ButtonState.Pressed));
                if (args.IsPressed)
                {
                    if (ButtonDown != null)
                        ButtonDown(this, args);
                }
                else
                {
                    if (ButtonUp != null)
                        ButtonUp(this, args);
                }
            }

            // Right button.
            if (newState.RightButton != oldState.RightButton)
            {
                var args = new MouseButtonEventArgs(newState.X, newState.Y, MouseButton.Right, (newState.RightButton == ButtonState.Pressed));
                if (args.IsPressed)
                {
                    if (ButtonDown != null)
                        ButtonDown(this, args);
                }
                else
                {
                    if (ButtonUp != null)
                        ButtonUp(this, args);
                }
            }

            // Middle button.
            if (newState.MiddleButton != oldState.MiddleButton)
            {
                var args = new MouseButtonEventArgs(newState.X, newState.Y, MouseButton.Middle, (newState.MiddleButton == ButtonState.Pressed));
                if (args.IsPressed)
                {
                    if (ButtonDown != null)
                        ButtonDown(this, args);
                }
                else
                {
                    if (ButtonUp != null)
                        ButtonUp(this, args);
                }
            }
        }
        public override bool MouseMove(GameTime gameTime, MouseMoveEventArgs e)
        {
            if (!Capture)
                return false;
            if (IgnoreNextUpdate)
            {
                IgnoreNextUpdate = false;
                return true;
            }
            var centerX = Game.GraphicsDevice.Viewport.Width / 2;
            var centerY = Game.GraphicsDevice.Viewport.Height / 2;

            if (e.X < 10 || e.X > Game.GraphicsDevice.Viewport.Width - 10 ||
                e.Y < 10 || e.Y > Game.GraphicsDevice.Viewport.Height - 10)
            {
                Mouse.SetPosition(centerX, centerY);
                IgnoreNextUpdate = true;
                return true;
            }

            var look = new Vector2((-e.DeltaX), (-e.DeltaY))
                * (float)(gameTime.ElapsedGameTime.TotalSeconds * 30);

            Game.Client.Yaw -= look.X;
            Game.Client.Pitch -= look.Y;
            Game.Client.Yaw %= 360;
            Game.Client.Pitch = MathHelper.Clamp(Game.Client.Pitch, -89.9f, 89.9f);

            return true;
        }
Exemple #9
0
        /// <summary>
        ///  Processes a change between two states.
        /// </summary>
        /// <param name="newState">The new state.</param>
        /// <param name="oldState">The old state.</param>
        private void Process(MouseState newState, MouseState oldState)
        {
            // Movement.
            if (newState.X != oldState.X || newState.Y != oldState.Y)
            {
                var args = new MouseMoveEventArgs(newState.X, newState.Y, newState.X - oldState.X,
                                                  newState.Y - oldState.Y);
                Move?.Invoke(this, args);
            }

            // Scrolling.
            if (newState.ScrollWheelValue != oldState.ScrollWheelValue)
            {
                var args = new MouseScrollEventArgs(newState.X, newState.Y, newState.ScrollWheelValue,
                                                    newState.ScrollWheelValue - oldState.ScrollWheelValue);
                Scroll?.Invoke(this, args);
            }

            // A bit of code duplication here, shame XNA doesn't expose button state through an enumeration...

            // Left button.
            if (newState.LeftButton != oldState.LeftButton)
            {
                var args = new MouseButtonEventArgs(newState.X, newState.Y, MouseButton.Left,
                                                    newState.LeftButton == ButtonState.Pressed);
                if (args.IsPressed)
                {
                    ButtonDown?.Invoke(this, args);
                }
                else
                {
                    ButtonUp?.Invoke(this, args);
                }
            }

            // Right button.
            if (newState.RightButton != oldState.RightButton)
            {
                var args = new MouseButtonEventArgs(newState.X, newState.Y, MouseButton.Right,
                                                    newState.RightButton == ButtonState.Pressed);
                if (args.IsPressed)
                {
                    ButtonDown?.Invoke(this, args);
                }
                else
                {
                    ButtonUp?.Invoke(this, args);
                }
            }

            // Middle button.
            if (newState.MiddleButton != oldState.MiddleButton)
            {
                var args = new MouseButtonEventArgs(newState.X, newState.Y, MouseButton.Middle,
                                                    newState.MiddleButton == ButtonState.Pressed);
                if (args.IsPressed)
                {
                    ButtonDown?.Invoke(this, args);
                }
                else
                {
                    ButtonUp?.Invoke(this, args);
                }
            }
        }