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 ++++++++++++++++++++++++------------------- GfxEditor.cs | 129 +++++++++++++++++++++++--------------------- MainForm.cs | 169 +++++++++++++++++++++++++++++++++++++++++----------------- Util.cs | 61 +++++++++++++++++++++ 4 files changed, 320 insertions(+), 166 deletions(-) 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>8; + } + } + + public static void WriteInt(Stream str, int l) + { + for(uint f=0;f<4;f++) + { + str.WriteByte((byte)(l&0xff)); + l=l>>8; + } + } + + public static void WriteString(Stream str, string s) + { + byte[] b=Encoding.ASCII.GetBytes(s); + + str.Write(b,0,b.Length); + } + + public static string ReadString(Stream str, int len) + { + byte[] b=new byte[len]; + + str.Read(b,0,len); + return Encoding.ASCII.GetString(b); + } + private Util() { } -- cgit v1.2.3