Skip to content

Commit

Permalink
Added the possibility to use upper cases or lower cases for HEX (#385)
Browse files Browse the repository at this point in the history
  • Loading branch information
lpeyr committed Feb 24, 2024
1 parent c72afc8 commit 36627eb
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 8 deletions.
14 changes: 9 additions & 5 deletions ColorPicker/Classes/ColorInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace ColorPicker.Classes
public class ColorInfo(RGB rgb)
{
public RGB RGB { get; set; } = rgb;
public HEX HEX { get; set; } = ColorConverter.RgbToHex(rgb);
public HEX HEX { get; set; } = GetHex(rgb);
public HSV HSV { get; set; } = ColorConverter.RgbToHsv(rgb);
public HSL HSL { get; set; } = ColorConverter.RgbToHsl(rgb);
public CMYK CMYK { get; set; } = ColorConverter.RgbToCmyk(rgb);
Expand All @@ -37,17 +37,21 @@ public class ColorInfo(RGB rgb)
public YUV YUV { get; set; } = ColorConverter.RgbToYuv(rgb);
public DEC DEC { get; set; } = DEC.FromRgb(rgb);

public override string ToString()
{
return $"{Properties.Resources.RGB}: {RGB.R}{Global.Settings.RgbSeparator}{RGB.G}{Global.Settings.RgbSeparator}{RGB.B}\n" +
$"{Properties.Resources.HEX}: {(HEX.Value.StartsWith("#") ? "" : "#")}{HEX.Value}\n" +
public override string ToString() => $"{Properties.Resources.RGB}: {RGB.R}{Global.Settings.RgbSeparator}{RGB.G}{Global.Settings.RgbSeparator}{RGB.B}\n" +
$"{Properties.Resources.HEX}: {(HEX.Value.StartsWith('#') ? "" : "#")}{((Global.Settings.UseUpperCasesHex ?? false) ? HEX.Value.ToUpper() : HEX.Value.ToLower())}\n" +
$"{Properties.Resources.HSV}: {HSV.H},{HSV.S},{HSV.V}\n" +
$"{Properties.Resources.HSL}: {HSL.H},{HSL.S},{HSL.L}\n" +
$"{Properties.Resources.CMYK}: {CMYK.C},{CMYK.M},{CMYK.Y},{CMYK.K}\n" +
$"{Properties.Resources.DEC}: {DEC.Value}\n" +
$"{Properties.Resources.XYZ}: {XYZ.X:0.00}..; {XYZ.Y:0.00}..; {XYZ.Z:0.00}..\n" +
$"{Properties.Resources.YIQ}: {YIQ.Y:0.00}..; {YIQ.I:0.00}..; {YIQ.Q:0.00}..\n" +
$"{Properties.Resources.YUV}: {YUV.Y:0.00}..; {YUV.U:0.00}..; {YUV.V:0.00}..";

private static HEX GetHex(RGB rgb)
{
var hex = ColorConverter.RgbToHex(rgb);
hex.Value = (Global.Settings.UseUpperCasesHex ?? false) ? hex.Value.ToUpper() : hex.Value.ToLower();
return hex;
}
}
}
2 changes: 2 additions & 0 deletions ColorPicker/Classes/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public Settings()
Model = "gpt-3.5-turbo";
SupportedModels = ["gpt-3.5-turbo", "gpt-4"];
RgbSeparator = ";";
UseUpperCasesHex = false;
}

public Themes Theme { get; set; }
Expand All @@ -69,5 +70,6 @@ public Settings()
public string? Model { get; set; }
public string[]? SupportedModels { get; set; }
public string? RgbSeparator { get; set; }
public bool? UseUpperCasesHex { get; set; }
}
}
10 changes: 10 additions & 0 deletions ColorPicker/Pages/SettingsPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,16 @@
TextChanged="RgbSeparatorTxt_TextChanged" />
</Border>
</StackPanel>
<CheckBox
x:Name="UpperCaseHexChk"
Margin="10 0 0 5"
VerticalContentAlignment="Center"
BorderThickness="2"
Checked="UpperCaseHexChk_Checked"
Content="{x:Static lang:Resources.UseUpperCasesHex}"
Foreground="{DynamicResource Foreground1}"
Style="{DynamicResource CheckBoxStyle1}"
Unchecked="UpperCaseHexChk_Checked" />
</StackPanel>
</Expander>
<Expander
Expand Down
8 changes: 8 additions & 0 deletions ColorPicker/Pages/SettingsPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,10 @@ private async void InitUI()

