Beispiel #1
0
        /// <summary>
        /// Handle user input.
        /// </summary>
        /// <param name="input">The helper for reading input from the user.</param>
        public void HandleInput(InputState input)
        {
            //Let the GUI handle user input.
            _GUI.HandleInput(input);
            //Enable the DebugSystem to handle input.
            _DebugSystem.HandleInput(input);

            #region Camera
            //If the CTRL button is not held down.
            if (!input.IsKeyDown(Keys.LeftControl))
            {
                //Manage the camera movement.
                if (input.IsKeyDown(Keys.W)) { MoveCamera(new Vector2(0, -1)); }
                if (input.IsKeyDown(Keys.S)) { MoveCamera(new Vector2(0, 1)); }
                if (input.IsKeyDown(Keys.A)) { MoveCamera(new Vector2(-1, 0)); }
                if (input.IsKeyDown(Keys.D)) { MoveCamera(new Vector2(1, 0)); }

                //Let the user zoom in and out.
                if (input.IsKeyDown(Keys.Z)) { _Camera.Zoom(-.05f); }
                if (input.IsKeyDown(Keys.X)) { _Camera.Zoom(.05f); }
            }
            #endregion

            #region Editing
            //If the CTRL button is down.
            if (input.IsKeyDown(Keys.LeftControl))
            {
                //Manage the item movement.
                if (input.IsKeyDown(Keys.W)) { MoveItem(new Vector2(0, -5)); }
                if (input.IsKeyDown(Keys.S)) { MoveItem(new Vector2(0, 5)); }
                if (input.IsKeyDown(Keys.A)) { MoveItem(new Vector2(-5, 0)); }
                if (input.IsKeyDown(Keys.D)) { MoveItem(new Vector2(5, 0)); }

                //Let the user rotate the item.
                if (input.IsKeyDown(Keys.Q)) { RotateItem(-.01f); }
                if (input.IsKeyDown(Keys.E)) { RotateItem(.01f); }

                //Let the user scale the item.
                if (input.IsKeyDown(Keys.Z)) { ScaleItem(new Vector2(-.05f, -.05f)); }
                if (input.IsKeyDown(Keys.X)) { ScaleItem(new Vector2(.05f, .05f)); }

                //Let the user copy the item.
                if (input.IsNewKeyPress(Keys.V)) { CopyItem(Helper.GetMousePosition()); }
            }

            //If the GUI hasn't been clicked.
            if (!_IsGUIClicked)
            {
                //Select an item.
                if (input.IsNewLeftMouseClick()) { SelectItem(GetItemAtPosition(Helper.GetMousePosition())); }

                //If the user wants to seize and move an item with the mouse.
                if (input.IsNewLeftMousePress() && _SelectedItem != null)
                {
                    //Handle the item grapple.
                    GrappleItem();
                }
            }

            //If the user disengages the grapple function.
            if (input.IsNewLeftMouseReleased())
            {
                //If the grapple joint exists.
                if (_MouseGrappleJoint != null)
                {
                    //Remove the grapple joint from the world simulation.
                    _Level.World.RemoveJoint(_MouseGrappleJoint);
                    _MouseGrappleJoint = null;
                }

                //Reset the grapple point.
                _ItemGrapplePoint = Vector2.Zero;
            }
            #endregion

            //Quickie.
            if (input.IsKeyDown(Keys.N)) { SetUpTreeView(); }
            if (input.IsNewKeyPress(Keys.M)) { ToggleGUI(); }

            //Let the level handle user input.
            _Level.HandleInput(input);
        }
Beispiel #2
0
        /// <summary>
        /// Handle user input.
        /// </summary>
        /// <param name="input">The helper for reading input from the user.</param>
        public virtual void HandleInput(InputState input)
        {
            //If the component is not active nor visible, discontinue.
            if (!_IsActive || !_IsVisible) { return; }

            //If the left mouse button has been pressed.
            if (input.IsNewLeftMouseClick())
            {
                //If the user clicks somewhere on the item, fire the event.
                if (Helper.IsPointWithinBox(new Vector2(Mouse.GetState().X, Mouse.GetState().Y), Position, Width, Height))
                {
                    //Fire the event.
                    MouseClickInvoke(new Vector2(Mouse.GetState().X, Mouse.GetState().Y), MouseButton.Left);
                }
                //If not, see if it is appropriate to defocus the component.
                else { FocusChangeInvoke(false); }
            }

            //If the right mouse button has been pressed.
            if (input.IsNewRightMouseClick())
            {
                //If the user clicks somewhere on the item, fire the event.
                if (Helper.IsPointWithinBox(new Vector2(Mouse.GetState().X, Mouse.GetState().Y), Position, Width, Height))
                {
                    //Fire the event.
                    MouseClickInvoke(new Vector2(Mouse.GetState().X, Mouse.GetState().Y), MouseButton.Right);
                }
                //If not, see if it is appropriate to defocus the component.
                else { FocusChangeInvoke(false); }
            }

            //If the left mouse button is being held down.
            if (input.IsNewLeftMousePress())
            {
                //If the user clicks somewhere on the item, fire the event.
                if (Helper.IsPointWithinBox(new Vector2(Mouse.GetState().X, Mouse.GetState().Y), Position, Width, Height))
                {
                    //Fire the event.
                    MouseDownInvoke(Helper.GetMousePosition(), MouseButton.Left);
                }
            }

            //If the mouse is currently hovering over the component.
            if (Helper.IsPointWithinBox(Helper.GetMousePosition(), Position, Width, Height))
            {
                //If the mouse has just entered the component's surface, fire the event and enable the flag.
                if (!_IsMouseHovering) { MouseHoverInvoke(); }
            }
            //Else, disable the flag.
            else { _IsMouseHovering = false; }

            //Loop through all items and give them access to user input.
            _Items.ForEach(item => item.HandleInput(input));
        }
Beispiel #3
0
        /// <summary>
        /// Handle user input.
        /// </summary>
        /// <param name="input">The helper for reading input from the user.</param>
        public override void HandleInput(InputState input)
        {
            //The inherited method.
            base.HandleInput(input);

            //If the scroller is active.
            if (IsActive)
            {
                //If the scroller is visible.
                if (IsVisible)
                {
                    //If the thumb button is currently held down but the mouse is pointing somewhere else.
                    if ((_IsThumbDown) && (!Helper.IsPointWithinBox(new Vector2(Mouse.GetState().X, Mouse.GetState().Y), _Thumb.Position, _Thumb.Width, _Thumb.Height)))
                    {
                        //If the left mouse button is still held down, pretend that the button is still held down.
                        if (input.IsNewLeftMousePress()) { OnThumbDown(this, new MouseClickEventArgs(new Vector2(Mouse.GetState().X, Mouse.GetState().Y), MouseButton.Left)); }
                        //Otherwise the thumb button isn't held down.
                        else { _IsThumbDown = false; }
                    }
                }
            }
        }