public virtual void Draw(FontRenderer fontRenderer, int x, int y, float openCoeff) { if (openCoeff <= 0) { return; } var rectInterior = new Rectangle(new Point(x, y), Size()); float openResize = MathHelper.Lerp(-0.5f, 0.0f, openCoeff); rectInterior.Inflate(rectInterior.Width * openResize, rectInterior.Height * openResize); var minWidth = rectInterior.Width * 2 / 3; fontRenderer.Scene.DrawUI(ContentSprite, rectInterior, Color.White); if (!Label.IsEmpty() && openCoeff >= 1) { var width = (int)MathHelper.Clamp(Label.GetContentWidth() + 8, minWidth, rectInterior.Width); Rectangle rectExterior = new Rectangle(rectInterior.X + (rectInterior.Width - width) / 2, rectInterior.Y - 20, width, 16); fontRenderer.Scene.DrawUI(LabelSprite, rectExterior, Color.White); Label.Draw(new Vector2(rectExterior.X, rectExterior.Y), fontRenderer); } }
private void DrawTooltip() { if (TooltipText != null && !TooltipText.IsEmpty()) { SpriteReference ui_tooltip = SpriteLoader.Instance.AddSprite("content/ui_box"); int tooltipWidth = (int)TooltipText.GetContentWidth(); int screenWidth = Viewport.Width - 8 - InputState.MouseX + 4; bool invert = false; if (tooltipWidth > screenWidth) { screenWidth = Viewport.Width - screenWidth; invert = true; } int tooltipHeight = (int)TooltipText.GetContentHeight(); int tooltipX = InputState.MouseX + 4; int tooltipY = Math.Max(0, InputState.MouseY - 4 - tooltipHeight); if (invert) { tooltipX -= tooltipWidth; } DrawUI(ui_tooltip, new Rectangle(tooltipX - 2, tooltipY - 2, tooltipWidth + 4, tooltipHeight + 4), Color.White); TooltipText.Draw(new Vector2(tooltipX, tooltipY), FontRenderer); } }