diff --git a/OpenRA.Game/Widgets/BackgroundWidget.cs b/OpenRA.Game/Widgets/BackgroundWidget.cs index 7f8e8674c7..160905fafc 100644 --- a/OpenRA.Game/Widgets/BackgroundWidget.cs +++ b/OpenRA.Game/Widgets/BackgroundWidget.cs @@ -1,3 +1,4 @@ +using System.Drawing; #region Copyright & License Information /* * Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford. @@ -30,8 +31,8 @@ namespace OpenRA.Widgets base.Draw(world); return; } - - WidgetUtils.DrawPanel(Background, Bounds); + var rect = new Rectangle(Bounds.X + getParentOffset().X, Bounds.Y + getParentOffset().Y, Bounds.Width, Bounds.Height); + WidgetUtils.DrawPanel(Background, rect); base.Draw(world); } } diff --git a/OpenRA.Game/Widgets/ButtonWidget.cs b/OpenRA.Game/Widgets/ButtonWidget.cs index 41494c38bb..ae6b3e4e92 100644 --- a/OpenRA.Game/Widgets/ButtonWidget.cs +++ b/OpenRA.Game/Widgets/ButtonWidget.cs @@ -88,10 +88,11 @@ namespace OpenRA.Widgets } var stateOffset = (Depressed) ? new int2(VisualHeight, VisualHeight) : new int2(0, 0); - WidgetUtils.DrawPanel(Depressed ? "dialog3" : "dialog2", Bounds); + WidgetUtils.DrawPanel(Depressed ? "dialog3" : "dialog2", new Rectangle(Bounds.X + getParentOffset().X, Bounds.Y + getParentOffset().Y, Bounds.Width, Bounds.Height ) ); + var text = GetText(); Game.chrome.renderer.BoldFont.DrawText(text, - new int2(Bounds.X + Bounds.Width / 2, Bounds.Y + Bounds.Height / 2) + new int2( ( Bounds.X + getParentOffset().X) + Bounds.Width / 2, ( Bounds.Y + getParentOffset().Y) + Bounds.Height / 2) - new int2(Game.chrome.renderer.BoldFont.Measure(text).X / 2, Game.chrome.renderer.BoldFont.Measure(text).Y / 2) + stateOffset, Color.White); diff --git a/OpenRA.Game/Widgets/CheckboxWidget.cs b/OpenRA.Game/Widgets/CheckboxWidget.cs index 3415afc2ee..fb02dcf8da 100644 --- a/OpenRA.Game/Widgets/CheckboxWidget.cs +++ b/OpenRA.Game/Widgets/CheckboxWidget.cs @@ -35,12 +35,12 @@ namespace OpenRA.Widgets base.Draw(world); return; } - - WidgetUtils.DrawPanel("dialog3", new Rectangle(Bounds.Location, + var rect = new Rectangle(Bounds.X + getParentOffset().X, Bounds.Y + getParentOffset().Y, Bounds.Width, Bounds.Height); + WidgetUtils.DrawPanel("dialog3", new Rectangle(rect.Location, new Size(Bounds.Height, Bounds.Height))); Game.chrome.renderer.BoldFont.DrawText(Text, - new float2(Bounds.Left + Bounds.Height * 2, Bounds.Top), Color.White); + new float2(rect.Left + rect.Height * 2, rect.Top), Color.White); if (Checked()) { @@ -48,10 +48,10 @@ namespace OpenRA.Widgets Game.chrome.lineRenderer.FillRect( new RectangleF( - Game.viewport.Location.X + Bounds.Left + 4, - Game.viewport.Location.Y + Bounds.Top + 5, - Bounds.Height - 9, - Bounds.Height - 9), + Game.viewport.Location.X + rect.Left + 4, + Game.viewport.Location.Y + rect.Top + 5, + rect.Height - 9, + rect.Height - 9), Color.White); Game.chrome.lineRenderer.Flush(); } diff --git a/OpenRA.Game/Widgets/Delegates/LobbyDelegate.cs b/OpenRA.Game/Widgets/Delegates/LobbyDelegate.cs index 3b12138be5..e339ccd086 100644 --- a/OpenRA.Game/Widgets/Delegates/LobbyDelegate.cs +++ b/OpenRA.Game/Widgets/Delegates/LobbyDelegate.cs @@ -38,10 +38,13 @@ namespace OpenRA.Widgets.Delegates int i = 0; foreach(var client in Game.LobbyInfo.Clients) { - Log.Write("Client {0}",client.Name); + //HACK : "the c# spec is, IMHO, broken here" + var c = client; + + Log.Write("Client {0}",c.Name); var template = PlayerTemplate.Clone(); - template.Id = "PLAYER_{0}".F(client.Index); - template.GetWidget("NAME").GetText = () => {return client.Name; }; + template.Id = "PLAYER_{0}".F(c.Index); + template.GetWidget("NAME").GetText = () => {return c.Name; }; template.Bounds = new Rectangle(template.Bounds.X, template.Bounds.Y + i, template.Bounds.Width, template.Bounds.Height); template.IsVisible = () => {return true;}; Players.AddChild(template); diff --git a/OpenRA.Game/Widgets/LabelWidget.cs b/OpenRA.Game/Widgets/LabelWidget.cs index de29d1f413..43ac9ebcbb 100644 --- a/OpenRA.Game/Widgets/LabelWidget.cs +++ b/OpenRA.Game/Widgets/LabelWidget.cs @@ -47,10 +47,10 @@ namespace OpenRA.Widgets var font = (Bold) ? Game.chrome.renderer.BoldFont : Game.chrome.renderer.RegularFont; var text = GetText(); int2 textSize = font.Measure(text); - int2 position = new int2(Bounds.X,Bounds.Y); + int2 position = new int2(Parent.Bounds.X + Bounds.X,Parent.Bounds.Y + Bounds.Y); if (Align == "Center") - position = new int2(Bounds.X+Bounds.Width/2, Bounds.Y+Bounds.Height/2) + position = new int2(Bounds.X + Parent.Bounds.X +Bounds.Width/2, Bounds.Y + Parent.Bounds.Y + Bounds.Height/2) - new int2(textSize.X / 2, textSize.Y/2); font.DrawText(text, position, Color.White); diff --git a/OpenRA.Game/Widgets/MapPreviewWidget.cs b/OpenRA.Game/Widgets/MapPreviewWidget.cs index 0343340831..e213e4a06b 100755 --- a/OpenRA.Game/Widgets/MapPreviewWidget.cs +++ b/OpenRA.Game/Widgets/MapPreviewWidget.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -25,8 +25,8 @@ namespace OpenRA.Widgets mapPreviewDirty = true; lastMap = map; } - - var mapRect = map.PreviewBounds( new Rectangle( Bounds.X, Bounds.Y, Bounds.Width, Bounds.Height ) ); + var rect = new Rectangle(Bounds.X + getParentOffset().X, Bounds.Y + getParentOffset().Y, Bounds.Width, Bounds.Height); + var mapRect = map.PreviewBounds( new Rectangle( rect.X, rect.Y, rect.Width, rect.Height ) ); if( mapPreviewDirty ) { diff --git a/OpenRA.Game/Widgets/PerfGraphWidget.cs b/OpenRA.Game/Widgets/PerfGraphWidget.cs index b890892fdb..65e446c1ce 100644 --- a/OpenRA.Game/Widgets/PerfGraphWidget.cs +++ b/OpenRA.Game/Widgets/PerfGraphWidget.cs @@ -33,9 +33,9 @@ namespace OpenRA.Widgets base.Draw(world); return; } - - float2 origin = Game.viewport.Location + new float2(Bounds.Right,Bounds.Bottom); - float2 basis = new float2(-Bounds.Width/100,-Bounds.Height/100); + var rect = new Rectangle(Bounds.X + getParentOffset().X, Bounds.Y + getParentOffset().Y, Bounds.Width, Bounds.Height); + float2 origin = Game.viewport.Location + new float2(rect.Right,rect.Bottom); + float2 basis = new float2(-rect.Width/100,-rect.Height/100); Game.chrome.lineRenderer.DrawLine(origin, origin + new float2(100, 0) * basis, Color.White, Color.White); Game.chrome.lineRenderer.DrawLine(origin + new float2(100,0) * basis, origin + new float2(100,100) * basis, Color.White, Color.White); diff --git a/OpenRA.Game/Widgets/SpecialPowerBinWidget.cs b/OpenRA.Game/Widgets/SpecialPowerBinWidget.cs index 8a071b277a..1e743b166a 100644 --- a/OpenRA.Game/Widgets/SpecialPowerBinWidget.cs +++ b/OpenRA.Game/Widgets/SpecialPowerBinWidget.cs @@ -85,26 +85,26 @@ namespace OpenRA.Widgets var powers = world.LocalPlayer.PlayerActor.traits.WithInterface(); var numPowers = powers.Count(p => p.IsAvailable); if (numPowers == 0) return; - - WidgetUtils.DrawRGBA(WidgetUtils.GetChromeImage(world, "specialbin-top"),new float2(Bounds.X,Bounds.Y)); + var rectBounds = new Rectangle(Bounds.X + getParentOffset().X, Bounds.Y + getParentOffset().Y, Bounds.Width, Bounds.Height); + WidgetUtils.DrawRGBA(WidgetUtils.GetChromeImage(world, "specialbin-top"),new float2(rectBounds.X,rectBounds.Y)); for (var i = 1; i < numPowers; i++) - WidgetUtils.DrawRGBA(WidgetUtils.GetChromeImage(world,"specialbin-middle"), new float2(Bounds.X, Bounds.Y + i * 51)); - WidgetUtils.DrawRGBA(WidgetUtils.GetChromeImage(world,"specialbin-bottom"), new float2(Bounds.X, Bounds.Y + numPowers * 51)); + WidgetUtils.DrawRGBA(WidgetUtils.GetChromeImage(world,"specialbin-middle"), new float2(rectBounds.X, rectBounds.Y + i * 51)); + WidgetUtils.DrawRGBA(WidgetUtils.GetChromeImage(world,"specialbin-bottom"), new float2(rectBounds.X, rectBounds.Y + numPowers * 51)); Game.chrome.renderer.RgbaSpriteRenderer.Flush(); // Hack Hack Hack - Bounds.Width = 69; - Bounds.Height = 10 + numPowers * 51 + 21; + rectBounds.Width = 69; + rectBounds.Height = 10 + numPowers * 51 + 21; - var y = Bounds.Y + 10; + var y = rectBounds.Y + 10; foreach (var sp in powers) { var image = spsprites[sp.Info.Image]; if (sp.IsAvailable) { - var drawPos = new float2(Bounds.X + 5, y); - var rect = new Rectangle(Bounds.X + 5, y, 64, 48); + var drawPos = new float2(rectBounds.X + 5, y); + var rect = new Rectangle(rectBounds.X + 5, y, 64, 48); if (rect.Contains(Game.chrome.lastMousePos.ToPoint())) { diff --git a/OpenRA.Game/Widgets/Widget.cs b/OpenRA.Game/Widgets/Widget.cs index 0bab1d9609..9680fc6a56 100644 --- a/OpenRA.Game/Widgets/Widget.cs +++ b/OpenRA.Game/Widgets/Widget.cs @@ -83,6 +83,11 @@ namespace OpenRA.Widgets return new Widget(this); } + public int2 getParentOffset() + { + return (Parent == null) ? int2.Zero : new int2(Parent.Bounds.Location.X, Parent.Bounds.Location.Y) ; + } + public virtual void Initialize() { // Parse the YAML equations to find the widget bounds @@ -99,8 +104,8 @@ namespace OpenRA.Widgets substitutions.Add("WIDTH", width); substitutions.Add("HEIGHT", height); - Bounds = new Rectangle(parentBounds.X + Evaluator.Evaluate(X, substitutions), - parentBounds.Y + Evaluator.Evaluate(Y, substitutions), + Bounds = new Rectangle(Evaluator.Evaluate(X, substitutions), + Evaluator.Evaluate(Y, substitutions), width, height); @@ -122,17 +127,19 @@ namespace OpenRA.Widgets public bool HitTest(int2 xy) { if (!IsVisible()) return false; - if (Bounds.Contains(xy.ToPoint()) && !ClickThrough) return true; + var rect = new Rectangle(Bounds.X + getParentOffset().X, Bounds.Y + getParentOffset().Y, Bounds.Width, Bounds.Height); + if (rect.Contains(xy.ToPoint()) && !ClickThrough) return true; return Children.Any(c => c.HitTest(xy)); } public Rectangle GetEventBounds() { + var rect = new Rectangle(Bounds.X + getParentOffset().X, Bounds.Y + getParentOffset().Y, Bounds.Width, Bounds.Height); return Children .Where(c => c.Visible) .Select(c => c.GetEventBounds()) - .Aggregate(Bounds, Rectangle.Union); + .Aggregate(rect, Rectangle.Union); } public virtual bool HandleInput(MouseInput mi)