Fix cursor interaction with widgets
This commit is contained in:
@@ -69,7 +69,6 @@ namespace OpenRA
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public bool HandleKeyPress(KeyInput e)
|
public bool HandleKeyPress(KeyInput e)
|
||||||
{
|
{
|
||||||
if (Widget.SelectedWidget != null)
|
if (Widget.SelectedWidget != null)
|
||||||
@@ -79,13 +78,5 @@ namespace OpenRA
|
|||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool HitTest(int2 mousePos)
|
|
||||||
{
|
|
||||||
if (Widget.SelectedWidget != null)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
return rootWidget.HitTest(mousePos);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ namespace OpenRA.Graphics
|
|||||||
Game.chrome.Draw(world);
|
Game.chrome.Draw(world);
|
||||||
Timer.Time( "widgets: {0}" );
|
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);
|
var c = new Cursor(cursorName);
|
||||||
cursorRenderer.DrawSprite(c.GetSprite((int)cursorFrame), mousePos + Location - c.GetHotspot(), "cursor");
|
cursorRenderer.DrawSprite(c.GetSprite((int)cursorFrame), mousePos + Location - c.GetHotspot(), "cursor");
|
||||||
Timer.Time( "cursors: {0}" );
|
Timer.Time( "cursors: {0}" );
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ namespace OpenRA.Widgets
|
|||||||
protected ChatDisplayWidget(Widget widget)
|
protected ChatDisplayWidget(Widget widget)
|
||||||
: base(widget) { }
|
: base(widget) { }
|
||||||
|
|
||||||
|
public override Rectangle EventBounds { get { return Rectangle.Empty; } }
|
||||||
public override void DrawInner(World world)
|
public override void DrawInner(World world)
|
||||||
{
|
{
|
||||||
var pos = RenderOrigin;
|
var pos = RenderOrigin;
|
||||||
|
|||||||
@@ -37,7 +37,8 @@ namespace OpenRA.Widgets
|
|||||||
Game.chrome.renderer.RgbaSpriteRenderer.Flush();
|
Game.chrome.renderer.RgbaSpriteRenderer.Flush();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override Rectangle EventBounds { get { return Rectangle.Empty; } }
|
||||||
public override bool LoseFocus(MouseInput mi)
|
public override bool LoseFocus(MouseInput mi)
|
||||||
{
|
{
|
||||||
return composing ? false : base.LoseFocus(mi);
|
return composing ? false : base.LoseFocus(mi);
|
||||||
|
|||||||
@@ -130,15 +130,6 @@ namespace OpenRA.Widgets
|
|||||||
}
|
}
|
||||||
|
|
||||||
public virtual Rectangle EventBounds { get { return RenderBounds; } }
|
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()
|
public Rectangle GetEventBounds()
|
||||||
{
|
{
|
||||||
return Children
|
return Children
|
||||||
@@ -147,7 +138,6 @@ namespace OpenRA.Widgets
|
|||||||
.Aggregate(EventBounds, Rectangle.Union);
|
.Aggregate(EventBounds, Rectangle.Union);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static Widget SelectedWidget;
|
public static Widget SelectedWidget;
|
||||||
public bool Focused { get { return SelectedWidget == this; } }
|
public bool Focused { get { return SelectedWidget == this; } }
|
||||||
public virtual bool TakeFocus(MouseInput mi)
|
public virtual bool TakeFocus(MouseInput mi)
|
||||||
@@ -176,6 +166,24 @@ namespace OpenRA.Widgets
|
|||||||
return true;
|
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 virtual bool HandleInput(MouseInput mi) { return !ClickThrough; }
|
||||||
public bool HandleMouseInputOuter(MouseInput mi)
|
public bool HandleMouseInputOuter(MouseInput mi)
|
||||||
{
|
{
|
||||||
@@ -290,7 +298,8 @@ namespace OpenRA.Widgets
|
|||||||
public ContainerWidget(Widget other) : base(other) { }
|
public ContainerWidget(Widget other) : base(other) { }
|
||||||
|
|
||||||
public override void DrawInner( World world ) { }
|
public override void DrawInner( World world ) { }
|
||||||
|
|
||||||
|
public override string GetCursor(int2 pos) { return null; }
|
||||||
public override Widget Clone() { return new ContainerWidget(this); }
|
public override Widget Clone() { return new ContainerWidget(this); }
|
||||||
}
|
}
|
||||||
public interface IWidgetDelegate { }
|
public interface IWidgetDelegate { }
|
||||||
|
|||||||
@@ -11,10 +11,6 @@ Container@ROOT:
|
|||||||
Y: 10
|
Y: 10
|
||||||
PostGame@POSTGAME_TEXT:
|
PostGame@POSTGAME_TEXT:
|
||||||
Id:POSTGAME_TEXT
|
Id:POSTGAME_TEXT
|
||||||
X:0
|
|
||||||
Y:0
|
|
||||||
Width: WINDOW_RIGHT
|
|
||||||
Height: WINDOW_BOTTOM
|
|
||||||
SpecialPowerBin@INGAME_POWERS_BIN:
|
SpecialPowerBin@INGAME_POWERS_BIN:
|
||||||
Id:INGAME_POWERS_BIN
|
Id:INGAME_POWERS_BIN
|
||||||
X:0
|
X:0
|
||||||
|
|||||||
@@ -11,10 +11,6 @@ Container@ROOT:
|
|||||||
Y: 10
|
Y: 10
|
||||||
PostGame@POSTGAME_TEXT:
|
PostGame@POSTGAME_TEXT:
|
||||||
Id:POSTGAME_TEXT
|
Id:POSTGAME_TEXT
|
||||||
X:0
|
|
||||||
Y:0
|
|
||||||
Width: WINDOW_RIGHT
|
|
||||||
Height: WINDOW_BOTTOM
|
|
||||||
SpecialPowerBin@INGAME_POWERS_BIN:
|
SpecialPowerBin@INGAME_POWERS_BIN:
|
||||||
Id:INGAME_POWERS_BIN
|
Id:INGAME_POWERS_BIN
|
||||||
X:0
|
X:0
|
||||||
|
|||||||
Reference in New Issue
Block a user