Better mouse input handling

This commit is contained in:
Paul Chote
2010-07-12 19:47:51 +12:00
parent bd096436d9
commit e23ee6d892
9 changed files with 126 additions and 139 deletions

View File

@@ -88,40 +88,27 @@ namespace OpenRA.Widgets
if (DownPressed) ListOffset -= ScrollVelocity;
}
public override bool HandleInput(MouseInput mi)
public override bool LoseFocus (MouseInput mi)
{
if (Chrome.selectedWidget == this)
{
UpPressed = upButtonRect.Contains(mi.Location.X,mi.Location.Y);
DownPressed = downButtonRect.Contains(mi.Location.X,mi.Location.Y);
}
UpPressed = DownPressed = false;
return base.LoseFocus(mi);
}
public override bool HandleInput(MouseInput mi)
{
if (mi.Event == MouseInputEvent.Down && !TakeFocus(mi))
return false;
// Relinquish focus
if (Chrome.selectedWidget == this && mi.Event == MouseInputEvent.Up)
{
Chrome.selectedWidget = null;
UpPressed = DownPressed = false;
}
if (!Focused)
return false;
UpPressed = upButtonRect.Contains(mi.Location.X,mi.Location.Y);
DownPressed = downButtonRect.Contains(mi.Location.X,mi.Location.Y);
// Are we able to handle this event?
if (!Visible || !GetEventBounds().Contains(mi.Location.X,mi.Location.Y))
return base.HandleInput(mi);
if (Focused && mi.Event == MouseInputEvent.Up)
LoseFocus(mi);
if (base.HandleInput(mi))
return true;
// Give button focus only while the mouse is down
// This is a bit of a hack: it will become cleaner soonish
// It will also steal events from any potential children
// We also want to play a click sound
if (mi.Event == MouseInputEvent.Down)
{
Chrome.selectedWidget = this;
return true;
}
return false;
return (UpPressed || DownPressed);
}
public override Widget Clone() { return new ListBoxWidget(this); }