public virtual void Render(Render.ImmediateMode2d context) { if (Visible) { if (GetSetting("hidden-container", null) == null) { if (GetSetting("transparent", null) == null) { context.Texture = context.White; context.Color = (GetSetting("bg-color", Vector3.One) as Vector3?).Value; context.Quad(rect); } var label = GetSetting("label", null); var font = GetSetting("font", null); if (label != null && font != null) { context.Color = (GetSetting("text-color", Vector3.Zero) as Vector3?).Value; BitmapFont.RenderText(label.ToString(), rect.X, rect.Y, rect.Width + rect.X, context, font as BitmapFont); } } foreach (var child in children) { child.Render(context); } } }
public GuiDriver(GraphicsDevice device, Microsoft.Xna.Framework.Content.ContentManager Content) { this.device = device; uiRenderer = new Render.ImmediateMode2d(device); defaultSettings = new PropertySet( "bg-color", new Vector3(0, 1, 0), "text-color", new Vector3(1, 1, 1), "fg-color", new Vector3(1, 1, 1), "hidden-container", null, "font", new BitmapFont(Content.Load <Texture2D>("Content/small-font"), 6, 8, 6) ); }
public static void RenderText( String text, float X, float Y, float wrapAt, Render.ImmediateMode2d context, BitmapFont font, float depth = 0) { context.Texture = font.fontData; var x = X; var y = Y; var kx = (font.glyphWidth - font.kerningWidth) / 2; int col = (int)font.fontData.Width / (int)font.glyphWidth; for (var i = 0; i < text.Length; ++i) { if (x >= wrapAt) { y += font.glyphHeight; x = X; } var code = text[i]; if (code == '\n') { x = X; y += font.glyphHeight; } else if (code == ' ') { x += font.kerningWidth; } else if (code < 0x80) { float fx = (code % col) * font.glyphWidth; float fy = (code / col) * font.glyphHeight; context.Glyph(x, y, font.glyphWidth, font.glyphHeight, fx / font.fontData.Width, fy / font.fontData.Height, (float)font.glyphWidth / (float)font.fontData.Width, (float)font.glyphHeight / (float)font.fontData.Height, depth); x += font.kerningWidth; } } }