summaryrefslogtreecommitdiff
path: root/MainForm.cs
blob: 13da6d8150d377a30a87806788e9e6693144c9f8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
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;
		}
	}
}