// Load the color option section
Global.Settings.RgbSeparator ??= ";";
Global.Settings.UseUpperCasesHex ??= false;
ColorTypeComboBox.SelectedIndex = (int)Global.Settings.DefaultColorType;
RgbSeparatorTxt.Text = Global.Settings.RgbSeparator;
UpperCaseHexChk.IsChecked = Global.Settings.UseUpperCasesHex;

// Load the default page ComboBox
PageComboBox.SelectedIndex = (int)Global.Settings.DefaultPage;
Expand Down Expand Up @@ -536,6 +538,12 @@ private void RgbSeparatorTxt_TextChanged(object sender, TextChangedEventArgs e)
XmlSerializerManager.SaveToXml(Global.Settings, Global.SettingsPath);
}

private void UpperCaseHexChk_Checked(object sender, RoutedEventArgs e)
{
Global.Settings.UseUpperCasesHex = UpperCaseHexChk.IsChecked;
XmlSerializerManager.SaveToXml(Global.Settings, Global.SettingsPath);
}

private void ResetSynethiaLink_Click(object sender, RoutedEventArgs e)
{
// Ask the user a confirmation
Expand Down
11 changes: 10 additions & 1 deletion ColorPicker/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions ColorPicker/Properties/Resources.en-US.resx
Original file line number Diff line number Diff line change
Expand Up @@ -735,4 +735,7 @@
<data name="BackgroundDetails" xml:space="preserve">
<value>Background color details</value>
</data>
<data name="UseUpperCasesHex" xml:space="preserve">
<value>Use upper cases for HEX color</value>
</data>
</root>
3 changes: 3 additions & 0 deletions ColorPicker/Properties/Resources.fr-FR.resx
Original file line number Diff line number Diff line change
Expand Up @@ -739,4 +739,7 @@
<data name="BackgroundDetails" xml:space="preserve">
<value>Détails de la couleur d'arrière-plan</value>
</data>
<data name="UseUpperCasesHex" xml:space="preserve">
<value>Utiliser des majuscules pour les couleurs HEX</value>
</data>
</root>
3 changes: 3 additions & 0 deletions ColorPicker/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -715,4 +715,7 @@
<data name="BackgroundDetails" xml:space="preserve">
<value>Background color details</value>
</data>
<data name="UseUpperCasesHex" xml:space="preserve">
<value>Use upper cases for HEX color</value>
</data>
</root>
3 changes: 3 additions & 0 deletions ColorPicker/Properties/Resources.zh-CN.resx
Original file line number Diff line number Diff line change
Expand Up @@ -743,4 +743,7 @@
<data name="BackgroundDetails" xml:space="preserve">
<value>背景颜色细节</value>
</data>
<data name="UseUpperCasesHex" xml:space="preserve">
<value>使用大写字母表示 HEX 颜色</value>
</data>
</root>
3 changes: 2 additions & 1 deletion ColorPicker/UserControls/ColorFrequenceItem.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
*/

using ColorHelper;
using ColorPicker.Classes;
using ColorPicker.Windows;
using System.Windows.Controls;
using System.Windows.Input;
Expand All @@ -49,7 +50,7 @@ public ColorFrequenceItem(RGB color, int freq)
private void InitUI()
{
ColorBorder.Background = new SolidColorBrush { Color = System.Windows.Media.Color.FromRgb(Color.R, Color.G, Color.B) };
ColorTxt.Text = $"#{ColorHelper.ColorConverter.RgbToHex(Color).Value}";
ColorTxt.Text = $"#{((Global.Settings.UseUpperCasesHex ?? false) ? ColorHelper.ColorConverter.RgbToHex(Color).Value.ToUpper() : ColorHelper.ColorConverter.RgbToHex(Color).Value.ToLower())}";
FreqTxt.Text = Freq.ToString();
}

Expand Down
2 changes: 1 addition & 1 deletion ColorPicker/UserControls/ColorItem.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public partial class ColorItem : UserControl
public ColorItem(string hexColor)
{
InitializeComponent();
HexColor = hexColor;
HexColor = (Global.Settings.UseUpperCasesHex ?? false) ? hexColor.ToUpper() : hexColor.ToLower();
ColorInfo = new(ColorHelper.ColorConverter.HexToRgb(new(HexColor)));

InitUI();
Expand Down

0 comments on commit 36627eb

Please sign in to comment.