Preparation for using Evaluator for widget positioning
This commit is contained in:
@@ -15,34 +15,32 @@ namespace OpenRA.Widgets
|
||||
}
|
||||
|
||||
string collection = "dialog";
|
||||
|
||||
Rectangle r = Bounds;
|
||||
Game.chrome.renderer.Device.EnableScissor(r.Left, r.Top, r.Width, r.Height);
|
||||
Game.chrome.renderer.Device.EnableScissor(Bounds.Left, Bounds.Top, Bounds.Width, Bounds.Height);
|
||||
|
||||
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]));
|
||||
|
||||
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 y = r.Top + (int)ss[0].size.Y; y < r.Bottom - (int)ss[1].size.Y; y += (int)ss[8].size.Y )
|
||||
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 = 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");
|
||||
|
||||
//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[3], new float2(r.Right - ss[3].size.X, y), "chrome");
|
||||
Game.chrome.rgbaRenderer.DrawSprite(ss[2], new float2(Bounds.Left, 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[1], new float2(x, r.Bottom - ss[1].size.Y), "chrome");
|
||||
Game.chrome.rgbaRenderer.DrawSprite(ss[0], new float2(x, Bounds.Top), "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[5], new float2(r.Right - ss[5].size.X, r.Top), "chrome");
|
||||
Game.chrome.rgbaRenderer.DrawSprite(ss[6], new float2(r.Left, r.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[4], new float2(Bounds.Left, Bounds.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(Bounds.Left, Bounds.Bottom - ss[6].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.renderer.Device.DisableScissor();
|
||||
|
||||
@@ -17,37 +17,35 @@ namespace OpenRA.Widgets
|
||||
}
|
||||
|
||||
string collection = "dialog2";
|
||||
|
||||
Rectangle r = Bounds;
|
||||
Game.chrome.renderer.Device.EnableScissor(r.Left, r.Top, r.Width, r.Height);
|
||||
Game.chrome.renderer.Device.EnableScissor(Bounds.Left, Bounds.Top, Bounds.Width, Bounds.Height);
|
||||
|
||||
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]));
|
||||
|
||||
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 y = r.Top + (int)ss[0].size.Y; y < r.Bottom - (int)ss[1].size.Y; y += (int)ss[8].size.Y )
|
||||
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 = 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");
|
||||
|
||||
//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[3], new float2(r.Right - ss[3].size.X, y), "chrome");
|
||||
Game.chrome.rgbaRenderer.DrawSprite(ss[2], new float2(Bounds.Left, 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[1], new float2(x, r.Bottom - ss[1].size.Y), "chrome");
|
||||
Game.chrome.rgbaRenderer.DrawSprite(ss[0], new float2(x, Bounds.Top), "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[5], new float2(r.Right - ss[5].size.X, r.Top), "chrome");
|
||||
Game.chrome.rgbaRenderer.DrawSprite(ss[6], new float2(r.Left, r.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[4], new float2(Bounds.Left, Bounds.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(Bounds.Left, Bounds.Bottom - ss[6].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.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();
|
||||
|
||||
|
||||
@@ -21,10 +21,10 @@ namespace OpenRA.Widgets
|
||||
Game.chrome.renderer.Device.EnableScissor(r.Left, r.Top, r.Width, r.Height);
|
||||
|
||||
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")
|
||||
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);
|
||||
|
||||
@@ -5,27 +5,32 @@ using OpenRA.FileFormats;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Widgets.Delegates;
|
||||
|
||||
|
||||
namespace OpenRA.Widgets
|
||||
{
|
||||
public class Widget
|
||||
{
|
||||
// Typically defined in YAML
|
||||
// Info defined in YAML
|
||||
public readonly string Id = null;
|
||||
public readonly int X = 0;
|
||||
public readonly int Y = 0;
|
||||
public readonly int Width = 0;
|
||||
public readonly int Height = 0;
|
||||
public readonly string X = "0";
|
||||
public readonly string Y = "0";
|
||||
public readonly string Width = "0";
|
||||
public readonly string Height = "0";
|
||||
public readonly string Delegate = null;
|
||||
|
||||
public bool Visible = true;
|
||||
public readonly List<Widget> Children = new List<Widget>();
|
||||
|
||||
// Calculated internally
|
||||
public Rectangle Bounds {get {return new Rectangle(X,Y,Width, Height);}}
|
||||
public Rectangle Bounds;
|
||||
public Rectangle ClickRect;
|
||||
|
||||
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
|
||||
ClickRect = Bounds;
|
||||
foreach (var child in Children)
|
||||
|
||||
Reference in New Issue
Block a user