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) 2006 Alexander Olk
23 // Alexander Olk alex.olk@googlemail.com
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 = new DialogForm (this);
78 form.SuspendLayout ();
82 form.FormBorderStyle = FormBorderStyle.FixedDialog;
83 form.MaximizeBox = false;
85 satTextBox = new TextBox ();
86 briTextBox = new TextBox ();
87 blueTextBox = new TextBox ();
88 greenTextBox = new TextBox ();
89 redTextBox = new TextBox ();
90 hueTextBox = new TextBox ();
92 redLabel = new Label ();
93 blueLabel = new Label ();
94 greenLabel = new Label ();
95 colorBaseLabel = new Label ();
96 hueLabel = new Label ();
97 satLabel = new Label ();
98 briLabel = new Label ();
100 okButton = new Button ();
101 cancelButton = new Button ();
102 form.CancelButton = cancelButton;
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 // FIXME: update resource files
200 defineColoursButton.Text = "Define Custom Colors >>";
201 //defineColoursButton.Text = Locale.GetText ("Define Custom Colors >>");
203 okButton.FlatStyle = FlatStyle.System;
204 okButton.Location = new Point (5, 271);
205 okButton.Size = new Size (66, 22);
206 okButton.TabIndex = 0;
207 okButton.Text = Locale.GetText ("OK");
209 cancelButton.FlatStyle = FlatStyle.System;
210 cancelButton.Location = new Point (78, 271);
211 cancelButton.Size = new Size (66, 22);
212 cancelButton.TabIndex = 1;
213 cancelButton.Text = Locale.GetText ("Cancel");
215 helpButton.FlatStyle = FlatStyle.System;
216 helpButton.Location = new Point (149, 271);
217 helpButton.Size = new Size (66, 22);
218 helpButton.TabIndex = 5;
219 helpButton.Text = Locale.GetText ("Help");
223 addColoursButton.FlatStyle = FlatStyle.System;
224 addColoursButton.Location = new Point (227, 271);
225 addColoursButton.Size = new Size (213, 22);
226 addColoursButton.TabIndex = 7;
227 // FIXME: update resource files
228 addColoursButton.Text = "Add To Custom Colors";
229 //addColoursButton.Text = Locale.GetText ("Add To Custom Colors");
232 baseColorControl.Location = new Point (3, 6);
233 baseColorControl.Size = new Size (212, 231);
234 baseColorControl.TabIndex = 13;
235 // colorMatrixControl
236 colorMatrixControl.Location = new Point (227, 7);
237 colorMatrixControl.Size = new Size (179, 190);
238 colorMatrixControl.TabIndex = 14;
240 triangleControl.Location = new Point (432, 0);
241 triangleControl.Size = new Size (16, 204);
242 triangleControl.TabIndex = 12;
244 brightnessControl.Location = new Point (415, 7);
245 brightnessControl.Size = new Size (14, 190);
246 brightnessControl.TabIndex = 20;
248 // selectedColorPanel
249 selectedColorPanel.BackColor = SystemColors.Desktop;
250 selectedColorPanel.BorderStyle = BorderStyle.Fixed3D;
251 selectedColorPanel.Location = new Point (227, 202);
252 selectedColorPanel.Size = new Size (60, 42);
253 selectedColorPanel.TabIndex = 10;
255 form.Controls.Add (hueTextBox);
256 form.Controls.Add (satTextBox);
257 form.Controls.Add (briTextBox);
258 form.Controls.Add (redTextBox);
259 form.Controls.Add (greenTextBox);
260 form.Controls.Add (blueTextBox);
262 form.Controls.Add (defineColoursButton);
263 form.Controls.Add (okButton);
264 form.Controls.Add (cancelButton);
265 form.Controls.Add (addColoursButton);
267 form.Controls.Add (baseColorControl);
268 form.Controls.Add (colorMatrixControl);
269 form.Controls.Add (brightnessControl);
270 form.Controls.Add (triangleControl);
272 form.Controls.Add (colorBaseLabel);
273 form.Controls.Add (greenLabel);
274 form.Controls.Add (blueLabel);
275 form.Controls.Add (redLabel);
276 form.Controls.Add (briLabel);
277 form.Controls.Add (hueLabel);
278 form.Controls.Add (satLabel);
280 form.Controls.Add (selectedColorPanel);
282 form.ResumeLayout (false);
286 defineColoursButton.Click += new EventHandler (OnClickButtonDefineColours);
287 addColoursButton.Click += new EventHandler (OnClickButtonAddColours);
288 helpButton.Click += new EventHandler (OnClickHelpButton);
289 cancelButton.Click += new EventHandler (OnClickCancelButton);
290 okButton.Click += new EventHandler (OnClickOkButton);
292 hueTextBox.KeyPress += new KeyPressEventHandler (OnKeyPressTextBoxes);
293 satTextBox.KeyPress += new KeyPressEventHandler (OnKeyPressTextBoxes);
294 briTextBox.KeyPress += new KeyPressEventHandler (OnKeyPressTextBoxes);
295 redTextBox.KeyPress += new KeyPressEventHandler (OnKeyPressTextBoxes);
296 greenTextBox.KeyPress += new KeyPressEventHandler (OnKeyPressTextBoxes);
297 blueTextBox.KeyPress += new KeyPressEventHandler (OnKeyPressTextBoxes);
299 hueTextBox.TextChanged += new EventHandler (OnTextChangedTextBoxes);
300 satTextBox.TextChanged += new EventHandler (OnTextChangedTextBoxes);
301 briTextBox.TextChanged += new EventHandler (OnTextChangedTextBoxes);
302 redTextBox.TextChanged += new EventHandler (OnTextChangedTextBoxes);
303 greenTextBox.TextChanged += new EventHandler (OnTextChangedTextBoxes);
304 blueTextBox.TextChanged += new EventHandler (OnTextChangedTextBoxes);
306 hueTextBox.GotFocus += new EventHandler (OnGotFocusTextBoxes);
307 satTextBox.GotFocus += new EventHandler (OnGotFocusTextBoxes);
308 briTextBox.GotFocus += new EventHandler (OnGotFocusTextBoxes);
309 redTextBox.GotFocus += new EventHandler (OnGotFocusTextBoxes);
310 greenTextBox.GotFocus += new EventHandler (OnGotFocusTextBoxes);
311 blueTextBox.GotFocus += new EventHandler (OnGotFocusTextBoxes);
313 hueTextBox.LostFocus += new EventHandler (OnLostFocusTextBoxes);
314 satTextBox.LostFocus += new EventHandler (OnLostFocusTextBoxes);
315 briTextBox.LostFocus += new EventHandler (OnLostFocusTextBoxes);
316 redTextBox.LostFocus += new EventHandler (OnLostFocusTextBoxes);
317 greenTextBox.LostFocus += new EventHandler (OnLostFocusTextBoxes);
318 blueTextBox.LostFocus += new EventHandler (OnLostFocusTextBoxes);
320 ResetCustomColors ();
322 #endregion // Public Constructors
324 #region Public Instance Properties
327 return selectedColorPanel.BackColor;
333 baseColorControl.SetColor (color);
334 } else if (color != value) {
336 baseColorControl.SetColor (color);
342 public virtual bool AllowFullOpen {
344 return allowFullOpen;
348 if (allowFullOpen != value) {
349 allowFullOpen = value;
352 defineColoursButton.Enabled = false;
354 defineColoursButton.Enabled = true;
359 // Currently AnyColor internally is always true
360 // Does really anybody still use 256 or less colors ???
361 // Naw, cairo only supports 24bit anyway - pdb
362 [DefaultValue(false)]
363 public virtual bool AnyColor {
373 [DefaultValue(false)]
374 public virtual bool FullOpen {
380 if (fullOpen != value) {
383 if (fullOpen && allowFullOpen) {
384 defineColoursButton.Enabled = false;
385 colorMatrixControl.ColorToShow = baseColorControl.ColorToShow;
386 form.Size = GetFormSize (true);
389 defineColoursButton.Enabled = true;
390 form.Size = GetFormSize (false);
397 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
398 public int[] CustomColors {
405 ResetCustomColors ();
407 int[] tmp_colors = value;
409 Array.Copy (tmp_colors, customColors, tmp_colors.Length);
412 baseColorControl.SetCustomColors ();
416 [DefaultValue(false)]
417 public virtual bool ShowHelp {
423 if (showHelp != value) {
433 [DefaultValue(false)]
434 public virtual bool SolidColorOnly {
436 return solidColorOnly;
440 solidColorOnly = value;
443 #endregion // Public Instance Properties
445 #region Public Instance Methods
446 public override void Reset ()
448 AllowFullOpen = true;
454 solidColorOnly = false;
457 public override string ToString ()
459 return base.ToString () + ", Color: " + Color.ToString ();
461 #endregion // Public Instance Methods
463 #region Protected Instance Properties
464 protected virtual IntPtr Instance {
467 return (IntPtr)GetHashCode ();
471 protected virtual int Options {
477 #endregion // Protected Instance Properties
479 #region Protected Instance Methods
480 protected override bool RunDialog (IntPtr hwndOwner)
482 defineColoursButton.Enabled = (AllowFullOpen && !FullOpen);
483 defineColoursButton.Refresh ();
485 form.Size = GetFormSize (FullOpen && AllowFullOpen);
486 // currently needed, otherwise there are a lot of drawing artefacts/transparent controls if the same dialog gets opened again
491 #endregion // Protected Instance Methods
493 #region Private Methods
495 Size GetFormSize (bool fullOpen)
498 return new Size (448, 332);
500 return new Size (221, 332); // 300
503 void OnClickCancelButton (object sender, EventArgs e)
505 form.DialogResult = DialogResult.Cancel;
508 void OnClickOkButton (object sender, EventArgs e)
510 form.DialogResult = DialogResult.OK;
513 void OnClickButtonAddColours (object sender, EventArgs e)
515 baseColorControl.SetUserColor (selectedColorPanel.BackColor);
518 void OnClickButtonDefineColours (object sender, EventArgs e)
521 defineColoursButton.Enabled = false;
522 colorMatrixControl.ColorToShow = baseColorControl.ColorToShow;
523 form.Size = GetFormSize (true);
527 // FIXME: Is this correct ?
528 void OnClickHelpButton (object sender, EventArgs e)
533 string textBox_text_old = "";
535 void OnGotFocusTextBoxes (object sender, EventArgs e)
537 TextBox textbox = sender as TextBox;
538 textBox_text_old = textbox.Text;
541 void OnLostFocusTextBoxes (object sender, EventArgs e)
543 TextBox textbox = sender as TextBox;
545 if (textbox.Text.Length == 0)
546 textbox.Text = textBox_text_old;
549 void OnKeyPressTextBoxes (object sender, KeyPressEventArgs e)
551 if (Char.IsLetter (e.KeyChar) || Char.IsWhiteSpace (e.KeyChar) || Char.IsPunctuation (e.KeyChar) || e.KeyChar == ',') {
556 internal_textbox_change = true;
559 internal TextBox edit_textbox = null;
560 bool internal_textbox_change = false;
562 void OnTextChangedTextBoxes (object sender, EventArgs e)
564 if (!internal_textbox_change)
567 internal_textbox_change = false;
569 TextBox tmp_box = sender as TextBox;
571 if (tmp_box.Text.Length == 0)
574 string text = tmp_box.Text;
579 val = System.Convert.ToInt32 (text);
580 } catch (Exception) {
584 if (sender == hueTextBox) {
587 hueTextBox.Text = val.ToString ();
591 hueTextBox.Text = val.ToString ();
594 edit_textbox = hueTextBox;
596 UpdateFromHSBTextBoxes ();
598 UpdateControls (selectedColorPanel.BackColor);
600 if (sender == satTextBox) {
603 satTextBox.Text = val.ToString ();
607 satTextBox.Text = val.ToString ();
610 edit_textbox = satTextBox;
612 UpdateFromHSBTextBoxes ();
614 UpdateControls (selectedColorPanel.BackColor);
616 if (sender == briTextBox) {
619 briTextBox.Text = val.ToString ();
623 briTextBox.Text = val.ToString ();
626 edit_textbox = briTextBox;
628 UpdateFromHSBTextBoxes ();
630 UpdateControls (selectedColorPanel.BackColor);
632 if (sender == redTextBox) {
635 redTextBox.Text = val.ToString ();
639 redTextBox.Text = val.ToString ();
642 edit_textbox = redTextBox;
644 UpdateFromRGBTextBoxes ();
646 if (sender == greenTextBox) {
649 greenTextBox.Text = val.ToString ();
653 greenTextBox.Text = val.ToString ();
656 edit_textbox = greenTextBox;
658 UpdateFromRGBTextBoxes ();
660 if (sender == blueTextBox) {
663 blueTextBox.Text = val.ToString ();
667 blueTextBox.Text = val.ToString ();
670 edit_textbox = blueTextBox;
672 UpdateFromRGBTextBoxes ();
675 textBox_text_old = edit_textbox.Text;
680 internal void UpdateControls (Color acolor)
682 selectedColorPanel.BackColor = acolor;
683 colorMatrixControl.ColorToShow = acolor;
684 brightnessControl.ColorToShow = acolor;
685 triangleControl.ColorToShow = acolor;
688 internal void UpdateRGBTextBoxes (Color acolor)
690 if (edit_textbox != redTextBox)
691 redTextBox.Text = acolor.R.ToString ();
692 if (edit_textbox != greenTextBox)
693 greenTextBox.Text = acolor.G.ToString ();
694 if (edit_textbox != blueTextBox)
695 blueTextBox.Text = acolor.B.ToString ();
698 internal void UpdateHSBTextBoxes (Color acolor)
700 HSB hsb = HSB.RGB2HSB (acolor);
702 if (edit_textbox != hueTextBox)
703 hueTextBox.Text = hsb.hue.ToString ();
704 if (edit_textbox != satTextBox)
705 satTextBox.Text = hsb.sat.ToString ();
706 if (edit_textbox != briTextBox)
707 briTextBox.Text = hsb.bri.ToString ();
710 internal void UpdateFromHSBTextBoxes ()
712 Color col = HSB.HSB2RGB (System.Convert.ToInt32 (hueTextBox.Text),
713 System.Convert.ToInt32 (satTextBox.Text),
714 System.Convert.ToInt32 (briTextBox.Text));
716 selectedColorPanel.BackColor = col;
717 UpdateRGBTextBoxes (col);
720 internal void UpdateFromRGBTextBoxes ()
722 Color col = Color.FromArgb (System.Convert.ToInt32 (redTextBox.Text),
723 System.Convert.ToInt32 (greenTextBox.Text),
724 System.Convert.ToInt32 (blueTextBox.Text));
726 selectedColorPanel.BackColor = col;
728 UpdateHSBTextBoxes (col);
730 UpdateControls (col);
733 void ResetCustomColors ()
735 // check if this.customColors already exists
736 if (customColors == null)
737 customColors = new int [16];
739 int default_color = Color.FromArgb(0, 255, 255, 255).ToArgb ();
741 for (int i = 0; i < customColors.Length; i++)
742 customColors [i] = default_color;
746 #region Internal structs and classes
747 internal struct HSB {
752 public static HSB RGB2HSB (Color color)
754 HSB hsb = new HSB ();
756 hsb.hue = (int)((color.GetHue () / 360.0f) * 240);
757 hsb.sat = (int)(color.GetSaturation () * 241);
758 hsb.bri = (int)(color.GetBrightness () * 241);
760 if (hsb.hue > 239) hsb.hue = 239;
761 if (hsb.sat > 240) hsb.sat = 240;
762 if (hsb.bri > 240) hsb.bri = 240;
767 // not using ControlPaint HBS2Color, this algo is more precise
768 public static Color HSB2RGB (int hue, int saturation, int brightness)
776 if (saturation > 240)
782 if (brightness > 240)
788 float H = hue / 239.0f;
789 float S = saturation / 240.0f;
790 float L = brightness / 240.0f;
792 float r = 0, g = 0, b = 0;
801 d2 = (L <= 0.5f) ? L * (1.0f + S) : L + S - (L * S);
804 float[] d3 = new float [] { H + 1.0f / 3.0f , H, H - 1.0f / 3.0f };
805 float[] rgb = new float [] { 0,0,0 };
807 for (int i = 0; i < 3; i++) {
813 if (6.0f * d3 [i] < 1.0f)
814 rgb [i] = d1 + (d2 - d1) * d3 [i] * 6.0f;
816 if (2.0f * d3 [i] < 1.0f)
819 if (3.0f * d3 [i] < 2.0f)
820 rgb [i] = (d1 + (d2 - d1) * ((2.0f / 3.0f) - d3 [i]) * 6.0f);
853 return Color.FromArgb ((int)r, (int)g, (int)b);
856 public static int Brightness (Color color)
858 return (int)(color.GetBrightness () * 241);
861 public static void GetHueSaturation (Color color, out int hue, out int sat)
863 hue = (int)((color.GetHue () / 360.0f) * 240);
864 sat = (int)(color.GetSaturation () * 241);
868 // there are some small glitches, but it is still better than ControlPaint implementation
869 public static void TestColor (Color color)
871 Console.WriteLine ("Color: " + color);
872 HSB hsb = HSB.RGB2HSB (color);
873 Console.WriteLine ("RGB2HSB: " + hsb.hue + ", " + hsb.sat + ", " + hsb.bri);
874 Console.WriteLine ("HSB2RGB: " + HSB.HSB2RGB (hsb.hue, hsb.sat, hsb.bri));
875 Console.WriteLine ();
879 internal class BaseColorControl : Control {
880 internal class SmallColorControl : Control {
881 private Color internalcolor;
883 private bool isSelected = false;
885 public SmallColorControl (Color color)
889 this.internalcolor = color;
891 Size = new Size (25, 23);
893 ResumeLayout (false);
895 SetStyle (ControlStyles.DoubleBuffer, true);
896 SetStyle (ControlStyles.AllPaintingInWmPaint, true);
897 SetStyle (ControlStyles.UserPaint, true);
898 SetStyle (ControlStyles.Selectable, true);
901 public bool IsSelected {
912 public Color InternalColor {
914 internalcolor = value;
919 return internalcolor;
923 protected override void OnPaint (PaintEventArgs pe)
927 pe.Graphics.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (internalcolor),
928 new Rectangle (4, 4, 17, 15));
930 ControlPaint.DrawBorder3D (pe.Graphics, 3, 3, 19, 17, Border3DStyle.Sunken);
933 pe.Graphics.DrawRectangle (ThemeEngine.Current.ResPool.GetPen (Color.Black),
934 new Rectangle (2, 2, 20, 18));
938 ControlPaint.DrawFocusRectangle (
939 pe.Graphics, new Rectangle (0, 0, 25, 23)
944 protected override void OnClick (EventArgs e)
953 protected override void OnLostFocus (EventArgs e)
957 base.OnLostFocus (e);
961 private SmallColorControl[] smallColorControl;
963 private SmallColorControl[] userSmallColorControl;
965 private Label userColorLabel;
966 private Label baseColorLabel;
968 private SmallColorControl selectedSmallColorControl;
970 #region UIA Framework Property
972 public SmallColorControl UIASelectedSmallColorControl {
974 for (int i = 0; i < smallColorControl.Length - 1; ++i)
975 if (smallColorControl [i].IsSelected)
976 return smallColorControl [i];
977 for (int j = 0; j < userSmallColorControl.Length - 1; ++j)
978 if (userSmallColorControl [j].IsSelected)
979 return userSmallColorControl [j];
986 private int currentlyUsedUserSmallColorControl = 0;
988 private ColorDialog colorDialog = null;
990 public BaseColorControl (ColorDialog colorDialog)
992 this.colorDialog = colorDialog;
994 userSmallColorControl = new SmallColorControl [16];
995 userSmallColorControl [0] = new SmallColorControl (Color.White);
996 userSmallColorControl [1] = new SmallColorControl (Color.White);
997 userSmallColorControl [2] = new SmallColorControl (Color.White);
998 userSmallColorControl [3] = new SmallColorControl (Color.White);
999 userSmallColorControl [4] = new SmallColorControl (Color.White);
1000 userSmallColorControl [5] = new SmallColorControl (Color.White);
1001 userSmallColorControl [6] = new SmallColorControl (Color.White);
1002 userSmallColorControl [7] = new SmallColorControl (Color.White);
1003 userSmallColorControl [8] = new SmallColorControl (Color.White);
1004 userSmallColorControl [9] = new SmallColorControl (Color.White);
1005 userSmallColorControl [10] = new SmallColorControl (Color.White);
1006 userSmallColorControl [11] = new SmallColorControl (Color.White);
1007 userSmallColorControl [12] = new SmallColorControl (Color.White);
1008 userSmallColorControl [13] = new SmallColorControl (Color.White);
1009 userSmallColorControl [14] = new SmallColorControl (Color.White);
1010 userSmallColorControl [15] = new SmallColorControl (Color.White);
1012 smallColorControl = new SmallColorControl [48];
1013 smallColorControl [0] = new SmallColorControl (Color.FromArgb (((Byte)(255)), ((Byte)(128)), ((Byte)(128))));
1014 smallColorControl [1] = new SmallColorControl (Color.FromArgb (((Byte)(128)), ((Byte)(128)), ((Byte)(64))));
1015 smallColorControl [2] = new SmallColorControl (Color.Gray);
1016 smallColorControl [3] = new SmallColorControl (Color.FromArgb (((Byte)(128)), ((Byte)(0)), ((Byte)(255))));
1017 smallColorControl [4] = new SmallColorControl (Color.Silver);
1018 smallColorControl [5] = new SmallColorControl (Color.FromArgb (((Byte)(64)), ((Byte)(128)), ((Byte)(128))));
1019 smallColorControl [6] = new SmallColorControl (Color.White);
1020 smallColorControl [7] = new SmallColorControl (Color.FromArgb (((Byte)(64)), ((Byte)(0)), ((Byte)(64))));
1021 smallColorControl [8] = new SmallColorControl (Color.FromArgb (((Byte)(255)), ((Byte)(128)), ((Byte)(64))));
1022 smallColorControl [9] = new SmallColorControl (Color.FromArgb (((Byte)(128)), ((Byte)(64)), ((Byte)(64))));
1023 smallColorControl [10] = new SmallColorControl (Color.Teal);
1024 smallColorControl [11] = new SmallColorControl (Color.Lime);
1025 smallColorControl [12] = new SmallColorControl (Color.FromArgb (((Byte)(128)), ((Byte)(128)), ((Byte)(255))));
1026 smallColorControl [13] = new SmallColorControl (Color.FromArgb (((Byte)(0)), ((Byte)(64)), ((Byte)(128))));
1027 smallColorControl [14] = new SmallColorControl (Color.FromArgb (((Byte)(255)), ((Byte)(0)), ((Byte)(128))));
1028 smallColorControl [15] = new SmallColorControl (Color.FromArgb (((Byte)(128)), ((Byte)(255)), ((Byte)(0))));
1029 smallColorControl [16] = new SmallColorControl (Color.FromArgb (((Byte)(0)), ((Byte)(255)), ((Byte)(64))));
1030 smallColorControl [17] = new SmallColorControl (Color.Red);
1031 smallColorControl [18] = new SmallColorControl (Color.FromArgb (((Byte)(255)), ((Byte)(128)), ((Byte)(0))));
1032 smallColorControl [19] = new SmallColorControl (Color.FromArgb (((Byte)(255)), ((Byte)(128)), ((Byte)(255))));
1033 smallColorControl [20] = new SmallColorControl (Color.Fuchsia);
1034 smallColorControl [21] = new SmallColorControl (Color.Aqua);
1035 smallColorControl [22] = new SmallColorControl (Color.FromArgb (((Byte)(128)), ((Byte)(255)), ((Byte)(128))));
1036 smallColorControl [23] = new SmallColorControl (Color.FromArgb (((Byte)(128)), ((Byte)(255)), ((Byte)(255))));
1037 smallColorControl [24] = new SmallColorControl (Color.FromArgb (((Byte)(0)), ((Byte)(128)), ((Byte)(255))));
1038 smallColorControl [25] = new SmallColorControl (Color.FromArgb (((Byte)(128)), ((Byte)(64)), ((Byte)(0))));
1039 smallColorControl [26] = new SmallColorControl (Color.FromArgb (((Byte)(64)), ((Byte)(0)), ((Byte)(0))));
1040 smallColorControl [27] = new SmallColorControl (Color.Maroon);
1041 smallColorControl [28] = new SmallColorControl (Color.Purple);
1042 smallColorControl [29] = new SmallColorControl (Color.FromArgb (((Byte)(0)), ((Byte)(0)), ((Byte)(160))));
1043 smallColorControl [30] = new SmallColorControl (Color.Blue);
1044 smallColorControl [31] = new SmallColorControl (Color.FromArgb (((Byte)(0)), ((Byte)(128)), ((Byte)(64))));
1045 smallColorControl [32] = new SmallColorControl (Color.Green);
1046 smallColorControl [33] = new SmallColorControl (Color.Yellow);
1047 smallColorControl [34] = new SmallColorControl (Color.FromArgb (((Byte)(128)), ((Byte)(128)), ((Byte)(192))));
1048 smallColorControl [35] = new SmallColorControl (Color.FromArgb (((Byte)(0)), ((Byte)(128)), ((Byte)(192))));
1049 smallColorControl [36] = new SmallColorControl (Color.FromArgb (((Byte)(128)), ((Byte)(0)), ((Byte)(64))));
1050 smallColorControl [37] = new SmallColorControl (Color.FromArgb (((Byte)(255)), ((Byte)(128)), ((Byte)(192))));
1051 smallColorControl [38] = new SmallColorControl (Color.FromArgb (((Byte)(0)), ((Byte)(255)), ((Byte)(128))));
1052 smallColorControl [39] = new SmallColorControl (Color.FromArgb (((Byte)(255)), ((Byte)(255)), ((Byte)(128))));
1053 smallColorControl [40] = new SmallColorControl (Color.FromArgb (((Byte)(0)), ((Byte)(64)), ((Byte)(0))));
1054 smallColorControl [41] = new SmallColorControl (Color.FromArgb (((Byte)(0)), ((Byte)(64)), ((Byte)(64))));
1055 smallColorControl [42] = new SmallColorControl (Color.Navy);
1056 smallColorControl [43] = new SmallColorControl (Color.FromArgb (((Byte)(0)), ((Byte)(0)), ((Byte)(64))));
1057 smallColorControl [44] = new SmallColorControl (Color.FromArgb (((Byte)(64)), ((Byte)(0)), ((Byte)(64))));
1058 smallColorControl [45] = new SmallColorControl (Color.FromArgb (((Byte)(64)), ((Byte)(0)), ((Byte)(128))));
1059 smallColorControl [46] = new SmallColorControl (Color.Black); //Black
1060 smallColorControl [47] = new SmallColorControl (Color.Olive);
1062 baseColorLabel = new Label ();
1063 userColorLabel = new Label ();
1068 smallColorControl [0].Location = new Point (0, 15);
1069 smallColorControl [0].TabIndex = 51;
1070 smallColorControl [0].Click += new EventHandler (OnSmallColorControlClick);
1072 smallColorControl [1].Location = new Point (50, 130);
1073 smallColorControl [1].TabIndex = 92;
1074 smallColorControl [1].Click += new EventHandler (OnSmallColorControlClick);
1076 smallColorControl [2].Location = new Point (75, 130);
1077 smallColorControl [2].TabIndex = 93;
1078 smallColorControl [2].Click += new EventHandler (OnSmallColorControlClick);
1080 smallColorControl [3].Location = new Point (175, 84);
1081 smallColorControl [3].TabIndex = 98;
1082 smallColorControl [3].Click += new EventHandler (OnSmallColorControlClick);
1084 smallColorControl [4].Location = new Point (125, 130);
1085 smallColorControl [4].TabIndex = 95;
1086 smallColorControl [4].Click += new EventHandler (OnSmallColorControlClick);
1088 smallColorControl [5].Location = new Point (100, 130);
1089 smallColorControl [5].TabIndex = 94;
1090 smallColorControl [5].Click += new EventHandler (OnSmallColorControlClick);
1092 smallColorControl [6].Location = new Point (175, 130);
1093 smallColorControl [6].TabIndex = 97;
1094 smallColorControl [6].Click += new EventHandler (OnSmallColorControlClick);
1096 smallColorControl [7].Location = new Point (150, 130);
1097 smallColorControl [7].TabIndex = 96;
1098 smallColorControl [7].Click += new EventHandler (OnSmallColorControlClick);
1100 smallColorControl [8].Location = new Point (25, 61);
1101 smallColorControl [8].TabIndex = 68;
1102 smallColorControl [8].Click += new EventHandler (OnSmallColorControlClick);
1104 smallColorControl [9].Location = new Point (0, 61);
1105 smallColorControl [9].TabIndex = 67;
1106 smallColorControl [9].Click += new EventHandler (OnSmallColorControlClick);
1108 smallColorControl [10].Location = new Point (75, 61);
1109 smallColorControl [10].TabIndex = 70;
1110 smallColorControl [10].Click += new EventHandler (OnSmallColorControlClick);
1112 smallColorControl [11].Location = new Point (50, 61);
1113 smallColorControl [11].TabIndex = 69;
1114 smallColorControl [11].Click += new EventHandler (OnSmallColorControlClick);
1116 smallColorControl [12].Location = new Point (125, 61);
1117 smallColorControl [12].TabIndex = 72;
1118 smallColorControl [12].Click += new EventHandler (OnSmallColorControlClick);
1120 smallColorControl [13].Location = new Point (100, 61);
1121 smallColorControl [13].TabIndex = 71;
1122 smallColorControl [13].Click += new EventHandler (OnSmallColorControlClick);
1124 smallColorControl [14].Location = new Point (175, 61);
1125 smallColorControl [14].TabIndex = 74;
1126 smallColorControl [14].Click += new EventHandler (OnSmallColorControlClick);
1128 smallColorControl [15].Location = new Point (50, 38);
1129 smallColorControl [15].TabIndex = 61;
1130 smallColorControl [15].Click += new EventHandler (OnSmallColorControlClick);
1132 smallColorControl [16].Location = new Point (75, 38);
1133 smallColorControl [16].TabIndex = 62;
1134 smallColorControl [16].Click += new EventHandler (OnSmallColorControlClick);
1136 smallColorControl [17].Location = new Point (0, 38);
1137 smallColorControl [17].TabIndex = 59;
1138 smallColorControl [17].Click += new EventHandler (OnSmallColorControlClick);
1140 smallColorControl [18].Location = new Point (25, 84);
1141 smallColorControl [18].TabIndex = 75;
1142 smallColorControl [18].Click += new EventHandler (OnSmallColorControlClick);
1144 smallColorControl [19].Location = new Point (175, 15);
1145 smallColorControl [19].TabIndex = 58;
1146 smallColorControl [19].Click += new EventHandler (OnSmallColorControlClick);
1148 smallColorControl [20].Location = new Point (175, 38);
1149 smallColorControl [20].TabIndex = 66;
1150 smallColorControl [20].Click += new EventHandler (OnSmallColorControlClick);
1152 smallColorControl [21].Location = new Point (100, 38);
1153 smallColorControl [21].TabIndex = 63;
1154 smallColorControl [21].Click += new EventHandler (OnSmallColorControlClick);
1156 smallColorControl [22].Location = new Point (50, 15);
1157 smallColorControl [22].TabIndex = 53;
1158 smallColorControl [22].Click += new EventHandler (OnSmallColorControlClick);
1160 smallColorControl [23].Location = new Point (100, 15);
1161 smallColorControl [23].TabIndex = 55;
1162 smallColorControl [23].Click += new EventHandler (OnSmallColorControlClick);
1164 smallColorControl [24].Location = new Point (125, 15);
1165 smallColorControl [24].TabIndex = 56;
1166 smallColorControl [24].Click += new EventHandler (OnSmallColorControlClick);
1168 smallColorControl [25].Location = new Point (25, 107);
1169 smallColorControl [25].TabIndex = 83;
1170 smallColorControl [25].Click += new EventHandler (OnSmallColorControlClick);
1172 smallColorControl [26].Location = new Point (0, 107);
1173 smallColorControl [26].TabIndex = 82;
1174 smallColorControl [26].Click += new EventHandler (OnSmallColorControlClick);
1176 smallColorControl [27].Location = new Point (0, 84);
1177 smallColorControl [27].TabIndex = 81;
1178 smallColorControl [27].Click += new EventHandler (OnSmallColorControlClick);
1180 smallColorControl [28].Location = new Point (150, 84);
1181 smallColorControl [28].TabIndex = 80;
1182 smallColorControl [28].Click += new EventHandler (OnSmallColorControlClick);
1184 smallColorControl [29].Location = new Point (125, 84);
1185 smallColorControl [29].TabIndex = 79;
1186 smallColorControl [29].Click += new EventHandler (OnSmallColorControlClick);
1188 smallColorControl [30].Location = new Point (100, 84);
1189 smallColorControl [30].TabIndex = 78;
1190 smallColorControl [30].Click += new EventHandler (OnSmallColorControlClick);
1192 smallColorControl [31].Location = new Point (75, 84);
1193 smallColorControl [31].TabIndex = 77;
1194 smallColorControl [31].Click += new EventHandler (OnSmallColorControlClick);
1196 smallColorControl [32].Location = new Point (50, 84);
1197 smallColorControl [32].TabIndex = 76;
1198 smallColorControl [32].Click += new EventHandler (OnSmallColorControlClick);
1200 smallColorControl [33].Location = new Point (25, 38);
1201 smallColorControl [33].TabIndex = 60;
1202 smallColorControl [33].Click += new EventHandler (OnSmallColorControlClick);
1204 smallColorControl [34].Location = new Point (150, 38);
1205 smallColorControl [34].TabIndex = 65;
1206 smallColorControl [34].Click += new EventHandler (OnSmallColorControlClick);
1208 smallColorControl [35].Location = new Point (125, 38);
1209 smallColorControl [35].TabIndex = 64;
1210 smallColorControl [35].Click += new EventHandler (OnSmallColorControlClick);
1212 smallColorControl [36].Location = new Point (150, 61);
1213 smallColorControl [36].TabIndex = 73;
1214 smallColorControl [36].Click += new EventHandler (OnSmallColorControlClick);
1216 smallColorControl [37].Location = new Point (150, 15);
1217 smallColorControl [37].TabIndex = 57;
1218 smallColorControl [37].Click += new EventHandler (OnSmallColorControlClick);
1220 smallColorControl [38].Location = new Point (75, 15);
1221 smallColorControl [38].TabIndex = 54;
1222 smallColorControl [38].Click += new EventHandler (OnSmallColorControlClick);
1224 smallColorControl [39].Location = new Point (25, 15);
1225 smallColorControl [39].TabIndex = 52;
1226 smallColorControl [39].Click += new EventHandler (OnSmallColorControlClick);
1228 smallColorControl [40].Location = new Point (50, 107);
1229 smallColorControl [40].TabIndex = 84;
1230 smallColorControl [40].Click += new EventHandler (OnSmallColorControlClick);
1232 smallColorControl [41].Location = new Point (75, 107);
1233 smallColorControl [41].TabIndex = 85;
1234 smallColorControl [41].Click += new EventHandler (OnSmallColorControlClick);
1236 smallColorControl [42].Location = new Point (100, 107);
1237 smallColorControl [42].TabIndex = 86;
1238 smallColorControl [42].Click += new EventHandler (OnSmallColorControlClick);
1240 smallColorControl [43].Location = new Point (125, 107);
1241 smallColorControl [43].TabIndex = 87;
1242 smallColorControl [43].Click += new EventHandler (OnSmallColorControlClick);
1244 smallColorControl [44].Location = new Point (150, 107);
1245 smallColorControl [44].TabIndex = 88;
1246 smallColorControl [44].Click += new EventHandler (OnSmallColorControlClick);
1248 smallColorControl [45].Location = new Point (175, 107);
1249 smallColorControl [45].TabIndex = 89;
1250 smallColorControl [45].Click += new EventHandler (OnSmallColorControlClick);
1252 smallColorControl [46].Location = new Point (0, 130);
1253 smallColorControl [46].TabIndex = 90;
1254 smallColorControl [46].Click += new EventHandler (OnSmallColorControlClick);
1256 smallColorControl [47].Location = new Point (25, 130);
1257 smallColorControl [47].TabIndex = 91;
1258 smallColorControl [47].Click += new EventHandler (OnSmallColorControlClick);
1261 userSmallColorControl [0].Location = new Point (0, 180);
1262 userSmallColorControl [0].TabIndex = 99;
1263 userSmallColorControl [0].Click += new EventHandler (OnSmallColorControlClick);
1265 userSmallColorControl [1].Location = new Point (0, 203);
1266 userSmallColorControl [1].TabIndex = 108;
1267 userSmallColorControl [1].Click += new EventHandler (OnSmallColorControlClick);
1269 userSmallColorControl [2].Location = new Point (25, 180);
1270 userSmallColorControl [2].TabIndex = 100;
1271 userSmallColorControl [2].Click += new EventHandler (OnSmallColorControlClick);
1273 userSmallColorControl [3].Location = new Point (25, 203);
1274 userSmallColorControl [3].TabIndex = 109;
1275 userSmallColorControl [3].Click += new EventHandler (OnSmallColorControlClick);
1277 userSmallColorControl [4].Location = new Point (50, 180);
1278 userSmallColorControl [4].TabIndex = 101;
1279 userSmallColorControl [4].Click += new EventHandler (OnSmallColorControlClick);
1281 userSmallColorControl [5].Location = new Point (50, 203);
1282 userSmallColorControl [5].TabIndex = 110;
1283 userSmallColorControl [5].Click += new EventHandler (OnSmallColorControlClick);
1285 userSmallColorControl [6].Location = new Point (75, 180);
1286 userSmallColorControl [6].TabIndex = 102;
1287 userSmallColorControl [6].Click += new EventHandler (OnSmallColorControlClick);
1289 userSmallColorControl [7].Location = new Point (75, 203);
1290 userSmallColorControl [7].TabIndex = 111;
1291 userSmallColorControl [7].Click += new EventHandler (OnSmallColorControlClick);
1293 userSmallColorControl [8].Location = new Point (100, 180);
1294 userSmallColorControl [8].TabIndex = 103;
1295 userSmallColorControl [8].Click += new EventHandler (OnSmallColorControlClick);
1297 userSmallColorControl [9].Location = new Point (100, 203);
1298 userSmallColorControl [9].TabIndex = 112;
1299 userSmallColorControl [9].Click += new EventHandler (OnSmallColorControlClick);
1301 userSmallColorControl [10].Location = new Point (125, 180);
1302 userSmallColorControl [10].TabIndex = 105;
1303 userSmallColorControl [10].Click += new EventHandler (OnSmallColorControlClick);
1305 userSmallColorControl [11].Location = new Point (125, 203);
1306 userSmallColorControl [11].TabIndex = 113;
1307 userSmallColorControl [11].Click += new EventHandler (OnSmallColorControlClick);
1309 userSmallColorControl [12].Location = new Point (150, 180);
1310 userSmallColorControl [12].TabIndex = 106;
1311 userSmallColorControl [12].Click += new EventHandler (OnSmallColorControlClick);
1313 userSmallColorControl [13].Location = new Point (150, 203);
1314 userSmallColorControl [13].TabIndex = 114;
1315 userSmallColorControl [13].Click += new EventHandler (OnSmallColorControlClick);
1317 userSmallColorControl [14].Location = new Point (175, 180);
1318 userSmallColorControl [14].TabIndex = 107;
1319 userSmallColorControl [14].Click += new EventHandler (OnSmallColorControlClick);
1321 userSmallColorControl [15].Location = new Point (175, 203);
1322 userSmallColorControl [15].TabIndex = 115;
1323 userSmallColorControl [15].Click += new EventHandler (OnSmallColorControlClick);
1326 baseColorLabel.Location = new Point (2, 0);
1327 baseColorLabel.Size = new Size (200, 12);
1328 baseColorLabel.TabIndex = 5;
1329 baseColorLabel.Text = Locale.GetText ("Base Colors") + ":";
1331 userColorLabel.FlatStyle = FlatStyle.System;
1332 userColorLabel.Location = new Point (2, 164);
1333 userColorLabel.Size = new Size (200, 14);
1334 userColorLabel.TabIndex = 104;
1335 userColorLabel.Text = Locale.GetText ("User Colors") + ":";
1337 Controls.Add (userSmallColorControl [7]);
1338 Controls.Add (userSmallColorControl [6]);
1339 Controls.Add (userSmallColorControl [5]);
1340 Controls.Add (userSmallColorControl [4]);
1341 Controls.Add (userSmallColorControl [3]);
1342 Controls.Add (userSmallColorControl [2]);
1343 Controls.Add (userSmallColorControl [1]);
1344 Controls.Add (userSmallColorControl [0]);
1345 Controls.Add (userSmallColorControl [15]);
1346 Controls.Add (userSmallColorControl [14]);
1347 Controls.Add (userSmallColorControl [13]);
1348 Controls.Add (userSmallColorControl [12]);
1349 Controls.Add (userSmallColorControl [11]);
1350 Controls.Add (userSmallColorControl [10]);
1351 Controls.Add (userSmallColorControl [9]);
1352 Controls.Add (userSmallColorControl [8]);
1354 Controls.Add (smallColorControl [0]);
1355 Controls.Add (smallColorControl [3]);
1356 Controls.Add (smallColorControl [6]);
1357 Controls.Add (smallColorControl [7]);
1358 Controls.Add (smallColorControl [4]);
1359 Controls.Add (smallColorControl [5]);
1360 Controls.Add (smallColorControl [2]);
1361 Controls.Add (smallColorControl [1]);
1362 Controls.Add (smallColorControl [47]);
1363 Controls.Add (smallColorControl [46]);
1364 Controls.Add (smallColorControl [45]);
1365 Controls.Add (smallColorControl [44]);
1366 Controls.Add (smallColorControl [43]);
1367 Controls.Add (smallColorControl [42]);
1368 Controls.Add (smallColorControl [41]);
1369 Controls.Add (smallColorControl [40]);
1370 Controls.Add (smallColorControl [25]);
1371 Controls.Add (smallColorControl [26]);
1372 Controls.Add (smallColorControl [27]);
1373 Controls.Add (smallColorControl [28]);
1374 Controls.Add (smallColorControl [29]);
1375 Controls.Add (smallColorControl [30]);
1376 Controls.Add (smallColorControl [31]);
1377 Controls.Add (smallColorControl [32]);
1378 Controls.Add (smallColorControl [18]);
1379 Controls.Add (smallColorControl [14]);
1380 Controls.Add (smallColorControl [36]);
1381 Controls.Add (smallColorControl [12]);
1382 Controls.Add (smallColorControl [13]);
1383 Controls.Add (smallColorControl [10]);
1384 Controls.Add (smallColorControl [11]);
1385 Controls.Add (smallColorControl [8]);
1386 Controls.Add (smallColorControl [9]);
1387 Controls.Add (smallColorControl [20]);
1388 Controls.Add (smallColorControl [34]);
1389 Controls.Add (smallColorControl [35]);
1390 Controls.Add (smallColorControl [21]);
1391 Controls.Add (smallColorControl [16]);
1392 Controls.Add (smallColorControl [15]);
1393 Controls.Add (smallColorControl [33]);
1394 Controls.Add (smallColorControl [17]);
1395 Controls.Add (smallColorControl [19]);
1396 Controls.Add (smallColorControl [37]);
1397 Controls.Add (smallColorControl [24]);
1398 Controls.Add (smallColorControl [23]);
1399 Controls.Add (smallColorControl [38]);
1400 Controls.Add (smallColorControl [22]);
1401 Controls.Add (smallColorControl [39]);
1403 Controls.Add (userColorLabel);
1404 Controls.Add (baseColorLabel);
1406 Size = new Size (212, 238);
1408 ResumeLayout (false);
1411 private void CheckIfColorIsInPanel (Color color)
1413 // check if we have a panel with a BackColor = color...
1414 for (int i = 0; i < smallColorControl.Length; i++) {
1415 if (smallColorControl [i].InternalColor == color) {
1416 selectedSmallColorControl = smallColorControl [i];
1417 selectedSmallColorControl.IsSelected = true;
1423 void OnSmallColorControlClick (object sender, EventArgs e)
1425 // previous selected smallcolorcontrol
1426 if (selectedSmallColorControl != (SmallColorControl)sender)
1427 selectedSmallColorControl.IsSelected = false;
1429 selectedSmallColorControl = (SmallColorControl)sender;
1431 TriangleControl.CurrentBrightness = HSB.Brightness (selectedSmallColorControl.InternalColor);
1433 colorDialog.UpdateControls (selectedSmallColorControl.InternalColor);
1434 colorDialog.UpdateRGBTextBoxes (selectedSmallColorControl.InternalColor);
1435 colorDialog.UpdateHSBTextBoxes (selectedSmallColorControl.InternalColor);
1438 public Color ColorToShow {
1440 return selectedSmallColorControl.InternalColor;
1445 public void SetColor (Color acolor)
1447 if (selectedSmallColorControl != null)
1448 selectedSmallColorControl.IsSelected = false;
1450 CheckIfColorIsInPanel (acolor);
1452 TriangleControl.CurrentBrightness = HSB.Brightness (acolor);
1454 colorDialog.UpdateControls (acolor);
1455 colorDialog.UpdateRGBTextBoxes (acolor);
1456 colorDialog.UpdateHSBTextBoxes (acolor);
1459 public void SetUserColor (Color col)
1461 userSmallColorControl [currentlyUsedUserSmallColorControl].InternalColor = col;
1463 colorDialog.customColors [currentlyUsedUserSmallColorControl] = col.ToArgb ();
1465 currentlyUsedUserSmallColorControl++;
1466 if (currentlyUsedUserSmallColorControl > 15)
1467 currentlyUsedUserSmallColorControl = 0;
1470 public void SetCustomColors ()
1472 for (int i = 0; i < colorDialog.customColors.Length; i++) {
1473 userSmallColorControl [i].InternalColor = Color.FromArgb (colorDialog.customColors [i]);
1478 internal class ColorMatrixControl : Panel {
1479 internal class DrawingBitmap {
1480 private Bitmap bitmap;
1482 public DrawingBitmap (Size size)
1484 bitmap = new Bitmap (size.Width, size.Height);
1486 float hueadd = 240.0f / (size.Width - 1);
1487 float satsub = 241.0f / (size.Height - 1);
1488 float satpos = 240.0f;
1490 // paint the matrix to the bitmap
1491 for (int height = 0; height < size.Height; height++) {
1492 float huepos = 0.0f;
1494 for (int width = 0; width < size.Width; width++) {
1495 HSB hsb = new HSB ();
1497 hsb.hue = (int)huepos;
1498 hsb.sat = (int)satpos;
1499 hsb.bri = 120; // paint it with 120 to get a nice bitmap
1501 bitmap.SetPixel (width, height, HSB.HSB2RGB (hsb.hue, hsb.sat, hsb.bri));
1510 public Bitmap Bitmap {
1521 internal class CrossCursor {
1522 private Bitmap bitmap;
1524 private Color cursorColor;
1526 public CrossCursor ()
1528 bitmap = new Bitmap (22, 22);
1530 cursorColor = Color.Black;
1537 using (Pen pen = new Pen (ThemeEngine.Current.ResPool.GetSolidBrush (cursorColor), 3)) {
1538 using (Graphics graphics = Graphics.FromImage (bitmap)) {
1539 graphics.DrawLine (pen, 11, 0, 11, 7);
1540 graphics.DrawLine (pen, 11, 14, 11, 21);
1541 graphics.DrawLine (pen, 0, 11, 7, 11);
1542 graphics.DrawLine (pen, 14, 11, 21, 11);
1547 public Bitmap Bitmap {
1557 public Color CursorColor {
1559 cursorColor = value;
1568 private DrawingBitmap drawingBitmap = null;
1570 private CrossCursor crossCursor = new CrossCursor();
1572 private bool mouseButtonDown = false;
1574 private bool drawCross = true;
1576 private Color color;
1578 private int currentXPos;
1579 private int currentYPos;
1581 private float xstep;
1582 private float ystep;
1584 private ColorDialog colorDialog;
1586 public ColorMatrixControl (ColorDialog colorDialog)
1588 this.colorDialog = colorDialog;
1592 BorderStyle = BorderStyle.Fixed3D;
1593 Location = new Point (0, 0);
1594 Size = new Size (179, 190);
1598 ResumeLayout (false);
1600 xstep = 240.0f / (ClientSize.Width - 1);
1601 ystep = 241.0f / (ClientSize.Height - 1);
1603 SetStyle (ControlStyles.DoubleBuffer, true);
1604 SetStyle (ControlStyles.AllPaintingInWmPaint, true);
1605 SetStyle (ControlStyles.UserPaint, true);
1608 protected override void OnPaint (PaintEventArgs e)
1610 if (drawingBitmap == null)
1611 drawingBitmap = new DrawingBitmap (ClientSize);
1618 private void Draw (PaintEventArgs e)
1620 e.Graphics.DrawImage (drawingBitmap.Bitmap, ClientRectangle.X, ClientRectangle.Y);
1622 // drawCross is false if the mouse gets moved...
1624 e.Graphics.DrawImage (crossCursor.Bitmap, currentXPos - 11 , currentYPos - 11);
1628 protected override void OnMouseDown (MouseEventArgs e)
1630 mouseButtonDown = true;
1640 XplatUI.GrabWindow (Handle, Handle);
1642 base.OnMouseDown (e);
1645 protected override void OnMouseMove (MouseEventArgs e)
1647 if (mouseButtonDown)
1648 if ((e.X < ClientSize.Width && e.X >= 0) && (e.Y < ClientSize.Height && e.Y >= 0)) {
1654 base.OnMouseMove (e);
1657 protected override void OnMouseUp (MouseEventArgs e)
1659 XplatUI.UngrabWindow (Handle);
1660 mouseButtonDown = false;
1666 public Color ColorToShow {
1672 private void ComputePos (Color acolor)
1674 if (acolor != color) {
1677 HSB hsb = HSB.RGB2HSB (color);
1679 currentXPos = (int)((float)hsb.hue / xstep);
1680 currentYPos = ClientSize.Height - 1 - (int)((float)hsb.sat / ystep);
1682 if (currentXPos < 0)
1684 if (currentYPos < 0)
1692 private Color GetColorFromHSB ()
1694 int hue = (int)((float)currentXPos * xstep);
1695 int sat = 240 - ((int)((float)currentYPos * ystep));
1696 int bri = TriangleControl.CurrentBrightness;
1698 return HSB.HSB2RGB (hue, sat, bri);
1701 private void UpdateControls ()
1703 Color tmpColor = GetColorFromHSB ();
1705 // update the brightness control
1706 colorDialog.brightnessControl.ShowColor ((int)((float)currentXPos * xstep), 240 - ((int)((float)currentYPos * ystep)));
1708 // update saturation text box
1709 int satvalue = (240 - ((int)((float)currentYPos * ystep)));
1710 colorDialog.satTextBox.Text = satvalue.ToString ();
1712 // update hue text box
1713 int huevalue = (int)((float)currentXPos * xstep);
1716 colorDialog.hueTextBox.Text = huevalue.ToString ();
1718 // update the main selected color panel
1719 colorDialog.selectedColorPanel.BackColor = tmpColor;
1721 // and finally the rgb text boxes
1722 colorDialog.UpdateRGBTextBoxes (tmpColor);
1727 internal class BrightnessControl : Panel {
1728 internal class DrawingBitmap {
1729 private Bitmap bitmap;
1731 public DrawingBitmap ()
1733 bitmap = new Bitmap (14, 190);
1736 public Bitmap Bitmap {
1746 // only hue and saturation are needed.
1747 // color will be computed with an iteration
1748 public void Draw (int hue, int sat)
1750 float brisub = 241.0f / 190.0f;
1753 for (int height = 0; height < 190; height++) {
1754 for (int width = 0; width < 14; width++) {
1755 Color pixcolor = HSB.HSB2RGB (hue, sat, (int)bri);
1756 bitmap.SetPixel (width, height, pixcolor);
1763 private const float step = 241.0f/189.0f;
1765 private DrawingBitmap bitmap;
1767 private ColorDialog colorDialog = null;
1769 public BrightnessControl (ColorDialog colorDialog)
1771 this.colorDialog = colorDialog;
1773 bitmap = new DrawingBitmap ();
1777 BorderStyle = BorderStyle.Fixed3D;
1778 Location = new Point (0, 0);
1779 Size = new Size (14, 190);
1782 Size = new Size (14, 190);
1784 ResumeLayout (false);
1786 SetStyle (ControlStyles.DoubleBuffer, true);
1787 SetStyle (ControlStyles.AllPaintingInWmPaint, true);
1788 SetStyle (ControlStyles.UserPaint, true);
1792 protected override void OnPaint (PaintEventArgs e)
1794 e.Graphics.DrawImage (bitmap.Bitmap, 0, 0);
1799 protected override void OnMouseDown (MouseEventArgs e)
1801 colorDialog.triangleControl.TrianglePosition = (int)((float)(189 - e.Y) * step);
1803 base.OnMouseDown (e);
1806 // this one is for ColorMatrixControl
1807 public void ShowColor (int hue, int sat)
1809 bitmap.Draw (hue, sat);
1814 // this one for the other controls
1815 public Color ColorToShow {
1818 HSB.GetHueSaturation (value, out hue, out sat);
1819 bitmap.Draw (hue, sat);
1827 internal class TriangleControl : Panel {
1828 private bool mouseButtonDown = false;
1830 private int currentTrianglePosition = 195;
1831 // private Rectangle clipRectangle;
1833 private const float briStep = 241.0f/186.0f;
1835 private static int currentBrightness = 0;
1837 private ColorDialog colorDialog;
1839 public TriangleControl (ColorDialog colorDialog)
1841 this.colorDialog = colorDialog;
1845 Size = new Size (16, 203);
1847 ResumeLayout (false);
1849 SetStyle (ControlStyles.DoubleBuffer, true);
1850 SetStyle (ControlStyles.AllPaintingInWmPaint, true);
1851 SetStyle (ControlStyles.UserPaint, true);
1854 public static int CurrentBrightness {
1856 currentBrightness = value;
1860 return currentBrightness;
1864 protected override void OnPaint (PaintEventArgs e)
1871 private void Draw (PaintEventArgs e)
1873 e.Graphics.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (BackColor), new Rectangle (0, 0, 16, 203));
1875 Point[] trianglePoints = new Point [3]
1877 new Point (0, currentTrianglePosition),
1878 new Point (8, currentTrianglePosition - 8),
1879 new Point (8, currentTrianglePosition + 8)
1882 e.Graphics.FillPolygon (ThemeEngine.Current.ResPool.GetSolidBrush (Color.Black), trianglePoints);
1885 protected override void OnMouseDown (MouseEventArgs e)
1887 if (e.Y > 195 || e.Y < 9) return; // helper until Cursor.Clip works
1889 mouseButtonDown = true;
1890 currentTrianglePosition = e.Y;
1892 // Cursor.Clip doesn't yet work in Managed.Windows.Forms
1893 // clipRectangle = Cursor.Clip;
1894 // Point p = Location;
1899 // Cursor.Clip = new Rectangle( Parent.PointToScreen( p ), s );
1901 colorDialog.briTextBox.Text = TrianglePosition.ToString ();
1902 colorDialog.UpdateFromHSBTextBoxes ();
1907 base.OnMouseDown (e);
1910 protected override void OnMouseMove (MouseEventArgs e)
1912 if (mouseButtonDown)
1913 if (e.Y < 196 && e.Y > 8) {
1914 currentTrianglePosition = e.Y;
1916 colorDialog.briTextBox.Text = TrianglePosition.ToString ();
1917 colorDialog.UpdateFromHSBTextBoxes ();
1923 base.OnMouseMove (e);
1926 protected override void OnMouseUp (MouseEventArgs e)
1928 mouseButtonDown = false;
1929 // Cursor.Clip = clipRectangle;
1934 public int TrianglePosition {
1936 float tmp = (float)(currentTrianglePosition - 9);
1937 tmp = tmp * briStep;
1939 int retval = 240 - (int)tmp;
1941 TriangleControl.CurrentBrightness = retval;
1947 float tmp = (float)value / briStep;
1948 currentTrianglePosition = 186 - (int)tmp + 9;
1950 colorDialog.briTextBox.Text = TrianglePosition.ToString ();
1952 colorDialog.UpdateFromHSBTextBoxes ();
1959 public Color ColorToShow {
1965 public void SetColor (Color color)
1967 int pos_raw = HSB.Brightness (color);
1969 float tmp = (float)pos_raw / briStep;
1970 currentTrianglePosition = 186 - (int)tmp + 9;
1972 if (colorDialog.edit_textbox == null)
1973 colorDialog.briTextBox.Text = TrianglePosition.ToString ();