Example #1
0
        /// <summary>
        /// This should update anything that requires mouse, keyboard, gamepad, joystick, or other input controls. (Dragging, etc.)
        /// </summary>
        /// <param name="m">The current MouseState object.</param>
        /// <param name="gt">A value representing the elapsed <code>GameTime</code> since the last update.</param>
        /// <param name="hasFocus">A value indicating whether or not the application has focus.</param>
        public static void UpdateAll(GameTime gt, bool hasFocus)
        {
            if (MouseStateManager.WentDown(MouseButtons.Left) ||
                MouseStateManager.WentDown(MouseButtons.Middle) ||
                MouseStateManager.WentDown(MouseButtons.Right))
            {
                int f = GetActiveForm(new EFD.Point(MouseStateManager.MouseStateNow.X, MouseStateManager.MouseStateNow.Y));

                if (f > 0 || (f > -1 && ActiveForm == null))
                {
                    Forms[f].Activate();
                }
                else if (f < 0)
                {
                    ActiveForm = null;
                }
            }

            (ActiveForm as Form)?.Update(hasFocus, gt);

            for (int i = 0; i < Forms.Count; i++)
            {
                (Forms[i] as Form)?.Update(false, gt);
            }
        }
Example #2
0
        private void Update(bool hasFocus, GameTime gt)
        {
            // We should only process things that require input if the game is focused, the form is visible, and the form is enabled.
            if (Enabled && Visible && hasFocus)
            {
                if (MouseStateManager.MouseStateNow.X >= Bounds.Left &&
                    MouseStateManager.MouseStateNow.X < Bounds.Right &&
                    MouseStateManager.MouseStateNow.Y >= Bounds.Top &&
                    MouseStateManager.MouseStateNow.Y < Bounds.Bottom)
                {
                    if (MouseStateManager.MouseStateNow.LeftButton == ButtonState.Pressed ||
                        MouseStateManager.MouseStateNow.RightButton == ButtonState.Pressed)
                    {
                        Select();
                        SelectControl(this, MouseStateManager.MouseStateNow);
                    }

                    if (MouseStateManager.WentUp(MouseButtons.Left))
                    {
                        if (DateTime.UtcNow - _clickStart <= _clickTrigger)
                        {
                            OnClick(new MouseEventArgs(MouseStateManager.ButtonsDown(), 1, MouseStateManager.MouseStateNow.X, MouseStateManager.MouseStateNow.Y, 0));
                        }

                        _inDrag = false;

                        OnMouseUp(new MouseEventArgs(MouseButtons.Left, 0, MouseStateManager.MouseStateNow.X, MouseStateManager.MouseStateNow.Y, MouseStateManager.MouseStateNow.ScrollWheelValue - MouseStateManager.MouseStatePrevious.ScrollWheelValue));
                    }
                    else if (MouseStateManager.WentDown(MouseButtons.Left))
                    {
                        _clickStart = DateTime.UtcNow;

                        if (ShowTitleBar)
                        {
                            if (MouseStateManager.MouseStateNow.X >= Bounds.Left &&
                                MouseStateManager.MouseStateNow.X < Bounds.Right &&
                                MouseStateManager.MouseStateNow.Y >= Location.Y &&
                                MouseStateManager.MouseStateNow.Y < Location.Y + TitleBarHeight)
                            {
                                _dragMouseStart = new EFD.Point(MouseStateManager.MouseStateNow.X, MouseStateManager.MouseStateNow.Y);
                                _dragPosStart   = Location;
                                _inDrag         = true;
                            }
                        }

                        OnMouseDown(new MouseEventArgs(MouseButtons.Left, 0, MouseStateManager.MouseStateNow.X, MouseStateManager.MouseStateNow.Y, MouseStateManager.MouseStateNow.ScrollWheelValue - MouseStateManager.MouseStatePrevious.ScrollWheelValue));
                    }
                }

                if (MouseStateManager.MouseStateNow.LeftButton == ButtonState.Pressed)
                {
                    if (AllowDrag && _inDrag && ShowTitleBar)
                    {
                        Location = _dragPosStart + new EFD.Size(MouseStateManager.MouseStateNow.X - _dragMouseStart.X, MouseStateManager.MouseStateNow.Y - _dragMouseStart.Y);
                    }
                }

                foreach (var c in Controls)
                {
                    var updateableControl = c as IUpdateableControl;
                    updateableControl?.Update(c == ActiveControl, gt);
                }
            }
            else if (Enabled && Visible)
            {
                // Down here we can do any updating that doesn't require input. The form must be both Enabled and Visible for us to do anything.
            }
        }