/// <summary> /// Takes a string of text and applies a texture to it. /// </summary> /// <param name="text">The text to texture.</param> /// <param name="font">The font of the text.</param> /// <param name="maxWidth">The maximum width of the text.</param> /// <param name="background">The background of the text. (default: none/null)</param> /// <param name="orientation">The orientation of the text. (default: left)</param> /// <returns>The texturized text.</returns> public LoadedTexture GenTextTexture(string text, CairoFont font, int maxWidth, TextBackground background = null, EnumTextOrientation orientation = EnumTextOrientation.Left) { if (background == null) { background = defaultBackground; } double fullTextWidth = 0; string[] lines = text.Split('\n'); for (int i = 0; i < lines.Length; i++) { lines[i] = lines[i].TrimEnd(); TextExtents textents = ((CairoFont)font).GetTextExtents(lines[i]); fullTextWidth = Math.Max(textents.Width, fullTextWidth); } int width = (int)Math.Min(maxWidth, fullTextWidth) + 2 * background.Padding; TextDrawUtil prober = new TextDrawUtil(); double height = prober.GetMultilineTextHeight(font as CairoFont, text, width) + 2 * background.Padding; return(GenTextTexture(text, font, width, (int)height + 1, background, orientation)); }
public RichTextComponent(ICoreClientAPI api, string displayText, CairoFont font) : base(api) { this.displayText = displayText; this.font = font; if (displayText.Length > 0) { // ok apparently text extents of " " is 0 on a mac? o.O if (displayText[displayText.Length - 1] == ' ') { PaddingRight = 0.75 * (font.GetTextExtents("a b").Width - font.GetTextExtents("ab").Width); // added 0.75 multiplier because there is always too much spacing o.o } if (displayText[0] == ' ') { PaddingLeft = 0.75 * (font.GetTextExtents("a b").Width - font.GetTextExtents("ab").Width); } //this.displayText = displayText.Trim(new char[] { ' ' }); } else { PaddingLeft = 0; PaddingRight = 0; } textUtil = new TextDrawUtil(); }
public RichTextComponent(ICoreClientAPI api, string displayText, CairoFont font) : base(api) { this.displayText = displayText; this.font = font; if (displayText.Length > 0) { // ok apparently text extents of " " is 0 on a mac? o.O if (displayText[displayText.Length - 1] == ' ') { PaddingRight = (font.GetTextExtents("a b").Width - font.GetTextExtents("ab").Width) / RuntimeEnv.GUIScale; } if (displayText[0] == ' ') { PaddingLeft = (font.GetTextExtents("a b").Width - font.GetTextExtents("ab").Width) / RuntimeEnv.GUIScale; } } else { PaddingLeft = 0; PaddingRight = 0; } textUtil = new TextDrawUtil(); }
/// <summary> /// The prober for the text size. /// </summary> ///public TextSizeProber Prober; /// <summary> /// Creates a new text based element. /// </summary> /// <param name="capi">The Client API</param> /// <param name="text">The text of this element.</param> /// <param name="font">The font of the text.</param> /// <param name="bounds">The bounds of the element.</param> public GuiElementTextBase(ICoreClientAPI capi, string text, CairoFont font, ElementBounds bounds) : base(capi, bounds) { Font = font; textUtil = new TextDrawUtil(); this.text = text; }