Widget refactoring to support listboxes
This commit is contained in:
@@ -27,9 +27,7 @@ namespace OpenRA.Widgets
|
||||
|
||||
public override void DrawInner(World world)
|
||||
{
|
||||
var pos = DrawPosition();
|
||||
var rect = new Rectangle(pos.X, pos.Y, Bounds.Width, Bounds.Height);
|
||||
WidgetUtils.DrawPanel(Background, rect);
|
||||
WidgetUtils.DrawPanel(Background, RenderBounds);
|
||||
}
|
||||
|
||||
public BackgroundWidget() : base() { }
|
||||
|
||||
@@ -82,15 +82,13 @@ namespace OpenRA.Widgets
|
||||
|
||||
public override void DrawInner(World world)
|
||||
{
|
||||
var pos = DrawPosition();
|
||||
var font = (Bold) ? Game.chrome.renderer.BoldFont : Game.chrome.renderer.RegularFont;
|
||||
var stateOffset = (Depressed) ? new int2(VisualHeight, VisualHeight) : new int2(0, 0);
|
||||
WidgetUtils.DrawPanel(Depressed ? "dialog3" : "dialog2",
|
||||
new Rectangle(pos.X, pos.Y, Bounds.Width, Bounds.Height ) );
|
||||
WidgetUtils.DrawPanel(Depressed ? "dialog3" : "dialog2", RenderBounds );
|
||||
|
||||
var text = GetText();
|
||||
font.DrawText(text,
|
||||
new int2( pos.X + Bounds.Width / 2, pos.Y + Bounds.Height / 2)
|
||||
new int2( RenderOrigin.X + Bounds.Width / 2, RenderOrigin.Y + Bounds.Height / 2)
|
||||
- new int2(font.Measure(text).X / 2,
|
||||
font.Measure(text).Y / 2) + stateOffset, Color.White);
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ namespace OpenRA.Widgets
|
||||
|
||||
public override void DrawInner(World world)
|
||||
{
|
||||
var pos = DrawPosition();
|
||||
var pos = RenderOrigin;
|
||||
var chatLogArea = new Rectangle(pos.X, pos.Y, Bounds.Width, Bounds.Height);
|
||||
var chatpos = new int2(chatLogArea.X + 10, chatLogArea.Bottom - 6);
|
||||
WidgetUtils.DrawPanel("dialog3", chatLogArea);
|
||||
|
||||
@@ -33,8 +33,8 @@ namespace OpenRA.Widgets
|
||||
public override void DrawInner(World world)
|
||||
{
|
||||
var font = (Bold) ? Game.chrome.renderer.BoldFont : Game.chrome.renderer.RegularFont;
|
||||
var pos = DrawPosition();
|
||||
var rect = new Rectangle(pos.X, pos.Y, Bounds.Width, Bounds.Height);
|
||||
var pos = RenderOrigin;
|
||||
var rect = RenderBounds;
|
||||
WidgetUtils.DrawPanel("dialog3", new Rectangle(rect.Location,
|
||||
new Size(Bounds.Height, Bounds.Height)));
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ namespace OpenRA.Widgets
|
||||
|
||||
public override void DrawInner(World world)
|
||||
{
|
||||
var pos = DrawPosition();
|
||||
var pos = RenderOrigin;
|
||||
var paletteRect = new RectangleF(pos.X + Game.viewport.Location.X, pos.Y + Game.viewport.Location.Y, Bounds.Width, Bounds.Height);
|
||||
Game.chrome.lineRenderer.FillRect(paletteRect, GetColor());
|
||||
}
|
||||
|
||||
@@ -36,8 +36,7 @@ namespace OpenRA.Widgets
|
||||
{
|
||||
var name = GetImageName();
|
||||
var collection = GetImageCollection();
|
||||
var position = DrawPosition();
|
||||
WidgetUtils.DrawRGBA(ChromeProvider.GetImage(Game.chrome.renderer, collection, name), position);
|
||||
WidgetUtils.DrawRGBA(ChromeProvider.GetImage(Game.chrome.renderer, collection, name), RenderOrigin);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ namespace OpenRA.Widgets
|
||||
return;
|
||||
|
||||
int2 textSize = font.Measure(text);
|
||||
int2 position = DrawPosition() + new int2(0, (Bounds.Height - textSize.Y)/2);
|
||||
int2 position = RenderOrigin + new int2(0, (Bounds.Height - textSize.Y)/2);
|
||||
|
||||
if (Align == TextAlign.Center)
|
||||
position += new int2((Bounds.Width - textSize.X)/2, 0);
|
||||
|
||||
@@ -38,7 +38,7 @@ namespace OpenRA.Widgets
|
||||
|
||||
if (mi.Event == MouseInputEvent.Down && mi.Button == MouseButton.Left)
|
||||
{
|
||||
var container = new Rectangle(DrawPosition().X, DrawPosition().Y, Parent.Bounds.Width, Parent.Bounds.Height);
|
||||
var container = new Rectangle(RenderOrigin.X, RenderOrigin.Y, Parent.Bounds.Width, Parent.Bounds.Height);
|
||||
|
||||
var p = map.Waypoints
|
||||
.Select((sp, i) => Pair.New(map.ConvertToPreview(sp.Value, container), i))
|
||||
@@ -64,9 +64,7 @@ namespace OpenRA.Widgets
|
||||
lastMap = map;
|
||||
}
|
||||
|
||||
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 ) );
|
||||
var mapRect = map.PreviewBounds( RenderBounds );
|
||||
|
||||
if( mapPreviewDirty )
|
||||
{
|
||||
@@ -83,7 +81,7 @@ namespace OpenRA.Widgets
|
||||
"chrome",
|
||||
new float2( mapRect.Size ) );
|
||||
|
||||
DrawSpawnPoints( map, new Rectangle(pos.X, pos.Y, Parent.Bounds.Width, Parent.Bounds.Height ), world );
|
||||
DrawSpawnPoints( map, new Rectangle(RenderOrigin.X, RenderOrigin.Y, Parent.Bounds.Width, Parent.Bounds.Height ), world );
|
||||
}
|
||||
|
||||
void DrawSpawnPoints(MapStub map, Rectangle container, World world)
|
||||
|
||||
@@ -34,8 +34,7 @@ namespace OpenRA.Widgets
|
||||
|
||||
public override void DrawInner(World world)
|
||||
{
|
||||
var pos = DrawPosition();
|
||||
var rect = new Rectangle(pos.X, pos.Y, Bounds.Width, Bounds.Height);
|
||||
var rect = RenderBounds;
|
||||
float2 origin = Game.viewport.Location + new float2(rect.Right,rect.Bottom);
|
||||
float2 basis = new float2(-rect.Width/100,-rect.Height/100);
|
||||
|
||||
|
||||
@@ -87,8 +87,8 @@ namespace OpenRA.Widgets
|
||||
var powers = world.LocalPlayer.PlayerActor.traits.WithInterface<SupportPower>();
|
||||
var numPowers = powers.Count(p => p.IsAvailable);
|
||||
if (numPowers == 0) return;
|
||||
var position = DrawPosition();
|
||||
var rectBounds = new Rectangle(position.X, position.Y, Bounds.Width, Bounds.Height);
|
||||
var position = RenderOrigin;
|
||||
var rectBounds = RenderBounds;
|
||||
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));
|
||||
|
||||
@@ -133,7 +133,7 @@ namespace OpenRA.Widgets
|
||||
var font = (Bold) ? Game.chrome.renderer.BoldFont : Game.chrome.renderer.RegularFont;
|
||||
var cursor = (showCursor && Chrome.selectedWidget == this) ? "|" : "";
|
||||
var textSize = font.Measure(Text + "|");
|
||||
var pos = DrawPosition();
|
||||
var pos = RenderOrigin;
|
||||
|
||||
WidgetUtils.DrawPanel("dialog3",
|
||||
new Rectangle(pos.X, pos.Y, Bounds.Width, Bounds.Height ) );
|
||||
|
||||
@@ -85,16 +85,15 @@ namespace OpenRA.Widgets
|
||||
|
||||
public abstract Widget Clone();
|
||||
|
||||
public int2 DrawPosition()
|
||||
public virtual int2 RenderOrigin
|
||||
{
|
||||
return new int2(Bounds.X, Bounds.Y) + ParentPosition();
|
||||
get {
|
||||
var offset = (Parent == null) ? int2.Zero : Parent.ChildOrigin;
|
||||
return new int2(Bounds.X, Bounds.Y) + offset;
|
||||
}
|
||||
}
|
||||
|
||||
public int2 ParentPosition()
|
||||
{
|
||||
return (Parent == null) ? int2.Zero : Parent.DrawPosition();
|
||||
}
|
||||
|
||||
public virtual int2 ChildOrigin { get { return RenderOrigin; } }
|
||||
public virtual Rectangle RenderBounds { get { return new Rectangle(RenderOrigin.X, RenderOrigin.Y, Bounds.Width, Bounds.Height); } }
|
||||
|
||||
public virtual void Initialize()
|
||||
{
|
||||
@@ -139,21 +138,17 @@ namespace OpenRA.Widgets
|
||||
public bool HitTest(int2 xy)
|
||||
{
|
||||
if (!IsVisible()) return false;
|
||||
var pos = DrawPosition();
|
||||
var rect = new Rectangle(pos.X, pos.Y, Bounds.Width, Bounds.Height);
|
||||
if (rect.Contains(xy.ToPoint()) && !ClickThrough) return true;
|
||||
if (RenderBounds.Contains(xy.ToPoint()) && !ClickThrough) return true;
|
||||
|
||||
return Children.Any(c => c.HitTest(xy));
|
||||
}
|
||||
|
||||
public Rectangle GetEventBounds()
|
||||
{
|
||||
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())
|
||||
.Aggregate(rect, Rectangle.Union);
|
||||
.Aggregate(RenderBounds, Rectangle.Union);
|
||||
}
|
||||
|
||||
public virtual bool HandleInput(MouseInput mi)
|
||||
|
||||
Reference in New Issue
Block a user