Skip to content

Commit

Permalink
Added instant theme switching (#353)
Browse files Browse the repository at this point in the history
  • Loading branch information
lpeyr committed Dec 10, 2023
1 parent 8c9a8a9 commit 9394770
Show file tree
Hide file tree
Showing 42 changed files with 863 additions and 883 deletions.
94 changes: 47 additions & 47 deletions ColorPicker/App.xaml

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion ColorPicker/Classes/Global.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
using ColorHelper;
using ColorPicker.Enums;
using ColorPicker.Pages;
using ColorPicker.Properties;
using Microsoft.Win32;
using PeyrSharp.Enums;
using PeyrSharp.Env;
Expand Down Expand Up @@ -161,7 +162,7 @@ public static System.Drawing.Color GenerateRandomColorDrawing()
int r = random.Next(0, 255); int g = random.Next(0, 255); int b = random.Next(0, 255); // Generate random values
return System.Drawing.Color.FromArgb(r, g, b);
}
public static Color GetColorFromResource(string resourceName) => (Color)System.Windows.Media.ColorConverter.ConvertFromString(Application.Current.Resources[resourceName].ToString());
public static SolidColorBrush GetColorFromResource(string resource) => (SolidColorBrush)Application.Current.Resources[resource];

public static double GetLuminance(int r, int g, int b)
{
Expand Down
56 changes: 27 additions & 29 deletions ColorPicker/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
AllowsTransparency="True"
Background="Transparent"
FontFamily="/Fonts/#Hauora"
Foreground="{Binding Source={StaticResource Foreground1}}"
Foreground="{DynamicResource Foreground1}"
Icon="Images/CPM.png"
ResizeMode="CanResize"
WindowStartupLocation="CenterScreen"
Expand Down Expand Up @@ -54,10 +54,10 @@
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="true">
<Setter TargetName="border" Property="Background" Value="{Binding Source={StaticResource WindowButtonsHover1}}" />
<Setter TargetName="border" Property="Background" Value="{DynamicResource WindowButtonsHover1}" />
</Trigger>
<Trigger Property="IsPressed" Value="true">
<Setter TargetName="border" Property="Background" Value="{Binding Source={StaticResource WindowButtonsPressed1}}" />
<Setter TargetName="border" Property="Background" Value="{DynamicResource WindowButtonsPressed1}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
Expand Down Expand Up @@ -116,11 +116,9 @@
Name="WindowBorder"
Margin="10"
d:Background="#fff"
Background="{DynamicResource BackgroundImg}"
BorderThickness="0"
CornerRadius="5">
<Border.Background>
<ImageBrush ImageSource="{Binding Source={StaticResource BackgroundImg}}" />
</Border.Background>
<Grid VerticalAlignment="Stretch">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
Expand All @@ -141,14 +139,14 @@
Grid.Column="1"
Padding="5 2"
VerticalAlignment="Center"
Background="{Binding Source={StaticResource CardBackground}}"
Background="{DynamicResource CardBackground}"
CornerRadius="10">
<TextBlock
x:Name="VersionTxt"
d:Text="5.4.0.2308"
FontSize="10"
FontWeight="SemiBold"
Foreground="{Binding Source={StaticResource DarkGray}}" />
Foreground="{DynamicResource DarkGray}" />
</Border>
<Button
x:Name="PinBtn"
Expand All @@ -160,7 +158,7 @@
Content="&#xF602;"
FontFamily="/Fonts/#FluentSystemIcons-Regular"
FontSize="14"
Foreground="{Binding Source={StaticResource Foreground1}}"
Foreground="{DynamicResource Foreground1}"
RenderOptions.EdgeMode="Aliased"
Style="{StaticResource TitleBarButtonStyle}" />
<Button
Expand All @@ -173,7 +171,7 @@
Content="&#xFC75;"
FontFamily="/Fonts/#FluentSystemIcons-Regular"
FontSize="14"
Foreground="{Binding Source={StaticResource Foreground1}}"
Foreground="{DynamicResource Foreground1}"
RenderOptions.EdgeMode="Aliased"
Style="{StaticResource TitleBarButtonStyle}" />
<Button
Expand All @@ -186,7 +184,7 @@
Content="&#xFA40;"
FontFamily="/Fonts/#FluentSystemIcons-Regular"
FontSize="14"
Foreground="{Binding Source={StaticResource Foreground1}}"
Foreground="{DynamicResource Foreground1}"
RenderOptions.EdgeMode="Aliased"
Style="{StaticResource TitleBarButtonStyle}" />
<Button
Expand All @@ -199,7 +197,7 @@
Content="&#xF36B;"
FontFamily="/Fonts/#FluentSystemIcons-Regular"
FontSize="14"
Foreground="{Binding Source={StaticResource Foreground1}}"
Foreground="{DynamicResource Foreground1}"
RenderOptions.EdgeMode="Aliased"
Style="{StaticResource TitleBarCloseButtonStyle}" />
</Grid>
Expand Down Expand Up @@ -267,7 +265,7 @@
VerticalAlignment="Center"
FontFamily="/Fonts/#FluentSystemIcons-Filled"
FontSize="18"
Foreground="{Binding Source={StaticResource WindowButtonsHoverForeground1}}"
Foreground="{DynamicResource WindowButtonsHoverForeground1}"
Text="&#xF488;" />
</Border>
<TextBlock
Expand All @@ -276,7 +274,7 @@
VerticalAlignment="Center"
FontSize="14"
FontWeight="Bold"
Foreground="{Binding Source={StaticResource Foreground1}}"
Foreground="{DynamicResource Foreground1}"
Text="{x:Static lang:Resources.Home}" />
</Grid>

Expand Down Expand Up @@ -325,7 +323,7 @@
VerticalAlignment="Center"
FontFamily="/Fonts/#FluentSystemIcons-Filled"
FontSize="18"
Foreground="{Binding Source={StaticResource WindowButtonsHoverForeground1}}"
Foreground="{DynamicResource WindowButtonsHoverForeground1}"
RenderTransformOrigin="0.5,0.5"
Text="&#xF1F6;" />
</Border>
Expand All @@ -335,7 +333,7 @@
VerticalAlignment="Center"
FontSize="14"
FontWeight="Bold"
Foreground="{Binding Source={StaticResource Foreground1}}"
Foreground="{DynamicResource Foreground1}"
Text="{x:Static lang:Resources.Bookmarks}" />
</Grid>

Expand Down Expand Up @@ -380,7 +378,7 @@
x:Name="SettingsIconTxt"
FontFamily="/Fonts/#FluentSystemIcons-Filled"
FontSize="18"
Foreground="{Binding Source={StaticResource WindowButtonsHoverForeground1}}"
Foreground="{DynamicResource WindowButtonsHoverForeground1}"
RenderTransformOrigin="0.5,0.5"
Text="&#xF6B3;">
<TextBlock.RenderTransform>
Expand All @@ -396,7 +394,7 @@
VerticalAlignment="Center"
FontSize="14"
FontWeight="Bold"
Foreground="{Binding Source={StaticResource Foreground1}}"
Foreground="{DynamicResource Foreground1}"
Text="{x:Static lang:Resources.Settings}" />
</Grid>

Expand Down Expand Up @@ -436,7 +434,7 @@
Background="Transparent"
BorderThickness="0"
Click="PickerBtn_Click"
Foreground="{Binding Source={StaticResource AccentColor}}"
Foreground="{DynamicResource AccentColor}"
Style="{DynamicResource DefaultButton}">
<Grid>
<Grid.ColumnDefinitions>
Expand Down Expand Up @@ -501,7 +499,7 @@
Content="{x:Static lang:Resources.Selector}"
FontSize="10"
FontWeight="ExtraBold"
Foreground="{Binding Source={StaticResource AccentColor}}"
Foreground="{DynamicResource AccentColor}"
Style="{DynamicResource DefaultButton}" />
<Button
x:Name="ChromaticPageBtn"
Expand All @@ -514,7 +512,7 @@
Content="{x:Static lang:Resources.ChromaticWheel}"
FontSize="10"
FontWeight="ExtraBold"
Foreground="{Binding Source={StaticResource AccentColor}}"
Foreground="{DynamicResource AccentColor}"
Style="{DynamicResource DefaultButton}" />
</StackPanel>
<Button
Expand All @@ -526,7 +524,7 @@
Background="Transparent"
BorderThickness="0"
Click="ColorToolsBtn_Click"
Foreground="{Binding Source={StaticResource AccentColor}}"
Foreground="{DynamicResource AccentColor}"
Style="{DynamicResource DefaultButton}">
<Grid>
<Grid.ColumnDefinitions>
Expand Down Expand Up @@ -591,7 +589,7 @@
Content="{x:Static lang:Resources.Converter}"
FontSize="10"
FontWeight="ExtraBold"
Foreground="{Binding Source={StaticResource AccentColor}}"
Foreground="{DynamicResource AccentColor}"
Style="{DynamicResource DefaultButton}" />
<Button
x:Name="TextPageBtn"
Expand All @@ -604,7 +602,7 @@
Content="{x:Static lang:Resources.TextTool}"
FontSize="10"
FontWeight="ExtraBold"
Foreground="{Binding Source={StaticResource AccentColor}}"
Foreground="{DynamicResource AccentColor}"
Style="{DynamicResource DefaultButton}" />
</StackPanel>
<Button
Expand All @@ -616,7 +614,7 @@
Background="Transparent"
BorderThickness="0"
Click="CreationBtn_Click"
Foreground="{Binding Source={StaticResource AccentColor}}"
Foreground="{DynamicResource AccentColor}"
Style="{DynamicResource DefaultButton}">
<Grid>
<Grid.ColumnDefinitions>
Expand Down Expand Up @@ -687,7 +685,7 @@
Content="{x:Static lang:Resources.Palette}"
FontSize="10"
FontWeight="ExtraBold"
Foreground="{Binding Source={StaticResource AccentColor}}"
Foreground="{DynamicResource AccentColor}"
Style="{DynamicResource DefaultButton}" />
<Button
x:Name="HarmoniesPageBtn"
Expand All @@ -700,7 +698,7 @@
Content="{x:Static lang:Resources.Harmonies}"
FontSize="10"
FontWeight="ExtraBold"
Foreground="{Binding Source={StaticResource AccentColor}}"
Foreground="{DynamicResource AccentColor}"
Style="{DynamicResource DefaultButton}" />
<Button
x:Name="GradientPageBtn"
Expand All @@ -713,7 +711,7 @@
Content="{x:Static lang:Resources.Gradient}"
FontSize="10"
FontWeight="ExtraBold"
Foreground="{Binding Source={StaticResource AccentColor}}"
Foreground="{DynamicResource AccentColor}"
Style="{DynamicResource DefaultButton}" />
<Button
x:Name="AiCreationPageBtn"
Expand All @@ -726,7 +724,7 @@
Content="{x:Static lang:Resources.AIGeneration}"
FontSize="10"
FontWeight="ExtraBold"
Foreground="{Binding Source={StaticResource AccentColor}}"
Foreground="{DynamicResource AccentColor}"
Style="{DynamicResource DefaultButton}" />
</StackPanel>
</StackPanel>
Expand Down
22 changes: 11 additions & 11 deletions ColorPicker/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -360,12 +360,12 @@ private void CheckButton(Button button, bool isSpecial = false)
{
if (isSpecial)
{
button.Background = new SolidColorBrush(Global.GetColorFromResource("Background1"));
button.Background = Global.GetColorFromResource("Background1");
}
else
{
button.Background = new SolidColorBrush(Global.GetColorFromResource("AccentColor"));
button.Foreground = new SolidColorBrush(Global.GetColorFromResource("WindowButtonsHoverForeground1"));
button.Background = Global.GetColorFromResource("AccentColor");
button.Foreground = Global.GetColorFromResource("WindowButtonsHoverForeground1");
}
}

Expand All @@ -385,14 +385,14 @@ private void UnCheckAllButton()
AiCreationPageBtn.Background = new SolidColorBrush(Colors.Transparent);
HarmoniesPageBtn.Background = new SolidColorBrush(Colors.Transparent);

SelectorPageBtn.Foreground = new SolidColorBrush(Global.GetColorFromResource("AccentColor"));
ChromaticPageBtn.Foreground = new SolidColorBrush(Global.GetColorFromResource("AccentColor"));
ConverterPageBtn.Foreground = new SolidColorBrush(Global.GetColorFromResource("AccentColor"));
TextPageBtn.Foreground = new SolidColorBrush(Global.GetColorFromResource("AccentColor"));
PalettePageBtn.Foreground = new SolidColorBrush(Global.GetColorFromResource("AccentColor"));
GradientPageBtn.Foreground = new SolidColorBrush(Global.GetColorFromResource("AccentColor"));
AiCreationPageBtn.Foreground = new SolidColorBrush(Global.GetColorFromResource("AccentColor"));
HarmoniesPageBtn.Foreground = new SolidColorBrush(Global.GetColorFromResource("AccentColor"));
SelectorPageBtn.Foreground = Global.GetColorFromResource("AccentColor");
ChromaticPageBtn.Foreground = Global.GetColorFromResource("AccentColor");
ConverterPageBtn.Foreground = Global.GetColorFromResource("AccentColor");
TextPageBtn.Foreground = Global.GetColorFromResource("AccentColor");
PalettePageBtn.Foreground = Global.GetColorFromResource("AccentColor");
GradientPageBtn.Foreground = Global.GetColorFromResource("AccentColor");
AiCreationPageBtn.Foreground = Global.GetColorFromResource("AccentColor");
HarmoniesPageBtn.Foreground = Global.GetColorFromResource("AccentColor");
}

private void ColorToolsBtn_Click(object sender, RoutedEventArgs e)
Expand Down
Loading

0 comments on commit 9394770

Please sign in to comment.