Пример #1
0
        public HitBox HitTest()
        {
            var buttonState = _button switch
            {
                MouseButton.Left => UiState.Mouse.LeftButton,
                MouseButton.Right => UiState.Mouse.RightButton,
                MouseButton.Middle => UiState.Mouse.MiddleButton,
            };
            var pos = UiState.Mouse.Position.ToVector2();

            switch (_state)
            {
            case DragState.End:
                if (buttonState != ButtonState.Pressed)
                {
                    return(HitBox.Miss);
                }
                if (_bounds.Contains(pos))
                {
                    _state = DragState.Start;
                }

                break;

            case DragState.Start:
                // could probably remove this one and just set it in the End case
                if (buttonState != ButtonState.Pressed)
                {
                    _state = DragState.End;
                    return(HitBox.Miss);
                }

                _lastMousePosition = pos;
                _state             = DragState.Move;

                break;

            case DragState.Move:
                if (buttonState != ButtonState.Pressed)
                {
                    _state = DragState.End;
                    return(HitBox.Miss);
                }

                var delta = _lastMousePosition - pos;
                if (Math.Abs(delta.X) >= _minimumDragDistance ||
                    Math.Abs(delta.Y) >= _minimumDragDistance)
                {
                    _moveDelta         = delta;
                    _lastMousePosition = pos;
                }

                return(HitBox.Hit(this));
            }

            return(HitBox.Miss);
        }
Пример #2
0
        public HitBox HitTest()
        {
            var delta = UiState.ScrollDelta;

            if (delta != 0 && _parent.Bounds.Contains(UiState.Mouse.Position) && KeyboardManager.IsModifierDown(_modifier))
            {
                if (delta > 0)
                {
                    OnScrollBackward?.Invoke(delta / 120);
                }
                else
                {
                    OnScrollForward?.Invoke(delta / 120);
                }
                OnScroll?.Invoke(delta / 120);
                return(HitBox.Hit(_parent));
            }

            return(HitBox.Miss);
        }
        public override HitBox HitTest()
        {
            HitBox hit;

            if (_draggable.HitTest().IsHit)
            {
                var delta  = (int)(_draggable.GetHorizontalMoveDelta() * _dragMultiplier);
                var parent = (ICanHaveHorizontalScrollBar)Parent;
                parent.HorizontalScroll(-delta);
                _draggable.InvalidateDelta();
                return(HitBox.Hit(this));
            }
            else if (MouseManager.IsDown(MouseButton.Left) &&
                     _bgHitBox.Contains(UiState.Mouse.Position))
            {
                var parent             = (ICanHaveHorizontalScrollBar)Parent;
                var hitBoxX            = UiState.Mouse.Position.X - _bgHitBox.Left;
                var scrollPercent      = (float)hitBoxX / _bgHitBox.Width;
                var scrollIndexAtClick = Math.Min((int)(parent.HorizontalMaxScrollIndex * scrollPercent),
                                                  parent.HorizontalMaxScrollIndex);
                parent.HorizontalScrollTo(scrollIndexAtClick);
            }
            else if ((hit = _leftArrow.HitTest()).IsHit)
            {
                return(hit);
            }
            else if ((hit = _rightArrow.HitTest()).IsHit)
            {
                return(hit);
            }
            else if ((hit = _mouseScrollable.HitTest()).IsHit)
            {
                return(hit);
            }

            return(HitBox.Miss);
        }