fixed 823 -- mouse interaction with password fields uses the metrics of the mask character, not the actual content
This commit is contained in:
@@ -12,16 +12,10 @@ namespace OpenRA.Widgets
|
||||
{
|
||||
public class PasswordFieldWidget : TextFieldWidget
|
||||
{
|
||||
public PasswordFieldWidget() : base() {}
|
||||
protected PasswordFieldWidget(PasswordFieldWidget widget) : base(widget) {}
|
||||
|
||||
// TODO: Mouse interaction is wrong with this.
|
||||
|
||||
public override void DrawInner()
|
||||
{
|
||||
DrawWithString(new string('*', Text.Length));
|
||||
}
|
||||
public PasswordFieldWidget() : base() { }
|
||||
protected PasswordFieldWidget(PasswordFieldWidget widget) : base(widget) { }
|
||||
|
||||
protected override string GetApparentText() { return new string('*', Text.Length); }
|
||||
public override Widget Clone() { return new PasswordFieldWidget(this); }
|
||||
}
|
||||
}
|
||||
@@ -79,11 +79,13 @@ namespace OpenRA.Widgets
|
||||
return true;
|
||||
}
|
||||
|
||||
protected virtual string GetApparentText() { return text; }
|
||||
|
||||
public int ClosestCursorPosition(int x)
|
||||
{
|
||||
var apparentText = GetApparentText();
|
||||
var font = Game.Renderer.Fonts[Font];
|
||||
var textSize = font.Measure(Text);
|
||||
var textSize = font.Measure(apparentText);
|
||||
|
||||
var start = RenderOrigin.X + LeftMargin;
|
||||
if (textSize.X > Bounds.Width - LeftMargin - RightMargin && Focused)
|
||||
@@ -91,9 +93,9 @@ namespace OpenRA.Widgets
|
||||
|
||||
int minIndex = -1;
|
||||
int minValue = int.MaxValue;
|
||||
for (int i = 0; i <= Text.Length; i++)
|
||||
for (int i = 0; i <= apparentText.Length; i++)
|
||||
{
|
||||
var dist = Math.Abs(start + font.Measure(Text.Substring(0,i)).X - x);
|
||||
var dist = Math.Abs(start + font.Measure(apparentText.Substring(0, i)).X - x);
|
||||
if (dist > minValue)
|
||||
break;
|
||||
minValue = dist;
|
||||
@@ -191,13 +193,14 @@ namespace OpenRA.Widgets
|
||||
base.Tick();
|
||||
}
|
||||
|
||||
public virtual void DrawWithString(string text)
|
||||
public override void DrawInner()
|
||||
{
|
||||
var apparentText = GetApparentText();
|
||||
var font = Game.Renderer.Fonts[Font];
|
||||
var pos = RenderOrigin;
|
||||
|
||||
var textSize = font.Measure(text);
|
||||
var cursorPosition = font.Measure(text.Substring(0,CursorPosition));
|
||||
var textSize = font.Measure(apparentText);
|
||||
var cursorPosition = font.Measure(apparentText.Substring(0, CursorPosition));
|
||||
|
||||
var disabled = IsDisabled();
|
||||
var state = disabled ? "textfield-disabled" :
|
||||
@@ -222,7 +225,7 @@ namespace OpenRA.Widgets
|
||||
}
|
||||
|
||||
var color = disabled ? DisabledColor : TextColor;
|
||||
font.DrawText(text, textPos, color);
|
||||
font.DrawText(apparentText, textPos, color);
|
||||
|
||||
if (showCursor && Focused)
|
||||
font.DrawText("|", new float2(textPos.X + cursorPosition.X - 2, textPos.Y), Color.White);
|
||||
@@ -231,11 +234,6 @@ namespace OpenRA.Widgets
|
||||
Game.Renderer.DisableScissor();
|
||||
}
|
||||
|
||||
public override void DrawInner()
|
||||
{
|
||||
DrawWithString(Text);
|
||||
}
|
||||
|
||||
public override Widget Clone() { return new TextFieldWidget(this); }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user