git-svn-id: svn://svn.ijw.co.nz/svn/OpenRa@2049 993157c7-ee19-0410-b2c4-bb4e9862e678
This commit is contained in:
51
OpenRa.Game/Graphics/Sheet.cs
Normal file
51
OpenRa.Game/Graphics/Sheet.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using Ijw.DirectX;
|
||||
|
||||
namespace OpenRa.Game.Graphics
|
||||
{
|
||||
class Sheet
|
||||
{
|
||||
readonly Renderer renderer;
|
||||
protected readonly Bitmap bitmap;
|
||||
|
||||
Texture texture;
|
||||
static int suffix = 0;
|
||||
|
||||
public Sheet(Renderer renderer, Size size)
|
||||
{
|
||||
this.renderer = renderer;
|
||||
this.bitmap = new Bitmap(size.Width, size.Height);
|
||||
}
|
||||
|
||||
void Resolve()
|
||||
{
|
||||
string filename = string.Format("../../../sheet-{0}.png", suffix++);
|
||||
bitmap.Save(filename);
|
||||
|
||||
using (Stream s = File.OpenRead(filename))
|
||||
texture = Texture.Create(s, renderer.Device);
|
||||
}
|
||||
|
||||
public Texture Texture
|
||||
{
|
||||
get
|
||||
{
|
||||
if (texture == null)
|
||||
Resolve();
|
||||
|
||||
return texture;
|
||||
}
|
||||
}
|
||||
|
||||
public Size Size { get { return bitmap.Size; } }
|
||||
|
||||
public Color this[Point p]
|
||||
{
|
||||
get { return bitmap.GetPixel(p.X, p.Y); }
|
||||
set { bitmap.SetPixel(p.X, p.Y, value); }
|
||||
}
|
||||
|
||||
public Bitmap Bitmap { get { return bitmap; } } // for perf
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user