Add UnionRectangles extension method.

This commit is contained in:
RoosterDragon
2019-06-14 21:05:50 +01:00
committed by abcdefg30
parent 0e6c37d765
commit 31918e8712
7 changed files with 29 additions and 54 deletions

View File

@@ -53,20 +53,10 @@ namespace OpenRA.Mods.Common.Widgets
.ToArray();
// Calculate the preview bounds
PreviewOffset = int2.Zero;
IdealPreviewSize = int2.Zero;
var r = preview.SelectMany(p => p.ScreenBounds(worldRenderer, WPos.Zero));
if (r.Any())
{
var b = r.First();
foreach (var rr in r.Skip(1))
b = Rectangle.Union(b, rr);
IdealPreviewSize = new int2(b.Width, b.Height);
PreviewOffset = -new int2(b.Left, b.Top) - IdealPreviewSize / 2;
}
var b = r.Union();
IdealPreviewSize = new int2(b.Width, b.Height);
PreviewOffset = -new int2(b.Left, b.Top) - IdealPreviewSize / 2;
}
IFinalizedRenderable[] renderables;

View File

@@ -425,7 +425,7 @@ namespace OpenRA.Mods.Common.Widgets
DisplayedIconCount++;
}
eventBounds = icons.Any() ? icons.Keys.Aggregate(Rectangle.Union) : Rectangle.Empty;
eventBounds = icons.Keys.Union();
if (oldIconCount != DisplayedIconCount)
OnIconCountChanged(oldIconCount, DisplayedIconCount);

View File

@@ -154,7 +154,7 @@ namespace OpenRA.Mods.Common.Widgets
IconCount++;
}
eventBounds = icons.Any() ? icons.Keys.Aggregate(Rectangle.Union) : Rectangle.Empty;
eventBounds = icons.Keys.Union();
if (oldIconCount != IconCount)
OnIconCountChanged(oldIconCount, IconCount);