From 57dd0ce113b97b1239726c0ca11d30b545af1c37 Mon Sep 17 00:00:00 2001 From: "Sekan, Tobias" Date: Fri, 23 Oct 2020 14:32:57 +0200 Subject: [PATCH 01/15] Add Ncol, HWB, HSB color format + cleanup --- .../ColorPickerProperties.cs | 29 +--- .../ColorPickerSettings.cs | 8 +- .../Enumerations/ColorRepresentationType.cs | 54 +++++++ .../ViewModels/ColorPickerViewModel.cs | 1 + .../Views/ColorPickerPage.xaml | 4 + .../ColorPickerUI/Helpers/ColorHelper.cs | 150 +++++++++++++----- .../Helpers/ColorRepresentationHelper.cs | 103 +++++++++--- .../ColorPickerUI/Settings/IUserSettings.cs | 2 +- .../ColorPickerUI/Settings/UserSettings.cs | 1 + .../Helpers/ColorRepresentationHelperTest.cs | 6 +- 10 files changed, 260 insertions(+), 98 deletions(-) create mode 100644 src/core/Microsoft.PowerToys.Settings.UI.Library/Enumerations/ColorRepresentationType.cs diff --git a/src/core/Microsoft.PowerToys.Settings.UI.Library/ColorPickerProperties.cs b/src/core/Microsoft.PowerToys.Settings.UI.Library/ColorPickerProperties.cs index 7f65789992..f5305f5960 100644 --- a/src/core/Microsoft.PowerToys.Settings.UI.Library/ColorPickerProperties.cs +++ b/src/core/Microsoft.PowerToys.Settings.UI.Library/ColorPickerProperties.cs @@ -4,37 +4,10 @@ using System.Text.Json; using System.Text.Json.Serialization; +using Microsoft.PowerToys.Settings.UI.Library.Enumerations; namespace Microsoft.PowerToys.Settings.UI.Library { - public enum ColorRepresentationType - { - /// - /// Color presentation as hexadecimal color value without the alpha-value (e.g. #0055FF) - /// - HEX = 0, - - /// - /// Color presentation as RGB color value (red[0..255], green[0..255], blue[0..255]) - /// - RGB = 1, - - /// - /// Color presentation as CMYK color value (cyan[0%..100%], magenta[0%..100%], yellow[0%..100%], black key[0%..100%]) - /// - CMYK = 2, - - /// - /// Color presentation as HSL color value (hue[0°..360°], saturation[0..100%], lightness[0%..100%]) - /// - HSL = 3, - - /// - /// Color presentation as HSV color value (hue[0°..360°], saturation[0%..100%], value[0%..100%]) - /// - HSV = 4, - } - public class ColorPickerProperties { public ColorPickerProperties() diff --git a/src/core/Microsoft.PowerToys.Settings.UI.Library/ColorPickerSettings.cs b/src/core/Microsoft.PowerToys.Settings.UI.Library/ColorPickerSettings.cs index 72ebb295c9..a27a1076a3 100644 --- a/src/core/Microsoft.PowerToys.Settings.UI.Library/ColorPickerSettings.cs +++ b/src/core/Microsoft.PowerToys.Settings.UI.Library/ColorPickerSettings.cs @@ -40,14 +40,10 @@ namespace Microsoft.PowerToys.Settings.UI.Library } public string GetModuleName() - { - return Name; - } + => Name; // This can be utilized in the future if the settings.json file is to be modified/deleted. public bool UpgradeSettingsConfiguration() - { - return false; - } + => false; } } diff --git a/src/core/Microsoft.PowerToys.Settings.UI.Library/Enumerations/ColorRepresentationType.cs b/src/core/Microsoft.PowerToys.Settings.UI.Library/Enumerations/ColorRepresentationType.cs new file mode 100644 index 0000000000..abcc78f775 --- /dev/null +++ b/src/core/Microsoft.PowerToys.Settings.UI.Library/Enumerations/ColorRepresentationType.cs @@ -0,0 +1,54 @@ +// 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. + +namespace Microsoft.PowerToys.Settings.UI.Library.Enumerations +{ + public enum ColorRepresentationType + { + /// + /// Color presentation as hexadecimal color value without the alpha-value (e.g. #0055FF) + /// + HEX = 0, + + /// + /// Color presentation as RGB color value (red[0..255], green[0..255], blue[0..255]) + /// + RGB = 1, + + /// + /// Color presentation as CMYK color value (cyan[0%..100%], magenta[0%..100%], yellow[0%..100%], black key[0%..100%]) + /// + CMYK = 2, + + /// + /// Color presentation as HSL color value (hue[0°..360°], saturation[0..100%], lightness[0%..100%]) + /// + HSL = 3, + + /// + /// Color presentation as HSV color value (hue[0°..360°], saturation[0%..100%], value[0%..100%]) + /// + HSV = 4, + + /// + /// Color presentation as HSB color value (hue[0°..360°], saturation[0%..100%], brightness[0%..100%]) + /// + HSB = 5, + + /// + /// Color presentation as HSI color value (hue[0°..360°], saturation[0%..100%], value[0%..100%]) + /// + HSI = 6, + + /// + /// Color presentation as HWB color value (hue[0°..360°], whiteness[0%..100%], blackness[0%..100%]) + /// + HWB = 7, + + /// + /// Color presentation as natural color (hue, saturation[0%..100%], value[0%..100%]) + /// + NCol = 8, + } +} 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 ff4f37f612..520427929e 100644 --- a/src/core/Microsoft.PowerToys.Settings.UI.Library/ViewModels/ColorPickerViewModel.cs +++ b/src/core/Microsoft.PowerToys.Settings.UI.Library/ViewModels/ColorPickerViewModel.cs @@ -5,6 +5,7 @@ using System; using System.Globalization; using System.Text.Json; +using Microsoft.PowerToys.Settings.UI.Library.Enumerations; using Microsoft.PowerToys.Settings.UI.Library.Helpers; using Microsoft.PowerToys.Settings.UI.Library.Interfaces; diff --git a/src/core/Microsoft.PowerToys.Settings.UI/Views/ColorPickerPage.xaml b/src/core/Microsoft.PowerToys.Settings.UI/Views/ColorPickerPage.xaml index 7fb9e40c5d..dac5f414d4 100644 --- a/src/core/Microsoft.PowerToys.Settings.UI/Views/ColorPickerPage.xaml +++ b/src/core/Microsoft.PowerToys.Settings.UI/Views/ColorPickerPage.xaml @@ -74,6 +74,10 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -26,113 +115,16 @@ - - + + - - - + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/core/Microsoft.PowerToys.Settings.UI/Views/ColorPickerPage.xaml.cs b/src/core/Microsoft.PowerToys.Settings.UI/Views/ColorPickerPage.xaml.cs index 6d994eedc2..8c9a3cd80e 100644 --- a/src/core/Microsoft.PowerToys.Settings.UI/Views/ColorPickerPage.xaml.cs +++ b/src/core/Microsoft.PowerToys.Settings.UI/Views/ColorPickerPage.xaml.cs @@ -21,5 +21,33 @@ namespace Microsoft.PowerToys.Settings.UI.Views DataContext = ViewModel; InitializeComponent(); } + + /// + /// Event is called when the is completly loaded, inclusive the ItemSource + /// + /// The sender of this event + /// The arguments of this event + private void ColorPicker_ComboBox_Loaded(object sender, Windows.UI.Xaml.RoutedEventArgs e) + { + /** + * UWP hack + * because UWP load the binded ItemSource of the ComboBox asyncronous, + * so after InitializeComponent() the ItemSource is still empty and can't automatically select a entry. + * Selection via SelectedItem and SelectedValue is still not working too + */ + var index = 0; + + foreach (var item in ViewModel.SelectableColorRepresentations) + { + if (item.Key == ViewModel.SelectedColorRepresentationValue) + { + break; + } + + index++; + } + + ColorPicker_ComboBox.SelectedIndex = index; + } } } From 36f55ae80cf554e11dfee2d754748416c0c1e14c Mon Sep 17 00:00:00 2001 From: "Sekan, Tobias" Date: Tue, 3 Nov 2020 21:36:11 +0100 Subject: [PATCH 10/15] Address feedback --- .../ViewModels/ColorPickerViewModel.cs | 50 ++++++++----------- 1 file changed, 21 insertions(+), 29 deletions(-) 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 cbff24aba7..9d6dce41d6 100644 --- a/src/core/Microsoft.PowerToys.Settings.UI.Library/ViewModels/ColorPickerViewModel.cs +++ b/src/core/Microsoft.PowerToys.Settings.UI.Library/ViewModels/ColorPickerViewModel.cs @@ -73,19 +73,17 @@ namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels get => _isEnabled; set { - if (_isEnabled == value) + if (_isEnabled != value) { - return; + _isEnabled = value; + OnPropertyChanged(nameof(IsEnabled)); + + // Set the status of ColorPicker in the general settings + GeneralSettingsConfig.Enabled.ColorPicker = value; + var outgoing = new OutGoingGeneralSettings(GeneralSettingsConfig); + + SendConfigMSG(outgoing.ToString()); } - - _isEnabled = value; - OnPropertyChanged(nameof(IsEnabled)); - - // Set the status of ColorPicker in the general settings - GeneralSettingsConfig.Enabled.ColorPicker = value; - var outgoing = new OutGoingGeneralSettings(GeneralSettingsConfig); - - SendConfigMSG(outgoing.ToString()); } } @@ -94,14 +92,12 @@ namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels get => _colorPickerSettings.Properties.ChangeCursor; set { - if (_colorPickerSettings.Properties.ChangeCursor == value) + if (_colorPickerSettings.Properties.ChangeCursor != value) { - return; + _colorPickerSettings.Properties.ChangeCursor = value; + OnPropertyChanged(nameof(ChangeCursor)); + NotifySettingsChanged(); } - - _colorPickerSettings.Properties.ChangeCursor = value; - OnPropertyChanged(nameof(ChangeCursor)); - NotifySettingsChanged(); } } @@ -110,14 +106,12 @@ namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels get => _colorPickerSettings.Properties.ActivationShortcut; set { - if (_colorPickerSettings.Properties.ActivationShortcut == value) + if (_colorPickerSettings.Properties.ActivationShortcut != value) { - return; + _colorPickerSettings.Properties.ActivationShortcut = value; + OnPropertyChanged(nameof(ActivationShortcut)); + NotifySettingsChanged(); } - - _colorPickerSettings.Properties.ActivationShortcut = value; - OnPropertyChanged(nameof(ActivationShortcut)); - NotifySettingsChanged(); } } @@ -126,14 +120,12 @@ namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels get => _colorPickerSettings.Properties.CopiedColorRepresentation; set { - if (_colorPickerSettings.Properties.CopiedColorRepresentation == value) + if (_colorPickerSettings.Properties.CopiedColorRepresentation != value) { - return; + _colorPickerSettings.Properties.CopiedColorRepresentation = value; + OnPropertyChanged(nameof(SelectedColorRepresentationValue)); + NotifySettingsChanged(); } - - _colorPickerSettings.Properties.CopiedColorRepresentation = value; - OnPropertyChanged(nameof(SelectedColorRepresentationValue)); - NotifySettingsChanged(); } } From d192e6feb6a7c8920f384cb77fddc41a6b30c67c Mon Sep 17 00:00:00 2001 From: "Sekan, Tobias" Date: Mon, 9 Nov 2020 06:30:36 +0100 Subject: [PATCH 11/15] fix misspellings --- .github/actions/spell-check/expect.txt | 5 +++++ .github/actions/spell-check/patterns.txt | 3 +++ .../Views/ColorPickerPage.xaml.cs | 4 ++-- .../ColorPickerUI/Helpers/ColorRepresentationHelper.cs | 6 +++--- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/.github/actions/spell-check/expect.txt b/.github/actions/spell-check/expect.txt index beae360464..211ffc92e7 100644 --- a/.github/actions/spell-check/expect.txt +++ b/.github/actions/spell-check/expect.txt @@ -903,6 +903,8 @@ hresult hrgn HRSRC HSCROLL +hsb +hsi hsl hstring hsv @@ -913,6 +915,7 @@ html htt http hu +hwb HWINEVENTHOOK hwnd HWNDFIRST @@ -1087,6 +1090,7 @@ IPrincipal IProgram IPublic IQuery +IReadOnlyDictionary IReflect IRegistered IRegistration @@ -1438,6 +1442,7 @@ NCMBUTTONDOWN NCMBUTTONUP NCMOUSELEAVE NCMOUSEMOVE +NCol NCPAINT NCRBUTTONDBLCLK NCRBUTTONDOWN diff --git a/.github/actions/spell-check/patterns.txt b/.github/actions/spell-check/patterns.txt index 60513959e0..46aec12d98 100644 --- a/.github/actions/spell-check/patterns.txt +++ b/.github/actions/spell-check/patterns.txt @@ -10,6 +10,9 @@ data:[a-zA-Z=;,/0-9+-]+ "Lorem[^"]+?\." TestCase\("[^"]+" +# Test line with hexadecimal colors +\[DataRow\("[0-9A-F]{6}", \d{3}, \d{3}, \d{3}\)\] + # Windows paths \\native \\notifications diff --git a/src/core/Microsoft.PowerToys.Settings.UI/Views/ColorPickerPage.xaml.cs b/src/core/Microsoft.PowerToys.Settings.UI/Views/ColorPickerPage.xaml.cs index 8c9a3cd80e..c7a17a3335 100644 --- a/src/core/Microsoft.PowerToys.Settings.UI/Views/ColorPickerPage.xaml.cs +++ b/src/core/Microsoft.PowerToys.Settings.UI/Views/ColorPickerPage.xaml.cs @@ -23,7 +23,7 @@ namespace Microsoft.PowerToys.Settings.UI.Views } /// - /// Event is called when the is completly loaded, inclusive the ItemSource + /// Event is called when the is completely loaded, inclusive the ItemSource /// /// The sender of this event /// The arguments of this event @@ -31,7 +31,7 @@ namespace Microsoft.PowerToys.Settings.UI.Views { /** * UWP hack - * because UWP load the binded ItemSource of the ComboBox asyncronous, + * because UWP load the bound ItemSource of the ComboBox asynchronous, * so after InitializeComponent() the ItemSource is still empty and can't automatically select a entry. * Selection via SelectedItem and SelectedValue is still not working too */ diff --git a/src/modules/colorPicker/ColorPickerUI/Helpers/ColorRepresentationHelper.cs b/src/modules/colorPicker/ColorPickerUI/Helpers/ColorRepresentationHelper.cs index cd2ab33c06..b21304a9ab 100644 --- a/src/modules/colorPicker/ColorPickerUI/Helpers/ColorRepresentationHelper.cs +++ b/src/modules/colorPicker/ColorPickerUI/Helpers/ColorRepresentationHelper.cs @@ -74,15 +74,15 @@ namespace ColorPicker.Helpers /// A representation of a HSB color private static string ColorToHSB(Color color) { - var (hue, saturation, brightnes) = ColorHelper.ConvertToHSBColor(color); + var (hue, saturation, brightness) = ColorHelper.ConvertToHSBColor(color); hue = Math.Round(hue); saturation = Math.Round(saturation * 100); - brightnes = Math.Round(brightnes * 100); + brightness = Math.Round(brightness * 100); return $"hsb({hue.ToString(CultureInfo.InvariantCulture)}" + $", {saturation.ToString(CultureInfo.InvariantCulture)}%" - + $", {brightnes.ToString(CultureInfo.InvariantCulture)}%)"; + + $", {brightness.ToString(CultureInfo.InvariantCulture)}%)"; } /// From 772255e4e00f494ef095d20fc336b2460d1c3ee8 Mon Sep 17 00:00:00 2001 From: "Sekan, Tobias" Date: Mon, 9 Nov 2020 06:46:13 +0100 Subject: [PATCH 12/15] fix spelling --- .github/actions/spell-check/expect.txt | 3 ++- .github/actions/spell-check/patterns.txt | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/actions/spell-check/expect.txt b/.github/actions/spell-check/expect.txt index 211ffc92e7..358f731159 100644 --- a/.github/actions/spell-check/expect.txt +++ b/.github/actions/spell-check/expect.txt @@ -295,6 +295,7 @@ codeofconduct codereview COINIT Colorbrush +colorconv colorpicker colorpickerref COLORREF @@ -1090,7 +1091,7 @@ IPrincipal IProgram IPublic IQuery -IReadOnlyDictionary +IRead IReflect IRegistered IRegistration diff --git a/.github/actions/spell-check/patterns.txt b/.github/actions/spell-check/patterns.txt index 46aec12d98..0e77f4806e 100644 --- a/.github/actions/spell-check/patterns.txt +++ b/.github/actions/spell-check/patterns.txt @@ -12,6 +12,8 @@ TestCase\("[^"]+" # Test line with hexadecimal colors \[DataRow\("[0-9A-F]{6}", \d{3}, \d{3}, \d{3}\)\] +\[DataRow\("[0-9A-F]{6}", \d{3}.\d{1}, \d{3}.\d{1}, \d{3}.\d{1}\)\] +\[DataRow\("[0-9A-F]{6}", "[0-9BCGMRY]3", \d{3}, \d{3}\)\] # Windows paths \\native From 4a2533503689c563de95486c995b5100452c5da4 Mon Sep 17 00:00:00 2001 From: "Sekan, Tobias" Date: Mon, 9 Nov 2020 06:48:12 +0100 Subject: [PATCH 13/15] fix wrong pattern --- .github/actions/spell-check/patterns.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/spell-check/patterns.txt b/.github/actions/spell-check/patterns.txt index 0e77f4806e..d2e14e1d01 100644 --- a/.github/actions/spell-check/patterns.txt +++ b/.github/actions/spell-check/patterns.txt @@ -13,7 +13,7 @@ TestCase\("[^"]+" # Test line with hexadecimal colors \[DataRow\("[0-9A-F]{6}", \d{3}, \d{3}, \d{3}\)\] \[DataRow\("[0-9A-F]{6}", \d{3}.\d{1}, \d{3}.\d{1}, \d{3}.\d{1}\)\] -\[DataRow\("[0-9A-F]{6}", "[0-9BCGMRY]3", \d{3}, \d{3}\)\] +\[DataRow\("[0-9A-F]{6}", "[0-9BCGMRY]", \d{3}, \d{3}\)\] # Windows paths \\native From f8e6802e3f9c7772a09f67d532ee99cf3f7aa9d0 Mon Sep 17 00:00:00 2001 From: "Sekan, Tobias" Date: Mon, 9 Nov 2020 09:33:57 +0100 Subject: [PATCH 14/15] Fix pattern --- .github/actions/spell-check/patterns.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/spell-check/patterns.txt b/.github/actions/spell-check/patterns.txt index d2e14e1d01..e5192cd0c3 100644 --- a/.github/actions/spell-check/patterns.txt +++ b/.github/actions/spell-check/patterns.txt @@ -13,7 +13,7 @@ TestCase\("[^"]+" # Test line with hexadecimal colors \[DataRow\("[0-9A-F]{6}", \d{3}, \d{3}, \d{3}\)\] \[DataRow\("[0-9A-F]{6}", \d{3}.\d{1}, \d{3}.\d{1}, \d{3}.\d{1}\)\] -\[DataRow\("[0-9A-F]{6}", "[0-9BCGMRY]", \d{3}, \d{3}\)\] +\[DataRow\("[0-9A-F]{6}", "[BCGMRY]\d\d?", \d{3}, \d{3}\)\] # Windows paths \\native From 83b2ffd0c972c8e238715489064e9cf396905d62 Mon Sep 17 00:00:00 2001 From: "Sekan, Tobias" Date: Mon, 9 Nov 2020 09:50:55 +0100 Subject: [PATCH 15/15] Commit to Re-Trigger Github PR --- .../colorPicker/ColorPickerUI/ViewModels/MainViewModel.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/modules/colorPicker/ColorPickerUI/ViewModels/MainViewModel.cs b/src/modules/colorPicker/ColorPickerUI/ViewModels/MainViewModel.cs index a600471f61..d747eae0a2 100644 --- a/src/modules/colorPicker/ColorPickerUI/ViewModels/MainViewModel.cs +++ b/src/modules/colorPicker/ColorPickerUI/ViewModels/MainViewModel.cs @@ -15,7 +15,6 @@ using ColorPicker.Mouse; using ColorPicker.Settings; using ColorPicker.Telemetry; using ColorPicker.ViewModelContracts; -using Microsoft.PowerToys.Settings.UI.Library; using Microsoft.PowerToys.Telemetry; namespace ColorPicker.ViewModels