diff --git a/OpenRA.Game/Widgets/PasswordFieldWidget.cs b/OpenRA.Game/Widgets/PasswordFieldWidget.cs index ee8c127667..ebf43f0682 100644 --- a/OpenRA.Game/Widgets/PasswordFieldWidget.cs +++ b/OpenRA.Game/Widgets/PasswordFieldWidget.cs @@ -16,46 +16,13 @@ namespace OpenRA.Widgets { public class PasswordFieldWidget : TextFieldWidget { - public PasswordFieldWidget() - : base() - { - } - - protected PasswordFieldWidget(PasswordFieldWidget widget) - : base(widget) - { - - } - + public PasswordFieldWidget() : base() {} + protected PasswordFieldWidget(PasswordFieldWidget widget) : base(widget) {} + public override void DrawInner( WorldRenderer wr ) { - int margin = 5; - var font = (Bold) ? Game.Renderer.BoldFont : Game.Renderer.RegularFont; - var cursor = (showCursor && Focused) ? "|" : ""; - var textSize = font.Measure(new string('*', Text.Length) + "|"); - var pos = RenderOrigin; - - WidgetUtils.DrawPanel("dialog3", - new Rectangle(pos.X, pos.Y, Bounds.Width, Bounds.Height)); - - // Inset text by the margin and center vertically - var textPos = pos + new int2(margin, (Bounds.Height - textSize.Y) / 2 - VisualHeight); - - // Right align when editing and scissor when the text overflows - if (textSize.X > Bounds.Width - 2 * margin) - { - if (Focused) - textPos += new int2(Bounds.Width - 2 * margin - textSize.X, 0); - - Game.Renderer.EnableScissor(pos.X + margin, pos.Y, Bounds.Width - 2 * margin, Bounds.Bottom); - } - - font.DrawText(new string('*', Text.Length) + cursor, textPos, Color.White); - - if (textSize.X > Bounds.Width - 2 * margin) - Game.Renderer.DisableScissor(); + DrawWithString(new string('*', Text.Length)); } - public override Widget Clone() { return new PasswordFieldWidget(this); } } } \ No newline at end of file diff --git a/OpenRA.Game/Widgets/TextFieldWidget.cs b/OpenRA.Game/Widgets/TextFieldWidget.cs index 8174bf3f90..67b468ecf0 100644 --- a/OpenRA.Game/Widgets/TextFieldWidget.cs +++ b/OpenRA.Game/Widgets/TextFieldWidget.cs @@ -24,11 +24,7 @@ namespace OpenRA.Widgets public Func OnTabKey = () => false; public Action OnLoseFocus = () => { }; - public TextFieldWidget() - : base() - { - } - + public TextFieldWidget() : base() {} protected TextFieldWidget(TextFieldWidget widget) : base(widget) { @@ -108,12 +104,12 @@ namespace OpenRA.Widgets base.Tick(); } - public override void DrawInner( WorldRenderer wr ) + public virtual void DrawWithString(string text) { int margin = 5; var font = (Bold) ? Game.Renderer.BoldFont : Game.Renderer.RegularFont; var cursor = (showCursor && Focused) ? "|" : ""; - var textSize = font.Measure(Text + "|"); + var textSize = font.Measure(text + "|"); var pos = RenderOrigin; WidgetUtils.DrawPanel("dialog3", @@ -131,11 +127,16 @@ namespace OpenRA.Widgets Game.Renderer.EnableScissor(pos.X + margin, pos.Y, Bounds.Width - 2 * margin, Bounds.Bottom); } - font.DrawText(Text + cursor, textPos, Color.White); + font.DrawText(text + cursor, textPos, Color.White); if (textSize.X > Bounds.Width - 2 * margin) Game.Renderer.DisableScissor(); } + + public override void DrawInner( WorldRenderer wr ) + { + DrawWithString(Text); + } public override Widget Clone() { return new TextFieldWidget(this); } }