public void Draw(SpriteBatch spriteBatch, GameTime time) { Use(); if (_currentState == null) { return; } MouseState state = Mouse.GetState(); MousePosition = new Vector2(state.X, state.Y); bool flag = state.LeftButton == ButtonState.Pressed && Main.hasFocus; UIElement uIElement = Main.hasFocus ? _currentState.GetElementAt(MousePosition) : null; _clickDisabledTimeRemaining = Math.Max(0.0, _clickDisabledTimeRemaining - time.ElapsedGameTime.TotalMilliseconds); bool flag2 = _clickDisabledTimeRemaining > 0.0; if (uIElement != _lastElementHover) { if (_lastElementHover != null) { _lastElementHover.MouseOut(new UIMouseEvent(_lastElementHover, MousePosition)); } uIElement?.MouseOver(new UIMouseEvent(uIElement, MousePosition)); _lastElementHover = uIElement; } if (flag && !_wasMouseDown && uIElement != null && !flag2) { _lastElementDown = uIElement; uIElement.MouseDown(new UIMouseEvent(uIElement, MousePosition)); if (_lastElementClicked == uIElement && time.TotalGameTime.TotalMilliseconds - _lastMouseDownTime < 500.0) { uIElement.DoubleClick(new UIMouseEvent(uIElement, MousePosition)); _lastElementClicked = null; } _lastMouseDownTime = time.TotalGameTime.TotalMilliseconds; } else if (!flag && _wasMouseDown && _lastElementDown != null && !flag2) { UIElement lastElementDown = _lastElementDown; if (lastElementDown.ContainsPoint(MousePosition)) { lastElementDown.Click(new UIMouseEvent(lastElementDown, MousePosition)); _lastElementClicked = _lastElementDown; } lastElementDown.MouseUp(new UIMouseEvent(lastElementDown, MousePosition)); _lastElementDown = null; } if (state.ScrollWheelValue != _scrollWheelState) { uIElement?.ScrollWheel(new UIScrollWheelEvent(uIElement, MousePosition, state.ScrollWheelValue - _scrollWheelState)); _scrollWheelState = state.ScrollWheelValue; } _wasMouseDown = flag; if (_currentState != null) { _currentState.Draw(spriteBatch); } }
public void Draw(SpriteBatch spriteBatch, GameTime time) { Use(); if (_currentState != null) { if (_isStateDirty) { _currentState.Recalculate(); _isStateDirty = false; } _currentState.Draw(spriteBatch); } }