Skip to content

Commit

Permalink
Added contrast quick action (#372)
Browse files Browse the repository at this point in the history
  • Loading branch information
Leo-Peyronnet committed Feb 20, 2024
1 parent 39ba77d commit 37c06df
Show file tree
Hide file tree
Showing 7 changed files with 218 additions and 0 deletions.
147 changes: 147 additions & 0 deletions ColorPicker/Pages/HomePage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
xmlns:lang="clr-namespace:ColorPicker.Properties"
xmlns:local="clr-namespace:ColorPicker.Pages"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
x:Name="Home"
Title="HomePage"
d:Background="White"
d:DesignHeight="450"
Expand Down Expand Up @@ -103,6 +104,33 @@
Text="{x:Static lang:Resources.SelectColor}" />
</StackPanel>
</Border>
<Border
x:Name="Contrast"
Margin="5 0"
Background="{DynamicResource LightAccentColor}"
CornerRadius="15"
Cursor="Hand"
MouseLeftButtonUp="Contrast_MouseLeftButtonUp">
<StackPanel
Margin="10 5"
VerticalAlignment="Center"
Orientation="Horizontal">
<TextBlock
VerticalAlignment="Center"
FontFamily="../Fonts/#FluentSystemIcons-Filled"
FontSize="16"
Foreground="{DynamicResource AccentColor}"
Text="&#xFD1B;" />
<TextBlock
Margin="10 0 0 0"
VerticalAlignment="Center"
FontFamily="../Fonts/#Hauora"
FontSize="14"
FontWeight="ExtraBold"
Foreground="{DynamicResource AccentColor}"
Text="{x:Static lang:Resources.GetContrast}" />
</StackPanel>
</Border>
</WrapPanel>

<StackPanel
Expand All @@ -127,5 +155,124 @@
x:Name="DiscoverPanel"
Grid.Row="6"
Orientation="Horizontal" />

<Popup
x:Name="ContrastPopup"
AllowsTransparency="True"
Placement="Center"
PlacementTarget="{Binding ElementName=Home}"
PopupAnimation="Fade"
StaysOpen="False">
<Border
Margin="10"
Padding="10"
Background="{DynamicResource Background1}"
CornerRadius="5">
<Border.Effect>
<DropShadowEffect
BlurRadius="10"
Opacity="0.4"
RenderingBias="Performance"
ShadowDepth="0"
Color="Black" />
</Border.Effect>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<TextBlock
VerticalAlignment="Center"
FontWeight="Bold"
Text="{x:Static lang:Resources.FirstColor}" />
<Border
Grid.Column="1"
Width="100"
Margin="5 0"
HorizontalAlignment="Center"
Background="{DynamicResource CardBackground}"
CornerRadius="5">
<Border.Effect>
<DropShadowEffect
BlurRadius="15"
Opacity="0.2"
ShadowDepth="0"
Color="{DynamicResource Accent}" />
</Border.Effect>
<TextBox
x:Name="Color1Txt"
Margin="3"
Padding="3"
Background="Transparent"
BorderThickness="0"
FontWeight="Bold"
Foreground="{DynamicResource DarkGray}" />
</Border>
<TextBlock
Grid.Row="1"
VerticalAlignment="Center"
FontWeight="Bold"
Text="{x:Static lang:Resources.SecondColor}" />
<Border
Grid.Row="1"
Grid.Column="1"
Width="100"
Margin="5 0"
HorizontalAlignment="Center"
Background="{DynamicResource CardBackground}"
CornerRadius="5">
<Border.Effect>
<DropShadowEffect
BlurRadius="15"
Opacity="0.2"
ShadowDepth="0"
Color="{DynamicResource Accent}" />
</Border.Effect>
<TextBox
x:Name="Color2Txt"
Margin="3"
Padding="3"
Background="Transparent"
BorderThickness="0"
FontWeight="Bold"
Foreground="{DynamicResource DarkGray}" />
</Border>
<Border
x:Name="ContrastBorder"
Grid.Row="2"
Grid.ColumnSpan="2"
Margin="5"
Padding="5"
Background="{DynamicResource AccentColor}"
CornerRadius="5">
<TextBlock
x:Name="ContrastTxt"
HorizontalAlignment="Center"
FontWeight="Bold"
Foreground="{DynamicResource WindowButtonsHoverForeground1}"
Text="{x:Static lang:Resources.Contrast}" />
</Border>
<Button
x:Name="GetContrastBtn"
Grid.Row="3"
Grid.ColumnSpan="2"
Margin="5"
Padding="3"
HorizontalAlignment="Center"
Background="{DynamicResource LightAccentColor}"
Click="GetContrastBtn_Click"
Content="{x:Static lang:Resources.GetContrast}"
FontWeight="Bold"
Foreground="{DynamicResource AccentColor}"
Style="{DynamicResource DefaultButton}" />
</Grid>
</Border>
</Popup>
</Grid>
</Page>
29 changes: 29 additions & 0 deletions ColorPicker/Pages/HomePage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ MIT License
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
using ColorHelper;
using ColorPicker.Classes;
using ColorPicker.UserControls;
using Synethia;
using System.Collections.Generic;
using System.Windows.Controls;
using System.Windows.Media;

namespace ColorPicker.Pages;
/// <summary>
Expand Down Expand Up @@ -65,4 +67,31 @@ private void SelectColor_MouseLeftButtonUp(object sender, System.Windows.Input.M
{
Global.SelectorPage.SelectBtn_Click(sender, e);
}

private void GetContrastBtn_Click(object sender, System.Windows.RoutedEventArgs e)
{
try
{
var color1 = ColorHelper.ColorConverter.HexToRgb(new(Color1Txt.Text));
var color2 = ColorHelper.ColorConverter.HexToRgb(new(Color2Txt.Text));
var contrast = Global.GetContrast(new int[] { color1.R, color1.G, color1.B }, new int[] { color2.R, color2.G, color2.B });
ContrastTxt.Text = $"{Properties.Resources.Contrast}: {contrast.Item1}";
ContrastBorder.Background = contrast.Item2 switch
{
0 => Global.GetColorFromResource("Green"),
1 => Global.GetColorFromResource("SliderBlue"),
2 => Global.GetColorFromResource("Orange"),
_ => Global.GetColorFromResource("Red"),
};
}
catch
{

}
}

private void Contrast_MouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
ContrastPopup.IsOpen = true;
}
}
18 changes: 18 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.

