Fix widget mouse focus

This commit is contained in:
Paul Chote
2010-04-11 16:49:06 +12:00
parent f2e95d04de
commit a75d173371
4 changed files with 41 additions and 14 deletions

View File

@@ -1068,7 +1068,7 @@ namespace OpenRA
if (selectedWidget != null) if (selectedWidget != null)
return true; return true;
return rootWidget.GetEventBounds().Contains(mousePos.X, mousePos.Y) return rootWidget.HitTest(mousePos)
|| buttons.Any(a => a.First.Contains(mousePos.ToPoint())); || buttons.Any(a => a.First.Contains(mousePos.ToPoint()));
} }

View File

@@ -36,6 +36,7 @@ namespace OpenRA.Widgets
public readonly string Width = "0"; public readonly string Width = "0";
public readonly string Height = "0"; public readonly string Height = "0";
public readonly string Delegate = null; public readonly string Delegate = null;
public readonly bool ClickThrough = false;
public bool Visible = true; public bool Visible = true;
public readonly List<Widget> Children = new List<Widget>(); public readonly List<Widget> Children = new List<Widget>();
@@ -87,6 +88,14 @@ namespace OpenRA.Widgets
Game.CreateObject<IWidgetDelegate>(d); Game.CreateObject<IWidgetDelegate>(d);
} }
public bool HitTest(int2 xy)
{
if (!IsVisible()) return false;
if (Bounds.Contains(xy.ToPoint()) && !ClickThrough) return true;
return Children.Any(c => c.HitTest(xy));
}
public Rectangle GetEventBounds() public Rectangle GetEventBounds()
{ {
return Children return Children

View File

@@ -1,4 +1,5 @@
Container: Container:
ClickThrough:true
Children: Children:
Background@MAINMENU_BG: Background@MAINMENU_BG:
Id:MAINMENU_BG Id:MAINMENU_BG
@@ -248,19 +249,6 @@ Container:
Delegate:IngameChromeDelegate Delegate:IngameChromeDelegate
Visible:false Visible:false
Children: Children:
PerfGraph@PERFGRAPH:
Id:PERFGRAPH
X:10
Y:WINDOW_BOTTOM - 250
Width:200
Height:200
Label@PERFTEXT:
Id:PERFTEXT
Bold: false
X:10
Y:WINDOW_BOTTOM - 40
Width:200
Height:100
SpecialPowerBin@INGAME_POWERS_BIN: SpecialPowerBin@INGAME_POWERS_BIN:
Id:INGAME_POWERS_BIN Id:INGAME_POWERS_BIN
X:0 X:0
@@ -309,6 +297,32 @@ Container:
Width:160 Width:160
Height:25 Height:25
Text:Quit Text:Quit
Background@PERF_BG:
ClickThrough:true
Id:PERF_BG
Background:dialog4
Delegate:PerfDebugDelegate
X:10
Y:WINDOW_BOTTOM - 250
Width: 210
Height: 250
Visible: true
Children:
PerfGraph@GRAPH:
ClickThrough:true
Id:GRAPH
X:5
Y:5
Width:200
Height:200
Label@TEXT:
ClickThrough:true
Id:TEXT
Bold: false
X:20
Y:210
Width:200
Height:100
Background@MUSIC_BG: Background@MUSIC_BG:
Id:MUSIC_BG Id:MUSIC_BG
Delegate:MusicPlayerDelegate Delegate:MusicPlayerDelegate

View File

@@ -1,4 +1,5 @@
Container: Container:
ClickThrough:true
Children: Children:
Background@MAINMENU_BG: Background@MAINMENU_BG:
Id:MAINMENU_BG Id:MAINMENU_BG
@@ -297,6 +298,7 @@ Container:
Height:25 Height:25
Text:Quit Text:Quit
Background@PERF_BG: Background@PERF_BG:
ClickThrough:true
Id:PERF_BG Id:PERF_BG
Background:dialog4 Background:dialog4
Delegate:PerfDebugDelegate Delegate:PerfDebugDelegate
@@ -307,12 +309,14 @@ Container:
Visible: true Visible: true
Children: Children:
PerfGraph@GRAPH: PerfGraph@GRAPH:
ClickThrough:true
Id:GRAPH Id:GRAPH
X:5 X:5
Y:5 Y:5
Width:200 Width:200
Height:200 Height:200
Label@TEXT: Label@TEXT:
ClickThrough:true
Id:TEXT Id:TEXT
Bold: false Bold: false
X:20 X:20