Preparation for using Evaluator for widget positioning

This commit is contained in:
Paul Chote
2010-03-15 18:52:12 +13:00
parent 31198c25e5
commit 9ecb0d57f1
4 changed files with 40 additions and 39 deletions

View File

@@ -15,34 +15,32 @@ namespace OpenRA.Widgets
} }
string collection = "dialog"; string collection = "dialog";
Game.chrome.renderer.Device.EnableScissor(Bounds.Left, Bounds.Top, Bounds.Width, Bounds.Height);
Rectangle r = Bounds;
Game.chrome.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" }; string[] images = { "border-t", "border-b", "border-l", "border-r", "corner-tl", "corner-tr", "corner-bl", "corner-br", "background" };
var ss = Graphics.Util.MakeArray(9, n => ChromeProvider.GetImage(Game.chrome.renderer, collection,images[n])); var ss = Graphics.Util.MakeArray(9, n => ChromeProvider.GetImage(Game.chrome.renderer, collection,images[n]));
for( var x = r.Left + (int)ss[2].size.X; x < r.Right - (int)ss[3].size.X; x += (int)ss[8].size.X ) for( var x = Bounds.Left + (int)ss[2].size.X; x < Bounds.Right - (int)ss[3].size.X; x += (int)ss[8].size.X )
for( var y = r.Top + (int)ss[0].size.Y; y < r.Bottom - (int)ss[1].size.Y; y += (int)ss[8].size.Y ) for( var y = Bounds.Top + (int)ss[0].size.Y; y < Bounds.Bottom - (int)ss[1].size.Y; y += (int)ss[8].size.Y )
Game.chrome.rgbaRenderer.DrawSprite(ss[8], new float2(x, y), "chrome"); Game.chrome.rgbaRenderer.DrawSprite(ss[8], new float2(x, y), "chrome");
//draw borders //draw borders
for (var y = r.Top + (int)ss[0].size.Y; y < r.Bottom - (int)ss[1].size.Y; y += (int)ss[2].size.Y) for (var y = Bounds.Top + (int)ss[0].size.Y; y < Bounds.Bottom - (int)ss[1].size.Y; y += (int)ss[2].size.Y)
{ {
Game.chrome.rgbaRenderer.DrawSprite(ss[2], new float2(r.Left, y), "chrome"); Game.chrome.rgbaRenderer.DrawSprite(ss[2], new float2(Bounds.Left, y), "chrome");
Game.chrome.rgbaRenderer.DrawSprite(ss[3], new float2(r.Right - ss[3].size.X, y), "chrome"); Game.chrome.rgbaRenderer.DrawSprite(ss[3], new float2(Bounds.Right - ss[3].size.X, y), "chrome");
} }
for (var x = r.Left + (int)ss[2].size.X; x < r.Right - (int)ss[3].size.X; x += (int)ss[0].size.X) for (var x = Bounds.Left + (int)ss[2].size.X; x < Bounds.Right - (int)ss[3].size.X; x += (int)ss[0].size.X)
{ {
Game.chrome.rgbaRenderer.DrawSprite(ss[0], new float2(x, r.Top), "chrome"); Game.chrome.rgbaRenderer.DrawSprite(ss[0], new float2(x, Bounds.Top), "chrome");
Game.chrome.rgbaRenderer.DrawSprite(ss[1], new float2(x, r.Bottom - ss[1].size.Y), "chrome"); Game.chrome.rgbaRenderer.DrawSprite(ss[1], new float2(x, Bounds.Bottom - ss[1].size.Y), "chrome");
} }
Game.chrome.rgbaRenderer.DrawSprite(ss[4], new float2(r.Left, r.Top), "chrome"); Game.chrome.rgbaRenderer.DrawSprite(ss[4], new float2(Bounds.Left, Bounds.Top), "chrome");
Game.chrome.rgbaRenderer.DrawSprite(ss[5], new float2(r.Right - ss[5].size.X, r.Top), "chrome"); Game.chrome.rgbaRenderer.DrawSprite(ss[5], new float2(Bounds.Right - ss[5].size.X, Bounds.Top), "chrome");
Game.chrome.rgbaRenderer.DrawSprite(ss[6], new float2(r.Left, r.Bottom - ss[6].size.Y), "chrome"); Game.chrome.rgbaRenderer.DrawSprite(ss[6], new float2(Bounds.Left, Bounds.Bottom - ss[6].size.Y), "chrome");
Game.chrome.rgbaRenderer.DrawSprite(ss[7], new float2(r.Right - ss[7].size.X, r.Bottom - ss[7].size.Y), "chrome"); Game.chrome.rgbaRenderer.DrawSprite(ss[7], new float2(Bounds.Right - ss[7].size.X, Bounds.Bottom - ss[7].size.Y), "chrome");
Game.chrome.rgbaRenderer.Flush(); Game.chrome.rgbaRenderer.Flush();
Game.chrome.renderer.Device.DisableScissor(); Game.chrome.renderer.Device.DisableScissor();

