From cddf48547dd153284b63e5a05eaf5bc10e772b12 Mon Sep 17 00:00:00 2001 From: martinchrzan Date: Tue, 15 Dec 2020 08:46:38 +0100 Subject: [PATCH] Color Picker - show color name (#8553) * Added color name ported from WinUI implementation * Added new words into expect.txt * Change color name foreground * Moved show color name checkbox --- .github/actions/spell-check/expect.txt | 21 + .../ColorPickerProperties.cs | 5 + .../ViewModels/ColorPickerViewModel.cs | 14 + .../Strings/en-us/Resources.resw | 3 + .../Views/ColorPickerPage.xaml | 23 +- .../Behaviors/AppearAnimationBehavior.cs | 4 + .../BoolToInvertedVisibilityConverter.cs | 29 ++ .../ColorPickerUI/Helpers/ColorNameHelper.cs | 264 ++++++++++++ .../colorPicker/ColorPickerUI/MainWindow.xaml | 3 +- .../Properties/Resources.Designer.cs | 378 ++++++++++++++++++ .../ColorPickerUI/Properties/Resources.resx | 168 ++++++++ .../ColorPickerUI/Resources/Styles.xaml | 1 + .../ColorPickerUI/Settings/IUserSettings.cs | 2 + .../ColorPickerUI/Settings/UserSettings.cs | 4 + .../ViewModelContracts/IMainViewModel.cs | 10 + .../ColorPickerUI/ViewModels/MainViewModel.cs | 25 ++ .../ColorPickerUI/Views/MainView.xaml | 60 ++- 17 files changed, 998 insertions(+), 16 deletions(-) create mode 100644 src/modules/colorPicker/ColorPickerUI/Converters/BoolToInvertedVisibilityConverter.cs create mode 100644 src/modules/colorPicker/ColorPickerUI/Helpers/ColorNameHelper.cs diff --git a/.github/actions/spell-check/expect.txt b/.github/actions/spell-check/expect.txt index 3ad73129db..57d678d1da 100644 --- a/.github/actions/spell-check/expect.txt +++ b/.github/actions/spell-check/expect.txt @@ -166,6 +166,7 @@ bitmask bla blockquote blog +BLUEGRAY BLURBEHIND BLURREGION bmi @@ -180,6 +181,7 @@ BPBF bpp Breadcrumb bricelam +BRIGHTGREEN Browsable bsd bsearch @@ -391,11 +393,19 @@ CYSMICON cz Dac dacl +DARKBLUE +DARKGRAY +DARKGREEN +DARKPURPLE +DARKRED +DARKTEAL +DARKYELLOW Dataflows DATAW davidegiacometti Dayof Dbg +DBLEPSILON DBLCLKS DCOM dcomp @@ -898,6 +908,7 @@ IBeam IBind icase iccex +ICEBLUE IClass ico ICollection @@ -1165,6 +1176,12 @@ LEVELID LExit lhs LIBID +LIGHTBLUE +LIGHTGRAY +LIGHTGREEN +LIGHTORANGE +LIGHTTURQUOISE +LIGHTYELLOW lindex linecap Linkmenu @@ -1503,6 +1520,7 @@ OLECHAR oledb oledbcommand oledbconnection +OLIVEGREEN OLogo Onboarding onebranch @@ -1537,6 +1555,7 @@ OWNDC PACL PAINTSTRUCT PAIT +PALEBLUE PALETTEWINDOW Pano paramref @@ -1910,6 +1929,7 @@ Shortcuttool shortdate SHORTPATH should've +showcolorname SHOWDEFAULT SHOWELEVATIONPROMPT SHOWMAXIMIZED @@ -1944,6 +1964,7 @@ SKIPDOTNETINSTALL SKIPOWNPROCESS sku Skype +SKYBLUE SLGP Slideshow sln diff --git a/src/core/Microsoft.PowerToys.Settings.UI.Library/ColorPickerProperties.cs b/src/core/Microsoft.PowerToys.Settings.UI.Library/ColorPickerProperties.cs index dd4f9f90c5..67c7fb696a 100644 --- a/src/core/Microsoft.PowerToys.Settings.UI.Library/ColorPickerProperties.cs +++ b/src/core/Microsoft.PowerToys.Settings.UI.Library/ColorPickerProperties.cs @@ -21,6 +21,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library VisibleColorFormats.Add("HEX", true); VisibleColorFormats.Add("RGB", true); VisibleColorFormats.Add("HSL", true); + ShowColorName = false; ActivationAction = ColorPickerActivationAction.OpenColorPickerAndThenEditor; } @@ -47,6 +48,10 @@ namespace Microsoft.PowerToys.Settings.UI.Library [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2227:Collection properties should be read only", Justification = "Need to change this collection")] public Dictionary VisibleColorFormats { get; set; } + [JsonPropertyName("showcolorname")] + [JsonConverter(typeof(BoolPropertyJsonConverter))] + public bool ShowColorName { get; set; } + public override string ToString() => JsonSerializer.Serialize(this); } diff --git a/src/core/Microsoft.PowerToys.Settings.UI.Library/ViewModels/ColorPickerViewModel.cs b/src/core/Microsoft.PowerToys.Settings.UI.Library/ViewModels/ColorPickerViewModel.cs index dbafa7a4f5..64c4b6627d 100644 --- a/src/core/Microsoft.PowerToys.Settings.UI.Library/ViewModels/ColorPickerViewModel.cs +++ b/src/core/Microsoft.PowerToys.Settings.UI.Library/ViewModels/ColorPickerViewModel.cs @@ -188,6 +188,20 @@ namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels } } + public bool ShowColorName + { + get => _colorPickerSettings.Properties.ShowColorName; + set + { + if (_colorPickerSettings.Properties.ShowColorName != value) + { + _colorPickerSettings.Properties.ShowColorName = value; + OnPropertyChanged(nameof(ShowColorName)); + NotifySettingsChanged(); + } + } + } + public ObservableCollection ColorFormats { get; } = new ObservableCollection(); private void InitializeColorFormats() diff --git a/src/core/Microsoft.PowerToys.Settings.UI/Strings/en-us/Resources.resw b/src/core/Microsoft.PowerToys.Settings.UI/Strings/en-us/Resources.resw index 8f84682255..46cc642a40 100644 --- a/src/core/Microsoft.PowerToys.Settings.UI/Strings/en-us/Resources.resw +++ b/src/core/Microsoft.PowerToys.Settings.UI/Strings/en-us/Resources.resw @@ -870,4 +870,7 @@ Editor color formats (Change the order by dragging) + + Show color name + \ No newline at end of file diff --git a/src/core/Microsoft.PowerToys.Settings.UI/Views/ColorPickerPage.xaml b/src/core/Microsoft.PowerToys.Settings.UI/Views/ColorPickerPage.xaml index 2ba3412133..cee4f0ad86 100644 --- a/src/core/Microsoft.PowerToys.Settings.UI/Views/ColorPickerPage.xaml +++ b/src/core/Microsoft.PowerToys.Settings.UI/Views/ColorPickerPage.xaml @@ -101,16 +101,16 @@ Margin="{StaticResource SmallTopMargin}" IsEnabled="{Binding IsEnabled}" GroupName="ColorPickerActivationAction"> - + - - - + + + - + @@ -126,7 +126,12 @@ Loaded="ColorPicker_ComboBox_Loaded" SelectedValue="{Binding SelectedColorRepresentationValue, Mode=TwoWay}" SelectedValuePath="Key" /> - + + + + + + + + diff --git a/src/modules/colorPicker/ColorPickerUI/Behaviors/AppearAnimationBehavior.cs b/src/modules/colorPicker/ColorPickerUI/Behaviors/AppearAnimationBehavior.cs index ffb12e52ae..cc4168a4ba 100644 --- a/src/modules/colorPicker/ColorPickerUI/Behaviors/AppearAnimationBehavior.cs +++ b/src/modules/colorPicker/ColorPickerUI/Behaviors/AppearAnimationBehavior.cs @@ -45,6 +45,10 @@ namespace ColorPicker.Behaviors }; AssociatedObject.BeginAnimation(UIElement.OpacityProperty, opacityAppear); + + // force re-evaluation of tooltip size + AssociatedObject.SizeToContent = SizeToContent.Manual; + AssociatedObject.SizeToContent = SizeToContent.WidthAndHeight; } private void Hide() diff --git a/src/modules/colorPicker/ColorPickerUI/Converters/BoolToInvertedVisibilityConverter.cs b/src/modules/colorPicker/ColorPickerUI/Converters/BoolToInvertedVisibilityConverter.cs new file mode 100644 index 0000000000..a6e03c0217 --- /dev/null +++ b/src/modules/colorPicker/ColorPickerUI/Converters/BoolToInvertedVisibilityConverter.cs @@ -0,0 +1,29 @@ +// Copyright (c) Microsoft Corporation +// The Microsoft Corporation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Globalization; +using System.Windows; +using System.Windows.Data; + +namespace ColorPicker.Converters +{ + public class BoolToInvertedVisibilityConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + if ((bool)value) + { + return Visibility.Collapsed; + } + + return Visibility.Visible; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } +} diff --git a/src/modules/colorPicker/ColorPickerUI/Helpers/ColorNameHelper.cs b/src/modules/colorPicker/ColorPickerUI/Helpers/ColorNameHelper.cs new file mode 100644 index 0000000000..e83d0e4672 --- /dev/null +++ b/src/modules/colorPicker/ColorPickerUI/Helpers/ColorNameHelper.cs @@ -0,0 +1,264 @@ +// Copyright (c) Microsoft Corporation +// The Microsoft Corporation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Drawing; +using ColorPicker.Properties; + +namespace ColorPicker.Helpers +{ + public static class ColorNameHelper + { + public const float DBLEPSILON = 2.2204460492503131e-16f; + + // For the purposes of naming colors, there are four steps that we go through. + // + // 1. For numerical ease, we convert the HSL values from the range [0, 1] + // to the range [0, 255]. + // + // 2. If luminosity is sufficiently high or low (> 240 or < 20), or if + // saturation is sufficiently low (<= 20), then we declare that we're in the + // achromatic range. In this case, we return either white, black, or three + // different shades of gray (depending on luminosity). + // + // 3. If we do have a chromatic color, the first thing we need to determine + // about it is what the hue limits are for its saturation value - at different + // levels of saturation, we have different hue values that we'll consider the + // boundaries for different classes of named colors. The hue limits for various + // saturation values are as below. + // + // The numbers correspond to the following color buckets, with 0 meaning that + // that bucket does not apply to the given saturation value: + // + // 1 - coral, 2 - red, 3 - orange, 4 - brown, 5 - tan, 6 - gold, 7 - yellow, 8 - olive green (with brown), + // 9 - olive green (with green) 10 - lime green, 11 - green - 12 - bright green 13 - teal, 14 - aqua, + // 15 - turquoise, 16 - pale blue, 17 - blue, 18 - blue-gray, 19 - indigo, 20 - purple, 21 - pink, 22 - brown, 23 - red + private static int[] hueLimitsForSatLevel1 = // Sat: 20-75 + { + // 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23 + 8, 0, 0, 44, 0, 0, 0, 63, 0, 0, 122, 0, 134, 0, 0, 0, 0, 166, 176, 241, 0, 256, 0, + }; + + private static int[] hueLimitsForSatLevel2 = // Sat: 75-115 + { + // 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23 + 0, 10, 0, 32, 46, 0, 0, 0, 61, 0, 106, 0, 136, 144, 0, 0, 0, 158, 166, 241, 0, 0, 256, + }; + + private static int[] hueLimitsForSatLevel3 = // Sat: 115-150 + { + // 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23 + 0, 8, 0, 0, 39, 46, 0, 0, 0, 71, 120, 0, 131, 144, 0, 0, 163, 0, 177, 211, 249, 0, 256, + }; + + private static int[] hueLimitsForSatLevel4 = // Sat: 150-240 + { + // 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23 + 0, 11, 26, 0, 0, 38, 45, 0, 0, 56, 100, 121, 129, 0, 140, 0, 180, 0, 0, 224, 241, 0, 256, + }; + + private static int[] hueLimitsForSatLevel5 = // Sat: 240-255 + { + // 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23 + 0, 13, 27, 0, 0, 36, 45, 0, 0, 59, 118, 0, 127, 136, 142, 0, 185, 0, 0, 216, 239, 0, 256, + }; + + // 4. Once we have the color bucket, next we have three sub-buckets that we need to worry about, + // corresponding to three different levels of luminosity. For example, if we're in the "blue" bucket, + // that might correspond to light blue, blue, or dark blue, depending on luminosity. + // For each bucket, the luminosity cutoffs for the purposes of discerning between light, mid, and dark colors + // are different, so we define luminosity limits for low and high luminosity for each bucket, as follows: + private static int[] lumLimitsForHueIndexLow = + { + // 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23 + 130, 100, 115, 100, 100, 100, 110, 75, 100, 90, 100, 100, 100, 100, 80, 100, 100, 100, 100, 100, 100, 100, 100, + }; + + private static int[] lumLimitsForHueIndexHigh = + { + // 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23 + 170, 170, 170, 155, 170, 170, 170, 170, 170, 115, 170, 170, 170, 170, 170, 170, 170, 170, 150, 150, 170, 140, 165, + }; + + // 5. Finally, once we have a luminosity sub-bucket in the saturation color bucket, we have everything we need + // to retrieve a name. For each of the 23 buckets, we have names associated with light, mid, and dark variations + // of that color, which are defined as follows: + private static string[] colorNamesLight = + { + Resources.TEXT_COLOR_CORAL, + Resources.TEXT_COLOR_ROSE, + Resources.TEXT_COLOR_LIGHTORANGE, + Resources.TEXT_COLOR_TAN, + Resources.TEXT_COLOR_TAN, + Resources.TEXT_COLOR_LIGHTYELLOW, + Resources.TEXT_COLOR_LIGHTYELLOW, + Resources.TEXT_COLOR_TAN, + Resources.TEXT_COLOR_LIGHTGREEN, + Resources.TEXT_COLOR_LIME, + Resources.TEXT_COLOR_LIGHTGREEN, + Resources.TEXT_COLOR_LIGHTGREEN, + Resources.TEXT_COLOR_AQUA, + Resources.TEXT_COLOR_SKYBLUE, + Resources.TEXT_COLOR_LIGHTTURQUOISE, + Resources.TEXT_COLOR_PALEBLUE, + Resources.TEXT_COLOR_LIGHTBLUE, + Resources.TEXT_COLOR_ICEBLUE, + Resources.TEXT_COLOR_PERIWINKLE, + Resources.TEXT_COLOR_LAVENDER, + Resources.TEXT_COLOR_PINK, + Resources.TEXT_COLOR_TAN, + Resources.TEXT_COLOR_ROSE, + }; + + private static string[] colorNamesMid = + { + Resources.TEXT_COLOR_CORAL, + Resources.TEXT_COLOR_RED, + Resources.TEXT_COLOR_ORANGE, + Resources.TEXT_COLOR_BROWN, + Resources.TEXT_COLOR_TAN, + Resources.TEXT_COLOR_GOLD, + Resources.TEXT_COLOR_YELLOW, + Resources.TEXT_COLOR_OLIVEGREEN, + Resources.TEXT_COLOR_OLIVEGREEN, + Resources.TEXT_COLOR_GREEN, + Resources.TEXT_COLOR_GREEN, + Resources.TEXT_COLOR_BRIGHTGREEN, + Resources.TEXT_COLOR_TEAL, + Resources.TEXT_COLOR_AQUA, + Resources.TEXT_COLOR_TURQUOISE, + Resources.TEXT_COLOR_PALEBLUE, + Resources.TEXT_COLOR_BLUE, + Resources.TEXT_COLOR_BLUEGRAY, + Resources.TEXT_COLOR_INDIGO, + Resources.TEXT_COLOR_PURPLE, + Resources.TEXT_COLOR_PINK, + Resources.TEXT_COLOR_BROWN, + Resources.TEXT_COLOR_RED, + }; + + private static string[] colorNamesDark = + { + Resources.TEXT_COLOR_BROWN, + Resources.TEXT_COLOR_DARKRED, + Resources.TEXT_COLOR_BROWN, + Resources.TEXT_COLOR_BROWN, + Resources.TEXT_COLOR_BROWN, + Resources.TEXT_COLOR_DARKYELLOW, + Resources.TEXT_COLOR_DARKYELLOW, + Resources.TEXT_COLOR_BROWN, + Resources.TEXT_COLOR_DARKGREEN, + Resources.TEXT_COLOR_DARKGREEN, + Resources.TEXT_COLOR_DARKGREEN, + Resources.TEXT_COLOR_DARKGREEN, + Resources.TEXT_COLOR_DARKTEAL, + Resources.TEXT_COLOR_DARKTEAL, + Resources.TEXT_COLOR_DARKTEAL, + Resources.TEXT_COLOR_DARKBLUE, + Resources.TEXT_COLOR_DARKBLUE, + Resources.TEXT_COLOR_BLUEGRAY, + Resources.TEXT_COLOR_INDIGO, + Resources.TEXT_COLOR_DARKPURPLE, + Resources.TEXT_COLOR_PLUM, + Resources.TEXT_COLOR_BROWN, + Resources.TEXT_COLOR_DARKRED, + }; + + public static string GetColorName(Color color) + { + var (hue, sat, lum) = ColorHelper.ConvertToHSLColor(color); + + hue = (hue == 0 ? 0 : hue / 360) * 255; // this implementation is using normalization to 0-255 instead of 0-360° + sat = sat * 255; + lum = lum * 255; + + // First, if we're in the achromatic state, return the appropriate achromatic color name. + if (lum > 240) + { + return Resources.TEXT_COLOR_WHITE; + } + else if (lum < 20) + { + return Resources.TEXT_COLOR_BLACK; + } + + if (sat <= 20) + { + if (lum > 170) + { + return Resources.TEXT_COLOR_LIGHTGRAY; + } + else if (lum > 100) + { + return Resources.TEXT_COLOR_GRAY; + } + else + { + return Resources.TEXT_COLOR_DARKGRAY; + } + } + + // If we have a chromatic color, we need to first get the hue limits for the saturation value. + int[] pHueLimits; + if (sat > 20 && sat <= 75) + { + pHueLimits = hueLimitsForSatLevel1; + } + else if (sat > 75 && sat <= 115) + { + pHueLimits = hueLimitsForSatLevel2; + } + else if (sat > 115 && sat <= 150) + { + pHueLimits = hueLimitsForSatLevel3; + } + else if (sat > 150 && sat <= 240) + { + pHueLimits = hueLimitsForSatLevel4; + } + else + { + pHueLimits = hueLimitsForSatLevel5; + } + + // Now that we have that, we can get the color index, which represents which + // of the 23 buckets we're located in. + int colorIndex = -1; + for (int i = 0; i < colorNamesMid.Length; ++i) + { + if (hue < pHueLimits[i]) + { + colorIndex = i; + break; + } + } + + // Assuming we got a color index (and we always should get one), then next we need to + // figure out which luminosity sub-bucket we're located in. + // Once we have that, we'll return the color name from the appropriate array. + if (colorIndex != -1) + { + if (lum > lumLimitsForHueIndexHigh[colorIndex]) + { + return colorNamesLight[colorIndex]; + } + else if (lum < lumLimitsForHueIndexLow[colorIndex]) + { + return colorNamesDark[colorIndex]; + } + else + { + return colorNamesMid[colorIndex]; + } + } + + return string.Empty; + } + + public static bool AreClose(double a, double b) + { + return (float)Math.Abs(a - b) <= DBLEPSILON * (float)Math.Abs(a); + } + } +} diff --git a/src/modules/colorPicker/ColorPickerUI/MainWindow.xaml b/src/modules/colorPicker/ColorPickerUI/MainWindow.xaml index 383a0532ef..4dafd761dc 100644 --- a/src/modules/colorPicker/ColorPickerUI/MainWindow.xaml +++ b/src/modules/colorPicker/ColorPickerUI/MainWindow.xaml @@ -6,14 +6,13 @@ mc:Ignorable="d" xmlns:e="http://schemas.microsoft.com/xaml/behaviors" xmlns:behaviors="clr-namespace:ColorPicker.Behaviors" - Height="64" WindowStyle="None" Opacity="0.01" ShowInTaskbar="False" ResizeMode="NoResize" Topmost="True" Background="Transparent" - SizeToContent="Width" + SizeToContent="WidthAndHeight" AllowsTransparency="True"> diff --git a/src/modules/colorPicker/ColorPickerUI/Properties/Resources.Designer.cs b/src/modules/colorPicker/ColorPickerUI/Properties/Resources.Designer.cs index cb2b1a9023..31a6a07565 100644 --- a/src/modules/colorPicker/ColorPickerUI/Properties/Resources.Designer.cs +++ b/src/modules/colorPicker/ColorPickerUI/Properties/Resources.Designer.cs @@ -222,6 +222,384 @@ namespace ColorPicker.Properties { } } + /// + /// Looks up a localized string similar to Aqua. + /// + public static string TEXT_COLOR_AQUA { + get { + return ResourceManager.GetString("TEXT_COLOR_AQUA", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Black. + /// + public static string TEXT_COLOR_BLACK { + get { + return ResourceManager.GetString("TEXT_COLOR_BLACK", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Blue. + /// + public static string TEXT_COLOR_BLUE { + get { + return ResourceManager.GetString("TEXT_COLOR_BLUE", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Blue gray. + /// + public static string TEXT_COLOR_BLUEGRAY { + get { + return ResourceManager.GetString("TEXT_COLOR_BLUEGRAY", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Bright green. + /// + public static string TEXT_COLOR_BRIGHTGREEN { + get { + return ResourceManager.GetString("TEXT_COLOR_BRIGHTGREEN", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Brown. + /// + public static string TEXT_COLOR_BROWN { + get { + return ResourceManager.GetString("TEXT_COLOR_BROWN", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Coral. + /// + public static string TEXT_COLOR_CORAL { + get { + return ResourceManager.GetString("TEXT_COLOR_CORAL", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Dark blue. + /// + public static string TEXT_COLOR_DARKBLUE { + get { + return ResourceManager.GetString("TEXT_COLOR_DARKBLUE", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Dark gray. + /// + public static string TEXT_COLOR_DARKGRAY { + get { + return ResourceManager.GetString("TEXT_COLOR_DARKGRAY", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Dark green. + /// + public static string TEXT_COLOR_DARKGREEN { + get { + return ResourceManager.GetString("TEXT_COLOR_DARKGREEN", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Dark purple. + /// + public static string TEXT_COLOR_DARKPURPLE { + get { + return ResourceManager.GetString("TEXT_COLOR_DARKPURPLE", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Dark red. + /// + public static string TEXT_COLOR_DARKRED { + get { + return ResourceManager.GetString("TEXT_COLOR_DARKRED", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Dark teal. + /// + public static string TEXT_COLOR_DARKTEAL { + get { + return ResourceManager.GetString("TEXT_COLOR_DARKTEAL", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Dark yellow. + /// + public static string TEXT_COLOR_DARKYELLOW { + get { + return ResourceManager.GetString("TEXT_COLOR_DARKYELLOW", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Gold. + /// + public static string TEXT_COLOR_GOLD { + get { + return ResourceManager.GetString("TEXT_COLOR_GOLD", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Gray. + /// + public static string TEXT_COLOR_GRAY { + get { + return ResourceManager.GetString("TEXT_COLOR_GRAY", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Green. + /// + public static string TEXT_COLOR_GREEN { + get { + return ResourceManager.GetString("TEXT_COLOR_GREEN", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Ice blue. + /// + public static string TEXT_COLOR_ICEBLUE { + get { + return ResourceManager.GetString("TEXT_COLOR_ICEBLUE", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Indigo. + /// + public static string TEXT_COLOR_INDIGO { + get { + return ResourceManager.GetString("TEXT_COLOR_INDIGO", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Lavender. + /// + public static string TEXT_COLOR_LAVENDER { + get { + return ResourceManager.GetString("TEXT_COLOR_LAVENDER", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Light blue. + /// + public static string TEXT_COLOR_LIGHTBLUE { + get { + return ResourceManager.GetString("TEXT_COLOR_LIGHTBLUE", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Light gray. + /// + public static string TEXT_COLOR_LIGHTGRAY { + get { + return ResourceManager.GetString("TEXT_COLOR_LIGHTGRAY", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Light green. + /// + public static string TEXT_COLOR_LIGHTGREEN { + get { + return ResourceManager.GetString("TEXT_COLOR_LIGHTGREEN", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Light orange. + /// + public static string TEXT_COLOR_LIGHTORANGE { + get { + return ResourceManager.GetString("TEXT_COLOR_LIGHTORANGE", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Light turquoise. + /// + public static string TEXT_COLOR_LIGHTTURQUOISE { + get { + return ResourceManager.GetString("TEXT_COLOR_LIGHTTURQUOISE", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Light yellow. + /// + public static string TEXT_COLOR_LIGHTYELLOW { + get { + return ResourceManager.GetString("TEXT_COLOR_LIGHTYELLOW", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Lime. + /// + public static string TEXT_COLOR_LIME { + get { + return ResourceManager.GetString("TEXT_COLOR_LIME", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Olive green. + /// + public static string TEXT_COLOR_OLIVEGREEN { + get { + return ResourceManager.GetString("TEXT_COLOR_OLIVEGREEN", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Orange. + /// + public static string TEXT_COLOR_ORANGE { + get { + return ResourceManager.GetString("TEXT_COLOR_ORANGE", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Pale blue. + /// + public static string TEXT_COLOR_PALEBLUE { + get { + return ResourceManager.GetString("TEXT_COLOR_PALEBLUE", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Periwinkle. + /// + public static string TEXT_COLOR_PERIWINKLE { + get { + return ResourceManager.GetString("TEXT_COLOR_PERIWINKLE", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Pink. + /// + public static string TEXT_COLOR_PINK { + get { + return ResourceManager.GetString("TEXT_COLOR_PINK", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Plum. + /// + public static string TEXT_COLOR_PLUM { + get { + return ResourceManager.GetString("TEXT_COLOR_PLUM", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Purple. + /// + public static string TEXT_COLOR_PURPLE { + get { + return ResourceManager.GetString("TEXT_COLOR_PURPLE", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Red. + /// + public static string TEXT_COLOR_RED { + get { + return ResourceManager.GetString("TEXT_COLOR_RED", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Rose. + /// + public static string TEXT_COLOR_ROSE { + get { + return ResourceManager.GetString("TEXT_COLOR_ROSE", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Sky blue. + /// + public static string TEXT_COLOR_SKYBLUE { + get { + return ResourceManager.GetString("TEXT_COLOR_SKYBLUE", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Tan. + /// + public static string TEXT_COLOR_TAN { + get { + return ResourceManager.GetString("TEXT_COLOR_TAN", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Teal. + /// + public static string TEXT_COLOR_TEAL { + get { + return ResourceManager.GetString("TEXT_COLOR_TEAL", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Turquoise. + /// + public static string TEXT_COLOR_TURQUOISE { + get { + return ResourceManager.GetString("TEXT_COLOR_TURQUOISE", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to White. + /// + public static string TEXT_COLOR_WHITE { + get { + return ResourceManager.GetString("TEXT_COLOR_WHITE", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Yellow. + /// + public static string TEXT_COLOR_YELLOW { + get { + return ResourceManager.GetString("TEXT_COLOR_YELLOW", resourceCulture); + } + } + /// /// Looks up a localized string similar to Value slider. /// diff --git a/src/modules/colorPicker/ColorPickerUI/Properties/Resources.resx b/src/modules/colorPicker/ColorPickerUI/Properties/Resources.resx index 61ee52abc2..a0c1b6b156 100644 --- a/src/modules/colorPicker/ColorPickerUI/Properties/Resources.resx +++ b/src/modules/colorPicker/ColorPickerUI/Properties/Resources.resx @@ -193,4 +193,172 @@ Value slider Tool tip that appears when hovering over a slider that represents the color value (from HSV) + + White + White color + + + Black + Black color + + + Light gray + Light gray color + + + Gray + Gray color + + + Dark gray + Dark gray color + + + Coral + Coral color + + + Rose + Rose color + + + Light orange + Light orange color + + + Tan + Tan color + + + Light yellow + Light yellow color + + + Light green + Light green color + + + Lime + Lime color + + + Aqua + Aqua color + + + Sky blue + Sky blue color + + + Light turquoise + Light turquoise color + + + Pale blue + Pale blue color + + + Light blue + Light blue color + + + Ice blue + Ice blue color + + + Periwinkle + Periwinkle color + + + Lavender + Lavender color + + + Pink + Pink color + + + Red + Red color + + + Orange + Orange color + + + Brown + Brown color + + + Gold + Gold color + + + Yellow + Yellow color + + + Olive green + Olive green color + + + Green + Green color + + + Bright green + Rose color + + + Teal + Teal color + + + Turquoise + Turquoise color + + + Blue + Blue color + + + Blue gray + Blue gray color + + + Indigo + Indigo color + + + Purple + Purple color + + + Dark red + Dark red color + + + Dark yellow + Dark yellow color + + + Dark green + Dark green color + + + Dark teal + Dark teal color + + + Dark blue + Dark blue color + + + Dark purple + Dark purple color + + + Plum + Plum color + \ No newline at end of file diff --git a/src/modules/colorPicker/ColorPickerUI/Resources/Styles.xaml b/src/modules/colorPicker/ColorPickerUI/Resources/Styles.xaml index e0949972da..89480b8e0c 100644 --- a/src/modules/colorPicker/ColorPickerUI/Resources/Styles.xaml +++ b/src/modules/colorPicker/ColorPickerUI/Resources/Styles.xaml @@ -4,6 +4,7 @@ xmlns:converters="clr-namespace:ColorPicker.Converters"> + diff --git a/src/modules/colorPicker/ColorPickerUI/Settings/IUserSettings.cs b/src/modules/colorPicker/ColorPickerUI/Settings/IUserSettings.cs index d2a2e92332..11d5db1ed2 100644 --- a/src/modules/colorPicker/ColorPickerUI/Settings/IUserSettings.cs +++ b/src/modules/colorPicker/ColorPickerUI/Settings/IUserSettings.cs @@ -23,5 +23,7 @@ namespace ColorPicker.Settings SettingItem ColorHistoryLimit { get; } ObservableCollection VisibleColorFormats { get; } + + SettingItem ShowColorName { get; } } } diff --git a/src/modules/colorPicker/ColorPickerUI/Settings/UserSettings.cs b/src/modules/colorPicker/ColorPickerUI/Settings/UserSettings.cs index 419817c947..c6adb3735d 100644 --- a/src/modules/colorPicker/ColorPickerUI/Settings/UserSettings.cs +++ b/src/modules/colorPicker/ColorPickerUI/Settings/UserSettings.cs @@ -42,6 +42,7 @@ namespace ColorPicker.Settings ActivationAction = new SettingItem(ColorPickerActivationAction.OpenEditor); ColorHistoryLimit = new SettingItem(20); ColorHistory.CollectionChanged += ColorHistory_CollectionChanged; + ShowColorName = new SettingItem(false); LoadSettingsFromJson(); @@ -73,6 +74,8 @@ namespace ColorPicker.Settings public ObservableCollection VisibleColorFormats { get; private set; } = new ObservableCollection(); + public SettingItem ShowColorName { get; } + private void LoadSettingsFromJson() { // TODO this IO call should by Async, update GetFileWatcher helper to support async @@ -103,6 +106,7 @@ namespace ColorPicker.Settings CopiedColorRepresentation.Value = settings.Properties.CopiedColorRepresentation; ActivationAction.Value = settings.Properties.ActivationAction; ColorHistoryLimit.Value = settings.Properties.ColorHistoryLimit; + ShowColorName.Value = settings.Properties.ShowColorName; if (settings.Properties.ColorHistory == null) { diff --git a/src/modules/colorPicker/ColorPickerUI/ViewModelContracts/IMainViewModel.cs b/src/modules/colorPicker/ColorPickerUI/ViewModelContracts/IMainViewModel.cs index dd2b83f787..59c5fd8d25 100644 --- a/src/modules/colorPicker/ColorPickerUI/ViewModelContracts/IMainViewModel.cs +++ b/src/modules/colorPicker/ColorPickerUI/ViewModelContracts/IMainViewModel.cs @@ -17,5 +17,15 @@ namespace ColorPicker.ViewModelContracts /// Gets the current selected color as a /// Brush ColorBrush { get; } + + /// + /// Gets the color name + /// + string ColorName { get; } + + /// + /// Gets a value indicating whether gets the show color name + /// + bool ShowColorName { get; } } } diff --git a/src/modules/colorPicker/ColorPickerUI/ViewModels/MainViewModel.cs b/src/modules/colorPicker/ColorPickerUI/ViewModels/MainViewModel.cs index 06f2c72320..1bc807bf64 100644 --- a/src/modules/colorPicker/ColorPickerUI/ViewModels/MainViewModel.cs +++ b/src/modules/colorPicker/ColorPickerUI/ViewModels/MainViewModel.cs @@ -37,6 +37,11 @@ namespace ColorPicker.ViewModels /// private Brush _colorBrush; + /// + /// Backing field for + /// + private string _colorName; + [ImportingConstructor] public MainViewModel( IMouseInfoProvider mouseInfoProvider, @@ -56,6 +61,7 @@ namespace ColorPicker.ViewModels mouseInfoProvider.OnMouseWheel += MouseInfoProvider_OnMouseWheel; } + _userSettings.ShowColorName.PropertyChanged += (s, e) => { OnPropertyChanged(nameof(ShowColorName)); }; keyboardMonitor?.Start(); } @@ -85,6 +91,21 @@ namespace ColorPicker.ViewModels } } + public string ColorName + { + get => _colorName; + private set + { + _colorName = value; + OnPropertyChanged(); + } + } + + public bool ShowColorName + { + get => _userSettings.ShowColorName.Value; + } + /// /// Tell the color picker that the color on the position of the mouse cursor have changed /// @@ -94,6 +115,10 @@ namespace ColorPicker.ViewModels { ColorBrush = new SolidColorBrush(Color.FromArgb(color.A, color.R, color.G, color.B)); ColorText = ColorRepresentationHelper.GetStringRepresentation(color, _userSettings.CopiedColorRepresentation.Value); + if (_userSettings.ShowColorName.Value) + { + ColorName = ColorNameHelper.GetColorName(color); + } } /// diff --git a/src/modules/colorPicker/ColorPickerUI/Views/MainView.xaml b/src/modules/colorPicker/ColorPickerUI/Views/MainView.xaml index 27ec3109e4..a310c4d698 100644 --- a/src/modules/colorPicker/ColorPickerUI/Views/MainView.xaml +++ b/src/modules/colorPicker/ColorPickerUI/Views/MainView.xaml @@ -22,26 +22,70 @@ ShadowDepth="1" /> --> - - - - - + + + + + + + - - + + + + + + + + + + + + + + + + + + +