summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan C <ianc@noddybox.co.uk>2005-07-30 01:55:41 +0000
committerIan C <ianc@noddybox.co.uk>2005-07-30 01:55:41 +0000
commit93ac9c657ce285c5daa5a3ea6ed8c91b50e0281c (patch)
tree40524242c2f73c6b922e2152f63b233f02545852
parentbe2ad76237e13937a37a4a9c419300bba563712c (diff)
Development checkin
-rw-r--r--.cvsignore1
-rw-r--r--AlphaColourDialog.cs508
-rw-r--r--AssemblyInfo.cs32
-rw-r--r--BitmapSpriteEd.GfxEditor.resourcesbin0 -> 14416 bytes
-rw-r--r--BitmapSpriteEd.MainForm.resourcesbin0 -> 12638 bytes
-rw-r--r--BitmapSpriteEd.cmbx16
-rw-r--r--BitmapSpriteEd.prjx32
-rw-r--r--CopyMenu.cs165
-rw-r--r--GfxEditor.cs1398
-rw-r--r--MainForm.cs456
-rw-r--r--Sprite.cs546
-rw-r--r--Util.cs122
12 files changed, 3276 insertions, 0 deletions
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/AlphaColourDialog.cs b/AlphaColourDialog.cs
new file mode 100644
index 0000000..cab8438
--- /dev/null
+++ b/AlphaColourDialog.cs
@@ -0,0 +1,508 @@
+// BitmapSpriteEd - Bitmap Sprite Editor
+// 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 BitmapSpriteEd
+{
+ /// <summary>
+ /// Description of AlphaColourDialog.
+ /// </summary>
+ public class AlphaColourDialog : System.Windows.Forms.Form
+ {
+ private System.Windows.Forms.Label m_common7;
+ private System.Windows.Forms.Label m_common4;
+ private System.Windows.Forms.Label m_common5;
+ private System.Windows.Forms.Label m_common3;
+ private System.Windows.Forms.TextBox m_red;
+ private System.Windows.Forms.TrackBar m_greenSlider;
+ private System.Windows.Forms.TextBox m_alpha;
+ private System.Windows.Forms.Label m_preview;
+ private System.Windows.Forms.ComboBox m_named;
+ private System.Windows.Forms.TrackBar m_redSlider;
+ private System.Windows.Forms.TrackBar m_alphaSlider;
+ private System.Windows.Forms.Label label1;
+ private System.Windows.Forms.TextBox m_green;
+ private System.Windows.Forms.TrackBar m_blueSlider;
+ private System.Windows.Forms.Label label3;
+ private System.Windows.Forms.Label label2;
+ private System.Windows.Forms.TextBox m_blue;
+ private System.Windows.Forms.Label m_common8;
+ private System.Windows.Forms.Label label6;
+ private System.Windows.Forms.Label label5;
+ private System.Windows.Forms.Label label4;
+ private System.Windows.Forms.Label m_common2;
+ private System.Windows.Forms.Button m_ok;
+ private System.Windows.Forms.Button m_cancel;
+ private System.Windows.Forms.Label m_common1;
+ private System.Windows.Forms.Label m_common6;
+
+ private bool m_allowAlpha;
+
+ public AlphaColourDialog(string title)
+ {
+ //
+ // The InitializeComponent() call is required for Windows Forms designer support.
+ //
+ InitializeComponent();
+
+ Text=title;
+
+ foreach (KnownColor col in Enum.GetValues(typeof(KnownColor)))
+ {
+ if (Color.FromKnownColor(col).A==255)
+ {
+ m_named.Items.Add(col.ToString());
+ }
+ }
+
+ m_allowAlpha=true;
+ }
+
+ public Color Color
+ {
+ get
+ {
+ return m_preview.BackColor;
+ }
+ set
+ {
+ m_redSlider.Value=value.R;
+ m_greenSlider.Value=value.G;
+ m_blueSlider.Value=value.B;
+
+ if (m_allowAlpha)
+ {
+ m_alphaSlider.Value=value.A;
+ }
+ else
+ {
+ m_alphaSlider.Value=255;
+ }
+
+ SetColour();
+ }
+ }
+
+ public bool AllowAlpha
+ {
+ set
+ {
+ m_allowAlpha=value;
+ m_alphaSlider.Visible=false;
+ }
+ }
+
+ private void SetColour()
+ {
+ m_red.Text=m_redSlider.Value.ToString();
+ m_green.Text=m_greenSlider.Value.ToString();
+ m_blue.Text=m_blueSlider.Value.ToString();
+ m_alpha.Text=m_alphaSlider.Value.ToString();
+
+ m_preview.BackColor=Color.FromArgb(m_alphaSlider.Value,
+ m_redSlider.Value,
+ m_greenSlider.Value,
+ m_blueSlider.Value);
+ }
+
+ #region Windows Forms Designer generated code
+ /// <summary>
+ /// 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.
+ /// </summary>
+ private void InitializeComponent() {
+ this.m_common6 = new System.Windows.Forms.Label();
+ this.m_common1 = new System.Windows.Forms.Label();
+ this.m_cancel = new System.Windows.Forms.Button();
+ this.m_ok = new System.Windows.Forms.Button();
+ this.m_common2 = 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_common8 = new System.Windows.Forms.Label();
+ this.m_blue = new System.Windows.Forms.TextBox();
+ this.label2 = new System.Windows.Forms.Label();
+ this.label3 = new System.Windows.Forms.Label();
+ this.m_blueSlider = new System.Windows.Forms.TrackBar();
+ this.m_green = new System.Windows.Forms.TextBox();
+ this.label1 = new System.Windows.Forms.Label();
+ this.m_alphaSlider = new System.Windows.Forms.TrackBar();
+ this.m_redSlider = new System.Windows.Forms.TrackBar();
+ this.m_named = new System.Windows.Forms.ComboBox();
+ this.m_preview = new System.Windows.Forms.Label();
+ this.m_alpha = new System.Windows.Forms.TextBox();
+ this.m_greenSlider = new System.Windows.Forms.TrackBar();
+ this.m_red = new System.Windows.Forms.TextBox();
+ this.m_common3 = new System.Windows.Forms.Label();
+ this.m_common5 = new System.Windows.Forms.Label();
+ this.m_common4 = new System.Windows.Forms.Label();
+ this.m_common7 = new System.Windows.Forms.Label();
+ ((System.ComponentModel.ISupportInitialize)(this.m_blueSlider)).BeginInit();
+ ((System.ComponentModel.ISupportInitialize)(this.m_alphaSlider)).BeginInit();
+ ((System.ComponentModel.ISupportInitialize)(this.m_redSlider)).BeginInit();
+ ((System.ComponentModel.ISupportInitialize)(this.m_greenSlider)).BeginInit();
+ this.SuspendLayout();
+ //
+ // m_common6
+ //
+ this.m_common6.BackColor = System.Drawing.Color.Yellow;
+ this.m_common6.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
+ this.m_common6.Location = new System.Drawing.Point(56, 240);
+ this.m_common6.Name = "m_common6";
+ this.m_common6.Size = new System.Drawing.Size(24, 24);
+ this.m_common6.TabIndex = 21;
+ this.m_common6.Click += new System.EventHandler(this.OnCommon);
+ //
+ // m_common1
+ //
+ this.m_common1.BackColor = System.Drawing.Color.Black;
+ this.m_common1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
+ this.m_common1.Location = new System.Drawing.Point(16, 208);
+ this.m_common1.Name = "m_common1";
+ this.m_common1.Size = new System.Drawing.Size(24, 24);
+ this.m_common1.TabIndex = 16;
+ this.m_common1.Click += new System.EventHandler(this.OnCommon);
+ //
+ // m_cancel
+ //
+ this.m_cancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
+ this.m_cancel.Location = new System.Drawing.Point(296, 328);
+ this.m_cancel.Name = "m_cancel";
+ this.m_cancel.Size = new System.Drawing.Size(104, 24);
+ this.m_cancel.TabIndex = 13;
+ this.m_cancel.Text = "Cancel";
+ //
+ // m_ok
+ //
+ this.m_ok.Location = new System.Drawing.Point(184, 328);
+ this.m_ok.Name = "m_ok";
+ this.m_ok.Size = new System.Drawing.Size(104, 24);
+ this.m_ok.TabIndex = 12;
+ this.m_ok.Text = "OK";
+ this.m_ok.Click += new System.EventHandler(this.OnOK);
+ //
+ // m_common2
+ //
+ this.m_common2.BackColor = System.Drawing.Color.White;
+ this.m_common2.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
+ this.m_common2.Location = new System.Drawing.Point(56, 208);
+ this.m_common2.Name = "m_common2";
+ this.m_common2.Size = new System.Drawing.Size(24, 24);
+ this.m_common2.TabIndex = 17;
+ this.m_common2.Click += new System.EventHandler(this.OnCommon);
+ //
+ // label4
+ //
+ this.label4.Location = new System.Drawing.Point(352, 0);
+ this.label4.Name = "label4";
+ this.label4.Size = new System.Drawing.Size(56, 24);
+ this.label4.TabIndex = 7;
+ this.label4.Text = "Alpha";
+ this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
+ //
+ // label5
+ //
+ this.label5.Location = new System.Drawing.Point(8, 192);
+ this.label5.Name = "label5";
+ this.label5.Size = new System.Drawing.Size(128, 16);
+ this.label5.TabIndex = 15;
+ this.label5.Text = "Primary Colours:";
+ //
+ // label6
+ //
+ this.label6.Location = new System.Drawing.Point(8, 280);
+ this.label6.Name = "label6";
+ this.label6.Size = new System.Drawing.Size(128, 16);
+ this.label6.TabIndex = 24;
+ this.label6.Text = "Named Colours:";
+ //
+ // m_common8
+ //
+ this.m_common8.BackColor = System.Drawing.Color.Cyan;
+ this.m_common8.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
+ this.m_common8.Location = new System.Drawing.Point(136, 240);
+ this.m_common8.Name = "m_common8";
+ this.m_common8.Size = new System.Drawing.Size(24, 24);
+ this.m_common8.TabIndex = 23;
+ this.m_common8.Click += new System.EventHandler(this.OnCommon);
+ //
+ // m_blue
+ //
+ this.m_blue.Location = new System.Drawing.Point(304, 296);
+ this.m_blue.MaxLength = 3;
+ this.m_blue.Name = "m_blue";
+ this.m_blue.ReadOnly = true;
+ this.m_blue.Size = new System.Drawing.Size(40, 20);
+ this.m_blue.TabIndex = 10;
+ this.m_blue.Text = "textBox1";
+ //
+ // label2
+ //
+ this.label2.Location = new System.Drawing.Point(240, 0);
+ this.label2.Name = "label2";
+ this.label2.Size = new System.Drawing.Size(56, 24);
+ this.label2.TabIndex = 3;
+ this.label2.Text = "Green";
+ this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
+ //
+ // label3
+ //
+ this.label3.Location = new System.Drawing.Point(296, 0);
+ this.label3.Name = "label3";
+ this.label3.Size = new System.Drawing.Size(56, 24);
+ this.label3.TabIndex = 5;
+ this.label3.Text = "Blue";
+ this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
+ //
+ // m_blueSlider
+ //
+ this.m_blueSlider.Location = new System.Drawing.Point(304, 24);
+ this.m_blueSlider.Maximum = 255;
+ this.m_blueSlider.Name = "m_blueSlider";
+ this.m_blueSlider.Orientation = System.Windows.Forms.Orientation.Vertical;
+ this.m_blueSlider.Size = new System.Drawing.Size(42, 264);
+ this.m_blueSlider.TabIndex = 4;
+ this.m_blueSlider.TickFrequency = 5;
+ this.m_blueSlider.Scroll += new System.EventHandler(this.OnBlue);
+ //
+ // m_green
+ //
+ this.m_green.Location = new System.Drawing.Point(248, 296);
+ this.m_green.MaxLength = 3;
+ this.m_green.Name = "m_green";
+ this.m_green.ReadOnly = true;
+ this.m_green.Size = new System.Drawing.Size(40, 20);
+ this.m_green.TabIndex = 9;
+ this.m_green.Text = "textBox1";
+ //
+ // label1
+ //
+ this.label1.Location = new System.Drawing.Point(184, 0);
+ this.label1.Name = "label1";
+ this.label1.Size = new System.Drawing.Size(56, 24);
+ this.label1.TabIndex = 1;
+ this.label1.Text = "Red";
+ this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
+ //
+ // m_alphaSlider
+ //
+ this.m_alphaSlider.Location = new System.Drawing.Point(360, 24);
+ this.m_alphaSlider.Maximum = 255;
+ this.m_alphaSlider.Name = "m_alphaSlider";
+ this.m_alphaSlider.Orientation = System.Windows.Forms.Orientation.Vertical;
+ this.m_alphaSlider.Size = new System.Drawing.Size(42, 264);
+ this.m_alphaSlider.TabIndex = 6;
+ this.m_alphaSlider.TickFrequency = 5;
+ this.m_alphaSlider.Value = 255;
+ this.m_alphaSlider.Scroll += new System.EventHandler(this.OnAlpha);
+ //
+ // m_redSlider
+ //
+ this.m_redSlider.Location = new System.Drawing.Point(192, 24);
+ this.m_redSlider.Maximum = 255;
+ this.m_redSlider.Name = "m_redSlider";
+ this.m_redSlider.Orientation = System.Windows.Forms.Orientation.Vertical;
+ this.m_redSlider.Size = new System.Drawing.Size(42, 264);
+ this.m_redSlider.TabIndex = 0;
+ this.m_redSlider.TickFrequency = 5;
+ this.m_redSlider.Scroll += new System.EventHandler(this.OnRed);
+ //
+ // m_named
+ //
+ this.m_named.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
+ this.m_named.Location = new System.Drawing.Point(8, 296);
+ this.m_named.MaxDropDownItems = 20;
+ this.m_named.Name = "m_named";
+ this.m_named.Size = new System.Drawing.Size(168, 21);
+ this.m_named.Sorted = true;
+ this.m_named.TabIndex = 25;
+ this.m_named.SelectedIndexChanged += new System.EventHandler(this.OnNamedColour);
+ //
+ // m_preview
+ //
+ this.m_preview.BackColor = System.Drawing.Color.Black;
+ this.m_preview.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
+ this.m_preview.Location = new System.Drawing.Point(8, 8);
+ this.m_preview.Name = "m_preview";
+ this.m_preview.Size = new System.Drawing.Size(168, 168);
+ this.m_preview.TabIndex = 14;
+ //
+ // m_alpha
+ //
+ this.m_alpha.Location = new System.Drawing.Point(360, 296);
+ this.m_alpha.MaxLength = 3;
+ this.m_alpha.Name = "m_alpha";
+ this.m_alpha.ReadOnly = true;
+ this.m_alpha.Size = new System.Drawing.Size(40, 20);
+ this.m_alpha.TabIndex = 11;
+ this.m_alpha.Text = "textBox1";
+ //
+ // m_greenSlider
+ //
+ this.m_greenSlider.Location = new System.Drawing.Point(248, 24);
+ this.m_greenSlider.Maximum = 255;
+ this.m_greenSlider.Name = "m_greenSlider";
+ this.m_greenSlider.Orientation = System.Windows.Forms.Orientation.Vertical;
+ this.m_greenSlider.Size = new System.Drawing.Size(42, 264);
+ this.m_greenSlider.TabIndex = 2;
+ this.m_greenSlider.TickFrequency = 5;
+ this.m_greenSlider.Scroll += new System.EventHandler(this.OnGreen);
+ //
+ // m_red
+ //
+ this.m_red.Location = new System.Drawing.Point(192, 296);
+ this.m_red.MaxLength = 3;
+ this.m_red.Name = "m_red";
+ this.m_red.ReadOnly = true;
+ this.m_red.Size = new System.Drawing.Size(40, 20);
+ this.m_red.TabIndex = 8;
+ this.m_red.Text = "textBox1";
+ //
+ // m_common3
+ //
+ this.m_common3.BackColor = System.Drawing.Color.Red;
+ this.m_common3.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
+ this.m_common3.Location = new System.Drawing.Point(96, 208);
+ this.m_common3.Name = "m_common3";
+ this.m_common3.Size = new System.Drawing.Size(24, 24);
+ this.m_common3.TabIndex = 18;
+ this.m_common3.Click += new System.EventHandler(this.OnCommon);
+ //
+ // m_common5
+ //
+ this.m_common5.BackColor = System.Drawing.Color.Blue;
+ this.m_common5.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
+ this.m_common5.Location = new System.Drawing.Point(16, 240);
+ this.m_common5.Name = "m_common5";
+ this.m_common5.Size = new System.Drawing.Size(24, 24);
+ this.m_common5.TabIndex = 20;
+ this.m_common5.Click += new System.EventHandler(this.OnCommon);
+ //
+ // m_common4
+ //
+ this.m_common4.BackColor = System.Drawing.Color.Lime;
+ this.m_common4.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
+ this.m_common4.Location = new System.Drawing.Point(136, 208);
+ this.m_common4.Name = "m_common4";
+ this.m_common4.Size = new System.Drawing.Size(24, 24);
+ this.m_common4.TabIndex = 19;
+ this.m_common4.Click += new System.EventHandler(this.OnCommon);
+ //
+ // m_common7
+ //
+ this.m_common7.BackColor = System.Drawing.Color.Fuchsia;
+ this.m_common7.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
+ this.m_common7.Location = new System.Drawing.Point(96, 240);
+ this.m_common7.Name = "m_common7";
+ this.m_common7.Size = new System.Drawing.Size(24, 24);
+ this.m_common7.TabIndex = 22;
+ this.m_common7.Click += new System.EventHandler(this.OnCommon);
+ //
+ // AlphaColourDialog
+ //
+ this.AcceptButton = this.m_ok;
+ this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
+ this.CancelButton = this.m_cancel;
+ this.ClientSize = new System.Drawing.Size(410, 362);
+ this.Controls.Add(this.m_named);
+ this.Controls.Add(this.label6);
+ this.Controls.Add(this.m_common8);
+ this.Controls.Add(this.m_common7);
+ this.Controls.Add(this.m_common6);
+ this.Controls.Add(this.m_common5);
+ this.Controls.Add(this.m_common4);
+ this.Controls.Add(this.m_common3);
+ this.Controls.Add(this.m_common2);
+ this.Controls.Add(this.m_common1);
+ this.Controls.Add(this.label5);
+ this.Controls.Add(this.m_preview);
+ this.Controls.Add(this.m_cancel);
+ this.Controls.Add(this.m_ok);
+ this.Controls.Add(this.m_alpha);
+ this.Controls.Add(this.m_blue);
+ this.Controls.Add(this.m_green);
+ this.Controls.Add(this.m_red);
+ this.Controls.Add(this.label4);
+ this.Controls.Add(this.m_alphaSlider);
+ this.Controls.Add(this.label3);
+ this.Controls.Add(this.m_blueSlider);
+ this.Controls.Add(this.label2);
+ this.Controls.Add(this.m_greenSlider);
+ this.Controls.Add(this.label1);
+ this.Controls.Add(this.m_redSlider);
+ this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
+ this.Name = "AlphaColourDialog";
+ this.ShowInTaskbar = false;
+ this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
+ this.Text = "AlphaColourDialog";
+ ((System.ComponentModel.ISupportInitialize)(this.m_blueSlider)).EndInit();
+ ((System.ComponentModel.ISupportInitialize)(this.m_alphaSlider)).EndInit();
+ ((System.ComponentModel.ISupportInitialize)(this.m_redSlider)).EndInit();
+ ((System.ComponentModel.ISupportInitialize)(this.m_greenSlider)).EndInit();
+ this.ResumeLayout(false);
+ }
+ #endregion
+
+ void OnRed(object sender, System.EventArgs e)
+ {
+ SetColour();
+ }
+
+ void OnGreen(object sender, System.EventArgs e)
+ {
+ SetColour();
+ }
+
+ void OnBlue(object sender, System.EventArgs e)
+ {
+ SetColour();
+ }
+
+ void OnAlpha(object sender, System.EventArgs e)
+ {
+ SetColour();
+ }
+
+ void OnOK(object sender, System.EventArgs e)
+ {
+ DialogResult=DialogResult.OK;
+ Close();
+ }
+
+ void OnCommon(object sender, System.EventArgs e)
+ {
+ Label l=(Label)sender;
+
+ Color=l.BackColor;
+ }
+
+ void OnNamedColour(object sender, System.EventArgs e)
+ {
+ string s=(string)m_named.SelectedItem;
+
+ Color=Color.FromKnownColor((KnownColor)Enum.Parse(typeof(KnownColor),s));
+ }
+
+ }
+}
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/BitmapSpriteEd.GfxEditor.resources b/BitmapSpriteEd.GfxEditor.resources
new file mode 100644
index 0000000..32fce11
--- /dev/null
+++ b/BitmapSpriteEd.GfxEditor.resources
Binary files differ
diff --git a/BitmapSpriteEd.MainForm.resources b/BitmapSpriteEd.MainForm.resources
new file mode 100644
index 0000000..19aa4b4
--- /dev/null
+++ b/BitmapSpriteEd.MainForm.resources
Binary files differ
diff --git a/BitmapSpriteEd.cmbx b/BitmapSpriteEd.cmbx
new file mode 100644
index 0000000..2466e19
--- /dev/null
+++ b/BitmapSpriteEd.cmbx
@@ -0,0 +1,16 @@
+<Combine fileversion="1.0" name="BitmapSpriteEd" description="">
+ <StartMode startupentry="BitmapSpriteEd" single="True">
+ <Execute entry="BitmapSpriteEd" type="None" />
+ </StartMode>
+ <Entries>
+ <Entry filename=".\BitmapSpriteEd.prjx" />
+ </Entries>
+ <Configurations active="Debug">
+ <Configuration name="Release">
+ <Entry name="BitmapSpriteEd" configurationname="Debug" build="False" />
+ </Configuration>
+ <Configuration name="Debug">
+ <Entry name="BitmapSpriteEd" configurationname="Debug" build="False" />
+ </Configuration>
+ </Configurations>
+</Combine> \ No newline at end of file
diff --git a/BitmapSpriteEd.prjx b/BitmapSpriteEd.prjx
new file mode 100644
index 0000000..d4db08c
--- /dev/null
+++ b/BitmapSpriteEd.prjx
@@ -0,0 +1,32 @@
+<Project name="BitmapSpriteEd" standardNamespace="BitmapSpriteEd" description="" newfilesearch="None" enableviewstate="True" version="1.1" projecttype="C#">
+ <Contents>
+ <File name=".\MainForm.cs" subtype="Code" buildaction="Compile" dependson="" data="" />
+ <File name=".\AssemblyInfo.cs" subtype="Code" buildaction="Compile" dependson="" data="" />
+ <File name=".\BitmapSpriteEd.MainForm.resources" subtype="Code" buildaction="EmbedAsResource" dependson="" data="" />
+ <File name=".\Util.cs" subtype="Code" buildaction="Compile" dependson="" data="" />
+ <File name=".\Sprite.cs" subtype="Code" buildaction="Compile" dependson="" data="" />
+ <File name=".\CopyMenu.cs" subtype="Code" buildaction="Compile" dependson="" data="" />
+ <File name=".\GfxEditor.cs" subtype="Code" buildaction="Compile" dependson="" data="" />
+ <File name=".\AlphaColourDialog.cs" subtype="Code" buildaction="Compile" dependson="" data="" />
+ <File name=".\BitmapSpriteEd.GfxEditor.resources" subtype="Code" buildaction="EmbedAsResource" dependson="" data="" />
+ </Contents>
+ <References />
+ <DeploymentInformation target="" script="" strategy="File" />
+ <Configuration runwithwarnings="True" name="Debug">
+ <CodeGeneration runtime="MsNet" compiler="Csc" compilerversion="" warninglevel="4" nowarn="" includedebuginformation="True" optimize="False" unsafecodeallowed="False" generateoverflowchecks="True" mainclass="" target="WinExe" definesymbols="" generatexmldocumentation="False" win32Icon="" noconfig="False" nostdlib="False" />
+ <Execution commandlineparameters="" consolepause="False" />
+ <Output directory=".\bin\Debug" assembly="BitmapSpriteEd" executeScript="" executeBeforeBuild="" executeAfterBuild="" executeBeforeBuildArguments="" executeAfterBuildArguments="" />
+ </Configuration>
+ <Configurations active="Debug">
+ <Configuration runwithwarnings="True" name="Debug">
+ <CodeGeneration runtime="MsNet" compiler="Csc" compilerversion="" warninglevel="4" nowarn="" includedebuginformation="True" optimize="False" unsafecodeallowed="False" generateoverflowchecks="True" mainclass="" target="WinExe" definesymbols="" generatexmldocumentation="False" win32Icon="" noconfig="False" nostdlib="False" />
+ <Execution commandlineparameters="" consolepause="False" />
+ <Output directory=".\bin\Debug" assembly="BitmapSpriteEd" executeScript="" executeBeforeBuild="" executeAfterBuild="" executeBeforeBuildArguments="" executeAfterBuildArguments="" />
+ </Configuration>
+ <Configuration runwithwarnings="True" name="Release">
+ <CodeGeneration runtime="MsNet" compiler="Csc" compilerversion="" warninglevel="4" nowarn="" includedebuginformation="False" optimize="True" unsafecodeallowed="False" generateoverflowchecks="False" mainclass="" target="WinExe" definesymbols="" generatexmldocumentation="False" win32Icon="" noconfig="False" nostdlib="False" />
+ <Execution commandlineparameters="" consolepause="False" />
+ <Output directory=".\bin\Release" assembly="BitmapSpriteEd" executeScript="" executeBeforeBuild="" executeAfterBuild="" executeBeforeBuildArguments="" executeAfterBuildArguments="" />
+ </Configuration>
+ </Configurations>
+</Project> \ No newline at end of file
diff --git a/CopyMenu.cs b/CopyMenu.cs
new file mode 100644
index 0000000..a123fe3
--- /dev/null
+++ b/CopyMenu.cs
@@ -0,0 +1,165 @@
+// BitmapSpriteEd - Bitmap Sprite Editor
+// 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 BitmapSpriteEd
+{
+ /// <summary>
+ /// Implements the Copy/Paste menu
+ /// </summary>
+ 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..c564a52
--- /dev/null
+++ b/GfxEditor.cs
@@ -0,0 +1,1398 @@
+// BitmapFrameEd - Bitmap Sprite Editor
+// 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 BitmapSpriteEd
+{
+ /// <summary>
+ /// Implements a control for drawing
+ /// </summary>
+ [ToolboxItem(true)]
+ public class GfxEditor : System.Windows.Forms.UserControl
+ {
+ private System.Windows.Forms.Label m_fgPreview;
+ private System.Windows.Forms.ComboBox m_modeList;
+ private System.Windows.Forms.Label m_recent8;
+ private System.Windows.Forms.Label m_recent1;
+ private System.Windows.Forms.Label label11;
+ private System.Windows.Forms.Label m_recent3;
+ private System.Windows.Forms.Label m_recent5;
+ private System.Windows.Forms.Label m_recent6;
+ private System.Windows.Forms.Label m_recent7;
+ private System.Windows.Forms.Label m_bgPreview;
+ private System.Windows.Forms.Label m_recent2;
+ private System.Windows.Forms.ComboBox m_sizeY;
+ private System.Windows.Forms.CheckBox m_mark;
+ private System.Windows.Forms.PictureBox m_preview;
+ private System.Windows.Forms.Label m_gridCol;
+ private System.Windows.Forms.PictureBox m_edit;
+ private System.Windows.Forms.Label label12;
+ private System.Windows.Forms.Label label13;
+ private System.Windows.Forms.Label m_pos;
+ private System.Windows.Forms.Label m_recent4;
+ private System.Windows.Forms.Label label14;
+ private System.Windows.Forms.Label label15;
+ private System.Windows.Forms.Button m_undoButton;
+ private System.Windows.Forms.Label label3;
+ private System.Windows.Forms.Label label2;
+ private System.Windows.Forms.Label label1;
+ private System.Windows.Forms.ComboBox m_sizeX;
+ private System.Windows.Forms.Label label7;
+ private System.Windows.Forms.Label label6;
+ private System.Windows.Forms.Label label5;
+ private System.Windows.Forms.Label label4;
+ private System.Windows.Forms.Label m_backCol;
+
+ public const int MAX_SIZE=32;
+
+ private const int 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 Frame m_char;
+ private Frame m_undo;
+ private int m_width;
+ private int m_height;
+
+ private Rectangle m_editRect;
+ private Bitmap m_editBmp;
+ private Rectangle m_prevRect;
+ private Bitmap m_prevBmp;
+
+ private int m_grid;
+ private int m_mx;
+ private int m_my;
+
+ private bool m_drawing;
+ private Mode m_mode;
+ private Color[,] m_overlay;
+ private int m_ox;
+ private int m_oy;
+ private Color m_pen;
+
+ private CopyMenu m_cpMenu;
+ private int m_cpX;
+ private int m_cpY;
+ private int m_cpWidth;
+ private int m_cpHeight;
+ private Color[,] m_cpBuff;
+
+ private Label[] m_recent;
+
+ public GfxEditor()
+ {
+ //
+ // InitializeComponent() call is required for Windows Forms designer support.
+ //
+ InitializeComponent();
+
+ //m_inEditor=false;
+
+ SetUndo(null);
+ m_char=null;
+ m_grid=8;
+ m_mx=SIZE;
+ m_my=SIZE;
+
+ 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;
+
+ m_bgPreview.BackColor=Color.FromArgb(0);
+
+ 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();
+
+ m_recent=new Label[]
+ {m_recent1,m_recent2,m_recent3,m_recent4,
+ m_recent5,m_recent6,m_recent7,m_recent8};
+ }
+
+ #region Windows Forms Designer generated code
+ /// <summary>
+ /// 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.
+ /// </summary>
+ private void InitializeComponent() {
+ this.m_backCol = 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.label7 = new System.Windows.Forms.Label();
+ this.m_sizeX = new System.Windows.Forms.ComboBox();
+ this.label1 = new System.Windows.Forms.Label();
+ this.label2 = new System.Windows.Forms.Label();
+ this.label3 = new System.Windows.Forms.Label();
+ this.m_undoButton = new System.Windows.Forms.Button();
+ this.label15 = new System.Windows.Forms.Label();
+ this.label14 = new System.Windows.Forms.Label();
+ this.m_recent4 = new System.Windows.Forms.Label();
+ this.m_pos = new System.Windows.Forms.Label();
+ this.label13 = new System.Windows.Forms.Label();
+ this.label12 = new System.Windows.Forms.Label();
+ this.m_edit = new System.Windows.Forms.PictureBox();
+ this.m_gridCol = new System.Windows.Forms.Label();
+ this.m_preview = new System.Windows.Forms.PictureBox();
+ this.m_mark = new System.Windows.Forms.CheckBox();
+ this.m_sizeY = new System.Windows.Forms.ComboBox();
+ this.m_recent2 = new System.Windows.Forms.Label();
+ this.m_bgPreview = new System.Windows.Forms.Label();
+ this.m_recent7 = new System.Windows.Forms.Label();
+ this.m_recent6 = new System.Windows.Forms.Label();
+ this.m_recent5 = new System.Windows.Forms.Label();
+ this.m_recent3 = new System.Windows.Forms.Label();
+ this.label11 = new System.Windows.Forms.Label();
+ this.m_recent1 = new System.Windows.Forms.Label();
+ this.m_recent8 = new System.Windows.Forms.Label();
+ this.m_modeList = new System.Windows.Forms.ComboBox();
+ this.m_fgPreview = new System.Windows.Forms.Label();
+ this.SuspendLayout();
+ //
+ // m_backCol
+ //
+ this.m_backCol.BackColor = System.Drawing.Color.Black;
+ this.m_backCol.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
+ this.m_backCol.Location = new System.Drawing.Point(168, 272);
+ this.m_backCol.Name = "m_backCol";
+ this.m_backCol.Size = new System.Drawing.Size(24, 24);
+ this.m_backCol.TabIndex = 34;
+ this.m_backCol.Click += new System.EventHandler(this.OnPaper);
+ //
+ // label4
+ //
+ this.label4.Location = new System.Drawing.Point(280, 88);
+ 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, 88);
+ 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;
+ //
+ // 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;
+ //
+ // label7
+ //
+ this.label7.Location = new System.Drawing.Point(280, 232);
+ this.label7.Name = "label7";
+ this.label7.Size = new System.Drawing.Size(88, 16);
+ this.label7.TabIndex = 24;
+ this.label7.Text = "Recent Colours";
+ this.label7.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
+ //
+ // m_sizeX
+ //
+ this.m_sizeX.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
+ this.m_sizeX.Enabled = false;
+ this.m_sizeX.Items.AddRange(new object[] {
+ "8",
+ "16",
+ "32"});
+ this.m_sizeX.Location = new System.Drawing.Point(280, 24);
+ this.m_sizeX.Name = "m_sizeX";
+ this.m_sizeX.Size = new System.Drawing.Size(48, 21);
+ this.m_sizeX.TabIndex = 36;
+ this.m_sizeX.SelectedIndexChanged += new System.EventHandler(this.OnSizeWidth);
+ //
+ // 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, 168);
+ 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;
+ //
+ // 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);
+ //
+ // label15
+ //
+ this.label15.Location = new System.Drawing.Point(0, 0);
+ this.label15.Name = "label15";
+ this.label15.TabIndex = 0;
+ //
+ // label14
+ //
+ this.label14.BackColor = System.Drawing.Color.White;
+ this.label14.Location = new System.Drawing.Point(152, 144);
+ this.label14.Name = "label14";
+ this.label14.Size = new System.Drawing.Size(16, 16);
+ this.label14.TabIndex = 29;
+ //
+ // m_recent4
+ //
+ this.m_recent4.BackColor = System.Drawing.Color.Black;
+ this.m_recent4.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
+ this.m_recent4.Location = new System.Drawing.Point(352, 248);
+ this.m_recent4.Name = "m_recent4";
+ this.m_recent4.Size = new System.Drawing.Size(16, 16);
+ this.m_recent4.TabIndex = 28;
+ this.m_recent4.MouseUp += new System.Windows.Forms.MouseEventHandler(this.OnRecent);
+ //
+ // m_pos
+ //
+ this.m_pos.Location = new System.Drawing.Point(208, 272);
+ this.m_pos.Name = "m_pos";
+ this.m_pos.Size = new System.Drawing.Size(56, 24);
+ this.m_pos.TabIndex = 23;
+ this.m_pos.TextAlign = System.Drawing.ContentAlignment.TopRight;
+ //
+ // label13
+ //
+ this.label13.BackColor = System.Drawing.Color.White;
+ this.label13.Location = new System.Drawing.Point(176, 144);
+ this.label13.Name = "label13";
+ this.label13.Size = new System.Drawing.Size(16, 16);
+ this.label13.TabIndex = 30;
+ //
+ // label12
+ //
+ this.label12.BackColor = System.Drawing.Color.White;
+ this.label12.Location = new System.Drawing.Point(200, 144);
+ this.label12.Name = "label12";
+ this.label12.Size = new System.Drawing.Size(16, 16);
+ this.label12.TabIndex = 31;
+ //
+ // 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_gridCol
+ //
+ this.m_gridCol.BackColor = System.Drawing.Color.Lime;
+ this.m_gridCol.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
+ this.m_gridCol.Location = new System.Drawing.Point(136, 272);
+ this.m_gridCol.Name = "m_gridCol";
+ this.m_gridCol.Size = new System.Drawing.Size(24, 24);
+ this.m_gridCol.TabIndex = 33;
+ this.m_gridCol.Click += new System.EventHandler(this.OnGrid);
+ //
+ // m_preview
+ //
+ this.m_preview.BackColor = System.Drawing.SystemColors.Control;
+ this.m_preview.Location = new System.Drawing.Point(288, 192);
+ 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_mark
+ //
+ this.m_mark.Checked = true;
+ this.m_mark.CheckState = System.Windows.Forms.CheckState.Checked;
+ this.m_mark.Location = new System.Drawing.Point(280, 136);
+ this.m_mark.Name = "m_mark";
+ this.m_mark.Size = new System.Drawing.Size(96, 32);
+ this.m_mark.TabIndex = 35;
+ this.m_mark.Text = "Highlight Dark Colours";
+ this.m_mark.CheckedChanged += new System.EventHandler(this.OnMark);
+ //
+ // m_sizeY
+ //
+ this.m_sizeY.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
+ this.m_sizeY.Enabled = false;
+ this.m_sizeY.Items.AddRange(new object[] {
+ "8",
+ "16",
+ "32"});
+ this.m_sizeY.Location = new System.Drawing.Point(336, 24);
+ this.m_sizeY.Name = "m_sizeY";
+ this.m_sizeY.Size = new System.Drawing.Size(48, 21);
+ this.m_sizeY.TabIndex = 37;
+ this.m_sizeY.SelectedIndexChanged += new System.EventHandler(this.OnSizeHeight);
+ //
+ // m_recent2
+ //
+ this.m_recent2.BackColor = System.Drawing.Color.Black;
+ this.m_recent2.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
+ this.m_recent2.Location = new System.Drawing.Point(304, 248);
+ this.m_recent2.Name = "m_recent2";
+ this.m_recent2.Size = new System.Drawing.Size(16, 16);
+ this.m_recent2.TabIndex = 26;
+ this.m_recent2.MouseUp += new System.Windows.Forms.MouseEventHandler(this.OnRecent);
+ //
+ // m_bgPreview
+ //
+ this.m_bgPreview.BackColor = System.Drawing.Color.Transparent;
+ this.m_bgPreview.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
+ this.m_bgPreview.Location = new System.Drawing.Point(336, 104);
+ this.m_bgPreview.Name = "m_bgPreview";
+ this.m_bgPreview.Size = new System.Drawing.Size(40, 32);
+ this.m_bgPreview.TabIndex = 18;
+ this.m_bgPreview.Click += new System.EventHandler(this.OnBackground);
+ //
+ // m_recent7
+ //
+ this.m_recent7.BackColor = System.Drawing.Color.Black;
+ this.m_recent7.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
+ this.m_recent7.Location = new System.Drawing.Point(328, 272);
+ this.m_recent7.Name = "m_recent7";
+ this.m_recent7.Size = new System.Drawing.Size(16, 16);
+ this.m_recent7.TabIndex = 31;
+ this.m_recent7.MouseUp += new System.Windows.Forms.MouseEventHandler(this.OnRecent);
+ //
+ // m_recent6
+ //
+ this.m_recent6.BackColor = System.Drawing.Color.Black;
+ this.m_recent6.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
+ this.m_recent6.Location = new System.Drawing.Point(304, 272);
+ this.m_recent6.Name = "m_recent6";
+ this.m_recent6.Size = new System.Drawing.Size(16, 16);
+ this.m_recent6.TabIndex = 30;
+ this.m_recent6.MouseUp += new System.Windows.Forms.MouseEventHandler(this.OnRecent);
+ //
+ // m_recent5
+ //
+ this.m_recent5.BackColor = System.Drawing.Color.Black;
+ this.m_recent5.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
+ this.m_recent5.Location = new System.Drawing.Point(280, 272);
+ this.m_recent5.Name = "m_recent5";
+ this.m_recent5.Size = new System.Drawing.Size(16, 16);
+ this.m_recent5.TabIndex = 29;
+ this.m_recent5.MouseUp += new System.Windows.Forms.MouseEventHandler(this.OnRecent);
+ //
+ // m_recent3
+ //
+ this.m_recent3.BackColor = System.Drawing.Color.Black;
+ this.m_recent3.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
+ this.m_recent3.Location = new System.Drawing.Point(328, 248);
+ this.m_recent3.Name = "m_recent3";
+ this.m_recent3.Size = new System.Drawing.Size(16, 16);
+ this.m_recent3.TabIndex = 27;
+ this.m_recent3.MouseUp += new System.Windows.Forms.MouseEventHandler(this.OnRecent);
+ //
+ // label11
+ //
+ this.label11.BackColor = System.Drawing.Color.White;
+ this.label11.Location = new System.Drawing.Point(224, 144);
+ this.label11.Name = "label11";
+ this.label11.Size = new System.Drawing.Size(16, 16);
+ this.label11.TabIndex = 32;
+ //
+ // m_recent1
+ //
+ this.m_recent1.BackColor = System.Drawing.Color.White;
+ this.m_recent1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
+ this.m_recent1.Location = new System.Drawing.Point(280, 248);
+ this.m_recent1.Name = "m_recent1";
+ this.m_recent1.Size = new System.Drawing.Size(16, 16);
+ this.m_recent1.TabIndex = 25;
+ this.m_recent1.MouseUp += new System.Windows.Forms.MouseEventHandler(this.OnRecent);
+ //
+ // m_recent8
+ //
+ this.m_recent8.BackColor = System.Drawing.Color.Black;
+ this.m_recent8.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
+ this.m_recent8.Location = new System.Drawing.Point(352, 272);
+ this.m_recent8.Name = "m_recent8";
+ this.m_recent8.Size = new System.Drawing.Size(16, 16);
+ this.m_recent8.TabIndex = 32;
+ this.m_recent8.MouseUp += new System.Windows.Forms.MouseEventHandler(this.OnRecent);
+ //
+ // 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_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, 104);
+ this.m_fgPreview.Name = "m_fgPreview";
+ this.m_fgPreview.Size = new System.Drawing.Size(40, 32);
+ this.m_fgPreview.TabIndex = 17;
+ this.m_fgPreview.Click += new System.EventHandler(this.OnForeground);
+ //
+ // GfxEditor
+ //
+ this.Controls.Add(this.m_sizeY);
+ this.Controls.Add(this.m_sizeX);
+ this.Controls.Add(this.m_mark);
+ this.Controls.Add(this.m_backCol);
+ this.Controls.Add(this.m_gridCol);
+ this.Controls.Add(this.m_recent8);
+ this.Controls.Add(this.m_recent7);
+ this.Controls.Add(this.m_recent6);
+ this.Controls.Add(this.m_recent5);
+ this.Controls.Add(this.m_recent4);
+ this.Controls.Add(this.m_recent3);
+ this.Controls.Add(this.m_recent2);
+ this.Controls.Add(this.m_recent1);
+ this.Controls.Add(this.label7);
+ this.Controls.Add(this.m_pos);
+ this.Controls.Add(this.label6);
+ this.Controls.Add(this.label2);
+ 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);
+ this.ResumeLayout(false);
+ }
+ #endregion
+
+ // -------------------------------------------------------
+ // PUBLIC INTERFACES
+ // -------------------------------------------------------
+ #region Public Interfaces
+
+ public int FrameWidth
+ {
+ get {return m_width;}
+ }
+
+ public int FrameHeight
+ {
+ get {return m_height;}
+ }
+
+ public Frame Frame
+ {
+ get {return m_char;}
+ set
+ {
+ m_char=value;
+ SetUndo(null);
+ m_width=m_char.Width;
+ m_height=m_char.Height;
+ m_sizeX.Enabled=true;
+ m_sizeY.Enabled=true;
+ m_sizeX.Text=m_char.Width.ToString();
+ m_sizeY.Text=m_char.Height.ToString();
+ InitialiseOverlay();
+ DrawGrid();
+ DrawChar();
+ }
+ }
+
+ public Color SelectedForeground
+ {
+ get {return m_fgPreview.BackColor;}
+ }
+
+ public Color SelectedBackground
+ {
+ get {return m_bgPreview.BackColor;}
+ }
+
+ #endregion
+
+ // -------------------------------------------------------
+ // MISC
+ // -------------------------------------------------------
+ #region Misc Routines
+
+ private void AddRecentColour(Color c)
+ {
+ foreach (Label l in m_recent)
+ {
+ if (l.BackColor==c)
+ {
+ return;
+ }
+ }
+
+ for(int f=m_recent.Length-1;f>0;f--)
+ {
+ m_recent[f].BackColor=m_recent[f-1].BackColor;
+ }
+
+ m_recent[0].BackColor=c;
+ }
+
+ private void SetUndo(Frame s)
+ {
+ m_undo=s;
+ m_undoButton.Enabled=(m_undo!=null);
+ }
+
+ #endregion
+
+ // -------------------------------------------------------
+ // SPRITE/GENERAL DRAWING
+ // -------------------------------------------------------
+ #region Frame/General Drawing
+
+ private void Flush(ref Graphics g)
+ {
+ g.Flush(FlushIntention.Sync);
+ g.Dispose();
+ g=null;
+ }
+
+ private void DrawGrid()
+ {
+ Graphics g=Graphics.FromImage(m_prevBmp);
+ Pen p=new Pen(m_gridCol.BackColor);
+
+ g.Clear(Color.Black);
+ Flush(ref g);
+
+ g=Graphics.FromImage(m_editBmp);
+
+ g.Clear(m_backCol.BackColor);
+
+ for(int x=0;x<m_width+1;x++)
+ {
+ g.DrawLine(p,x*m_grid,0,x*m_grid,m_my);
+ }
+
+ for(int y=0;y<m_height+1;y++)
+ {
+ g.DrawLine(p,0,y*m_grid,m_mx,y*m_grid);
+ }
+
+ Flush(ref g);
+
+ m_edit.Invalidate();
+ m_preview.Invalidate();
+ }
+
+ private void RedrawChar()
+ {
+ DrawGrid();
+ DrawChar();
+ }
+
+ // This could really do with some optimisations
+ //
+ private void DrawChar()
+ {
+ if (m_char==null)
+ {
+ return;
+ }
+
+ Graphics editg=Graphics.FromImage(m_editBmp);
+ Graphics prevg=Graphics.FromImage(m_prevBmp);
+
+ for(int x=0;x<m_char.Width;x++)
+ for(int y=0;y<m_char.Height;y++)
+ if (m_overlay[x,y]==TRANS)
+ CharPlot(editg,prevg,x,y,m_char[x,y]);
+ else
+ CharPlot(editg,prevg,x,y,m_overlay[x,y]);
+
+ Flush(ref editg);
+ Flush(ref prevg);
+
+ m_edit.Invalidate();
+ m_edit.Update();
+ m_preview.Invalidate();
+ m_preview.Update();
+ }
+
+ private void CharPlot(Graphics edit, Graphics prev,
+ int x, int y, Color c)
+ {
+ SolidBrush p=new SolidBrush(m_backCol.BackColor);
+
+ int gx=x*m_grid+1;
+ int gy=y*m_grid+1;
+ int gw=m_grid-1;
+
+ edit.FillRectangle(p,gx,gy,gw,gw);
+ prev.FillRectangle(p,1+x,1+y,1,1);
+
+ p=new SolidBrush(c);
+
+ edit.FillRectangle(p,gx,gy,gw,gw);
+ prev.FillRectangle(p,1+x,1+y,1,1);
+
+ if (m_mark.Checked)
+ {
+ if ((c.R<100 && c.G<100 && c.B<100 && c.A>0) || (c.A>0 && c.A<100))
+ {
+ edit.DrawRectangle(Pens.White,gx+1,gy+1,gw-3,gw-3);
+ }
+ }
+ }
+
+ #endregion
+
+ // -------------------------------------------------------
+ // OVERLAY HANDLING
+ // -------------------------------------------------------
+ #region Overlay Handling
+
+ private void InitialiseOverlay()
+ {
+ if (m_char==null)
+ {
+ m_overlay=null;
+ return;
+ }
+
+ m_overlay=new Color[m_char.Width,m_char.Height];
+
+ for(int y=0;y<m_char.Height;y++)
+ for(int x=0;x<m_char.Width;x++)
+ m_overlay[x,y]=TRANS;
+ }
+
+ private void ClearOverlay()
+ {
+ if (m_overlay==null)
+ {
+ return;
+ }
+
+ for(int y=0;y<m_char.Height;y++)
+ for(int x=0;x<m_char.Width;x++)
+ m_overlay[x,y]=TRANS;
+ }
+
+ private void ApplyOverlay()
+ {
+ for(int y=0;y<m_char.Height;y++)
+ for(int x=0;x<m_char.Width;x++)
+ {
+ if (m_overlay[x,y]!=TRANS)
+ m_char[x,y]=m_overlay[x,y];
+
+ m_overlay[x,y]=TRANS;
+ }
+ }
+
+ private void OverlayFromFrame()
+ {
+ for(int y=0;y<m_char.Height;y++)
+ for(int x=0;x<m_char.Width;x++)
+ m_overlay[x,y]=m_char[x,y];
+ }
+
+ #endregion
+
+ // -------------------------------------------------------
+ // COPY/PASTE ROUTINES
+ // -------------------------------------------------------
+ #region Copy/Paste
+
+ private void DrawMarkBox(int x1, int y1,int x2, int y2)
+ {
+ RankCoord(ref x1, ref x2);
+ RankCoord(ref y1, ref y2);
+
+ for(int x=x1;x<=x2;x++)
+ {
+ m_overlay[x,y1]=m_gridCol.BackColor;
+ m_overlay[x,y2]=m_gridCol.BackColor;
+ }
+
+ for(int y=y1;y<=y2;y++)
+ {
+ m_overlay[x1,y]=m_gridCol.BackColor;
+ m_overlay[x2,y]=m_gridCol.BackColor;
+ }
+ }
+
+ private void Copy(int x1, int y1, int x2, int y2)
+ {
+ RankCoord(ref x1, ref x2);
+ RankCoord(ref y1, ref y2);
+
+ m_cpX=x1;
+ m_cpY=y1;
+ m_cpWidth=x2-x1+1;
+ m_cpHeight=y2-y1+1;
+
+ m_cpBuff=new Color[m_cpWidth,m_cpHeight];
+
+ for(int x=0;x<m_cpWidth;x++)
+ for(int y=0;y<m_cpHeight;y++)
+ m_cpBuff[x,y]=m_char[x1+x,y1+y];
+
+ m_drawing=false;
+ m_cpMenu.Mode=CopyMenu.EMode.eNothing;
+ }
+
+ private void Paste(int x, int y, bool trans)
+ {
+ switch (m_cpMenu.Gravity)
+ {
+ case CopyMenu.EGravity.eTopLeft:
+ break;
+
+ case CopyMenu.EGravity.eTopRight:
+ x-=m_cpWidth;
+ break;
+
+ case CopyMenu.EGravity.eBottomLeft:
+ y-=m_cpHeight;
+ break;
+
+ case CopyMenu.EGravity.eBottomRight:
+ x-=m_cpWidth;
+ y-=m_cpHeight;
+ break;
+
+ case CopyMenu.EGravity.eCentre:
+ x-=m_cpWidth/2;
+ y-=m_cpHeight/2;
+ break;
+ }
+
+ for(int w=0;w<m_cpWidth;w++)
+ for(int h=0;h<m_cpHeight;h++)
+ if (!trans || m_cpBuff[w,h].A!=0)
+ SafePlot(x+w,y+h,m_cpBuff[w,h]);
+ }
+
+ #endregion
+
+ // -------------------------------------------------------
+ // DRAWING ROUTINES
+ // -------------------------------------------------------
+ #region Drawing Routines
+
+ private void RankCoord(ref int c1, ref int c2)
+ {
+ if (c1>c2)
+ {
+ int t=c2;
+ c2=c1;
+ c1=t;
+ }
+ }
+
+ private void SafePlot(int x, int y, Color col)
+ {
+ if (x>=0 && x<m_char.Width && y>=0 && y<m_char.Height)
+ m_overlay[x,y]=col;
+ }
+
+ private void DrawLine(int x1, int y1,
+ int x2, int y2,
+ Color col)
+ {
+ int dx=x2-x1;
+ int dy=y2-y1;
+
+ int ix=Math.Sign(dx);
+ int iy=Math.Sign(dy);
+
+ dx=Math.Abs(dx);
+ dy=Math.Abs(dy);
+
+ int incrE;
+ int incrNE;
+ int d;
+ bool ymode;
+
+ if (dy>dx)
+ {
+ 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(int x1, int y1,
+ int x2, int y2,
+ Color col, bool fill)
+ {
+ RankCoord(ref x1, ref x2);
+ RankCoord(ref y1, ref y2);
+
+ if (fill)
+ {
+ for(int x=x1;x<=x2;x++)
+ for(int y=y1;y<=y2;y++)
+ m_overlay[x,y]=col;
+ }
+ else
+ {
+ for(int x=x1;x<=x2;x++)
+ {
+ m_overlay[x,y1]=col;
+ m_overlay[x,y2]=col;
+ }
+
+ for(int y=y1;y<=y2;y++)
+ {
+ m_overlay[x1,y]=col;
+ m_overlay[x2,y]=col;
+ }
+ }
+ }
+
+ private void DrawEllipse(int ox, int oy,
+ int radpointx, int radpointy,
+ Color col, bool circle, bool fill)
+ {
+ double rx=Math.Abs(ox-radpointx)+1;
+ double ry=Math.Abs(oy-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(int x, int 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_char.Width-1)
+ FloodFill(x+1,y,col,bg);
+
+ if (y<m_char.Height-1)
+ FloodFill(x,y+1,col,bg);
+ }
+
+ #endregion
+
+ // -------------------------------------------------------
+ // CALLBACKS
+ // -------------------------------------------------------
+ #region Callbacks
+
+ void OnDrawMode(object sender, System.EventArgs e)
+ {
+ m_mode=(Mode)m_modeList.SelectedIndex;
+ }
+
+ void OnSizeWidth(object sender, System.EventArgs e)
+ {
+ m_width=Convert.ToInt32(m_sizeX.Text);
+
+ if (m_char!=null)
+ {
+ SetUndo(null);
+ m_char.Resize(m_width,m_height);
+ InitialiseOverlay();
+ }
+
+ 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 OnSizeHeight(object sender, System.EventArgs e)
+ {
+ m_height=Convert.ToInt32(m_sizeY.Text);
+
+ if (m_char!=null)
+ {
+ SetUndo(null);
+ m_char.Resize(m_width,m_height);
+ InitialiseOverlay();
+ }
+
+ 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;
+ }
+
+ void OnLeaveEditor(object sender, System.EventArgs e)
+ {
+ //m_inEditor=false;
+
+ m_pos.Text="";
+
+ if (m_drawing && m_mode==Mode.ePlot)
+ {
+ SetUndo(new Frame(m_char));
+ ApplyOverlay();
+ }
+
+ m_drawing=false;
+
+ ClearOverlay();
+ DrawChar();
+ }
+
+ void OnModeSelect(object sender, System.EventArgs e)
+ {
+ m_mode=(Mode)m_modeList.SelectedIndex;
+ }
+
+ void OnUndo(object sender, System.EventArgs e)
+ {
+ if (m_undo!=null)
+ {
+ Frame s=m_char;
+ m_char=m_undo;
+ m_undo=s;
+ DrawChar();
+ }
+ }
+
+ void OnMouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
+ {
+ if (m_char==null || e.X<0 || e.X>=m_mx || e.Y<0 || e.Y>=m_my)
+ {
+ return;
+ }
+
+ int x;
+ int y;
+
+ x=e.X/m_grid;
+ y=e.Y/m_grid;
+
+ m_pos.Text=x+","+y;
+
+ if (x>=m_char.Width || y>=m_char.Height)
+ {
+ return;
+ }
+
+ if (e.Button==MouseButtons.None)
+ {
+ switch(m_mode)
+ {
+ case Mode.eFloodFill:
+ if (m_drawing)
+ {
+ OverlayFromFrame();
+ FloodFill(m_ox,m_oy,m_pen,m_char[m_ox,m_oy]);
+ m_drawing=false;
+ SetUndo(new Frame(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;
+ SetUndo(new Frame(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:
+ SetUndo(new Frame(m_char));
+ ApplyOverlay();
+ DrawChar();
+ m_drawing=false;
+ m_cpMenu.Mode=CopyMenu.EMode.eNothing;
+ break;
+
+ default:
+ break;
+ }
+ }
+ break;
+ }
+ }
+
+ void OnForeground(object sender, System.EventArgs e)
+ {
+ AlphaColourDialog d=new AlphaColourDialog("Select Colour for Left Mouse Button");
+
+ d.Color=m_fgPreview.BackColor;
+
+ if (d.ShowDialog()==DialogResult.OK)
+ {
+ m_fgPreview.BackColor=d.Color;
+ AddRecentColour(d.Color);
+ }
+ }
+
+ void OnBackground(object sender, System.EventArgs e)
+ {
+ AlphaColourDialog d=new AlphaColourDialog("Select Colour for Right Mouse Button");
+
+ d.Color=m_bgPreview.BackColor;
+
+ if (d.ShowDialog()==DialogResult.OK)
+ {
+ m_bgPreview.BackColor=d.Color;
+ AddRecentColour(d.Color);
+ }
+ }
+
+ void OnRecent(object sender, System.Windows.Forms.MouseEventArgs e)
+ {
+ Label l=(Label)sender;
+
+ if (e.Button==MouseButtons.Left)
+ {
+ m_fgPreview.BackColor=l.BackColor;
+ }
+ else if (e.Button==MouseButtons.Right)
+ {
+ m_bgPreview.BackColor=l.BackColor;
+ }
+ }
+
+ void OnGrid(object sender, System.EventArgs e)
+ {
+ AlphaColourDialog d=new AlphaColourDialog("Select Grid Colour");
+
+ d.AllowAlpha=false;
+ d.Color=m_gridCol.BackColor;
+
+ if (d.ShowDialog()==DialogResult.OK)
+ {
+ m_gridCol.BackColor=d.Color;
+ RedrawChar();
+ }
+ }
+
+ void OnPaper(object sender, System.EventArgs e)
+ {
+ AlphaColourDialog d=new AlphaColourDialog("Select Background Colour");
+
+ d.AllowAlpha=false;
+ d.Color=m_backCol.BackColor;
+
+ if (d.ShowDialog()==DialogResult.OK)
+ {
+ m_backCol.BackColor=d.Color;
+ RedrawChar();
+ }
+ }
+
+ void OnMark(object sender, System.EventArgs e)
+ {
+ RedrawChar();
+ }
+
+ #endregion
+ }
+}
diff --git a/MainForm.cs b/MainForm.cs
new file mode 100644
index 0000000..13da6d8
--- /dev/null
+++ b/MainForm.cs
@@ -0,0 +1,456 @@
+// BitmapSpriteEd - Bitmap Sprite Editor
+// 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 BitmapSpriteEd
+{
+ /// <summary>
+ /// Description of MainForm.
+ /// </summary>
+ public class MainForm : System.Windows.Forms.Form
+ {
+ private System.Windows.Forms.MainMenu m_menu;
+ private System.Windows.Forms.NumericUpDown m_frameNum;
+ private System.Windows.Forms.MenuItem m_new;
+ private System.Windows.Forms.Button m_addFrame;
+ private System.Windows.Forms.MenuItem m_about;
+ private System.Windows.Forms.NumericUpDown m_spriteNum;
+ private System.Windows.Forms.TextBox m_spriteName;
+ private System.Windows.Forms.MenuItem m_saveAs;
+ private System.Windows.Forms.Button m_removeFrame;
+ private System.Windows.Forms.MenuItem m_open;
+ private System.Windows.Forms.MenuItem m_fileMenu;
+ private System.Windows.Forms.MenuItem m_exportMenu;
+ private System.Windows.Forms.MenuItem m_quit;
+ private System.Windows.Forms.MenuItem m_exportPNG;
+ private System.Windows.Forms.GroupBox m_animGroup;
+ private System.Windows.Forms.Label label3;
+ private System.Windows.Forms.Label label2;
+ private System.Windows.Forms.Label label1;
+ private System.Windows.Forms.MenuItem m_break1;
+ private System.Windows.Forms.GroupBox m_editGroup;
+ private System.Windows.Forms.Button m_addSprite;
+ private System.Windows.Forms.MenuItem m_save;
+ private System.Windows.Forms.GroupBox m_spriteGroup;
+ private System.Windows.Forms.Button m_removeSprite;
+ private System.Windows.Forms.MenuItem m_helpMenu;
+
+ private GfxEditor m_edit;
+ private SpriteList m_sprites;
+
+ public MainForm()
+ {
+ //
+ // The InitializeComponent() call is required for Windows Forms designer support.
+ //
+ InitializeComponent();
+
+ m_edit=new GfxEditor();
+ m_edit.Location=new Point(4,16);
+ m_editGroup.Controls.Add(m_edit);
+
+ OnNew(null,null);
+ }
+
+ [STAThread]
+ public static void Main(string[] args)
+ {
+ Application.Run(new MainForm());
+ }
+
+ #region Windows Forms Designer generated code
+ /// <summary>
+ /// 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.
+ /// </summary>
+ private void InitializeComponent() {
+ this.m_helpMenu = new System.Windows.Forms.MenuItem();
+ this.m_removeSprite = new System.Windows.Forms.Button();
+ this.m_spriteGroup = new System.Windows.Forms.GroupBox();
+ this.m_save = new System.Windows.Forms.MenuItem();
+ this.m_addSprite = new System.Windows.Forms.Button();
+ this.m_editGroup = new System.Windows.Forms.GroupBox();
+ this.m_break1 = new System.Windows.Forms.MenuItem();
+ this.label1 = new System.Windows.Forms.Label();
+ this.label2 = new System.Windows.Forms.Label();
+ this.label3 = new System.Windows.Forms.Label();
+ this.m_animGroup = new System.Windows.Forms.GroupBox();
+ this.m_exportPNG = new System.Windows.Forms.MenuItem();
+ this.m_quit = new System.Windows.Forms.MenuItem();
+ this.m_exportMenu = new System.Windows.Forms.MenuItem();
+ this.m_fileMenu = new System.Windows.Forms.MenuItem();
+ this.m_open = new System.Windows.Forms.MenuItem();
+ this.m_removeFrame = new System.Windows.Forms.Button();
+ this.m_saveAs = new System.Windows.Forms.MenuItem();
+ this.m_spriteName = new System.Windows.Forms.TextBox();
+ this.m_spriteNum = new System.Windows.Forms.NumericUpDown();
+ this.m_about = new System.Windows.Forms.MenuItem();
+ this.m_addFrame = new System.Windows.Forms.Button();
+ this.m_new = new System.Windows.Forms.MenuItem();
+ this.m_frameNum = new System.Windows.Forms.NumericUpDown();
+ this.m_menu = new System.Windows.Forms.MainMenu();
+ this.m_spriteGroup.SuspendLayout();
+ ((System.ComponentModel.ISupportInitialize)(this.m_spriteNum)).BeginInit();
+ ((System.ComponentModel.ISupportInitialize)(this.m_frameNum)).BeginInit();
+ this.SuspendLayout();
+ //
+ // m_helpMenu
+ //
+ this.m_helpMenu.Index = 2;
+ this.m_helpMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
+ this.m_about});
+ this.m_helpMenu.Text = "Help";
+ //
+ // m_removeSprite
+ //
+ this.m_removeSprite.Location = new System.Drawing.Point(224, 32);
+ this.m_removeSprite.Name = "m_removeSprite";
+ this.m_removeSprite.Size = new System.Drawing.Size(64, 24);
+ this.m_removeSprite.TabIndex = 5;
+ this.m_removeSprite.Text = "Remove";
+ this.m_removeSprite.Click += new System.EventHandler(this.OnRemoveSprite);
+ //
+ // m_spriteGroup
+ //
+ this.m_spriteGroup.Controls.Add(this.m_spriteName);
+ this.m_spriteGroup.Controls.Add(this.label3);
+ this.m_spriteGroup.Controls.Add(this.m_removeFrame);
+ this.m_spriteGroup.Controls.Add(this.m_addFrame);
+ this.m_spriteGroup.Controls.Add(this.m_removeSprite);
+ this.m_spriteGroup.Controls.Add(this.m_addSprite);
+ this.m_spriteGroup.Controls.Add(this.label2);
+ this.m_spriteGroup.Controls.Add(this.m_frameNum);
+ this.m_spriteGroup.Controls.Add(this.label1);
+ this.m_spriteGroup.Controls.Add(this.m_spriteNum);
+ this.m_spriteGroup.Location = new System.Drawing.Point(424, 8);
+ this.m_spriteGroup.Name = "m_spriteGroup";
+ this.m_spriteGroup.Size = new System.Drawing.Size(304, 152);
+ this.m_spriteGroup.TabIndex = 1;
+ this.m_spriteGroup.TabStop = false;
+ this.m_spriteGroup.Text = "Sprite Frames";
+ //
+ // m_save
+ //
+ this.m_save.Enabled = false;
+ 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_addSprite
+ //
+ this.m_addSprite.Location = new System.Drawing.Point(144, 32);
+ this.m_addSprite.Name = "m_addSprite";
+ this.m_addSprite.Size = new System.Drawing.Size(64, 24);
+ this.m_addSprite.TabIndex = 4;
+ this.m_addSprite.Text = "Add";
+ this.m_addSprite.Click += new System.EventHandler(this.OnAddSprite);
+ //
+ // 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_break1
+ //
+ this.m_break1.Index = 4;
+ this.m_break1.Text = "-";
+ //
+ // label1
+ //
+ this.label1.Location = new System.Drawing.Point(8, 32);
+ this.label1.Name = "label1";
+ this.label1.Size = new System.Drawing.Size(56, 24);
+ this.label1.TabIndex = 1;
+ this.label1.Text = "Sprite:";
+ this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
+ //
+ // label2
+ //
+ this.label2.Location = new System.Drawing.Point(8, 72);
+ this.label2.Name = "label2";
+ this.label2.Size = new System.Drawing.Size(56, 24);
+ this.label2.TabIndex = 3;
+ this.label2.Text = "Frame:";
+ this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
+ //
+ // label3
+ //
+ this.label3.Location = new System.Drawing.Point(8, 112);
+ this.label3.Name = "label3";
+ this.label3.Size = new System.Drawing.Size(56, 24);
+ this.label3.TabIndex = 8;
+ this.label3.Text = "Name:";
+ this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
+ //
+ // m_animGroup
+ //
+ this.m_animGroup.Location = new System.Drawing.Point(424, 176);
+ this.m_animGroup.Name = "m_animGroup";
+ this.m_animGroup.Size = new System.Drawing.Size(304, 160);
+ this.m_animGroup.TabIndex = 2;
+ this.m_animGroup.TabStop = false;
+ this.m_animGroup.Text = "Animation Preview";
+ //
+ // m_exportPNG
+ //
+ this.m_exportPNG.Index = 0;
+ this.m_exportPNG.Text = "Export to PNG";
+ this.m_exportPNG.Click += new System.EventHandler(this.OnExportPNG);
+ //
+ // 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_exportMenu
+ //
+ this.m_exportMenu.Index = 1;
+ this.m_exportMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
+ this.m_exportPNG});
+ this.m_exportMenu.Text = "Export";
+ //
+ // 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.m_break1,
+ this.m_quit});
+ this.m_fileMenu.Text = "File";
+ //
+ // 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_removeFrame
+ //
+ this.m_removeFrame.Location = new System.Drawing.Point(224, 72);
+ this.m_removeFrame.Name = "m_removeFrame";
+ this.m_removeFrame.Size = new System.Drawing.Size(64, 24);
+ this.m_removeFrame.TabIndex = 7;
+ this.m_removeFrame.Text = "Remove";
+ this.m_removeFrame.Click += new System.EventHandler(this.OnRemoveFrame);
+ //
+ // m_saveAs
+ //
+ this.m_saveAs.Index = 3;
+ this.m_saveAs.Shortcut = System.Windows.Forms.Shortcut.F12;
+ this.m_saveAs.Text = "Save as...";
+ this.m_saveAs.Click += new System.EventHandler(this.OnSaveAs);
+ //
+ // m_spriteName
+ //
+ this.m_spriteName.CharacterCasing = System.Windows.Forms.CharacterCasing.Upper;
+ this.m_spriteName.Location = new System.Drawing.Point(64, 112);
+ this.m_spriteName.Name = "m_spriteName";
+ this.m_spriteName.Size = new System.Drawing.Size(224, 21);
+ this.m_spriteName.TabIndex = 9;
+ this.m_spriteName.Text = "";
+ this.m_spriteName.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.OnSpriteNameKey);
+ this.m_spriteName.TextChanged += new System.EventHandler(this.OnSpriteName);
+ //
+ // m_spriteNum
+ //
+ this.m_spriteNum.Location = new System.Drawing.Point(64, 32);
+ this.m_spriteNum.Name = "m_spriteNum";
+ this.m_spriteNum.ReadOnly = true;
+ this.m_spriteNum.Size = new System.Drawing.Size(64, 21);
+ this.m_spriteNum.TabIndex = 0;
+ this.m_spriteNum.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
+ this.m_spriteNum.ValueChanged += new System.EventHandler(this.OnSpriteSelected);
+ //
+ // m_about
+ //
+ this.m_about.Index = 0;
+ this.m_about.Text = "About";
+ this.m_about.Click += new System.EventHandler(this.OnAbout);
+ //
+ // m_addFrame
+ //
+ this.m_addFrame.Location = new System.Drawing.Point(144, 72);
+ this.m_addFrame.Name = "m_addFrame";
+ this.m_addFrame.Size = new System.Drawing.Size(64, 24);
+ this.m_addFrame.TabIndex = 6;
+ this.m_addFrame.Text = "Add";
+ this.m_addFrame.Click += new System.EventHandler(this.OnAddFrame);
+ //
+ // 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_frameNum
+ //
+ this.m_frameNum.Location = new System.Drawing.Point(64, 72);
+ this.m_frameNum.Name = "m_frameNum";
+ this.m_frameNum.ReadOnly = true;
+ this.m_frameNum.Size = new System.Drawing.Size(64, 21);
+ this.m_frameNum.TabIndex = 2;
+ this.m_frameNum.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
+ this.m_frameNum.ValueChanged += new System.EventHandler(this.OnFrameSelected);
+ //
+ // m_menu
+ //
+ this.m_menu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
+ this.m_fileMenu,
+ this.m_exportMenu,
+ this.m_helpMenu});
+ //
+ // MainForm
+ //
+ this.AutoScaleBaseSize = new System.Drawing.Size(5, 14);
+ this.ClientSize = new System.Drawing.Size(738, 351);
+ this.Controls.Add(this.m_animGroup);
+ this.Controls.Add(this.m_spriteGroup);
+ this.Controls.Add(this.m_editGroup);
+ this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
+ this.MaximizeBox = false;
+ this.Menu = this.m_menu;
+ this.Name = "MainForm";
+ this.Text = "Bitmap Sprite Editor";
+ this.m_spriteGroup.ResumeLayout(false);
+ ((System.ComponentModel.ISupportInitialize)(this.m_spriteNum)).EndInit();
+ ((System.ComponentModel.ISupportInitialize)(this.m_frameNum)).EndInit();
+ this.ResumeLayout(false);
+ }
+ #endregion
+
+ private Sprite SelectedSprite
+ {
+ get
+ {
+ int spr=Convert.ToInt32(m_spriteNum.Value);
+
+ return m_sprites[spr];
+ }
+ }
+
+ private Frame SelectedFrame
+ {
+ get
+ {
+ int frame=Convert.ToInt32(m_frameNum.Value);
+
+ return SelectedSprite[frame];
+ }
+ }
+
+ void OnNew(object sender, System.EventArgs e)
+ {
+ m_sprites=new SpriteList();
+ m_sprites.Add(new Sprite());
+
+ m_spriteNum.Maximum=0;
+ m_frameNum.Maximum=0;
+ m_spriteNum.Value=0;
+ OnSpriteSelected(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)
+ {
+ }
+
+ void OnAbout(object sender, System.EventArgs e)
+ {
+ Util.About();
+ }
+
+ void OnExportPNG(object sender, System.EventArgs e)
+ {
+ }
+
+ void OnAddSprite(object sender, System.EventArgs e)
+ {
+ m_sprites.Add(new Sprite());
+ m_spriteNum.Maximum=m_sprites.Count-1;
+ }
+
+ void OnRemoveSprite(object sender, System.EventArgs e)
+ {
+ }
+
+ void OnAddFrame(object sender, System.EventArgs e)
+ {
+ SelectedSprite.Add(new Frame(SelectedFrame));
+ m_frameNum.Maximum=SelectedSprite.Count-1;
+ }
+
+ void OnRemoveFrame(object sender, System.EventArgs e)
+ {
+ }
+
+ void OnSpriteNameKey(object sender, System.Windows.Forms.KeyPressEventArgs e)
+ {
+ if (!Sprite.IsValidNameChar(e.KeyChar) && e.KeyChar!='\b')
+ {
+ e.Handled=true;
+ return;
+ }
+ }
+
+ void OnSpriteName(object sender, System.EventArgs e)
+ {
+ SelectedSprite.Name=m_spriteName.Text;
+ }
+
+ void OnSpriteSelected(object sender, System.EventArgs e)
+ {
+ m_spriteName.Text=SelectedSprite.Name;
+ m_frameNum.Value=0;
+ m_frameNum.Maximum=SelectedSprite.Count-1;
+ OnFrameSelected(null,null);
+ }
+
+ void OnFrameSelected(object sender, System.EventArgs e)
+ {
+ m_edit.Frame=SelectedFrame;
+ }
+ }
+}
diff --git a/Sprite.cs b/Sprite.cs
new file mode 100644
index 0000000..47678e9
--- /dev/null
+++ b/Sprite.cs
@@ -0,0 +1,546 @@
+// BitmapSpriteEd - Bitmap Sprite Editor
+// 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;
+using System.Collections;
+
+namespace BitmapSpriteEd
+{
+ /// <summary>
+ /// A sprite frame.
+ /// </summary>
+ public class Frame
+ {
+ public Frame(int width, int height)
+ {
+ CheckSize(width,height);
+ m_width=width;
+ m_height=height;
+ m_data=new Color[m_width,m_height];
+ Clear(Color.Transparent);
+ m_changed=false;
+ }
+
+ public Frame() : this(16,16)
+ {
+ }
+
+ public Frame(Frame old)
+ {
+ m_width=old.m_width;
+ m_height=old.m_height;
+ m_data=new Color[m_width,m_height];
+
+ for(int x=0;x<m_width;x++)
+ {
+ for(int y=0;y<m_height;y++)
+ {
+ m_data[x,y]=old.m_data[x,y];
+ }
+ }
+
+ m_changed=old.m_changed;
+ }
+
+ public int Width
+ {
+ get {return m_width;}
+ }
+
+ public int Height
+ {
+ get {return m_height;}
+ }
+
+ public bool Changed
+ {
+ get {return m_changed;}
+ }
+
+ public void Resize(int width, int height)
+ {
+ CheckSize(width,height);
+
+ if (width==m_width && height==m_height)
+ {
+ return;
+ }
+
+ Color[,] data=new Color[width,height];
+
+ for(int y=0;y<height;y++)
+ {
+ for(int x=0;x<width;x++)
+ {
+ data[x,y]=Color.Transparent;
+ }
+ }
+
+ int mx=Math.Min(width,m_width);
+ int my=Math.Min(height,m_height);
+
+ for(int x=0;x<mx;x++)
+ {
+ for(int y=0;y<my;y++)
+ {
+ data[x,y]=m_data[x,y];
+ }
+ }
+
+ m_width=width;
+ m_height=height;
+ m_data=data;
+ m_changed=true;
+ }
+
+ public Color this [int x, int y]
+ {
+ set
+ {
+ m_data[x,y]=value;
+ m_changed=true;
+ }
+ get {return m_data[x,y];}
+ }
+
+ public void Clear(Color c)
+ {
+ for(int y=0;y<m_height;y++)
+ {
+ for(int x=0;x<m_width;x++)
+ {
+ m_data[x,y]=c;
+ }
+ }
+
+ m_changed=true;
+ }
+
+ public void MirrorHorizontal()
+ {
+ Color[,] d=new Color[m_width,m_height];
+
+ for(int y=0;y<m_height;y++)
+ for(int x=0;x<m_width;x++)
+ d[x,y]=m_data[m_width-x-1,y];
+
+ m_data=d;
+ m_changed=true;
+ }
+
+ public void MirrorVertical()
+ {
+ Color[,] d=new Color[m_width,m_height];
+
+ for(int y=0;y<m_height;y++)
+ for(int x=0;x<m_width;x++)
+ d[x,y]=m_data[x,m_height-y-1];
+
+ m_data=d;
+ m_changed=true;
+ }
+
+ public void Scroll(int dx, int dy)
+ {
+ Color[,] d=new Color[m_width,m_height];
+
+ for(int y=0;y<m_height;y++)
+ for(int x=0;x<m_width;x++)
+ d[Mod(x+dx,m_width),Mod(y+dy,m_height)]=m_data[x,y];
+
+ m_data=d;
+ m_changed=true;
+ }
+
+ public void RotateRight()
+ {
+ Color[,] d=new Color[m_width,m_height];
+ int min=Math.Min(m_width,m_height);
+
+ for(int y=0;y<m_height;y++)
+ for(int x=0;x<m_width;x++)
+ {
+ long nx=min-y-1;
+ long ny=x;
+
+ if (nx>=0 && nx<m_width && ny>=0 && ny<m_height)
+ {
+ d[nx,ny]=m_data[x,y];
+ }
+ }
+
+ m_data=d;
+ m_changed=true;
+ }
+
+ public void RotateLeft()
+ {
+ Color[,] d=new Color[m_width,m_height];
+ int min=Math.Min(m_width,m_height);
+
+ for(int y=0;y<m_height;y++)
+ for(int x=0;x<m_width;x++)
+ {
+ long nx=y;
+ long ny=min-x-1;
+
+ if (nx>=0 && nx<m_width && ny>=0 && ny<m_height)
+ {
+ d[nx,ny]=m_data[x,y];
+ }
+ }
+
+ m_data=d;
+ m_changed=true;
+ }
+
+ public void Output(Stream stream)
+ {
+ Util.WriteInt(stream,m_width);
+ Util.WriteInt(stream,m_height);
+
+ for(int x=0;x<m_width;x++)
+ {
+ for(int y=0;y<m_height;y++)
+ {
+ stream.WriteByte(m_data[x,y].B);
+ stream.WriteByte(m_data[x,y].G);
+ stream.WriteByte(m_data[x,y].R);
+ stream.WriteByte(m_data[x,y].A);
+ }
+ }
+
+ m_changed=false;
+ }
+
+ public static Frame Input(Stream stream)
+ {
+ int width=Util.ReadInt(stream);
+ int height=Util.ReadInt(stream);
+
+ Frame s=new Frame(width,height);
+
+ for(int x=0;x<width;x++)
+ {
+ for(int y=0;y<height;y++)
+ {
+ int B=stream.ReadByte();
+ int G=stream.ReadByte();
+ int R=stream.ReadByte();
+ int A=stream.ReadByte();
+
+ s[x,y]=Color.FromArgb(A,R,G,B);
+ }
+ }
+
+ s.m_changed=false;
+
+ return s;
+ }
+
+ // ------------------------------------------------
+ // PRIVATE
+ //
+ private int m_width;
+ private int m_height;
+ private Color[,] m_data;
+ private bool m_changed;
+
+ private void CheckSize(int width, int height)
+ {
+ if (width<0 || height<0)
+ {
+ throw new ArgumentException("Cannot use negative sizes");
+ }
+ }
+
+ private int Mod(int v, int m)
+ {
+ while (v<0)
+ {
+ v+=m;
+ }
+
+ return v%m;
+ }
+ }
+
+ /// <summary>
+ /// Describes a set of sprite frames that make up a single sprite
+ /// </summary>
+ public class Sprite : IEnumerable
+ {
+ // ------------------------------------------------
+ // PUBLIC
+ //
+ public Sprite()
+ {
+ m_changed=false;
+ m_name="Untitled";
+ m_frames=new ArrayList();
+ m_frames.Add(new Frame(16,16));
+ }
+
+ public IEnumerator GetEnumerator()
+ {
+ return m_frames.GetEnumerator();
+ }
+
+ public string Name
+ {
+ get {return m_name;}
+ set {m_name=value;}
+ }
+
+ public static bool IsValidNameChar(char c)
+ {
+ return (Char.IsLetterOrDigit(c) || c=='_');
+ }
+
+ public Frame this[int i]
+ {
+ get
+ {
+ return (Frame)m_frames[i];
+ }
+ set
+ {
+ m_frames[i]=value;
+ m_changed=true;
+ }
+ }
+
+ public void Add(Frame s)
+ {
+ m_frames.Add(s);
+ m_changed=true;
+ }
+
+ public void Remove(Frame s)
+ {
+ m_frames.Remove(s);
+ m_changed=true;
+ }
+
+ public bool Changed
+ {
+ get
+ {
+ if (!m_changed)
+ {
+ foreach (Frame s in m_frames)
+ {
+ if (s.Changed)
+ {
+ return true;
+ }
+ }
+ }
+
+ return m_changed;
+ }
+ set {m_changed=value;}
+ }
+
+ public int Count
+ {
+ get {return m_frames.Count;}
+ }
+
+ public void Output(Stream stream)
+ {
+ Util.WriteString(stream,m_name);
+ Util.WriteInt(stream,m_frames.Count);
+
+ foreach (Frame s in m_frames)
+ {
+ s.Output(stream);
+ }
+
+ m_changed=false;
+ }
+
+ public static Sprite Input(Stream stream)
+ {
+ Sprite fr=new Sprite();
+
+ fr.Name=Util.ReadString(stream);
+
+ int num=Util.ReadInt(stream);
+
+ for(int f=0;f<num;f++)
+ {
+ fr.Add(Frame.Input(stream));
+ }
+
+ fr.Changed=false;
+
+ return fr;
+ }
+
+ // ------------------------------------------------
+ // PRIVATE
+ //
+ private bool m_changed;
+ private string m_name;
+ private ArrayList m_frames;
+ }
+
+
+ /// <summary>
+ /// Describes a list of sprites
+ /// </summary>
+ public class SpriteList : IEnumerable
+ {
+ // ------------------------------------------------
+ // PUBLIC
+ //
+ public SpriteList()
+ {
+ m_changed=false;
+ m_list=new ArrayList();
+ }
+
+ public IEnumerator GetEnumerator()
+ {
+ return m_list.GetEnumerator();
+ }
+
+ public Sprite this[int i]
+ {
+ get
+ {
+ return (Sprite)m_list[i];
+ }
+ set
+ {
+ m_list[i]=value;
+ m_changed=true;
+ }
+ }
+
+ public void Add(Sprite s)
+ {
+ m_list.Add(s);
+ m_changed=true;
+ }
+
+ public void Remove(Sprite s)
+ {
+ m_list.Remove(s);
+ m_changed=true;
+ }
+
+ public bool Changed
+ {
+ get
+ {
+ if (!m_changed)
+ {
+ foreach (Sprite s in m_list)
+ {
+ if (s.Changed)
+ {
+ return true;
+ }
+ }
+ }
+
+ return m_changed;
+ }
+
+ set {m_changed=value;}
+ }
+
+ public int Count
+ {
+ get {return m_list.Count;}
+ }
+
+ public void Validate()
+ {
+ int num=m_list.Count;
+
+ for(int i=0;i<num;i++)
+ {
+ if (this[i].Name.Length==0)
+ {
+ throw new ApplicationException("Empty sprite name found");
+ }
+
+ for(int j=0;j<num;i++)
+ {
+ if (i!=j)
+ {
+ if (this[i].Name.ToLower()==this[j].Name.ToLower())
+ {
+ throw new ApplicationException
+ ("Sprite name " + this[i].Name + " is used more than once");
+ }
+ }
+ }
+ }
+ }
+
+ public void Output(Stream stream)
+ {
+ Util.WriteInt(stream,MAGIC);
+ Util.WriteInt(stream,m_list.Count);
+
+ foreach (Sprite s in m_list)
+ {
+ s.Output(stream);
+ }
+
+ m_changed=false;
+ }
+
+ public static SpriteList Input(Stream stream)
+ {
+ SpriteList l=new SpriteList();
+
+ int magic=Util.ReadInt(stream);
+
+ if (magic!=MAGIC)
+ {
+ throw new ApplicationException("Not a recognised sprite file");
+ }
+
+ int num=Util.ReadInt(stream);
+
+ for(int f=0;f<num;f++)
+ {
+ l.Add(Sprite.Input(stream));
+ }
+
+ l.Changed=false;
+
+ return l;
+ }
+
+ // ------------------------------------------------
+ // PRIVATE
+ //
+ private const int MAGIC=0x424d5331;
+ private bool m_changed;
+ private ArrayList m_list;
+ }
+}
diff --git a/Util.cs b/Util.cs
new file mode 100644
index 0000000..384ea3c
--- /dev/null
+++ b/Util.cs
@@ -0,0 +1,122 @@
+// BitmapSpriteEd - Bitmap Sprite Editor
+// 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.Windows.Forms;
+using System.Text;
+using System.IO;
+using System.Drawing;
+using System.Diagnostics;
+
+namespace BitmapSpriteEd
+{
+ /// <summary>
+ /// Usual utils and some state machine
+ /// </summary>
+ public class Util
+ {
+ public static bool YesNo(string s)
+ {
+ return MessageBox.Show(s,"Bitmap Sprite Editor",
+ MessageBoxButtons.YesNo,
+ MessageBoxIcon.Question)==DialogResult.Yes;
+ }
+
+ public static DialogResult YesNoCancel(string s)
+ {
+ return MessageBox.Show(s,"Bitmap Sprite Editor",
+ MessageBoxButtons.YesNoCancel,
+ MessageBoxIcon.Question);
+ }
+
+ public static void Message(string s)
+ {
+ MessageBox.Show(s,"Bitmap Sprite Editor",MessageBoxButtons.OK,MessageBoxIcon.Information);
+ }
+
+ public static void Error(string s)
+ {
+ MessageBox.Show(s,"Bitmap Sprite Editor - ERROR",MessageBoxButtons.OK,MessageBoxIcon.Error);
+ }
+
+ public static void About()
+ {
+ MessageBox.Show(m_about,"About Bitmap Sprite Editor",
+ MessageBoxButtons.OK,MessageBoxIcon.Information);
+ }
+
+ 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 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);
+
+ WriteInt(str,b.Length);
+ str.Write(b,0,b.Length);
+ }
+
+ public static string ReadString(Stream str)
+ {
+ int len=ReadInt(str);
+ byte[] b=new byte[len];
+
+ str.Read(b,0,len);
+ return Encoding.ASCII.GetString(b);
+ }
+
+ private Util()
+ {
+ }
+
+ private static string m_about=
+ "Bitmap Sprite Editor\n"+
+ "Copyright Ian Cowburn 2005\n\n"+
+ "This program is free software; you can redistribute it and/or\n"+
+ "modify it under the terms of the GNU General Public License\n"+
+ "as published by the Free Software Foundation; either version 2\n"+
+ "of the License, or (at your option) any later version.\n\n"+
+ "This program is distributed in the hope that it will be useful,\n"+
+ "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"+
+ "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"+
+ "GNU General Public License for more details.\n\n"+
+ "You should have received a copy of the GNU General Public License\n"+
+ "along with this program; if not, write to the Free Software\n"+
+ "Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.";
+ }
+}