diff --git a/OpenRA.Game/Chrome.cs b/OpenRA.Game/Chrome.cs index 2370e0dd45..b58202e0bd 100644 --- a/OpenRA.Game/Chrome.cs +++ b/OpenRA.Game/Chrome.cs @@ -69,7 +69,6 @@ namespace OpenRA return false; } - public bool HandleKeyPress(KeyInput e) { if (Widget.SelectedWidget != null) @@ -79,13 +78,5 @@ namespace OpenRA return true; return false; } - - public bool HitTest(int2 mousePos) - { - if (Widget.SelectedWidget != null) - return true; - - return rootWidget.HitTest(mousePos); - } } } diff --git a/OpenRA.Game/Graphics/Viewport.cs b/OpenRA.Game/Graphics/Viewport.cs index 4e4548a330..76b1252efd 100644 --- a/OpenRA.Game/Graphics/Viewport.cs +++ b/OpenRA.Game/Graphics/Viewport.cs @@ -69,7 +69,7 @@ namespace OpenRA.Graphics Game.chrome.Draw(world); Timer.Time( "widgets: {0}" ); - var cursorName = Game.chrome.HitTest(mousePos) ? "default" : Game.controller.ChooseCursor( world ); + var cursorName = Chrome.rootWidget.GetCursorOuter(mousePos) ?? Game.controller.ChooseCursor( world ); var c = new Cursor(cursorName); cursorRenderer.DrawSprite(c.GetSprite((int)cursorFrame), mousePos + Location - c.GetHotspot(), "cursor"); Timer.Time( "cursors: {0}" ); diff --git a/OpenRA.Game/Widgets/ChatDisplayWidget.cs b/OpenRA.Game/Widgets/ChatDisplayWidget.cs index a884ed6d4f..6ba146e070 100644 --- a/OpenRA.Game/Widgets/ChatDisplayWidget.cs +++ b/OpenRA.Game/Widgets/ChatDisplayWidget.cs @@ -28,6 +28,7 @@ namespace OpenRA.Widgets protected ChatDisplayWidget(Widget widget) : base(widget) { } + public override Rectangle EventBounds { get { return Rectangle.Empty; } } public override void DrawInner(World world) { var pos = RenderOrigin; diff --git a/OpenRA.Game/Widgets/ChatEntryWidget.cs b/OpenRA.Game/Widgets/ChatEntryWidget.cs index 2d2e00e175..68924a170b 100644 --- a/OpenRA.Game/Widgets/ChatEntryWidget.cs +++ b/OpenRA.Game/Widgets/ChatEntryWidget.cs @@ -37,7 +37,8 @@ namespace OpenRA.Widgets Game.chrome.renderer.RgbaSpriteRenderer.Flush(); } } - + + public override Rectangle EventBounds { get { return Rectangle.Empty; } } public override bool LoseFocus(MouseInput mi) { return composing ? false : base.LoseFocus(mi); diff --git a/OpenRA.Game/Widgets/Widget.cs b/OpenRA.Game/Widgets/Widget.cs index a61769053b..da544ceff9 100644 --- a/OpenRA.Game/Widgets/Widget.cs +++ b/OpenRA.Game/Widgets/Widget.cs @@ -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().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 { } diff --git a/mods/cnc/chrome/ingame.yaml b/mods/cnc/chrome/ingame.yaml index 32142caa59..39b58c689b 100644 --- a/mods/cnc/chrome/ingame.yaml +++ b/mods/cnc/chrome/ingame.yaml @@ -11,10 +11,6 @@ Container@ROOT: Y: 10 PostGame@POSTGAME_TEXT: Id:POSTGAME_TEXT - X:0 - Y:0 - Width: WINDOW_RIGHT - Height: WINDOW_BOTTOM SpecialPowerBin@INGAME_POWERS_BIN: Id:INGAME_POWERS_BIN X:0 diff --git a/mods/ra/chrome/ingame.yaml b/mods/ra/chrome/ingame.yaml index 652c1b5966..a8146f5d03 100644 --- a/mods/ra/chrome/ingame.yaml +++ b/mods/ra/chrome/ingame.yaml @@ -11,10 +11,6 @@ Container@ROOT: Y: 10 PostGame@POSTGAME_TEXT: Id:POSTGAME_TEXT - X:0 - Y:0 - Width: WINDOW_RIGHT - Height: WINDOW_BOTTOM SpecialPowerBin@INGAME_POWERS_BIN: Id:INGAME_POWERS_BIN X:0