From 5fb32592ed08ca0f45e3bf1dce77c637441f716e Mon Sep 17 00:00:00 2001 From: Ian C Date: Sat, 14 May 2005 21:59:59 +0000 Subject: Initial Checkin --- .cvsignore | 1 + AssemblyInfo.cs | 32 ++ BitmapChar.cs | 257 +++++++++ BitmapFontEd.GfxEditor.resources | Bin 0 -> 8040 bytes BitmapFontEd.MainForm.resources | Bin 0 -> 6234 bytes BitmapFontEd.cmbx | 16 + BitmapFontEd.prjx | 31 ++ CopyMenu.cs | 165 ++++++ GfxEditor.cs | 1077 ++++++++++++++++++++++++++++++++++++++ MainForm.cs | 159 ++++++ 10 files changed, 1738 insertions(+) create mode 100644 .cvsignore create mode 100644 AssemblyInfo.cs create mode 100644 BitmapChar.cs create mode 100644 BitmapFontEd.GfxEditor.resources create mode 100644 BitmapFontEd.MainForm.resources create mode 100644 BitmapFontEd.cmbx create mode 100644 BitmapFontEd.prjx create mode 100644 CopyMenu.cs create mode 100644 GfxEditor.cs create mode 100644 MainForm.cs diff --git a/.cvsignore b/.cvsignore new file mode 100644 index 0000000..c5e82d7 --- /dev/null +++ b/.cvsignore @@ -0,0 +1 @@ +bin \ No newline at end of file diff --git a/AssemblyInfo.cs b/AssemblyInfo.cs new file mode 100644 index 0000000..0e5b82c --- /dev/null +++ b/AssemblyInfo.cs @@ -0,0 +1,32 @@ +using System.Reflection; +using System.Runtime.CompilerServices; + +// Information about this assembly is defined by the following +// attributes. +// +// change them to the information which is associated with the assembly +// you compile. + +[assembly: AssemblyTitle("")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("")] +[assembly: AssemblyCopyright("")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// The assembly version has following format : +// +// Major.Minor.Build.Revision +// +// You can specify all values by your own or you can build default build and revision +// numbers with the '*' character (the default): + +[assembly: AssemblyVersion("1.0.*")] + +// The following attributes specify the key for the sign of your assembly. See the +// .NET Framework documentation for more information about signing. +// This is not required, if you don't want signing let these attributes like they're. +[assembly: AssemblyDelaySign(false)] +[assembly: AssemblyKeyFile("")] diff --git a/BitmapChar.cs b/BitmapChar.cs new file mode 100644 index 0000000..910a4b2 --- /dev/null +++ b/BitmapChar.cs @@ -0,0 +1,257 @@ +// 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.IO; + +namespace BitmapFontEd +{ + /// + /// Description of BitmapChar. + /// + public class BitmapChar + { + public BitmapChar(uint width, uint height) + { + m_width=width; + m_height=height; + m_data=new Color[m_width,m_height]; + } + + public BitmapChar() : this(8,8) + { + } + + public BitmapChar(BitmapChar old) + { + m_width=old.m_width; + m_height=old.m_height; + m_data=new Color[m_width,m_height]; + + for(int x=0;x=0 && nx=0 && ny=0 && nx=0 && ny>8; + } + } + + private static void WriteInt(Stream s, int l) + { + for(uint f=0;f<4;f++) + { + s.WriteByte((byte)(l&0xff)); + l=l>>8; + } + } + } +} diff --git a/BitmapFontEd.GfxEditor.resources b/BitmapFontEd.GfxEditor.resources new file mode 100644 index 0000000..77fb9e2 Binary files /dev/null and b/BitmapFontEd.GfxEditor.resources differ diff --git a/BitmapFontEd.MainForm.resources b/BitmapFontEd.MainForm.resources new file mode 100644 index 0000000..263887f Binary files /dev/null and b/BitmapFontEd.MainForm.resources differ diff --git a/BitmapFontEd.cmbx b/BitmapFontEd.cmbx new file mode 100644 index 0000000..2a46d3a --- /dev/null +++ b/BitmapFontEd.cmbx @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/BitmapFontEd.prjx b/BitmapFontEd.prjx new file mode 100644 index 0000000..92b8bb5 --- /dev/null +++ b/BitmapFontEd.prjx @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/CopyMenu.cs b/CopyMenu.cs new file mode 100644 index 0000000..06cd39b --- /dev/null +++ b/CopyMenu.cs @@ -0,0 +1,165 @@ +// 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.Collections; +using System.Drawing; +using System.Windows.Forms; + +namespace BitmapFontEd +{ + /// + /// Implements the Copy/Paste menu + /// + public class CopyMenu + { + public enum EMode + { + eNothing, + eMark, + ePaste, + ePasteTransparent + }; + + public enum EGravity + { + eTopLeft, + eTopRight, + eBottomLeft, + eBottomRight, + eCentre + }; + + public CopyMenu() + { + m_mode=EMode.eNothing; + m_grav=EGravity.eTopLeft; + + CreateMenus(); + } + + public bool AllowPaste + { + set + { + m_paste.Enabled=value; + m_pasteTrans.Enabled=value; + } + } + + public EMode Mode + { + get {return m_mode;} + set {m_mode=value;} + } + + public EGravity Gravity + { + get {return m_grav;} + } + + public void Show(Control c, int x, int y) + { + m_menu.Show(c, new Point(x,y)); + } + + + // ------------------------------------------------ + // PRIVATE + // + private EMode m_mode; + private EGravity m_grav; + + private Hashtable m_modeMap; + private Hashtable m_gravMap; + + private ContextMenu m_menu; + private MenuItem m_mark; + private MenuItem m_paste; + private MenuItem m_pasteTrans; + private MenuItem m_gravSub; + private MenuItem m_topLeft; + private MenuItem m_topRight; + private MenuItem m_bottomLeft; + private MenuItem m_bottomRight; + private MenuItem m_centre; + + private void CreateMenus() + { + m_menu=new ContextMenu(); + + m_mark=new MenuItem("Mark and Copy", new EventHandler(OnMenu)); + m_paste=new MenuItem("Paste", new EventHandler(OnMenu)); + m_pasteTrans=new MenuItem("Paste Transparent", new EventHandler(OnMenu)); + + m_gravSub=new MenuItem("Paste Gravity"); + + m_topLeft=new MenuItem("Top Left",new EventHandler(OnGravity)); + m_topRight=new MenuItem("Top Right",new EventHandler(OnGravity)); + m_bottomLeft=new MenuItem("Bottom Left",new EventHandler(OnGravity)); + m_bottomRight=new MenuItem("Bottom Right",new EventHandler(OnGravity)); + m_centre=new MenuItem("Centre",new EventHandler(OnGravity)); + + m_gravSub.MenuItems.Add(m_topLeft); + m_gravSub.MenuItems.Add(m_topRight); + m_gravSub.MenuItems.Add(m_bottomLeft); + m_gravSub.MenuItems.Add(m_bottomRight); + m_gravSub.MenuItems.Add(m_centre); + + m_topLeft.Checked=true; + + m_menu.MenuItems.Add(m_mark); + m_menu.MenuItems.Add(m_gravSub); + m_menu.MenuItems.Add(m_paste); + m_menu.MenuItems.Add(m_pasteTrans); + + m_modeMap=new Hashtable(); + m_gravMap=new Hashtable(); + + m_modeMap[m_mark]=EMode.eMark; + m_modeMap[m_paste]=EMode.ePaste; + m_modeMap[m_pasteTrans]=EMode.ePasteTransparent; + + m_gravMap[m_topLeft]=EGravity.eTopLeft; + m_gravMap[m_topRight]=EGravity.eTopRight; + m_gravMap[m_bottomLeft]=EGravity.eBottomLeft; + m_gravMap[m_bottomRight]=EGravity.eBottomRight; + m_gravMap[m_centre]=EGravity.eCentre; + } + + private void OnMenu(object sender, System.EventArgs e) + { + m_mode=(EMode)m_modeMap[sender]; + } + + private void OnGravity(object sender, System.EventArgs e) + { + MenuItem i=(MenuItem)sender; + + m_grav=(EGravity)m_gravMap[sender]; + + foreach (MenuItem m in m_gravSub.MenuItems) + { + m.Checked=false; + } + + i.Checked=true; + } + } +} diff --git a/GfxEditor.cs b/GfxEditor.cs new file mode 100644 index 0000000..d67b19e --- /dev/null +++ b/GfxEditor.cs @@ -0,0 +1,1077 @@ +// 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.ComponentModel; +using System.Windows.Forms; +using System.Drawing; +using System.Drawing.Drawing2D; + +using System.Diagnostics; + +namespace BitmapFontEd +{ + /// + /// Implements a control for drawing + /// + [ToolboxItem(true)] + public class GfxEditor : System.Windows.Forms.UserControl + { + private System.Windows.Forms.Label label3; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.Button m_undoButton; + private System.Windows.Forms.Label label5; + private System.Windows.Forms.Label label4; + private System.Windows.Forms.Label m_fgPreview; + private System.Windows.Forms.NumericUpDown m_sizeX; + private System.Windows.Forms.Label label6; + private System.Windows.Forms.Label m_bgPreview; + private System.Windows.Forms.PictureBox m_edit; + private System.Windows.Forms.NumericUpDown m_sizeY; + private System.Windows.Forms.ComboBox m_modeList; + private System.Windows.Forms.PictureBox m_preview; + + private const uint SIZE=256; + private Color TRANS=Color.Empty; + + // These MUST match the entries in the drop down list + // + private enum Mode + { + ePlot, + eLine, + eRectangle, + eFilledRectangle, + eCircle, + eFilledCircle, + eEllipse, + eFilledEllipse, + eFloodFill, + eCopyPaste + }; + + //private bool m_inEditor; + + private BitmapChar m_char; + private BitmapChar m_undo; + private uint m_width; + private uint m_height; + + private bool m_ignoreSize; + + private Rectangle m_editRect; + private Bitmap m_editBmp; + private Rectangle m_prevRect; + private Bitmap m_prevBmp; + + private uint m_grid; + private uint m_mx; + private uint m_my; + private Color m_gridCol; + + private bool m_drawing; + private Mode m_mode; + private Color[,] m_overlay; + private uint m_ox; + private uint m_oy; + private Color m_pen; + + private CopyMenu m_cpMenu; + private uint m_cpX; + private uint m_cpY; + private uint m_cpWidth; + private uint m_cpHeight; + private Color[,] m_cpBuff; + + public GfxEditor() + { + // + // InitializeComponent() call is required for Windows Forms designer support. + // + InitializeComponent(); + + //m_inEditor=false; + + m_char=null; + m_grid=8; + m_grid=8; + m_mx=SIZE; + 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; + + m_prevRect=m_edit.ClientRectangle; + m_prevBmp=new Bitmap(m_prevRect.Width,m_prevRect.Height); + m_preview.Image=m_prevBmp; + + m_drawing=false; + m_mode=Mode.ePlot; + + if (m_editRect.Width!=SIZE && m_editRect.Height!=SIZE) + { + throw new Exception("GfxEditor built with bad SIZE!"); + } + + m_modeList.SelectedIndex=0; + + m_cpMenu=new CopyMenu(); + } + + #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_preview = new System.Windows.Forms.PictureBox(); + this.m_modeList = new System.Windows.Forms.ComboBox(); + this.m_sizeY = new System.Windows.Forms.NumericUpDown(); + this.m_edit = new System.Windows.Forms.PictureBox(); + this.m_bgPreview = new System.Windows.Forms.Label(); + this.label6 = new System.Windows.Forms.Label(); + this.m_sizeX = new System.Windows.Forms.NumericUpDown(); + this.m_fgPreview = new System.Windows.Forms.Label(); + this.label4 = new System.Windows.Forms.Label(); + this.label5 = new System.Windows.Forms.Label(); + this.m_undoButton = new System.Windows.Forms.Button(); + this.label1 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + this.label3 = new System.Windows.Forms.Label(); + ((System.ComponentModel.ISupportInitialize)(this.m_sizeY)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.m_sizeX)).BeginInit(); + this.SuspendLayout(); + // + // m_preview + // + this.m_preview.BackColor = System.Drawing.SystemColors.Control; + this.m_preview.Location = new System.Drawing.Point(288, 208); + this.m_preview.Name = "m_preview"; + this.m_preview.Size = new System.Drawing.Size(34, 34); + this.m_preview.TabIndex = 1; + this.m_preview.TabStop = false; + // + // m_modeList + // + this.m_modeList.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.m_modeList.Items.AddRange(new object[] { + "Plot", + "Line", + "Rectangle", + "Filled Rect", + "Circle", + "Filled Circle", + "Ellipse", + "Filled Ellipse", + "Flood Fill", + "Copy/Paste"}); + this.m_modeList.Location = new System.Drawing.Point(280, 64); + this.m_modeList.MaxDropDownItems = 16; + this.m_modeList.Name = "m_modeList"; + this.m_modeList.Size = new System.Drawing.Size(104, 21); + this.m_modeList.TabIndex = 15; + this.m_modeList.SelectedIndexChanged += new System.EventHandler(this.OnModeSelect); + // + // m_sizeY + // + this.m_sizeY.CausesValidation = false; + this.m_sizeY.Location = new System.Drawing.Point(336, 24); + this.m_sizeY.Maximum = new System.Decimal(new int[] { + 32, + 0, + 0, + 0}); + this.m_sizeY.Minimum = new System.Decimal(new int[] { + 1, + 0, + 0, + 0}); + this.m_sizeY.Name = "m_sizeY"; + this.m_sizeY.ReadOnly = true; + this.m_sizeY.Size = new System.Drawing.Size(48, 21); + this.m_sizeY.TabIndex = 20; + this.m_sizeY.Value = new System.Decimal(new int[] { + 1, + 0, + 0, + 0}); + this.m_sizeY.ValueChanged += new System.EventHandler(this.OnSize); + this.m_sizeY.Leave += new System.EventHandler(this.OnSize); + // + // m_edit + // + this.m_edit.BackColor = System.Drawing.SystemColors.Control; + this.m_edit.Location = new System.Drawing.Point(8, 8); + this.m_edit.Name = "m_edit"; + this.m_edit.Size = new System.Drawing.Size(256, 256); + this.m_edit.TabIndex = 0; + this.m_edit.TabStop = false; + this.m_edit.MouseEnter += new System.EventHandler(this.OnEnterEditor); + this.m_edit.MouseUp += new System.Windows.Forms.MouseEventHandler(this.OnMouseMove); + this.m_edit.MouseMove += new System.Windows.Forms.MouseEventHandler(this.OnMouseMove); + this.m_edit.MouseLeave += new System.EventHandler(this.OnLeaveEditor); + this.m_edit.MouseDown += new System.Windows.Forms.MouseEventHandler(this.OnMouseMove); + // + // m_bgPreview + // + 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); + // + // label6 + // + this.label6.Location = new System.Drawing.Point(336, 8); + this.label6.Name = "label6"; + this.label6.Size = new System.Drawing.Size(48, 16); + this.label6.TabIndex = 22; + this.label6.Text = "Height"; + this.label6.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; + // + // m_sizeX + // + this.m_sizeX.CausesValidation = false; + this.m_sizeX.Location = new System.Drawing.Point(280, 24); + this.m_sizeX.Maximum = new System.Decimal(new int[] { + 32, + 0, + 0, + 0}); + this.m_sizeX.Minimum = new System.Decimal(new int[] { + 1, + 0, + 0, + 0}); + this.m_sizeX.Name = "m_sizeX"; + this.m_sizeX.ReadOnly = true; + this.m_sizeX.Size = new System.Drawing.Size(48, 21); + this.m_sizeX.TabIndex = 19; + this.m_sizeX.Value = new System.Decimal(new int[] { + 1, + 0, + 0, + 0}); + this.m_sizeX.ValueChanged += new System.EventHandler(this.OnSize); + this.m_sizeX.Leave += new System.EventHandler(this.OnSize); + // + // m_fgPreview + // + this.m_fgPreview.BackColor = System.Drawing.Color.White; + this.m_fgPreview.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.m_fgPreview.Location = new System.Drawing.Point(280, 120); + this.m_fgPreview.Name = "m_fgPreview"; + this.m_fgPreview.Size = new System.Drawing.Size(40, 40); + this.m_fgPreview.TabIndex = 17; + this.m_fgPreview.Click += new System.EventHandler(this.OnForeground); + // + // label4 + // + 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 + // + this.label5.Location = new System.Drawing.Point(336, 96); + this.label5.Name = "label5"; + this.label5.Size = new System.Drawing.Size(40, 16); + this.label5.TabIndex = 12; + this.label5.Text = "Right"; + this.label5.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; + // + // m_undoButton + // + this.m_undoButton.Location = new System.Drawing.Point(8, 272); + this.m_undoButton.Name = "m_undoButton"; + this.m_undoButton.Size = new System.Drawing.Size(72, 24); + this.m_undoButton.TabIndex = 16; + this.m_undoButton.Text = "Undo"; + this.m_undoButton.Click += new System.EventHandler(this.OnUndo); + // + // label1 + // + this.label1.Location = new System.Drawing.Point(280, 48); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(64, 16); + this.label1.TabIndex = 3; + this.label1.Text = "Draw Mode"; + this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; + // + // 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; + // + // 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; + // + // GfxEditor + // + this.Controls.Add(this.label6); + this.Controls.Add(this.label2); + this.Controls.Add(this.m_sizeY); + this.Controls.Add(this.m_sizeX); + this.Controls.Add(this.m_bgPreview); + this.Controls.Add(this.m_fgPreview); + this.Controls.Add(this.m_undoButton); + this.Controls.Add(this.m_modeList); + this.Controls.Add(this.label5); + this.Controls.Add(this.label4); + this.Controls.Add(this.label3); + this.Controls.Add(this.label1); + this.Controls.Add(this.m_preview); + this.Controls.Add(this.m_edit); + this.Name = "GfxEditor"; + this.Size = new System.Drawing.Size(392, 304); + ((System.ComponentModel.ISupportInitialize)(this.m_sizeY)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.m_sizeX)).EndInit(); + this.ResumeLayout(false); + } + #endregion + + // ------------------------------------------------------- + // PUBLIC INTERFACES + // ------------------------------------------------------- + #region Public Interfaces + + public Color GridColour + { + set {m_gridCol=value;} + } + + public Size CharSize + { + get {return new Size((int)m_width,(int)m_height);} + } + + public BitmapChar BitmapChar + { + get {return m_char;} + set + { + m_char=value; + m_ignoreSize=true; + m_sizeX.Value=Convert.ToDecimal(m_char.Width); + m_sizeY.Value=Convert.ToDecimal(m_char.Height); + m_ignoreSize=false; + InitialiseOverlay(); + DrawChar(); + } + } + + #endregion + + // ------------------------------------------------------- + // SPRITE/GENERAL DRAWING + // ------------------------------------------------------- + #region Sprite/General Drawing + + private void Flush(ref Graphics g) + { + g.Flush(FlushIntention.Flush); + g.Dispose(); + g=null; + } + + private void DrawGrid() + { + Graphics g=Graphics.FromImage(m_editBmp); + 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); + + for(int x=0;xc2) + { + uint t=c2; + c2=c1; + c1=t; + } + } + + private void SafePlot(int x, int y, Color col) + { + if (x>=0 && x=0 && ydx) + { + ymode=true; + d=dx*2-dy; + incrE=dx*2; + incrNE=(dx-dy)*2; + } + else + { + ymode=false; + d=dy*2-dx; + incrE=dy*2; + incrNE=(dy-dx)*2; + } + + int x=x1; + int y=y1; + + SafePlot(x,y,col); + + if (ymode) + { + while(y!=y2) + { + if (d<=0) + { + d+=incrE; + y+=iy; + } + else + { + d+=incrNE; + y+=iy; + x+=ix; + } + + SafePlot(x,y,col); + } + } + else + { + while(x!=x2) + { + if (d<=0) + { + d+=incrE; + x+=ix; + } + else + { + d+=incrNE; + y+=iy; + x+=ix; + } + + SafePlot(x,y,col); + } + } + } + + private void DrawRect(uint x1, uint y1, + uint x2, uint y2, + Color col, bool fill) + { + RankCoord(ref x1, ref x2); + RankCoord(ref y1, ref y2); + + if (fill) + { + for(uint x=x1;x<=x2;x++) + for(uint y=y1;y<=y2;y++) + m_overlay[x,y]=col; + } + else + { + for(uint x=x1;x<=x2;x++) + { + m_overlay[x,y1]=col; + m_overlay[x,y2]=col; + } + + for(uint y=y1;y<=y2;y++) + { + m_overlay[x1,y]=col; + m_overlay[x2,y]=col; + } + } + } + + private void DrawEllipse(uint originx, uint originy, + uint radpointx, uint radpointy, + Color col, bool circle, bool fill) + { + int ox=(int)originx; + int oy=(int)originy; + double rx=Math.Abs(ox-(int)radpointx)+1; + double ry=Math.Abs(oy-(int)radpointy)+1; + + if (circle) + { + rx=Math.Max(rx,ry); + ry=rx; + } + + for(double a=0;a<=Math.PI;a+=Math.PI/180) + { + int x=(int)(Math.Sin(a)*rx); + int y=(int)(Math.Cos(a)*ry); + + if (fill) + { + for(int f=-x;f<=x;f++) + SafePlot(ox+f,oy+y,col); + } + else + { + SafePlot(ox+x,oy+y,col); + SafePlot(ox-x,oy+y,col); + } + } + } + + private void FloodFill(uint x, uint y, Color col, Color bg) + { + if (m_overlay[x,y]==col || m_overlay[x,y]!=bg) + { + return; + } + + m_overlay[x,y]=col; + + if (x>0) + FloodFill(x-1,y,col,bg); + + if (y>0) + FloodFill(x,y-1,col,bg); + + if (x=m_mx || e.Y<0 || e.Y>=m_my) + { + return; + } + + uint x; + uint y; + + x=(uint)e.X/m_grid; + y=(uint)e.Y/m_grid; + + if (x>=m_char.Width || y>=m_char.Height) + { + return; + } + + if (e.Button==MouseButtons.None) + { + switch(m_mode) + { + case Mode.eFloodFill: + if (m_drawing) + { + OverlayFromSprite(); + FloodFill(m_ox,m_oy,m_pen,m_char[m_ox,m_oy]); + m_drawing=false; + m_undo=new BitmapChar(m_char); + ApplyOverlay(); + DrawChar(); + } + break; + + case Mode.eCopyPaste: + switch(m_cpMenu.Mode) + { + case CopyMenu.EMode.eMark: + if (m_drawing) + { + ClearOverlay(); + Copy(m_ox,m_oy,x,y); + DrawChar(); + m_drawing=false; + } + break; + + case CopyMenu.EMode.ePaste: + ClearOverlay(); + Paste((int)x,(int)y,false); + DrawChar(); + break; + + case CopyMenu.EMode.ePasteTransparent: + ClearOverlay(); + Paste((int)x,(int)y,true); + DrawChar(); + break; + + default: + break; + } + break; + + default: + if (m_drawing) + { + m_drawing=false; + m_undo=new BitmapChar(m_char); + ApplyOverlay(); + DrawChar(); + } + break; + } + + return; + } + + if (!m_drawing) + { + m_ox=x; + m_oy=y; + m_drawing=true; + + if (e.Button==MouseButtons.Left) + { + m_pen=m_fgPreview.BackColor; + } + else + { + m_pen=m_bgPreview.BackColor; + } + } + + switch(m_mode) + { + case Mode.ePlot: + m_overlay[x,y]=m_pen; + DrawChar(); + break; + + case Mode.eLine: + ClearOverlay(); + DrawLine(m_ox,m_oy,x,y,m_pen); + DrawChar(); + break; + + case Mode.eRectangle: + ClearOverlay(); + DrawRect(m_ox,m_oy,x,y,m_pen,false); + DrawChar(); + break; + + case Mode.eFilledRectangle: + ClearOverlay(); + DrawRect(m_ox,m_oy,x,y,m_pen,true); + DrawChar(); + break; + + case Mode.eCircle: + ClearOverlay(); + DrawEllipse(m_ox,m_oy,x,y,m_pen,true,false); + DrawChar(); + break; + + case Mode.eFilledCircle: + ClearOverlay(); + DrawEllipse(m_ox,m_oy,x,y,m_pen,true,true); + DrawChar(); + break; + + case Mode.eEllipse: + ClearOverlay(); + DrawEllipse(m_ox,m_oy,x,y,m_pen,false,false); + DrawChar(); + break; + + case Mode.eFilledEllipse: + ClearOverlay(); + DrawEllipse(m_ox,m_oy,x,y,m_pen,false,true); + DrawChar(); + break; + + case Mode.eFloodFill: + break; + + case Mode.eCopyPaste: + if (e.Button==MouseButtons.Right) + { + m_cpMenu.AllowPaste=(m_cpBuff!=null); + m_cpMenu.Show(m_edit,e.X,e.Y); + } + else + { + switch(m_cpMenu.Mode) + { + case CopyMenu.EMode.eMark: + ClearOverlay(); + DrawMarkBox(m_ox,m_oy,x,y); + DrawChar(); + break; + + case CopyMenu.EMode.ePaste: + case CopyMenu.EMode.ePasteTransparent: + m_undo=new BitmapChar(m_char); + ApplyOverlay(); + DrawChar(); + m_drawing=false; + m_cpMenu.Mode=CopyMenu.EMode.eNothing; + break; + + default: + break; + } + } + break; + } + } + + void OnForeground(object sender, System.EventArgs e) + { + ColorDialog d=new ColorDialog(); + + d.Color=m_fgPreview.BackColor; + + if (d.ShowDialog()==DialogResult.OK) + { + m_fgPreview.BackColor=d.Color; + } + } + + void OnBackground(object sender, System.EventArgs e) + { + ColorDialog d=new ColorDialog(); + + d.Color=m_bgPreview.BackColor; + + if (d.ShowDialog()==DialogResult.OK) + { + m_bgPreview.BackColor=d.Color; + } + } + + #endregion + + } +} diff --git a/MainForm.cs b/MainForm.cs new file mode 100644 index 0000000..731bf2a --- /dev/null +++ b/MainForm.cs @@ -0,0 +1,159 @@ +// 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; + +namespace BitmapFontEd +{ + /// + /// Description of MainForm. + /// + public class MainForm : System.Windows.Forms.Form + { + private System.Windows.Forms.MenuItem menuItem6; + private System.Windows.Forms.MenuItem m_quit; + private System.Windows.Forms.MenuItem m_saveAs; + private System.Windows.Forms.MenuItem m_save; + private System.Windows.Forms.MainMenu m_menu; + private System.Windows.Forms.MenuItem m_fileMenu; + private System.Windows.Forms.GroupBox m_editGroup; + private System.Windows.Forms.MenuItem m_open; + private System.Windows.Forms.MenuItem m_new; + + private GfxEditor m_edit; + + 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_edit.BitmapChar=new BitmapChar(); + } + + [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_new = new System.Windows.Forms.MenuItem(); + this.m_open = new System.Windows.Forms.MenuItem(); + this.m_editGroup = new System.Windows.Forms.GroupBox(); + this.m_fileMenu = new System.Windows.Forms.MenuItem(); + this.m_menu = new System.Windows.Forms.MainMenu(); + this.m_save = new System.Windows.Forms.MenuItem(); + this.m_saveAs = new System.Windows.Forms.MenuItem(); + this.m_quit = new System.Windows.Forms.MenuItem(); + this.menuItem6 = new System.Windows.Forms.MenuItem(); + this.SuspendLayout(); + // + // m_new + // + this.m_new.Index = 0; + this.m_new.Shortcut = System.Windows.Forms.Shortcut.CtrlN; + this.m_new.Text = "&New"; + // + // m_open + // + this.m_open.Index = 1; + this.m_open.Shortcut = System.Windows.Forms.Shortcut.CtrlO; + this.m_open.Text = "&Open"; + // + // 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_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_menu + // + this.m_menu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { + this.m_fileMenu}); + // + // m_save + // + this.m_save.Index = 2; + this.m_save.Shortcut = System.Windows.Forms.Shortcut.CtrlS; + this.m_save.Text = "&Save"; + // + // m_saveAs + // + this.m_saveAs.Index = 3; + this.m_saveAs.Shortcut = System.Windows.Forms.Shortcut.F12; + this.m_saveAs.Text = "S&ave as..."; + // + // m_quit + // + this.m_quit.Index = 5; + this.m_quit.Shortcut = System.Windows.Forms.Shortcut.CtrlQ; + this.m_quit.Text = "&Quit"; + // + // menuItem6 + // + this.menuItem6.Index = 4; + this.menuItem6.Text = "-"; + // + // MainForm + // + this.AutoScaleBaseSize = new System.Drawing.Size(5, 14); + this.ClientSize = new System.Drawing.Size(642, 479); + 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.ResumeLayout(false); + } + #endregion + } +} -- cgit v1.2.3