Support borderless panel types.

This commit is contained in:
Paul Chote
2014-03-23 17:03:58 +13:00
parent 31991c3679
commit aa77536e96
2 changed files with 33 additions and 40 deletions

View File

@@ -79,12 +79,8 @@ namespace OpenRA.Graphics
return cachedSprites[collection][image]; return cachedSprites[collection][image];
MappedImage mi; MappedImage mi;
try { mi = collections[collection].regions[image]; } if (!collections[collection].regions.TryGetValue(image, out mi))
catch (KeyNotFoundException) return null;
{
throw new InvalidOperationException(
"Collection `{0}` does not have an image `{1}`".F(collection, image));
}
// Cached sheet // Cached sheet
Sheet sheet; Sheet sheet;

View File

@@ -91,53 +91,50 @@ namespace OpenRA.Widgets
public static void DrawPanelPartial(Sprite[] ss, Rectangle bounds, PanelSides ps) public static void DrawPanelPartial(Sprite[] ss, Rectangle bounds, PanelSides ps)
{ {
var marginLeft = ss[2] == null ? 0 : (int)ss[2].size.X;
var marginTop = ss[0] == null ? 0 : (int)ss[0].size.Y;
var marginRight = ss[3] == null ? 0 : (int)ss[3].size.X;
var marginBottom = ss[1] == null ? 0 : (int)ss[1].size.Y;
var marginWidth = marginRight + marginLeft;
var marginHeight = marginBottom + marginTop;
// Background // Background
if (ps.HasFlags(PanelSides.Center)) if (ps.HasFlags(PanelSides.Center) && ss[8] != null)
FillRectWithSprite(new Rectangle(bounds.Left + (int)ss[2].size.X, FillRectWithSprite(new Rectangle(bounds.Left + marginLeft, bounds.Top + marginTop,
bounds.Top + (int)ss[0].size.Y, bounds.Width - marginWidth, bounds.Height - marginHeight),
bounds.Right - (int)ss[3].size.X - bounds.Left - (int)ss[2].size.X, ss[8]);
bounds.Bottom - (int)ss[1].size.Y - bounds.Top - (int)ss[0].size.Y),
ss[8]);
// Left border // Left border
if (ps.HasFlags(PanelSides.Left)) if (ps.HasFlags(PanelSides.Left) && ss[2] != null)
FillRectWithSprite(new Rectangle(bounds.Left, FillRectWithSprite(new Rectangle(bounds.Left, bounds.Top + marginTop,
bounds.Top + (int)ss[0].size.Y, marginLeft, bounds.Height - marginHeight),
(int)ss[2].size.X, ss[2]);
bounds.Bottom - (int)ss[1].size.Y - bounds.Top - (int)ss[0].size.Y),
ss[2]);
// Right border // Right border
if (ps.HasFlags(PanelSides.Right)) if (ps.HasFlags(PanelSides.Right) && ss[3] != null)
FillRectWithSprite(new Rectangle(bounds.Right - (int)ss[3].size.X, FillRectWithSprite(new Rectangle(bounds.Right - marginRight, bounds.Top + marginTop,
bounds.Top + (int)ss[0].size.Y, marginLeft, bounds.Height - marginHeight),
(int)ss[2].size.X, ss[3]);
bounds.Bottom - (int)ss[1].size.Y - bounds.Top - (int)ss[0].size.Y),
ss[3]);
// Top border // Top border
if (ps.HasFlags(PanelSides.Top)) if (ps.HasFlags(PanelSides.Top) && ss[0] != null)
FillRectWithSprite(new Rectangle(bounds.Left + (int)ss[2].size.X, FillRectWithSprite(new Rectangle(bounds.Left + marginLeft, bounds.Top,
bounds.Top, bounds.Width - marginWidth, marginTop),
bounds.Right - (int)ss[3].size.X - bounds.Left - (int)ss[2].size.X, ss[0]);
(int)ss[0].size.Y),
ss[0]);
// Bottom border // Bottom border
if (ps.HasFlags(PanelSides.Bottom)) if (ps.HasFlags(PanelSides.Bottom) && ss[1] != null)
FillRectWithSprite(new Rectangle(bounds.Left + (int)ss[2].size.X, FillRectWithSprite(new Rectangle(bounds.Left + marginLeft, bounds.Bottom - marginBottom,
bounds.Bottom - (int)ss[1].size.Y, bounds.Width - marginWidth, marginTop),
bounds.Right - (int)ss[3].size.X - bounds.Left - (int)ss[2].size.X, ss[1]);
(int)ss[0].size.Y),
ss[1]);
if (ps.HasFlags(PanelSides.Left | PanelSides.Top)) if (ps.HasFlags(PanelSides.Left | PanelSides.Top) && ss[4] != null)
DrawRGBA(ss[4], new float2(bounds.Left, bounds.Top)); DrawRGBA(ss[4], new float2(bounds.Left, bounds.Top));
if (ps.HasFlags(PanelSides.Right | PanelSides.Top)) if (ps.HasFlags(PanelSides.Right | PanelSides.Top) && ss[5] != null)
DrawRGBA(ss[5], new float2(bounds.Right - ss[5].size.X, bounds.Top)); DrawRGBA(ss[5], new float2(bounds.Right - ss[5].size.X, bounds.Top));
if (ps.HasFlags(PanelSides.Left | PanelSides.Bottom)) if (ps.HasFlags(PanelSides.Left | PanelSides.Bottom) && ss[6] != null)
DrawRGBA(ss[6], new float2(bounds.Left, bounds.Bottom - ss[6].size.Y)); DrawRGBA(ss[6], new float2(bounds.Left, bounds.Bottom - ss[6].size.Y));
if (ps.HasFlags(PanelSides.Right | PanelSides.Bottom)) if (ps.HasFlags(PanelSides.Right | PanelSides.Bottom) && ss[7] != null)
DrawRGBA(ss[7], new float2(bounds.Right - ss[7].size.X, bounds.Bottom - ss[7].size.Y)); DrawRGBA(ss[7], new float2(bounds.Right - ss[7].size.X, bounds.Bottom - ss[7].size.Y));
} }