Skip to content

Commit

Permalink
Added Decimal color type in Text tool (#311)
Browse files Browse the repository at this point in the history
  • Loading branch information
Leo-Peyronnet committed Sep 2, 2023
1 parent 56d086b commit 93866ba
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
12 changes: 12 additions & 0 deletions ColorPicker/Pages/TextPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,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
15 changes: 13 additions & 2 deletions ColorPicker/Pages/TextPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,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 @@ -285,7 +286,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 @@ -379,6 +380,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 Expand Up @@ -420,7 +430,7 @@ private void Txt1_PreviewExecuted(object sender, ExecutedRoutedEventArgs e)
Txt3.Text = split[2];
Txt4.Text = split.Length > 3 ? split[3] : "";
}
else if (SelectedColorBtn == HexBtn)
else if (SelectedColorBtn == HexBtn || SelectedColorBtn == DecBtn)
{
Txt5.Text = text;
}
Expand Down Expand Up @@ -518,6 +528,7 @@ private ColorHelper.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

0 comments on commit 93866ba

Please sign in to comment.