From 4cdbf742564b8d37edf5edf09b24b92ae67d3f97 Mon Sep 17 00:00:00 2001 From: Mustafa Alperen Seki Date: Mon, 5 Oct 2020 20:36:18 +0300 Subject: [PATCH] Add Align: to SupportPowerTimerWidget. --- .../Widgets/SupportPowerTimerWidget.cs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/OpenRA.Mods.Common/Widgets/SupportPowerTimerWidget.cs b/OpenRA.Mods.Common/Widgets/SupportPowerTimerWidget.cs index 831601ed25..c75aef8c55 100644 --- a/OpenRA.Mods.Common/Widgets/SupportPowerTimerWidget.cs +++ b/OpenRA.Mods.Common/Widgets/SupportPowerTimerWidget.cs @@ -22,6 +22,7 @@ namespace OpenRA.Mods.Common.Widgets { public readonly string Font = "Bold"; public readonly string Format = "{0}: {1}"; + public readonly TextAlign Align = TextAlign.Left; public readonly TimerOrder Order = TimerOrder.Descending; readonly int timestep; @@ -80,7 +81,16 @@ namespace OpenRA.Mods.Common.Widgets foreach (var t in texts) { var font = Game.Renderer.Fonts[Font]; - font.DrawTextWithShadow(t.Text, new float2(Bounds.Location) + new float2(0, y), t.Color, bgDark, bgLight, 1); + var textSize = font.Measure(t.Text); + var location = new float2(Bounds.Location) + new float2(0, y); + + if (Align == TextAlign.Center) + location += new int2((Bounds.Width - textSize.X) / 2, 0); + + if (Align == TextAlign.Right) + location += new int2(Bounds.Width - textSize.X, 0); + + font.DrawTextWithShadow(t.Text, location, t.Color, bgDark, bgLight, 1); y += (font.Measure(t.Text).Y + 5) * (int)Order; } }