// 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
{
///
/// Description of AlphaColourDialog.
///
public class AlphaColourDialog : System.Windows.Forms.Form
{
private System.Windows.Forms.ComboBox m_named;
private System.Windows.Forms.Label m_common4;
private System.Windows.Forms.Label m_common3;
private System.Windows.Forms.Label m_common5;
private System.Windows.Forms.TextBox m_red;
private System.Windows.Forms.Label m_common7;
private System.Windows.Forms.TrackBar m_greenSlider;
private System.Windows.Forms.TextBox m_alpha;
private System.Windows.Forms.Label m_preview;
private System.Windows.Forms.TrackBar m_redSlider;
private System.Windows.Forms.TrackBar m_alphaSlider;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox m_green;
private System.Windows.Forms.TrackBar m_blueSlider;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.TextBox m_blue;
private System.Windows.Forms.Label m_common8;
private System.Windows.Forms.Label label6;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.Label m_common2;
private System.Windows.Forms.Button m_ok;
private System.Windows.Forms.Button m_cancel;
private System.Windows.Forms.Label m_common1;
private System.Windows.Forms.Label m_common6;
private bool m_allowAlpha;
public AlphaColourDialog(string title)
{
//
// The InitializeComponent() call is required for Windows Forms designer support.
//
InitializeComponent();
Text=title;
foreach (KnownColor col in Enum.GetValues(typeof(KnownColor)))
{
if (Color.FromKnownColor(col).A==255)
{
m_named.Items.Add(col.ToString());
}
}
m_allowAlpha=true;
Color=Color.White;
}
public Color Color
{
get
{
return m_preview.BackColor;
}
set
{
m_redSlider.Value=value.R;
m_greenSlider.Value=value.G;
m_blueSlider.Value=value.B;
if (m_allowAlpha)
{
m_alphaSlider.Value=value.A;
}
else
{
m_alphaSlider.Value=255;
}
SetColour();
}
}
public bool AllowAlpha
{
set
{
m_allowAlpha=value;
m_alphaSlider.Visible=false;
}
}
private void SetColour()
{
m_red.Text=m_redSlider.Value.ToString();
m_green.Text=m_greenSlider.Value.ToString();
m_blue.Text=m_blueSlider.Value.ToString();
m_alpha.Text=m_alphaSlider.Value.ToString();
m_preview.BackColor=Color.FromArgb(m_alphaSlider.Value,
m_redSlider.Value,
m_greenSlider.Value,
m_blueSlider.Value);
}
#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.m_common6 = new System.Windows.Forms.Label();
this.m_common1 = new System.Windows.Forms.Label();
this.m_cancel = new System.Windows.Forms.Button();
this.m_ok = new System.Windows.Forms.Button();
this.m_common2 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.label5 = new System.Windows.Forms.Label();
this.label6 = new System.Windows.Forms.Label();
this.m_common8 = new System.Windows.Forms.Label();
this.m_blue = new System.Windows.Forms.TextBox();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.m_blueSlider = new System.Windows.Forms.TrackBar();
this.m_green = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.m_alphaSlider = new System.Windows.Forms.TrackBar();
this.m_redSlider = new System.Windows.Forms.TrackBar();
this.m_preview = new System.Windows.Forms.Label();
this.m_alpha = new System.Windows.Forms.TextBox();
this.m_greenSlider = new System.Windows.Forms.TrackBar();
this.m_common7 = new System.Windows.Forms.Label();
this.m_red = new System.Windows.Forms.TextBox();
this.m_common5 = new System.Windows.Forms.Label();
this.m_common3 = new System.Windows.Forms.Label();
this.m_common4 = new System.Windows.Forms.Label();
this.m_named = new System.Windows.Forms.ComboBox();
((System.ComponentModel.ISupportInitialize)(this.m_blueSlider)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.m_alphaSlider)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.m_redSlider)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.m_greenSlider)).BeginInit();
this.SuspendLayout();
//
// m_common6
//
this.m_common6.BackColor = System.Drawing.Color.Yellow;
this.m_common6.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.m_common6.Location = new System.Drawing.Point(56, 240);
this.m_common6.Name = "m_common6";
this.m_common6.Size = new System.Drawing.Size(24, 24);
this.m_common6.TabIndex = 21;
this.m_common6.Click += new System.EventHandler(this.OnCommon);
//
// m_common1
//
this.m_common1.BackColor = System.Drawing.Color.Black;
this.m_common1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.m_common1.Location = new System.Drawing.Point(16, 208);
this.m_common1.Name = "m_common1";
this.m_common1.Size = new System.Drawing.Size(24, 24);
this.m_common1.TabIndex = 16;
this.m_common1.Click += new System.EventHandler(this.OnCommon);
//
// m_cancel
//
this.m_cancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.m_cancel.Location = new System.Drawing.Point(296, 328);
this.m_cancel.Name = "m_cancel";
this.m_cancel.Size = new System.Drawing.Size(104, 24);
this.m_cancel.TabIndex = 13;
this.m_cancel.Text = "Cancel";
//
// m_ok
//
this.m_ok.Location = new System.Drawing.Point(184, 328);
this.m_ok.Name = "m_ok";
this.m_ok.Size = new System.Drawing.Size(104, 24);
this.m_ok.TabIndex = 12;
this.m_ok.Text = "OK";
this.m_ok.Click += new System.EventHandler(this.OnOK);
//
// m_common2
//
this.m_common2.BackColor = System.Drawing.Color.White;
this.m_common2.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.m_common2.Location = new System.Drawing.Point(56, 208);
this.m_common2.Name = "m_common2";
this.m_common2.Size = new System.Drawing.Size(24, 24);
this.m_common2.TabIndex = 17;
this.m_common2.Click += new System.EventHandler(this.OnCommon);
//
// label4
//
this.label4.Location = new System.Drawing.Point(352, 0);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(56, 24);
this.label4.TabIndex = 7;
this.label4.Text = "Alpha";
this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// label5
//
this.label5.Location = new System.Drawing.Point(8, 192);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(128, 16);
this.label5.TabIndex = 15;
this.label5.Text = "Primary Colours:";
//
// label6
//
this.label6.Location = new System.Drawing.Point(8, 280);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(128, 16);
this.label6.TabIndex = 24;
this.label6.Text = "Named Colours:";
//
// m_common8
//
this.m_common8.BackColor = System.Drawing.Color.Cyan;
this.m_common8.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.m_common8.Location = new System.Drawing.Point(136, 240);
this.m_common8.Name = "m_common8";
this.m_common8.Size = new System.Drawing.Size(24, 24);
this.m_common8.TabIndex = 23;
this.m_common8.Click += new System.EventHandler(this.OnCommon);
//
// m_blue
//
this.m_blue.Location = new System.Drawing.Point(304, 296);
this.m_blue.MaxLength = 3;
this.m_blue.Name = "m_blue";
this.m_blue.ReadOnly = true;
this.m_blue.Size = new System.Drawing.Size(40, 20);
this.m_blue.TabIndex = 10;
this.m_blue.Text = "textBox1";
//
// label2
//
this.label2.Location = new System.Drawing.Point(240, 0);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(56, 24);
this.label2.TabIndex = 3;
this.label2.Text = "Green";
this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// label3
//
this.label3.Location = new System.Drawing.Point(296, 0);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(56, 24);
this.label3.TabIndex = 5;
this.label3.Text = "Blue";
this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// m_blueSlider
//
this.m_blueSlider.Location = new System.Drawing.Point(304, 24);
this.m_blueSlider.Maximum = 255;
this.m_blueSlider.Name = "m_blueSlider";
this.m_blueSlider.Orientation = System.Windows.Forms.Orientation.Vertical;
this.m_blueSlider.Size = new System.Drawing.Size(42, 264);
this.m_blueSlider.TabIndex = 4;
this.m_blueSlider.TickFrequency = 5;
this.m_blueSlider.Scroll += new System.EventHandler(this.OnBlue);
//
// m_green
//
this.m_green.Location = new System.Drawing.Point(248, 296);
this.m_green.MaxLength = 3;
this.m_green.Name = "m_green";
this.m_green.ReadOnly = true;
this.m_green.Size = new System.Drawing.Size(40, 20);
this.m_green.TabIndex = 9;
this.m_green.Text = "textBox1";
//
// label1
//
this.label1.Location = new System.Drawing.Point(184, 0);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(56, 24);
this.label1.TabIndex = 1;
this.label1.Text = "Red";
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// m_alphaSlider
//
this.m_alphaSlider.Location = new System.Drawing.Point(360, 24);
this.m_alphaSlider.Maximum = 255;
this.m_alphaSlider.Name = "m_alphaSlider";
this.m_alphaSlider.Orientation = System.Windows.Forms.Orientation.Vertical;
this.m_alphaSlider.Size = new System.Drawing.Size(42, 264);
this.m_alphaSlider.TabIndex = 6;
this.m_alphaSlider.TickFrequency = 5;
this.m_alphaSlider.Value = 255;
this.m_alphaSlider.Scroll += new System.EventHandler(this.OnAlpha);
//
// m_redSlider
//
this.m_redSlider.Location = new System.Drawing.Point(192, 24);
this.m_redSlider.Maximum = 255;
this.m_redSlider.Name = "m_redSlider";
this.m_redSlider.Orientation = System.Windows.Forms.Orientation.Vertical;
this.m_redSlider.Size = new System.Drawing.Size(42, 264);
this.m_redSlider.TabIndex = 0;
this.m_redSlider.TickFrequency = 5;
this.m_redSlider.Scroll += new System.EventHandler(this.OnRed);
//
// m_preview
//
this.m_preview.BackColor = System.Drawing.Color.Black;
this.m_preview.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.m_preview.Location = new System.Drawing.Point(8, 8);
this.m_preview.Name = "m_preview";
this.m_preview.Size = new System.Drawing.Size(168, 168);
this.m_preview.TabIndex = 14;
this.m_preview.Text = "Click Here to use standard Windows Colour Picker";
this.m_preview.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.m_preview.Click += new System.EventHandler(this.OnSelectColour);
//
// m_alpha
//
this.m_alpha.Location = new System.Drawing.Point(360, 296);
this.m_alpha.MaxLength = 3;
this.m_alpha.Name = "m_alpha";
this.m_alpha.ReadOnly = true;
this.m_alpha.Size = new System.Drawing.Size(40, 20);
this.m_alpha.TabIndex = 11;
this.m_alpha.Text = "textBox1";
//
// m_greenSlider
//
this.m_greenSlider.Location = new System.Drawing.Point(248, 24);
this.m_greenSlider.Maximum = 255;
this.m_greenSlider.Name = "m_greenSlider";
this.m_greenSlider.Orientation = System.Windows.Forms.Orientation.Vertical;
this.m_greenSlider.Size = new System.Drawing.Size(42, 264);
this.m_greenSlider.TabIndex = 2;
this.m_greenSlider.TickFrequency = 5;
this.m_greenSlider.Scroll += new System.EventHandler(this.OnGreen);
//
// m_common7
//
this.m_common7.BackColor = System.Drawing.Color.Fuchsia;
this.m_common7.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.m_common7.Location = new System.Drawing.Point(96, 240);
this.m_common7.Name = "m_common7";
this.m_common7.Size = new System.Drawing.Size(24, 24);
this.m_common7.TabIndex = 22;
this.m_common7.Click += new System.EventHandler(this.OnCommon);
//
// m_red
//
this.m_red.Location = new System.Drawing.Point(192, 296);
this.m_red.MaxLength = 3;
this.m_red.Name = "m_red";
this.m_red.ReadOnly = true;
this.m_red.Size = new System.Drawing.Size(40, 20);
this.m_red.TabIndex = 8;
this.m_red.Text = "textBox1";
//
// m_common5
//
this.m_common5.BackColor = System.Drawing.Color.Blue;
this.m_common5.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.m_common5.Location = new System.Drawing.Point(16, 240);
this.m_common5.Name = "m_common5";
this.m_common5.Size = new System.Drawing.Size(24, 24);
this.m_common5.TabIndex = 20;
this.m_common5.Click += new System.EventHandler(this.OnCommon);
//
// m_common3
//
this.m_common3.BackColor = System.Drawing.Color.Red;
this.m_common3.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.m_common3.Location = new System.Drawing.Point(96, 208);
this.m_common3.Name = "m_common3";
this.m_common3.Size = new System.Drawing.Size(24, 24);
this.m_common3.TabIndex = 18;
this.m_common3.Click += new System.EventHandler(this.OnCommon);
//
// m_common4
//
this.m_common4.BackColor = System.Drawing.Color.Lime;
this.m_common4.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.m_common4.Location = new System.Drawing.Point(136, 208);
this.m_common4.Name = "m_common4";
this.m_common4.Size = new System.Drawing.Size(24, 24);
this.m_common4.TabIndex = 19;
this.m_common4.Click += new System.EventHandler(this.OnCommon);
//
// m_named
//
this.m_named.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.m_named.Location = new System.Drawing.Point(8, 296);
this.m_named.MaxDropDownItems = 20;
this.m_named.Name = "m_named";
this.m_named.Size = new System.Drawing.Size(168, 21);
this.m_named.Sorted = true;
this.m_named.TabIndex = 25;
this.m_named.SelectedIndexChanged += new System.EventHandler(this.OnNamedColour);
//
// AlphaColourDialog
//
this.AcceptButton = this.m_ok;
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.CancelButton = this.m_cancel;
this.ClientSize = new System.Drawing.Size(410, 362);
this.Controls.Add(this.m_named);
this.Controls.Add(this.label6);
this.Controls.Add(this.m_common8);
this.Controls.Add(this.m_common7);
this.Controls.Add(this.m_common6);
this.Controls.Add(this.m_common5);
this.Controls.Add(this.m_common4);
this.Controls.Add(this.m_common3);
this.Controls.Add(this.m_common2);
this.Controls.Add(this.m_common1);
this.Controls.Add(this.label5);
this.Controls.Add(this.m_preview);
this.Controls.Add(this.m_cancel);
this.Controls.Add(this.m_ok);
this.Controls.Add(this.m_alpha);
this.Controls.Add(this.m_blue);
this.Controls.Add(this.m_green);
this.Controls.Add(this.m_red);
this.Controls.Add(this.label4);
this.Controls.Add(this.m_alphaSlider);
this.Controls.Add(this.label3);
this.Controls.Add(this.m_blueSlider);
this.Controls.Add(this.label2);
this.Controls.Add(this.m_greenSlider);
this.Controls.Add(this.label1);
this.Controls.Add(this.m_redSlider);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
this.Name = "AlphaColourDialog";
this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "AlphaColourDialog";
((System.ComponentModel.ISupportInitialize)(this.m_blueSlider)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.m_alphaSlider)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.m_redSlider)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.m_greenSlider)).EndInit();
this.ResumeLayout(false);
}
#endregion
void OnRed(object sender, System.EventArgs e)
{
SetColour();
}
void OnGreen(object sender, System.EventArgs e)
{
SetColour();
}
void OnBlue(object sender, System.EventArgs e)
{
SetColour();
}
void OnAlpha(object sender, System.EventArgs e)
{
SetColour();
}
void OnOK(object sender, System.EventArgs e)
{
DialogResult=DialogResult.OK;
Close();
}
void OnCommon(object sender, System.EventArgs e)
{
Label l=(Label)sender;
Color=l.BackColor;
}
void OnNamedColour(object sender, System.EventArgs e)
{
string s=(string)m_named.SelectedItem;
Color=Color.FromKnownColor((KnownColor)Enum.Parse(typeof(KnownColor),s));
}
void OnSelectColour(object sender, System.EventArgs e)
{
ColorDialog dlg=new ColorDialog();
dlg.Color=Color.FromArgb(m_alphaSlider.Value,
m_redSlider.Value,
m_greenSlider.Value,
m_blueSlider.Value);
dlg.AnyColor=true;
dlg.SolidColorOnly=false;
dlg.FullOpen=true;
if (dlg.ShowDialog()==DialogResult.OK)
{
m_redSlider.Value=dlg.Color.R;
m_greenSlider.Value=dlg.Color.G;
m_blueSlider.Value=dlg.Color.B;
SetColour();
}
}
}
}