Merge pull request #461 from knocte/xbuild_improvements
[mono.git] / mcs / class / System.Drawing / System.Drawing / KnownColors.cs
index 749a691486340a186479f5dbe9cbce591fba199e..5773a0d5d6de542b854c096a228dfd94fe98f744 100644 (file)
@@ -39,6 +39,7 @@ namespace System.Drawing {
                {
                }
 #endif
+               // FindColorMatch relies on the index + 1 == KnowColor match
                static internal uint[] ArgbValues = new uint[] {
                        0x00000000,     /* 000 - Empty */
                        0xFFD4D0C8,     /* 001 - ActiveBorder */
@@ -229,10 +230,12 @@ namespace System.Drawing {
                        // correct system colors outside Windows
                }
 
-               // Windows values are without alpha, force it to opaque (or everything will be transparent)
+               // Windows values are in BGR format and without alpha
+               // so we force it to opaque (or everything will be transparent) and reverse B and R
                static uint GetSysColor (GetSysColorIndex index)
                {
-                       return 0xFF000000 | GDIPlus.Win32GetSysColor (index);
+                       uint bgr = GDIPlus.Win32GetSysColor (index);
+                       return 0xFF000000 | (bgr & 0xFF) << 16 | (bgr & 0xFF00) | (bgr >> 16);
                }
 
                static void RetrieveWindowsSystemColors ()
@@ -290,7 +293,7 @@ namespace System.Drawing {
                                c.state = (short) (Color.ColorType.ARGB | Color.ColorType.Known | Color.ColorType.Named);
                                if ((n < 27) || (n > 169))
                                        c.state |= (short) Color.ColorType.System;
-                               c.value = ArgbValues [n];
+                               c.Value = ArgbValues [n];
 #if ONLY_1_1
                                c.name = GetName (n);
 #endif
@@ -487,13 +490,20 @@ namespace System.Drawing {
                        return GetName ((short)kc);
                }
 
+               // FIXME: Linear scan
                public static Color FindColorMatch (Color c)
                {
                        uint argb = (uint) c.ToArgb ();
-                       for (int i = 0; i < KnownColors.ArgbValues.Length; i++) {
+                       
+                       // 1-based
+                       const int first_real_color_index = (int) KnownColor.AliceBlue;
+                       const int last_real_color_index = (int) KnownColor.YellowGreen;
+                       
+                       for (int i = first_real_color_index - 1; i < last_real_color_index; i++) {
                                if (argb == KnownColors.ArgbValues [i])
                                        return KnownColors.FromKnownColor ((KnownColor)i);
-                        }
+                       }
+                       
                        return Color.Empty;
                }