interim hack to support use of raw data in Sheet

This commit is contained in:
Chris Forbes
2010-08-19 18:42:45 +12:00
parent db7a11e8a6
commit 1595c6a0ed
2 changed files with 24 additions and 23 deletions

View File

@@ -71,15 +71,9 @@ namespace OpenRA.FileFormats.Graphics
public interface ITexture public interface ITexture
{ {
void SetData( Bitmap bitmap ); void SetData(Bitmap bitmap);
void SetData(uint[,] colors); void SetData(uint[,] colors);
} void SetData(byte[] colors, int width, int height);
public interface IFont
{
void DrawText( string text, int2 pos, Color c );
int2 Measure( string text );
} }
public enum PrimitiveType public enum PrimitiveType

View File

@@ -16,18 +16,21 @@ namespace OpenRA.Graphics
{ {
public class Sheet public class Sheet
{ {
protected readonly Bitmap bitmap; Bitmap bitmap;
ITexture texture; ITexture texture;
bool dirty; bool dirty;
byte[] data;
public readonly Size Size;
public Sheet(Size size) public Sheet(Size size)
{ {
this.bitmap = new Bitmap(size.Width, size.Height); Size = size;
} }
internal Sheet(string filename) internal Sheet(string filename)
{ {
this.bitmap = (Bitmap)Image.FromStream(FileSystem.Open(filename)); bitmap = (Bitmap)Image.FromStream(FileSystem.Open(filename));
Size = bitmap.Size;
} }
public ITexture Texture public ITexture Texture
@@ -35,27 +38,31 @@ namespace OpenRA.Graphics
get get
{ {
if (texture == null) if (texture == null)
texture = Game.Renderer.Device.CreateTexture(bitmap); {
texture = Game.Renderer.Device.CreateTexture();
dirty = true;
}
if (dirty) if (dirty)
{ {
texture.SetData(bitmap); if (data != null)
dirty = false; {
texture.SetData(data, Size.Width, Size.Height);
dirty = false;
}
else if (bitmap != null)
{
texture.SetData(Bitmap);
dirty = false;
}
} }
return texture; return texture;
} }
} }
public Size Size { get { return bitmap.Size; } } public Bitmap Bitmap { get { if (bitmap == null) bitmap = new Bitmap(Size.Width, Size.Height); return bitmap; } }
public byte[] Data { get { if (data == null) data = new byte[4 * Size.Width * Size.Height]; return data; } }
protected 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
public void MakeDirty() { dirty = true; } public void MakeDirty() { dirty = true; }
} }