diff --git a/OpenRA.Game/Widgets/Widget.cs b/OpenRA.Game/Widgets/Widget.cs index 3f4b7368db..9a0eb09288 100644 --- a/OpenRA.Game/Widgets/Widget.cs +++ b/OpenRA.Game/Widgets/Widget.cs @@ -277,21 +277,18 @@ namespace OpenRA.Widgets public virtual Rectangle EventBounds { get { return RenderBounds; } } - public virtual Rectangle GetEventBounds() + public virtual bool EventBoundsContains(int2 location) { // PERF: Avoid LINQ. - var bounds = EventBounds; - foreach (var child in Children) - { - if (child.IsVisible()) - { - var childBounds = child.GetEventBounds(); - if (childBounds != Rectangle.Empty) - bounds = Rectangle.Union(bounds, childBounds); - } - } + if (EventBounds.Contains(location)) + return true; - return bounds; + foreach (var child in Children) + if (child.IsVisible()) + if (child.EventBoundsContains(location)) + return true; + + return false; } public bool HasMouseFocus { get { return Ui.MouseFocusWidget == this; } } @@ -354,7 +351,7 @@ namespace OpenRA.Widgets public string GetCursorOuter(int2 pos) { // Is the cursor on top of us? - if (!(IsVisible() && GetEventBounds().Contains(pos))) + if (!(IsVisible() && EventBoundsContains(pos))) return null; // Do any of our children specify a cursor? @@ -379,7 +376,7 @@ namespace OpenRA.Widgets public bool HandleMouseInputOuter(MouseInput mi) { // Are we able to handle this event? - if (!(HasMouseFocus || (IsVisible() && GetEventBounds().Contains(mi.Location)))) + if (!(HasMouseFocus || (IsVisible() && EventBoundsContains(mi.Location)))) return false; var oldMouseOver = Ui.MouseOverWidget; diff --git a/OpenRA.Mods.Common/Widgets/ScrollPanelWidget.cs b/OpenRA.Mods.Common/Widgets/ScrollPanelWidget.cs index c5172e70d9..57c6f93aae 100644 --- a/OpenRA.Mods.Common/Widgets/ScrollPanelWidget.cs +++ b/OpenRA.Mods.Common/Widgets/ScrollPanelWidget.cs @@ -238,9 +238,9 @@ namespace OpenRA.Mods.Common.Widgets } } - public override Rectangle GetEventBounds() + public override bool EventBoundsContains(int2 location) { - return EventBounds; + return EventBounds.Contains(location); } void Scroll(int amount, bool smooth = false) diff --git a/OpenRA.Mods.Common/Widgets/TooltipContainerWidget.cs b/OpenRA.Mods.Common/Widgets/TooltipContainerWidget.cs index dc48e2c209..af3572cf4e 100644 --- a/OpenRA.Mods.Common/Widgets/TooltipContainerWidget.cs +++ b/OpenRA.Mods.Common/Widgets/TooltipContainerWidget.cs @@ -62,7 +62,7 @@ namespace OpenRA.Mods.Common.Widgets public override void Draw() { BeforeRender(); } - public override Rectangle GetEventBounds() { return Rectangle.Empty; } + public override bool EventBoundsContains(int2 location) { return false; } public override int2 ChildOrigin {