1 // Permission is hereby granted, free of charge, to any person obtaining
2 // a copy of this software and associated documentation files (the
3 // "Software"), to deal in the Software without restriction, including
4 // without limitation the rights to use, copy, modify, merge, publish,
5 // distribute, sublicense, and/or sell copies of the Software, and to
6 // permit persons to whom the Software is furnished to do so, subject to
7 // the following conditions:
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
12 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
13 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
14 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
16 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
17 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
18 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 // Copyright (c) 2004-2006 Novell, Inc. (http://www.novell.com)
23 // Alexander Olk xenomorph2@onlinehome.de
28 using System.ComponentModel;
30 using System.Globalization;
31 using System.Resources;
34 namespace System.Windows.Forms {
35 [DefaultProperty ("Color")]
36 public class ColorDialog : CommonDialog {
37 #region Local Variables
38 private bool allowFullOpen = true;
39 private bool anyColor = false;
41 private int[] customColors = null;
42 private bool fullOpen = false;
43 private bool showHelp = false;
44 private bool solidColorOnly = false;
46 private Panel selectedColorPanel;
47 private BaseColorControl baseColorControl;
48 private ColorMatrixControl colorMatrixControl;
49 private BrightnessControl brightnessControl;
50 private TriangleControl triangleControl;
52 private Button okButton;
53 private Button cancelButton;
54 private Button helpButton;
55 private Button addColoursButton;
56 private Button defineColoursButton;
58 private TextBox hueTextBox;
59 private TextBox satTextBox;
60 private TextBox briTextBox;
61 private TextBox redTextBox;
62 private TextBox greenTextBox;
63 private TextBox blueTextBox;
65 private Label briLabel;
66 private Label satLabel;
67 private Label hueLabel;
68 private Label colorBaseLabel;
69 private Label greenLabel;
70 private Label blueLabel;
71 private Label redLabel;
72 #endregion // Local Variables
74 #region Public Constructors
75 public ColorDialog () : base()
77 form.SuspendLayout ();
81 form.Size = new Size (221, 332); // 300
83 form.FormBorderStyle = FormBorderStyle.FixedDialog;
84 form.MaximizeBox = false;
86 satTextBox = new TextBox ();
87 briTextBox = new TextBox ();
88 blueTextBox = new TextBox ();
89 greenTextBox = new TextBox ();
90 redTextBox = new TextBox ();
91 hueTextBox = new TextBox ();
93 redLabel = new Label ();
94 blueLabel = new Label ();
95 greenLabel = new Label ();
96 colorBaseLabel = new Label ();
97 hueLabel = new Label ();
98 satLabel = new Label ();
99 briLabel = new Label ();
101 okButton = new Button ();
102 cancelButton = new Button ();
103 helpButton = new Button ();
104 defineColoursButton = new Button ();
105 addColoursButton = new Button ();
107 baseColorControl = new BaseColorControl (this);
108 colorMatrixControl = new ColorMatrixControl (this);
109 brightnessControl = new BrightnessControl (this);
110 triangleControl = new TriangleControl (this);
112 selectedColorPanel = new Panel ();
115 hueTextBox.Location = new Point (324, 203);
116 hueTextBox.Size = new Size (27, 21);
117 hueTextBox.TabIndex = 11;
118 hueTextBox.MaxLength = 3;
120 satTextBox.Location = new Point (324, 225);
121 satTextBox.Size = new Size (27, 21);
122 satTextBox.TabIndex = 15;
123 satTextBox.MaxLength = 3;
125 greenTextBox.Location = new Point (404, 225);
126 greenTextBox.Size = new Size (27, 21);
127 greenTextBox.TabIndex = 18;
128 greenTextBox.MaxLength = 3;
130 briTextBox.Location = new Point (324, 247);
131 briTextBox.Size = new Size (27, 21);
132 briTextBox.TabIndex = 16;
133 briTextBox.MaxLength = 3;
135 blueTextBox.Location = new Point (404, 247);
136 blueTextBox.Size = new Size (27, 21);
137 blueTextBox.TabIndex = 19;
138 blueTextBox.MaxLength = 3;
140 redTextBox.Location = new Point (404, 203);
141 redTextBox.Size = new Size (27, 21);
142 redTextBox.TabIndex = 17;
143 redTextBox.MaxLength = 3;
146 redLabel.FlatStyle = FlatStyle.System;
147 redLabel.Location = new Point (361, 206);
148 redLabel.Size = new Size (40, 16);
149 redLabel.TabIndex = 25;
150 redLabel.Text = Locale.GetText ("Red") + ":";
151 redLabel.TextAlign = ContentAlignment.MiddleRight;
153 blueLabel.FlatStyle = FlatStyle.System;
154 blueLabel.Location = new Point (361, 250);
155 blueLabel.Size = new Size (40, 16);
156 blueLabel.TabIndex = 26;
157 blueLabel.Text = Locale.GetText ("Blue") + ":";
158 blueLabel.TextAlign = ContentAlignment.MiddleRight;
160 greenLabel.FlatStyle = FlatStyle.System;
161 greenLabel.Location = new Point (361, 228);
162 greenLabel.Size = new Size (40, 16);
163 greenLabel.TabIndex = 27;
164 greenLabel.Text = Locale.GetText ("Green") + ":";
165 greenLabel.TextAlign = ContentAlignment.MiddleRight;
167 colorBaseLabel.Location = new Point (228, 247);
168 colorBaseLabel.Size = new Size (60, 25);
169 colorBaseLabel.TabIndex = 28;
170 colorBaseLabel.Text = Locale.GetText ("Color");
171 colorBaseLabel.TextAlign = ContentAlignment.MiddleCenter;
173 hueLabel.FlatStyle = FlatStyle.System;
174 hueLabel.Location = new Point (287, 206);
175 hueLabel.Size = new Size (36, 16);
176 hueLabel.TabIndex = 23;
177 hueLabel.Text = Locale.GetText ("Hue") + ":";
178 hueLabel.TextAlign = ContentAlignment.MiddleRight;
180 satLabel.FlatStyle = FlatStyle.System;
181 satLabel.Location = new Point (287, 228);
182 satLabel.Size = new Size (36, 16);
183 satLabel.TabIndex = 22;
184 satLabel.Text = Locale.GetText ("Sat") + ":";
185 satLabel.TextAlign = ContentAlignment.MiddleRight;
187 briLabel.FlatStyle = FlatStyle.System;
188 briLabel.Location = new Point (287, 250);
189 briLabel.Size = new Size (36, 16);
190 briLabel.TabIndex = 24;
191 briLabel.Text = Locale.GetText ("Bri") + ":";
192 briLabel.TextAlign = ContentAlignment.MiddleRight;
194 // defineColoursButton
195 defineColoursButton.FlatStyle = FlatStyle.System;
196 defineColoursButton.Location = new Point (5, 244);
197 defineColoursButton.Size = new Size (210, 22);
198 defineColoursButton.TabIndex = 6;
199 defineColoursButton.Text = Locale.GetText ("Define Colors >>");
201 okButton.FlatStyle = FlatStyle.System;
202 okButton.Location = new Point (5, 271);
203 okButton.Size = new Size (66, 22);
204 okButton.TabIndex = 0;
205 okButton.Text = Locale.GetText ("OK");
207 cancelButton.FlatStyle = FlatStyle.System;
208 cancelButton.Location = new Point (78, 271);
209 cancelButton.Size = new Size (66, 22);
210 cancelButton.TabIndex = 1;
211 cancelButton.Text = Locale.GetText ("Cancel");
213 helpButton.FlatStyle = FlatStyle.System;
214 helpButton.Location = new Point (149, 271);
215 helpButton.Size = new Size (66, 22);
216 helpButton.TabIndex = 5;
217 helpButton.Text = Locale.GetText ("Help");
221 addColoursButton.FlatStyle = FlatStyle.System;
222 addColoursButton.Location = new Point (227, 271);
223 addColoursButton.Size = new Size (213, 22);
224 addColoursButton.TabIndex = 7;
225 addColoursButton.Text = Locale.GetText ("Add Colors");
228 baseColorControl.Location = new Point (3, 6);
229 baseColorControl.Size = new Size (212, 231);
230 baseColorControl.TabIndex = 13;
231 // colorMatrixControl
232 colorMatrixControl.Location = new Point (227, 7);
233 colorMatrixControl.Size = new Size (179, 190);
234 colorMatrixControl.TabIndex = 14;
236 triangleControl.Location = new Point (432, 0);
237 triangleControl.Size = new Size (16, 204);
238 triangleControl.TabIndex = 12;
240 brightnessControl.Location = new Point (415, 7);
241 brightnessControl.Size = new Size (14, 190);
242 brightnessControl.TabIndex = 20;
244 // selectedColorPanel
245 selectedColorPanel.BackColor = SystemColors.Desktop;
246 selectedColorPanel.BorderStyle = BorderStyle.Fixed3D;
247 selectedColorPanel.Location = new Point (227, 202);
248 selectedColorPanel.Size = new Size (60, 42);
249 selectedColorPanel.TabIndex = 10;
251 form.Controls.Add (hueTextBox);
252 form.Controls.Add (satTextBox);
253 form.Controls.Add (briTextBox);
254 form.Controls.Add (redTextBox);
255 form.Controls.Add (greenTextBox);
256 form.Controls.Add (blueTextBox);
258 form.Controls.Add (defineColoursButton);
259 form.Controls.Add (okButton);
260 form.Controls.Add (cancelButton);
261 form.Controls.Add (addColoursButton);
263 form.Controls.Add (baseColorControl);
264 form.Controls.Add (colorMatrixControl);
265 form.Controls.Add (brightnessControl);
266 form.Controls.Add (triangleControl);
268 form.Controls.Add (colorBaseLabel);
269 form.Controls.Add (greenLabel);
270 form.Controls.Add (blueLabel);
271 form.Controls.Add (redLabel);
272 form.Controls.Add (briLabel);
273 form.Controls.Add (hueLabel);
274 form.Controls.Add (satLabel);
276 form.Controls.Add (selectedColorPanel);
278 form.ResumeLayout (false);
282 defineColoursButton.Click += new EventHandler (OnClickButtonDefineColours);
283 addColoursButton.Click += new EventHandler (OnClickButtonAddColours);
284 helpButton.Click += new EventHandler (OnClickHelpButton);
285 cancelButton.Click += new EventHandler (OnClickCancelButton);
286 okButton.Click += new EventHandler (OnClickOkButton);
288 hueTextBox.KeyPress += new KeyPressEventHandler (OnKeyPressTextBoxes);
289 satTextBox.KeyPress += new KeyPressEventHandler (OnKeyPressTextBoxes);
290 briTextBox.KeyPress += new KeyPressEventHandler (OnKeyPressTextBoxes);
291 redTextBox.KeyPress += new KeyPressEventHandler (OnKeyPressTextBoxes);
292 greenTextBox.KeyPress += new KeyPressEventHandler (OnKeyPressTextBoxes);
293 blueTextBox.KeyPress += new KeyPressEventHandler (OnKeyPressTextBoxes);
295 hueTextBox.TextChanged += new EventHandler (OnTextChangedTextBoxes);
296 satTextBox.TextChanged += new EventHandler (OnTextChangedTextBoxes);
297 briTextBox.TextChanged += new EventHandler (OnTextChangedTextBoxes);
298 redTextBox.TextChanged += new EventHandler (OnTextChangedTextBoxes);
299 greenTextBox.TextChanged += new EventHandler (OnTextChangedTextBoxes);
300 blueTextBox.TextChanged += new EventHandler (OnTextChangedTextBoxes);
302 hueTextBox.GotFocus += new EventHandler (OnGotFocusTextBoxes);
303 satTextBox.GotFocus += new EventHandler (OnGotFocusTextBoxes);
304 briTextBox.GotFocus += new EventHandler (OnGotFocusTextBoxes);
305 redTextBox.GotFocus += new EventHandler (OnGotFocusTextBoxes);
306 greenTextBox.GotFocus += new EventHandler (OnGotFocusTextBoxes);
307 blueTextBox.GotFocus += new EventHandler (OnGotFocusTextBoxes);
309 hueTextBox.LostFocus += new EventHandler (OnLostFocusTextBoxes);
310 satTextBox.LostFocus += new EventHandler (OnLostFocusTextBoxes);
311 briTextBox.LostFocus += new EventHandler (OnLostFocusTextBoxes);
312 redTextBox.LostFocus += new EventHandler (OnLostFocusTextBoxes);
313 greenTextBox.LostFocus += new EventHandler (OnLostFocusTextBoxes);
314 blueTextBox.LostFocus += new EventHandler (OnLostFocusTextBoxes);
316 #endregion // Public Constructors
318 #region Public Instance Properties
321 return selectedColorPanel.BackColor;
327 baseColorControl.SetColor (color);
328 } else if (color != value) {
330 baseColorControl.SetColor (color);
336 public virtual bool AllowFullOpen {
338 return allowFullOpen;
342 if (allowFullOpen != value) {
343 allowFullOpen = value;
346 defineColoursButton.Enabled = false;
348 defineColoursButton.Enabled = true;
353 // Currently AnyColor internally is always true
354 // Does really anybody still use 256 or less colors ???
355 // Naw, cairo only supports 24bit anyway - pdb
356 [DefaultValue(false)]
357 public virtual bool AnyColor {
367 [DefaultValue(false)]
368 public virtual bool FullOpen {
374 if (fullOpen != value) {
377 if (fullOpen && allowFullOpen) {
378 defineColoursButton.Enabled = false;
380 colorMatrixControl.ColorToShow = baseColorControl.ColorToShow;
382 form.Size = new Size (448, 332);
385 defineColoursButton.Enabled = true;
387 form.Size = new Size (221, 332); // 300
394 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
395 public int[] CustomColors {
402 customColors = value;
404 baseColorControl.SetCustomColors ();
409 [DefaultValue(false)]
410 public virtual bool ShowHelp {
416 if (showHelp != value) {
426 [DefaultValue(false)]
427 public virtual bool SolidColorOnly {
429 return solidColorOnly;
433 solidColorOnly = value;
436 #endregion // Public Instance Properties
438 #region Public Instance Methods
439 public override void Reset ()
441 AllowFullOpen = true;
447 solidColorOnly = false;
450 public override string ToString ()
452 return base.ToString () + ", Color: " + Color.ToString ();
454 #endregion // Public Instance Methods
456 #region Protected Instance Properties
457 protected virtual IntPtr Instance {
460 return (IntPtr)GetHashCode ();
464 protected virtual int Options {
470 #endregion // Protected Instance Properties
472 #region Protected Instance Methods
473 protected override bool RunDialog (IntPtr hwndOwner)
475 // currently needed, otherwise there are a lot of drawing artefacts/transparent controls if the same dialog gets opened again
480 #endregion // Protected Instance Methods
482 #region Private Methods
483 void OnClickCancelButton (object sender, EventArgs e)
485 form.DialogResult = DialogResult.Cancel;
488 void OnClickOkButton (object sender, EventArgs e)
490 form.DialogResult = DialogResult.OK;
493 void OnClickButtonAddColours (object sender, EventArgs e)
495 baseColorControl.SetUserColor (selectedColorPanel.BackColor);
498 void OnClickButtonDefineColours (object sender, EventArgs e)
501 defineColoursButton.Enabled = false;
503 colorMatrixControl.ColorToShow = baseColorControl.ColorToShow;
505 form.Size = new Size (448, 332);
509 // FIXME: Is this correct ?
510 void OnClickHelpButton (object sender, EventArgs e)
515 string textBox_text_old = "";
517 void OnGotFocusTextBoxes (object sender, EventArgs e)
519 TextBox textbox = sender as TextBox;
520 textBox_text_old = textbox.Text;
523 void OnLostFocusTextBoxes (object sender, EventArgs e)
525 TextBox textbox = sender as TextBox;
527 if (textbox.Text.Length == 0)
528 textbox.Text = textBox_text_old;
531 void OnKeyPressTextBoxes (object sender, KeyPressEventArgs e)
533 if (Char.IsLetter (e.KeyChar) || Char.IsWhiteSpace (e.KeyChar) || Char.IsPunctuation (e.KeyChar) || e.KeyChar == ',') {
538 internal_textbox_change = true;
541 internal TextBox edit_textbox = null;
542 bool internal_textbox_change = false;
544 void OnTextChangedTextBoxes (object sender, EventArgs e)
546 if (!internal_textbox_change)
549 internal_textbox_change = false;
551 TextBox tmp_box = sender as TextBox;
553 if (tmp_box.Text.Length == 0)
556 string text = tmp_box.Text;
561 val = System.Convert.ToInt32 (text);
562 } catch (Exception) {
566 if (sender == hueTextBox) {
569 hueTextBox.Text = val.ToString ();
573 hueTextBox.Text = val.ToString ();
576 edit_textbox = hueTextBox;
578 UpdateFromHSBTextBoxes ();
580 UpdateControls (selectedColorPanel.BackColor);
582 if (sender == satTextBox) {
585 satTextBox.Text = val.ToString ();
589 satTextBox.Text = val.ToString ();
592 edit_textbox = satTextBox;
594 UpdateFromHSBTextBoxes ();
596 UpdateControls (selectedColorPanel.BackColor);
598 if (sender == briTextBox) {
601 briTextBox.Text = val.ToString ();
605 briTextBox.Text = val.ToString ();
608 edit_textbox = briTextBox;
610 UpdateFromHSBTextBoxes ();
612 UpdateControls (selectedColorPanel.BackColor);
614 if (sender == redTextBox) {
617 redTextBox.Text = val.ToString ();
621 redTextBox.Text = val.ToString ();
624 edit_textbox = redTextBox;
626 UpdateFromRGBTextBoxes ();
628 if (sender == greenTextBox) {
631 greenTextBox.Text = val.ToString ();
635 greenTextBox.Text = val.ToString ();
638 edit_textbox = greenTextBox;
640 UpdateFromRGBTextBoxes ();
642 if (sender == blueTextBox) {
645 blueTextBox.Text = val.ToString ();
649 blueTextBox.Text = val.ToString ();
652 edit_textbox = blueTextBox;
654 UpdateFromRGBTextBoxes ();
657 textBox_text_old = edit_textbox.Text;
662 internal void UpdateControls (Color acolor)
664 selectedColorPanel.BackColor = acolor;
665 colorMatrixControl.ColorToShow = acolor;
666 brightnessControl.ColorToShow = acolor;
667 triangleControl.ColorToShow = acolor;
670 internal void UpdateRGBTextBoxes (Color acolor)
672 if (edit_textbox != redTextBox)
673 redTextBox.Text = acolor.R.ToString ();
674 if (edit_textbox != greenTextBox)
675 greenTextBox.Text = acolor.G.ToString ();
676 if (edit_textbox != blueTextBox)
677 blueTextBox.Text = acolor.B.ToString ();
680 internal void UpdateHSBTextBoxes (Color acolor)
682 HSB hsb = HSB.RGB2HSB (acolor);
684 if (edit_textbox != hueTextBox)
685 hueTextBox.Text = hsb.hue.ToString ();
686 if (edit_textbox != satTextBox)
687 satTextBox.Text = hsb.sat.ToString ();
688 if (edit_textbox != briTextBox)
689 briTextBox.Text = hsb.bri.ToString ();
692 internal void UpdateFromHSBTextBoxes ()
694 Color col = HSB.HSB2RGB (System.Convert.ToInt32 (hueTextBox.Text),
695 System.Convert.ToInt32 (satTextBox.Text),
696 System.Convert.ToInt32 (briTextBox.Text));
698 selectedColorPanel.BackColor = col;
699 UpdateRGBTextBoxes (col);
702 internal void UpdateFromRGBTextBoxes ()
704 Color col = Color.FromArgb (System.Convert.ToInt32 (redTextBox.Text),
705 System.Convert.ToInt32 (greenTextBox.Text),
706 System.Convert.ToInt32 (blueTextBox.Text));
708 selectedColorPanel.BackColor = col;
710 UpdateHSBTextBoxes (col);
712 UpdateControls (col);
716 #region Internal structs and classes
717 internal struct HSB {
722 public static HSB RGB2HSB (Color color)
724 HSB hsb = new HSB ();
726 hsb.hue = (int)((color.GetHue () / 360.0f) * 240);
727 hsb.sat = (int)(color.GetSaturation () * 241);
728 hsb.bri = (int)(color.GetBrightness () * 241);
730 if (hsb.hue > 239) hsb.hue = 239;
731 if (hsb.sat > 240) hsb.sat = 240;
732 if (hsb.bri > 240) hsb.bri = 240;
737 // not using ControlPaint HBS2Color, this algo is more precise
738 public static Color HSB2RGB (int hue, int saturation, int brightness)
746 if (saturation > 240)
752 if (brightness > 240)
758 float H = hue / 239.0f;
759 float S = saturation / 240.0f;
760 float L = brightness / 240.0f;
762 float r = 0, g = 0, b = 0;
771 d2 = (L <= 0.5f) ? L * (1.0f + S) : L + S - (L * S);
774 float[] d3 = new float [] { H + 1.0f / 3.0f , H, H - 1.0f / 3.0f };
775 float[] rgb = new float [] { 0,0,0 };
777 for (int i = 0; i < 3; i++) {
783 if (6.0f * d3 [i] < 1.0f)
784 rgb [i] = d1 + (d2 - d1) * d3 [i] * 6.0f;
786 if (2.0f * d3 [i] < 1.0f)
789 if (3.0f * d3 [i] < 2.0f)
790 rgb [i] = (d1 + (d2 - d1) * ((2.0f / 3.0f) - d3 [i]) * 6.0f);
823 return Color.FromArgb ((int)r, (int)g, (int)b);
826 public static int Brightness (Color color)
828 return (int)(color.GetBrightness () * 241);
831 public static void GetHueSaturation (Color color, out int hue, out int sat)
833 hue = (int)((color.GetHue () / 360.0f) * 240);
834 sat = (int)(color.GetSaturation () * 241);
838 // there are some small glitches, but it is still better than ControlPaint implementation
839 public static void TestColor (Color color)
841 Console.WriteLine ("Color: " + color);
842 HSB hsb = HSB.RGB2HSB (color);
843 Console.WriteLine ("RGB2HSB: " + hsb.hue + ", " + hsb.sat + ", " + hsb.bri);
844 Console.WriteLine ("HSB2RGB: " + HSB.HSB2RGB (hsb.hue, hsb.sat, hsb.bri));
845 Console.WriteLine ();
849 internal class BaseColorControl : Control {
850 internal class SmallColorControl : Control {
851 private Color internalcolor;
853 private bool isSelected = false;
855 public SmallColorControl (Color color)
859 this.internalcolor = color;
861 Size = new Size (25, 23);
863 ResumeLayout (false);
865 SetStyle (ControlStyles.DoubleBuffer, true);
866 SetStyle (ControlStyles.AllPaintingInWmPaint, true);
867 SetStyle (ControlStyles.UserPaint, true);
868 SetStyle (ControlStyles.Selectable, true);
871 public bool IsSelected {
878 public Color InternalColor {
880 internalcolor = value;
885 return internalcolor;
889 protected override void OnPaint (PaintEventArgs pe)
893 pe.Graphics.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (internalcolor),
894 new Rectangle (4, 4, 17, 15));
896 ControlPaint.DrawBorder3D (pe.Graphics, 3, 3, 19, 17, Border3DStyle.Sunken);
899 pe.Graphics.DrawRectangle (ThemeEngine.Current.ResPool.GetPen (Color.Black),
900 new Rectangle (2, 2, 20, 18));
904 ControlPaint.DrawFocusRectangle (
905 pe.Graphics, new Rectangle (0, 0, 25, 23)
910 protected override void OnClick (EventArgs e)
919 protected override void OnLostFocus (EventArgs e)
923 base.OnLostFocus (e);
927 private SmallColorControl[] smallColorControl;
929 private SmallColorControl[] userSmallColorControl;
931 private Label userColorLabel;
932 private Label baseColorLabel;
934 private SmallColorControl selectedSmallColorControl;
936 private int currentlyUsedUserSmallColorControl = 0;
937 private int[] customColors = null;
939 private ColorDialog colorDialog = null;
941 public BaseColorControl (ColorDialog colorDialog)
943 this.colorDialog = colorDialog;
945 userSmallColorControl = new SmallColorControl [16];
946 userSmallColorControl [0] = new SmallColorControl (Color.White);
947 userSmallColorControl [1] = new SmallColorControl (Color.White);
948 userSmallColorControl [2] = new SmallColorControl (Color.White);
949 userSmallColorControl [3] = new SmallColorControl (Color.White);
950 userSmallColorControl [4] = new SmallColorControl (Color.White);
951 userSmallColorControl [5] = new SmallColorControl (Color.White);
952 userSmallColorControl [6] = new SmallColorControl (Color.White);
953 userSmallColorControl [7] = new SmallColorControl (Color.White);
954 userSmallColorControl [8] = new SmallColorControl (Color.White);
955 userSmallColorControl [9] = new SmallColorControl (Color.White);
956 userSmallColorControl [10] = new SmallColorControl (Color.White);
957 userSmallColorControl [11] = new SmallColorControl (Color.White);
958 userSmallColorControl [12] = new SmallColorControl (Color.White);
959 userSmallColorControl [13] = new SmallColorControl (Color.White);
960 userSmallColorControl [14] = new SmallColorControl (Color.White);
961 userSmallColorControl [15] = new SmallColorControl (Color.White);
963 smallColorControl = new SmallColorControl [48];
964 smallColorControl [0] = new SmallColorControl (Color.FromArgb (((Byte)(255)), ((Byte)(128)), ((Byte)(128))));
965 smallColorControl [1] = new SmallColorControl (Color.FromArgb (((Byte)(128)), ((Byte)(128)), ((Byte)(64))));
966 smallColorControl [2] = new SmallColorControl (Color.Gray);
967 smallColorControl [3] = new SmallColorControl (Color.FromArgb (((Byte)(128)), ((Byte)(0)), ((Byte)(255))));
968 smallColorControl [4] = new SmallColorControl (Color.Silver);
969 smallColorControl [5] = new SmallColorControl (Color.FromArgb (((Byte)(64)), ((Byte)(128)), ((Byte)(128))));
970 smallColorControl [6] = new SmallColorControl (Color.White);
971 smallColorControl [7] = new SmallColorControl (Color.FromArgb (((Byte)(64)), ((Byte)(0)), ((Byte)(64))));
972 smallColorControl [8] = new SmallColorControl (Color.FromArgb (((Byte)(255)), ((Byte)(128)), ((Byte)(64))));
973 smallColorControl [9] = new SmallColorControl (Color.FromArgb (((Byte)(128)), ((Byte)(64)), ((Byte)(64))));
974 smallColorControl [10] = new SmallColorControl (Color.Teal);
975 smallColorControl [11] = new SmallColorControl (Color.Lime);
976 smallColorControl [12] = new SmallColorControl (Color.FromArgb (((Byte)(128)), ((Byte)(128)), ((Byte)(255))));
977 smallColorControl [13] = new SmallColorControl (Color.FromArgb (((Byte)(0)), ((Byte)(64)), ((Byte)(128))));
978 smallColorControl [14] = new SmallColorControl (Color.FromArgb (((Byte)(255)), ((Byte)(0)), ((Byte)(128))));
979 smallColorControl [15] = new SmallColorControl (Color.FromArgb (((Byte)(128)), ((Byte)(255)), ((Byte)(0))));
980 smallColorControl [16] = new SmallColorControl (Color.FromArgb (((Byte)(0)), ((Byte)(255)), ((Byte)(64))));
981 smallColorControl [17] = new SmallColorControl (Color.Red);
982 smallColorControl [18] = new SmallColorControl (Color.FromArgb (((Byte)(255)), ((Byte)(128)), ((Byte)(0))));
983 smallColorControl [19] = new SmallColorControl (Color.FromArgb (((Byte)(255)), ((Byte)(128)), ((Byte)(255))));
984 smallColorControl [20] = new SmallColorControl (Color.Fuchsia);
985 smallColorControl [21] = new SmallColorControl (Color.Aqua);
986 smallColorControl [22] = new SmallColorControl (Color.FromArgb (((Byte)(128)), ((Byte)(255)), ((Byte)(128))));
987 smallColorControl [23] = new SmallColorControl (Color.FromArgb (((Byte)(128)), ((Byte)(255)), ((Byte)(255))));
988 smallColorControl [24] = new SmallColorControl (Color.FromArgb (((Byte)(0)), ((Byte)(128)), ((Byte)(255))));
989 smallColorControl [25] = new SmallColorControl (Color.FromArgb (((Byte)(128)), ((Byte)(64)), ((Byte)(0))));
990 smallColorControl [26] = new SmallColorControl (Color.FromArgb (((Byte)(64)), ((Byte)(0)), ((Byte)(0))));
991 smallColorControl [27] = new SmallColorControl (Color.Maroon);
992 smallColorControl [28] = new SmallColorControl (Color.Purple);
993 smallColorControl [29] = new SmallColorControl (Color.FromArgb (((Byte)(0)), ((Byte)(0)), ((Byte)(160))));
994 smallColorControl [30] = new SmallColorControl (Color.Blue);
995 smallColorControl [31] = new SmallColorControl (Color.FromArgb (((Byte)(0)), ((Byte)(128)), ((Byte)(64))));
996 smallColorControl [32] = new SmallColorControl (Color.Green);
997 smallColorControl [33] = new SmallColorControl (Color.Yellow);
998 smallColorControl [34] = new SmallColorControl (Color.FromArgb (((Byte)(128)), ((Byte)(128)), ((Byte)(192))));
999 smallColorControl [35] = new SmallColorControl (Color.FromArgb (((Byte)(0)), ((Byte)(128)), ((Byte)(192))));
1000 smallColorControl [36] = new SmallColorControl (Color.FromArgb (((Byte)(128)), ((Byte)(0)), ((Byte)(64))));
1001 smallColorControl [37] = new SmallColorControl (Color.FromArgb (((Byte)(255)), ((Byte)(128)), ((Byte)(192))));
1002 smallColorControl [38] = new SmallColorControl (Color.FromArgb (((Byte)(0)), ((Byte)(255)), ((Byte)(128))));
1003 smallColorControl [39] = new SmallColorControl (Color.FromArgb (((Byte)(255)), ((Byte)(255)), ((Byte)(128))));
1004 smallColorControl [40] = new SmallColorControl (Color.FromArgb (((Byte)(0)), ((Byte)(64)), ((Byte)(0))));
1005 smallColorControl [41] = new SmallColorControl (Color.FromArgb (((Byte)(0)), ((Byte)(64)), ((Byte)(64))));
1006 smallColorControl [42] = new SmallColorControl (Color.Navy);
1007 smallColorControl [43] = new SmallColorControl (Color.FromArgb (((Byte)(0)), ((Byte)(0)), ((Byte)(64))));
1008 smallColorControl [44] = new SmallColorControl (Color.FromArgb (((Byte)(64)), ((Byte)(0)), ((Byte)(64))));
1009 smallColorControl [45] = new SmallColorControl (Color.FromArgb (((Byte)(64)), ((Byte)(0)), ((Byte)(128))));
1010 smallColorControl [46] = new SmallColorControl (Color.Black); //Black
1011 smallColorControl [47] = new SmallColorControl (Color.Olive);
1013 baseColorLabel = new Label ();
1014 userColorLabel = new Label ();
1019 smallColorControl [0].Location = new Point (0, 15);
1020 smallColorControl [0].TabIndex = 51;
1021 smallColorControl [0].Click += new EventHandler (OnSmallColorControlClick);
1023 smallColorControl [1].Location = new Point (50, 130);
1024 smallColorControl [1].TabIndex = 92;
1025 smallColorControl [1].Click += new EventHandler (OnSmallColorControlClick);
1027 smallColorControl [2].Location = new Point (75, 130);
1028 smallColorControl [2].TabIndex = 93;
1029 smallColorControl [2].Click += new EventHandler (OnSmallColorControlClick);
1031 smallColorControl [3].Location = new Point (175, 84);
1032 smallColorControl [3].TabIndex = 98;
1033 smallColorControl [3].Click += new EventHandler (OnSmallColorControlClick);
1035 smallColorControl [4].Location = new Point (125, 130);
1036 smallColorControl [4].TabIndex = 95;
1037 smallColorControl [4].Click += new EventHandler (OnSmallColorControlClick);
1039 smallColorControl [5].Location = new Point (100, 130);
1040 smallColorControl [5].TabIndex = 94;
1041 smallColorControl [5].Click += new EventHandler (OnSmallColorControlClick);
1043 smallColorControl [6].Location = new Point (175, 130);
1044 smallColorControl [6].TabIndex = 97;
1045 smallColorControl [6].Click += new EventHandler (OnSmallColorControlClick);
1047 smallColorControl [7].Location = new Point (150, 130);
1048 smallColorControl [7].TabIndex = 96;
1049 smallColorControl [7].Click += new EventHandler (OnSmallColorControlClick);
1051 smallColorControl [8].Location = new Point (25, 61);
1052 smallColorControl [8].TabIndex = 68;
1053 smallColorControl [8].Click += new EventHandler (OnSmallColorControlClick);
1055 smallColorControl [9].Location = new Point (0, 61);
1056 smallColorControl [9].TabIndex = 67;
1057 smallColorControl [9].Click += new EventHandler (OnSmallColorControlClick);
1059 smallColorControl [10].Location = new Point (75, 61);
1060 smallColorControl [10].TabIndex = 70;
1061 smallColorControl [10].Click += new EventHandler (OnSmallColorControlClick);
1063 smallColorControl [11].Location = new Point (50, 61);
1064 smallColorControl [11].TabIndex = 69;
1065 smallColorControl [11].Click += new EventHandler (OnSmallColorControlClick);
1067 smallColorControl [12].Location = new Point (125, 61);
1068 smallColorControl [12].TabIndex = 72;
1069 smallColorControl [12].Click += new EventHandler (OnSmallColorControlClick);
1071 smallColorControl [13].Location = new Point (100, 61);
1072 smallColorControl [13].TabIndex = 71;
1073 smallColorControl [13].Click += new EventHandler (OnSmallColorControlClick);
1075 smallColorControl [14].Location = new Point (175, 61);
1076 smallColorControl [14].TabIndex = 74;
1077 smallColorControl [14].Click += new EventHandler (OnSmallColorControlClick);
1079 smallColorControl [15].Location = new Point (50, 38);
1080 smallColorControl [15].TabIndex = 61;
1081 smallColorControl [15].Click += new EventHandler (OnSmallColorControlClick);
1083 smallColorControl [16].Location = new Point (75, 38);
1084 smallColorControl [16].TabIndex = 62;
1085 smallColorControl [16].Click += new EventHandler (OnSmallColorControlClick);
1087 smallColorControl [17].Location = new Point (0, 38);
1088 smallColorControl [17].TabIndex = 59;
1089 smallColorControl [17].Click += new EventHandler (OnSmallColorControlClick);
1091 smallColorControl [18].Location = new Point (25, 84);
1092 smallColorControl [18].TabIndex = 75;
1093 smallColorControl [18].Click += new EventHandler (OnSmallColorControlClick);
1095 smallColorControl [19].Location = new Point (175, 15);
1096 smallColorControl [19].TabIndex = 58;
1097 smallColorControl [19].Click += new EventHandler (OnSmallColorControlClick);
1099 smallColorControl [20].Location = new Point (175, 38);
1100 smallColorControl [20].TabIndex = 66;
1101 smallColorControl [20].Click += new EventHandler (OnSmallColorControlClick);
1103 smallColorControl [21].Location = new Point (100, 38);
1104 smallColorControl [21].TabIndex = 63;
1105 smallColorControl [21].Click += new EventHandler (OnSmallColorControlClick);
1107 smallColorControl [22].Location = new Point (50, 15);
1108 smallColorControl [22].TabIndex = 53;
1109 smallColorControl [22].Click += new EventHandler (OnSmallColorControlClick);
1111 smallColorControl [23].Location = new Point (100, 15);
1112 smallColorControl [23].TabIndex = 55;
1113 smallColorControl [23].Click += new EventHandler (OnSmallColorControlClick);
1115 smallColorControl [24].Location = new Point (125, 15);
1116 smallColorControl [24].TabIndex = 56;
1117 smallColorControl [24].Click += new EventHandler (OnSmallColorControlClick);
1119 smallColorControl [25].Location = new Point (25, 107);
1120 smallColorControl [25].TabIndex = 83;
1121 smallColorControl [25].Click += new EventHandler (OnSmallColorControlClick);
1123 smallColorControl [26].Location = new Point (0, 107);
1124 smallColorControl [26].TabIndex = 82;
1125 smallColorControl [26].Click += new EventHandler (OnSmallColorControlClick);
1127 smallColorControl [27].Location = new Point (0, 84);
1128 smallColorControl [27].TabIndex = 81;
1129 smallColorControl [27].Click += new EventHandler (OnSmallColorControlClick);
1131 smallColorControl [28].Location = new Point (150, 84);
1132 smallColorControl [28].TabIndex = 80;
1133 smallColorControl [28].Click += new EventHandler (OnSmallColorControlClick);
1135 smallColorControl [29].Location = new Point (125, 84);
1136 smallColorControl [29].TabIndex = 79;
1137 smallColorControl [29].Click += new EventHandler (OnSmallColorControlClick);
1139 smallColorControl [30].Location = new Point (100, 84);
1140 smallColorControl [30].TabIndex = 78;
1141 smallColorControl [30].Click += new EventHandler (OnSmallColorControlClick);
1143 smallColorControl [31].Location = new Point (75, 84);
1144 smallColorControl [31].TabIndex = 77;
1145 smallColorControl [31].Click += new EventHandler (OnSmallColorControlClick);
1147 smallColorControl [32].Location = new Point (50, 84);
1148 smallColorControl [32].TabIndex = 76;
1149 smallColorControl [32].Click += new EventHandler (OnSmallColorControlClick);
1151 smallColorControl [33].Location = new Point (25, 38);
1152 smallColorControl [33].TabIndex = 60;
1153 smallColorControl [33].Click += new EventHandler (OnSmallColorControlClick);
1155 smallColorControl [34].Location = new Point (150, 38);
1156 smallColorControl [34].TabIndex = 65;
1157 smallColorControl [34].Click += new EventHandler (OnSmallColorControlClick);
1159 smallColorControl [35].Location = new Point (125, 38);
1160 smallColorControl [35].TabIndex = 64;
1161 smallColorControl [35].Click += new EventHandler (OnSmallColorControlClick);
1163 smallColorControl [36].Location = new Point (150, 61);
1164 smallColorControl [36].TabIndex = 73;
1165 smallColorControl [36].Click += new EventHandler (OnSmallColorControlClick);
1167 smallColorControl [37].Location = new Point (150, 15);
1168 smallColorControl [37].TabIndex = 57;
1169 smallColorControl [37].Click += new EventHandler (OnSmallColorControlClick);
1171 smallColorControl [38].Location = new Point (75, 15);
1172 smallColorControl [38].TabIndex = 54;
1173 smallColorControl [38].Click += new EventHandler (OnSmallColorControlClick);
1175 smallColorControl [39].Location = new Point (25, 15);
1176 smallColorControl [39].TabIndex = 52;
1177 smallColorControl [39].Click += new EventHandler (OnSmallColorControlClick);
1179 smallColorControl [40].Location = new Point (50, 107);
1180 smallColorControl [40].TabIndex = 84;
1181 smallColorControl [40].Click += new EventHandler (OnSmallColorControlClick);
1183 smallColorControl [41].Location = new Point (75, 107);
1184 smallColorControl [41].TabIndex = 85;
1185 smallColorControl [41].Click += new EventHandler (OnSmallColorControlClick);
1187 smallColorControl [42].Location = new Point (100, 107);
1188 smallColorControl [42].TabIndex = 86;
1189 smallColorControl [42].Click += new EventHandler (OnSmallColorControlClick);
1191 smallColorControl [43].Location = new Point (125, 107);
1192 smallColorControl [43].TabIndex = 87;
1193 smallColorControl [43].Click += new EventHandler (OnSmallColorControlClick);
1195 smallColorControl [44].Location = new Point (150, 107);
1196 smallColorControl [44].TabIndex = 88;
1197 smallColorControl [44].Click += new EventHandler (OnSmallColorControlClick);
1199 smallColorControl [45].Location = new Point (175, 107);
1200 smallColorControl [45].TabIndex = 89;
1201 smallColorControl [45].Click += new EventHandler (OnSmallColorControlClick);
1203 smallColorControl [46].Location = new Point (0, 130);
1204 smallColorControl [46].TabIndex = 90;
1205 smallColorControl [46].Click += new EventHandler (OnSmallColorControlClick);
1207 smallColorControl [47].Location = new Point (25, 130);
1208 smallColorControl [47].TabIndex = 91;
1209 smallColorControl [47].Click += new EventHandler (OnSmallColorControlClick);
1212 userSmallColorControl [0].Location = new Point (0, 180);
1213 userSmallColorControl [0].TabIndex = 99;
1214 userSmallColorControl [0].Click += new EventHandler (OnSmallColorControlClick);
1216 userSmallColorControl [1].Location = new Point (0, 203);
1217 userSmallColorControl [1].TabIndex = 108;
1218 userSmallColorControl [1].Click += new EventHandler (OnSmallColorControlClick);
1220 userSmallColorControl [2].Location = new Point (25, 180);
1221 userSmallColorControl [2].TabIndex = 100;
1222 userSmallColorControl [2].Click += new EventHandler (OnSmallColorControlClick);
1224 userSmallColorControl [3].Location = new Point (25, 203);
1225 userSmallColorControl [3].TabIndex = 109;
1226 userSmallColorControl [3].Click += new EventHandler (OnSmallColorControlClick);
1228 userSmallColorControl [4].Location = new Point (50, 180);
1229 userSmallColorControl [4].TabIndex = 101;
1230 userSmallColorControl [4].Click += new EventHandler (OnSmallColorControlClick);
1232 userSmallColorControl [5].Location = new Point (50, 203);
1233 userSmallColorControl [5].TabIndex = 110;
1234 userSmallColorControl [5].Click += new EventHandler (OnSmallColorControlClick);
1236 userSmallColorControl [6].Location = new Point (75, 180);
1237 userSmallColorControl [6].TabIndex = 102;
1238 userSmallColorControl [6].Click += new EventHandler (OnSmallColorControlClick);
1240 userSmallColorControl [7].Location = new Point (75, 203);
1241 userSmallColorControl [7].TabIndex = 111;
1242 userSmallColorControl [7].Click += new EventHandler (OnSmallColorControlClick);
1244 userSmallColorControl [8].Location = new Point (100, 180);
1245 userSmallColorControl [8].TabIndex = 103;
1246 userSmallColorControl [8].Click += new EventHandler (OnSmallColorControlClick);
1248 userSmallColorControl [9].Location = new Point (100, 203);
1249 userSmallColorControl [9].TabIndex = 112;
1250 userSmallColorControl [9].Click += new EventHandler (OnSmallColorControlClick);
1252 userSmallColorControl [10].Location = new Point (125, 180);
1253 userSmallColorControl [10].TabIndex = 105;
1254 userSmallColorControl [10].Click += new EventHandler (OnSmallColorControlClick);
1256 userSmallColorControl [11].Location = new Point (125, 203);
1257 userSmallColorControl [11].TabIndex = 113;
1258 userSmallColorControl [11].Click += new EventHandler (OnSmallColorControlClick);
1260 userSmallColorControl [12].Location = new Point (150, 180);
1261 userSmallColorControl [12].TabIndex = 106;
1262 userSmallColorControl [12].Click += new EventHandler (OnSmallColorControlClick);
1264 userSmallColorControl [13].Location = new Point (150, 203);
1265 userSmallColorControl [13].TabIndex = 114;
1266 userSmallColorControl [13].Click += new EventHandler (OnSmallColorControlClick);
1268 userSmallColorControl [14].Location = new Point (175, 180);
1269 userSmallColorControl [14].TabIndex = 107;
1270 userSmallColorControl [14].Click += new EventHandler (OnSmallColorControlClick);
1272 userSmallColorControl [15].Location = new Point (175, 203);
1273 userSmallColorControl [15].TabIndex = 115;
1274 userSmallColorControl [15].Click += new EventHandler (OnSmallColorControlClick);
1277 baseColorLabel.Location = new Point (2, 0);
1278 baseColorLabel.Size = new Size (200, 12);
1279 baseColorLabel.TabIndex = 5;
1280 baseColorLabel.Text = Locale.GetText ("Base Colors") + ":";
1282 userColorLabel.FlatStyle = FlatStyle.System;
1283 userColorLabel.Location = new Point (2, 164);
1284 userColorLabel.Size = new Size (200, 14);
1285 userColorLabel.TabIndex = 104;
1286 userColorLabel.Text = Locale.GetText ("User Colors") + ":";
1288 Controls.Add (userSmallColorControl [7]);
1289 Controls.Add (userSmallColorControl [6]);
1290 Controls.Add (userSmallColorControl [5]);
1291 Controls.Add (userSmallColorControl [4]);
1292 Controls.Add (userSmallColorControl [3]);
1293 Controls.Add (userSmallColorControl [2]);
1294 Controls.Add (userSmallColorControl [1]);
1295 Controls.Add (userSmallColorControl [0]);
1296 Controls.Add (userSmallColorControl [15]);
1297 Controls.Add (userSmallColorControl [14]);
1298 Controls.Add (userSmallColorControl [13]);
1299 Controls.Add (userSmallColorControl [12]);
1300 Controls.Add (userSmallColorControl [11]);
1301 Controls.Add (userSmallColorControl [10]);
1302 Controls.Add (userSmallColorControl [9]);
1303 Controls.Add (userSmallColorControl [8]);
1305 Controls.Add (smallColorControl [0]);
1306 Controls.Add (smallColorControl [3]);
1307 Controls.Add (smallColorControl [6]);
1308 Controls.Add (smallColorControl [7]);
1309 Controls.Add (smallColorControl [4]);
1310 Controls.Add (smallColorControl [5]);
1311 Controls.Add (smallColorControl [2]);
1312 Controls.Add (smallColorControl [1]);
1313 Controls.Add (smallColorControl [47]);
1314 Controls.Add (smallColorControl [46]);
1315 Controls.Add (smallColorControl [45]);
1316 Controls.Add (smallColorControl [44]);
1317 Controls.Add (smallColorControl [43]);
1318 Controls.Add (smallColorControl [42]);
1319 Controls.Add (smallColorControl [41]);
1320 Controls.Add (smallColorControl [40]);
1321 Controls.Add (smallColorControl [25]);
1322 Controls.Add (smallColorControl [26]);
1323 Controls.Add (smallColorControl [27]);
1324 Controls.Add (smallColorControl [28]);
1325 Controls.Add (smallColorControl [29]);
1326 Controls.Add (smallColorControl [30]);
1327 Controls.Add (smallColorControl [31]);
1328 Controls.Add (smallColorControl [32]);
1329 Controls.Add (smallColorControl [18]);
1330 Controls.Add (smallColorControl [14]);
1331 Controls.Add (smallColorControl [36]);
1332 Controls.Add (smallColorControl [12]);
1333 Controls.Add (smallColorControl [13]);
1334 Controls.Add (smallColorControl [10]);
1335 Controls.Add (smallColorControl [11]);
1336 Controls.Add (smallColorControl [8]);
1337 Controls.Add (smallColorControl [9]);
1338 Controls.Add (smallColorControl [20]);
1339 Controls.Add (smallColorControl [34]);
1340 Controls.Add (smallColorControl [35]);
1341 Controls.Add (smallColorControl [21]);
1342 Controls.Add (smallColorControl [16]);
1343 Controls.Add (smallColorControl [15]);
1344 Controls.Add (smallColorControl [33]);
1345 Controls.Add (smallColorControl [17]);
1346 Controls.Add (smallColorControl [19]);
1347 Controls.Add (smallColorControl [37]);
1348 Controls.Add (smallColorControl [24]);
1349 Controls.Add (smallColorControl [23]);
1350 Controls.Add (smallColorControl [38]);
1351 Controls.Add (smallColorControl [22]);
1352 Controls.Add (smallColorControl [39]);
1354 Controls.Add (userColorLabel);
1355 Controls.Add (baseColorLabel);
1357 Size = new Size (212, 238);
1359 ResumeLayout (false);
1362 private void CheckIfColorIsInPanel (Color color)
1364 // check if we have a panel with a BackColor = color...
1365 for (int i = 0; i < smallColorControl.Length; i++) {
1366 if (smallColorControl [i].InternalColor == color) {
1367 selectedSmallColorControl = smallColorControl [i];
1368 selectedSmallColorControl.IsSelected = true;
1374 void OnSmallColorControlClick (object sender, EventArgs e)
1376 // previous selected smallcolorcontrol
1377 if (selectedSmallColorControl != (SmallColorControl)sender)
1378 selectedSmallColorControl.IsSelected = false;
1380 selectedSmallColorControl = (SmallColorControl)sender;
1382 TriangleControl.CurrentBrightness = HSB.Brightness (selectedSmallColorControl.InternalColor);
1384 colorDialog.UpdateControls (selectedSmallColorControl.InternalColor);
1385 colorDialog.UpdateRGBTextBoxes (selectedSmallColorControl.InternalColor);
1386 colorDialog.UpdateHSBTextBoxes (selectedSmallColorControl.InternalColor);
1389 public Color ColorToShow {
1391 return selectedSmallColorControl.InternalColor;
1396 public void SetColor (Color acolor)
1398 if (selectedSmallColorControl != null)
1399 selectedSmallColorControl.IsSelected = false;
1401 CheckIfColorIsInPanel (acolor);
1403 TriangleControl.CurrentBrightness = HSB.Brightness (acolor);
1405 colorDialog.UpdateControls (acolor);
1406 colorDialog.UpdateRGBTextBoxes (acolor);
1407 colorDialog.UpdateHSBTextBoxes (acolor);
1410 public void SetUserColor (Color col)
1412 userSmallColorControl [currentlyUsedUserSmallColorControl].InternalColor = col;
1414 // check if this.customColors already exists
1415 if (customColors == null) {
1416 customColors = new int [16];
1417 int white = Color.White.ToArgb ();
1419 for (int i = 0; i < customColors.Length; i++)
1420 customColors [i] = white;
1423 customColors [currentlyUsedUserSmallColorControl] = col.ToArgb ();
1425 // update ColorDialog dialog property
1426 colorDialog.CustomColors = customColors;
1428 currentlyUsedUserSmallColorControl++;
1429 if (currentlyUsedUserSmallColorControl > 15)
1430 currentlyUsedUserSmallColorControl = 0;
1433 public void SetCustomColors ()
1435 int[] customColors = colorDialog.CustomColors;
1437 if (customColors != null) {
1438 for (int i = 0; i < customColors.Length; i++) {
1439 userSmallColorControl [i].InternalColor = Color.FromArgb (customColors [i]);
1442 for (int i = 0; i < userSmallColorControl.Length; i++) {
1443 userSmallColorControl [i].InternalColor = Color.White;
1449 internal class ColorMatrixControl : Panel {
1450 internal class DrawingBitmap {
1451 private Bitmap bitmap;
1453 public DrawingBitmap (Size size)
1455 bitmap = new Bitmap (size.Width, size.Height);
1457 float hueadd = 240.0f / (size.Width - 1);
1458 float satsub = 241.0f / (size.Height - 1);
1459 float satpos = 240.0f;
1461 // paint the matrix to the bitmap
1462 for (int height = 0; height < size.Height; height++) {
1463 float huepos = 0.0f;
1465 for (int width = 0; width < size.Width; width++) {
1466 HSB hsb = new HSB ();
1468 hsb.hue = (int)huepos;
1469 hsb.sat = (int)satpos;
1470 hsb.bri = 120; // paint it with 120 to get a nice bitmap
1472 bitmap.SetPixel (width, height, HSB.HSB2RGB (hsb.hue, hsb.sat, hsb.bri));
1481 public Bitmap Bitmap {
1492 internal class CrossCursor {
1493 private Bitmap bitmap;
1495 private Color cursorColor;
1497 public CrossCursor ()
1499 bitmap = new Bitmap (22, 22);
1501 cursorColor = Color.Black;
1508 using (Pen pen = new Pen (ThemeEngine.Current.ResPool.GetSolidBrush (cursorColor), 3)) {
1509 using (Graphics graphics = Graphics.FromImage (bitmap)) {
1510 graphics.DrawLine (pen, 11, 0, 11, 7);
1511 graphics.DrawLine (pen, 11, 14, 11, 21);
1512 graphics.DrawLine (pen, 0, 11, 7, 11);
1513 graphics.DrawLine (pen, 14, 11, 21, 11);
1518 public Bitmap Bitmap {
1528 public Color CursorColor {
1530 cursorColor = value;
1539 private DrawingBitmap drawingBitmap = null;
1541 private CrossCursor crossCursor = new CrossCursor();
1543 private bool mouseButtonDown = false;
1545 private bool drawCross = true;
1547 private Color color;
1549 private int currentXPos;
1550 private int currentYPos;
1552 private float xstep;
1553 private float ystep;
1555 private ColorDialog colorDialog;
1557 public ColorMatrixControl (ColorDialog colorDialog)
1559 this.colorDialog = colorDialog;
1563 BorderStyle = BorderStyle.Fixed3D;
1564 Location = new Point (0, 0);
1565 Size = new Size (179, 190);
1569 ResumeLayout (false);
1571 xstep = 240.0f / (ClientSize.Width - 1);
1572 ystep = 241.0f / (ClientSize.Height - 1);
1574 SetStyle (ControlStyles.DoubleBuffer, true);
1575 SetStyle (ControlStyles.AllPaintingInWmPaint, true);
1576 SetStyle (ControlStyles.UserPaint, true);
1579 protected override void OnPaint (PaintEventArgs e)
1581 if (drawingBitmap == null)
1582 drawingBitmap = new DrawingBitmap (ClientSize);
1589 private void Draw (PaintEventArgs e)
1591 e.Graphics.DrawImage (drawingBitmap.Bitmap, ClientRectangle.X, ClientRectangle.Y);
1593 // drawCross is false if the mouse gets moved...
1595 e.Graphics.DrawImage (crossCursor.Bitmap, currentXPos - 11 , currentYPos - 11);
1599 protected override void OnMouseDown (MouseEventArgs e)
1601 mouseButtonDown = true;
1611 XplatUI.GrabWindow (Handle, Handle);
1613 base.OnMouseDown (e);
1616 protected override void OnMouseMove (MouseEventArgs e)
1618 if (mouseButtonDown)
1619 if ((e.X < ClientSize.Width && e.X >= 0) && (e.Y < ClientSize.Height && e.Y >= 0)) {
1625 base.OnMouseMove (e);
1628 protected override void OnMouseUp (MouseEventArgs e)
1630 XplatUI.UngrabWindow (Handle);
1631 mouseButtonDown = false;
1637 public Color ColorToShow {
1643 private void ComputePos (Color acolor)
1645 if (acolor != color) {
1648 HSB hsb = HSB.RGB2HSB (color);
1650 currentXPos = (int)((float)hsb.hue / xstep);
1651 currentYPos = ClientSize.Height - 1 - (int)((float)hsb.sat / ystep);
1653 if (currentXPos < 0)
1655 if (currentYPos < 0)
1663 private Color GetColorFromHSB ()
1665 int hue = (int)((float)currentXPos * xstep);
1666 int sat = 240 - ((int)((float)currentYPos * ystep));
1667 int bri = TriangleControl.CurrentBrightness;
1669 return HSB.HSB2RGB (hue, sat, bri);
1672 private void UpdateControls ()
1674 Color tmpColor = GetColorFromHSB ();
1676 // update the brightness control
1677 colorDialog.brightnessControl.ShowColor ((int)((float)currentXPos * xstep), 240 - ((int)((float)currentYPos * ystep)));
1679 // update saturation text box
1680 int satvalue = (240 - ((int)((float)currentYPos * ystep)));
1681 colorDialog.satTextBox.Text = satvalue.ToString ();
1683 // update hue text box
1684 int huevalue = (int)((float)currentXPos * xstep);
1687 colorDialog.hueTextBox.Text = huevalue.ToString ();
1689 // update the main selected color panel
1690 colorDialog.selectedColorPanel.BackColor = tmpColor;
1692 // and finally the rgb text boxes
1693 colorDialog.UpdateRGBTextBoxes (tmpColor);
1698 internal class BrightnessControl : Panel {
1699 internal class DrawingBitmap {
1700 private Bitmap bitmap;
1702 public DrawingBitmap ()
1704 bitmap = new Bitmap (14, 190);
1707 public Bitmap Bitmap {
1717 // only hue and saturation are needed.
1718 // color will be computed with an iteration
1719 public void Draw (int hue, int sat)
1721 float brisub = 241.0f / 190.0f;
1724 for (int height = 0; height < 190; height++) {
1725 for (int width = 0; width < 14; width++) {
1726 Color pixcolor = HSB.HSB2RGB (hue, sat, (int)bri);
1727 bitmap.SetPixel (width, height, pixcolor);
1734 private const float step = 241.0f/189.0f;
1736 private DrawingBitmap bitmap;
1738 private ColorDialog colorDialog = null;
1740 public BrightnessControl (ColorDialog colorDialog)
1742 this.colorDialog = colorDialog;
1744 bitmap = new DrawingBitmap ();
1748 BorderStyle = BorderStyle.Fixed3D;
1749 Location = new Point (0, 0);
1750 Size = new Size (14, 190);
1753 Size = new Size (14, 190);
1755 ResumeLayout (false);
1757 SetStyle (ControlStyles.DoubleBuffer, true);
1758 SetStyle (ControlStyles.AllPaintingInWmPaint, true);
1759 SetStyle (ControlStyles.UserPaint, true);
1763 protected override void OnPaint (PaintEventArgs e)
1765 e.Graphics.DrawImage (bitmap.Bitmap, 0, 0);
1770 protected override void OnMouseDown (MouseEventArgs e)
1772 colorDialog.triangleControl.TrianglePosition = (int)((float)(189 - e.Y) * step);
1774 base.OnMouseDown (e);
1777 // this one is for ColorMatrixControl
1778 public void ShowColor (int hue, int sat)
1780 bitmap.Draw (hue, sat);
1785 // this one for the other controls
1786 public Color ColorToShow {
1789 HSB.GetHueSaturation (value, out hue, out sat);
1790 bitmap.Draw (hue, sat);
1798 internal class TriangleControl : Panel {
1799 private bool mouseButtonDown = false;
1801 private int currentTrianglePosition = 195;
1802 // private Rectangle clipRectangle;
1804 private const float briStep = 241.0f/186.0f;
1806 private static int currentBrightness = 0;
1808 private ColorDialog colorDialog;
1810 public TriangleControl (ColorDialog colorDialog)
1812 this.colorDialog = colorDialog;
1816 Size = new Size (16, 203);
1818 ResumeLayout (false);
1820 SetStyle (ControlStyles.DoubleBuffer, true);
1821 SetStyle (ControlStyles.AllPaintingInWmPaint, true);
1822 SetStyle (ControlStyles.UserPaint, true);
1825 public static int CurrentBrightness {
1827 currentBrightness = value;
1831 return currentBrightness;
1835 protected override void OnPaint (PaintEventArgs e)
1842 private void Draw (PaintEventArgs e)
1844 e.Graphics.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (BackColor), new Rectangle (0, 0, 16, 203));
1846 Point[] trianglePoints = new Point [3]
1848 new Point (0, currentTrianglePosition),
1849 new Point (8, currentTrianglePosition - 8),
1850 new Point (8, currentTrianglePosition + 8)
1853 e.Graphics.FillPolygon (ThemeEngine.Current.ResPool.GetSolidBrush (Color.Black), trianglePoints);
1856 protected override void OnMouseDown (MouseEventArgs e)
1858 if (e.Y > 195 || e.Y < 9) return; // helper until Cursor.Clip works
1860 mouseButtonDown = true;
1861 currentTrianglePosition = e.Y;
1863 // Cursor.Clip doesn't yet work in Managed.Windows.Forms
1864 // clipRectangle = Cursor.Clip;
1865 // Point p = Location;
1870 // Cursor.Clip = new Rectangle( Parent.PointToScreen( p ), s );
1872 colorDialog.briTextBox.Text = TrianglePosition.ToString ();
1873 colorDialog.UpdateFromHSBTextBoxes ();
1878 base.OnMouseDown (e);
1881 protected override void OnMouseMove (MouseEventArgs e)
1883 if (mouseButtonDown)
1884 if (e.Y < 196 && e.Y > 8) {
1885 currentTrianglePosition = e.Y;
1887 colorDialog.briTextBox.Text = TrianglePosition.ToString ();
1888 colorDialog.UpdateFromHSBTextBoxes ();
1894 base.OnMouseMove (e);
1897 protected override void OnMouseUp (MouseEventArgs e)
1899 mouseButtonDown = false;
1900 // Cursor.Clip = clipRectangle;
1905 public int TrianglePosition {
1907 float tmp = (float)(currentTrianglePosition - 9);
1908 tmp = tmp * briStep;
1910 int retval = 240 - (int)tmp;
1912 TriangleControl.CurrentBrightness = retval;
1918 float tmp = (float)value / briStep;
1919 currentTrianglePosition = 186 - (int)tmp + 9;
1921 colorDialog.briTextBox.Text = TrianglePosition.ToString ();
1923 colorDialog.UpdateFromHSBTextBoxes ();
1930 public Color ColorToShow {
1936 public void SetColor (Color color)
1938 int pos_raw = HSB.Brightness (color);
1940 float tmp = (float)pos_raw / briStep;
1941 currentTrianglePosition = 186 - (int)tmp + 9;
1943 if (colorDialog.edit_textbox == null)
1944 colorDialog.briTextBox.Text = TrianglePosition.ToString ();