From 93ac9c657ce285c5daa5a3ea6ed8c91b50e0281c Mon Sep 17 00:00:00 2001 From: Ian C Date: Sat, 30 Jul 2005 01:55:41 +0000 Subject: Development checkin --- MainForm.cs | 456 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 456 insertions(+) create mode 100644 MainForm.cs (limited to 'MainForm.cs') 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 +{ + /// + /// Description of MainForm. + /// + 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 + /// + /// This method is required for Windows Forms designer support. + /// Do not change the method contents inside the source code editor. The Forms designer might + /// not be able to load this method if it was changed manually. + /// + private void InitializeComponent() { + this.m_helpMenu = new System.Windows.Forms.MenuItem(); + this.m_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; + } + } +} -- cgit v1.2.3