diff --git a/OpenRA.Game/Chrome.cs b/OpenRA.Game/Chrome.cs index 4480d6a528..4893d162f0 100644 --- a/OpenRA.Game/Chrome.cs +++ b/OpenRA.Game/Chrome.cs @@ -1077,6 +1077,9 @@ namespace OpenRA int2 lastMousePos; public bool HandleInput(World world, MouseInput mi) { + if (rootWidget.HandleInput(mi)) + return true; + if (mi.Event == MouseInputEvent.Move) lastMousePos = mi.Location; diff --git a/OpenRA.Game/Chrome/BackgroundWidget.cs b/OpenRA.Game/Chrome/BackgroundWidget.cs index 26d368d82b..5265ea77db 100644 --- a/OpenRA.Game/Chrome/BackgroundWidget.cs +++ b/OpenRA.Game/Chrome/BackgroundWidget.cs @@ -10,7 +10,7 @@ namespace OpenRA.Widgets { string collection = "dialog"; - Rectangle r = new Rectangle(X,Y,Width,Height); + Rectangle r = Bounds; renderer.Device.EnableScissor(r.Left, r.Top, r.Width, r.Height); string[] images = { "border-t", "border-b", "border-l", "border-r", "corner-tl", "corner-tr", "corner-bl", "corner-br", "background" }; diff --git a/OpenRA.Game/Chrome/ButtonWidget.cs b/OpenRA.Game/Chrome/ButtonWidget.cs index d30251730f..93815077bd 100644 --- a/OpenRA.Game/Chrome/ButtonWidget.cs +++ b/OpenRA.Game/Chrome/ButtonWidget.cs @@ -8,11 +8,23 @@ namespace OpenRA.Widgets { public readonly string Text = null; + public override bool HandleInput(MouseInput mi) + { + // TEMPORARY: Define a default mouse button event - quit the game + if (mi.Event == MouseInputEvent.Down && ClickRect.Contains(mi.Location.X,mi.Location.Y)) + { + Game.Exit(); + return true; + } + + return base.HandleInput(mi); + } + public override void Draw(SpriteRenderer rgbaRenderer, Renderer renderer) { string collection = "dialog2"; - Rectangle r = new Rectangle(X,Y,Width,Height); + Rectangle r = Bounds; renderer.Device.EnableScissor(r.Left, r.Top, r.Width, r.Height); string[] images = { "border-t", "border-b", "border-l", "border-r", "corner-tl", "corner-tr", "corner-bl", "corner-br", "background" }; diff --git a/OpenRA.Game/Chrome/LabelWidget.cs b/OpenRA.Game/Chrome/LabelWidget.cs index d4e28bc02a..9c61b7d5db 100644 --- a/OpenRA.Game/Chrome/LabelWidget.cs +++ b/OpenRA.Game/Chrome/LabelWidget.cs @@ -10,7 +10,7 @@ namespace OpenRA.Widgets public override void Draw(SpriteRenderer rgbaRenderer, Renderer renderer) { - Rectangle r = new Rectangle(X,Y,Width,Height); + Rectangle r = Bounds; renderer.Device.EnableScissor(r.Left, r.Top, r.Width, r.Height); renderer.BoldFont.DrawText(rgbaRenderer, Text, new int2(X+Width/2, Y+Height/2) - new int2(renderer.BoldFont.Measure(Text).X / 2, renderer.BoldFont.Measure(Text).Y/2), Color.White); renderer.Device.DisableScissor(); diff --git a/OpenRA.Game/Chrome/Widget.cs b/OpenRA.Game/Chrome/Widget.cs index ce40690d4e..84d4bc39a3 100644 --- a/OpenRA.Game/Chrome/Widget.cs +++ b/OpenRA.Game/Chrome/Widget.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Drawing; using OpenRA.FileFormats; using OpenRA.Graphics; @@ -12,12 +13,48 @@ namespace OpenRA.Widgets public readonly int Width = 0; public readonly int Height = 0; public readonly List Children = new List(); + public Rectangle Bounds + { + get {return new Rectangle(X,Y,Width, Height);} + } + + public Rectangle ClickRect; + + public virtual void Initialize() + { + // Create the clickrect + ClickRect = Bounds; + foreach (var child in Children) + ClickRect = Rectangle.Union(ClickRect, child.Bounds); + + } public virtual void Draw(SpriteRenderer rgbaRenderer, Renderer renderer) { foreach (var child in Children) child.Draw(rgbaRenderer, renderer); } + + public virtual bool HandleInput(MouseInput mi) + { + bool caught = false; + if (ClickRect.Contains(mi.Location.X,mi.Location.Y)) + { + foreach (var child in Children) + { + caught = child.HandleInput(mi); + if (caught) + break; + } + } + + return caught; + } + + public void AddChild(Widget child) + { + Children.Add( child ); + } } class ContainerWidget : Widget { } } \ No newline at end of file diff --git a/OpenRA.Game/Chrome/WidgetLoader.cs b/OpenRA.Game/Chrome/WidgetLoader.cs index b978dc8c0b..79133c7c21 100644 --- a/OpenRA.Game/Chrome/WidgetLoader.cs +++ b/OpenRA.Game/Chrome/WidgetLoader.cs @@ -36,13 +36,13 @@ namespace OpenRA { // Hack around a bug in MiniYaml c.Value.Value = c.Key; - widget.Children.Add( LoadWidget( c.Value ) ); + widget.AddChild( LoadWidget( c.Value ) ); } } else FieldLoader.LoadField( widget, child.Key, child.Value ); } - + widget.Initialize(); return widget; }