6 changes: 6 additions & 0 deletions ColorPicker/Properties/Resources.en-US.resx
Original file line number Diff line number Diff line change
Expand Up @@ -648,4 +648,10 @@
<data name="AmountToGenerate" xml:space="preserve">
<value>Amount to generate</value>
</data>
<data name="FirstColor" xml:space="preserve">
<value>First color</value>
</data>
<data name="SecondColor" xml:space="preserve">
<value>Second color</value>
</data>
</root>
6 changes: 6 additions & 0 deletions ColorPicker/Properties/Resources.fr-FR.resx
Original file line number Diff line number Diff line change
Expand Up @@ -652,4 +652,10 @@
<data name="AmountToGenerate" xml:space="preserve">
<value>Nombre de couleurs à générer</value>
</data>
<data name="FirstColor" xml:space="preserve">
<value>Première couleur</value>
</data>
<data name="SecondColor" xml:space="preserve">
<value>Seconde couleur</value>
</data>
</root>
6 changes: 6 additions & 0 deletions ColorPicker/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -628,4 +628,10 @@
<data name="AmountToGenerate" xml:space="preserve">
<value>Amount to generate</value>
</data>
<data name="FirstColor" xml:space="preserve">
<value>First color</value>
</data>
<data name="SecondColor" xml:space="preserve">
<value>Second color</value>
</data>
</root>
6 changes: 6 additions & 0 deletions ColorPicker/Properties/Resources.zh-CN.resx
Original file line number Diff line number Diff line change
Expand Up @@ -656,4 +656,10 @@
<data name="AmountToGenerate" xml:space="preserve">
<value>产生金额</value>
</data>
<data name="FirstColor" xml:space="preserve">
<value>第一种颜色</value>
</data>
<data name="SecondColor" xml:space="preserve">
<value>第一种颜色</value>
</data>
</root>

0 comments on commit 37c06df

Please sign in to comment.