Ejemplo n.º 1
0
 private bool IsCurrentlyMousedOver(GuiComponent component)
 {
     if (component == null) { return false; }
     double mouseX = _currentMousePositionInWorldCoordinates.X;
     double mouseY = _currentMousePositionInWorldCoordinates.Y;
     if (mouseX > component.Left && mouseX < component.Right && mouseY < component.Top && mouseY > component.Bottom)
     {
         return true;
     }
     return false;
 }
Ejemplo n.º 2
0
        public override void Update(double elapsedTime)
        {
            if (_registrees.Count == 0) { return; }

            UpdateCurrentMousePosition();

            if (SingletonFactory.GetInput().Mouse.LeftPressed && _previouslyMousedOverComponent != null && IsCurrentlyMousedOver(_previouslyMousedOverComponent))
            {
                SingletonFactory.GetEventHub().SendEvent("ChangeTextureCommand", this, EventArgWriteUtil.GetChangeTextureCommandArgs(GuiTextureType.MOUSE_OVER), _previouslyMousedOverComponent);
                SingletonFactory.GetEventHub().FireEvent("OnClick", _previouslyMousedOverComponent);
                _isPreviouslyMousedOverComponentAlreadyDown = false;
            }
            if (!IsCurrentlyMousedOver(_previouslyMousedOverComponent) && !SingletonFactory.GetInput().Mouse.LeftHeld) // If still mousing over same component or holding the mouse, do nothing.
            {
                if (_previouslyMousedOverComponent != null)
                {
                    SingletonFactory.GetEventHub().SendEvent("ChangeTextureCommand", this, EventArgWriteUtil.GetChangeTextureCommandArgs(GuiTextureType.NULL), _previouslyMousedOverComponent);
                    _previouslyMousedOverComponent = null;
                }
                foreach (GuiComponent component in _registrees)
                {
                    if (component.IsClickable && IsCurrentlyMousedOver(component))
                    {
                        _previouslyMousedOverComponent = component;
                        SingletonFactory.GetEventHub().SendEvent("ChangeTextureCommand", this, EventArgWriteUtil.GetChangeTextureCommandArgs(GuiTextureType.MOUSE_OVER), component);
                        break;
                    }
                }
            }

            if (SingletonFactory.GetInput().Mouse.LeftHeld && _previouslyMousedOverComponent != null && !_isPreviouslyMousedOverComponentAlreadyDown)
            {
                _isPreviouslyMousedOverComponentAlreadyDown = true;
                SingletonFactory.GetEventHub().SendEvent("ChangeTextureCommand", this, EventArgWriteUtil.GetChangeTextureCommandArgs(GuiTextureType.MOUSE_DOWN), _previouslyMousedOverComponent);
            }
        }