interim hack to support use of raw data in Sheet
This commit is contained in:
@@ -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
|
||||||
|
|||||||
@@ -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; }
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user