summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan C <ianc@noddybox.co.uk>2005-11-12 00:35:55 +0000
committerIan C <ianc@noddybox.co.uk>2005-11-12 00:35:55 +0000
commit63f5209cf4c5e1ee36f4bd32948e582cd051d065 (patch)
treea0c88fd3424eeefdb46c9d6ce53eb6a0a9c63db0
parentfb9f2ab945ec9795905eb738e115a05354cd6c58 (diff)
Added importing of images
-rw-r--r--BitmapSpriteEd.MainForm.resourcesbin16803 -> 17379 bytes
-rw-r--r--GfxEditor.cs5
-rw-r--r--MainForm.cs80
3 files changed, 83 insertions, 2 deletions
diff --git a/BitmapSpriteEd.MainForm.resources b/BitmapSpriteEd.MainForm.resources
index fff1e6f..5440cc3 100644
--- a/BitmapSpriteEd.MainForm.resources
+++ b/BitmapSpriteEd.MainForm.resources
Binary files differ
diff --git a/GfxEditor.cs b/GfxEditor.cs
index 25578b9..0e307eb 100644
--- a/GfxEditor.cs
+++ b/GfxEditor.cs
@@ -656,6 +656,11 @@ namespace BitmapSpriteEd
get {return m_bgPreview.BackColor;}
}
+ public void ForceRedraw()
+ {
+ RedrawChar();
+ }
+
#endregion
// -------------------------------------------------------
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<Math.Min(frame.Width,bmp.Width);x++)
+ {
+ for(int y=0;y<Math.Min(frame.Height,bmp.Height);y++)
+ {
+ frame[x,y]=bmp.GetPixel(x,y);
+ }
+ }
+
+ m_importPath=fsel.FileName;
+ m_edit.ForceRedraw();
+
+ Cursor=Cursors.Default;
+ }
+ }
+ catch (Exception ex)
+ {
+ Cursor=Cursors.Default;
+ Util.Error("Error importing " + fsel.FileName + ":\n" + ex.Message);
+ }
+ }
+ }
+
void OnAddSprite(object sender, System.EventArgs e)
{
m_timer.Enabled=false;