From f57eab300848365618caa2233269e942bfbec7bf Mon Sep 17 00:00:00 2001 From: d11n Date: Thu, 9 Mar 2023 21:34:15 +0100 Subject: [PATCH] Store branding: Add complementing text and accent colors (#4746) --- BTCPayServer/ColorPalette.cs | 39 +++++++++++++++++++ .../Shared/LayoutHeadStoreBranding.cshtml | 17 +++++--- .../Views/UIStores/GeneralSettings.cshtml | 2 +- 3 files changed, 52 insertions(+), 6 deletions(-) diff --git a/BTCPayServer/ColorPalette.cs b/BTCPayServer/ColorPalette.cs index 78cc94895..8e7e09ef0 100644 --- a/BTCPayServer/ColorPalette.cs +++ b/BTCPayServer/ColorPalette.cs @@ -59,5 +59,44 @@ namespace BTCPayServer return Labels[num % Labels.Length]; } } + + /// https://gist.github.com/zihotki/09fc41d52981fb6f93a81ebf20b35cd5 + /// + /// Creates color with corrected brightness. + /// + /// Color to correct. + /// The brightness correction factor. Must be between -1 and 1. + /// Negative values produce darker colors. + /// + /// Corrected structure. + /// + public Color AdjustBrightness(Color color, float correctionFactor) + { + float red = color.R; + float green = color.G; + float blue = color.B; + + if (correctionFactor < 0) + { + correctionFactor = 1 + correctionFactor; + red *= correctionFactor; + green *= correctionFactor; + blue *= correctionFactor; + } + else + { + red = (255 - red) * correctionFactor + red; + green = (255 - green) * correctionFactor + green; + blue = (255 - blue) * correctionFactor + blue; + } + + return Color.FromArgb(color.A, (int)red, (int)green, (int)blue); + } + + public string AdjustBrightness(string html, float correctionFactor) + { + var color = AdjustBrightness(ColorTranslator.FromHtml(html), correctionFactor); + return ColorTranslator.ToHtml(color); + } } } diff --git a/BTCPayServer/Views/Shared/LayoutHeadStoreBranding.cshtml b/BTCPayServer/Views/Shared/LayoutHeadStoreBranding.cshtml index 8f585dd61..e4c0b7045 100644 --- a/BTCPayServer/Views/Shared/LayoutHeadStoreBranding.cshtml +++ b/BTCPayServer/Views/Shared/LayoutHeadStoreBranding.cshtml @@ -10,13 +10,20 @@ } @if (!string.IsNullOrEmpty(Model.BrandColor)) { + var brandColor = Model.BrandColor; + var accentColor = ColorPalette.Default.AdjustBrightness(brandColor, (float)-0.15); + var complement = ColorPalette.Default.TextColor(brandColor).ToLowerInvariant(); + var complementColor = $"var(--btcpay-{(complement == "black" ? "black" : "white")})"; } diff --git a/BTCPayServer/Views/UIStores/GeneralSettings.cshtml b/BTCPayServer/Views/UIStores/GeneralSettings.cshtml index b354001bd..c7d2f0730 100644 --- a/BTCPayServer/Views/UIStores/GeneralSettings.cshtml +++ b/BTCPayServer/Views/UIStores/GeneralSettings.cshtml @@ -38,7 +38,7 @@
- +