Refactoring on GetEventBounds in Widget

This commit is contained in:
teinarss
2020-02-15 09:43:08 +01:00
committed by abcdefg30
parent 1a9f707d18
commit 2cf6b74295
3 changed files with 14 additions and 17 deletions

View File

@@ -277,21 +277,18 @@ namespace OpenRA.Widgets
public virtual Rectangle EventBounds { get { return RenderBounds; } } public virtual Rectangle EventBounds { get { return RenderBounds; } }
public virtual Rectangle GetEventBounds() public virtual bool EventBoundsContains(int2 location)
{ {
// PERF: Avoid LINQ. // PERF: Avoid LINQ.
var bounds = EventBounds; if (EventBounds.Contains(location))
foreach (var child in Children) return true;
{
if (child.IsVisible())
{
var childBounds = child.GetEventBounds();
if (childBounds != Rectangle.Empty)
bounds = Rectangle.Union(bounds, childBounds);
}
}
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; } } public bool HasMouseFocus { get { return Ui.MouseFocusWidget == this; } }
@@ -354,7 +351,7 @@ namespace OpenRA.Widgets
public string GetCursorOuter(int2 pos) public string GetCursorOuter(int2 pos)
{ {
// Is the cursor on top of us? // Is the cursor on top of us?
if (!(IsVisible() && GetEventBounds().Contains(pos))) if (!(IsVisible() && EventBoundsContains(pos)))
return null; return null;
// Do any of our children specify a cursor? // Do any of our children specify a cursor?
@@ -379,7 +376,7 @@ namespace OpenRA.Widgets
public bool HandleMouseInputOuter(MouseInput mi) public bool HandleMouseInputOuter(MouseInput mi)
{ {
// Are we able to handle this event? // Are we able to handle this event?
if (!(HasMouseFocus || (IsVisible() && GetEventBounds().Contains(mi.Location)))) if (!(HasMouseFocus || (IsVisible() && EventBoundsContains(mi.Location))))
return false; return false;
var oldMouseOver = Ui.MouseOverWidget; var oldMouseOver = Ui.MouseOverWidget;

View File

@@ -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) void Scroll(int amount, bool smooth = false)

View File

@@ -62,7 +62,7 @@ namespace OpenRA.Mods.Common.Widgets
public override void Draw() { BeforeRender(); } public override void Draw() { BeforeRender(); }
public override Rectangle GetEventBounds() { return Rectangle.Empty; } public override bool EventBoundsContains(int2 location) { return false; }
public override int2 ChildOrigin public override int2 ChildOrigin
{ {