Esempio n. 1
0
 public void OnSecondaryMouseButtonAction(InputAction.CallbackContext context)
 {
     // Listen for right mouse button press and release.
     if (context.ReadValueAsButton() && !context.performed)
     {
         RightClicked?.Invoke(ScreenLocation);
     }
     else if (!context.ReadValueAsButton())
     {
         RightReleased?.Invoke(ScreenLocation);
     }
 }
        protected override void HandleInput(Vector2 cursorPos)
        {
            if (IsMousedOver)
            {
                if (!mouseCursorEntered)
                {
                    mouseCursorEntered = true;
                    CursorEntered?.Invoke(_parent, EventArgs.Empty);
                }

                if (SharedBinds.LeftButton.IsNewPressed)
                {
                    GetInputFocus();
                    OnLeftClick();
                }
                else
                    IsNewLeftClicked = false;

                if (SharedBinds.RightButton.IsNewPressed)
                {
                    GetInputFocus();
                    OnRightClick();
                }
                else
                    IsNewRightClicked = false;
            }
            else
            {
                if (mouseCursorEntered)
                {
                    mouseCursorEntered = false;
                    CursorExited?.Invoke(_parent, EventArgs.Empty);
                }

                if (HasFocus && (SharedBinds.LeftButton.IsNewPressed || SharedBinds.RightButton.IsNewPressed))
                    LoseFocus();

                IsNewLeftClicked = false;
                IsNewRightClicked = false;
            }

            if (!SharedBinds.LeftButton.IsPressed && IsLeftClicked)
            {
                LeftReleased?.Invoke(_parent, EventArgs.Empty);
                IsLeftClicked = false;
            }

            if (!SharedBinds.RightButton.IsPressed && IsRightClicked)
            {
                RightReleased?.Invoke(_parent, EventArgs.Empty);
                IsRightClicked = false;
            }
        }
Esempio n. 3
0
        public void Update()
        {
            MouseState    mouse    = Mouse.GetState();
            KeyboardState keyboard = Keyboard.GetState();

            if (!Enabled)
            {
                return;
            }

            if (keyboard.IsKeyDown(Keys.LeftAlt) || keyboard.IsKeyDown(Keys.RightAlt))
            {
                BoxYOffset    += (float)(mouse.ScrollWheelValue - LastMouseWheel) * 0.01f;
                LastMouseWheel = mouse.ScrollWheelValue;
            }
            else
            {
                LastMouseWheel = mouse.ScrollWheelValue;
            }

            MouseOverTimer.Update(DwarfTime.LastTime);
            if (MouseOverTimer.HasTriggered)
            {
                List <Body> selected = SelectBodies(new Rectangle(mouse.X - 10, mouse.Y - 10, 20, 20));

                if (selected.Count > 0)
                {
                    OnMouseOver(selected);
                }
            }

            if (isLeftPressed)
            {
                if (mouse.LeftButton == ButtonState.Released)
                {
                    isLeftPressed   = false;
                    SelectionBuffer = Components.SelectRootBodiesOnScreen(SelectionRectangle, CameraController);
                    LeftReleased.Invoke();
                }
                else
                {
                    Vector3 screenPoint = CameraController.Project(ClickPoint3D);
                    ClickPoint = new Point((int)screenPoint.X, (int)screenPoint.Y);
                    UpdateSelectionRectangle(mouse.X, mouse.Y);
                }
            }
            else if (mouse.LeftButton == ButtonState.Pressed)
            {
                isLeftPressed      = true;
                ClickPoint         = new Point(mouse.X, mouse.Y);
                ClickPoint3D       = PlayState.CursorLightPos;
                SelectionRectangle = new Rectangle(mouse.X, mouse.Y, 0, 0);
            }

            if (AllowRightClickSelection)
            {
                if (isRightPressed)
                {
                    if (mouse.RightButton == ButtonState.Released)
                    {
                        isRightPressed  = false;
                        SelectionBuffer = Components.SelectRootBodiesOnScreen(SelectionRectangle, CameraController);
                        RightReleased.Invoke();
                    }
                    else
                    {
                        Vector3 screenPoint = CameraController.Project(ClickPoint3D);
                        ClickPoint = new Point((int)screenPoint.X, (int)screenPoint.Y);
                        UpdateSelectionRectangle(mouse.X, mouse.Y);
                    }
                }
                else if (mouse.RightButton == ButtonState.Pressed)
                {
                    isRightPressed     = true;
                    ClickPoint         = new Point(mouse.X, mouse.Y);
                    ClickPoint3D       = PlayState.CursorLightPos;
                    SelectionRectangle = new Rectangle(mouse.X, mouse.Y, 0, 0);
                }
            }
        }
Esempio n. 4
0
 protected override void OnRightReleased() => RightReleased?.Invoke(this, EventArgs.Empty);
Esempio n. 5
0
        /// <summary>
        ///     Called every tick.
        /// </summary>
        public void Update()
        {
            MouseState    mouse    = Mouse.GetState();
            KeyboardState keyboard = Keyboard.GetState();

            if (!Enabled)
            {
                return;
            }

            // Select bodies under the mouse if it is hovering.
            MouseOverTimer.Update(DwarfTime.LastTime);
            if (MouseOverTimer.HasTriggered)
            {
                SelectedEntities = SelectBodies(new Rectangle(mouse.X - 2, mouse.Y - 2, 4, 4));

                if (SelectedEntities.Count > 0)
                {
                    OnMouseOver(SelectedEntities);
                }
                else
                {
                    OnMouseOver(new List <Body>());
                }
            }


            // If the left mouse button is pressed, update the selection rectangle.
            if (isLeftPressed)
            {
                if (mouse.LeftButton == ButtonState.Released)
                {
                    isLeftPressed   = false;
                    SelectionBuffer = Components.SelectRootBodiesOnScreen(SelectionRectangle, CameraController);
                    LeftReleased.Invoke();
                }
                else
                {
                    UpdateSelectionRectangle(mouse.X, mouse.Y);
                }
            }
            // Otherwise, if the mouse has first been pressed, initialize selection
            else if (mouse.LeftButton == ButtonState.Pressed)
            {
                isLeftPressed      = true;
                ClickPoint         = new Point(mouse.X, mouse.Y);
                ClickPoint3D       = World.CursorLightPos;
                SelectionRectangle = new Rectangle(mouse.X, mouse.Y, 0, 0);
            }

            if (AllowRightClickSelection)
            {
                // If the right mouse button has been sustained-pressed, update
                // the selection rectangle.
                if (isRightPressed)
                {
                    if (mouse.RightButton == ButtonState.Released)
                    {
                        isRightPressed  = false;
                        SelectionBuffer = Components.SelectRootBodiesOnScreen(SelectionRectangle, CameraController);
                        RightReleased.Invoke();
                    }
                    else
                    {
                        UpdateSelectionRectangle(mouse.X, mouse.Y);
                    }
                }
                // Otherwise if the mouse has been first pressed, initialize selection
                else if (mouse.RightButton == ButtonState.Pressed)
                {
                    isRightPressed     = true;
                    ClickPoint         = new Point(mouse.X, mouse.Y);
                    ClickPoint3D       = World.CursorLightPos;
                    SelectionRectangle = new Rectangle(mouse.X, mouse.Y, 0, 0);
                }
            }

            // If no mouse button has been pressed, there are no bodies currently being selected.
            if (!(isLeftPressed || isRightPressed))
            {
                CurrentBodies.Clear();
            }
        }
Esempio n. 6
0
 protected override void OnRightReleased() => RightReleased?.Invoke(this, new ClickArg(MouseButtons.ButtonRight, ButtonState.Release));