summaryrefslogtreecommitdiff
path: root/PaletteForm.cs
blob: b24824bf0d6658fda816430619c6eb8c2eec8609 (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
// GfxEd8
// Copyright (C) 2004  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.Windows.Forms;
using GfxEdInterface;

namespace GfxEd8
{
	/// <summary>
	/// Description of PaletteForm.	
	/// </summary>
	public class PaletteForm : System.Windows.Forms.Form
	{
		private System.Windows.Forms.NumericUpDown m_index;
		private System.Windows.Forms.Label m_warning;
		private System.Windows.Forms.Button m_cancel;
		private System.Windows.Forms.Label m_col;
		private System.Windows.Forms.ComboBox m_pal;
		private System.Windows.Forms.Button m_ok;
		
		private IPlugin		m_plugin;
		private Sprite		m_sprite;

		public PaletteForm(IPlugin plugin, Sprite s)
		{
			//
			// The InitializeComponent() call is required for Windows Forms designer support.
			//
			InitializeComponent();
			
			m_plugin=plugin;
			m_sprite=s;
			
			CancelButton=m_cancel;
			
			foreach (Colour c in m_plugin.Palette)
			{
				m_pal.Items.Add(c);
			}
			
			m_index.Minimum=0;
			m_index.Maximum=m_plugin.MaxColours-1;
			m_index.Value=1;
		}
		
		public Sprite Sprite
		{
			get {return m_sprite;}
		}
		
		#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_ok = new System.Windows.Forms.Button();
			this.m_pal = new System.Windows.Forms.ComboBox();
			this.m_col = new System.Windows.Forms.Label();
			this.m_cancel = new System.Windows.Forms.Button();
			this.m_warning = new System.Windows.Forms.Label();
			this.m_index = new System.Windows.Forms.NumericUpDown();
			((System.ComponentModel.ISupportInitialize)(this.m_index)).BeginInit();
			this.SuspendLayout();
			// 
			// m_ok
			// 
			this.m_ok.Location = new System.Drawing.Point(160, 64);
			this.m_ok.Name = "m_ok";
			this.m_ok.Size = new System.Drawing.Size(88, 24);
			this.m_ok.TabIndex = 0;
			this.m_ok.Text = "OK";
			this.m_ok.Click += new System.EventHandler(this.OnOK);
			// 
			// m_pal
			// 
			this.m_pal.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
			this.m_pal.Location = new System.Drawing.Point(80, 24);
			this.m_pal.Name = "m_pal";
			this.m_pal.Size = new System.Drawing.Size(192, 21);
			this.m_pal.TabIndex = 3;
			this.m_pal.SelectedIndexChanged += new System.EventHandler(this.OnSelectColour);
			// 
			// m_col
			// 
			this.m_col.Location = new System.Drawing.Point(280, 16);
			this.m_col.Name = "m_col";
			this.m_col.Size = new System.Drawing.Size(64, 40);
			this.m_col.TabIndex = 4;
			// 
			// m_cancel
			// 
			this.m_cancel.Location = new System.Drawing.Point(256, 64);
			this.m_cancel.Name = "m_cancel";
			this.m_cancel.Size = new System.Drawing.Size(88, 24);
			this.m_cancel.TabIndex = 1;
			this.m_cancel.Text = "Cancel";
			this.m_cancel.Click += new System.EventHandler(this.OnCancel);
			// 
			// m_warning
			// 
			this.m_warning.Location = new System.Drawing.Point(8, 48);
			this.m_warning.Name = "m_warning";
			this.m_warning.Size = new System.Drawing.Size(144, 40);
			this.m_warning.TabIndex = 5;
			this.m_warning.Text = "label1";
			// 
			// m_index
			// 
			this.m_index.Location = new System.Drawing.Point(8, 24);
			this.m_index.Name = "m_index";
			this.m_index.Size = new System.Drawing.Size(56, 20);
			this.m_index.TabIndex = 2;
			this.m_index.ValueChanged += new System.EventHandler(this.OnSelectIndex);
			// 
			// PaletteForm
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(354, 95);
			this.ControlBox = false;
			this.Controls.Add(this.m_warning);
			this.Controls.Add(this.m_col);
			this.Controls.Add(this.m_pal);
			this.Controls.Add(this.m_index);
			this.Controls.Add(this.m_cancel);
			this.Controls.Add(this.m_ok);
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
			this.MaximizeBox = false;
			this.MinimizeBox = false;
			this.Name = "PaletteForm";
			this.ShowInTaskbar = false;
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
			this.Text = "Edit Sprite Palette";
			((System.ComponentModel.ISupportInitialize)(this.m_index)).EndInit();
			this.ResumeLayout(false);
		}
		#endregion

		void OnSelectIndex(object sender, System.EventArgs e)
		{
			uint i=(uint)m_index.Value;
			
			m_pal.SelectedIndex=(int)m_sprite.Pal(i);
			
			m_pal.Enabled=m_plugin.SprPalEditable[i];
			
			if (m_pal.Enabled && m_plugin.SprPalCommon[i])
			{
				m_warning.Text="WARNING:\nThis colour is common amongst all sprites";
			}
			else
			{
				m_warning.Text="";
			}
		}
		
		void OnSelectColour(object sender, System.EventArgs e)
		{
			uint i=(uint)m_pal.SelectedIndex;
			
			if (m_index.Value!=0 && i==0)
			{
				Util.Message("The background colour cannot be used\n"+
				             "for anything but the background");
				m_pal.SelectedIndex=1;
			}
			
			Colour c=(Colour)m_pal.Items[m_pal.SelectedIndex];
			
			m_sprite.Pal((uint)m_index.Value,(uint)m_pal.SelectedIndex);
			m_col.BackColor=c.DrawCol;
		}
		
		void OnOK(object sender, System.EventArgs e)
		{
			DialogResult=DialogResult.OK;
			Close();
		}
		
		void OnCancel(object sender, System.EventArgs e)
		{
			DialogResult=DialogResult.Cancel;
			Close();
		}
		
	}
}