View File

@@ -17,37 +17,35 @@ namespace OpenRA.Widgets
} }
string collection = "dialog2"; string collection = "dialog2";
Game.chrome.renderer.Device.EnableScissor(Bounds.Left, Bounds.Top, Bounds.Width, Bounds.Height);
Rectangle r = Bounds;
Game.chrome.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" }; string[] images = { "border-t", "border-b", "border-l", "border-r", "corner-tl", "corner-tr", "corner-bl", "corner-br", "background" };
var ss = Graphics.Util.MakeArray(9, n => ChromeProvider.GetImage(Game.chrome.renderer, collection,images[n])); var ss = Graphics.Util.MakeArray(9, n => ChromeProvider.GetImage(Game.chrome.renderer, collection,images[n]));
for( var x = r.Left + (int)ss[2].size.X; x < r.Right - (int)ss[3].size.X; x += (int)ss[8].size.X ) for( var x = Bounds.Left + (int)ss[2].size.X; x < Bounds.Right - (int)ss[3].size.X; x += (int)ss[8].size.X )
for( var y = r.Top + (int)ss[0].size.Y; y < r.Bottom - (int)ss[1].size.Y; y += (int)ss[8].size.Y ) for( var y = Bounds.Top + (int)ss[0].size.Y; y < Bounds.Bottom - (int)ss[1].size.Y; y += (int)ss[8].size.Y )
Game.chrome.rgbaRenderer.DrawSprite(ss[8], new float2(x, y), "chrome"); Game.chrome.rgbaRenderer.DrawSprite(ss[8], new float2(x, y), "chrome");
//draw borders //draw borders
for (var y = r.Top + (int)ss[0].size.Y; y < r.Bottom - (int)ss[1].size.Y; y += (int)ss[2].size.Y) for (var y = Bounds.Top + (int)ss[0].size.Y; y < Bounds.Bottom - (int)ss[1].size.Y; y += (int)ss[2].size.Y)
{ {
Game.chrome.rgbaRenderer.DrawSprite(ss[2], new float2(r.Left, y), "chrome"); Game.chrome.rgbaRenderer.DrawSprite(ss[2], new float2(Bounds.Left, y), "chrome");
Game.chrome.rgbaRenderer.DrawSprite(ss[3], new float2(r.Right - ss[3].size.X, y), "chrome"); Game.chrome.rgbaRenderer.DrawSprite(ss[3], new float2(Bounds.Right - ss[3].size.X, y), "chrome");
} }
for (var x = r.Left + (int)ss[2].size.X; x < r.Right - (int)ss[3].size.X; x += (int)ss[0].size.X) for (var x = Bounds.Left + (int)ss[2].size.X; x < Bounds.Right - (int)ss[3].size.X; x += (int)ss[0].size.X)
{ {
Game.chrome.rgbaRenderer.DrawSprite(ss[0], new float2(x, r.Top), "chrome"); Game.chrome.rgbaRenderer.DrawSprite(ss[0], new float2(x, Bounds.Top), "chrome");
Game.chrome.rgbaRenderer.DrawSprite(ss[1], new float2(x, r.Bottom - ss[1].size.Y), "chrome"); Game.chrome.rgbaRenderer.DrawSprite(ss[1], new float2(x, Bounds.Bottom - ss[1].size.Y), "chrome");
} }
Game.chrome.rgbaRenderer.DrawSprite(ss[4], new float2(r.Left, r.Top), "chrome"); Game.chrome.rgbaRenderer.DrawSprite(ss[4], new float2(Bounds.Left, Bounds.Top), "chrome");
Game.chrome.rgbaRenderer.DrawSprite(ss[5], new float2(r.Right - ss[5].size.X, r.Top), "chrome"); Game.chrome.rgbaRenderer.DrawSprite(ss[5], new float2(Bounds.Right - ss[5].size.X, Bounds.Top), "chrome");
Game.chrome.rgbaRenderer.DrawSprite(ss[6], new float2(r.Left, r.Bottom - ss[6].size.Y), "chrome"); Game.chrome.rgbaRenderer.DrawSprite(ss[6], new float2(Bounds.Left, Bounds.Bottom - ss[6].size.Y), "chrome");
Game.chrome.rgbaRenderer.DrawSprite(ss[7], new float2(r.Right - ss[7].size.X, r.Bottom - ss[7].size.Y), "chrome"); Game.chrome.rgbaRenderer.DrawSprite(ss[7], new float2(Bounds.Right - ss[7].size.X, Bounds.Bottom - ss[7].size.Y), "chrome");
Game.chrome.rgbaRenderer.Flush(); Game.chrome.rgbaRenderer.Flush();
Game.chrome.renderer.BoldFont.DrawText(Game.chrome.rgbaRenderer, Text, new int2(X+Width/2, Y+Height/2) - new int2(Game.chrome.renderer.BoldFont.Measure(Text).X / 2, Game.chrome.renderer.BoldFont.Measure(Text).Y/2), Color.White); Game.chrome.renderer.BoldFont.DrawText(Game.chrome.rgbaRenderer, Text, new int2(Bounds.X+Bounds.Width/2, Bounds.Y+Bounds.Height/2) - new int2(Game.chrome.renderer.BoldFont.Measure(Text).X / 2, Game.chrome.renderer.BoldFont.Measure(Text).Y/2), Color.White);
Game.chrome.renderer.Device.DisableScissor(); Game.chrome.renderer.Device.DisableScissor();

