diff options
author | Evgeny Zinoviev <me@ch1p.io> | 2022-07-11 15:01:02 +0300 |
---|---|---|
committer | Evgeny Zinoviev <me@ch1p.io> | 2022-07-11 15:01:02 +0300 |
commit | c2f382aba86aaebb9806ff1b43c1af69992e9a10 (patch) | |
tree | aee205721fd675926c5e7163eec0dddc448f7813 /engine | |
parent | 24982a48f570b89e537850dda4a4d1ac33ea919f (diff) |
support dark mode for images with alpha channel
Diffstat (limited to 'engine')
-rw-r--r-- | engine/Skin.php | 4 | ||||
-rw-r--r-- | engine/themes.php | 38 |
2 files changed, 40 insertions, 2 deletions
diff --git a/engine/Skin.php b/engine/Skin.php index 917eef7..a8924d4 100644 --- a/engine/Skin.php +++ b/engine/Skin.php @@ -23,8 +23,8 @@ class Skin { else $js = null; - $theme = ($_COOKIE['theme'] ?? 'auto'); - if (!in_array($theme, ['auto', 'dark', 'light'])) + $theme = themes::getUserTheme(); + if ($theme != 'auto' && !themes::themeExists($theme)) $theme = 'auto'; $layout_ctx = new SkinContext('\\skin\\base'); diff --git a/engine/themes.php b/engine/themes.php new file mode 100644 index 0000000..839377f --- /dev/null +++ b/engine/themes.php @@ -0,0 +1,38 @@ +<?php + +class themes { + + public static array $Themes = [ + 'dark' => [ + 'bg' => 0x222222, + // 'alpha' => 0x303132, + 'alpha' => 0x222222, + ], + 'light' => [ + 'bg' => 0xffffff, + // 'alpha' => 0xf2f2f2, + 'alpha' => 0xffffff, + ] + ]; + + public static function getThemes(): array { + return array_keys(self::$Themes); + } + + public static function themeExists(string $name): bool { + return array_key_exists($name, self::$Themes); + } + + public static function getThemeAlphaColorAsRGB(string $name): array { + $color = self::$Themes[$name]['alpha']; + $r = ($color >> 16) & 0xff; + $g = ($color >> 8) & 0xff; + $b = $color & 0xff; + return [$r, $g, $b]; + } + + public static function getUserTheme(): string { + return ($_COOKIE['theme'] ?? 'auto'); + } + +}
\ No newline at end of file |