public void display(SpriteBatch spriteBatch, Vector2 mouseLocation, int screenWidth, int screenHeight) { foreach (UIElement button in UIElements) { UIElement.buttonInteractionState state = getInteractionState(ref mouseLocation, button); button.draw(spriteBatch, state); } foreach (UIElement button in UIElements) { if (button.hasToolTip() && button.locIsWithinElement(mouseLocation)) { string toDraw = button.getToolTip(); int toolTipWidthInPixels = (int)(toDraw.Length * 8.1429) + 3; Vector2 toolTipLoc = new Vector2(button.getRectangle().Center.X - toolTipWidthInPixels / 2, button.getRectangle().Center.Y - button.getRectangle().Height / 2 - 23);//mouseLocation + new Vector2(20, 0); if (toolTipLoc.X + toolTipWidthInPixels > screenWidth) { toolTipLoc.X = screenWidth - toolTipWidthInPixels; } spriteBatch.Draw(ContentDistributor.consoleBackground, new Rectangle((int)toolTipLoc.X - 3, (int)(toolTipLoc.Y - 3), toolTipWidthInPixels, 20), Color.White); spriteBatch.DrawString(ContentDistributor.toolTipFont, toDraw, toolTipLoc, Color.White); } } }
private static UIElement.buttonInteractionState getInteractionState(ref Vector2 mouseLocation, UIElement button) { UIElement.buttonInteractionState state = UIElement.buttonInteractionState.none; if (button.locIsWithinElement(mouseLocation)) { state = UIElement.buttonInteractionState.mousedOver; } return(state); }