From a75d173371c15766ab325840b36a5f0a79574803 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sun, 11 Apr 2010 16:49:06 +1200 Subject: [PATCH] Fix widget mouse focus --- OpenRA.Game/Chrome.cs | 2 +- OpenRA.Game/Widgets/Widget.cs | 9 ++++++++ mods/cnc/menus.yaml | 40 +++++++++++++++++++++++------------ mods/ra/menus.yaml | 4 ++++ 4 files changed, 41 insertions(+), 14 deletions(-) diff --git a/OpenRA.Game/Chrome.cs b/OpenRA.Game/Chrome.cs index 96e7f31920..b698f3a3e4 100644 --- a/OpenRA.Game/Chrome.cs +++ b/OpenRA.Game/Chrome.cs @@ -1068,7 +1068,7 @@ namespace OpenRA if (selectedWidget != null) return true; - return rootWidget.GetEventBounds().Contains(mousePos.X, mousePos.Y) + return rootWidget.HitTest(mousePos) || buttons.Any(a => a.First.Contains(mousePos.ToPoint())); } diff --git a/OpenRA.Game/Widgets/Widget.cs b/OpenRA.Game/Widgets/Widget.cs index 29156d22ea..53d9a8d0cb 100644 --- a/OpenRA.Game/Widgets/Widget.cs +++ b/OpenRA.Game/Widgets/Widget.cs @@ -36,6 +36,7 @@ namespace OpenRA.Widgets public readonly string Width = "0"; public readonly string Height = "0"; public readonly string Delegate = null; + public readonly bool ClickThrough = false; public bool Visible = true; public readonly List Children = new List(); @@ -87,6 +88,14 @@ namespace OpenRA.Widgets Game.CreateObject(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() { return Children diff --git a/mods/cnc/menus.yaml b/mods/cnc/menus.yaml index 3ea5c00c80..b007e61dfe 100644 --- a/mods/cnc/menus.yaml +++ b/mods/cnc/menus.yaml @@ -1,4 +1,5 @@ Container: + ClickThrough:true Children: Background@MAINMENU_BG: Id:MAINMENU_BG @@ -248,19 +249,6 @@ Container: Delegate:IngameChromeDelegate Visible:false 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: Id:INGAME_POWERS_BIN X:0 @@ -309,6 +297,32 @@ Container: Width:160 Height:25 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: Id:MUSIC_BG Delegate:MusicPlayerDelegate diff --git a/mods/ra/menus.yaml b/mods/ra/menus.yaml index 8b63724634..b007e61dfe 100644 --- a/mods/ra/menus.yaml +++ b/mods/ra/menus.yaml @@ -1,4 +1,5 @@ Container: + ClickThrough:true Children: Background@MAINMENU_BG: Id:MAINMENU_BG @@ -297,6 +298,7 @@ Container: Height:25 Text:Quit Background@PERF_BG: + ClickThrough:true Id:PERF_BG Background:dialog4 Delegate:PerfDebugDelegate @@ -307,12 +309,14 @@ Container: 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