From b8b5e5a5cc836a381b4861bc9fc18eb0b72cf0c9 Mon Sep 17 00:00:00 2001 From: Ian C Date: Sun, 12 Jun 2005 01:16:15 +0000 Subject: Added controls for setting characters to top left and setting widths and heights accordingly. --- BitmapChar.cs | 52 +++++++++++++ BitmapFontEd.MainForm.resources | Bin 18455 -> 19283 bytes MainForm.cs | 166 +++++++++++++++++++++++++++++++++++++++- Util.cs | 7 ++ 4 files changed, 221 insertions(+), 4 deletions(-) diff --git a/BitmapChar.cs b/BitmapChar.cs index 649c135..cd1fc00 100644 --- a/BitmapChar.cs +++ b/BitmapChar.cs @@ -71,6 +71,58 @@ namespace BitmapFontEd get {return m_changed;} } + public int FirstUsedRow + { + get + { + for(int y=0;y=0;y--) + for(int x=0;x=0;x--) + for(int y=0;y private void InitializeComponent() { this.m_clear = new System.Windows.Forms.Button(); + this.m_autowidth = new System.Windows.Forms.Button(); this.m_selectGroup = new System.Windows.Forms.GroupBox(); this.m_mirrorHorizontal = new System.Windows.Forms.Button(); this.m_open = new System.Windows.Forms.MenuItem(); @@ -161,7 +165,9 @@ namespace BitmapFontEd this.m_about = new System.Windows.Forms.MenuItem(); this.m_dropShadow = new System.Windows.Forms.Button(); this.m_revert = new System.Windows.Forms.Button(); + this.m_topleft = new System.Windows.Forms.Button(); this.m_rotRight = new System.Windows.Forms.Button(); + this.m_autoheight = new System.Windows.Forms.Button(); this.m_mirrorVertical = new System.Windows.Forms.Button(); this.m_fileMenu = new System.Windows.Forms.MenuItem(); this.m_break1 = new System.Windows.Forms.MenuItem(); @@ -189,6 +195,15 @@ namespace BitmapFontEd this.m_clear.Text = "Clear"; this.m_clear.Click += new System.EventHandler(this.OnClear); // + // m_autowidth + // + this.m_autowidth.Location = new System.Drawing.Point(112, 40); + this.m_autowidth.Name = "m_autowidth"; + this.m_autowidth.Size = new System.Drawing.Size(96, 24); + this.m_autowidth.TabIndex = 19; + this.m_autowidth.Text = "Auto Width"; + this.m_autowidth.Click += new System.EventHandler(this.OnAutoWidth); + // // m_selectGroup // this.m_selectGroup.Controls.Add(this.m_codeSelect); @@ -298,7 +313,7 @@ namespace BitmapFontEd // 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.Size = new System.Drawing.Size(96, 24); this.m_resize.TabIndex = 1; this.m_resize.Text = "Resize All"; this.m_resize.Click += new System.EventHandler(this.OnResize); @@ -404,6 +419,15 @@ namespace BitmapFontEd this.m_revert.Text = "Revert"; this.m_revert.Click += new System.EventHandler(this.OnRevert); // + // m_topleft + // + this.m_topleft.Location = new System.Drawing.Point(112, 16); + this.m_topleft.Name = "m_topleft"; + this.m_topleft.Size = new System.Drawing.Size(96, 24); + this.m_topleft.TabIndex = 2; + this.m_topleft.Text = "Align Top Left"; + this.m_topleft.Click += new System.EventHandler(this.OnAlignTopLeft); + // // m_rotRight // this.m_rotRight.Location = new System.Drawing.Point(112, 216); @@ -413,6 +437,15 @@ namespace BitmapFontEd this.m_rotRight.Text = "Right"; this.m_rotRight.Click += new System.EventHandler(this.OnRotateRight); // + // m_autoheight + // + this.m_autoheight.Location = new System.Drawing.Point(8, 48); + this.m_autoheight.Name = "m_autoheight"; + this.m_autoheight.Size = new System.Drawing.Size(96, 24); + this.m_autoheight.TabIndex = 3; + this.m_autoheight.Text = "Auto Height"; + this.m_autoheight.Click += new System.EventHandler(this.OnAutoHeight); + // // m_mirrorVertical // this.m_mirrorVertical.Location = new System.Drawing.Point(112, 88); @@ -459,6 +492,7 @@ namespace BitmapFontEd // // m_adjustGroup // + this.m_adjustGroup.Controls.Add(this.m_autowidth); this.m_adjustGroup.Controls.Add(this.m_grabFont); this.m_adjustGroup.Controls.Add(this.m_edge); this.m_adjustGroup.Controls.Add(this.m_dropShadow); @@ -476,19 +510,21 @@ namespace BitmapFontEd this.m_adjustGroup.Controls.Add(this.label3); this.m_adjustGroup.Controls.Add(this.m_clear); this.m_adjustGroup.Controls.Add(this.m_applyAll); - this.m_adjustGroup.Location = new System.Drawing.Point(424, 64); + this.m_adjustGroup.Location = new System.Drawing.Point(424, 96); this.m_adjustGroup.Name = "m_adjustGroup"; - this.m_adjustGroup.Size = new System.Drawing.Size(216, 384); + this.m_adjustGroup.Size = new System.Drawing.Size(216, 352); this.m_adjustGroup.TabIndex = 3; this.m_adjustGroup.TabStop = false; this.m_adjustGroup.Text = "Adjustments and Effects"; // // m_globaladjustGroup // + this.m_globaladjustGroup.Controls.Add(this.m_autoheight); + this.m_globaladjustGroup.Controls.Add(this.m_topleft); 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.Size = new System.Drawing.Size(216, 80); this.m_globaladjustGroup.TabIndex = 2; this.m_globaladjustGroup.TabStop = false; this.m_globaladjustGroup.Text = "Global Adjustments"; @@ -658,6 +694,7 @@ namespace BitmapFontEd { m_chars.Output(str); m_path=fsel.FileName; + m_save.Enabled=true; str.Close(); } catch (Exception ex) @@ -1020,5 +1057,126 @@ namespace BitmapFontEd } } } + + void OnAlignTopLeft(object sender, System.EventArgs e) + { + int row=Int32.MaxValue; + int col=Int32.MaxValue; + int gap=0; + + if (Util.YesNo("Leave one column gap to left and top?")) + { + gap=1; + } + + foreach (BitmapChar c in m_chars) + { + if (c.FirstUsedColumn!=-1) + { + row=Math.Min(c.FirstUsedRow-gap,row); + } + + if (c.FirstUsedRow!=-1) + { + col=Math.Min(c.FirstUsedColumn-gap,col); + } + } + + if (col==0 && row==0) + { + Util.Message("There is a character already aligned to the top left"); + return; + } + + if (Util.YesNo("Characters will be scrolled up by " + row + " row(s)\n" + + "and left by " + col + " column(s)\n\nContinue?")) + { + FetchEdit(); + + foreach (BitmapChar c in m_chars) + { + c.Scroll(-col,-row); + } + + m_chars.Changed=true; + + m_edit.BitmapChar=new BitmapChar(m_chars[m_selected]); + } + } + + void OnAutoWidth(object sender, System.EventArgs e) + { + int gap=1; + + if (Util.YesNo("Leave one column gap on right?")) + { + gap=2; + } + + FetchEdit(); + + if (m_applyAll.Checked) + { + foreach (BitmapChar c in m_chars) + { + int col=Math.Max(1,Math.Min(GfxEditor.MAX_SIZE,c.LastUsedColumn+gap)); + c.Resize(col,c.Height); + } + } + else + { + int col=Math.Max(1,Math.Min(GfxEditor.MAX_SIZE,m_chars[m_selected].LastUsedColumn+gap)); + m_chars[m_selected].Resize(col,m_chars[m_selected].Height); + } + + m_edit.BitmapChar=new BitmapChar(m_chars[m_selected]); + } + + void OnAutoHeight(object sender, System.EventArgs e) + { + bool each=false; + + switch(Util.YesNoCancel("Set all characters to the same height?")) + { + case DialogResult.Yes: + each=false; + break; + case DialogResult.No: + each=true; + break; + default: + return; + } + + FetchEdit(); + + if (each) + { + foreach (BitmapChar c in m_chars) + { + int row=Math.Max(1,Math.Min(GfxEditor.MAX_SIZE,c.LastUsedRow+1)); + + c.Resize(c.Width,row); + } + } + else + { + int row=1; + + foreach (BitmapChar c in m_chars) + { + row=Math.Max(row,Math.Min(GfxEditor.MAX_SIZE,c.LastUsedRow+1)); + } + + foreach (BitmapChar c in m_chars) + { + c.Resize(c.Width,row); + } + } + + m_chars.Changed=true; + + m_edit.BitmapChar=new BitmapChar(m_chars[m_selected]); + } } } diff --git a/Util.cs b/Util.cs index 4589775..1dce4fd 100644 --- a/Util.cs +++ b/Util.cs @@ -38,6 +38,13 @@ namespace BitmapFontEd MessageBoxIcon.Question)==DialogResult.Yes; } + public static DialogResult YesNoCancel(string s) + { + return MessageBox.Show(s,"Bitmap Font Editor", + MessageBoxButtons.YesNoCancel, + MessageBoxIcon.Question); + } + public static void Message(string s) { MessageBox.Show(s,"Bitmap Font Editor",MessageBoxButtons.OK,MessageBoxIcon.Information); -- cgit v1.2.3