Fix focus issues and show a blinky cursor

This commit is contained in:
Paul Chote
2010-07-10 18:09:38 +12:00
parent faf5e7bbf1
commit 5dba8842de
2 changed files with 28 additions and 9 deletions

View File

@@ -61,16 +61,14 @@ namespace OpenRA
public static Widget rootWidget = null;
public static Widget selectedWidget;
public static Widget keyboardFocusWidget;
public void Tick(World world)
{
rootWidget.Tick(world);
if (!world.GameHasStarted) return;
if (world.LocalPlayer == null) return;
++ticksSinceLastMove;
rootWidget.Tick(world);
++ticksSinceLastMove;
}
public void Draw( World world )
@@ -251,8 +249,8 @@ namespace OpenRA
public bool HandleKeyPress(System.Windows.Forms.KeyPressEventArgs e, Modifiers modifiers)
{
if (keyboardFocusWidget != null)
return keyboardFocusWidget.HandleKeyPress(e, modifiers);
if (selectedWidget != null)
return selectedWidget.HandleKeyPress(e, modifiers);
if (rootWidget.HandleKeyPress(e, modifiers))
return true;

View File

@@ -40,16 +40,24 @@ namespace OpenRA.Widgets
public override bool HandleInput(MouseInput mi)
{
// We get this first if we are focussed; if the click was somewhere else remove focus
if (Chrome.selectedWidget == this && mi.Event == MouseInputEvent.Down && !GetEventBounds().Contains(mi.Location.X,mi.Location.Y))
{
Chrome.selectedWidget = null;
return false;
}
// Are we able to handle this event?
if (!Visible || !GetEventBounds().Contains(mi.Location.X,mi.Location.Y))
return base.HandleInput(mi);
if (base.HandleInput(mi))
return true;
if (mi.Event == MouseInputEvent.Down)
{
Chrome.keyboardFocusWidget = this;
Chrome.selectedWidget = this;
return true;
}
@@ -76,6 +84,19 @@ namespace OpenRA.Widgets
TextBuffer += c;
}
int blinkCycle = 10;
bool showCursor = true;
public override void Tick(World world)
{
if (--blinkCycle <= 0)
{
blinkCycle = 20;
showCursor ^= true;
}
base.Tick(world);
}
public override void DrawInner(World world)
{
var pos = DrawPosition();
@@ -83,7 +104,7 @@ namespace OpenRA.Widgets
WidgetUtils.DrawPanel("dialog3",
new Rectangle(pos.X, pos.Y, Bounds.Width, Bounds.Height ) );
var text = TextBuffer;
var text = TextBuffer + ((showCursor && Chrome.selectedWidget == this) ? "|" : "");
Game.chrome.renderer.BoldFont.DrawText(text,
new int2( pos.X + margin, pos.Y + Bounds.Height / 2)
- new int2(0, Game.chrome.renderer.BoldFont.Measure(text).Y / 2),