diff --git a/ColorPicker/Classes/Global.cs b/ColorPicker/Classes/Global.cs
index 4ce37c7..b5afbf0 100644
--- a/ColorPicker/Classes/Global.cs
+++ b/ColorPicker/Classes/Global.cs
@@ -120,6 +120,7 @@ public static string ColorTypesToString(ColorTypes colorTypes)
ColorTypes.HEX => Properties.Resources.HEX,
ColorTypes.RGB => Properties.Resources.RGB,
ColorTypes.HSV => Properties.Resources.HSV,
+ ColorTypes.HSL => Properties.Resources.HSL,
_ => Properties.Resources.RGB
}; // Return value
}
diff --git a/ColorPicker/Enums/ColorTypes.cs b/ColorPicker/Enums/ColorTypes.cs
index da8d8e7..206be08 100644
--- a/ColorPicker/Enums/ColorTypes.cs
+++ b/ColorPicker/Enums/ColorTypes.cs
@@ -36,6 +36,7 @@ public enum ColorTypes
{
RGB,
HEX,
- HSV
+ HSV,
+ HSL
}
}
diff --git a/ColorPicker/Pages/ConverterPage.xaml b/ColorPicker/Pages/ConverterPage.xaml
index c7be74b..88cbd2b 100644
--- a/ColorPicker/Pages/ConverterPage.xaml
+++ b/ColorPicker/Pages/ConverterPage.xaml
@@ -49,6 +49,22 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -63,6 +79,7 @@
+
diff --git a/ColorPicker/Pages/ConverterPage.xaml.cs b/ColorPicker/Pages/ConverterPage.xaml.cs
index 669af8c..8ad7d3e 100644
--- a/ColorPicker/Pages/ConverterPage.xaml.cs
+++ b/ColorPicker/Pages/ConverterPage.xaml.cs
@@ -59,6 +59,7 @@ private void InitUI()
ColorTypeComboBox.Items.Add(Global.ColorTypesToString(ColorTypes.RGB)); // Add
ColorTypeComboBox.Items.Add(Global.ColorTypesToString(ColorTypes.HEX)); // Add
ColorTypeComboBox.Items.Add(Global.ColorTypesToString(ColorTypes.HSV)); // Add
+ ColorTypeComboBox.Items.Add(Global.ColorTypesToString(ColorTypes.HSL)); // Add
ColorTypeComboBox.SelectedIndex = 0; // Set index
// Generate random color
@@ -79,10 +80,12 @@ private void ColorTxt_TextChanged(object sender, TextChangedEventArgs e)
{
string[] rgb = ColorTxt.Text.Split(new string[] { ";" }, StringSplitOptions.None); // Split
var hsv = ColorsConverter.RGBtoHSV(int.Parse(rgb[0]), int.Parse(rgb[1]), int.Parse(rgb[2])); // Convert
+ var hsl = ColorHelper.ColorConverter.RgbToHsl(new((byte)int.Parse(rgb[0]), (byte)int.Parse(rgb[1]), (byte)int.Parse(rgb[2])));
RGBTxt.Text = $"{Properties.Resources.RGB} {rgb[0]};{rgb[1]};{rgb[2]}"; // Set text
HEXTxt.Text = $"{Properties.Resources.HEX} #{ColorsConverter.RGBtoHEX(int.Parse(rgb[0]), int.Parse(rgb[1]), int.Parse(rgb[2])).Value}"; // Set text
HSVTxt.Text = $"{Properties.Resources.HSV} ({hsv.Hue},{hsv.Saturation},{hsv.Value})"; // Set text
+ HSLTxt.Text = $"{Properties.Resources.HSL} ({hsl.H},{hsl.S},{hsl.L})"; // Set text
rgbColor = $"{rgb[0]};{rgb[1]};{rgb[2]}"; // Set text
hexColor = $"#{ColorsConverter.RGBtoHEX(int.Parse(rgb[0]), int.Parse(rgb[1]), int.Parse(rgb[2])).Value}"; // Set text
@@ -93,10 +96,12 @@ private void ColorTxt_TextChanged(object sender, TextChangedEventArgs e)
var rgb = ColorsConverter.HEXtoRGB(new() { Value = ColorTxt.Text }); // Convert
string hex = ColorTxt.Text.StartsWith("#") ? ColorTxt.Text : "#" + ColorTxt.Text; // Set
var hsv = ColorsConverter.RGBtoHSV(rgb); // Convert
+ var hsl = ColorHelper.ColorConverter.HexToHsl(new(hex)); // Convert
RGBTxt.Text = $"{Properties.Resources.RGB} {rgb.R};{rgb.G};{rgb.B}"; // Set text
HEXTxt.Text = $"{Properties.Resources.HEX} {hex}"; // Set text
HSVTxt.Text = $"{Properties.Resources.HSV} ({hsv.Hue},{hsv.Saturation},{hsv.Value})"; // Set text
+ HSLTxt.Text = $"{Properties.Resources.HSL} ({hsl.H},{hsl.S},{hsl.L})"; // Set text
rgbColor = $"{rgb.R};{rgb.G};{rgb.B}"; // Set text
hexColor = $"{hex}"; // Set text
@@ -147,10 +152,12 @@ private void ConvertHSV()
int v = int.Parse(ValTxt.Text); // Parse
var rgb = ColorHelper.ColorConverter.HsvToRgb(new(h, (byte)s, (byte)v)); // Convert
var hex = ColorsConverter.RGBtoHEX(rgb.R, rgb.G, rgb.B); // Convert
+ var hsl = ColorHelper.ColorConverter.RgbToHsl(rgb); // Convert
RGBTxt.Text = $"{Properties.Resources.RGB} {rgb.R};{rgb.G};{rgb.B}"; // Set text
HEXTxt.Text = $"{Properties.Resources.HEX} #{hex.Value}"; // Set text
HSVTxt.Text = $"{Properties.Resources.HSV} ({h},{s},{v})"; // Set text
+ HSLTxt.Text = $"{Properties.Resources.HSL} ({hsl.H},{hsl.S},{hsl.L})"; // Set text
hsvColor = $"({h},{s},{v})"; // Set
@@ -168,11 +175,56 @@ private void ConvertHSV()
}
}
+ private void ConvertHSL()
+ {
+ try
+ {
+ int h = int.Parse(HTxt.Text); // Parse
+ int s = int.Parse(STxt.Text); // Parse
+ int l = int.Parse(LTxt.Text); // Parse
+ var rgb = ColorHelper.ColorConverter.HslToRgb(new(h, (byte)s, (byte)l)); // Convert
+ var hex = ColorsConverter.RGBtoHEX(rgb.R, rgb.G, rgb.B); // Convert
+ var hsv = ColorHelper.ColorConverter.RgbToHsv(rgb); // Convert
+
+ RGBTxt.Text = $"{Properties.Resources.RGB} {rgb.R};{rgb.G};{rgb.B}"; // Set text
+ HEXTxt.Text = $"{Properties.Resources.HEX} #{hex.Value}"; // Set text
+ HSVTxt.Text = $"{Properties.Resources.HSV} ({hsv.H},{hsv.S},{hsv.V})"; // Set text
+ HSLTxt.Text = $"{Properties.Resources.HSL} ({h},{s},{l})"; // Set text
+
+ ColorDisplayer.Background = new SolidColorBrush { Color = Color.FromRgb(rgb.R, rgb.G, rgb.B) }; // Set color
+
+ IconValidMsgTxt.Foreground = new SolidColorBrush { Color = Color.FromRgb(0, 223, 57) }; // Set foreground color
+ IconValidMsgTxt.Text = "\uF299"; // Set icon
+ ValidMsgTxt.Text = Properties.Resources.ColorValid; // Set text
+ }
+ catch
+ {
+ IconValidMsgTxt.Foreground = new SolidColorBrush { Color = Color.FromRgb(255, 69, 0) }; // Set foreground color
+ IconValidMsgTxt.Text = "\uF36E"; // Set icon
+ ValidMsgTxt.Text = Properties.Resources.InvalidColor; // Set text
+ }
+ }
+
private void CopyHSVBtn_Click(object sender, RoutedEventArgs e)
{
Clipboard.SetText(hsvColor); // Copy
}
+ private void HTxt_TextChanged(object sender, TextChangedEventArgs e)
+ {
+ ConvertHSL();
+ }
+
+ private void STxt_TextChanged(object sender, TextChangedEventArgs e)
+ {
+ ConvertHSL();
+ }
+
+ private void LTxt_TextChanged(object sender, TextChangedEventArgs e)
+ {
+ ConvertHSL();
+ }
+
private void CopyHEXBtn_Click(object sender, RoutedEventArgs e)
{
Clipboard.SetText(hexColor); // Copy
@@ -197,14 +249,22 @@ private void ColorTypeComboBox_SelectionChanged(object sender, SelectionChangedE
case 0: // RGB
ColorTxt.Visibility = Visibility.Visible; // Show
HSVGrid.Visibility = Visibility.Collapsed; // Hide
+ HSLGrid.Visibility = Visibility.Collapsed; // Hide
break;
case 1: // HEX
ColorTxt.Visibility = Visibility.Visible; // Show
HSVGrid.Visibility = Visibility.Collapsed; // Hide
+ HSLGrid.Visibility = Visibility.Collapsed; // Hide
break;
- case 2:
+ case 2: // HSV
ColorTxt.Visibility = Visibility.Collapsed; // Hide
HSVGrid.Visibility = Visibility.Visible; // Show
+ HSLGrid.Visibility = Visibility.Collapsed; // Hide
+ break;
+ case 3: // HSL
+ ColorTxt.Visibility = Visibility.Collapsed; // Hide
+ HSVGrid.Visibility = Visibility.Collapsed; // Hide
+ HSLGrid.Visibility = Visibility.Visible; // Show
break;
}
}
diff --git a/ColorPicker/Properties/Resources.Designer.cs b/ColorPicker/Properties/Resources.Designer.cs
index c2c654b..272c316 100644
--- a/ColorPicker/Properties/Resources.Designer.cs
+++ b/ColorPicker/Properties/Resources.Designer.cs
@@ -330,6 +330,15 @@ public class Resources {
}
}
+ ///
+ /// Looks up a localized string similar to HSL.
+ ///
+ public static string HSL {
+ get {
+ return ResourceManager.GetString("HSL", resourceCulture);
+ }
+ }
+
///
/// Looks up a localized string similar to HSV.
///
@@ -375,6 +384,15 @@ public class Resources {
}
}
+ ///
+ /// Looks up a localized string similar to L.
+ ///
+ public static string L {
+ get {
+ return ResourceManager.GetString("L", resourceCulture);
+ }
+ }
+
///
/// Looks up a localized string similar to Language.
///
diff --git a/ColorPicker/Properties/Resources.en-US.resx b/ColorPicker/Properties/Resources.en-US.resx
index 92bf934..272c39d 100644
--- a/ColorPicker/Properties/Resources.en-US.resx
+++ b/ColorPicker/Properties/Resources.en-US.resx
@@ -297,4 +297,10 @@
Copy HSV
+
+ HSL
+
+
+ L
+
\ No newline at end of file
diff --git a/ColorPicker/Properties/Resources.fr-FR.resx b/ColorPicker/Properties/Resources.fr-FR.resx
index cb7edf2..5da5248 100644
--- a/ColorPicker/Properties/Resources.fr-FR.resx
+++ b/ColorPicker/Properties/Resources.fr-FR.resx
@@ -297,4 +297,10 @@
Copier HSV
+
+ HSL
+
+
+ L
+
\ No newline at end of file
diff --git a/ColorPicker/Properties/Resources.resx b/ColorPicker/Properties/Resources.resx
index 7512f35..18fba01 100644
--- a/ColorPicker/Properties/Resources.resx
+++ b/ColorPicker/Properties/Resources.resx
@@ -277,4 +277,10 @@
Copy HSV
+
+ HSL
+
+
+ L
+
\ No newline at end of file