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 class PasswordFieldWidget : TextFieldWidget
|
||||||
{
|
{
|
||||||
public PasswordFieldWidget() : base() {}
|
public PasswordFieldWidget() : base() { }
|
||||||
protected PasswordFieldWidget(PasswordFieldWidget widget) : base(widget) {}
|
protected PasswordFieldWidget(PasswordFieldWidget widget) : base(widget) { }
|
||||||
|
|
||||||
// TODO: Mouse interaction is wrong with this.
|
|
||||||
|
|
||||||
public override void DrawInner()
|
|
||||||
{
|
|
||||||
DrawWithString(new string('*', Text.Length));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
protected override string GetApparentText() { return new string('*', Text.Length); }
|
||||||
public override Widget Clone() { return new PasswordFieldWidget(this); }
|
public override Widget Clone() { return new PasswordFieldWidget(this); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -78,12 +78,14 @@ namespace OpenRA.Widgets
|
|||||||
CursorPosition = ClosestCursorPosition(mi.Location.X);
|
CursorPosition = ClosestCursorPosition(mi.Location.X);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected virtual string GetApparentText() { return text; }
|
||||||
|
|
||||||
public int ClosestCursorPosition(int x)
|
public int ClosestCursorPosition(int x)
|
||||||
{
|
{
|
||||||
|
var apparentText = GetApparentText();
|
||||||
var font = Game.Renderer.Fonts[Font];
|
var font = Game.Renderer.Fonts[Font];
|
||||||
var textSize = font.Measure(Text);
|
var textSize = font.Measure(apparentText);
|
||||||
|
|
||||||
var start = RenderOrigin.X + LeftMargin;
|
var start = RenderOrigin.X + LeftMargin;
|
||||||
if (textSize.X > Bounds.Width - LeftMargin - RightMargin && Focused)
|
if (textSize.X > Bounds.Width - LeftMargin - RightMargin && Focused)
|
||||||
@@ -91,9 +93,9 @@ namespace OpenRA.Widgets
|
|||||||
|
|
||||||
int minIndex = -1;
|
int minIndex = -1;
|
||||||
int minValue = int.MaxValue;
|
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)
|
if (dist > minValue)
|
||||||
break;
|
break;
|
||||||
minValue = dist;
|
minValue = dist;
|
||||||
@@ -190,15 +192,16 @@ namespace OpenRA.Widgets
|
|||||||
|
|
||||||
base.Tick();
|
base.Tick();
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void DrawWithString(string text)
|
public override void DrawInner()
|
||||||
{
|
{
|
||||||
|
var apparentText = GetApparentText();
|
||||||
var font = Game.Renderer.Fonts[Font];
|
var font = Game.Renderer.Fonts[Font];
|
||||||
var pos = RenderOrigin;
|
var pos = RenderOrigin;
|
||||||
|
|
||||||
var textSize = font.Measure(text);
|
var textSize = font.Measure(apparentText);
|
||||||
var cursorPosition = font.Measure(text.Substring(0,CursorPosition));
|
var cursorPosition = font.Measure(apparentText.Substring(0, CursorPosition));
|
||||||
|
|
||||||
var disabled = IsDisabled();
|
var disabled = IsDisabled();
|
||||||
var state = disabled ? "textfield-disabled" :
|
var state = disabled ? "textfield-disabled" :
|
||||||
Focused ? "textfield-focused" :
|
Focused ? "textfield-focused" :
|
||||||
@@ -217,12 +220,12 @@ namespace OpenRA.Widgets
|
|||||||
if (Focused)
|
if (Focused)
|
||||||
textPos += new int2(Bounds.Width - LeftMargin - RightMargin - textSize.X, 0);
|
textPos += new int2(Bounds.Width - LeftMargin - RightMargin - textSize.X, 0);
|
||||||
|
|
||||||
Game.Renderer.EnableScissor(pos.X + LeftMargin, pos.Y,
|
Game.Renderer.EnableScissor(pos.X + LeftMargin, pos.Y,
|
||||||
Bounds.Width - LeftMargin - RightMargin, Bounds.Bottom);
|
Bounds.Width - LeftMargin - RightMargin, Bounds.Bottom);
|
||||||
}
|
}
|
||||||
|
|
||||||
var color = disabled ? DisabledColor : TextColor;
|
var color = disabled ? DisabledColor : TextColor;
|
||||||
font.DrawText(text, textPos, color);
|
font.DrawText(apparentText, textPos, color);
|
||||||
|
|
||||||
if (showCursor && Focused)
|
if (showCursor && Focused)
|
||||||
font.DrawText("|", new float2(textPos.X + cursorPosition.X - 2, textPos.Y), Color.White);
|
font.DrawText("|", new float2(textPos.X + cursorPosition.X - 2, textPos.Y), Color.White);
|
||||||
@@ -230,11 +233,6 @@ namespace OpenRA.Widgets
|
|||||||
if (textSize.X > Bounds.Width - LeftMargin - RightMargin)
|
if (textSize.X > Bounds.Width - LeftMargin - RightMargin)
|
||||||
Game.Renderer.DisableScissor();
|
Game.Renderer.DisableScissor();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void DrawInner()
|
|
||||||
{
|
|
||||||
DrawWithString(Text);
|
|
||||||
}
|
|
||||||
|
|
||||||
public override Widget Clone() { return new TextFieldWidget(this); }
|
public override Widget Clone() { return new TextFieldWidget(this); }
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user