git-svn-id: svn://svn.ijw.co.nz/svn/OpenRa@1111 993157c7-ee19-0410-b2c4-bb4e9862e678
This commit is contained in:
@@ -6,25 +6,48 @@ using System.Drawing;
|
|||||||
namespace OpenRa.Game
|
namespace OpenRa.Game
|
||||||
{
|
{
|
||||||
// T is probably going to be BluntDirectX.Direct3D.Texture
|
// T is probably going to be BluntDirectX.Direct3D.Texture
|
||||||
|
|
||||||
|
|
||||||
public delegate T Provider<T>();
|
public delegate T Provider<T>();
|
||||||
|
|
||||||
public class TileSheetBuilder<T>
|
public class TileSheetBuilder<T>
|
||||||
where T : class
|
where T : class
|
||||||
{
|
{
|
||||||
readonly Size pageSize;
|
readonly SizeF pageSize;
|
||||||
readonly Provider<T> pageProvider;
|
readonly Provider<T> pageProvider;
|
||||||
|
|
||||||
public TileSheetBuilder(Size pageSize, Provider<T> pageProvider)
|
public TileSheetBuilder(SizeF pageSize, Provider<T> pageProvider)
|
||||||
{
|
{
|
||||||
this.pageSize = pageSize;
|
this.pageSize = pageSize;
|
||||||
this.pageProvider = pageProvider;
|
this.pageProvider = pageProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SheetRectangle<T> AddImage(Size imageSize)
|
T current = null;
|
||||||
|
float x = 0, y = 0, rowHeight = 0;
|
||||||
|
|
||||||
|
public SheetRectangle<T> AddImage(SizeF imageSize)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
if (imageSize.Width > pageSize.Width || imageSize.Height > pageSize.Height)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
if (current == null)
|
||||||
|
current = pageProvider();
|
||||||
|
|
||||||
|
if (imageSize.Height > rowHeight || rowHeight == 0 || imageSize.Width + x > pageSize.Width)
|
||||||
|
{
|
||||||
|
y += rowHeight;
|
||||||
|
rowHeight = imageSize.Height;
|
||||||
|
x = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (y + imageSize.Height > pageSize.Height)
|
||||||
|
{
|
||||||
|
current = pageProvider();
|
||||||
|
x = y = rowHeight = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
SheetRectangle<T> rect = new SheetRectangle<T>(current, new PointF(x, y), imageSize);
|
||||||
|
x += imageSize.Width;
|
||||||
|
|
||||||
|
return rect;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user