Skip to content

Commit

Permalink
Added the possibility to copy a HSL color (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
lpeyr committed May 15, 2021
1 parent 4583c06 commit e6020ab
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 2 deletions.
3 changes: 2 additions & 1 deletion ColorPicker/Pages/ConverterPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@
<StackPanel Orientation="Horizontal" Grid.Row="3" HorizontalAlignment="Center">
<Button x:Name="CopyBtn" Click="CopyBtn_Click" Content="{x:Static lang:Resources.CopyRGB}" HorizontalAlignment="Center" Padding="10,5,10,5" Style="{DynamicResource TabButtonStyle}" Foreground="{Binding Source={StaticResource Foreground1}}" Background="{Binding Source={StaticResource Background2}}" FontWeight="Bold" Margin="0,10,10,0"/>
<Button x:Name="CopyHEXBtn" Click="CopyHEXBtn_Click" Content="{x:Static lang:Resources.CopyHEX}" HorizontalAlignment="Center" Padding="10,5,10,5" Style="{DynamicResource TabButtonStyle}" Foreground="{Binding Source={StaticResource Foreground1}}" Background="{Binding Source={StaticResource Background2}}" FontWeight="Bold" Margin="0,10,10,0"/>
<Button x:Name="CopyHSVBtn" Click="CopyHSVBtn_Click" Content="{x:Static lang:Resources.CopyHSV}" HorizontalAlignment="Center" Padding="10,5,10,5" Style="{DynamicResource TabButtonStyle}" Foreground="{Binding Source={StaticResource Foreground1}}" Background="{Binding Source={StaticResource Background2}}" FontWeight="Bold" Margin="0,10,0,0"/>
<Button x:Name="CopyHSVBtn" Click="CopyHSVBtn_Click" Content="{x:Static lang:Resources.CopyHSV}" HorizontalAlignment="Center" Padding="10,5,10,5" Style="{DynamicResource TabButtonStyle}" Foreground="{Binding Source={StaticResource Foreground1}}" Background="{Binding Source={StaticResource Background2}}" FontWeight="Bold" Margin="0,10,10,0"/>
<Button x:Name="CopyHSLBtn" Click="CopyHSLBtn_Click" Content="{x:Static lang:Resources.CopyHSL}" HorizontalAlignment="Center" Padding="10,5,10,5" Style="{DynamicResource TabButtonStyle}" Foreground="{Binding Source={StaticResource Foreground1}}" Background="{Binding Source={StaticResource Background2}}" FontWeight="Bold" Margin="0,10,0,0"/>
</StackPanel>
</Grid>
</StackPanel>
Expand Down
18 changes: 17 additions & 1 deletion ColorPicker/Pages/ConverterPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ namespace ColorPicker.Pages
/// </summary>
public partial class ConverterPage : Page
{
string rgbColor, hexColor, hsvColor = "";
string rgbColor, hexColor, hsvColor, hslColor = "";
public ConverterPage()
{
InitializeComponent();
Expand Down Expand Up @@ -90,6 +90,7 @@ private void ColorTxt_TextChanged(object sender, TextChangedEventArgs e)
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
hsvColor = $"({hsv.Hue},{hsv.Saturation},{hsv.Value})"; // Set
hslColor = $"({hsl.H},{hsl.S},{hsl.L})"; // Set
}
else if (ColorTypeComboBox.Text == Properties.Resources.HEX)
{
Expand All @@ -105,6 +106,8 @@ private void ColorTxt_TextChanged(object sender, TextChangedEventArgs e)

rgbColor = $"{rgb.R};{rgb.G};{rgb.B}"; // Set text
hexColor = $"{hex}"; // Set text
hsvColor = $"({hsv.Hue},{hsv.Saturation},{hsv.Value})"; // Set
hslColor = $"({hsl.H},{hsl.S},{hsl.L})"; // Set
}

string[] rC = rgbColor.Split(new string[] { ";" }, StringSplitOptions.None); // Split
Expand Down Expand Up @@ -159,7 +162,10 @@ private void ConvertHSV()
HSVTxt.Text = $"{Properties.Resources.HSV} ({h},{s},{v})"; // 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
hsvColor = $"({h},{s},{v})"; // Set
hslColor = $"({hsl.H},{hsl.S},{hsl.L})"; // Set

ColorDisplayer.Background = new SolidColorBrush { Color = Color.FromRgb(rgb.R, rgb.G, rgb.B) }; // Set color

Expand Down Expand Up @@ -191,6 +197,11 @@ private void ConvertHSL()
HSVTxt.Text = $"{Properties.Resources.HSV} ({hsv.H},{hsv.S},{hsv.V})"; // Set text
HSLTxt.Text = $"{Properties.Resources.HSL} ({h},{s},{l})"; // Set text

hslColor = $"({h},{s},{l})"; // Set
hsvColor = $"({hsv.H},{hsv.S},{hsv.V})"; // Set
rgbColor = $"{rgb.R};{rgb.G};{rgb.B}"; // Set
hexColor = hex.Value; // Set

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
Expand Down Expand Up @@ -225,6 +236,11 @@ private void LTxt_TextChanged(object sender, TextChangedEventArgs e)
ConvertHSL();
}

private void CopyHSLBtn_Click(object sender, RoutedEventArgs e)
{
Clipboard.SetText(hslColor);
}

private void CopyHEXBtn_Click(object sender, RoutedEventArgs e)
{
Clipboard.SetText(hexColor); // Copy
Expand Down
9 changes: 9 additions & 0 deletions 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 @@ -303,4 +303,7 @@
<data name="L" xml:space="preserve">
<value>L</value>
</data>
<data name="CopyHSL" xml:space="preserve">
<value>Copy HSL</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 @@ -303,4 +303,7 @@
<data name="L" xml:space="preserve">
<value>L</value>
</data>
<data name="CopyHSL" xml:space="preserve">
<value>Copier HSL</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 @@ -283,4 +283,7 @@
<data name="L" xml:space="preserve">
<value>L</value>
</data>
<data name="CopyHSL" xml:space="preserve">
<value>Copy HSL</value>
</data>
</root>

0 comments on commit e6020ab

Please sign in to comment.