public override void Render(DwarfTime time, SpriteBatch batch) { string text = Text; if (WordWrap) { text = DwarfGUI.WrapLines(Text, LocalBounds, TextFont); } if (Truncate) { Vector2 measure = Datastructures.SafeMeasure(TextFont, text); Vector2 wMeasure = Datastructures.SafeMeasure(TextFont, "W"); if (measure.X > GlobalBounds.Width) { int numLetters = GlobalBounds.Width / (int)wMeasure.X; text = Text.Substring(0, Math.Min(numLetters, Text.Length)) + "..."; } } if (StrokeColor.A > 0) { Drawer2D.DrawAlignedStrokedText(batch, text, TextFont, TextColor, StrokeColor, Alignment, GlobalBounds); } else { Drawer2D.DrawAlignedText(batch, text, TextFont, TextColor, Alignment, GlobalBounds); } base.Render(time, batch); }
public override void Render(DwarfTime time, SpriteBatch batch) { string text = Text; if (WordWrap) { text = DwarfGUI.WrapLines(Text, LocalBounds, TextFont); } Drawer2D.DrawAlignedStrokedText(batch, text, TextFont, TextColor, StrokeColor, Alignment, GlobalBounds); base.Render(time, batch); }
public static void DrawAlignedStrokedText(SpriteBatch batch, string origText, SpriteFont font, Color textColor, Color strokeColor, Alignment align, Rectangle bounds, bool wrap = false) { string text = origText; if (wrap) { text = DwarfGUI.WrapLines(text, bounds, font); } Vector2 size = Datastructures.SafeMeasure(font, text); Vector2 pos = new Vector2((int)(bounds.X + bounds.Width / 2), (int)(bounds.Y + bounds.Height / 2)); Vector2 origin = size * 0.5f; if (align.HasFlag(Alignment.Left)) { origin.X += bounds.Width / 2 - size.X / 2; } if (align.HasFlag(Alignment.Right)) { origin.X -= bounds.Width / 2 - size.X / 2; } if (align.HasFlag(Alignment.Top)) { origin.Y += bounds.Height / 2 - size.Y / 2; } if (align.HasFlag(Alignment.Bottom)) { origin.Y -= bounds.Height / 2 - size.Y / 2; } if (align.HasFlag(Alignment.Under)) { origin.Y -= bounds.Height - size.Y; } origin.X = (int)origin.X; origin.Y = (int)origin.Y; if (textColor.A > 0 && strokeColor.A > 0) { SafeDraw(batch, text, font, strokeColor, pos - new Vector2(1, 0), origin, false); SafeDraw(batch, text, font, strokeColor, pos + new Vector2(1, 0), origin, false); SafeDraw(batch, text, font, strokeColor, pos - new Vector2(0, 1), origin, false); SafeDraw(batch, text, font, strokeColor, pos - new Vector2(0, 1), origin, false); } SafeDraw(batch, text, font, textColor, pos, origin); }
public static void DrawAlignedText(SpriteBatch batch, string origText, SpriteFont font, Color textColor, Alignment align, Rectangle bounds, bool wrap = false) { string text = origText; if (wrap) { text = DwarfGUI.WrapLines(text, bounds, font); } Vector2 size = Datastructures.SafeMeasure(font, text); Vector2 pos = new Vector2(bounds.X + bounds.Width / 2, bounds.Y + bounds.Height / 2); Vector2 origin = size * 0.5f; if (align.HasFlag(Alignment.Left)) { pos.X -= bounds.Width / 2 - size.X / 2; } if (align.HasFlag(Alignment.Right)) { pos.X += bounds.Width / 2 - size.X / 2; } if (align.HasFlag(Alignment.Top)) { pos.Y -= bounds.Height / 2 - size.Y / 2; } if (align.HasFlag(Alignment.Bottom)) { pos.Y += bounds.Height / 2 - size.Y / 2; } if (align.HasFlag(Alignment.Under)) { pos.Y += bounds.Height / 2 + size.Y / 2; } SafeDraw(batch, text, font, textColor, pos, origin); }