From d21fe17023e2a03f9b8eec4a5dcf086187b84ca2 Mon Sep 17 00:00:00 2001 From: FireCubeStudios <40955345+FireCubeStudios@users.noreply.github.com> Date: Wed, 9 Dec 2020 12:11:49 +0100 Subject: [PATCH] Added Rebecca Purple (#42785) * 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 --- .../Common/src/System/Drawing/KnownColor.cs | 12 ++++---- .../src/System/Drawing/KnownColorTable.cs | 28 +++++++++++++++---- .../ref/System.Drawing.Primitives.cs | 2 ++ .../src/System/Drawing/Color.cs | 7 +++-- .../src/System/Drawing/KnownColorNames.cs | 13 +++++++-- .../tests/ColorTests.cs | 12 ++++---- 6 files changed, 54 insertions(+), 20 deletions(-) diff --git a/src/libraries/Common/src/System/Drawing/KnownColor.cs b/src/libraries/Common/src/System/Drawing/KnownColor.cs index cf15dbe09405e..a96bc024c6a2a 100644 --- a/src/libraries/Common/src/System/Drawing/KnownColor.cs +++ b/src/libraries/Common/src/System/Drawing/KnownColor.cs @@ -21,7 +21,7 @@ enum KnownColor // 0 - reserved for "not a known color" - // "System" colors + // "System" colors, Part 1 ActiveBorder = 1, ActiveCaption, ActiveCaptionText, @@ -49,7 +49,7 @@ enum KnownColor WindowFrame, WindowText, - // "Web" Colors + // "Web" Colors, Part 1 Transparent, AliceBlue, AntiqueWhite, @@ -192,14 +192,16 @@ enum KnownColor 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, } } diff --git a/src/libraries/Common/src/System/Drawing/KnownColorTable.cs b/src/libraries/Common/src/System/Drawing/KnownColorTable.cs index ca342e5b75a7e..3dc018c968ea5 100644 --- a/src/libraries/Common/src/System/Drawing/KnownColorTable.cs +++ b/src/libraries/Common/src/System/Drawing/KnownColorTable.cs @@ -10,6 +10,8 @@ internal static class KnownColorTable // 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 @@ internal static class KnownColorTable 0xFFF5F5F5, // WhiteSmoke 0xFFFFFF00, // Yellow 0xFF9ACD32, // YellowGreen + + // Second contiguous set. + + 0xFF663399, // RebeccaPurple }; internal static Color ArgbToKnownColor(uint argb) @@ -163,7 +169,14 @@ internal static Color ArgbToKnownColor(uint argb) { 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 @@ internal static Color ArgbToKnownColor(uint argb) 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 diff --git a/src/libraries/System.Drawing.Primitives/ref/System.Drawing.Primitives.cs b/src/libraries/System.Drawing.Primitives/ref/System.Drawing.Primitives.cs index 7f409066648d0..f5153c453ff66 100644 --- a/src/libraries/System.Drawing.Primitives/ref/System.Drawing.Primitives.cs +++ b/src/libraries/System.Drawing.Primitives/ref/System.Drawing.Primitives.cs @@ -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 @@ public enum KnownColor 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 diff --git a/src/libraries/System.Drawing.Primitives/src/System/Drawing/Color.cs b/src/libraries/System.Drawing.Primitives/src/System/Drawing/Color.cs index 0ea4b583bd73c..6b63d7932dc43 100644 --- a/src/libraries/System.Drawing.Primitives/src/System/Drawing/Color.cs +++ b/src/libraries/System.Drawing.Primitives/src/System/Drawing/Color.cs @@ -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 @@ private Color(long value, short state, string? name, KnownColor knownColor) 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 @@ public static Color FromArgb(int alpha, Color baseColor) 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) { diff --git a/src/libraries/System.Drawing.Primitives/src/System/Drawing/KnownColorNames.cs b/src/libraries/System.Drawing.Primitives/src/System/Drawing/KnownColorNames.cs index 19925378680de..cfb2afb256777 100644 --- a/src/libraries/System.Drawing.Primitives/src/System/Drawing/KnownColorNames.cs +++ b/src/libraries/System.Drawing.Primitives/src/System/Drawing/KnownColorNames.cs @@ -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 @@ internal static class KnownColorNames "Window", "WindowFrame", "WindowText", + + // "Web" Colors, Part 1 "Transparent", "AliceBlue", "AntiqueWhite", @@ -176,18 +180,23 @@ internal static class KnownColorNames "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]; } } diff --git a/src/libraries/System.Drawing.Primitives/tests/ColorTests.cs b/src/libraries/System.Drawing.Primitives/tests/ColorTests.cs index 979d1e4d3a4b5..e4e1df8366ce9 100644 --- a/src/libraries/System.Drawing.Primitives/tests/ColorTests.cs +++ b/src/libraries/System.Drawing.Primitives/tests/ColorTests.cs @@ -130,6 +130,7 @@ public class ColorTests 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 @@ public void FromKnownColor(string name, int alpha, int red, int green, int blue) [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 @@ public void ToKnownColorMatchesButIsNotKnown(KnownColor known) [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 @@ public void IsSystemColorFalseOnMatching(KnownColor known) [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 @@ public void IsKnownColorMatchFalse(KnownColor known) [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 @@ public void GetHashCodeForUnknownNamed() 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)]