Skip to content

Commit

Permalink
Added Rebecca Purple (dotnet#42785)
Browse files Browse the repository at this point in the history
* Added Rebecca Purple

Added Rebecca Purple color to System.Drawing.Color

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

dotnet#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.

dotnet#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.

dotnet#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.

dotnet#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.

dotnet#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.

dotnet#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

dotnet#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.

dotnet#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.

dotnet#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.

dotnet#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.

dotnet#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.

dotnet#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

dotnet#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

dotnet#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
dotnet#38244

Co-authored-by: Tanner Gooding <[email protected]>
  • Loading branch information
FireCubeStudios and tannergooding authored Dec 9, 2020
1 parent 53c1619 commit d21fe17
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 20 deletions.
12 changes: 7 additions & 5 deletions src/libraries/Common/src/System/Drawing/KnownColor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ enum KnownColor

// 0 - reserved for "not a known color"

// "System" colors
// "System" colors, Part 1
ActiveBorder = 1,
ActiveCaption,
ActiveCaptionText,
Expand Down Expand Up @@ -49,7 +49,7 @@ enum KnownColor
WindowFrame,
WindowText,

// "Web" Colors
// "Web" Colors, Part 1
Transparent,
AliceBlue,
AntiqueWhite,
Expand Down Expand Up @@ -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,
}
}
28 changes: 23 additions & 5 deletions src/libraries/Common/src/System/Drawing/KnownColorTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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);
}
}

Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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; } }
Expand Down Expand Up @@ -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<System.Drawing.Point>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
// -------------------------------------------------------------------
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -35,6 +37,8 @@ internal static class KnownColorNames
"Window",
"WindowFrame",
"WindowText",

// "Web" Colors, Part 1
"Transparent",
"AliceBlue",
"AntiqueWhite",
Expand Down Expand Up @@ -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];
}
}
Expand Down
12 changes: 7 additions & 5 deletions src/libraries/System.Drawing.Primitives/tests/ColorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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)]
Expand Down

0 comments on commit d21fe17

Please sign in to comment.