View File

@@ -21,10 +21,10 @@ namespace OpenRA.Widgets
Game.chrome.renderer.Device.EnableScissor(r.Left, r.Top, r.Width, r.Height); Game.chrome.renderer.Device.EnableScissor(r.Left, r.Top, r.Width, r.Height);
int2 bounds = Game.chrome.renderer.BoldFont.Measure(Text); int2 bounds = Game.chrome.renderer.BoldFont.Measure(Text);
int2 position = new int2(X,Y); int2 position = new int2(Bounds.X,Bounds.Y);
if (Align == "Center") if (Align == "Center")
position = new int2(X+Width/2, Y+Height/2) - new int2(bounds.X / 2, bounds.Y/2); position = new int2(Bounds.X+Bounds.Width/2, Bounds.Y+Bounds.Height/2) - new int2(bounds.X / 2, bounds.Y/2);
Game.chrome.renderer.BoldFont.DrawText(Game.chrome.rgbaRenderer, Text, position, Color.White); Game.chrome.renderer.BoldFont.DrawText(Game.chrome.rgbaRenderer, Text, position, Color.White);

View File

@@ -5,27 +5,32 @@ using OpenRA.FileFormats;
using OpenRA.Graphics; using OpenRA.Graphics;
using OpenRA.Widgets.Delegates; using OpenRA.Widgets.Delegates;
namespace OpenRA.Widgets namespace OpenRA.Widgets
{ {
public class Widget public class Widget
{ {
// Typically defined in YAML // Info defined in YAML
public readonly string Id = null; public readonly string Id = null;
public readonly int X = 0; public readonly string X = "0";
public readonly int Y = 0; public readonly string Y = "0";
public readonly int Width = 0; public readonly string Width = "0";
public readonly int Height = 0; public readonly string Height = "0";
public readonly string Delegate = null; public readonly string Delegate = null;
public bool Visible = true; public bool Visible = true;
public readonly List<Widget> Children = new List<Widget>(); public readonly List<Widget> Children = new List<Widget>();
// Calculated internally // Calculated internally
public Rectangle Bounds {get {return new Rectangle(X,Y,Width, Height);}} public Rectangle Bounds;
public Rectangle ClickRect; public Rectangle ClickRect;
public virtual void Initialize() public virtual void Initialize()
{ {
// Evaluate the bounds rectangle
Bounds = new Rectangle(int.Parse(X),int.Parse(Y),int.Parse(Width),int.Parse(Height));
// Create the clickrect // Create the clickrect
ClickRect = Bounds; ClickRect = Bounds;
foreach (var child in Children) foreach (var child in Children)