From 034a0b8f6335f37329b24e8686cf28ef608d4d8d Mon Sep 17 00:00:00 2001 From: billz Date: Wed, 29 Nov 2023 09:16:28 +0000 Subject: [PATCH] Generalize @marek-guran's lighten/darkenColor functions --- app/css/material-dark.php | 31 ---------------------------- app/css/material-light.php | 33 ------------------------------ includes/functions.php | 42 ++++++++++++++++++++++++++++++++++++-- 3 files changed, 40 insertions(+), 66 deletions(-) diff --git a/app/css/material-dark.php b/app/css/material-dark.php index e14ccea0..69c466b3 100644 --- a/app/css/material-dark.php +++ b/app/css/material-dark.php @@ -16,43 +16,12 @@ License: GNU General Public License v3.0 // Base color $baseColor = $color; -// Function to darken a color by a percentage -function darkenColor($color, $percent) -{ - $percent /= 100; - $r = hexdec(substr($color, 1, 2)); - $g = hexdec(substr($color, 3, 2)); - $b = hexdec(substr($color, 5, 2)); - - $r = round($r * (1 - $percent)); - $g = round($g * (1 - $percent)); - $b = round($b * (1 - $percent)); - - return sprintf("#%02x%02x%02x", $r, $g, $b); -} - -// Function to lighten a color by a percentage -function lightenColor($color, $percent) -{ - $percent /= 100; - $r = hexdec(substr($color, 1, 2)); - $g = hexdec(substr($color, 3, 2)); - $b = hexdec(substr($color, 5, 2)); - - $r = round($r + (255 - $r) * $percent); - $g = round($g + (255 - $g) * $percent); - $b = round($b + (255 - $b) * $percent); - - return sprintf("#%02x%02x%02x", $r, $g, $b); -} - $textColor = lightenColor($baseColor, 95); // Create other color variables $cardsColor = darkenColor($baseColor, 60); $secondaryColor = lightenColor($baseColor, 30); $primaryColor = $baseColor; $backgroundColor = darkenColor($baseColor, 90); - ?> @import url('all.css'); diff --git a/app/css/material-light.php b/app/css/material-light.php index 8ee6804e..349beb9e 100644 --- a/app/css/material-light.php +++ b/app/css/material-light.php @@ -4,7 +4,6 @@ require_once '../../includes/functions.php'; $color = getColorOpt(); ?> - /* Theme Name: Material Light Author: @marek-guran @@ -16,44 +15,12 @@ License: GNU General Public License v3.0 @import url('all.css'); diff --git a/includes/functions.php b/includes/functions.php index f909311d..ff41f124 100755 --- a/includes/functions.php +++ b/includes/functions.php @@ -715,10 +715,10 @@ function getColorOpt() $color = "#2b8080"; } else { $color = $_COOKIE['color']; - setcookie('color', $color); } return $color; } + function getSidebarState() { if(isset($_COOKIE['sidebarToggled'])) { @@ -784,7 +784,7 @@ function validate_host($host) // @return boolean function getNightmode() { - if (isset($_COOKIE['theme']) && $_COOKIE['theme'] == 'lightsout.css') { + if (isset($_COOKIE['theme']) && $_COOKIE['theme'] == 'lightsout.php') { return true; } else { return false; @@ -924,3 +924,41 @@ function checkReleaseVersion($installed, $latest) { return false; } +/** + * Function to darken a color by a percentage + * From @marek-guran's material-dark theme for RaspAP + * Author URI: https://github.com/marek-guran + */ +function darkenColor($color, $percent) +{ + $percent /= 100; + $r = hexdec(substr($color, 1, 2)); + $g = hexdec(substr($color, 3, 2)); + $b = hexdec(substr($color, 5, 2)); + + $r = round($r * (1 - $percent)); + $g = round($g * (1 - $percent)); + $b = round($b * (1 - $percent)); + + return sprintf("#%02x%02x%02x", $r, $g, $b); +} + +/** + * Function to lighten a color by a percentage + * From @marek-guran's material-dark theme for RaspAP + * Author URI: https://github.com/marek-guran + */ +function lightenColor($color, $percent) +{ + $percent /= 100; + $r = hexdec(substr($color, 1, 2)); + $g = hexdec(substr($color, 3, 2)); + $b = hexdec(substr($color, 5, 2)); + + $r = round($r + (255 - $r) * $percent); + $g = round($g + (255 - $g) * $percent); + $b = round($b + (255 - $b) * $percent); + + return sprintf("#%02x%02x%02x", $r, $g, $b); +} +