From 63f5209cf4c5e1ee36f4bd32948e582cd051d065 Mon Sep 17 00:00:00 2001 From: Ian C Date: Sat, 12 Nov 2005 00:35:55 +0000 Subject: Added importing of images --- MainForm.cs | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 78 insertions(+), 2 deletions(-) (limited to 'MainForm.cs') diff --git a/MainForm.cs b/MainForm.cs index 18ffb97..5b9a1df 100644 --- a/MainForm.cs +++ b/MainForm.cs @@ -41,6 +41,7 @@ namespace BitmapSpriteEd 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; @@ -52,6 +53,7 @@ namespace BitmapSpriteEd 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; @@ -72,6 +74,7 @@ namespace BitmapSpriteEd 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; @@ -84,6 +87,7 @@ namespace BitmapSpriteEd m_path=""; m_exportPath=""; + m_importPath=""; m_sprites=new SpriteList(); m_edit=new GfxEditor(); @@ -124,6 +128,7 @@ namespace BitmapSpriteEd 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); @@ -135,6 +140,7 @@ namespace BitmapSpriteEd 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(); @@ -326,6 +332,13 @@ namespace BitmapSpriteEd 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); @@ -346,6 +359,7 @@ namespace BitmapSpriteEd this.m_menu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { this.m_fileMenu, this.m_exportMenu, + this.m_importMenu, this.m_helpMenu}); // // m_timer @@ -390,7 +404,7 @@ namespace BitmapSpriteEd // m_about // this.m_about.Index = 0; - this.m_about.Text = "About"; + this.m_about.Text = "About..."; this.m_about.Click += new System.EventHandler(this.OnAbout); // // m_addFrameAsCopy @@ -420,6 +434,12 @@ namespace BitmapSpriteEd 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); @@ -489,7 +509,7 @@ namespace BitmapSpriteEd // // m_helpMenu // - this.m_helpMenu.Index = 2; + this.m_helpMenu.Index = 3; this.m_helpMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { this.m_about}); this.m_helpMenu.Text = "Help"; @@ -781,6 +801,62 @@ namespace BitmapSpriteEd } } + 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