// 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.Drawing.Imaging;
using System.Windows.Forms;
using System.IO;
namespace BitmapSpriteEd
{
///
/// Description of MainForm.
///
public class MainForm : System.Windows.Forms.Form
{
private System.ComponentModel.IContainer components;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.MenuItem m_helpMenu;
private System.Windows.Forms.Button m_removeFrame;
private System.Windows.Forms.Button m_addFrame;
private System.Windows.Forms.MenuItem m_break1;
private System.Windows.Forms.MenuItem m_fileMenu;
private System.Windows.Forms.Button m_addSprite;
private System.Windows.Forms.MenuItem m_exportSinglePNG;
private System.Windows.Forms.Label m_spriteCount;
private System.Windows.Forms.Button m_removeSprite;
private System.Windows.Forms.MenuItem m_importFramePNG;
private System.Windows.Forms.TextBox m_spriteName;
private System.Windows.Forms.MenuItem m_exportMenu;
private System.Windows.Forms.CheckBox m_addFrameAsCopy;
private System.Windows.Forms.MenuItem m_about;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.CheckBox m_animStretch;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.Timer m_timer;
private System.Windows.Forms.MainMenu m_menu;
private System.Windows.Forms.GroupBox m_animGroup;
private System.Windows.Forms.MenuItem m_importMenu;
private System.Windows.Forms.CheckBox m_animEnable;
private System.Windows.Forms.NumericUpDown m_animSpeed;
private System.Windows.Forms.MenuItem m_quit;
private System.Windows.Forms.MenuItem m_save;
private System.Windows.Forms.MenuItem m_exportPNG;
private System.Windows.Forms.MenuItem m_saveAs;
private System.Windows.Forms.CheckBox m_animPong;
private System.Windows.Forms.NumericUpDown m_spriteNum;
private System.Windows.Forms.GroupBox m_editGroup;
private System.Windows.Forms.MenuItem m_new;
private System.Windows.Forms.MenuItem m_open;
private System.Windows.Forms.PictureBox m_preview;
private System.Windows.Forms.Label m_frameCount;
private System.Windows.Forms.GroupBox m_spriteGroup;
private System.Windows.Forms.NumericUpDown m_frameNum;
private GfxEditor m_edit;
private SpriteList m_sprites;
private string m_path;
private string m_exportPath;
private string m_importPath;
private int m_animIndex;
private int m_animIndexInc=1;
public MainForm()
{
//
// The InitializeComponent() call is required for Windows Forms designer support.
//
InitializeComponent();
m_path="";
m_exportPath="";
m_importPath="";
m_sprites=new SpriteList();
m_edit=new GfxEditor();
m_edit.Location=new Point(4,16);
m_editGroup.Controls.Add(m_edit);
m_edit.FrameResize+=new GfxEditor.FrameResizeEventHandler(OnFrameResize);
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.components = new System.ComponentModel.Container();
this.m_frameNum = new System.Windows.Forms.NumericUpDown();
this.m_spriteGroup = new System.Windows.Forms.GroupBox();
this.m_frameCount = new System.Windows.Forms.Label();
this.m_preview = new System.Windows.Forms.PictureBox();
this.m_open = new System.Windows.Forms.MenuItem();
this.m_new = new System.Windows.Forms.MenuItem();
this.m_editGroup = new System.Windows.Forms.GroupBox();
this.m_spriteNum = new System.Windows.Forms.NumericUpDown();
this.m_animPong = new System.Windows.Forms.CheckBox();
this.m_saveAs = new System.Windows.Forms.MenuItem();
this.m_exportPNG = new System.Windows.Forms.MenuItem();
this.m_save = new System.Windows.Forms.MenuItem();
this.m_quit = new System.Windows.Forms.MenuItem();
this.m_animSpeed = new System.Windows.Forms.NumericUpDown();
this.m_animEnable = new System.Windows.Forms.CheckBox();
this.m_importMenu = new System.Windows.Forms.MenuItem();
this.m_animGroup = new System.Windows.Forms.GroupBox();
this.m_menu = new System.Windows.Forms.MainMenu();
this.m_timer = new System.Windows.Forms.Timer(this.components);
this.label4 = new System.Windows.Forms.Label();
this.m_animStretch = new System.Windows.Forms.CheckBox();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.m_about = new System.Windows.Forms.MenuItem();
this.m_addFrameAsCopy = new System.Windows.Forms.CheckBox();
this.m_exportMenu = new System.Windows.Forms.MenuItem();
this.m_spriteName = new System.Windows.Forms.TextBox();
this.m_importFramePNG = new System.Windows.Forms.MenuItem();
this.m_removeSprite = new System.Windows.Forms.Button();
this.m_spriteCount = new System.Windows.Forms.Label();
this.m_exportSinglePNG = new System.Windows.Forms.MenuItem();
this.m_addSprite = new System.Windows.Forms.Button();
this.m_fileMenu = new System.Windows.Forms.MenuItem();
this.m_break1 = new System.Windows.Forms.MenuItem();
this.m_addFrame = new System.Windows.Forms.Button();
this.m_removeFrame = new System.Windows.Forms.Button();
this.m_helpMenu = new System.Windows.Forms.MenuItem();
this.label1 = new System.Windows.Forms.Label();
((System.ComponentModel.ISupportInitialize)(this.m_frameNum)).BeginInit();
this.m_spriteGroup.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.m_spriteNum)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.m_animSpeed)).BeginInit();
this.m_animGroup.SuspendLayout();
this.SuspendLayout();
//
// m_frameNum
//
this.m_frameNum.Location = new System.Drawing.Point(64, 96);
this.m_frameNum.Minimum = new System.Decimal(new int[] {
1,
0,
0,
0});
this.m_frameNum.Name = "m_frameNum";
this.m_frameNum.ReadOnly = true;
this.m_frameNum.Size = new System.Drawing.Size(64, 20);
this.m_frameNum.TabIndex = 2;
this.m_frameNum.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
this.m_frameNum.Value = new System.Decimal(new int[] {
1,
0,
0,
0});
this.m_frameNum.ValueChanged += new System.EventHandler(this.OnFrameSelected);
//
// m_spriteGroup
//
this.m_spriteGroup.Controls.Add(this.m_addFrameAsCopy);
this.m_spriteGroup.Controls.Add(this.m_frameCount);
this.m_spriteGroup.Controls.Add(this.m_spriteCount);
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(288, 192);
this.m_spriteGroup.TabIndex = 1;
this.m_spriteGroup.TabStop = false;
this.m_spriteGroup.Text = "Sprite Frames";
//
// m_frameCount
//
this.m_frameCount.Location = new System.Drawing.Point(136, 104);
this.m_frameCount.Name = "m_frameCount";
this.m_frameCount.Size = new System.Drawing.Size(56, 16);
this.m_frameCount.TabIndex = 11;
this.m_frameCount.Text = "label5";
//
// m_preview
//
this.m_preview.BackColor = System.Drawing.Color.Black;
this.m_preview.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.m_preview.Location = new System.Drawing.Point(176, 24);
this.m_preview.Name = "m_preview";
this.m_preview.Size = new System.Drawing.Size(64, 64);
this.m_preview.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage;
this.m_preview.TabIndex = 3;
this.m_preview.TabStop = false;
//
// 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_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_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_spriteNum
//
this.m_spriteNum.Location = new System.Drawing.Point(64, 32);
this.m_spriteNum.Minimum = new System.Decimal(new int[] {
1,
0,
0,
0});
this.m_spriteNum.Name = "m_spriteNum";
this.m_spriteNum.ReadOnly = true;
this.m_spriteNum.Size = new System.Drawing.Size(64, 20);
this.m_spriteNum.TabIndex = 0;
this.m_spriteNum.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
this.m_spriteNum.Value = new System.Decimal(new int[] {
1,
0,
0,
0});
this.m_spriteNum.ValueChanged += new System.EventHandler(this.OnSpriteSelected);
//
// m_animPong
//
this.m_animPong.Location = new System.Drawing.Point(8, 48);
this.m_animPong.Name = "m_animPong";
this.m_animPong.Size = new System.Drawing.Size(120, 16);
this.m_animPong.TabIndex = 4;
this.m_animPong.Text = "Ping/Pong";
this.m_animPong.CheckedChanged += new System.EventHandler(this.OnAnimPingPong);
//
// 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_exportPNG
//
this.m_exportPNG.Index = 0;
this.m_exportPNG.Text = "Export to PNG";
this.m_exportPNG.Click += new System.EventHandler(this.OnExportPNG);
//
// 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_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_animSpeed
//
this.m_animSpeed.Location = new System.Drawing.Point(8, 96);
this.m_animSpeed.Maximum = new System.Decimal(new int[] {
50,
0,
0,
0});
this.m_animSpeed.Minimum = new System.Decimal(new int[] {
1,
0,
0,
0});
this.m_animSpeed.Name = "m_animSpeed";
this.m_animSpeed.ReadOnly = true;
this.m_animSpeed.Size = new System.Drawing.Size(48, 20);
this.m_animSpeed.TabIndex = 1;
this.m_animSpeed.Value = new System.Decimal(new int[] {
5,
0,
0,
0});
this.m_animSpeed.ValueChanged += new System.EventHandler(this.OnAnimSpeed);
//
// m_animEnable
//
this.m_animEnable.Location = new System.Drawing.Point(8, 24);
this.m_animEnable.Name = "m_animEnable";
this.m_animEnable.Size = new System.Drawing.Size(120, 16);
this.m_animEnable.TabIndex = 0;
this.m_animEnable.Text = "Preview Animation";
this.m_animEnable.CheckedChanged += new System.EventHandler(this.OnAnimEnable);
//
// m_importMenu
//
this.m_importMenu.Index = 2;
this.m_importMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.m_importFramePNG});
this.m_importMenu.Text = "Import";
//
// m_animGroup
//
this.m_animGroup.Controls.Add(this.m_animStretch);
this.m_animGroup.Controls.Add(this.m_animPong);
this.m_animGroup.Controls.Add(this.m_preview);
this.m_animGroup.Controls.Add(this.label4);
this.m_animGroup.Controls.Add(this.m_animSpeed);
this.m_animGroup.Controls.Add(this.m_animEnable);
this.m_animGroup.Location = new System.Drawing.Point(424, 208);
this.m_animGroup.Name = "m_animGroup";
this.m_animGroup.Size = new System.Drawing.Size(288, 128);
this.m_animGroup.TabIndex = 2;
this.m_animGroup.TabStop = false;
this.m_animGroup.Text = "Animation Preview";
//
// m_menu
//
this.m_menu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.m_fileMenu,
this.m_exportMenu,
this.m_importMenu,
this.m_helpMenu});
//
// m_timer
//
this.m_timer.Tick += new System.EventHandler(this.OnTimer);
//
// label4
//
this.label4.Location = new System.Drawing.Point(64, 104);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(104, 16);
this.label4.TabIndex = 2;
this.label4.Text = "/50 secs per frame";
//
// m_animStretch
//
this.m_animStretch.Location = new System.Drawing.Point(8, 72);
this.m_animStretch.Name = "m_animStretch";
this.m_animStretch.Size = new System.Drawing.Size(120, 16);
this.m_animStretch.TabIndex = 5;
this.m_animStretch.Text = "Stretch";
this.m_animStretch.CheckedChanged += new System.EventHandler(this.OnAnimStretch);
//
// label2
//
this.label2.Location = new System.Drawing.Point(8, 96);
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, 160);
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_about
//
this.m_about.Index = 0;
this.m_about.Text = "About...";
this.m_about.Click += new System.EventHandler(this.OnAbout);
//
// m_addFrameAsCopy
//
this.m_addFrameAsCopy.Location = new System.Drawing.Point(64, 128);
this.m_addFrameAsCopy.Name = "m_addFrameAsCopy";
this.m_addFrameAsCopy.Size = new System.Drawing.Size(128, 16);
this.m_addFrameAsCopy.TabIndex = 12;
this.m_addFrameAsCopy.Text = "New Frame as Copy";
//
// m_exportMenu
//
this.m_exportMenu.Index = 1;
this.m_exportMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.m_exportPNG,
this.m_exportSinglePNG});
this.m_exportMenu.Text = "Export";
//
// m_spriteName
//
this.m_spriteName.Location = new System.Drawing.Point(64, 160);
this.m_spriteName.Name = "m_spriteName";
this.m_spriteName.Size = new System.Drawing.Size(208, 20);
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_importFramePNG
//
this.m_importFramePNG.Index = 0;
this.m_importFramePNG.Text = "Import Frame from Image File";
this.m_importFramePNG.Click += new System.EventHandler(this.OnImportFramePNG);
//
// m_removeSprite
//
this.m_removeSprite.Location = new System.Drawing.Point(200, 48);
this.m_removeSprite.Name = "m_removeSprite";
this.m_removeSprite.Size = new System.Drawing.Size(72, 24);
this.m_removeSprite.TabIndex = 5;
this.m_removeSprite.Text = "Remove";
this.m_removeSprite.Click += new System.EventHandler(this.OnRemoveSprite);
//
// m_spriteCount
//
this.m_spriteCount.Location = new System.Drawing.Point(136, 40);
this.m_spriteCount.Name = "m_spriteCount";
this.m_spriteCount.Size = new System.Drawing.Size(56, 16);
this.m_spriteCount.TabIndex = 10;
this.m_spriteCount.Text = "label5";
//
// m_exportSinglePNG
//
this.m_exportSinglePNG.Index = 1;
this.m_exportSinglePNG.Text = "Export to Single PNG";
this.m_exportSinglePNG.Click += new System.EventHandler(this.OnExportSinglePNG);
//
// m_addSprite
//
this.m_addSprite.Location = new System.Drawing.Point(200, 16);
this.m_addSprite.Name = "m_addSprite";
this.m_addSprite.Size = new System.Drawing.Size(72, 24);
this.m_addSprite.TabIndex = 4;
this.m_addSprite.Text = "Add";
this.m_addSprite.Click += new System.EventHandler(this.OnAddSprite);
//
// 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_break1
//
this.m_break1.Index = 4;
this.m_break1.Text = "-";
//
// m_addFrame
//
this.m_addFrame.Location = new System.Drawing.Point(200, 80);
this.m_addFrame.Name = "m_addFrame";
this.m_addFrame.Size = new System.Drawing.Size(72, 24);
this.m_addFrame.TabIndex = 6;
this.m_addFrame.Text = "Add";
this.m_addFrame.Click += new System.EventHandler(this.OnAddFrame);
//
// m_removeFrame
//
this.m_removeFrame.Location = new System.Drawing.Point(200, 112);
this.m_removeFrame.Name = "m_removeFrame";
this.m_removeFrame.Size = new System.Drawing.Size(72, 24);
this.m_removeFrame.TabIndex = 7;
this.m_removeFrame.Text = "Remove";
this.m_removeFrame.Click += new System.EventHandler(this.OnRemoveFrame);
//
// m_helpMenu
//
this.m_helpMenu.Index = 3;
this.m_helpMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.m_about});
this.m_helpMenu.Text = "Help";
//
// 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;
//
// MainForm
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(722, 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.Closing += new System.ComponentModel.CancelEventHandler(this.OnClosing);
((System.ComponentModel.ISupportInitialize)(this.m_frameNum)).EndInit();
this.m_spriteGroup.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.m_spriteNum)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.m_animSpeed)).EndInit();
this.m_animGroup.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private Sprite SelectedSprite
{
get
{
int spr=Convert.ToInt32(m_spriteNum.Value)-1;
return m_sprites[spr];
}
}
private Frame SelectedFrame
{
get
{
int frame=Convert.ToInt32(m_frameNum.Value)-1;
return SelectedSprite[frame];
}
}
private bool EditChanged
{
get {return m_edit.Frame!=null && m_edit.Frame.Changed;}
}
private bool ChangesAllowed
{
get {return (!m_sprites.Changed && !EditChanged) || Util.YesNo("Abandon changes?");}
}
private void UpdateInfo()
{
m_spriteCount.Text="of "+m_sprites.Count;
m_frameCount.Text="of "+SelectedSprite.Count;
m_removeSprite.Enabled=(m_sprites.Count>1);
m_removeFrame.Enabled=(SelectedSprite.Count>1);
}
private void OnFrameResize(object sender, GfxEditor.FrameResizeEventArgs e)
{
foreach (Frame f in SelectedSprite)
{
if (f!=m_edit.Frame)
{
f.Resize(e.Width,e.Height);
}
}
}
void OnNew(object sender, System.EventArgs e)
{
if (ChangesAllowed)
{
m_sprites=new SpriteList();
m_sprites.Add(new Sprite());
m_sprites.Changed=false;
m_save.Enabled=false;
m_animIndex=0;
m_animIndexInc=1;
m_spriteNum.Maximum=1;
m_frameNum.Maximum=1;
m_spriteNum.Value=1;
OnSpriteSelected(null,null);
}
}
void OnOpen(object sender, System.EventArgs e)
{
if (ChangesAllowed)
{
OpenFileDialog fsel=new OpenFileDialog();
fsel.FileName=m_path;
fsel.Filter="Bitmap Sprite Files (*.bms)|*.bms|All files (*.*)|*.*";
if (fsel.ShowDialog()==DialogResult.OK)
{
using(FileStream str=File.Open(fsel.FileName,FileMode.Open))
{
try
{
m_sprites=SpriteList.Input(str);
str.Close();
m_spriteNum.Value=1;
m_spriteNum.Maximum=m_sprites.Count;
OnSpriteSelected(null,null);
m_path=fsel.FileName;
m_save.Enabled=true;
}
catch (Exception ex)
{
Util.Error("Error opening " + fsel.FileName + ":\n" + ex.Message);
}
}
}
}
}
void OnSave(object sender, System.EventArgs e)
{
using(FileStream str=File.Open(m_path,FileMode.Create))
{
try
{
m_sprites.Output(str);
str.Close();
}
catch (Exception ex)
{
Util.Error("Error writing " + m_path + ":\n" + ex.Message);
}
}
}
void OnSaveAs(object sender, System.EventArgs e)
{
SaveFileDialog fsel=new SaveFileDialog();
fsel.FileName=m_path;
fsel.Filter="Bitmap Sprite Files (*.bms)|*.bms|All files (*.*)|*.*";
if (fsel.ShowDialog()==DialogResult.OK)
{
using(FileStream str=File.Open(fsel.FileName,FileMode.Create))
{
try
{
m_sprites.Output(str);
str.Close();
m_path=fsel.FileName;
m_save.Enabled=true;
}
catch (Exception ex)
{
Util.Error("Error writing " + fsel.FileName + ":\n" + ex.Message);
}
}
}
}
void OnQuit(object sender, System.EventArgs e)
{
Close();
}
void OnAbout(object sender, System.EventArgs e)
{
Util.About();
}
void OnExportPNG(object sender, System.EventArgs e)
{
try
{
m_sprites.Validate();
}
catch (ApplicationException ex)
{
Util.Error(ex.Message);
return;
}
FolderBrowserDialog fsel=new FolderBrowserDialog();
fsel.ShowNewFolderButton=true;
fsel.Description="Select folder to ouput PNG files to";
fsel.SelectedPath=m_exportPath;
if (fsel.ShowDialog()==DialogResult.OK)
{
try
{
foreach(Sprite s in m_sprites)
{
using (Bitmap bmp=new Bitmap(s[0].Width*s.Count,s[0].Height,PixelFormat.Format32bppArgb))
{
using (Graphics g=Graphics.FromImage(bmp))
{
string fname=fsel.SelectedPath +
Path.DirectorySeparatorChar +
s.Name + ".png";
int x=0;
foreach (Frame f in s)
{
g.DrawImageUnscaled(f.Bitmap,x,0);
x+=f.Width;
}
bmp.Save(fname,ImageFormat.Png);
}
}
}
m_exportPath=fsel.SelectedPath;
}
catch (Exception ex)
{
Util.Error("Error writing to " + fsel.SelectedPath + ":\n" + ex.Message);
}
}
}
void OnExportSinglePNG(object sender, System.EventArgs e)
{
SaveFileDialog fsel=new SaveFileDialog();
fsel.Filter="PNG Files (*.png)|*.png|All files (*.*)|*.*";
if (fsel.ShowDialog()==DialogResult.OK)
{
int height=0;
int width=0;
foreach (Sprite s in m_sprites)
{
height+=s[0].Height;
width=Math.Max(width,s[0].Width*s.Count);
}
try
{
using (Bitmap bmp=new Bitmap(width,height,PixelFormat.Format32bppArgb))
{
using (Graphics g=Graphics.FromImage(bmp))
{
int y=0;
foreach(Sprite s in m_sprites)
{
int x=0;
foreach (Frame f in s)
{
g.DrawImageUnscaled(f.Bitmap,x,y);
x+=f.Width;
}
y+=s[0].Height;
}
bmp.Save(fsel.FileName,ImageFormat.Png);
}
}
}
catch (Exception ex)
{
Util.Error("Error writing " + fsel.FileName + ":\n" + ex.Message);
}
}
}
void OnImportFramePNG(object sender, System.EventArgs e)
{
OpenFileDialog fsel=new OpenFileDialog();
fsel.FileName=m_importPath;
fsel.Filter="Image Files (*.png;*.bmp;*.gif;*.jpg)|*.png;*.bmp;*.gif;*.jpg|All files (*.*)|*.*";
if (fsel.ShowDialog()==DialogResult.OK)
{
try
{
Cursor=Cursors.WaitCursor;
Frame frame=SelectedFrame;
using (Bitmap bmp=new Bitmap(fsel.FileName))
{
if (bmp.Width>frame.Width || bmp.Height>frame.Height)
{
if (Util.YesNo("Shrink image (Selecting No will crop to top left)?"))
{
using (Bitmap tmp=new Bitmap(bmp))
{
using (Graphics g=Graphics.FromImage(bmp))
{
g.DrawImage
(tmp,
new Rectangle
(0,0,frame.Width,frame.Height));
}
}
}
}
for(int x=0;x=SelectedSprite.Count-1)
{
m_animIndex=SelectedSprite.Count-1;
m_animIndexInc=-1;
}
}
else
{
if (m_animIndex==SelectedSprite.Count)
{
m_animIndex=0;
}
}
m_preview.Image=SelectedSprite[m_animIndex].Bitmap;
if (m_animPong.Checked)
{
m_animIndex+=m_animIndexInc;
}
else
{
m_animIndex++;
}
}
void OnAnimEnable(object sender, System.EventArgs e)
{
m_animIndex=0;
m_animIndexInc=1;
m_timer.Enabled=m_animEnable.Checked;
}
void OnAnimPingPong(object sender, System.EventArgs e)
{
m_animIndex=0;
m_animIndexInc=1;
}
void OnAnimSpeed(object sender, System.EventArgs e)
{
m_timer.Interval=20*Convert.ToInt32(m_animSpeed.Value);
}
void OnAnimStretch(object sender, System.EventArgs e)
{
if (m_animStretch.Checked)
{
m_preview.SizeMode=PictureBoxSizeMode.StretchImage;
}
else
{
m_preview.SizeMode=PictureBoxSizeMode.CenterImage;
}
}
void OnClosing(object sender, System.ComponentModel.CancelEventArgs e)
{
if (!ChangesAllowed)
{
e.Cancel=true;
}
}
}
}