diff options
-rw-r--r-- | BitmapChar.cs | 127 | ||||
-rw-r--r-- | GfxEditor.cs | 129 | ||||
-rw-r--r-- | MainForm.cs | 169 | ||||
-rw-r--r-- | 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<m_height;y++)
+ for(uint x=0;x<m_width;x++)
{
- for(uint x=0;x<m_width;x++)
+ for(uint y=0;y<m_height;y++)
{
- WriteInt(stream,m_data[x,y].ToArgb());
+ if (m_data[x,y]!=Color.Black)
+ {
+ Util.WriteInt(stream,m_data[x,y].ToArgb());
+ }
+ else
+ {
+ Util.WriteInt(stream,0);
+ }
}
}
}
public static BitmapChar Input(Stream stream)
{
- uint width=ReadUint(stream);
- uint height=ReadUint(stream);
+ uint width=Util.ReadUint(stream);
+ uint height=Util.ReadUint(stream);
BitmapChar s=new BitmapChar(width,height);
- for(uint y=0;y<height;y++)
+ for(uint x=0;x<width;x++)
{
- for(uint x=0;x<width;x++)
+ for(uint y=0;y<height;y++)
{
- s[x,y]=Color.FromArgb(ReadInt(stream));
+ int col=Util.ReadInt(stream);
+
+ if (col==0)
+ {
+ s[x,y]=Color.Black;
+ }
+ else
+ {
+ s[x,y]=Color.FromArgb(255,(col&0xff0000)>>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;
- }
- }
}
/// <summary>
@@ -295,7 +272,7 @@ namespace BitmapFontEd /// </summary>
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<CHARS;f++)
{
l.m_list[f]=BitmapChar.Input(stream);
@@ -355,6 +370,8 @@ namespace BitmapFontEd // ------------------------------------------------
// PRIVATE
//
+ private const string MAGIC="BMF1";
+
private BitmapChar[] m_list;
private bool m_changed;
}
diff --git a/GfxEditor.cs b/GfxEditor.cs index d72b2fb..048317e 100644 --- a/GfxEditor.cs +++ b/GfxEditor.cs @@ -33,18 +33,18 @@ namespace BitmapFontEd [ToolboxItem(true)]
public class GfxEditor : System.Windows.Forms.UserControl
{
- private System.Windows.Forms.Label label4;
- private System.Windows.Forms.Label label2;
+ private System.Windows.Forms.Label label3;
+ private System.Windows.Forms.Label m_bgPreview;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.PictureBox m_edit;
private System.Windows.Forms.ComboBox m_modeList;
private System.Windows.Forms.Label m_fgPreview;
+ private System.Windows.Forms.Label label2;
private System.Windows.Forms.PictureBox m_preview;
private System.Windows.Forms.NumericUpDown m_sizeY;
private System.Windows.Forms.Label label6;
private System.Windows.Forms.Label label5;
- private System.Windows.Forms.Label m_bgPreview;
- private System.Windows.Forms.Label label3;
+ private System.Windows.Forms.Label label4;
private System.Windows.Forms.NumericUpDown m_sizeX;
private System.Windows.Forms.Label m_pos;
private System.Windows.Forms.Button m_undoButton;
@@ -75,8 +75,6 @@ namespace BitmapFontEd private uint m_width;
private uint m_height;
- private bool m_ignoreSize;
-
private Rectangle m_editRect;
private Bitmap m_editBmp;
private Rectangle m_prevRect;
@@ -117,8 +115,6 @@ namespace BitmapFontEd m_my=SIZE;
m_gridCol=Color.LightGreen;
- m_ignoreSize=false;
-
m_editRect=m_edit.ClientRectangle;
m_editBmp=new Bitmap(m_editRect.Width,m_editRect.Height);
m_edit.Image=m_editBmp;
@@ -150,18 +146,18 @@ namespace BitmapFontEd this.m_undoButton = new System.Windows.Forms.Button();
this.m_pos = new System.Windows.Forms.Label();
this.m_sizeX = new System.Windows.Forms.NumericUpDown();
- this.label3 = new System.Windows.Forms.Label();
- this.m_bgPreview = new System.Windows.Forms.Label();
+ this.label4 = new System.Windows.Forms.Label();
this.label5 = new System.Windows.Forms.Label();
this.label6 = new System.Windows.Forms.Label();
this.m_sizeY = new System.Windows.Forms.NumericUpDown();
this.m_preview = new System.Windows.Forms.PictureBox();
+ this.label2 = new System.Windows.Forms.Label();
this.m_fgPreview = new System.Windows.Forms.Label();
this.m_modeList = new System.Windows.Forms.ComboBox();
this.m_edit = new System.Windows.Forms.PictureBox();
this.label1 = new System.Windows.Forms.Label();
- this.label2 = new System.Windows.Forms.Label();
- this.label4 = new System.Windows.Forms.Label();
+ this.m_bgPreview = new System.Windows.Forms.Label();
+ this.label3 = new System.Windows.Forms.Label();
((System.ComponentModel.ISupportInitialize)(this.m_sizeX)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.m_sizeY)).BeginInit();
this.SuspendLayout();
@@ -206,27 +202,17 @@ namespace BitmapFontEd 0,
0,
0});
- this.m_sizeX.ValueChanged += new System.EventHandler(this.OnSize);
- this.m_sizeX.Leave += new System.EventHandler(this.OnSize);
- //
- // label3
- //
- this.label3.Location = new System.Drawing.Point(280, 8);
- this.label3.Name = "label3";
- this.label3.Size = new System.Drawing.Size(48, 16);
- this.label3.TabIndex = 8;
- this.label3.Text = "Width";
- this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
+ this.m_sizeX.ValueChanged += new System.EventHandler(this.OnSizeWidth);
+ this.m_sizeX.Leave += new System.EventHandler(this.OnSizeWidth);
//
- // m_bgPreview
+ // label4
//
- this.m_bgPreview.BackColor = System.Drawing.Color.Black;
- this.m_bgPreview.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
- this.m_bgPreview.Location = new System.Drawing.Point(336, 120);
- this.m_bgPreview.Name = "m_bgPreview";
- this.m_bgPreview.Size = new System.Drawing.Size(40, 40);
- this.m_bgPreview.TabIndex = 18;
- this.m_bgPreview.Click += new System.EventHandler(this.OnBackground);
+ this.label4.Location = new System.Drawing.Point(280, 96);
+ this.label4.Name = "label4";
+ this.label4.Size = new System.Drawing.Size(32, 16);
+ this.label4.TabIndex = 10;
+ this.label4.Text = "Left";
+ this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// label5
//
@@ -269,8 +255,8 @@ namespace BitmapFontEd 0,
0,
0});
- this.m_sizeY.ValueChanged += new System.EventHandler(this.OnSize);
- this.m_sizeY.Leave += new System.EventHandler(this.OnSize);
+ this.m_sizeY.ValueChanged += new System.EventHandler(this.OnSizeHeight);
+ this.m_sizeY.Leave += new System.EventHandler(this.OnSizeHeight);
//
// m_preview
//
@@ -281,6 +267,15 @@ namespace BitmapFontEd this.m_preview.TabIndex = 1;
this.m_preview.TabStop = false;
//
+ // label2
+ //
+ this.label2.Location = new System.Drawing.Point(280, 176);
+ this.label2.Name = "label2";
+ this.label2.Size = new System.Drawing.Size(56, 16);
+ this.label2.TabIndex = 21;
+ this.label2.Text = "Preview";
+ this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
+ //
// m_fgPreview
//
this.m_fgPreview.BackColor = System.Drawing.Color.White;
@@ -335,23 +330,24 @@ namespace BitmapFontEd this.label1.Text = "Draw Mode";
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
- // label2
+ // m_bgPreview
//
- this.label2.Location = new System.Drawing.Point(280, 176);
- this.label2.Name = "label2";
- this.label2.Size = new System.Drawing.Size(56, 16);
- this.label2.TabIndex = 21;
- this.label2.Text = "Preview";
- this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
+ this.m_bgPreview.BackColor = System.Drawing.Color.Black;
+ this.m_bgPreview.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
+ this.m_bgPreview.Location = new System.Drawing.Point(336, 120);
+ this.m_bgPreview.Name = "m_bgPreview";
+ this.m_bgPreview.Size = new System.Drawing.Size(40, 40);
+ this.m_bgPreview.TabIndex = 18;
+ this.m_bgPreview.Click += new System.EventHandler(this.OnBackground);
//
- // label4
+ // label3
//
- this.label4.Location = new System.Drawing.Point(280, 96);
- this.label4.Name = "label4";
- this.label4.Size = new System.Drawing.Size(32, 16);
- this.label4.TabIndex = 10;
- this.label4.Text = "Left";
- this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
+ this.label3.Location = new System.Drawing.Point(280, 8);
+ this.label3.Name = "label3";
+ this.label3.Size = new System.Drawing.Size(48, 16);
+ this.label3.TabIndex = 8;
+ this.label3.Text = "Width";
+ this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// GfxEditor
//
@@ -404,11 +400,12 @@ namespace BitmapFontEd set
{
m_char=value;
- m_ignoreSize=true;
+ m_width=m_char.Width;
+ m_height=m_char.Height;
m_sizeX.Value=Convert.ToDecimal(m_char.Width);
- m_ignoreSize=false;
m_sizeY.Value=Convert.ToDecimal(m_char.Height);
InitialiseOverlay();
+ DrawGrid();
DrawChar();
}
}
@@ -429,19 +426,16 @@ namespace BitmapFontEd private void DrawGrid()
{
- Graphics g=Graphics.FromImage(m_editBmp);
+ Graphics g=Graphics.FromImage(m_prevBmp);
Pen p=new Pen(m_gridCol);
-
- g.Clear(Color.Black);
- Flush(ref g);
-
- g=Graphics.FromImage(m_prevBmp);
g.Clear(Color.Black);
Flush(ref g);
g=Graphics.FromImage(m_editBmp);
+ g.Clear(Color.Black);
+
for(int x=0;x<m_width+1;x++)
{
g.DrawLine(p,x*m_grid,0,x*m_grid,m_my);
@@ -822,14 +816,27 @@ namespace BitmapFontEd m_mode=(Mode)m_modeList.SelectedIndex;
}
- void OnSize(object sender, System.EventArgs e)
+ void OnSizeWidth(object sender, System.EventArgs e)
{
- if (m_ignoreSize)
+ m_width=Convert.ToUInt32(m_sizeX.Value);
+
+ if (m_char!=null)
{
- return;
+ m_undo=new BitmapChar(m_char);
+ m_char.Resize(m_width,m_height);
+ InitialiseOverlay();
}
- m_width=Convert.ToUInt32(m_sizeX.Value);
+ m_grid=Math.Min(SIZE/m_width,SIZE/m_height);
+
+ m_mx=m_width*m_grid;
+
+ DrawGrid();
+ DrawChar();
+ }
+
+ void OnSizeHeight(object sender, System.EventArgs e)
+ {
m_height=Convert.ToUInt32(m_sizeY.Value);
if (m_char!=null)
@@ -841,13 +848,12 @@ namespace BitmapFontEd m_grid=Math.Min(SIZE/m_width,SIZE/m_height);
- m_mx=m_width*m_grid;
m_my=m_height*m_grid;
DrawGrid();
DrawChar();
}
-
+
void OnEnterEditor(object sender, System.EventArgs e)
{
//m_inEditor=true;
@@ -1094,6 +1100,5 @@ namespace BitmapFontEd }
#endregion
-
}
}
diff --git a/MainForm.cs b/MainForm.cs index e63371a..9e803d7 100644 --- a/MainForm.cs +++ b/MainForm.cs @@ -21,6 +21,7 @@ using System; using System.Drawing;
using System.Windows.Forms;
using System.Text;
+using System.IO;
namespace BitmapFontEd
{
@@ -34,20 +35,20 @@ namespace BitmapFontEd private System.Windows.Forms.GroupBox m_adjustGroup;
private System.Windows.Forms.MainMenu m_menu;
private System.Windows.Forms.ComboBox m_asciiSelect;
- private System.Windows.Forms.MenuItem m_fileMenu;
+ private System.Windows.Forms.MenuItem m_about;
private System.Windows.Forms.MenuItem m_open;
private System.Windows.Forms.MenuItem menuItem6;
private System.Windows.Forms.MenuItem m_saveAs;
private System.Windows.Forms.TrackBar m_charSelect;
+ private System.Windows.Forms.MenuItem m_fileMenu;
private System.Windows.Forms.MenuItem m_quit;
private System.Windows.Forms.MenuItem m_new;
- private System.Windows.Forms.GroupBox m_editGroup;
- private System.Windows.Forms.Button m_revert;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Button m_resize;
- private System.Windows.Forms.MenuItem m_about;
+ private System.Windows.Forms.GroupBox m_editGroup;
private System.Windows.Forms.MenuItem m_save;
+ private System.Windows.Forms.Button m_revert;
private System.Windows.Forms.NumericUpDown m_codeSelect;
private System.Windows.Forms.GroupBox m_globaladjustGroup;
private System.Windows.Forms.MenuItem m_helpMenu;
@@ -56,6 +57,7 @@ namespace BitmapFontEd private BitmapCharList m_chars;
private int m_selected;
private bool m_inSelect;
+ private string m_path;
public MainForm()
{
@@ -72,7 +74,7 @@ namespace BitmapFontEd m_chars=new BitmapCharList();
- for(byte c=32;c<128;c++)
+ for(byte c=32;c<127;c++)
{
switch(c)
{
@@ -89,8 +91,10 @@ namespace BitmapFontEd }
}
- m_selected=0;
+ m_path="";
+ m_save.Enabled=false;
+ m_selected=0;
SelectChar(0);
}
@@ -110,20 +114,20 @@ namespace BitmapFontEd this.m_helpMenu = new System.Windows.Forms.MenuItem();
this.m_globaladjustGroup = new System.Windows.Forms.GroupBox();
this.m_codeSelect = new System.Windows.Forms.NumericUpDown();
+ this.m_revert = new System.Windows.Forms.Button();
this.m_save = new System.Windows.Forms.MenuItem();
- this.m_about = new System.Windows.Forms.MenuItem();
+ this.m_editGroup = new System.Windows.Forms.GroupBox();
this.m_resize = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
- this.m_revert = new System.Windows.Forms.Button();
- this.m_editGroup = new System.Windows.Forms.GroupBox();
this.m_new = new System.Windows.Forms.MenuItem();
this.m_quit = new System.Windows.Forms.MenuItem();
+ this.m_fileMenu = new System.Windows.Forms.MenuItem();
this.m_charSelect = new System.Windows.Forms.TrackBar();
this.m_saveAs = new System.Windows.Forms.MenuItem();
this.menuItem6 = new System.Windows.Forms.MenuItem();
this.m_open = new System.Windows.Forms.MenuItem();
- this.m_fileMenu = new System.Windows.Forms.MenuItem();
+ this.m_about = new System.Windows.Forms.MenuItem();
this.m_asciiSelect = new System.Windows.Forms.ComboBox();
this.m_menu = new System.Windows.Forms.MainMenu();
this.m_adjustGroup = new System.Windows.Forms.GroupBox();
@@ -168,7 +172,7 @@ namespace BitmapFontEd 0});
this.m_codeSelect.Name = "m_codeSelect";
this.m_codeSelect.ReadOnly = true;
- this.m_codeSelect.Size = new System.Drawing.Size(64, 21);
+ this.m_codeSelect.Size = new System.Drawing.Size(64, 20);
this.m_codeSelect.TabIndex = 9;
this.m_codeSelect.Value = new System.Decimal(new int[] {
32,
@@ -177,6 +181,15 @@ namespace BitmapFontEd 0});
this.m_codeSelect.ValueChanged += new System.EventHandler(this.OnSelectByCode);
//
+ // m_revert
+ //
+ this.m_revert.Location = new System.Drawing.Point(304, 64);
+ this.m_revert.Name = "m_revert";
+ this.m_revert.Size = new System.Drawing.Size(88, 24);
+ this.m_revert.TabIndex = 6;
+ this.m_revert.Text = "Revert";
+ this.m_revert.Click += new System.EventHandler(this.OnRevert);
+ //
// m_save
//
this.m_save.Index = 2;
@@ -184,11 +197,14 @@ namespace BitmapFontEd this.m_save.Text = "&Save";
this.m_save.Click += new System.EventHandler(this.OnSave);
//
- // m_about
+ // m_editGroup
//
- this.m_about.Index = 0;
- this.m_about.Text = "&About";
- this.m_about.Click += new System.EventHandler(this.OnAbout);
+ this.m_editGroup.Location = new System.Drawing.Point(8, 8);
+ this.m_editGroup.Name = "m_editGroup";
+ this.m_editGroup.Size = new System.Drawing.Size(408, 328);
+ this.m_editGroup.TabIndex = 0;
+ this.m_editGroup.TabStop = false;
+ this.m_editGroup.Text = "Editor";
//
// m_resize
//
@@ -217,24 +233,6 @@ namespace BitmapFontEd this.label2.Text = "Character:";
this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
- // m_revert
- //
- this.m_revert.Location = new System.Drawing.Point(304, 64);
- this.m_revert.Name = "m_revert";
- this.m_revert.Size = new System.Drawing.Size(88, 24);
- this.m_revert.TabIndex = 6;
- this.m_revert.Text = "Revert";
- this.m_revert.Click += new System.EventHandler(this.OnRevert);
- //
- // m_editGroup
- //
- this.m_editGroup.Location = new System.Drawing.Point(8, 8);
- this.m_editGroup.Name = "m_editGroup";
- this.m_editGroup.Size = new System.Drawing.Size(408, 328);
- this.m_editGroup.TabIndex = 0;
- this.m_editGroup.TabStop = false;
- this.m_editGroup.Text = "Editor";
- //
// m_new
//
this.m_new.Index = 0;
@@ -249,10 +247,22 @@ namespace BitmapFontEd this.m_quit.Text = "&Quit";
this.m_quit.Click += new System.EventHandler(this.OnQuit);
//
+ // m_fileMenu
+ //
+ this.m_fileMenu.Index = 0;
+ this.m_fileMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
+ this.m_new,
+ this.m_open,
+ this.m_save,
+ this.m_saveAs,
+ this.menuItem6,
+ this.m_quit});
+ this.m_fileMenu.Text = "&File";
+ //
// m_charSelect
//
this.m_charSelect.Location = new System.Drawing.Point(8, 16);
- this.m_charSelect.Maximum = 95;
+ this.m_charSelect.Maximum = 94;
this.m_charSelect.Name = "m_charSelect";
this.m_charSelect.Size = new System.Drawing.Size(392, 42);
this.m_charSelect.TabIndex = 5;
@@ -277,17 +287,11 @@ namespace BitmapFontEd this.m_open.Text = "&Open";
this.m_open.Click += new System.EventHandler(this.OnOpen);
//
- // m_fileMenu
+ // m_about
//
- this.m_fileMenu.Index = 0;
- this.m_fileMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
- this.m_new,
- this.m_open,
- this.m_save,
- this.m_saveAs,
- this.menuItem6,
- this.m_quit});
- this.m_fileMenu.Text = "&File";
+ this.m_about.Index = 0;
+ this.m_about.Text = "&About";
+ this.m_about.Click += new System.EventHandler(this.OnAbout);
//
// m_asciiSelect
//
@@ -340,7 +344,7 @@ namespace BitmapFontEd //
// MainForm
//
- this.AutoScaleBaseSize = new System.Drawing.Size(5, 14);
+ this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(650, 479);
this.Controls.Add(this.m_adjustGroup);
this.Controls.Add(this.m_globaladjustGroup);
@@ -384,22 +388,84 @@ namespace BitmapFontEd m_chars=new BitmapCharList();
m_edit.BitmapChar=new BitmapChar();
OnSelectChar(null,null);
+ m_save.Enabled=false;
}
}
void OnOpen(object sender, System.EventArgs e)
{
-
+ if (ChangesAllowed)
+ {
+ OpenFileDialog fsel=new OpenFileDialog();
+
+ fsel.FileName=m_path;
+ fsel.Filter="Bitmap Font Files (*.bmf)|*.bmf|All files (*.*)|*.*";
+
+ if (fsel.ShowDialog()==DialogResult.OK)
+ {
+ using(FileStream str=File.Open(fsel.FileName,FileMode.Open))
+ {
+ try
+ {
+ m_chars=BitmapCharList.Input(str);
+ m_path=fsel.FileName;
+ m_save.Enabled=true;
+ str.Close();
+ }
+ catch (Exception ex)
+ {
+ Util.Error("Error opening " + fsel.FileName + ":\n" + ex.Message);
+ }
+ }
+ }
+
+ m_edit.BitmapChar=m_chars[m_selected];
+ }
}
void OnSave(object sender, System.EventArgs e)
{
+ FetchEdit();
+ using(FileStream str=File.Open(m_path,FileMode.Create))
+ {
+ try
+ {
+ m_chars.Output(str);
+ str.Close();
+ }
+ catch (Exception ex)
+ {
+ Util.Error("Error writing " + m_path + ":\n" + ex.Message);
+ }
+ }
}
void OnSaveAs(object sender, System.EventArgs e)
{
+ SaveFileDialog fsel=new SaveFileDialog();
+
+ fsel.FileName=m_path;
+ fsel.Filter="Bitmap Font Files (*.bmf)|*.bmf|All files (*.*)|*.*";
+ if (fsel.ShowDialog()==DialogResult.OK)
+ {
+ FetchEdit();
+
+ using(FileStream str=File.Open(fsel.FileName,FileMode.Create))
+ {
+ try
+ {
+ m_chars.Output(str);
+ m_path=fsel.FileName;
+ str.Close();
+ }
+ catch (Exception ex)
+ {
+ Util.Error("Error writing " + fsel.FileName + ":\n" + ex.Message);
+ }
+ }
+ }
}
void OnQuit(object sender, System.EventArgs e)
@@ -415,14 +481,19 @@ namespace BitmapFontEd }
}
- private void SelectChar(int sel)
+ private void FetchEdit()
{
- m_inSelect=true;
-
if (EditChanged)
{
m_chars[m_selected]=m_edit.BitmapChar;
}
+ }
+
+ private void SelectChar(int sel)
+ {
+ m_inSelect=true;
+
+ FetchEdit();
m_selected=sel;
@@ -20,6 +20,7 @@ using System;
using System.Windows.Forms;
using System.Text;
+using System.IO;
namespace BitmapFontEd
{
@@ -56,6 +57,66 @@ namespace BitmapFontEd MessageBoxButtons.OK,MessageBoxIcon.Information);
}
+
+ public static uint ReadUint(Stream str)
+ {
+ uint l=0;
+
+ for(int f=0;f<4;f++)
+ {
+ int b=str.ReadByte();
+ l|=(uint)(b<<(f*8));
+ }
+
+ return l;
+ }
+
+ public static int ReadInt(Stream str)
+ {
+ int l=0;
+
+ for(int f=0;f<4;f++)
+ {
+ int b=str.ReadByte();
+ l|=b<<(f*8);
+ }
+
+ return l;
+ }
+
+ public static void WriteUint(Stream str, uint l)
+ {
+ for(uint f=0;f<4;f++)
+ {
+ str.WriteByte((byte)(l&0xff));
+ l=l>>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()
{
}
|