public virtual void SetNewText(string[] textByCardinal, int color) { this.textByCardinal = textByCardinal; font.WithColor(ColorUtil.ToRGBADoubles(color)); font.UnscaledFontsize = fontSize / RuntimeEnv.GUIScale; int lines = 0; for (int i = 0; i < textByCardinal.Length; i++) { if (textByCardinal[i].Length > 0) { lines++; } } if (lines == 0) { loadedTexture?.Dispose(); loadedTexture = null; return; } ImageSurface surface = new ImageSurface(Format.Argb32, TextWidth, TextHeight * lines); Context ctx = new Context(surface); font.SetupContext(ctx); int line = 0; for (int i = 0; i < textByCardinal.Length; i++) { if (textByCardinal[i].Length > 0) { double linewidth = font.GetTextExtents(textByCardinal[i]).Width; ctx.MoveTo((TextWidth - linewidth) / 2, line * TextHeight + ctx.FontExtents.Ascent); ctx.ShowText(textByCardinal[i]); line++; } } if (loadedTexture == null) { loadedTexture = new LoadedTexture(api); } api.Gui.LoadOrUpdateCairoTexture(surface, true, ref loadedTexture); surface.Dispose(); ctx.Dispose(); genMesh(); }
private void OnTextChangedDlg(string text) { if (ignorechange) { return; } ignorechange = true; ImageSurface surface = new ImageSurface(Format.Argb32, 1, 1); Context ctx = new Context(surface); signPostFont.SetupContext(ctx); string[] textByCardinal = new string[8]; for (int i = 0; i < 8; i++) { GuiElementTextInput texinput = SingleComposer.GetTextInput("text" + i); textByCardinal[i] = texinput.GetText(); if (textByCardinal[i] == null) { textByCardinal[i] = ""; } int j = 0; while (ctx.TextExtents(textByCardinal[i]).Width > 185 && j++ < 100) { textByCardinal[i] = textByCardinal[i].Substring(0, textByCardinal[i].Length - 1); } texinput.SetValue(textByCardinal[i]); } OnTextChanged?.Invoke(textByCardinal); ignorechange = false; surface.Dispose(); ctx.Dispose(); }
public override void ComposeElements(Context ctx, ImageSurface surface) { Font.SetupContext(ctx); Bounds.CalcWorldBounds(); Recompose(); }