refactored a bit - something is still failing

This commit is contained in:
alzeih
2010-04-24 17:33:43 +12:00
parent 3d1d6f5e00
commit 471a5c29c8
12 changed files with 32 additions and 18 deletions

View File

@@ -31,7 +31,8 @@ namespace OpenRA.Widgets
base.Draw(world);
return;
}
var rect = new Rectangle(Bounds.X + getParentOffset().X, Bounds.Y + getParentOffset().Y, Bounds.Width, Bounds.Height);
var pos = DrawPosition();
var rect = new Rectangle(pos.X, pos.Y, Bounds.Width, Bounds.Height);
WidgetUtils.DrawPanel(Background, rect);
base.Draw(world);
}

View File

@@ -86,13 +86,14 @@ namespace OpenRA.Widgets
base.Draw(world);
return;
}
var pos = DrawPosition();
var stateOffset = (Depressed) ? new int2(VisualHeight, VisualHeight) : new int2(0, 0);
WidgetUtils.DrawPanel(Depressed ? "dialog3" : "dialog2", new Rectangle(Bounds.X + getParentOffset().X, Bounds.Y + getParentOffset().Y, Bounds.Width, Bounds.Height ) );
WidgetUtils.DrawPanel(Depressed ? "dialog3" : "dialog2", new Rectangle(pos.X, pos.Y, Bounds.Width, Bounds.Height ) );
var text = GetText();
Game.chrome.renderer.BoldFont.DrawText(text,
new int2( ( Bounds.X + getParentOffset().X) + Bounds.Width / 2, ( Bounds.Y + getParentOffset().Y) + Bounds.Height / 2)
new int2( pos.X + Bounds.Width / 2, pos.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);

View File

@@ -35,9 +35,10 @@ namespace OpenRA.Widgets
base.Draw(world);
return;
}
var rect = new Rectangle(Bounds.X + getParentOffset().X, Bounds.Y + getParentOffset().Y, Bounds.Width, Bounds.Height);
var pos = DrawPosition();
var rect = new Rectangle(pos.X, pos.Y, Bounds.Width, Bounds.Height);
WidgetUtils.DrawPanel("dialog3", new Rectangle(rect.Location,
new Size(Bounds.Height, Bounds.Height)));
new Size(Bounds.Height, Bounds.Height))); //HACK!
Game.chrome.renderer.BoldFont.DrawText(Text,
new float2(rect.Left + rect.Height * 2, rect.Top), Color.White);

View File

@@ -36,6 +36,7 @@ namespace OpenRA.Widgets.Delegates
Players.Children.Clear();
int i = 0;
foreach(var client in Game.LobbyInfo.Clients)
{
//HACK : "the c# spec is, IMHO, broken here"
@@ -43,9 +44,12 @@ namespace OpenRA.Widgets.Delegates
Log.Write("Client {0}",c.Name);
var template = PlayerTemplate.Clone();
var pos = template.DrawPosition();
template.Id = "PLAYER_{0}".F(c.Index);
template.Parent = Players;
template.GetWidget<ButtonWidget>("NAME").GetText = () => {return c.Name; };
template.Bounds = new Rectangle(template.Bounds.X, template.Bounds.Y + i, template.Bounds.Width, template.Bounds.Height);
template.Bounds = new Rectangle(pos.X, pos.Y + i, template.Bounds.Width, template.Bounds.Height);
template.IsVisible = () => {return true;};
Players.AddChild(template);
i += 30;

View File

@@ -64,7 +64,7 @@ namespace OpenRA.Widgets.Delegates
var g = game;
var b = new ButtonWidget
{
Bounds = new Rectangle(bg.Bounds.X + margin, bg.Bounds.Y + height, bg.Bounds.Width - 2 * margin, 25),
Bounds = new Rectangle(bg.DrawPosition().X + margin, bg.DrawPosition().Y + height, bg.Bounds.Width - 2 * margin, 25),
Id = "JOIN_GAME_{0}".F(i),
Text = "{0} ({1})".F(game.Name, game.Address),
Delegate = "ServerBrowserDelegate",

View File

@@ -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(Parent.Bounds.X + Bounds.X,Parent.Bounds.Y + Bounds.Y);
int2 position = DrawPosition();
if (Align == "Center")
position = new int2(Bounds.X + Parent.Bounds.X +Bounds.Width/2, Bounds.Y + Parent.Bounds.Y + Bounds.Height/2)
position = new int2(position.X +Bounds.Width/2, position.Y + Bounds.Height/2)
- new int2(textSize.X / 2, textSize.Y/2);
font.DrawText(text, position, Color.White);

View File

@@ -25,7 +25,8 @@ namespace OpenRA.Widgets
mapPreviewDirty = true;
lastMap = map;
}
var rect = new Rectangle(Bounds.X + getParentOffset().X, Bounds.Y + getParentOffset().Y, Bounds.Width, Bounds.Height);
var pos = DrawPosition();
var rect = new Rectangle(pos.X, pos.Y, Bounds.Width, Bounds.Height);
var mapRect = map.PreviewBounds( new Rectangle( rect.X, rect.Y, rect.Width, rect.Height ) );
if( mapPreviewDirty )
@@ -43,7 +44,7 @@ namespace OpenRA.Widgets
"chrome",
new float2( mapRect.Size ) );
DrawSpawnPoints( map, Parent.Bounds, world );
DrawSpawnPoints( map, new Rectangle(pos.X, pos.Y, Parent.Bounds.Width, Parent.Bounds.Height ), world );
base.Draw( world );
}

