/// <summary> /// lineX is set to 0 after the second line, lineY is advanced by line height for each line /// </summary> /// <param name="ctx">The context of the text.</param> /// <param name="lines">The preformatted lines of the text.</param> /// <param name="font">The font of the text</param> /// <param name="orientation">The orientation of text (Default: Left)</param> public void DrawMultilineText(Context ctx, CairoFont font, TextLine[] lines, EnumTextOrientation orientation = EnumTextOrientation.Left) { font.SetupContext(ctx); double offsetX = 0; for (int i = 0; i < lines.Length; i++) { TextLine textLine = lines[i]; if (textLine.Text.Length == 0) { continue; } if (orientation == EnumTextOrientation.Center) { offsetX = (textLine.LeftSpace + textLine.RightSpace) / 2; } if (orientation == EnumTextOrientation.Right) { offsetX = textLine.LeftSpace + textLine.RightSpace; } DrawTextLine(ctx, font, textLine.Text, offsetX + textLine.Bounds.X, textLine.Bounds.Y); } }
public double DrawMultilineTextAt(Context ctx, double posX, double posY, EnumTextOrientation orientation = EnumTextOrientation.Left) { Font.SetupContext(ctx); TextLine[] lines = textUtil.Lineize(Font, text, Bounds.InnerWidth); ctx.Save(); Matrix m = ctx.Matrix; m.Translate(posX, posY); ctx.Matrix = m; textUtil.DrawMultilineText(ctx, Font, lines, orientation); ctx.Restore(); return(lines.Length == 0 ? 0 : (lines[lines.Length - 1].Bounds.Y + lines[lines.Length - 1].Bounds.Height)); }
public void Copy(DataGridDrawing v) { this._headVisible = v._headVisible; this._headFont = (System.Drawing.Font)v._headFont.Clone(); this._headColor = v._headColor; this._headBackColor = v._headBackColor; this._headHeight = v._headHeight; this._headOrient = v._headOrient; this._headLineColor = v._headLineColor; this._headLine = v._headLine; this._headUseBackColor = v._headUseBackColor; this._rowHeight = v._rowHeight; this._rowFont = (System.Drawing.Font)v._rowFont.Clone(); this._rowColor = v._rowColor; this._altColor = v._altColor; this._useAltColor = v._useAltColor; this._rowLine = v._rowLine; this._rowLineColor = v._rowLineColor; this._colLine = v._colLine; this._colLineColor = v._colLineColor; this._textOrient = v._textOrient; }
/// <summary> /// Sets the orientation of the text both when clicked and when idle. /// </summary> /// <param name="orientation">The orientation of the text.</param> public void SetOrientation(EnumTextOrientation orientation) { normalText.orientation = orientation; pressedText.orientation = orientation; }
/// <summary> /// Creates a small button for the current GUI. /// </summary> /// <param name="text">The text on the button.</param> /// <param name="onClick">The event fired when the button is clicked.</param> /// <param name="bounds">The bounds of the button.</param> /// <param name="style">The style of the button. (Default: Normal)</param> /// <param name="orientation">The orientation of the text. (Default: center)</param> /// <param name="key">The internal name of the button.</param> public static GuiComposer AddSmallButton(this GuiComposer composer, string text, ActionConsumable onClick, ElementBounds bounds, EnumButtonStyle style = EnumButtonStyle.Normal, EnumTextOrientation orientation = EnumTextOrientation.Center, string key = null) { if (!composer.composed) { CairoFont font1 = CairoFont.ButtonText(); CairoFont font2 = CairoFont.ButtonPressedText(); font1.Fontname = GuiStyle.StandardFontName; font2.Fontname = GuiStyle.StandardFontName; font1.FontWeight = FontWeight.Bold; font2.FontWeight = FontWeight.Bold; font1.UnscaledFontsize = GuiStyle.SmallFontSize; font2.UnscaledFontsize = GuiStyle.SmallFontSize; GuiElementTextButton elem = new GuiElementTextButton(composer.Api, text, font1, font2, onClick, bounds, style); elem.SetOrientation(orientation); composer.AddInteractiveElement(elem, key); } return(composer); }
/// <summary> /// Creates a button for the current GUI. /// </summary> /// <param name="text">The text on the button.</param> /// <param name="onClick">The event fired when the button is clicked.</param> /// <param name="bounds">The bounds of the button.</param> /// <param name="style">The style of the button. (Default: Normal)</param> /// <param name="orientation">The orientation of the text. (Default: center)</param> /// <param name="key">The internal name of the button.</param> public static GuiComposer AddButton(this GuiComposer composer, string text, ActionConsumable onClick, ElementBounds bounds, EnumButtonStyle style = EnumButtonStyle.Normal, EnumTextOrientation orientation = EnumTextOrientation.Center, string key = null) { if (!composer.composed) { GuiElementTextButton elem = new GuiElementTextButton(composer.Api, text, CairoFont.ButtonText(), CairoFont.ButtonPressedText(), onClick, bounds, style); elem.SetOrientation(orientation); composer.AddInteractiveElement(elem, key); } return(composer); }
/// <summary> /// Creates a button for the current GUI. /// </summary> /// <param name="text">The text on the button.</param> /// <param name="onClick">The event fired when the button is clicked.</param> /// <param name="bounds">The bounds of the button.</param> /// <param name="buttonFont">The font of the button.</param> /// <param name="style">The style of the button. (Default: Normal)</param> /// <param name="orientation">The orientation of the text. (Default: center)</param> /// <param name="key">The internal name of the button.</param> public static GuiComposer AddButton(this GuiComposer composer, string text, ActionConsumable onClick, ElementBounds bounds, CairoFont buttonFont, EnumButtonStyle style = EnumButtonStyle.Normal, EnumTextOrientation orientation = EnumTextOrientation.Center, string key = null) { if (!composer.composed) { CairoFont hoverFont = buttonFont.Clone().WithColor(GuiStyle.ActiveButtonTextColor); GuiElementTextButton elem = new GuiElementTextButton(composer.Api, text, buttonFont, hoverFont, onClick, bounds, style); elem.SetOrientation(orientation); composer.AddInteractiveElement(elem, key); } return(composer); }
/// <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="width">The width of the text.</param> /// <param name="height">The height 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 width, int height, TextBackground background = null, EnumTextOrientation orientation = EnumTextOrientation.Left, bool demulAlpha = false) { LoadedTexture tex = new LoadedTexture(capi); GenOrUpdateTextTexture(text, font, width, height, ref tex, background, orientation); return(tex); }
/// <summary> /// Creates a new GUIElementStaticText. /// </summary> /// <param name="capi">The Client API</param> /// <param name="text">The text of the Element</param> /// <param name="orientation">The orientation of the text.</param> /// <param name="bounds">The bounds of the element.</param> /// <param name="font">The font of the text.</param> public GuiElementStaticText(ICoreClientAPI capi, string text, EnumTextOrientation orientation, ElementBounds bounds, CairoFont font) : base(capi, text, font, bounds) { this.orientation = orientation; }
/// <summary> /// Adds a new element that renders text dynamically. /// </summary> /// <param name="capi">The client API.</param> /// <param name="text">The starting text on the component.</param> /// <param name="font">The font of the text.</param> /// <param name="orientation">The orientation of the text.</param> /// <param name="bounds">the bounds of the text.</param> public GuiElementDynamicText(ICoreClientAPI capi, string text, CairoFont font, EnumTextOrientation orientation, ElementBounds bounds) : base(capi, text, font, bounds) { this.orientation = orientation; textTexture = new LoadedTexture(capi); }
/// <summary> /// Draws the text with matrix transformations. /// </summary> /// <param name="ctx">The context of the text.</param> /// <param name="font">The font of the text.</param> /// <param name="text">The text itself.</param> /// <param name="posX">The X position of the text.</param> /// <param name="posY">The Y position of the text.</param> /// <param name="boxWidth">The width of the box containing the text.</param> /// <param name="orientation">The orientation of the text.</param> /// <returns>The new height of the text.</returns> public double AutobreakAndDrawMultilineTextAt(Context ctx, CairoFont font, string text, double posX, double posY, double boxWidth, EnumTextOrientation orientation = EnumTextOrientation.Left) { ctx.Save(); Matrix m = ctx.Matrix; m.Translate((int)posX, (int)posY); ctx.Matrix = m; double height = AutobreakAndDrawMultilineText(ctx, font, text, 0, 0, new TextFlowPath[] { new TextFlowPath(boxWidth) }, orientation); ctx.Restore(); return(height); }
/// <summary> /// Use Matrix transformation to move the draw position /// </summary> /// <param name="ctx">The context of the text.</param> /// <param name="font">The font of the text.</param> /// <param name="text">The text itself.</param> /// <param name="boxWidth">The width of the box containing the text.</param> /// <param name="orientation">The orientation of the text.</param> public void AutobreakAndDrawMultilineText(Context ctx, CairoFont font, string text, double boxWidth, EnumTextOrientation orientation = EnumTextOrientation.Left) => AutobreakAndDrawMultilineText(ctx, font, text, 0, 0, new TextFlowPath[] { new TextFlowPath(boxWidth) }, orientation);
public CairoFont WithOrientation(EnumTextOrientation orientation) { this.Orientation = orientation; return(this); }
static CairoFont getFont(VtmlTagToken tag, Stack <CairoFont> fontStack) { double size = 0; double lineHeight = 1; string fontName = ""; EnumTextOrientation orient = EnumTextOrientation.Left; double[] color = ColorUtil.WhiteArgbDouble; FontWeight weight = FontWeight.Normal; CairoFont prevFont = fontStack.Pop(); if (!tag.Attributes.ContainsKey("size") || !double.TryParse(tag.Attributes["size"], NumberStyles.Any, GlobalConstants.DefaultCultureInfo, out size)) { size = prevFont.UnscaledFontsize; } if (!tag.Attributes.ContainsKey("family")) { fontName = prevFont.Fontname; } else { fontName = tag.Attributes["family"]; } if (!tag.Attributes.ContainsKey("color") || !parseHexColor(tag.Attributes["color"], out color)) { color = prevFont.Color; } double opacity; if (tag.Attributes.ContainsKey("opacity") && double.TryParse(tag.Attributes["opacity"], NumberStyles.Any, GlobalConstants.DefaultCultureInfo, out opacity)) { color = (double[])color.Clone(); color[3] *= opacity; } if (tag.Attributes.ContainsKey("weight")) { weight = tag.Attributes["weight"] == "bold" ? FontWeight.Bold : FontWeight.Normal; } else { weight = prevFont.FontWeight; } if (!tag.Attributes.ContainsKey("lineheight") || !double.TryParse(tag.Attributes["lineheight"], NumberStyles.Any, GlobalConstants.DefaultCultureInfo, out lineHeight)) { lineHeight = prevFont.LineHeightMultiplier; } if (tag.Attributes.ContainsKey("align")) { switch (tag.Attributes["align"]) { case "left": orient = EnumTextOrientation.Left; break; case "right": orient = EnumTextOrientation.Right; break; case "center": orient = EnumTextOrientation.Center; break; case "justify": orient = EnumTextOrientation.Justify; break; } } else { orient = prevFont.Orientation; } fontStack.Push(prevFont); return(new CairoFont(size, fontName, color).WithWeight(weight).WithLineHeightMultiplier(lineHeight).WithOrientation(orient)); }
/// <summary> /// Creates a new Engraved Text element. /// </summary> /// <param name="capi">The client API.</param> /// <param name="text">The text on the element.</param> /// <param name="font">The font of the text.</param> /// <param name="bounds">The bounds of the Text Element.</param> /// <param name="orientation">The orientation of the text.</param> public GuiElementEngravedText(ICoreClientAPI capi, string text, CairoFont font, ElementBounds bounds, EnumTextOrientation orientation = EnumTextOrientation.Left) : base(capi, text, font, bounds) { this.orientation = orientation; }
/// <summary> /// Takes a texture and applies some text to it. /// </summary> /// <param name="text">The text to texture.</param> /// <param name="font">The font of the text.</param> /// <param name="width">The width of the text.</param> /// <param name="height">The height of the text.</param> /// <param name="loadedTexture">The texture to be loaded on to.</param> /// <param name="background">The background of the text. (default: none/null)</param> /// <param name="orientation">The orientation of the text. (default: left)</param> public void GenOrUpdateTextTexture(string text, CairoFont font, int width, int height, ref LoadedTexture loadedTexture, TextBackground background = null, EnumTextOrientation orientation = EnumTextOrientation.Left, bool demulAlpha = false) { if (background == null) { background = defaultBackground; } ElementBounds bounds = new ElementBounds().WithFixedSize(width, height); ImageSurface surface = new ImageSurface(Format.Argb32, width, height); Context ctx = new Context(surface); GuiElementTextBase elTeBa = new GuiElementTextBase(capi, text, font, bounds); ctx.SetSourceRGBA(background.FillColor); GuiElement.RoundRectangle(ctx, 0, 0, width, height, background.Radius); if (background.BorderWidth > 0) { ctx.FillPreserve(); ctx.Operator = Operator.Atop; ctx.LineWidth = background.BorderWidth; ctx.SetSourceRGBA(background.BorderColor); ctx.Stroke(); ctx.Operator = Operator.Over; } else { ctx.Fill(); } //ctx.Antialias = Antialias.Subpixel; elTeBa.textUtil.AutobreakAndDrawMultilineTextAt(ctx, font, text, background.Padding, background.Padding, width, orientation); //int textureId = capi.Gui.LoadCairoTexture(surface, true); - WTF! What was this for?! if (demulAlpha) { surface.DemulAlpha(); } capi.Gui.LoadOrUpdateCairoTexture(surface, true, ref loadedTexture); //surface.WriteToPng("test.png"); surface.Dispose(); ctx.Dispose(); }
/// <summary> /// Adds dynamic text to the GUI. /// </summary> /// <param name="composer"></param> /// <param name="text"></param> /// <param name="font"></param> /// <param name="orientation"></param> /// <param name="bounds"></param> /// <param name="key"></param> /// <returns></returns> public static GuiComposer AddDynamicText(this GuiComposer composer, string text, CairoFont font, EnumTextOrientation orientation, ElementBounds bounds, string key = null) { if (!composer.composed) { GuiElementDynamicText elem = new GuiElementDynamicText(composer.Api, text, font, orientation, bounds); composer.AddInteractiveElement(elem, key); } return(composer); }
/// <summary> /// Draws the text with pre-set breaks. /// </summary> /// <param name="ctx">The context of the text.</param> /// <param name="font">The font of the text.</param> /// <param name="lines">The lines of text.</param> /// <param name="posX">The X position of the text.</param> /// <param name="posY">The Y position of the text.</param> /// <param name="boxWidth">The width of the box containing the text.</param> /// <param name="orientation">The orientation of the text.</param> public void DrawMultilineTextAt(Context ctx, CairoFont font, TextLine[] lines, double posX, double posY, double boxWidth, EnumTextOrientation orientation = EnumTextOrientation.Left) { ctx.Save(); Matrix m = ctx.Matrix; m.Translate(posX, posY); ctx.Matrix = m; font.SetupContext(ctx); DrawMultilineText(ctx, font, lines, orientation); ctx.Restore(); }
/// <summary> /// Adds a static text component to the GUI that automatically resizes as necessary. /// </summary> /// <param name="text">The text of the text component.</param> /// <param name="font">The font of the text.</param> /// <param name="orientation">The orientation of the text.</param> /// <param name="bounds">The bounds of the text container.</param> /// <param name="key">The name of the component.</param> public static GuiComposer AddStaticTextAutoBoxSize(this GuiComposer composer, string text, CairoFont font, EnumTextOrientation orientation, ElementBounds bounds, string key = null) { if (!composer.composed) { GuiElementStaticText elem = new GuiElementStaticText(composer.Api, text, orientation, bounds, font); composer.AddStaticElement(elem, key); elem.AutoBoxSize(); } return(composer); }
public double AutobreakAndDrawMultilineText(Context ctx, CairoFont font, string text, double lineX, double lineY, TextFlowPath[] flowPath, EnumTextOrientation orientation = EnumTextOrientation.Left) { TextLine[] lines = Lineize(font, text, flowPath, lineX, lineY); DrawMultilineText(ctx, font, lines, orientation); if (lines.Length == 0) { return(0); } return(lines[lines.Length - 1].Bounds.Y + lines[lines.Length - 1].Bounds.Height); }
/// <summary> /// Adds a static text component to the GUI /// </summary> /// <param name="text">The text of the text component.</param> /// <param name="font">The font of the text.</param> /// <param name="orientation">The orientation of the text.</param> /// <param name="bounds">The bounds of the text container.</param> /// <param name="key">The name of the component.</param> public static GuiComposer AddStaticText(this GuiComposer composer, string text, CairoFont font, EnumTextOrientation orientation, ElementBounds bounds, string key = null) { if (!composer.composed) { composer.AddStaticElement(new GuiElementStaticText(composer.Api, text, orientation, bounds, font), key); } return(composer); }
/// <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)); }