Fix cursor interaction with widgets
This commit is contained in:
@@ -130,15 +130,6 @@ namespace OpenRA.Widgets
|
||||
}
|
||||
|
||||
public virtual Rectangle EventBounds { get { return RenderBounds; } }
|
||||
|
||||
public bool HitTest(int2 xy)
|
||||
{
|
||||
if (!IsVisible()) return false;
|
||||
if (EventBounds.Contains(xy.ToPoint()) && !ClickThrough) return true;
|
||||
|
||||
return Children.Any(c => c.HitTest(xy));
|
||||
}
|
||||
|
||||
public Rectangle GetEventBounds()
|
||||
{
|
||||
return Children
|
||||
@@ -147,7 +138,6 @@ namespace OpenRA.Widgets
|
||||
.Aggregate(EventBounds, Rectangle.Union);
|
||||
}
|
||||
|
||||
|
||||
public static Widget SelectedWidget;
|
||||
public bool Focused { get { return SelectedWidget == this; } }
|
||||
public virtual bool TakeFocus(MouseInput mi)
|
||||
@@ -176,6 +166,24 @@ namespace OpenRA.Widgets
|
||||
return true;
|
||||
}
|
||||
|
||||
public virtual string GetCursor(int2 pos) { return "default"; }
|
||||
public string GetCursorOuter(int2 pos)
|
||||
{
|
||||
// Is the cursor on top of us?
|
||||
if (!(IsVisible() && GetEventBounds().Contains(pos.ToPoint())))
|
||||
return null;
|
||||
|
||||
// Do any of our children specify a cursor?
|
||||
foreach (var child in Children.OfType<Widget>().Reverse())
|
||||
{
|
||||
var cc = child.GetCursorOuter(pos);
|
||||
if (cc != null)
|
||||
return cc;
|
||||
}
|
||||
|
||||
return EventBounds.Contains(pos.ToPoint()) ? GetCursor(pos) : null;
|
||||
}
|
||||
|
||||
public virtual bool HandleInput(MouseInput mi) { return !ClickThrough; }
|
||||
public bool HandleMouseInputOuter(MouseInput mi)
|
||||
{
|
||||
@@ -290,7 +298,8 @@ namespace OpenRA.Widgets
|
||||
public ContainerWidget(Widget other) : base(other) { }
|
||||
|
||||
public override void DrawInner( World world ) { }
|
||||
|
||||
|
||||
public override string GetCursor(int2 pos) { return null; }
|
||||
public override Widget Clone() { return new ContainerWidget(this); }
|
||||
}
|
||||
public interface IWidgetDelegate { }
|
||||
|
||||
Reference in New Issue
Block a user