// BitmapFontEd // Copyright (C) 2005 Ian Cowburn // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License // as published by the Free Software Foundation; either version 2 // of the License, or (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // // $Id$ // using System; using System.Drawing; using System.Windows.Forms; using System.Text; namespace BitmapFontEd { /// /// Description of MainForm. /// public class MainForm : System.Windows.Forms.Form { private System.Windows.Forms.CheckBox m_applyAll; private System.Windows.Forms.GroupBox m_selectGroup; 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_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_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.MenuItem m_save; private System.Windows.Forms.NumericUpDown m_codeSelect; private System.Windows.Forms.GroupBox m_globaladjustGroup; private System.Windows.Forms.MenuItem m_helpMenu; private GfxEditor m_edit; private BitmapCharList m_chars; private int m_selected; private bool m_inSelect; public MainForm() { // // The InitializeComponent() call is required for Windows Forms designer support. // InitializeComponent(); // Trying to add this in the designer seems to mess up quite a bit. // m_edit=new GfxEditor(); m_edit.Location=new Point(4,16); m_editGroup.Controls.Add(m_edit); m_chars=new BitmapCharList(); for(byte c=32;c<128;c++) { switch(c) { case 32: m_asciiSelect.Items.Add("Space"); break; case 127: m_asciiSelect.Items.Add("DEL"); break; default: m_asciiSelect.Items.Add (Encoding.ASCII.GetString(new byte[] {c})); break; } } m_selected=0; SelectChar(0); } [STAThread] public static void Main(string[] args) { Application.Run(new MainForm()); } #region Windows Forms Designer generated code /// /// This method is required for Windows Forms designer support. /// Do not change the method contents inside the source code editor. The Forms designer might /// not be able to load this method if it was changed manually. /// private void InitializeComponent() { 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_save = new System.Windows.Forms.MenuItem(); this.m_about = new System.Windows.Forms.MenuItem(); 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_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_asciiSelect = new System.Windows.Forms.ComboBox(); this.m_menu = new System.Windows.Forms.MainMenu(); this.m_adjustGroup = new System.Windows.Forms.GroupBox(); this.m_selectGroup = new System.Windows.Forms.GroupBox(); this.m_applyAll = new System.Windows.Forms.CheckBox(); this.m_globaladjustGroup.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.m_codeSelect)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.m_charSelect)).BeginInit(); this.m_adjustGroup.SuspendLayout(); this.m_selectGroup.SuspendLayout(); this.SuspendLayout(); // // m_helpMenu // this.m_helpMenu.Index = 1; this.m_helpMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { this.m_about}); this.m_helpMenu.Text = "&Help"; // // m_globaladjustGroup // this.m_globaladjustGroup.Controls.Add(this.m_resize); this.m_globaladjustGroup.Location = new System.Drawing.Point(424, 8); this.m_globaladjustGroup.Name = "m_globaladjustGroup"; this.m_globaladjustGroup.Size = new System.Drawing.Size(216, 48); this.m_globaladjustGroup.TabIndex = 2; this.m_globaladjustGroup.TabStop = false; this.m_globaladjustGroup.Text = "Global Adjustments"; // // m_codeSelect // this.m_codeSelect.Location = new System.Drawing.Point(88, 64); this.m_codeSelect.Maximum = new System.Decimal(new int[] { 127, 0, 0, 0}); this.m_codeSelect.Minimum = new System.Decimal(new int[] { 32, 0, 0, 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.TabIndex = 9; this.m_codeSelect.Value = new System.Decimal(new int[] { 32, 0, 0, 0}); this.m_codeSelect.ValueChanged += new System.EventHandler(this.OnSelectByCode); // // m_save // this.m_save.Index = 2; this.m_save.Shortcut = System.Windows.Forms.Shortcut.CtrlS; this.m_save.Text = "&Save"; this.m_save.Click += new System.EventHandler(this.OnSave); // // m_about // this.m_about.Index = 0; this.m_about.Text = "&About"; this.m_about.Click += new System.EventHandler(this.OnAbout); // // m_resize // this.m_resize.Location = new System.Drawing.Point(8, 16); this.m_resize.Name = "m_resize"; this.m_resize.Size = new System.Drawing.Size(88, 24); this.m_resize.TabIndex = 0; this.m_resize.Text = "Resize All"; this.m_resize.Click += new System.EventHandler(this.OnResize); // // label1 // this.label1.Location = new System.Drawing.Point(16, 64); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(72, 24); this.label1.TabIndex = 1; this.label1.Text = "ASCII Code:"; this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; // // label2 // this.label2.Location = new System.Drawing.Point(160, 64); this.label2.Name = "label2"; this.label2.Size = new System.Drawing.Size(72, 24); this.label2.TabIndex = 3; 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; this.m_new.Shortcut = System.Windows.Forms.Shortcut.CtrlN; this.m_new.Text = "&New"; this.m_new.Click += new System.EventHandler(this.OnNew); // // m_quit // this.m_quit.Index = 5; this.m_quit.Shortcut = System.Windows.Forms.Shortcut.CtrlQ; this.m_quit.Text = "&Quit"; this.m_quit.Click += new System.EventHandler(this.OnQuit); // // m_charSelect // this.m_charSelect.Location = new System.Drawing.Point(8, 16); this.m_charSelect.Maximum = 95; this.m_charSelect.Name = "m_charSelect"; this.m_charSelect.Size = new System.Drawing.Size(392, 42); this.m_charSelect.TabIndex = 5; this.m_charSelect.Scroll += new System.EventHandler(this.OnSelectChar); // // m_saveAs // this.m_saveAs.Index = 3; this.m_saveAs.Shortcut = System.Windows.Forms.Shortcut.F12; this.m_saveAs.Text = "S&ave as..."; this.m_saveAs.Click += new System.EventHandler(this.OnSaveAs); // // menuItem6 // this.menuItem6.Index = 4; this.menuItem6.Text = "-"; // // m_open // this.m_open.Index = 1; this.m_open.Shortcut = System.Windows.Forms.Shortcut.CtrlO; this.m_open.Text = "&Open"; this.m_open.Click += new System.EventHandler(this.OnOpen); // // 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_asciiSelect // this.m_asciiSelect.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.m_asciiSelect.Location = new System.Drawing.Point(224, 64); this.m_asciiSelect.MaxDropDownItems = 20; this.m_asciiSelect.Name = "m_asciiSelect"; this.m_asciiSelect.Size = new System.Drawing.Size(64, 21); this.m_asciiSelect.TabIndex = 8; this.m_asciiSelect.SelectedIndexChanged += new System.EventHandler(this.OnSelectByChar); // // m_menu // this.m_menu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { this.m_fileMenu, this.m_helpMenu}); // // m_adjustGroup // this.m_adjustGroup.Controls.Add(this.m_applyAll); this.m_adjustGroup.Location = new System.Drawing.Point(424, 64); this.m_adjustGroup.Name = "m_adjustGroup"; this.m_adjustGroup.Size = new System.Drawing.Size(216, 384); this.m_adjustGroup.TabIndex = 3; this.m_adjustGroup.TabStop = false; this.m_adjustGroup.Text = "Character Adjustments"; // // m_selectGroup // this.m_selectGroup.Controls.Add(this.m_codeSelect); this.m_selectGroup.Controls.Add(this.m_asciiSelect); this.m_selectGroup.Controls.Add(this.m_revert); this.m_selectGroup.Controls.Add(this.m_charSelect); this.m_selectGroup.Controls.Add(this.label2); this.m_selectGroup.Controls.Add(this.label1); this.m_selectGroup.Location = new System.Drawing.Point(8, 344); this.m_selectGroup.Name = "m_selectGroup"; this.m_selectGroup.Size = new System.Drawing.Size(408, 104); this.m_selectGroup.TabIndex = 1; this.m_selectGroup.TabStop = false; this.m_selectGroup.Text = "Character"; // // m_applyAll // this.m_applyAll.Location = new System.Drawing.Point(8, 16); this.m_applyAll.Name = "m_applyAll"; this.m_applyAll.Size = new System.Drawing.Size(88, 16); this.m_applyAll.TabIndex = 1; this.m_applyAll.Text = "Apply To All"; // // MainForm // this.AutoScaleBaseSize = new System.Drawing.Size(5, 14); this.ClientSize = new System.Drawing.Size(650, 479); this.Controls.Add(this.m_adjustGroup); this.Controls.Add(this.m_globaladjustGroup); this.Controls.Add(this.m_selectGroup); this.Controls.Add(this.m_editGroup); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; this.MaximizeBox = false; this.Menu = this.m_menu; this.MinimumSize = new System.Drawing.Size(648, 504); this.Name = "MainForm"; this.Text = "Bitmap Font Editor"; this.Closing += new System.ComponentModel.CancelEventHandler(this.OnClosing); this.m_globaladjustGroup.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)(this.m_codeSelect)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.m_charSelect)).EndInit(); this.m_adjustGroup.ResumeLayout(false); this.m_selectGroup.ResumeLayout(false); this.ResumeLayout(false); } #endregion private bool EditChanged { get {return m_edit.BitmapChar!=null && m_edit.BitmapChar.Changed;} } private bool ChangesAllowed { get {return (!m_chars.Changed && !EditChanged) || Util.YesNo("Abandon changes?");} } void OnAbout(object sender, System.EventArgs e) { Util.About(); } void OnNew(object sender, System.EventArgs e) { if (ChangesAllowed) { m_chars=new BitmapCharList(); m_edit.BitmapChar=new BitmapChar(); OnSelectChar(null,null); } } void OnOpen(object sender, System.EventArgs e) { } void OnSave(object sender, System.EventArgs e) { } void OnSaveAs(object sender, System.EventArgs e) { } void OnQuit(object sender, System.EventArgs e) { Close(); } void OnClosing(object sender, System.ComponentModel.CancelEventArgs e) { if (!ChangesAllowed) { e.Cancel=true; } } private void SelectChar(int sel) { m_inSelect=true; if (EditChanged) { m_chars[m_selected]=m_edit.BitmapChar; } m_selected=sel; m_charSelect.Value=sel; m_codeSelect.Value=sel+32; m_asciiSelect.SelectedIndex=sel; m_edit.BitmapChar=new BitmapChar(m_chars[m_selected]); m_inSelect=false; } void OnSelectByCode(object sender, System.EventArgs e) { if (!m_inSelect) { SelectChar(Convert.ToInt32(m_codeSelect.Value-32)); } } void OnSelectByChar(object sender, System.EventArgs e) { if (!m_inSelect) { SelectChar(m_asciiSelect.SelectedIndex); } } void OnSelectChar(object sender, System.EventArgs e) { if (!m_inSelect) { SelectChar(m_charSelect.Value); } } void OnRevert(object sender, System.EventArgs e) { m_edit.BitmapChar=new BitmapChar(m_chars[m_selected]); } void OnResize(object sender, System.EventArgs e) { uint w=m_edit.CharWidth; uint h=m_edit.CharHeight; if (Util.YesNo("Sure you want to resize all characters to " + w + " by " + h)) { foreach (BitmapChar c in m_chars) { c.Resize(w,h); } } } } }