Skip to content

Commit 87129fe

Browse files
committedSep 5, 2023
Show color name functionality, increased version number
1 parent ae1d73f commit 87129fe

16 files changed

+116
-31
lines changed
 

‎ColorPicker.nuspec

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
<package>
33
<metadata>
44
<id>ColorPicker</id>
5-
<version>1.2.1</version>
5+
<version>1.3.0</version>
66
<authors>Martin Chrzan</authors>
77
<owners>Martin Chrzan</owners>
88
<licenseUrl>https://github.com/martinchrzan/ColorPicker/blob/master/LICENSE</licenseUrl>
99
<projectUrl>http://github.com/martinchrzan/ColorPicker</projectUrl>
1010
<!--<iconUrl></iconUrl>-->
1111
<releaseNotes>
12-
Added new color formats - RGB565, decimal big-endian, decimal little-endian
12+
Show name of a color - you can enable this functionality in settings
1313
</releaseNotes>
1414
<requireLicenseAcceptance>false</requireLicenseAcceptance>
1515
<description>Color Picker</description>

‎ColorPicker/App.config

+4-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@
2929
<value>HEX</value>
3030
</setting>
3131
<setting name="ColorsHistory" serializeAs="String">
32-
<value/>
32+
<value />
33+
</setting>
34+
<setting name="ShowColorName" serializeAs="String">
35+
<value>False</value>
3336
</setting>
3437
</ColorPicker.Properties.Settings>
3538
</userSettings>

‎ColorPicker/ColorPicker.csproj

+3
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,9 @@
248248
<None Include="App.config" />
249249
</ItemGroup>
250250
<ItemGroup>
251+
<PackageReference Include="ColorName">
252+
<Version>1.0.0</Version>
253+
</PackageReference>
251254
<PackageReference Include="Microsoft.Xaml.Behaviors.Wpf">
252255
<Version>1.1.39</Version>
253256
</PackageReference>

‎ColorPicker/Controls/CircularMenu.cs

+22-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using ColorPicker.Helpers;
1+
using ColorName;
2+
using ColorPicker.Helpers;
23
using ColorPicker.Settings;
34
using System;
45
using System.Collections.ObjectModel;
@@ -28,7 +29,7 @@ public bool IsOpen
2829
public static readonly DependencyProperty CentralItemProperty =
2930
DependencyProperty.Register("CentralItem", typeof(CircularMenuCentralItem), typeof(CircularMenu),
3031
new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.AffectsRender | FrameworkPropertyMetadataOptions.AffectsMeasure));
31-
32+
3233

