Skip to content

Commit

Permalink
Added the possibility to convert from decimal type (#312)
Browse files Browse the repository at this point in the history
  • Loading branch information
lpeyr committed Sep 3, 2023
1 parent 0cf2234 commit e71b458
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
12 changes: 12 additions & 0 deletions ColorPicker/Pages/ConverterPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,18 @@
FontWeight="ExtraBold"
Foreground="{Binding Source={StaticResource AccentColor}}"
Style="{DynamicResource DefaultButton}" />
<Button
x:Name="DecBtn"
Margin="4 2"
Padding="5"
HorizontalContentAlignment="Stretch"
Background="Transparent"
BorderThickness="0"
Click="RgbBtn_Click"
Content="{x:Static lang:Resources.DEC}"
FontWeight="ExtraBold"
Foreground="{Binding Source={StaticResource AccentColor}}"
Style="{DynamicResource DefaultButton}" />
<Button
x:Name="XyzBtn"
Margin="4 2"
Expand Down
13 changes: 12 additions & 1 deletion ColorPicker/Pages/ConverterPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ private void UnCheckAllButtons()
XyzBtn.Background = new SolidColorBrush { Color = Colors.Transparent };
YiqBtn.Background = new SolidColorBrush { Color = Colors.Transparent };
YuvBtn.Background = new SolidColorBrush { Color = Colors.Transparent };
DecBtn.Background = new SolidColorBrush { Color = Colors.Transparent };
}

// Note: This event handler is used for all the choices
Expand Down Expand Up @@ -123,6 +124,7 @@ private RGB ConvertToRgb()
else if (SelectedColorBtn == YuvBtn) return ColorHelper.ColorConverter.YuvToRgb(new(double.Parse(Txt1.Text),
double.Parse(Txt2.Text),
double.Parse(Txt3.Text)));
else if (SelectedColorBtn == DecBtn) return new DEC(int.Parse(Txt5.Text)).ToRgb();
else return ColorHelper.ColorConverter.YiqToRgb(new(double.Parse(Txt1.Text),
double.Parse(Txt2.Text),
double.Parse(Txt3.Text)));
Expand Down Expand Up @@ -226,7 +228,7 @@ private void HideAllInput()
private void LoadInputUI()
{
HideAllInput();
if (SelectedColorBtn != HexBtn)
if (SelectedColorBtn != HexBtn && SelectedColorBtn != DecBtn)
{
DisplayText1.Visibility = Visibility.Visible;
DisplayText2.Visibility = Visibility.Visible;
Expand Down Expand Up @@ -322,6 +324,15 @@ private void LoadInputUI()
Txt2.Text = ColorInfo.YUV.U.ToString();
Txt3.Text = ColorInfo.YUV.V.ToString();
}
else if (SelectedColorBtn == DecBtn)
{
DisplayText5.Visibility = Visibility.Visible;

DisplayText5.Text = Properties.Resources.DEC;
B5.Visibility = Visibility.Visible;

Txt5.Text = ColorInfo.DEC.Value.ToString();
}
}

private void Txt1_TextChanged(object sender, TextChangedEventArgs e)
Expand Down

0 comments on commit e71b458

Please sign in to comment.