summaryrefslogtreecommitdiff
path: root/MainForm.cs
diff options
context:
space:
mode:
Diffstat (limited to 'MainForm.cs')
-rw-r--r--MainForm.cs169
1 files changed, 120 insertions, 49 deletions
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;