View File

@@ -1,4 +1,4 @@
#region Copyright & License Information
#region Copyright & License Information
/*
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
* This file is part of OpenRA.

View File

@@ -33,7 +33,8 @@ namespace OpenRA.Widgets
base.Draw(world);
return;
}
var rect = new Rectangle(Bounds.X + getParentOffset().X, Bounds.Y + getParentOffset().Y, Bounds.Width, Bounds.Height);
var pos = DrawPosition();
var rect = new Rectangle(pos.X, pos.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);

View File

@@ -85,7 +85,8 @@ namespace OpenRA.Widgets
var powers = world.LocalPlayer.PlayerActor.traits.WithInterface<SupportPower>();
var numPowers = powers.Count(p => p.IsAvailable);
if (numPowers == 0) return;
var rectBounds = new Rectangle(Bounds.X + getParentOffset().X, Bounds.Y + getParentOffset().Y, Bounds.Width, Bounds.Height);
var position = DrawPosition();
var rectBounds = new Rectangle(position.X, position.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(rectBounds.X, rectBounds.Y + i * 51));

View File

@@ -83,9 +83,9 @@ namespace OpenRA.Widgets
return new Widget(this);
}
public int2 getParentOffset()
public int2 DrawPosition()
{
return (Parent == null) ? int2.Zero : new int2(Parent.Bounds.Location.X, Parent.Bounds.Location.Y) ;
return new int2(Bounds.X, Bounds.Y) + ((Parent == null) ? int2.Zero : Parent.DrawPosition());
}
public virtual void Initialize()
@@ -127,7 +127,8 @@ namespace OpenRA.Widgets
public bool HitTest(int2 xy)
{
if (!IsVisible()) return false;
var rect = new Rectangle(Bounds.X + getParentOffset().X, Bounds.Y + getParentOffset().Y, Bounds.Width, Bounds.Height);
var pos = DrawPosition();
var rect = new Rectangle(pos.X, pos.Y, Bounds.Width, Bounds.Height);
if (rect.Contains(xy.ToPoint()) && !ClickThrough) return true;
return Children.Any(c => c.HitTest(xy));
@@ -135,7 +136,8 @@ namespace OpenRA.Widgets
public Rectangle GetEventBounds()
{
var rect = new Rectangle(Bounds.X + getParentOffset().X, Bounds.Y + getParentOffset().Y, Bounds.Width, Bounds.Height);
var pos = DrawPosition();
var rect = new Rectangle(pos.X, pos.Y, Bounds.Width, Bounds.Height);
return Children
.Where(c => c.Visible)
.Select(c => c.GetEventBounds())

View File

@@ -295,6 +295,8 @@ Container:
Children:
Container@TEMPLATE
Id:TEMPLATE
X:0
Y:0
Visible:false
Children:
Button@NAME