示例#1
0
        protected override void OnPreviewMouseMove(MouseEventArgs e)
        {
            // Restart the mouse over timer
            MouseOverTimer.Stop();
            MouseOverTimer.Start();

            base.OnPreviewMouseMove(e);
        }
示例#2
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();
            }
        }