Exemple #1
0
            public void Update(TaeInputHandler input, TaeTransport parentTransport)
            {
                if (IsSeparator)
                {
                    return;
                }

                if (!(GetIsEnabled?.Invoke() ?? true) || Rect.IsEmpty)
                {
                    state = prevState = TransportButtonState.Normal;
                    return;
                }

                bool hotkeyPressed = GetHotkey?.Invoke(this) ?? false;

                var relativeMousePos = input.MousePositionPoint - parentTransport.Rect.Location;

                bool mouseHover = Rect.Contains(relativeMousePos);

                if (mouseHover)
                {
                    if (input.LeftClickDown && state != TransportButtonState.HoldingClick)
                    {
                        state = TransportButtonState.HoldingClick;
                    }
                    else if (!input.LeftClickHeld)
                    {
                        state = TransportButtonState.Hover;
                    }
                }
                else
                {
                    if (prevMouseHover)
                    {
                        state = prevState = TransportButtonState.Normal;
                    }
                }

                //if (input.LeftClickHeld && !hotkeyPressed)
                //    prevState = state;

                if (hotkeyPressed)
                {
                    state = TransportButtonState.HoldingClick;
                }
                else if (!mouseHover)
                {
                    state = TransportButtonState.Normal;
                }

                if (state != TransportButtonState.HoldingClick && prevState == TransportButtonState.HoldingClick)
                {
                    OnClick?.Invoke();
                }

                prevState      = state;
                prevMouseHover = mouseHover;
            }
        public void UpdateInput(TaeInputHandler input, float elapsedSeconds, bool allowScrollWheel)
        {
            var relMouse = new Point((int)(input.MousePosition.X),
                                     (int)(input.MousePosition.Y));

            if (CurrentScroll == ScrollbarType.None && input.LeftClickDown)
            {
                if (!DisableHorizontalScroll && HorizontalBox.Contains(relMouse))
                {
                    CurrentScroll           = ScrollbarType.Horizontal;
                    HorizontalBoxGrabOffset = new Point(relMouse.X - HorizontalBox.X, relMouse.Y - HorizontalBox.Y);
                }
                else if (!DisableVerticalScroll && VerticalBox.Contains(relMouse))
                {
                    CurrentScroll         = ScrollbarType.Vertical;
                    VerticalBoxGrabOffset = new Point(relMouse.X - VerticalBox.X, relMouse.Y - VerticalBox.Y);
                }
            }
            else if (CurrentScroll == ScrollbarType.Horizontal)
            {
                //ScrollByPixels(new Vector2(input.MousePositionDelta.X, 0));
                ScrollHorizontalBarToMouse(relMouse);
            }
            else if (CurrentScroll == ScrollbarType.Vertical)
            {
                //ScrollByPixels(new Vector2(0, input.MousePositionDelta.Y));
                ScrollVerticalBarToMouse(relMouse);
            }

            if (!input.LeftClickHeld)
            {
                CurrentScroll = ScrollbarType.None;
            }

            ScrollUpButtonHeld    = CurrentScroll == ScrollbarType.None && !DisableVerticalScroll && input.LeftClickHeld && ScrollUpArrowBox.Contains(relMouse);
            ScrollDownButtonHeld  = CurrentScroll == ScrollbarType.None && !DisableVerticalScroll && input.LeftClickHeld && ScrollDownArrowBox.Contains(relMouse);
            ScrollLeftButtonHeld  = CurrentScroll == ScrollbarType.None && !DisableHorizontalScroll && input.LeftClickHeld && ScrollLeftArrowBox.Contains(relMouse);
            ScrollRightButtonHeld = CurrentScroll == ScrollbarType.None && !DisableHorizontalScroll && input.LeftClickHeld && ScrollRightArrowBox.Contains(relMouse);

            if (!DisableVerticalScroll)
            {
                if (ScrollUpButton.Update(elapsedSeconds, ScrollUpButtonHeld))
                {
                    ScrollByVirtualScrollUnits(new Vector2(0, -ScrollArrowButtonVirtualScrollAmountY));
                }

                if (ScrollDownButton.Update(elapsedSeconds, ScrollDownButtonHeld))
                {
                    ScrollByVirtualScrollUnits(new Vector2(0, ScrollArrowButtonVirtualScrollAmountY));
                }
            }

            if (!DisableHorizontalScroll)
            {
                if (ScrollLeftButton.Update(elapsedSeconds, ScrollLeftButtonHeld))
                {
                    ScrollByVirtualScrollUnits(new Vector2(-ScrollArrowButtonVirtualScrollAmountX, 0));
                }

                if (ScrollRightButton.Update(elapsedSeconds, ScrollRightButtonHeld))
                {
                    ScrollByVirtualScrollUnits(new Vector2(ScrollArrowButtonVirtualScrollAmountX, 0));
                }
            }


            var scrollWheel = allowScrollWheel ? input.ScrollDelta : 0;

            if (scrollWheel != 0)
            {
                if (input.KeyHeld(Microsoft.Xna.Framework.Input.Keys.LeftShift) || input.KeyHeld(Microsoft.Xna.Framework.Input.Keys.RightShift))
                {
                    if (!DisableHorizontalScroll)
                    {
                        ScrollByVirtualScrollUnits(new Vector2(-scrollWheel * ScrollWheelVirtualScrollAmountX, 0));
                    }
                }
                else
                {
                    if (!DisableVerticalScroll)
                    {
                        ScrollByVirtualScrollUnits(new Vector2(0, -scrollWheel * ScrollWheelVirtualScrollAmountY));
                    }
                }
            }
        }