3334
public CircularMenuCentralItem CentralItem
3435
{
@@ -57,7 +58,7 @@ public override void BeginInit()
5758
private void Items_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
5859
{
5960
var newItem = e.NewItems[0] as CircularMenuItem;
60-
if(newItem != null)
61+
if (newItem != null)
6162
{
6263
if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add)
6364
{
@@ -72,10 +73,11 @@ private void Items_CollectionChanged(object sender, System.Collections.Specializ
7273
newItem.PreviewMouseDown -= CircularMenuItem_MouseDown;
7374
}
7475
}
75-
76-
if(Items?.Count > 0)
76+
77+
if (Items?.Count > 0)
7778
{
7879
CentralItem.ContentText = string.Empty;
80+
CentralItem.ColorName = string.Empty;
7981
}
8082
}
8183

@@ -92,16 +94,29 @@ private void CircularMenuItem_MouseDown(object sender, System.Windows.Input.Mous
9294
private void CircularMenuItem_MouseLeave(object sender, System.Windows.Input.MouseEventArgs e)
9395
{
9496
CentralItem.ContentText = string.Empty;
97+
CentralItem.ColorName = string.Empty;
9598
}
9699

97100
private void CircularMenuItem_MouseEnter(object sender, EventArgs e)
98101
{
99-
if(_userSettings == null)
102+
if (_userSettings == null)
100103
{
101104
_userSettings = Bootstrapper.Container.GetExportedValue<IUserSettings>();
102105
}
103-
106+
104107
var color = (sender as CircularMenuItem).Color;
108+
109+
if (_userSettings.ShowColorName.Value)
110+
{
111+
var colorName = _userSettings.ShowColorName.Value ? ColorNameProvider.GetColorNameFromRGB(color.R, color.G, color.B).colorName : "";
112+
CentralItem.ColorName = colorName;
113+
CentralItem.IsColorNameVisible = true;
114+
}
115+
else
116+
{
117+
CentralItem.IsColorNameVisible = false;
118+
}
119+
105120
CentralItem.ContentText = ColorFormatHelper.ColorToString(color, _userSettings.SelectedColorFormat.Value);
106121
}
107122

‎ColorPicker/Controls/CircularMenuCentralItem.cs

+20
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,30 @@ static CircularMenuCentralItem()
1414
DependencyProperty.Register("ContentText", typeof(string), typeof(CircularMenuCentralItem),
1515
new FrameworkPropertyMetadata(string.Empty, FrameworkPropertyMetadataOptions.AffectsRender));
1616

17+
public static readonly DependencyProperty ColorNameProperty =
18+
DependencyProperty.Register("ColorName", typeof(string), typeof(CircularMenuCentralItem),
19+
new FrameworkPropertyMetadata(string.Empty, FrameworkPropertyMetadataOptions.AffectsRender));
20+
21+
public static readonly DependencyProperty IsColorNameVisibleProperty =
22+
DependencyProperty.Register("IsColorNameVisible", typeof(bool), typeof(CircularMenuCentralItem),
23+
new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
24+
1725
public string ContentText
1826
{
1927
get { return (string)GetValue(ContentTextProperty); }
2028
set { SetValue(ContentTextProperty, value); }
2129
}
30+
31+
public string ColorName
32+
{
33+
get { return (string)GetValue(ColorNameProperty); }
34+
set { SetValue(ColorNameProperty, value); }
35+
}
36+
37+
public bool IsColorNameVisible
38+
{
39+
get { return (bool)GetValue(IsColorNameVisibleProperty); }
40+
set { SetValue(IsColorNameVisibleProperty, value); }
41+
}
2242
}
2343
}

‎ColorPicker/Mouse/MouseInfoProvider.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ private void AppStateMonitor_AppShown(object sender, WindowType e)
115115
_timer.Start();
116116
}
117117

