Skip to content

Commit

Permalink
barevna responzivita podle loga obce
Browse files Browse the repository at this point in the history
  • Loading branch information
martinrotter committed Mar 1, 2024
1 parent 2b4fd96 commit 94aaab0
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 3 deletions.
3 changes: 3 additions & 0 deletions ZZZO/ZZZO/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
<ResourceDictionary>
<Thickness x:Key="FormMargin">9,9,9,9</Thickness>

<Color x:Key="ThemeColorMain">#59C9A5</Color>
<Color x:Key="ThemeColorAccent">#D81E5B</Color>

<Style BasedOn="{StaticResource {x:Type Button}}"
TargetType="{x:Type Button}">
<Setter Property="Margin"
Expand Down
58 changes: 55 additions & 3 deletions ZZZO/ZZZO/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using System.Globalization;
using System.Windows;
using System.Windows.Media.Imaging;
using CefSharp;
using CefSharp.Wpf;
using MaterialDesignThemes.Wpf;
using ZZZO.Common.API;
using ZZZO.ViewModels;
using ZZZO.Windows;
using Color = System.Windows.Media.Color;
Expand Down Expand Up @@ -67,13 +69,63 @@ protected override void OnStartup(StartupEventArgs e)
// CefSharp.
Cef.Initialize(new CefSettings());

Core.PropertyChanged += (sender, args) =>
{
if (args.PropertyName == nameof(ZzzoCore.Zasedani))
{
if (Core.Zasedani != null)
{
AktualizovatBarvy(Core.Zasedani.LogoObce);
Core.Zasedani.PropertyChanged += (o, zasArgs) =>
{
if (zasArgs.PropertyName == nameof(Zasedani.LogoObce))
{
AktualizovatBarvy(Core.Zasedani.LogoObce);
}
};
}
else
{
SetDefaultTheme();
}
}
};

// Theme.
SetDefaultTheme();
}

private void SetDefaultTheme()
{
AdjustThemeContrastAndColors(
(Color)ColorConverter.ConvertFromString("#59C9A5"),
(Color)ColorConverter.ConvertFromString("#D81E5B"));
(Color)FindResource("ThemeColorMain"),
(Color)FindResource("ThemeColorAccent"));
}

private void AktualizovatBarvy(BitmapImage zasedaniLogoObce)
{
if (zasedaniLogoObce == null)
{
SetDefaultTheme();
return;
}

try
{
var clrs = ColorImageSearcher.Get2MostUsedColors(Core.Zasedani.LogoObce).ToArray();

App.Current.AdjustThemeContrastAndColors(
clrs[0],
clrs[1]);
}
catch
{
//
}
}

private void AdjustThemeContrastAndColors(Color primary = default, Color secondary = default)
public void AdjustThemeContrastAndColors(Color primary = default, Color secondary = default)
{
PaletteHelper a = new PaletteHelper();
Theme b = a.GetTheme() as Theme;
Expand Down
4 changes: 4 additions & 0 deletions ZZZO/ZZZO/ViewModels/BasicInfoViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
using System.Collections.Specialized;
using System.ComponentModel;
using System.IO;
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using MaterialDesignThemes.Wpf;
using Microsoft.Win32;
using ZZZO.Commands;
Expand Down
1 change: 1 addition & 0 deletions ZZZO/ZZZO/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Windows;
using System.Windows.Automation.Peers;
using System.Windows.Input;
using System.Windows.Media.Imaging;
using MaterialDesignThemes.Wpf;
using ZZZO.Commands;
using ZZZO.Common.API;
Expand Down

0 comments on commit 94aaab0

Please sign in to comment.