Added Rebecca Purple (#42785)
authorFireCubeStudios <40955345+FireCubeStudios@users.noreply.github.com>
Wed, 9 Dec 2020 11:11:49 +0000 (12:11 +0100)
committerGitHub <noreply@github.com>
Wed, 9 Dec 2020 11:11:49 +0000 (11:11 +0000)
* Added Rebecca Purple

Added Rebecca Purple color to System.Drawing.Color

Added RebeccaPurple (#663399) to KnownColorNames.cs, Color.cs, KnownColortable.cs and KnownColor.cs

#38244

* Added RebeccaPurple to UnitTest and Ref

Added RebeccaPurple color to the  UnitTest and to the ref

Added RebeccaPurple a,r,g,b value to unittest in System.Drawing.Primitive. Also updated the ref.

#38244

* Added RebeccaPurple to the system.drawing.primitive ref

Added RebeccaPurple color to the  System.Drawing.Primitive ref file.

"RebeccaPurple = 141" was added. I updated the other colors to their previous number by one.

#38244

* Reverted breaking changes in drawing.primitive ref

Reverted the breaking changes in system.drawing.primivite ref.

the numbers of colors were restored back and i removed rebeccapurple.

#38244

* Added RebeccaPurple to the ref

I added rebeccapurple to the ref file with value 175.

RebeccaPurple was added with value 175 to the bottom of the enum.

#38244

* Added rebeccapurple to bottom of Knowncolors.cs

I added rebeccapurple to theend of the file

RebeccaPurple was added to the bottom of the enum.

#38244

* Added Rebecca Purple

Added Rebecca Purple color to System.Drawing.Color

Added RebeccaPurple (#663399) to KnownColorNames.cs, Color.cs, KnownColortable.cs and KnownColor.cs

#38244

* Added RebeccaPurple to UnitTest and Ref

Added RebeccaPurple color to the  UnitTest and to the ref

Added RebeccaPurple a,r,g,b value to unittest in System.Drawing.Primitive. Also updated the ref.

#38244

* Added RebeccaPurple to the system.drawing.primitive ref

Added RebeccaPurple color to the  System.Drawing.Primitive ref file.

"RebeccaPurple = 141" was added. I updated the other colors to their previous number by one.

#38244

* Reverted breaking changes in drawing.primitive ref

Reverted the breaking changes in system.drawing.primivite ref.

the numbers of colors were restored back and i removed rebeccapurple.

#38244

* Added RebeccaPurple to the ref

I added rebeccapurple to the ref file with value 175.

RebeccaPurple was added with value 175 to the bottom of the enum.

#38244

* Added rebeccapurple to bottom of Knowncolors.cs

I added rebeccapurple to theend of the file

RebeccaPurple was added to the bottom of the enum.

#38244

* Fixed some of the requested changes with ordering of Enum

Removed a comment in "knowncolor.cs" and moved rebeccapurple to match enum order.

moved rebeccapurple in knowncolortable.cs, color.cs, and knowncolornames.cs

#38244

* Removed duplicates and added a comment

Added a comment in KnownColorNames.cs stating that the array follows order of knowncolor enum. Also removed duplicate rebeccapurple entries

#38244

* Fixing up the handling of RebeccaPurple

* Added a comment to explain changes

Added a comment in KnownColortable.cs stating that the code accounts for the system colors and new rebeccapurple color
#38244

Co-authored-by: Tanner Gooding <tagoo@outlook.com>
src/libraries/Common/src/System/Drawing/KnownColor.cs
src/libraries/Common/src/System/Drawing/KnownColorTable.cs
src/libraries/System.Drawing.Primitives/ref/System.Drawing.Primitives.cs
src/libraries/System.Drawing.Primitives/src/System/Drawing/Color.cs
src/libraries/System.Drawing.Primitives/src/System/Drawing/KnownColorNames.cs
src/libraries/System.Drawing.Primitives/tests/ColorTests.cs

index cf15dbe..a96bc02 100644 (file)
@@ -21,7 +21,7 @@ namespace System.Drawing
 
         // 0 - reserved for "not a known color"
 
-        // "System" colors
+        // "System" colors, Part 1
         ActiveBorder = 1,
         ActiveCaption,
         ActiveCaptionText,
@@ -49,7 +49,7 @@ namespace System.Drawing
         WindowFrame,
         WindowText,
 
-        // "Web" Colors
+        // "Web" Colors, Part 1
         Transparent,
         AliceBlue,
         AntiqueWhite,
@@ -192,14 +192,16 @@ namespace System.Drawing
         Yellow,
         YellowGreen,
 
-        // New system color additions in Visual Studio 2005 (.NET Framework 2.0)
-
+        // "System" colors, Part 2
         ButtonFace,
         ButtonHighlight,
         ButtonShadow,
         GradientActiveCaption,
         GradientInactiveCaption,
         MenuBar,
-        MenuHighlight
+        MenuHighlight,
+
+        // "Web" colors, Part 2
+        RebeccaPurple,
     }
 }
index ca342e5..3dc018c 100644 (file)
@@ -10,6 +10,8 @@ namespace System.Drawing
         // All non system colors (in order of definition in the KnownColor enum).
         private static readonly uint[] s_colorTable = new uint[]
         {
+            // First contiguous set.
+
             0x00FFFFFF,     // Transparent
             0xFFF0F8FF,     // AliceBlue
             0xFFFAEBD7,     // AntiqueWhite
@@ -151,6 +153,10 @@ namespace System.Drawing
             0xFFF5F5F5,     // WhiteSmoke
             0xFFFFFF00,     // Yellow
             0xFF9ACD32,     // YellowGreen
+
+            // Second contiguous set.
+
+            0xFF663399,     // RebeccaPurple
         };
 
         internal static Color ArgbToKnownColor(uint argb)
@@ -163,7 +169,14 @@ namespace System.Drawing
             {
                 if (s_colorTable[index] == argb)
                 {
-                    return Color.FromKnownColor((KnownColor)(index + (int)KnownColor.Transparent));
+                    var knownColor = KnownColor.Transparent + index;
+                    // Handles the mismatching of the RebeccaPurple color with ButtonFace color ("System" colors, Part 2)
+                    if (knownColor > KnownColor.YellowGreen)
+                    {
+                        knownColor += (int)KnownColor.RebeccaPurple - (int)KnownColor.ButtonFace;
+                    }
+
+                    return Color.FromKnownColor(knownColor);
                 }
             }
 
@@ -173,11 +186,16 @@ namespace System.Drawing
 
         public static uint KnownColorToArgb(KnownColor color)
         {
-            Debug.Assert(color > 0 && color <= KnownColor.MenuHighlight);
+            Debug.Assert(color > 0 && color <= KnownColor.RebeccaPurple);
+
+            if (Color.IsKnownColorSystem(color))
+            {
+                return GetSystemColorArgb(color);
+            }
 
-            return Color.IsKnownColorSystem(color)
-                ? GetSystemColorArgb(color)
-                : s_colorTable[(int)color - (int)KnownColor.Transparent];
+            return color < KnownColor.ButtonFace
+                 ? s_colorTable[(int)color - (int)KnownColor.Transparent]
+                 : s_colorTable[(int)color - (int)KnownColor.RebeccaPurple + ((int)KnownColor.YellowGreen - (int)KnownColor.WindowText)];
         }
 
 #if FEATURE_WINDOWS_SYSTEM_COLORS
index 7f40906..f5153c4 100644 (file)
@@ -135,6 +135,7 @@ namespace System.Drawing
         public static System.Drawing.Color PowderBlue { get { throw null; } }
         public static System.Drawing.Color Purple { get { throw null; } }
         public byte R { get { throw null; } }
+        public static System.Drawing.Color RebeccaPurple { get { throw null; } }
         public static System.Drawing.Color Red { get { throw null; } }
         public static System.Drawing.Color RosyBrown { get { throw null; } }
         public static System.Drawing.Color RoyalBlue { get { throw null; } }
@@ -366,6 +367,7 @@ namespace System.Drawing
         GradientInactiveCaption = 172,
         MenuBar = 173,
         MenuHighlight = 174,
+        RebeccaPurple = 175,
     }
     [System.ComponentModel.TypeConverterAttribute("System.Drawing.PointConverter, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
     public partial struct Point : System.IEquatable<System.Drawing.Point>
index 0ea4b58..6b63d79 100644 (file)
@@ -248,6 +248,8 @@ namespace System.Drawing
 
         public static Color Purple => new Color(KnownColor.Purple);
 
+        public static Color RebeccaPurple => new Color(KnownColor.RebeccaPurple);
+
         public static Color Red => new Color(KnownColor.Red);
 
         public static Color RosyBrown => new Color(KnownColor.RosyBrown);
@@ -301,7 +303,6 @@ namespace System.Drawing
         public static Color Yellow => new Color(KnownColor.Yellow);
 
         public static Color YellowGreen => new Color(KnownColor.YellowGreen);
-
         //
         //  end "web" colors
         // -------------------------------------------------------------------
@@ -372,7 +373,7 @@ namespace System.Drawing
         public bool IsSystemColor => IsKnownColor && IsKnownColorSystem((KnownColor)knownColor);
 
         internal static bool IsKnownColorSystem(KnownColor knownColor)
-            => (knownColor <= KnownColor.WindowText) || (knownColor > KnownColor.YellowGreen);
+            => ((knownColor >= KnownColor.ActiveBorder) && (knownColor <= KnownColor.WindowText)) || ((knownColor >= KnownColor.ButtonFace) && (knownColor <= KnownColor.MenuHighlight));
 
         // Used for the [DebuggerDisplay]. Inlining in the attribute is possible, but
         // against best practices as the current project language parses the string with
@@ -464,7 +465,7 @@ namespace System.Drawing
         public static Color FromArgb(int red, int green, int blue) => FromArgb(byte.MaxValue, red, green, blue);
 
         public static Color FromKnownColor(KnownColor color) =>
-            color <= 0 || color > KnownColor.MenuHighlight ? FromName(color.ToString()) : new Color(color);
+            color <= 0 || color > KnownColor.RebeccaPurple ? FromName(color.ToString()) : new Color(color);
 
         public static Color FromName(string name)
         {
index 1992537..cfb2afb 100644 (file)
@@ -7,8 +7,10 @@ namespace System.Drawing
 {
     internal static class KnownColorNames
     {
+        //  Names of all colors (in order of definition in the KnownColor enum).
         private static readonly string[] s_colorNameTable = new string[]
         {
+            // "System" colors, Part 1
             "ActiveBorder",
             "ActiveCaption",
             "ActiveCaptionText",
@@ -35,6 +37,8 @@ namespace System.Drawing
             "Window",
             "WindowFrame",
             "WindowText",
+
+            // "Web" Colors, Part 1
             "Transparent",
             "AliceBlue",
             "AntiqueWhite",
@@ -176,18 +180,23 @@ namespace System.Drawing
             "WhiteSmoke",
             "Yellow",
             "YellowGreen",
+
+            // "System" colors, Part 2
             "ButtonFace",
             "ButtonHighlight",
             "ButtonShadow",
             "GradientActiveCaption",
             "GradientInactiveCaption",
             "MenuBar",
-            "MenuHighlight"
+            "MenuHighlight",
+
+            // "Web" colors, Part 2
+            "RebeccaPurple",
         };
 
         public static string KnownColorToName(KnownColor color)
         {
-            Debug.Assert(color > 0 && color <= KnownColor.MenuHighlight);
+            Debug.Assert(color > 0 && color <= KnownColor.RebeccaPurple);
             return s_colorNameTable[unchecked((int)color) - 1];
         }
     }
index 979d1e4..e4e1df8 100644 (file)
@@ -130,6 +130,7 @@ namespace System.Drawing.Primitives.Tests
                 new object[] {"Plum", 255, 221, 160, 221},
                 new object[] {"PowderBlue", 255, 176, 224, 230},
                 new object[] {"Purple", 255, 128, 0, 128},
+                new object[] {"RebeccaPurple", 255, 102, 51, 153},
                 new object[] {"Red", 255, 255, 0, 0},
                 new object[] {"RosyBrown", 255, 188, 143, 143},
                 new object[] {"RoyalBlue", 255, 65, 105, 225},
@@ -532,7 +533,7 @@ namespace System.Drawing.Primitives.Tests
         [Theory]
         [InlineData((KnownColor)(-1))]
         [InlineData((KnownColor)0)]
-        [InlineData(KnownColor.MenuHighlight + 1)]
+        [InlineData(KnownColor.RebeccaPurple + 1)]
         public void FromOutOfRangeKnownColor(KnownColor known)
         {
             Color color = Color.FromKnownColor(known);
@@ -556,7 +557,7 @@ namespace System.Drawing.Primitives.Tests
         [Theory]
         [InlineData((KnownColor)(-1))]
         [InlineData((KnownColor)0)]
-        [InlineData(KnownColor.MenuHighlight + 1)]
+        [InlineData(KnownColor.RebeccaPurple + 1)]
         public void FromOutOfRangeKnownColorToKnownColor(KnownColor known)
         {
             Color color = Color.FromKnownColor(known);
@@ -588,7 +589,7 @@ namespace System.Drawing.Primitives.Tests
         [Theory]
         [InlineData((KnownColor)(-1))]
         [InlineData((KnownColor)0)]
-        [InlineData(KnownColor.MenuHighlight + 1)]
+        [InlineData(KnownColor.RebeccaPurple + 1)]
         public void IsSystemColorOutOfRangeKnown(KnownColor known)
         {
             Color color = Color.FromKnownColor(known);
@@ -612,7 +613,7 @@ namespace System.Drawing.Primitives.Tests
         [Theory]
         [InlineData((KnownColor)(-1))]
         [InlineData((KnownColor)0)]
-        [InlineData(KnownColor.MenuHighlight + 1)]
+        [InlineData(KnownColor.RebeccaPurple + 1)]
         public void IsKnownColorOutOfRangeKnown(KnownColor known)
         {
             Color color = Color.FromKnownColor(known);
@@ -683,7 +684,8 @@ namespace System.Drawing.Primitives.Tests
                 KnownColor.SeaShell, KnownColor.Sienna, KnownColor.Silver, KnownColor.SkyBlue, KnownColor.SlateBlue,
                 KnownColor.SlateGray, KnownColor.Snow, KnownColor.SpringGreen, KnownColor.SteelBlue, KnownColor.Tan,
                 KnownColor.Teal, KnownColor.Thistle, KnownColor.Tomato, KnownColor.Turquoise, KnownColor.Violet,
-                KnownColor.Wheat, KnownColor.White, KnownColor.WhiteSmoke, KnownColor.Yellow, KnownColor.YellowGreen
+                KnownColor.Wheat, KnownColor.White, KnownColor.WhiteSmoke, KnownColor.Yellow, KnownColor.YellowGreen,
+                KnownColor.RebeccaPurple
             }.Select(kc => new object[] { kc }).ToArray();
 
         [DllImport("user32.dll", SetLastError = true)]