118-
if(!_eventsSubscribed)
118+
if (!_eventsSubscribed)
119119
{
120120
_mouseHook.OnLeftMouseDown += MouseHook_OnLeftMouseDown;
121121
_mouseHook.OnLeftMouseUp += MouseHook_OnLeftMouseUp;
@@ -138,7 +138,7 @@ private void MouseHook_OnLeftMouseUp(object sender, Point p)
138138

139139
private void MouseHook_OnMouseWheel(object sender, MouseWheelEventArgs e)
140140
{
141-
if(e.Delta == 0)
141+
if (e.Delta == 0)
142142
{
143143
return;
144144
}
@@ -169,7 +169,7 @@ private void DisposeMouseHook()
169169
{
170170
_timer.Stop();
171171
}
172-
172+
173173
_previousMousePosition = new System.Windows.Point(-1, 1);
174174
_mouseHook.OnLeftMouseDown -= MouseHook_OnLeftMouseDown;
175175
_mouseHook.OnLeftMouseUp -= MouseHook_OnLeftMouseUp;

‎ColorPicker/Properties/AssemblyInfo.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
[assembly: AssemblyDescription("Windows system wide color picker")]
1010
[assembly: AssemblyConfiguration("")]
1111
[assembly: AssemblyProduct("ColorPicker")]
12-
[assembly: AssemblyCopyright("Martin Chrzan © 2020")]
12+
[assembly: AssemblyCopyright("Martin Chrzan © 2020-2023")]
1313
[assembly: AssemblyTrademark("")]
1414
[assembly: AssemblyCulture("")]
1515

@@ -48,6 +48,6 @@
4848
// You can specify all the values or you can default the Build and Revision Numbers
4949
// by using the '*' as shown below:
5050
// [assembly: AssemblyVersion("1.0.*")]
51-
[assembly: AssemblyVersion("1.2.1.0")]
52-
[assembly: AssemblyFileVersion("1.2.1.0")]
51+
[assembly: AssemblyVersion("1.3.0.0")]
52+
[assembly: AssemblyFileVersion("1.3.0.0")]
5353
[assembly: AssemblyMetadata("SquirrelAwareVersion", "1")]

‎ColorPicker/Properties/Settings.Designer.cs

+13-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎ColorPicker/Properties/Settings.settings

+3
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,8 @@
2323
<Setting Name="ColorsHistory" Type="System.String" Scope="User">
2424
<Value Profile="(Default)" />
2525
</Setting>
26+
<Setting Name="ShowColorName" Type="System.Boolean" Scope="User">
27+
<Value Profile="(Default)">False</Value>
28+
</Setting>
2629
</Settings>
2730
</SettingsFile>

‎ColorPicker/Resources/Styles.xaml

+4-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,10 @@
132132
<ControlTemplate TargetType="controls:CircularMenuCentralItem">
133133
<Grid>
134134
<Ellipse UseLayoutRounding="True" Stroke="White" StrokeThickness="4" Fill="{StaticResource CenterGradientColor}"/>
135-
<TextBlock Text="{TemplateBinding ContentText}" Foreground="White" FontSize="16" FontWeight="Light" VerticalAlignment="Center" HorizontalAlignment="Center"/>
135+
<StackPanel VerticalAlignment="Center" HorizontalAlignment="Center">
136+
<TextBlock Margin="5" Text="{TemplateBinding ContentText}" Foreground="White" FontSize="16" FontWeight="Light" VerticalAlignment="Center" HorizontalAlignment="Center" />
137+
<TextBlock Margin="5" Text="{TemplateBinding ColorName}" Visibility="{TemplateBinding IsColorNameVisible, Converter={StaticResource bool2VisibilityConverter}}" Foreground="White" FontSize="15" FontWeight="Normal" VerticalAlignment="Center" HorizontalAlignment="Center" TextWrapping="Wrap" />
138+
</StackPanel>
136139
</Grid>
137140
</ControlTemplate>
138141
</Setter.Value>

‎ColorPicker/Settings/IUserSettings.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
namespace ColorPicker.Settings
55
{
6-
public enum ColorFormat { hex, rgb, hsl, hsv, vec4, rgb565, decimalBE, decimalLE};
6+
public enum ColorFormat { hex, rgb, hsl, hsv, vec4, rgb565, decimalBE, decimalLE };
77

88
public interface IUserSettings
99
{
@@ -15,6 +15,8 @@ public interface IUserSettings
1515

1616
SettingItem<bool> ChangeCursor { get; }
1717

18+
SettingItem<bool> ShowColorName { get; }
19+
1820
SettingItem<ColorFormat> SelectedColorFormat { get; }
1921

2022
List<Color> ColorsHistory { get; }

‎ColorPicker/Settings/UserSettings.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
using System.Collections.Generic;
44
using System.ComponentModel.Composition;
55
using System.Drawing;
6-
using Windows.Media.Devices;
76

87
namespace ColorPicker.Settings
98
{
@@ -23,6 +22,7 @@ public UserSettings()
2322
AutomaticUpdates = new SettingItem<bool>(settings.AutomaticUpdates, (currentValue) => { settings.AutomaticUpdates = currentValue; SaveSettings(); });
2423
ActivationShortcut = new SettingItem<string>(settings.ActivationShortcut, (currentValue) => { settings.ActivationShortcut = currentValue; SaveSettings(); });
2524
ChangeCursor = new SettingItem<bool>(settings.ChangeCursorWhenPickingColor, (currentValue) => { settings.ChangeCursorWhenPickingColor = currentValue; SaveSettings(); });
25+
ShowColorName = new SettingItem<bool>(settings.ShowColorName, (currentValue) => { settings.ShowColorName = currentValue; SaveSettings(); });
2626
SelectedColorFormat = new SettingItem<ColorFormat>((ColorFormat)Enum.Parse(typeof(ColorFormat), settings.SelectedColorFormat, true), (currentValue) => { settings.SelectedColorFormat = currentValue.ToString(); SaveSettings(); });
2727
LoadColorsHistory();
2828
}
@@ -35,6 +35,8 @@ public UserSettings()
3535

3636
public SettingItem<bool> ChangeCursor { get; }
3737

38+
public SettingItem<bool> ShowColorName { get; }
39+
3840
public SettingItem<ColorFormat> SelectedColorFormat { get; }
3941

4042
public List<Color> ColorsHistory { get; } = new List<Color>();

‎ColorPicker/ViewModelContracts/ISettingsViewModel.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,16 @@ public interface ISettingsViewModel
1313

1414
bool ChangeCursorWhenPickingColor { get; set; }
1515

16+
bool ShowColorName { get; set; }
17+
1618
string ShortCut { get; }
1719

1820
string ShortCutPreview { get; set; }
1921

2022
string ApplicationVersion { get; }
2123

2224
ColorFormat SelectedColorFormat { get; }
23-
25+
2426
bool CheckingForUpdateInProgress { get; }
2527

2628
ICommand ChangeShortcutCommand { get; }

‎ColorPicker/ViewModels/MainViewModel.cs

+12-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using ColorMeter.Helpers;
2+
using ColorName;
23
using ColorPicker.Common;
34
using ColorPicker.Helpers;
45
using ColorPicker.Keyboard;
@@ -28,10 +29,10 @@ public class MainViewModel : ViewModelBase, IMainViewModel
2829

2930
[ImportingConstructor]
3031
public MainViewModel(
31-
IMouseInfoProvider mouseInfoProvider,
32-
ZoomWindowHelper zoomWindowHelper,
33-
AppStateHandler appStateHandler,
34-
KeyboardMonitor keyboardMonitor,
32+
IMouseInfoProvider mouseInfoProvider,
33+
ZoomWindowHelper zoomWindowHelper,
34+
AppStateHandler appStateHandler,
35+
KeyboardMonitor keyboardMonitor,
3536
AppUpdateManager appUpdateManager,
3637
IUserSettings userSettings,
3738
IColorProvider colorProvider)
@@ -49,10 +50,10 @@ public MainViewModel(
4950
mouseInfoProvider.OnMouseWheel += MouseInfoProvider_OnMouseWheel;
5051

5152
keyboardMonitor.Start();
52-
53-
#if !DEBUG
53+
54+
#if !DEBUG
5455
CheckForUpdates(appUpdateManager, userSettings);
55-
#endif
56+
#endif
5657
}
5758

5859
private static void CheckForUpdates(AppUpdateManager appUpdateManager, IUserSettings userSettings)
@@ -75,6 +76,10 @@ public string ColorString
7576
{
7677
get
7778
{
79+
if (_userSettings.ShowColorName.Value)
80+
{
81+
return $"{_colorString} - {ColorNameProvider.GetColorNameFromRGB(_currentColor.R, _currentColor.G, _currentColor.B).colorName}";
82+
}
7883
return _colorString;
7984
}
8085
set

‎ColorPicker/ViewModels/SettingsViewModel.cs

+16-3
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public bool RunOnStartup
5959
set
6060
{
6161
// only set value if registry save successful
62-
if(RegistryHelper.SetRunOnStartup(value))
62+
if (RegistryHelper.SetRunOnStartup(value))
6363
{
6464
_userSettings.RunOnStartup.Value = value;
6565
OnPropertyChanged();
@@ -157,12 +157,25 @@ public bool ChangeCursorWhenPickingColor
157157
}
158158
}
159159

160+
public bool ShowColorName
161+
{
162+
get
163+
{
164+
return _userSettings.ShowColorName.Value;
165+
}
166+
set
167+
{
168+
_userSettings.ShowColorName.Value = value;
169+
OnPropertyChanged();
170+
}
171+
}
172+
160173
public string ApplicationVersion { get { return Assembly.GetExecutingAssembly().GetName().Version.ToString(); } }
161174

162175
public ICommand ChangeShortcutCommand { get; }
163-
176+
164177
public ICommand CheckForUpdatesCommand { get; }
165-
178+
166179
public ICommand ConfirmShortcutCommand { get; }
167180

168181
public ICommand CancelShortcutCommand { get; }

‎ColorPicker/Views/SettingsView.xaml

+2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
<CheckBox Margin="5,0" IsChecked="{Binding RunOnStartup}" FontWeight="Light" Content="Run on startup"/>
3232
<CheckBox Margin="5,0" IsChecked="{Binding AutomaticUpdates}" FontWeight="Light" Content="Automatic updates"/>
3333
<CheckBox Margin="5,0" IsChecked="{Binding ChangeCursorWhenPickingColor}" FontWeight="Light" Content="Change cursor when picking a color"/>
34+
<CheckBox Margin="5,0" IsChecked="{Binding ShowColorName}" FontWeight="Light" Content="Show color name"/>
35+
3436
<Rectangle Height="1" Fill="DarkGray" Margin="5"/>
3537
<WrapPanel>
3638
<TextBlock VerticalAlignment="Center" Style="{StaticResource NormalTextBlock}" FontWeight="Light" Margin="7" Text="Copied color format:"/>

0 commit comments

Comments
 (0)
Please sign in to comment.