1
2
3
4
5
6 using System;
7 using System.Collections;
8
9 namespace System.Windows
10 {
11 public class Color
12 {
13 public nothrow Color() : alpha(255u), red(0u), green(0u), blue(0u)
14 {
15 }
16 public nothrow Color(byte alpha_, byte red_, byte green_, byte blue_) : alpha(alpha_), red(red_), green(green_), blue(blue_)
17 {
18 }
19 public nothrow Color(byte red_, byte green_, byte blue_) : alpha(255u), red(red_), green(green_), blue(blue_)
20 {
21 }
22 public nothrow Color ToGray(const Color& transparentColor) const
23 {
24 if (*this == transparentColor) return *this;
25 byte g = cast<byte>((cast<int>(red) + cast<int>(green) + cast<int>(blue) + 2 * 255) / 5);
26 return Color(alpha, g, g, g);
27 }
28 public nothrow Color ToGray() const
29 {
30 return ToGray(Color(0u, 255u, 255u, 255u));
31 }
32 public nothrow string ToString() const
33 {
34 string s = System.ToString(alpha);
35 s.Append('.').Append(System.ToString(red)).Append('.').Append(System.ToString(green)).Append('.').Append(System.ToString(blue));
36 return s;
37 }
38 public static nothrow Color AliceBlue()
39 {
40 return Color(0xF0u, 0xF8u, 0xFFu);
41 }
42 public static nothrow Color AntiqueWhite()
43 {
44 return Color(0xFAu, 0xEBu, 0xD7u);
45 }
46 public static nothrow Color Aqua()
47 {
48 return Color(0x00u, 0xFFu, 0xFFu);
49 }
50 public static nothrow Color Aquamarine()
51 {
52 return Color(0x7Fu, 0xFFu, 0xD4u);
53 }
54 public static nothrow Color Azure()
55 {
56 return Color(0xF0u, 0xFFu, 0xFFu);
57 }
58 public static nothrow Color Beige()
59 {
60 return Color(0xF5u, 0xF5u, 0xDCu);
61 }
62 public static nothrow Color Bisque()
63 {
64 return Color(0xFFu, 0xE4u, 0xC4u);
65 }
66 public static nothrow Color Black()
67 {
68 return Color(0x00u, 0x00u, 0x00u);
69 }
70 public static nothrow Color BlanchedAlmond()
71 {
72 return Color(0xFFu, 0xEBu, 0xCDu);
73 }
74 public static nothrow Color Blue()
75 {
76 return Color(0x00u, 0x00u, 0xFFu);
77 }
78 public static nothrow Color BlueViolet()
79 {
80 return Color(0x8Au, 0x2Bu, 0xE2u);
81 }
82 public static nothrow Color Brown()
83 {
84 return Color(0xA5u, 0x2Au, 0x2Au);
85 }
86 public static nothrow Color BurlyWood()
87 {
88 return Color(0xDEu, 0xB8u, 0x87u);
89 }
90 public static nothrow Color CadetBlue()
91 {
92 return Color(0x5Fu, 0x9Eu, 0xA0u);
93 }
94 public static nothrow Color Chartreuse()
95 {
96 return Color(0x7Fu, 0xFFu, 0x00u);
97 }
98 public static nothrow Color Chocolate()
99 {
100 return Color(0xD2u, 0x69u, 0x1Eu);
101 }
102 public static nothrow Color Coral()
103 {
104 return Color(0xFFu, 0x7Fu, 0x50u);
105 }
106 public static nothrow Color CornflowerBlue()
107 {
108 return Color(0x64u, 0x95u, 0xEDu);
109 }
110 public static nothrow Color Cornsilk()
111 {
112 return Color(0xFFu, 0xF8u, 0xDCu);
113 }
114 public static nothrow Color Crimson()
115 {
116 return Color(0xDCu, 0x14u, 0x3Cu);
117 }
118 public static nothrow Color Cyan()
119 {
120 return Color(0x00u, 0xFFu, 0xFFu);
121 }
122 public static nothrow Color DarkBlue()
123 {
124 return Color(0x00u, 0x00u, 0x8Bu);
125 }
126 public static nothrow Color DarkCyan()
127 {
128 return Color(0x00u, 0x8Bu, 0x8Bu);
129 }
130 public static nothrow Color DarkGoldenrod()
131 {
132 return Color(0xB8u, 0x86u, 0x0Bu);
133 }
134 public static nothrow Color DarkGray()
135 {
136 return Color(0xA9u, 0xA9u, 0xA9u);
137 }
138 public static nothrow Color DarkGreen()
139 {
140 return Color(0x00u, 0x64u, 0x00u);
141 }
142 public static nothrow Color DarkKhaki()
143 {
144 return Color(0xBDu, 0xB7u, 0x6Bu);
145 }
146 public static nothrow Color DarkMagenta()
147 {
148 return Color(0x8Bu, 0x00u, 0x8Bu);
149 }
150 public static nothrow Color DarkOliveGreen()
151 {
152 return Color(0x55u, 0x6Bu, 0x2Fu);
153 }
154 public static nothrow Color DarkOrange()
155 {
156 return Color(0xFFu, 0x8Cu, 0x00u);
157 }
158 public static nothrow Color DarkOrchid()
159 {
160 return Color(0x99u, 0x32u, 0xCCu);
161 }
162 public static nothrow Color DarkRed()
163 {
164 return Color(0x8Bu, 0x00u, 0x00u);
165 }
166 public static nothrow Color DarkSalmon()
167 {
168 return Color(0xE9u, 0x96u, 0x7Au);
169 }
170 public static nothrow Color DarkSeaGreen()
171 {
172 return Color(0x8Fu, 0xBCu, 0x8Bu);
173 }
174 public static nothrow Color DarkSlateBlue()
175 {
176 return Color(0x48u, 0x3Du, 0x8Bu);
177 }
178 public static nothrow Color DarkSlateGray()
179 {
180 return Color(0x2Fu, 0x4Fu, 0x4Fu);
181 }
182 public static nothrow Color DarkTurquoise()
183 {
184 return Color(0x00u, 0xCEu, 0xD1u);
185 }
186 public static nothrow Color DarkViolet()
187 {
188 return Color(0x94u, 0x00u, 0xD3u);
189 }
190 public static nothrow Color DeepPink()
191 {
192 return Color(0xFFu, 0x14u, 0x93u);
193 }
194 public static nothrow Color DeepSkyBlue()
195 {
196 return Color(0x00u, 0xBFu, 0xFFu);
197 }
198 public static nothrow Color DimGray()
199 {
200 return Color(0x69u, 0x69u, 0x69u);
201 }
202 public static nothrow Color DodgerBlue()
203 {
204 return Color(0x1Eu, 0x90u, 0xFFu);
205 }
206 public static nothrow Color Firebrick()
207 {
208 return Color(0xB2u, 0x22u, 0x22u);
209 }
210 public static nothrow Color FloralWhite()
211 {
212 return Color(0xFFu, 0xFAu, 0xF0u);
213 }
214 public static nothrow Color ForestGreen()
215 {
216 return Color(0x22u, 0x8Bu, 0x22u);
217 }
218 public static nothrow Color Fuchsia()
219 {
220 return Color(0xFFu, 0x00u, 0xFFu);
221 }
222 public static nothrow Color Gainsboro()
223 {
224 return Color(0xDCu, 0xDCu, 0xDCu);
225 }
226 public static nothrow Color GhostWhite()
227 {
228 return Color(0xF8u, 0xF8u, 0xFFu);
229 }
230 public static nothrow Color Gold()
231 {
232 return Color(0xFFu, 0xD7u, 0x00u);
233 }
234 public static nothrow Color Goldenrod()
235 {
236 return Color(0xDAu, 0xA5u, 0x20u);
237 }
238 public static nothrow Color Gray()
239 {
240 return Color(0x80u, 0x80u, 0x80u);
241 }
242 public static nothrow Color Green()
243 {
244 return Color(0x00u, 0x80u, 0x00u);
245 }
246 public static nothrow Color GreenYellow()
247 {
248 return Color(0xADu, 0xFFu, 0x2Fu);
249 }
250 public static nothrow Color Honeydew()
251 {
252 return Color(0xF0u, 0xFFu, 0xF0u);
253 }
254 public static nothrow Color HotPink()
255 {
256 return Color(0xFFu, 0x69u, 0xB4u);
257 }
258 public static nothrow Color IndianRed()
259 {
260 return Color(0xCDu, 0x5Cu, 0x5Cu);
261 }
262 public static nothrow Color Indigo()
263 {
264 return Color(0x4Bu, 0x00u, 0x82u);
265 }
266 public static nothrow Color Ivory()
267 {
268 return Color(0xFFu, 0xFFu, 0xF0u);
269 }
270 public static nothrow Color Khaki()
271 {
272 return Color(0xF0u, 0xE6u, 0x8Cu);
273 }
274 public static nothrow Color Lavender()
275 {
276 return Color(0xE6u, 0xE6u, 0xFAu);
277 }
278 public static nothrow Color LavenderBlush()
279 {
280 return Color(0xFFu, 0xF0u, 0xF5u);
281 }
282 public static nothrow Color LawnGreen()
283 {
284 return Color(0x7Cu, 0xFCu, 0x00u);
285 }
286 public static nothrow Color LemonChiffon()
287 {
288 return Color(0xFFu, 0xFAu, 0xCDu);
289 }
290 public static nothrow Color LightBlue()
291 {
292 return Color(0xADu, 0xD8u, 0xE6u);
293 }
294 public static nothrow Color LightCoral()
295 {
296 return Color(0xF0u, 0x80u, 0x80u);
297 }
298 public static nothrow Color LightCyan()
299 {
300 return Color(0xE0u, 0xFFu, 0xFFu);
301 }
302 public static nothrow Color LightGoldenrodYellow()
303 {
304 return Color(0xFAu, 0xFAu, 0xD2u);
305 }
306 public static nothrow Color LightGray()
307 {
308 return Color(0xD3u, 0xD3u, 0xD3u);
309 }
310 public static nothrow Color LightGreen()
311 {
312 return Color(0x90u, 0xEEu, 0x90u);
313 }
314 public static nothrow Color LightPink()
315 {
316 return Color(0xFFu, 0xB6u, 0xC1u);
317 }
318 public static nothrow Color LightSalmon()
319 {
320 return Color(0xFFu, 0xA0u, 0x7Au);
321 }
322 public static nothrow Color LightSeaGreen()
323 {
324 return Color(0x20u, 0xB2u, 0xAAu);
325 }
326 public static nothrow Color LightSkyBlue()
327 {
328 return Color(0x87u, 0xCEu, 0xFAu);
329 }
330 public static nothrow Color LightSlateGray()
331 {
332 return Color(0x77u, 0x88u, 0x99u);
333 }
334 public static nothrow Color LightSteelBlue()
335 {
336 return Color(0xB0u, 0xC4u, 0xDEu);
337 }
338 public static nothrow Color LightYellow()
339 {
340 return Color(0xFFu, 0xFFu, 0xE0u);
341 }
342 public static nothrow Color Lime()
343 {
344 return Color(0x00u, 0xFFu, 0x00u);
345 }
346 public static nothrow Color LimeGreen()
347 {
348 return Color(0x32u, 0xCDu, 0x32u);
349 }
350 public static nothrow Color Linen()
351 {
352 return Color(0xFAu, 0xF0u, 0xE6u);
353 }
354 public static nothrow Color Magenta()
355 {
356 return Color(0xFFu, 0x00u, 0xFFu);
357 }
358 public static nothrow Color Maroon()
359 {
360 return Color(0x80u, 0x00u, 0x00u);
361 }
362 public static nothrow Color MediumAquamarine()
363 {
364 return Color(0x66u, 0xCDu, 0xAAu);
365 }
366 public static nothrow Color MediumBlue()
367 {
368 return Color(0x00u, 0x00u, 0xCDu);
369 }
370 public static nothrow Color MediumOrchid()
371 {
372 return Color(0xBAu, 0x55u, 0xD3u);
373 }
374 public static nothrow Color MediumPurple()
375 {
376 return Color(0x93u, 0x70u, 0xDBu);
377 }
378 public static nothrow Color MediumSeaGreen()
379 {
380 return Color(0x3Cu, 0xB3u, 0x71u);
381 }
382 public static nothrow Color MediumSlateBlue()
383 {
384 return Color(0x7Bu, 0x68u, 0xEEu);
385 }
386 public static nothrow Color MediumSpringGreen()
387 {
388 return Color(0x00u, 0xFAu, 0x9Au);
389 }
390 public static nothrow Color MediumTurquoise()
391 {
392 return Color(0x48u, 0xD1u, 0xCCu);
393 }
394 public static nothrow Color MediumVioletRed()
395 {
396 return Color(0xC7u, 0x15u, 0x85u);
397 }
398 public static nothrow Color MidnightBlue()
399 {
400 return Color(0x19u, 0x19u, 0x70u);
401 }
402 public static nothrow Color MintCream()
403 {
404 return Color(0xF5u, 0xFFu, 0xFAu);
405 }
406 public static nothrow Color MistyRose()
407 {
408 return Color(0xFFu, 0xE4u, 0xE1u);
409 }
410 public static nothrow Color Moccasin()
411 {
412 return Color(0xFFu, 0xE4u, 0xB5u);
413 }
414 public static nothrow Color NavajoWhite()
415 {
416 return Color(0xFFu, 0xDEu, 0xADu);
417 }
418 public static nothrow Color Navy()
419 {
420 return Color(0x00u, 0x00u, 0x80u);
421 }
422 public static nothrow Color OldLace()
423 {
424 return Color(0xFDu, 0xF5u, 0xE6u);
425 }
426 public static nothrow Color Olive()
427 {
428 return Color(0x80u, 0x80u, 0x00u);
429 }
430 public static nothrow Color OliveDrab()
431 {
432 return Color(0x6Bu, 0x8Eu, 0x23u);
433 }
434 public static nothrow Color Orange()
435 {
436 return Color(0xFFu, 0xA5u, 0x00u);
437 }
438 public static nothrow Color OrangeRed()
439 {
440 return Color(0xFFu, 0x45u, 0x00u);
441 }
442 public static nothrow Color Orchid()
443 {
444 return Color(0xDAu, 0x70u, 0xD6u);
445 }
446 public static nothrow Color PaleGoldenrod()
447 {
448 return Color(0xEEu, 0xE8u, 0xAAu);
449 }
450 public static nothrow Color PaleGreen()
451 {
452 return Color(0x98u, 0xFBu, 0x98u);
453 }
454 public static nothrow Color PaleTurquoise()
455 {
456 return Color(0xAFu, 0xEEu, 0xEEu);
457 }
458 public static nothrow Color PaleVioletRed()
459 {
460 return Color(0xDBu, 0x70u, 0x93u);
461 }
462 public static nothrow Color PapayaWhip()
463 {
464 return Color(0xFFu, 0xEFu, 0xD5u);
465 }
466 public static nothrow Color PeachPuff()
467 {
468 return Color(0xFFu, 0xDAu, 0xB9u);
469 }
470 public static nothrow Color Peru()
471 {
472 return Color(0xCDu, 0x85u, 0x3Fu);
473 }
474 public static nothrow Color Pink()
475 {
476 return Color(0xFFu, 0xC0u, 0xCBu);
477 }
478 public static nothrow Color Plum()
479 {
480 return Color(0xDDu, 0xA0u, 0xDDu);
481 }
482 public static nothrow Color PowderBlue()
483 {
484 return Color(0xB0u, 0xE0u, 0xE6u);
485 }
486 public static nothrow Color Purple()
487 {
488 return Color(0x80u, 0x00u, 0x80u);
489 }
490 public static nothrow Color Red()
491 {
492 return Color(0xFFu, 0x00u, 0x00u);
493 }
494 public static nothrow Color RosyBrown()
495 {
496 return Color(0xBCu, 0x8Fu, 0x8Fu);
497 }
498 public static nothrow Color RoyalBlue()
499 {
500 return Color(0x41u, 0x69u, 0xE1u);
501 }
502 public static nothrow Color SaddleBrown()
503 {
504 return Color(0x8Bu, 0x45u, 0x13u);
505 }
506 public static nothrow Color Salmon()
507 {
508 return Color(0xFAu, 0x80u, 0x72u);
509 }
510 public static nothrow Color SandyBrown()
511 {
512 return Color(0xF4u, 0xA4u, 0x60u);
513 }
514 public static nothrow Color SeaGreen()
515 {
516 return Color(0x2Eu, 0x8Bu, 0x57u);
517 }
518 public static nothrow Color SeaShell()
519 {
520 return Color(0xFFu, 0xF5u, 0xEEu);
521 }
522 public static nothrow Color Sienna()
523 {
524 return Color(0xA0u, 0x52u, 0x2Du);
525 }
526 public static nothrow Color Silver()
527 {
528 return Color(0xC0u, 0xC0u, 0xC0u);
529 }
530 public static nothrow Color SkyBlue()
531 {
532 return Color(0x87u, 0xCEu, 0xEBu);
533 }
534 public static nothrow Color SlateBlue()
535 {
536 return Color(0x6Au, 0x5Au, 0xCDu);
537 }
538 public static nothrow Color SlateGray()
539 {
540 return Color(0x70u, 0x80u, 0x90u);
541 }
542 public static nothrow Color Snow()
543 {
544 return Color(0xFFu, 0xFAu, 0xFAu);
545 }
546 public static nothrow Color SpringGreen()
547 {
548 return Color(0x00u, 0xFFu, 0x7Fu);
549 }
550 public static nothrow Color SteelBlue()
551 {
552 return Color(0x46u, 0x82u, 0xB4u);
553 }
554 public static nothrow Color Tan()
555 {
556 return Color(0xD2u, 0xB4u, 0x8Cu);
557 }
558 public static nothrow Color Teal()
559 {
560 return Color(0x00u, 0x80u, 0x80u);
561 }
562 public static nothrow Color Thistle()
563 {
564 return Color(0xD8u, 0xBFu, 0xD8u);
565 }
566 public static nothrow Color Tomato()
567 {
568 return Color(0xFFu, 0x63u, 0x47u);
569 }
570 public static nothrow Color Transparent()
571 {
572 return Color(0x00u, 0xFFu, 0xFFu, 0xFFu);
573 }
574 public static nothrow Color Turquoise()
575 {
576 return Color(0x40u, 0xE0u, 0xD0u);
577 }
578 public static nothrow Color Violet()
579 {
580 return Color(0xEEu, 0x82u, 0xEEu);
581 }
582 public static nothrow Color Wheat()
583 {
584 return Color(0xF5u, 0xDEu, 0xB3u);
585 }
586 public static nothrow Color White()
587 {
588 return Color(0xFFu, 0xFFu, 0xFFu);
589 }
590 public static nothrow Color WhiteSmoke()
591 {
592 return Color(0xF5u, 0xF5u, 0xF5u);
593 }
594 public static nothrow Color Yellow()
595 {
596 return Color(0xFFu, 0xFFu, 0x00u);
597 }
598 public static nothrow Color YellowGreen()
599 {
600 return Color(0x9Au, 0xCDu, 0x32u);
601 }
602 public static nothrow Color DefaultBitmapTransparent()
603 {
604 return Color(0u, 128u, 128u);
605 }
606 public byte alpha;
607 public byte red;
608 public byte green;
609 public byte blue;
610 }
611
612 public nothrow bool operator==(const Color& left, const Color& right)
613 {
614 return left.alpha == right.alpha && left.red == right.red && left.green == right.green && left.blue == right.blue;
615 }
616
617 public nothrow ulong GetHashCode(const Color& color)
618 {
619 return (cast<ulong>(color.alpha) << (8u * 3u)) | (cast<ulong>(color.red) << (8u * 2u)) | (cast<ulong>(color.green) << (8u * 1u)) | cast<ulong>(color.blue);
620 }
621
622 public Color ParseColor(const string& s)
623 {
624 Color color;
625 List<string> components = s.Split('.');
626 if (components.Count() == 4)
627 {
628 color.alpha = cast<byte>(ParseInt(components[0]));
629 color.red = cast<byte>(ParseInt(components[1]));
630 color.green = cast<byte>(ParseInt(components[2]));
631 color.blue = cast<byte>(ParseInt(components[3]));
632 }
633 else
634 {
635 ThrowConversionException("could not parse color from string '" + s + "'");
636 }
637 return color;
638 }
639
640 public Color GetSystemColor(SystemColor color)
641 {
642 byte red;
643 byte green;
644 byte blue;
645 WinGetSysColor(cast<int>(color), red, green, blue);
646 return Color(red, green, blue);
647 }
648
649 public nothrow System.Windows.Color GetColor(System.Color.Constant consoleColor)
650 {
651 switch (consoleColor)
652 {
653 case System.Color.Constant.black:
654 {
655 return System.Windows.Color(12u, 12u, 12u);
656 }
657 case System.Color.Constant.darkRed:
658 {
659 return System.Windows.Color(197u, 15u, 31u);
660 }
661 case System.Color.Constant.darkGreen:
662 {
663 return System.Windows.Color(19u, 161u, 14u);
664 }
665 case System.Color.Constant.darkYellow:
666 {
667 return System.Windows.Color(193u, 156u, 0u);
668 }
669 case System.Color.Constant.darkBlue:
670 {
671 return System.Windows.Color(0u, 55u, 218u);
672 }
673 case System.Color.Constant.darkGray:
674 {
675 return System.Windows.Color(169u, 169u, 169u);
676 }
677 case System.Color.Constant.darkCyan:
678 {
679 return System.Windows.Color(58u, 150u, 221u);
680 }
681 case System.Color.Constant.gray:
682 {
683 return System.Windows.Color(204u, 204u, 204u);
684 }
685 case System.Color.Constant.red:
686 {
687 return System.Windows.Color(231u, 72u, 86u);
688 }
689 case System.Color.Constant.green:
690 {
691 return System.Windows.Color(22u, 198u, 12u);
692 }
693 case System.Color.Constant.yellow:
694 {
695 return System.Windows.Color(249u, 241u, 165u);
696 }
697 case System.Color.Constant.blue:
698 {
699 return System.Windows.Color(59u, 120u, 255u);
700 }
701 case System.Color.Constant.magenta:
702 {
703 return System.Windows.Color(180u, 0u, 158u);
704 }
705 case System.Color.Constant.cyan:
706 {
707 return System.Windows.Color(97u, 214u, 214u);
708 }
709 case System.Color.Constant.white:
710 {
711 return System.Windows.Color(242u, 242u, 242u);
712 }
713 }
714 return System.Windows.Color.Black();
715 }
716 }