public void DrawTooltip(SpriteBatch spriteBatch, GraphicsDevice graphicsDevice) { if (!hasTooltip) return; MouseState mouseState = Mouse.GetState(); int widthOfTooltip = graphicsDevice.Viewport.Width - mouseState.X - 18; // right padding, width of cursor bool tooltipToRightOfMouse = true; if (widthOfTooltip < 240) { tooltipToRightOfMouse = false; widthOfTooltip = mouseState.X - 5; // left padding } string[] tooltipLines = Skin.TooltipFont.WordWrap(Tooltip, widthOfTooltip); Vector2 tooltipSize = Skin.TooltipFont.MeasureStringMultiline(tooltipLines); tooltipSize.X += 2 * TooltipPadding; Vector2 tooltipLocation = new Vector2(mouseState.X + (tooltipToRightOfMouse ? 13 : 0), (mouseState.Y + tooltipSize.Y + 5 < graphicsDevice.Viewport.Height ? mouseState.Y : mouseState.Y - tooltipSize.Y)); spriteBatch.FillRectangle(tooltipLocation, tooltipSize, Color.Beige); spriteBatch.DrawRectangle(tooltipLocation, tooltipSize, Color.Black); spriteBatch.DrawStrings(Skin.TooltipFont, tooltipLines, tooltipLocation + new Vector2(TooltipPadding, 0), Color.Black); }