Refactoring on GetEventBounds in Widget
This commit is contained in:
@@ -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;
|
||||||
|
|||||||
@@ -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)
|
||||||
|
|||||||
@@ -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
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user