1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
|
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// Copyright (c) 2004-2006 Novell, Inc. (http://www.novell.com)
//
// Authors:
// Alexander Olk xenomorph2@onlinehome.de
//
// COMPLETE
using System.ComponentModel;
using System.Drawing;
using System.Globalization;
using System.Resources;
using System;
namespace System.Windows.Forms {
[DefaultProperty ("Color")]
public class ColorDialog : CommonDialog {
#region Local Variables
private bool allowFullOpen = true;
private bool anyColor = false;
private Color color = Color.Black;
private int[] customColors = null;
private bool fullOpen = false;
private bool showHelp = false;
private bool solidColorOnly = false;
private Panel selectedColorPanel;
private BaseColorControl baseColorControl;
private ColorMatrixControl colorMatrixControl;
private BrightnessControl brightnessControl;
private TriangleControl triangleControl;
private Button okButton;
private Button cancelButton;
private Button helpButton;
private Button addColoursButton;
private Button defineColoursButton;
private TextBox hueTextBox;
private TextBox satTextBox;
private TextBox briTextBox;
private TextBox redTextBox;
private TextBox greenTextBox;
private TextBox blueTextBox;
private Label briLabel;
private Label satLabel;
private Label hueLabel;
private Label colorBaseLabel;
private Label greenLabel;
private Label blueLabel;
private Label redLabel;
#endregion // Local Variables
#region Public Constructors
public ColorDialog () : base()
{
form.SuspendLayout ();
form.Text = "Color";
form.Size = new Size (221, 332); // 300
form.FormBorderStyle = FormBorderStyle.FixedDialog;
form.MaximizeBox = false;
satTextBox = new TextBox ();
briTextBox = new TextBox ();
blueTextBox = new TextBox ();
greenTextBox = new TextBox ();
redTextBox = new TextBox ();
hueTextBox = new TextBox ();
redLabel = new Label ();
blueLabel = new Label ();
greenLabel = new Label ();
colorBaseLabel = new Label ();
hueLabel = new Label ();
satLabel = new Label ();
briLabel = new Label ();
okButton = new Button ();
cancelButton = new Button ();
helpButton = new Button ();
defineColoursButton = new Button ();
addColoursButton = new Button ();
baseColorControl = new BaseColorControl (this);
colorMatrixControl = new ColorMatrixControl (this);
brightnessControl = new BrightnessControl (this);
triangleControl = new TriangleControl (this);
selectedColorPanel = new Panel ();
// hueTextBox
hueTextBox.Location = new Point (324, 203);
hueTextBox.Size = new Size (27, 21);
hueTextBox.TabIndex = 11;
hueTextBox.TextAlign = HorizontalAlignment.Right;
hueTextBox.MaxLength = 3;
// satTextBox
satTextBox.Location = new Point (324, 225);
satTextBox.Size = new Size (27, 21);
satTextBox.TabIndex = 15;
satTextBox.TextAlign = HorizontalAlignment.Right;
satTextBox.MaxLength = 3;
// greenTextBox
greenTextBox.Location = new Point (404, 225);
greenTextBox.Size = new Size (27, 21);
greenTextBox.TabIndex = 18;
greenTextBox.TextAlign = HorizontalAlignment.Right;
greenTextBox.MaxLength = 3;
// briTextBox
briTextBox.Location = new Point (324, 247);
briTextBox.Size = new Size (27, 21);
briTextBox.TabIndex = 16;
briTextBox.TextAlign = HorizontalAlignment.Right;
briTextBox.MaxLength = 3;
// blueTextBox
blueTextBox.Location = new Point (404, 247);
blueTextBox.Size = new Size (27, 21);
blueTextBox.TabIndex = 19;
blueTextBox.TextAlign = HorizontalAlignment.Right;
blueTextBox.MaxLength = 3;
// redTextBox
redTextBox.Location = new Point (404, 203);
redTextBox.Size = new Size (27, 21);
redTextBox.TabIndex = 17;
redTextBox.TextAlign = HorizontalAlignment.Right;
redTextBox.MaxLength = 3;
// redLabel
redLabel.FlatStyle = FlatStyle.System;
redLabel.Location = new Point (361, 206);
redLabel.Size = new Size (40, 16);
redLabel.TabIndex = 25;
redLabel.Text = Locale.GetText ("Red") + ":";
redLabel.TextAlign = ContentAlignment.MiddleRight;
// blueLabel
blueLabel.FlatStyle = FlatStyle.System;
blueLabel.Location = new Point (361, 250);
blueLabel.Size = new Size (40, 16);
blueLabel.TabIndex = 26;
blueLabel.Text = Locale.GetText ("Blue") + ":";
blueLabel.TextAlign = ContentAlignment.MiddleRight;
// greenLabel
greenLabel.FlatStyle = FlatStyle.System;
greenLabel.Location = new Point (361, 228);
greenLabel.Size = new Size (40, 16);
greenLabel.TabIndex = 27;
greenLabel.Text = Locale.GetText ("Green") + ":";
greenLabel.TextAlign = ContentAlignment.MiddleRight;
// colorBaseLabel
colorBaseLabel.Location = new Point (228, 247);
colorBaseLabel.Size = new Size (60, 25);
colorBaseLabel.TabIndex = 28;
colorBaseLabel.Text = Locale.GetText ("Color");
colorBaseLabel.TextAlign = ContentAlignment.MiddleCenter;
// hueLabel
hueLabel.FlatStyle = FlatStyle.System;
hueLabel.Location = new Point (287, 206);
hueLabel.Size = new Size (36, 16);
hueLabel.TabIndex = 23;
hueLabel.Text = Locale.GetText ("Hue") + ":";
hueLabel.TextAlign = ContentAlignment.MiddleRight;
// satLabel
satLabel.FlatStyle = FlatStyle.System;
satLabel.Location = new Point (287, 228);
satLabel.Size = new Size (36, 16);
satLabel.TabIndex = 22;
satLabel.Text = Locale.GetText ("Sat") + ":";
satLabel.TextAlign = ContentAlignment.MiddleRight;
// briLabel
briLabel.FlatStyle = FlatStyle.System;
briLabel.Location = new Point (287, 250);
briLabel.Size = new Size (36, 16);
briLabel.TabIndex = 24;
briLabel.Text = Locale.GetText ("Bri") + ":";
briLabel.TextAlign = ContentAlignment.MiddleRight;
// defineColoursButton
defineColoursButton.FlatStyle = FlatStyle.System;
defineColoursButton.Location = new Point (5, 244);
defineColoursButton.Size = new Size (210, 22);
defineColoursButton.TabIndex = 6;
defineColoursButton.Text = Locale.GetText ("Define Colours >>");
// okButton
okButton.FlatStyle = FlatStyle.System;
okButton.Location = new Point (5, 271);
okButton.Size = new Size (66, 22);
okButton.TabIndex = 0;
okButton.Text = Locale.GetText ("OK");
// cancelButton
cancelButton.FlatStyle = FlatStyle.System;
cancelButton.Location = new Point (78, 271);
cancelButton.Size = new Size (66, 22);
cancelButton.TabIndex = 1;
cancelButton.Text = Locale.GetText ("Cancel");
// helpButton
helpButton.FlatStyle = FlatStyle.System;
helpButton.Location = new Point (149, 271);
helpButton.Size = new Size (66, 22);
helpButton.TabIndex = 5;
helpButton.Text = Locale.GetText ("Help");
helpButton.Hide ();
// addColoursButton
addColoursButton.FlatStyle = FlatStyle.System;
addColoursButton.Location = new Point (227, 271);
addColoursButton.Size = new Size (213, 22);
addColoursButton.TabIndex = 7;
addColoursButton.Text = Locale.GetText ("Add Colours");
// baseColorControl
baseColorControl.Location = new Point (3, 6);
baseColorControl.Size = new Size (212, 231);
baseColorControl.TabIndex = 13;
// colorMatrixControl
colorMatrixControl.Location = new Point (227, 7);
colorMatrixControl.Size = new Size (179, 190);
colorMatrixControl.TabIndex = 14;
// triangleControl
triangleControl.Location = new Point (432, 0);
triangleControl.Size = new Size (16, 204);
triangleControl.TabIndex = 12;
// brightnessControl
brightnessControl.Location = new Point (415, 7);
brightnessControl.Size = new Size (14, 190);
brightnessControl.TabIndex = 20;
// selectedColorPanel
selectedColorPanel.BackColor = SystemColors.Desktop;
selectedColorPanel.BorderStyle = BorderStyle.Fixed3D;
selectedColorPanel.Location = new Point (227, 202);
selectedColorPanel.Size = new Size (60, 42);
selectedColorPanel.TabIndex = 10;
form.Controls.Add (hueTextBox);
form.Controls.Add (satTextBox);
form.Controls.Add (briTextBox);
form.Controls.Add (redTextBox);
form.Controls.Add (greenTextBox);
form.Controls.Add (blueTextBox);
form.Controls.Add (defineColoursButton);
form.Controls.Add (okButton);
form.Controls.Add (cancelButton);
form.Controls.Add (addColoursButton);
form.Controls.Add (baseColorControl);
form.Controls.Add (colorMatrixControl);
form.Controls.Add (brightnessControl);
form.Controls.Add (triangleControl);
form.Controls.Add (colorBaseLabel);
form.Controls.Add (greenLabel);
form.Controls.Add (blueLabel);
form.Controls.Add (redLabel);
form.Controls.Add (briLabel);
form.Controls.Add (hueLabel);
form.Controls.Add (satLabel);
form.Controls.Add (selectedColorPanel);
form.ResumeLayout (false);
brightnessControl.ColorToShow = selectedColorPanel.BackColor;
redTextBox.Text = selectedColorPanel.BackColor.R.ToString ();
greenTextBox.Text = selectedColorPanel.BackColor.G.ToString ();
blueTextBox.Text = selectedColorPanel.BackColor.B.ToString ();
HSB hsb = HSB.RGB2HSB (selectedColorPanel.BackColor);
hueTextBox.Text = hsb.hue.ToString ();
satTextBox.Text = hsb.sat.ToString ();
briTextBox.Text = hsb.bri.ToString ();
if (!allowFullOpen)
defineColoursButton.Enabled = false;
if (fullOpen)
DoButtonDefineColours ();
defineColoursButton.Click += new EventHandler (OnClickButtonDefineColours);
addColoursButton.Click += new EventHandler (OnClickButtonAddColours);
if (showHelp)
helpButton.Click += new EventHandler (OnClickHelpButton);
cancelButton.Click += new EventHandler (OnClickCancelButton);
okButton.Click += new EventHandler (OnClickOkButton);
hueTextBox.KeyPress += new KeyPressEventHandler (OnKeyPressTextBoxes);
satTextBox.KeyPress += new KeyPressEventHandler (OnKeyPressTextBoxes);
briTextBox.KeyPress += new KeyPressEventHandler (OnKeyPressTextBoxes);
redTextBox.KeyPress += new KeyPressEventHandler (OnKeyPressTextBoxes);
greenTextBox.KeyPress += new KeyPressEventHandler (OnKeyPressTextBoxes);
blueTextBox.KeyPress += new KeyPressEventHandler (OnKeyPressTextBoxes);
}
#endregion // Public Constructors
#region Public Instance Properties
public Color Color {
get {
return color;
}
set {
color = value;
}
}
[DefaultValue(true)]
public virtual bool AllowFullOpen {
get {
return allowFullOpen;
}
set {
allowFullOpen = value;
}
}
// Currently AnyColor internally is always true
// Does really anybody still use 256 or less colors ???
// Naw, cairo only supports 24bit anyway - pdb
[DefaultValue(false)]
public virtual bool AnyColor {
get {
return anyColor;
}
set {
anyColor = value;
}
}
[DefaultValue(false)]
public virtual bool FullOpen {
get {
return fullOpen;
}
set {
fullOpen = value;
}
}
[Browsable(false)]
[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
public int[] CustomColors {
get {
return customColors;
}
set {
customColors = value;
}
}
[DefaultValue(false)]
public virtual bool ShowHelp {
get {
return showHelp;
}
set {
showHelp = value;
if (showHelp)
helpButton.Show ();
else
helpButton.Hide ();
}
}
[DefaultValue(false)]
public virtual bool SolidColorOnly {
get {
return solidColorOnly;
}
set {
solidColorOnly = value;
}
}
#endregion // Public Instance Properties
#region Public Instance Methods
public override void Reset ()
{
allowFullOpen = true;
anyColor = false;
color = Color.Black;
customColors = null;
fullOpen = false;
showHelp = false;
solidColorOnly = false;
}
public override string ToString ()
{
return base.ToString () + ", Color: " + Color.ToString ();
}
#endregion // Public Instance Methods
#region Protected Instance Properties
protected virtual IntPtr Instance {
get {
// MS Internal
return (IntPtr)GetHashCode ();
}
}
protected virtual int Options {
get {
// MS Internal
return 0;
}
}
#endregion // Protected Instance Properties
#region Protected Instance Methods
protected override bool RunDialog (IntPtr hwndOwner)
{
// currently needed, otherwise there are a lot of drawing artefacts/transparent controls if the same dialog gets opened again
form.Refresh ();
if (customColors != null)
baseColorControl.SetCustomColors ();
return true;
}
#endregion // Protected Instance Methods
#region Private Methods
void OnClickCancelButton (object sender, EventArgs e)
{
form.DialogResult = DialogResult.Cancel;
}
void OnClickOkButton (object sender, EventArgs e)
{
form.DialogResult = DialogResult.OK;
}
void OnClickButtonDefineColours (object sender, EventArgs e)
{
DoButtonDefineColours ();
}
void DoButtonDefineColours ()
{
defineColoursButton.Enabled = false;
fullOpen = true;
colorMatrixControl.ColorToShow = baseColorControl.ColorToShow;
form.ClientSize = new Size (448, 332);
}
void OnClickButtonAddColours (object sender, EventArgs e)
{
baseColorControl.SetUserColor (selectedColorPanel.BackColor);
}
// FIXME: Is this correct ?
void OnClickHelpButton (object sender, EventArgs e)
{
OnHelpRequest (e);
}
// not working 100 %, S.W.F.TextBox isn't finished yet
void OnKeyPressTextBoxes (object sender, KeyPressEventArgs e)
{
// accept only '0', '1', ... , '9'
// 48 = '0', 57 = '9'
if (e.KeyChar < (char)48 || e.KeyChar > (char)57)
e.Handled = true;
TextChangedTextBoxes (sender);
}
// not working 100 %, S.W.F.TextBox isn't finished yet
void TextChangedTextBoxes (object sender)
{
if (((TextBox)sender).Text.Length == 0)
return;
int val;
if (sender == hueTextBox) {
val = System.Convert.ToInt32 (hueTextBox.Text);
if (val > 240) {
val = 240;
hueTextBox.Text = val.ToString ();
} else
if (val < 0) {
val = 0;
hueTextBox.Text = val.ToString ();
}
UpdateFromHSBTextBoxes ();
UpdateControls (selectedColorPanel.BackColor);
} else
if (sender == satTextBox) {
val = System.Convert.ToInt32 (satTextBox.Text);
if (val > 239) {
val = 239;
satTextBox.Text = val.ToString ();
} else
if (val < 0) {
val = 0;
satTextBox.Text = val.ToString ();
}
UpdateFromHSBTextBoxes ();
UpdateControls (selectedColorPanel.BackColor);
} else
if (sender == briTextBox) {
val = System.Convert.ToInt32 (briTextBox.Text);
if (val > 239) {
val = 239;
briTextBox.Text = val.ToString ();
} else
if (val < 0) {
val = 0;
briTextBox.Text = val.ToString ();
}
UpdateFromHSBTextBoxes ();
UpdateControls (selectedColorPanel.BackColor);
} else
if (sender == redTextBox) {
val = System.Convert.ToInt32 (redTextBox.Text);
if (val > 255) {
val = 255;
redTextBox.Text = val.ToString ();
} else
if (val < 0) {
val = 0;
redTextBox.Text = val.ToString ();
}
UpdateFromRGBTextBoxes ();
} else
if (sender == greenTextBox) {
val = System.Convert.ToInt32 (greenTextBox.Text);
if (val > 255) {
val = 255;
greenTextBox.Text = val.ToString ();
} else
if (val < 0) {
val = 0;
greenTextBox.Text = val.ToString ();
}
UpdateFromRGBTextBoxes ();
} else
if (sender == blueTextBox) {
val = System.Convert.ToInt32 (blueTextBox.Text);
if (val > 255) {
val = 255;
blueTextBox.Text = val.ToString ();
} else
if (val < 0) {
val = 0;
blueTextBox.Text = val.ToString ();
}
UpdateFromRGBTextBoxes ();
}
}
private void UpdateControls (Color acolor)
{
color = acolor;
selectedColorPanel.BackColor = acolor;
colorMatrixControl.ColorToShow = acolor;
brightnessControl.ColorToShow = acolor;
triangleControl.ColorToShow = acolor;
}
private void UpdateRGBTextBoxes (Color color)
{
redTextBox.Text = color.R.ToString ();
greenTextBox.Text = color.G.ToString ();
blueTextBox.Text = color.B.ToString ();
}
private void UpdateHSBTextBoxes (Color color)
{
HSB hsb = HSB.RGB2HSB (color);
hueTextBox.Text = hsb.hue.ToString ();
satTextBox.Text = hsb.sat.ToString ();
briTextBox.Text = hsb.bri.ToString ();
}
private void UpdateFromHSBTextBoxes ()
{
Color col = HSB.HSB2RGB (System.Convert.ToInt32 (hueTextBox.Text),
System.Convert.ToInt32 (satTextBox.Text),
System.Convert.ToInt32 (briTextBox.Text));
selectedColorPanel.BackColor = col;
UpdateRGBTextBoxes (col);
}
private void UpdateFromRGBTextBoxes ()
{
Color col = Color.FromArgb (System.Convert.ToInt32 (redTextBox.Text),
System.Convert.ToInt32 (greenTextBox.Text),
System.Convert.ToInt32 (blueTextBox.Text));
selectedColorPanel.BackColor = col;
UpdateHSBTextBoxes (col);
UpdateFromHSBTextBoxes ();
UpdateControls (col);
}
#endregion
#region Internal structs and classes
internal struct HSB {
public int hue;
public int sat;
public int bri;
public static HSB RGB2HSB (Color color)
{
HSB hsb = new HSB ();
hsb.hue = (int)((color.GetHue () / 360.0f) * 241);
hsb.sat = (int)(color.GetSaturation () * 241);
hsb.bri = (int)(color.GetBrightness () * 240);
if (hsb.hue > 240) hsb.hue = 240;
if (hsb.sat > 240) hsb.sat = 240;
if (hsb.bri > 239) hsb.bri = 239;
return hsb;
}
// not using ControlPaint HBS2Color, this algo is more precise
public static Color HSB2RGB (int hue, int saturation, int brightness)
{
if (hue > 240)
hue = 240;
else
if (hue < 0)
hue = 0;
if (saturation > 240)
saturation = 240;
else
if (saturation < 0)
saturation = 0;
if (brightness > 239)
brightness = 239;
else
if (brightness < 0)
brightness = 0;
float H = hue / 240.0f;
float S = saturation / 240.0f;
float L = brightness / 239.0f;
float r = 0, g = 0, b = 0;
float d1, d2;
if (L == 0) {
r = g = b = 0;
} else {
if (S == 0) {
r = g = b = L;
} else {
d2 = (L <= 0.5f) ? L * (1.0f + S) : L + S - (L * S);
d1 = 2.0f * L - d2;
float[] d3 = new float [] { H + 1.0f / 3.0f , H, H - 1.0f / 3.0f };
float[] rgb = new float [] { 0,0,0 };
for (int i = 0; i < 3; i++) {
if (d3 [i] < 0)
d3 [i] += 1.0f;
if (d3 [i] > 1.0f)
d3 [i] -= 1.0f;
if (6.0f * d3 [i] < 1.0f)
rgb [i] = d1 + (d2 - d1) * d3 [i] * 6.0f;
else
if (2.0f * d3 [i] < 1.0f)
rgb [i] = d2;
else
if (3.0f * d3 [i] < 2.0f)
rgb [i] = (d1 + (d2 - d1) * ((2.0f / 3.0f) - d3 [i]) * 6.0f);
else
rgb [i] = d1;
}
r = rgb [0];
g = rgb [1];
b = rgb [2];
}
}
r = 255.0f * r;
g = 255.0f * g;
b = 255.0f * b;
if (r < 1)
r = 0.0f;
else
if (r > 255.0f)
r = 255.0f;
if (g < 1)
g = 0.0f;
else
if (g > 255.0f)
g = 255.0f;
if (b < 1)
b = 0.0f;
else
if (b > 255.0f)
b = 255.0f;
return Color.FromArgb ((int)r, (int)g, (int)b);
}
public static int Brightness (Color color)
{
return (int)(color.GetBrightness () * 240);
}
public static void GetHueSaturation (Color color, out int hue, out int sat)
{
hue = (int)((color.GetHue () / 360.0f) * 241);
sat = (int)(color.GetSaturation () * 241);
}
// only for testing
// there are some small glitches, but it is still better than ControlPaint implementation
public static void TestColor (Color color)
{
Console.WriteLine ("Color: " + color);
HSB hsb = HSB.RGB2HSB (color);
Console.WriteLine ("RGB2HSB: " + hsb.hue + ", " + hsb.sat + ", " + hsb.bri);
Console.WriteLine ("HSB2RGB: " + HSB.HSB2RGB (hsb.hue, hsb.sat, hsb.bri));
Console.WriteLine ();
}
}
internal class BaseColorControl : Control {
internal class SmallColorControl : Control {
private Color color;
private bool isSelected = false;
public SmallColorControl (Color color)
{
SuspendLayout ();
this.color = color;
Size = new Size (25, 23);
ResumeLayout (false);
SetStyle (ControlStyles.DoubleBuffer, true);
SetStyle (ControlStyles.AllPaintingInWmPaint, true);
SetStyle (ControlStyles.UserPaint, true);
SetStyle (ControlStyles.Selectable, true);
}
public bool IsSelected {
set {
isSelected = value;
Invalidate ();
}
}
public Color Color {
set {
color = value;
Invalidate ();
}
get {
return color;
}
}
protected override void OnPaint (PaintEventArgs pe)
{
base.OnPaint (pe);
pe.Graphics.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (BackColor), 0, 0, 26, 23);
pe.Graphics.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (color),
new Rectangle (4, 4, 17, 15));
DrawBorder (pe.Graphics, new Rectangle (4, 4, 17, 15));
if (isSelected) {
pe.Graphics.DrawRectangle (ThemeEngine.Current.ResPool.GetPen (Color.Black),
new Rectangle (2, 2, 20, 18));
}
if (Focused) {
ControlPaint.DrawFocusRectangle (
pe.Graphics, new Rectangle (0, 0, 25, 23)
);
}
}
protected override void OnClick (EventArgs e)
{
Focus ();
IsSelected = true;
base.OnClick (e);
}
protected override void OnLostFocus (EventArgs e)
{
Invalidate ();
base.OnLostFocus (e);
}
private void DrawBorder (Graphics dc, Rectangle rect)
{
Pen pen = ThemeEngine.Current.ResPool.GetPen (Color.Black);
dc.DrawLine (pen, rect.X, rect.Y, rect.X, rect.Bottom - 1);
dc.DrawLine (pen, rect.X + 1, rect.Y, rect.Right - 1, rect.Y);
}
}
private SmallColorControl[] smallColorControl;
private SmallColorControl[] userSmallColorControl;
private Label userColorLabel;
private Label baseColorLabel;
private SmallColorControl selectedSmallColorControl;
private int currentlyUsedUserSmallColorControl = 0;
private int[] customColors = null;
private ColorDialog colorDialog = null;
public BaseColorControl (ColorDialog colorDialog)
{
this.colorDialog = colorDialog;
userSmallColorControl = new SmallColorControl [16];
userSmallColorControl [0] = new SmallColorControl (Color.White);
userSmallColorControl [1] = new SmallColorControl (Color.White);
userSmallColorControl [2] = new SmallColorControl (Color.White);
userSmallColorControl [3] = new SmallColorControl (Color.White);
userSmallColorControl [4] = new SmallColorControl (Color.White);
userSmallColorControl [5] = new SmallColorControl (Color.White);
userSmallColorControl [6] = new SmallColorControl (Color.White);
userSmallColorControl [7] = new SmallColorControl (Color.White);
userSmallColorControl [8] = new SmallColorControl (Color.White);
userSmallColorControl [9] = new SmallColorControl (Color.White);
userSmallColorControl [10] = new SmallColorControl (Color.White);
userSmallColorControl [11] = new SmallColorControl (Color.White);
userSmallColorControl [12] = new SmallColorControl (Color.White);
userSmallColorControl [13] = new SmallColorControl (Color.White);
userSmallColorControl [14] = new SmallColorControl (Color.White);
userSmallColorControl [15] = new SmallColorControl (Color.White);
smallColorControl = new SmallColorControl [48];
smallColorControl [0] = new SmallColorControl (Color.FromArgb (((Byte)(255)), ((Byte)(128)), ((Byte)(138))));
smallColorControl [1] = new SmallColorControl (Color.FromArgb (((Byte)(128)), ((Byte)(128)), ((Byte)(64))));
smallColorControl [2] = new SmallColorControl (Color.Gray);
smallColorControl [3] = new SmallColorControl (Color.FromArgb (((Byte)(128)), ((Byte)(0)), ((Byte)(255))));
smallColorControl [4] = new SmallColorControl (Color.Silver);
smallColorControl [5] = new SmallColorControl (Color.FromArgb (((Byte)(64)), ((Byte)(128)), ((Byte)(128))));
smallColorControl [6] = new SmallColorControl (Color.White);
smallColorControl [7] = new SmallColorControl (Color.FromArgb (((Byte)(64)), ((Byte)(0)), ((Byte)(64))));
smallColorControl [8] = new SmallColorControl (Color.FromArgb (((Byte)(255)), ((Byte)(128)), ((Byte)(64))));
smallColorControl [9] = new SmallColorControl (Color.FromArgb (((Byte)(128)), ((Byte)(64)), ((Byte)(64))));
smallColorControl [10] = new SmallColorControl (Color.Teal);
smallColorControl [11] = new SmallColorControl (Color.Lime);
smallColorControl [12] = new SmallColorControl (Color.FromArgb (((Byte)(128)), ((Byte)(128)), ((Byte)(255))));
smallColorControl [13] = new SmallColorControl (Color.FromArgb (((Byte)(0)), ((Byte)(64)), ((Byte)(128))));
smallColorControl [14] = new SmallColorControl (Color.FromArgb (((Byte)(255)), ((Byte)(0)), ((Byte)(128))));
smallColorControl [15] = new SmallColorControl (Color.FromArgb (((Byte)(128)), ((Byte)(255)), ((Byte)(0))));
smallColorControl [16] = new SmallColorControl (Color.FromArgb (((Byte)(0)), ((Byte)(255)), ((Byte)(64))));
smallColorControl [17] = new SmallColorControl (Color.Red);
smallColorControl [18] = new SmallColorControl (Color.FromArgb (((Byte)(255)), ((Byte)(128)), ((Byte)(0))));
smallColorControl [19] = new SmallColorControl (Color.FromArgb (((Byte)(255)), ((Byte)(128)), ((Byte)(255))));
smallColorControl [20] = new SmallColorControl (Color.Fuchsia);
smallColorControl [21] = new SmallColorControl (Color.Aqua);
smallColorControl [22] = new SmallColorControl (Color.FromArgb (((Byte)(128)), ((Byte)(255)), ((Byte)(128))));
smallColorControl [23] = new SmallColorControl (Color.FromArgb (((Byte)(128)), ((Byte)(255)), ((Byte)(255))));
smallColorControl [24] = new SmallColorControl (Color.FromArgb (((Byte)(0)), ((Byte)(128)), ((Byte)(255))));
smallColorControl [25] = new SmallColorControl (Color.FromArgb (((Byte)(128)), ((Byte)(64)), ((Byte)(0))));
smallColorControl [26] = new SmallColorControl (Color.FromArgb (((Byte)(64)), ((Byte)(0)), ((Byte)(0))));
smallColorControl [27] = new SmallColorControl (Color.Maroon);
smallColorControl [28] = new SmallColorControl (Color.Purple);
smallColorControl [29] = new SmallColorControl (Color.FromArgb (((Byte)(0)), ((Byte)(0)), ((Byte)(160))));
smallColorControl [30] = new SmallColorControl (Color.Blue);
smallColorControl [31] = new SmallColorControl (Color.FromArgb (((Byte)(0)), ((Byte)(128)), ((Byte)(64))));
smallColorControl [32] = new SmallColorControl (Color.Green);
smallColorControl [33] = new SmallColorControl (Color.Yellow);
smallColorControl [34] = new SmallColorControl (Color.FromArgb (((Byte)(128)), ((Byte)(128)), ((Byte)(192))));
smallColorControl [35] = new SmallColorControl (Color.FromArgb (((Byte)(0)), ((Byte)(128)), ((Byte)(192))));
smallColorControl [36] = new SmallColorControl (Color.FromArgb (((Byte)(128)), ((Byte)(0)), ((Byte)(64))));
smallColorControl [37] = new SmallColorControl (Color.FromArgb (((Byte)(255)), ((Byte)(128)), ((Byte)(192))));
smallColorControl [38] = new SmallColorControl (Color.FromArgb (((Byte)(0)), ((Byte)(255)), ((Byte)(128))));
smallColorControl [39] = new SmallColorControl (Color.FromArgb (((Byte)(255)), ((Byte)(255)), ((Byte)(128))));
smallColorControl [40] = new SmallColorControl (Color.FromArgb (((Byte)(0)), ((Byte)(64)), ((Byte)(0))));
smallColorControl [41] = new SmallColorControl (Color.FromArgb (((Byte)(0)), ((Byte)(64)), ((Byte)(64))));
smallColorControl [42] = new SmallColorControl (Color.Navy);
smallColorControl [43] = new SmallColorControl (Color.FromArgb (((Byte)(0)), ((Byte)(0)), ((Byte)(64))));
smallColorControl [44] = new SmallColorControl (Color.FromArgb (((Byte)(64)), ((Byte)(0)), ((Byte)(64))));
smallColorControl [45] = new SmallColorControl (Color.FromArgb (((Byte)(64)), ((Byte)(0)), ((Byte)(128))));
smallColorControl [46] = new SmallColorControl (Color.Black); //Black
smallColorControl [47] = new SmallColorControl (Color.Olive);
baseColorLabel = new Label ();
userColorLabel = new Label ();
SuspendLayout ();
// colorPanel1
smallColorControl [0].Location = new Point (0, 15);
smallColorControl [0].TabIndex = 51;
smallColorControl [0].Click += new EventHandler (OnSmallColorControlClick);
// colorPanel2
smallColorControl [1].Location = new Point (50, 130);
smallColorControl [1].TabIndex = 92;
smallColorControl [1].Click += new EventHandler (OnSmallColorControlClick);
// colorPanel3
smallColorControl [2].Location = new Point (75, 130);
smallColorControl [2].TabIndex = 93;
smallColorControl [2].Click += new EventHandler (OnSmallColorControlClick);
// colorPanel4
smallColorControl [3].Location = new Point (175, 84);
smallColorControl [3].TabIndex = 98;
smallColorControl [3].Click += new EventHandler (OnSmallColorControlClick);
// colorPanel5
smallColorControl [4].Location = new Point (125, 130);
smallColorControl [4].TabIndex = 95;
smallColorControl [4].Click += new EventHandler (OnSmallColorControlClick);
// colorPanel6
smallColorControl [5].Location = new Point (100, 130);
smallColorControl [5].TabIndex = 94;
smallColorControl [5].Click += new EventHandler (OnSmallColorControlClick);
// colorPanel7
smallColorControl [6].Location = new Point (175, 130);
smallColorControl [6].TabIndex = 97;
smallColorControl [6].Click += new EventHandler (OnSmallColorControlClick);
// colorPanel8
smallColorControl [7].Location = new Point (150, 130);
smallColorControl [7].TabIndex = 96;
smallColorControl [7].Click += new EventHandler (OnSmallColorControlClick);
// colorPanel9
smallColorControl [8].Location = new Point (25, 61);
smallColorControl [8].TabIndex = 68;
smallColorControl [8].Click += new EventHandler (OnSmallColorControlClick);
// colorPanel10
smallColorControl [9].Location = new Point (0, 61);
smallColorControl [9].TabIndex = 67;
smallColorControl [9].Click += new EventHandler (OnSmallColorControlClick);
// colorPanel11
smallColorControl [10].Location = new Point (75, 61);
smallColorControl [10].TabIndex = 70;
smallColorControl [10].Click += new EventHandler (OnSmallColorControlClick);
// colorPanel12
smallColorControl [11].Location = new Point (50, 61);
smallColorControl [11].TabIndex = 69;
smallColorControl [11].Click += new EventHandler (OnSmallColorControlClick);
// colorPanel13
smallColorControl [12].Location = new Point (125, 61);
smallColorControl [12].TabIndex = 72;
smallColorControl [12].Click += new EventHandler (OnSmallColorControlClick);
// colorPanel14
smallColorControl [13].Location = new Point (100, 61);
smallColorControl [13].TabIndex = 71;
smallColorControl [13].Click += new EventHandler (OnSmallColorControlClick);
// colorPanel15
smallColorControl [14].Location = new Point (175, 61);
smallColorControl [14].TabIndex = 74;
smallColorControl [14].Click += new EventHandler (OnSmallColorControlClick);
// colorPanel16
smallColorControl [15].Location = new Point (50, 38);
smallColorControl [15].TabIndex = 61;
smallColorControl [15].Click += new EventHandler (OnSmallColorControlClick);
// colorPanel17
smallColorControl [16].Location = new Point (75, 38);
smallColorControl [16].TabIndex = 62;
smallColorControl [16].Click += new EventHandler (OnSmallColorControlClick);
// colorPanel18
smallColorControl [17].Location = new Point (0, 38);
smallColorControl [17].TabIndex = 59;
smallColorControl [17].Click += new EventHandler (OnSmallColorControlClick);
// colorPanel19
smallColorControl [18].Location = new Point (25, 84);
smallColorControl [18].TabIndex = 75;
smallColorControl [18].Click += new EventHandler (OnSmallColorControlClick);
// colorPanel20
smallColorControl [19].Location = new Point (175, 15);
smallColorControl [19].TabIndex = 58;
smallColorControl [19].Click += new EventHandler (OnSmallColorControlClick);
// colorPanel21
smallColorControl [20].Location = new Point (175, 38);
smallColorControl [20].TabIndex = 66;
smallColorControl [20].Click += new EventHandler (OnSmallColorControlClick);
// colorPanel22
smallColorControl [21].Location = new Point (100, 38);
smallColorControl [21].TabIndex = 63;
smallColorControl [21].Click += new EventHandler (OnSmallColorControlClick);
// colorPanel23
smallColorControl [22].Location = new Point (50, 15);
smallColorControl [22].TabIndex = 53;
smallColorControl [22].Click += new EventHandler (OnSmallColorControlClick);
// colorPanel24
smallColorControl [23].Location = new Point (100, 15);
smallColorControl [23].TabIndex = 55;
smallColorControl [23].Click += new EventHandler (OnSmallColorControlClick);
// colorPanel25
smallColorControl [24].Location = new Point (125, 15);
smallColorControl [24].TabIndex = 56;
smallColorControl [24].Click += new EventHandler (OnSmallColorControlClick);
// colorPanel26
smallColorControl [25].Location = new Point (25, 107);
smallColorControl [25].TabIndex = 83;
smallColorControl [25].Click += new EventHandler (OnSmallColorControlClick);
// colorPanel27
smallColorControl [26].Location = new Point (0, 107);
smallColorControl [26].TabIndex = 82;
smallColorControl [26].Click += new EventHandler (OnSmallColorControlClick);
// colorPanel28
smallColorControl [27].Location = new Point (0, 84);
smallColorControl [27].TabIndex = 81;
smallColorControl [27].Click += new EventHandler (OnSmallColorControlClick);
// colorPanel29
smallColorControl [28].Location = new Point (150, 84);
smallColorControl [28].TabIndex = 80;
smallColorControl [28].Click += new EventHandler (OnSmallColorControlClick);
// colorPanel30
smallColorControl [29].Location = new Point (125, 84);
smallColorControl [29].TabIndex = 79;
smallColorControl [29].Click += new EventHandler (OnSmallColorControlClick);
// colorPanel31
smallColorControl [30].Location = new Point (100, 84);
smallColorControl [30].TabIndex = 78;
smallColorControl [30].Click += new EventHandler (OnSmallColorControlClick);
// colorPanel32
smallColorControl [31].Location = new Point (75, 84);
smallColorControl [31].TabIndex = 77;
smallColorControl [31].Click += new EventHandler (OnSmallColorControlClick);
// colorPanel33
smallColorControl [32].Location = new Point (50, 84);
smallColorControl [32].TabIndex = 76;
smallColorControl [32].Click += new EventHandler (OnSmallColorControlClick);
// colorPanel34
smallColorControl [33].Location = new Point (25, 38);
smallColorControl [33].TabIndex = 60;
smallColorControl [33].Click += new EventHandler (OnSmallColorControlClick);
// colorPanel35
smallColorControl [34].Location = new Point (150, 38);
smallColorControl [34].TabIndex = 65;
smallColorControl [34].Click += new EventHandler (OnSmallColorControlClick);
// colorPanel36
smallColorControl [35].Location = new Point (125, 38);
smallColorControl [35].TabIndex = 64;
smallColorControl [35].Click += new EventHandler (OnSmallColorControlClick);
// colorPanel37
smallColorControl [36].Location = new Point (150, 61);
smallColorControl [36].TabIndex = 73;
smallColorControl [36].Click += new EventHandler (OnSmallColorControlClick);
// colorPanel38
smallColorControl [37].Location = new Point (150, 15);
smallColorControl [37].TabIndex = 57;
smallColorControl [37].Click += new EventHandler (OnSmallColorControlClick);
// colorPanel39
smallColorControl [38].Location = new Point (75, 15);
smallColorControl [38].TabIndex = 54;
smallColorControl [38].Click += new EventHandler (OnSmallColorControlClick);
// colorPanel40
smallColorControl [39].Location = new Point (25, 15);
smallColorControl [39].TabIndex = 52;
smallColorControl [39].Click += new EventHandler (OnSmallColorControlClick);
// colorPanel41
smallColorControl [40].Location = new Point (50, 107);
smallColorControl [40].TabIndex = 84;
smallColorControl [40].Click += new EventHandler (OnSmallColorControlClick);
// colorPanel42
smallColorControl [41].Location = new Point (75, 107);
smallColorControl [41].TabIndex = 85;
smallColorControl [41].Click += new EventHandler (OnSmallColorControlClick);
// colorPanel43
smallColorControl [42].Location = new Point (100, 107);
smallColorControl [42].TabIndex = 86;
smallColorControl [42].Click += new EventHandler (OnSmallColorControlClick);
// colorPanel44
smallColorControl [43].Location = new Point (125, 107);
smallColorControl [43].TabIndex = 87;
smallColorControl [43].Click += new EventHandler (OnSmallColorControlClick);
// colorPanel45
smallColorControl [44].Location = new Point (150, 107);
smallColorControl [44].TabIndex = 88;
smallColorControl [44].Click += new EventHandler (OnSmallColorControlClick);
// colorPanel46
smallColorControl [45].Location = new Point (175, 107);
smallColorControl [45].TabIndex = 89;
smallColorControl [45].Click += new EventHandler (OnSmallColorControlClick);
// colorPanel47
smallColorControl [46].Location = new Point (0, 130);
smallColorControl [46].TabIndex = 90;
smallColorControl [46].Click += new EventHandler (OnSmallColorControlClick);
// colorPanel48
smallColorControl [47].Location = new Point (25, 130);
smallColorControl [47].TabIndex = 91;
smallColorControl [47].Click += new EventHandler (OnSmallColorControlClick);
// userColorPane1
userSmallColorControl [0].Location = new Point (0, 180);
userSmallColorControl [0].TabIndex = 99;
userSmallColorControl [0].Click += new EventHandler (OnSmallColorControlClick);
// userColorPanel2
userSmallColorControl [1].Location = new Point (0, 203);
userSmallColorControl [1].TabIndex = 108;
userSmallColorControl [1].Click += new EventHandler (OnSmallColorControlClick);
// userColorPanel13
userSmallColorControl [2].Location = new Point (25, 180);
userSmallColorControl [2].TabIndex = 100;
userSmallColorControl [2].Click += new EventHandler (OnSmallColorControlClick);
// userColorPanel4
userSmallColorControl [3].Location = new Point (25, 203);
userSmallColorControl [3].TabIndex = 109;
userSmallColorControl [3].Click += new EventHandler (OnSmallColorControlClick);
// userColorPanel5
userSmallColorControl [4].Location = new Point (50, 180);
userSmallColorControl [4].TabIndex = 101;
userSmallColorControl [4].Click += new EventHandler (OnSmallColorControlClick);
// userColorPanel6
userSmallColorControl [5].Location = new Point (50, 203);
userSmallColorControl [5].TabIndex = 110;
userSmallColorControl [5].Click += new EventHandler (OnSmallColorControlClick);
// userColorPanel7
userSmallColorControl [6].Location = new Point (75, 180);
userSmallColorControl [6].TabIndex = 102;
userSmallColorControl [6].Click += new EventHandler (OnSmallColorControlClick);
// userColorPanel8
userSmallColorControl [7].Location = new Point (75, 203);
userSmallColorControl [7].TabIndex = 111;
userSmallColorControl [7].Click += new EventHandler (OnSmallColorControlClick);
// userColorPanel9
userSmallColorControl [8].Location = new Point (100, 180);
userSmallColorControl [8].TabIndex = 103;
userSmallColorControl [8].Click += new EventHandler (OnSmallColorControlClick);
// userColorPanel10
userSmallColorControl [9].Location = new Point (100, 203);
userSmallColorControl [9].TabIndex = 112;
userSmallColorControl [9].Click += new EventHandler (OnSmallColorControlClick);
// userColorPanel11
userSmallColorControl [10].Location = new Point (125, 180);
userSmallColorControl [10].TabIndex = 105;
userSmallColorControl [10].Click += new EventHandler (OnSmallColorControlClick);
// userColorPanel2
userSmallColorControl [11].Location = new Point (125, 203);
userSmallColorControl [11].TabIndex = 113;
userSmallColorControl [11].Click += new EventHandler (OnSmallColorControlClick);
// userColorPanel13
userSmallColorControl [12].Location = new Point (150, 180);
userSmallColorControl [12].TabIndex = 106;
userSmallColorControl [12].Click += new EventHandler (OnSmallColorControlClick);
// userColorPanel4
userSmallColorControl [13].Location = new Point (150, 203);
userSmallColorControl [13].TabIndex = 114;
userSmallColorControl [13].Click += new EventHandler (OnSmallColorControlClick);
// userColorPanel15
userSmallColorControl [14].Location = new Point (175, 180);
userSmallColorControl [14].TabIndex = 107;
userSmallColorControl [14].Click += new EventHandler (OnSmallColorControlClick);
// userColorPanel16
userSmallColorControl [15].Location = new Point (175, 203);
userSmallColorControl [15].TabIndex = 115;
userSmallColorControl [15].Click += new EventHandler (OnSmallColorControlClick);
// baseColorLabel
baseColorLabel.Location = new Point (2, 0);
baseColorLabel.Size = new Size (200, 12);
baseColorLabel.TabIndex = 5;
baseColorLabel.Text = Locale.GetText ("Base Colours") + ":";
// userColorLabel
userColorLabel.FlatStyle = FlatStyle.System;
userColorLabel.Location = new Point (2, 164);
userColorLabel.Size = new Size (200, 14);
userColorLabel.TabIndex = 104;
userColorLabel.Text = Locale.GetText ("User Colors") + ":";
Controls.Add (userSmallColorControl [7]);
Controls.Add (userSmallColorControl [6]);
Controls.Add (userSmallColorControl [5]);
Controls.Add (userSmallColorControl [4]);
Controls.Add (userSmallColorControl [3]);
Controls.Add (userSmallColorControl [2]);
Controls.Add (userSmallColorControl [1]);
Controls.Add (userSmallColorControl [0]);
Controls.Add (userSmallColorControl [15]);
Controls.Add (userSmallColorControl [14]);
Controls.Add (userSmallColorControl [13]);
Controls.Add (userSmallColorControl [12]);
Controls.Add (userSmallColorControl [11]);
Controls.Add (userSmallColorControl [10]);
Controls.Add (userSmallColorControl [9]);
Controls.Add (userSmallColorControl [8]);
Controls.Add (smallColorControl [0]);
Controls.Add (smallColorControl [3]);
Controls.Add (smallColorControl [6]);
Controls.Add (smallColorControl [7]);
Controls.Add (smallColorControl [4]);
Controls.Add (smallColorControl [5]);
Controls.Add (smallColorControl [2]);
Controls.Add (smallColorControl [1]);
Controls.Add (smallColorControl [47]);
Controls.Add (smallColorControl [46]);
Controls.Add (smallColorControl [45]);
Controls.Add (smallColorControl [44]);
Controls.Add (smallColorControl [43]);
Controls.Add (smallColorControl [42]);
Controls.Add (smallColorControl [41]);
Controls.Add (smallColorControl [40]);
Controls.Add (smallColorControl [25]);
Controls.Add (smallColorControl [26]);
Controls.Add (smallColorControl [27]);
Controls.Add (smallColorControl [28]);
Controls.Add (smallColorControl [29]);
Controls.Add (smallColorControl [30]);
Controls.Add (smallColorControl [31]);
Controls.Add (smallColorControl [32]);
Controls.Add (smallColorControl [18]);
Controls.Add (smallColorControl [14]);
Controls.Add (smallColorControl [36]);
Controls.Add (smallColorControl [12]);
Controls.Add (smallColorControl [13]);
Controls.Add (smallColorControl [10]);
Controls.Add (smallColorControl [11]);
Controls.Add (smallColorControl [8]);
Controls.Add (smallColorControl [9]);
Controls.Add (smallColorControl [20]);
Controls.Add (smallColorControl [34]);
Controls.Add (smallColorControl [35]);
Controls.Add (smallColorControl [21]);
Controls.Add (smallColorControl [16]);
Controls.Add (smallColorControl [15]);
Controls.Add (smallColorControl [33]);
Controls.Add (smallColorControl [17]);
Controls.Add (smallColorControl [19]);
Controls.Add (smallColorControl [37]);
Controls.Add (smallColorControl [24]);
Controls.Add (smallColorControl [23]);
Controls.Add (smallColorControl [38]);
Controls.Add (smallColorControl [22]);
Controls.Add (smallColorControl [39]);
Controls.Add (userColorLabel);
Controls.Add (baseColorLabel);
Size = new Size (212, 238);
ResumeLayout (false);
selectedSmallColorControl = smallColorControl [46]; // default, Black
selectedSmallColorControl.IsSelected = true;
CheckIfColorIsInPanel ();
}
private void CheckIfColorIsInPanel ()
{
if (colorDialog.Color != Color.Black) {
// check if we have a panel with a BackColor = ColorDialog.Color...
for (int i = 0; i < smallColorControl.Length; i++) {
if (smallColorControl [i].BackColor == colorDialog.Color) {
selectedSmallColorControl = smallColorControl [i];
break;
}
}
}
}
void OnSmallColorControlClick (object sender, EventArgs e)
{
// previous selected smallcolorcontrol
if (selectedSmallColorControl != (SmallColorControl)sender)
selectedSmallColorControl.IsSelected = false;
selectedSmallColorControl = (SmallColorControl)sender;
TriangleControl.CurrentBrightness = HSB.Brightness (selectedSmallColorControl.Color);
colorDialog.UpdateControls (selectedSmallColorControl.Color);
colorDialog.UpdateRGBTextBoxes (selectedSmallColorControl.Color);
colorDialog.UpdateHSBTextBoxes (selectedSmallColorControl.Color);
}
public Color ColorToShow {
get {
return selectedSmallColorControl.Color;
}
}
public void SetUserColor (Color col)
{
userSmallColorControl [currentlyUsedUserSmallColorControl].Color = col;
// check if this.customColors already exists
if (customColors == null) {
customColors = new int [16];
int white = Color.White.ToArgb ();
for (int i = 0; i < customColors.Length; i++)
customColors [i] = white;
}
customColors [currentlyUsedUserSmallColorControl] = col.ToArgb ();
// update ColorDialog dialog property
colorDialog.CustomColors = customColors;
currentlyUsedUserSmallColorControl++;
if (currentlyUsedUserSmallColorControl > 15)
currentlyUsedUserSmallColorControl = 0;
}
public void SetCustomColors ()
{
int[] customColors = colorDialog.CustomColors;
for (int i = 0; i < customColors.Length; i++) {
userSmallColorControl [i].Color = Color.FromArgb (customColors [i]);
}
}
}
internal class ColorMatrixControl : Panel {
internal class DrawingBitmap {
private Bitmap bitmap;
public DrawingBitmap ()
{
bitmap = new Bitmap (180, 191);
float hueadd = 241.0f / 178.0f;
float satsub = 241.0f / 189.0f;
float satpos = 240.0f;
// paint the matrix to the bitmap
for (int height = 0; height < 191; height++) {
float huepos = 0.0f;
for (int width = 0; width < 180; width++) {
HSB hsb = new HSB ();
hsb.hue = (int)huepos;
hsb.sat = (int)satpos;
hsb.bri = 120; // paint it with 120 to get a nice bitmap
bitmap.SetPixel (width, height, HSB.HSB2RGB (hsb.hue, hsb.sat, hsb.bri));
huepos += hueadd;
}
satpos -= satsub;
}
}
public Bitmap Bitmap {
set {
bitmap = value;
}
get {
return bitmap;
}
}
}
internal class CrossCursor {
private Bitmap bitmap;
private Color cursorColor;
public CrossCursor ()
{
bitmap = new Bitmap (22, 22);
cursorColor = Color.Black;
Draw ();
}
public void Draw ()
{
using (Pen pen = new Pen (ThemeEngine.Current.ResPool.GetSolidBrush (cursorColor), 3)) {
using (Graphics graphics = Graphics.FromImage (bitmap)) {
graphics.DrawLine (pen, 11, 0, 11, 7);
graphics.DrawLine (pen, 11, 14, 11, 21);
graphics.DrawLine (pen, 0, 11, 7, 11);
graphics.DrawLine (pen, 14, 11, 21, 11);
}
}
}
public Bitmap Bitmap {
set {
bitmap = value;
}
get {
return bitmap;
}
}
public Color CursorColor {
set {
cursorColor = value;
}
get {
return cursorColor;
}
}
}
private DrawingBitmap drawingBitmap = new DrawingBitmap( );
private CrossCursor crossCursor = new CrossCursor();
private bool mouseButtonDown = false;
private bool drawCross = true;
private Color color;
private int currentXPos;
private int currentYPos;
private const float xstep = 240.0f/178.0f;
private const float ystep = 240.0f/189.0f;
private ColorDialog colorDialog;
public ColorMatrixControl (ColorDialog colorDialog)
{
this.colorDialog = colorDialog;
SuspendLayout ();
BorderStyle = BorderStyle.Fixed3D;
Location = new Point (0, 0);
Size = new Size (179, 190);
TabIndex = 0;
TabStop = false;
//BackColor = SystemColors.Control;
Size = new Size (179, 190);
ResumeLayout (false);
SetStyle (ControlStyles.DoubleBuffer, true);
SetStyle (ControlStyles.AllPaintingInWmPaint, true);
SetStyle (ControlStyles.UserPaint, true);
}
protected override void OnPaint (PaintEventArgs e)
{
Draw (e);
base.OnPaint (e);
}
private void Draw (PaintEventArgs e)
{
e.Graphics.DrawImage (drawingBitmap.Bitmap, 0, 0);
// drawCross is false if the mouse gets moved...
if (drawCross) {
e.Graphics.DrawImage (crossCursor.Bitmap, currentXPos - 11 , currentYPos - 11);
}
}
protected override void OnMouseDown (MouseEventArgs e)
{
mouseButtonDown = true;
currentXPos = e.X;
currentYPos = e.Y;
if (drawCross) {
drawCross = false;
Invalidate ();
Update ();
}
UpdateControls ();
base.OnMouseDown (e);
}
protected override void OnMouseMove (MouseEventArgs e)
{
if (mouseButtonDown)
if ((e.X < 178 && e.X >= 0) && (e.Y < 189 && e.Y >= 0)) {
currentXPos = e.X;
currentYPos = e.Y;
UpdateControls ();
}
base.OnMouseMove (e);
}
protected override void OnMouseUp (MouseEventArgs e)
{
mouseButtonDown = false;
drawCross = true;
Invalidate ();
Update ();
}
public Color ColorToShow {
set {
color = value;
HSB hsb = HSB.RGB2HSB (color);
currentXPos = (int)((float)hsb.hue / xstep);
currentYPos = 189 - (int)((float)hsb.sat / ystep);
if (currentXPos < 0)
currentXPos = 0;
if (currentYPos < 0)
currentYPos = 0;
Invalidate ();
Update ();
UpdateControls ();
}
}
private Color GetColorFromHSB ()
{
int hue = (int)((float)currentXPos * xstep);
int sat = 240 - ((int)((float)currentYPos * ystep));
int bri = TriangleControl.CurrentBrightness;
return HSB.HSB2RGB (hue, sat, bri);
}
private void UpdateControls ()
{
Color tmpColor = GetColorFromHSB ();
// update the brightness control
colorDialog.brightnessControl.ShowColor ((int)((float)currentXPos * xstep), 240 - ((int)((float)currentYPos * ystep)));
// update saturation text box
int satvalue = (240 - ((int)((float)currentYPos * ystep)));
satvalue = satvalue == 240 ? 239 : satvalue;
colorDialog.satTextBox.Text = satvalue.ToString ();
// update hue text box
colorDialog.hueTextBox.Text = ((int)((float)currentXPos * xstep)).ToString ();
// update the main selected color panel
colorDialog.selectedColorPanel.BackColor = tmpColor;
// and finally the rgb text boxes
colorDialog.UpdateRGBTextBoxes (tmpColor);
}
}
internal class BrightnessControl : Panel {
internal class DrawingBitmap {
private Bitmap bitmap;
public DrawingBitmap ()
{
bitmap = new Bitmap (14, 190);
}
public Bitmap Bitmap {
set {
bitmap = value;
}
get {
return bitmap;
}
}
// only hue and saturation are needed.
// color will be computed with an iteration
public void Draw (int hue, int sat)
{
float brisub = 240.0f / 190.0f;
float bri = 240.0f;
for (int height = 0; height < 190; height++) {
for (int width = 0; width < 14; width++) {
Color pixcolor = HSB.HSB2RGB (hue, sat, (int)bri);
bitmap.SetPixel (width, height, pixcolor);
}
bri = bri - brisub;
}
}
}
private const float step = 240.0f/189.0f;
private DrawingBitmap bitmap;
private Color color;
private ColorDialog colorDialog;
public BrightnessControl (ColorDialog colorDialogPanel)
{
this.colorDialog = colorDialogPanel;
bitmap = new DrawingBitmap ();
SuspendLayout ();
BorderStyle = BorderStyle.Fixed3D;
Location = new Point (0, 0);
Size = new Size (14, 190);
TabIndex = 0;
TabStop = false;
Size = new Size (14, 190);
ResumeLayout (false);
SetStyle (ControlStyles.DoubleBuffer, true);
SetStyle (ControlStyles.AllPaintingInWmPaint, true);
SetStyle (ControlStyles.UserPaint, true);
}
protected override void OnPaint (PaintEventArgs e)
{
e.Graphics.DrawImage (bitmap.Bitmap, 0, 0);
base.OnPaint (e);
}
protected override void OnMouseDown (MouseEventArgs e)
{
colorDialog.triangleControl.TrianglePosition = (int)((float)(189 - e.Y) * step);
base.OnMouseDown (e);
}
// this one is for ColorMatrixControl
public void ShowColor (int hue, int sat)
{
bitmap.Draw (hue, sat);
Invalidate ();
Update ();
}
// this one for the other controls
public Color ColorToShow {
set {
int hue, sat;
HSB.GetHueSaturation (value, out hue, out sat);
bitmap.Draw (hue, sat);
Invalidate ();
Update ();
}
}
}
internal class TriangleControl : Panel {
private bool mouseButtonDown = false;
private int currentTrianglePosition = 195;
// private Rectangle clipRectangle;
private const float briStep = 239.0f/186.0f;
private static int currentBrightness = 0;
private ColorDialog colorDialog;
public TriangleControl (ColorDialog colorDialog)
{
this.colorDialog = colorDialog;
SuspendLayout ();
Size = new Size (16, 203);
ResumeLayout (false);
SetStyle (ControlStyles.DoubleBuffer, true);
SetStyle (ControlStyles.AllPaintingInWmPaint, true);
SetStyle (ControlStyles.UserPaint, true);
}
public static int CurrentBrightness {
set {
currentBrightness = value;
}
get {
return currentBrightness;
}
}
protected override void OnPaint (PaintEventArgs e)
{
Draw (e);
base.OnPaint (e);
}
private void Draw (PaintEventArgs e)
{
e.Graphics.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (BackColor), new Rectangle (0, 0, 16, 203));
Point[] trianglePoints = new Point [3]
{
new Point (0, currentTrianglePosition),
new Point (8, currentTrianglePosition - 8),
new Point (8, currentTrianglePosition + 8)
};
e.Graphics.FillPolygon (ThemeEngine.Current.ResPool.GetSolidBrush (Color.Black), trianglePoints);
}
protected override void OnMouseDown (MouseEventArgs e)
{
if (e.Y > 195 || e.Y < 9) return; // helper until Cursor.Clip works
mouseButtonDown = true;
currentTrianglePosition = e.Y;
// Cursor.Clip doesn't yet work in Managed.Windows.Forms
// clipRectangle = Cursor.Clip;
// Point p = Location;
// p.Y += 8;
// Size s = Size;
// s.Width -= 5;
// s.Height -= 16;
// Cursor.Clip = new Rectangle( Parent.PointToScreen( p ), s );
colorDialog.briTextBox.Text = TrianglePosition.ToString ();
colorDialog.UpdateFromHSBTextBoxes ();
Invalidate ();
Update ();
base.OnMouseDown (e);
}
protected override void OnMouseMove (MouseEventArgs e)
{
if (mouseButtonDown)
if (e.Y < 196 && e.Y > 8) {
currentTrianglePosition = e.Y;
colorDialog.briTextBox.Text = TrianglePosition.ToString ();
colorDialog.UpdateFromHSBTextBoxes ();
Invalidate ();
Update ();
}
base.OnMouseMove (e);
}
protected override void OnMouseUp (MouseEventArgs e)
{
mouseButtonDown = false;
// Cursor.Clip = clipRectangle;
base.OnMouseUp (e);
}
public int TrianglePosition {
get {
float tmp = (float)(currentTrianglePosition - 9);
tmp = tmp * briStep;
int retval = 239 - (int)tmp;
TriangleControl.CurrentBrightness = retval;
return retval;
}
set {
float tmp = (float)value / briStep;
currentTrianglePosition = 186 - (int)tmp + 9;
colorDialog.briTextBox.Text = TrianglePosition.ToString ();
colorDialog.UpdateFromHSBTextBoxes ();
Invalidate ();
Update ();
}
}
public Color ColorToShow {
set {
TrianglePosition = HSB.Brightness (value);
}
}
}
#endregion
}
}
|