public virtual Point MeasureString() { if (FontId == "" && Font != null) { var p = Font.MeasureString(_text).toPoint(); TextSize = new Point((int)(p.X * Scale), (int)(p.Y * Scale)); } else if (FontId != "") { TextSize = UIFontRenderer.MeasureString(FontId, _text, Scale); } return(TextSize); }
public static void DrawElement(SpriteBatch b, UIElement element, float opacity = 1f) { element.PerfromDrawAction(b); foreach (UIElement child in element.Children.OrderBy(c => c.Z).Where(c => c.Z < 0)) { DrawElement(b, child, element.Opacity * opacity); } if (!element.IsContainer && element.Visible) { if (element.Theme != null && !element.OutOfBounds) { if (!element.Tiled) { b.Draw(element.Theme is ScaledTexture2D s ? s.STexture : element.Theme, element.Bounds, element.SourceRectangle, element.Color * element.Opacity * opacity, element.Rotation, element.Origin, element.SpriteEffects, 0); } else { DrawTiled(b, element, opacity); } } if (element is UITextElement text) { string t = text.GetText(); if (t != null && t != "") { if (text.FontId == "") { b.DrawString(text.Font, text.Text, new Vector2(element.Bounds.X, element.Bounds.Y), text.TextColor * element.Opacity * opacity, 0f, Vector2.Zero, text.Scale, SpriteEffects.None, 0); } else { UIFontRenderer.DrawText(text.FontId, b, element.Bounds.X, element.Bounds.Y, text.Text, text.TextColor * element.Opacity * opacity, text.Scale, 0f, Vector2.Zero); } } } } if (!element.OutOfBounds) { foreach (UIElement child in element.Children.OrderBy(c => c.Z).Where(c => c.Z >= 0)) { DrawElement(b, child, element.Opacity * opacity); } } }