Exemplo n.º 1
0
        public void Update(GameTime time, IMouseManager mouse, IKeyboardManager keyboard)
        {
            IsHovered = ScreenRect.Contains(mouse.Position);
            if (IsHovered)
            {
                if (mouse.IsScrollWheelUp())
                {
                    OnMouseWheel(mouse.ScrollWheelDelta);
                    if (MouseWheel != null)
                    {
                        MouseWheel(mouse.ScrollWheelDelta);
                    }
                }
                else if (mouse.IsScrollWheelDown())
                {
                    OnMouseWheel(mouse.ScrollWheelDelta);
                    if (MouseWheel != null)
                    {
                        MouseWheel(mouse.ScrollWheelDelta);
                    }
                }

                if (mouse.IsButtonPressed(MouseButton.Left))
                {
                    OnMouseClick(MouseButton.Left);
                    if (Clicked != null)
                    {
                        Clicked();
                    }
                    if (MouseClicked != null)
                    {
                        MouseClicked(MouseButton.Left);
                    }
                }
                if (mouse.IsButtonPressed(MouseButton.Middle))
                {
                    OnMouseClick(MouseButton.Middle);
                    if (MouseClicked != null)
                    {
                        MouseClicked(MouseButton.Middle);
                    }
                }
                if (mouse.IsButtonPressed(MouseButton.Right))
                {
                    OnMouseClick(MouseButton.Right);
                    if (MouseClicked != null)
                    {
                        MouseClicked(MouseButton.Right);
                    }
                }
            }

            OnUpdate(time, mouse, keyboard);
        }
Exemplo n.º 2
0
        public void Update(GameTime time, IMouseManager mouse)
        {
            TextMenuItem currentHoveredItem = null;

            var currentPos = Pos;

            foreach (var item in _items)
            {
                currentPos = currentPos.Offset(item.Margin.Left, item.Margin.Top);

                var rect      = item.GetScreenRect(currentPos);
                var isHovered = rect.Contains(mouse.Position);

                item.IsHovered = isHovered;

                if (item.IsHovered)
                {
                    currentHoveredItem = item;

                    if (_lastHoverItem != item)
                    {
                        _lastHoverItem = item;
                        if (ItemHovered != null)
                        {
                            ItemHovered(item);
                        }
                    }
                }

                if (item.IsHovered && mouse.IsButtonPressed(MouseButton.Left) && item.IsEnabled)
                {
                    if (ItemClicked != null)
                    {
                        ItemClicked(item);
                    }

                    item.RaiseClicked();
                }

                currentPos = currentPos.Offset(0f, _font.Data.LineHeight + Padding + item.Margin.Bottom);
            }

            if (currentHoveredItem == null)
            {
                _lastHoverItem = null;
            }
        }