internal TextCanvas(int vao, int vbo) { alignHorizontal = TextAlignHorizontal.Left; alignVertical = TextAlignVertical.Center; VAO = vao; VBO = vbo; }
internal void Render(float x, float y, float width, float height, SpriteFont font, TextAlignHorizontal align, Color textColor, Color hotKeyColor) { Vector2 fullSize = font.MeasureString(text1 + hotkeyText + text2); Vector2 size1 = font.MeasureString(text1); Vector2 size2 = font.MeasureString(hotkeyText); Vector2 position = new Vector2(0, y - 3); if (height > 0) position.Y = y + ((float)height / 2.0f - fullSize.Y / 2.0f); switch (align) { case TextAlignHorizontal.Center: position.X = x + ((float)width / 2.0f - fullSize.X / 2.0f); break; case TextAlignHorizontal.Left: position.X = x; break; case TextAlignHorizontal.Right: position.X = x + ((float)width - fullSize.X); break; } MainGame.SpriteBatch.Begin (SpriteSortMode.Immediate, BlendState.AlphaBlend, SamplerState.PointWrap, DepthStencilState.None, RasterizerState.CullCounterClockwise); FontRenderer.DrawString (font, text1, position.X, position.Y, textColor); if (string.IsNullOrEmpty(hotkeyText) == false) { FontRenderer.DrawString (font, hotkeyText, (position.X + size1.X), position.Y, hotKeyColor); } if (string.IsNullOrEmpty(text2) == false) { FontRenderer.DrawString (font, text2, (position.X + size1.X + size2.X), position.Y, textColor); } MainGame.SpriteBatch.End (); }
internal UILabel(string setText) { colText = new UIColorizedText(setText); font = MainGame.DefaultFont; TextAlign = TextAlignHorizontal.Center; }
internal void Render(float x, float y, float width, float height, SpriteFont font, TextAlignHorizontal align, Color textColor, Color hotKeyColor) { Vector2 fullSize = font.MeasureString(text1 + hotkeyText + text2); Vector2 size1 = font.MeasureString(text1); Vector2 size2 = font.MeasureString(hotkeyText); Vector2 position = new Vector2(0, y - 3); if (height > 0) { position.Y = y + ((float)height / 2.0f - fullSize.Y / 2.0f); } switch (align) { case TextAlignHorizontal.Center: position.X = x + ((float)width / 2.0f - fullSize.X / 2.0f); break; case TextAlignHorizontal.Left: position.X = x; break; case TextAlignHorizontal.Right: position.X = x + ((float)width - fullSize.X); break; } MainGame.SpriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, SamplerState.PointWrap, DepthStencilState.None, RasterizerState.CullCounterClockwise); FontRenderer.DrawString(font, text1, position.X, position.Y, textColor); if (string.IsNullOrEmpty(hotkeyText) == false) { FontRenderer.DrawString(font, hotkeyText, (position.X + size1.X), position.Y, hotKeyColor); } if (string.IsNullOrEmpty(text2) == false) { FontRenderer.DrawString(font, text2, (position.X + size1.X + size2.X), position.Y, textColor); } MainGame.SpriteBatch.End(); }