From 779300236a4bc3cda33fbdf91411b7a40c17b16d Mon Sep 17 00:00:00 2001 From: Ian C Date: Sun, 15 May 2005 20:46:43 +0000 Subject: Implemented load/save and tidied some editor control bugs --- BitmapChar.cs | 127 +++++++++++++++++++++++++++++++++------------------------- 1 file changed, 72 insertions(+), 55 deletions(-) (limited to 'BitmapChar.cs') diff --git a/BitmapChar.cs b/BitmapChar.cs index f902d7c..e1cf532 100644 --- a/BitmapChar.cs +++ b/BitmapChar.cs @@ -195,30 +195,51 @@ namespace BitmapFontEd public void Output(Stream stream) { - WriteUint(stream,m_width); - WriteUint(stream,m_height); + Util.WriteUint(stream,m_width); + Util.WriteUint(stream,m_height); - for(uint y=0;y>16,(col&0xff00)>>8,col&0xff); + + if (s[x,y].R==0 && s[x,y].G==0 && s[x,y].B==0) + { + s[x,y]=Color.Black; + } + } } } @@ -244,50 +265,6 @@ namespace BitmapFontEd return v; } - - private static uint ReadUint(Stream s) - { - uint l=0; - - for(int f=0;f<4;f++) - { - int b=s.ReadByte(); - l|=(uint)(b<<(f*8)); - } - - return l; - } - - private static int ReadInt(Stream s) - { - int l=0; - - for(int f=0;f<4;f++) - { - int b=s.ReadByte(); - l|=b<<(f*8); - } - - return l; - } - - private static void WriteUint(Stream s, uint l) - { - for(uint f=0;f<4;f++) - { - s.WriteByte((byte)(l&0xff)); - l=l>>8; - } - } - - private static void WriteInt(Stream s, int l) - { - for(uint f=0;f<4;f++) - { - s.WriteByte((byte)(l&0xff)); - l=l>>8; - } - } } /// @@ -295,7 +272,7 @@ namespace BitmapFontEd /// public class BitmapCharList : IEnumerable { - private const int CHARS=96; + private const int CHARS=95; public BitmapCharList() { @@ -325,6 +302,24 @@ namespace BitmapFontEd set {m_changed=value;} } + public bool IsFixedWidth + { + get + { + uint w=m_list[0].Width; + + foreach (BitmapChar c in m_list) + { + if (c.Width!=w) + { + return false; + } + } + + return true; + } + } + public IEnumerator GetEnumerator() { return m_list.GetEnumerator(); @@ -332,6 +327,17 @@ namespace BitmapFontEd public void Output(Stream stream) { + Util.WriteString(stream,MAGIC); + + if (IsFixedWidth) + { + Util.WriteInt(stream,1); + } + else + { + Util.WriteInt(stream,0); + } + foreach (BitmapChar c in m_list) { c.Output(stream); @@ -342,6 +348,15 @@ namespace BitmapFontEd { BitmapCharList l=new BitmapCharList(); + string magic=Util.ReadString(stream,4); + + if (magic!=MAGIC) + { + throw new Exception("Not a recognised BMF file"); + } + + Util.ReadInt(stream); + for(int f=0;f