From 00c5a6c4f13579bc9e9b96669adac9c75ab208ab Mon Sep 17 00:00:00 2001 From: krlvm <51774833+krlvm@users.noreply.github.com> Date: Wed, 13 Jul 2022 20:23:30 +0300 Subject: [PATCH] Fix colorization with marginal accent color (#7) --- AccentColorizer/AccentColorHelper.cpp | 3 --- AccentColorizer/ColorHelper.cpp | 11 +++++++++++ AccentColorizer/ColorHelper.h | 4 +++- AccentColorizer/StyleModifier.cpp | 4 +--- AccentColorizer/SysColorsModifier.cpp | 26 ++++++++++++++++++-------- 5 files changed, 33 insertions(+), 15 deletions(-) diff --git a/AccentColorizer/AccentColorHelper.cpp b/AccentColorizer/AccentColorHelper.cpp index 6f0a1a0..027588b 100644 --- a/AccentColorizer/AccentColorHelper.cpp +++ b/AccentColorizer/AccentColorHelper.cpp @@ -30,9 +30,6 @@ bool InitializeDwmApi() return TRUE; } -#include -#include - COLORREF accent; COLORREF accentOpaque; bool accentOpaqueAvailable; diff --git a/AccentColorizer/ColorHelper.cpp b/AccentColorizer/ColorHelper.cpp index 88e9a23..cad1603 100644 --- a/AccentColorizer/ColorHelper.cpp +++ b/AccentColorizer/ColorHelper.cpp @@ -103,4 +103,15 @@ rgb hsv2rgb(hsv in) break; } return out; +} + +int GetHSVh(COLORREF dwColor) +{ + rgb rgbVal = { + (double)GetRValue(dwColor), + (double)GetGValue(dwColor), + (double)GetBValue(dwColor) + }; + hsv hsvVal = rgb2hsv(rgbVal); + return hsvVal.h; } \ No newline at end of file diff --git a/AccentColorizer/ColorHelper.h b/AccentColorizer/ColorHelper.h index 086171d..1de2636 100644 --- a/AccentColorizer/ColorHelper.h +++ b/AccentColorizer/ColorHelper.h @@ -14,4 +14,6 @@ typedef struct { } hsv; hsv rgb2hsv(rgb in); -rgb hsv2rgb(hsv in); \ No newline at end of file +rgb hsv2rgb(hsv in); + +int GetHSVh(COLORREF dwColor); \ No newline at end of file diff --git a/AccentColorizer/StyleModifier.cpp b/AccentColorizer/StyleModifier.cpp index d132a11..326990f 100644 --- a/AccentColorizer/StyleModifier.cpp +++ b/AccentColorizer/StyleModifier.cpp @@ -296,9 +296,7 @@ void ModifyStyles() { void ModifyStyles(COLORREF accentColor) { - rgb rgbAccent = { GetRValue(accentColor), GetGValue(accentColor), GetBValue(accentColor) }; - hsv hsvAccent = rgb2hsv(rgbAccent); - hsvAccentH = hsvAccent.h; + hsvAccentH = GetHSVh(accentColor); ModifyStyles(); } \ No newline at end of file diff --git a/AccentColorizer/SysColorsModifier.cpp b/AccentColorizer/SysColorsModifier.cpp index 9a2a1a8..ff00545 100644 --- a/AccentColorizer/SysColorsModifier.cpp +++ b/AccentColorizer/SysColorsModifier.cpp @@ -2,10 +2,12 @@ #include "ColorHelper.h" #include "AccentColorHelper.h" -const int size = 5; +#define SYS_COLORS_SIZE 5 -void ModifySysColors(COLORREF accentColor) { - int aElements[size] = +void ModifySysColors(COLORREF dwAccentColor) { + int hsvAccentH = GetHSVh(dwAccentColor); + + int aElements[SYS_COLORS_SIZE] = { COLOR_ACTIVECAPTION, COLOR_GRADIENTACTIVECAPTION, @@ -13,13 +15,21 @@ void ModifySysColors(COLORREF accentColor) { COLOR_HOTLIGHT, COLOR_MENUHILIGHT }; - DWORD aNewColors[size]; + DWORD aNewColors[SYS_COLORS_SIZE]; - COLORREF color = RGB(GetRValue(accentColor), GetGValue(accentColor), GetBValue(accentColor)); - for (int i = 0; i < size; i++) + for (int i = 0; i < SYS_COLORS_SIZE; i++) { - aNewColors[i] = color; + COLORREF dwCurrentColor = GetSysColor(aElements[i]); + + rgb rgbVal = rgb{ (double)GetRValue(dwCurrentColor), (double)GetGValue(dwCurrentColor), (double)GetBValue(dwCurrentColor) }; + hsv hsvVal = rgb2hsv(rgbVal); + + hsvVal.h = hsvAccentH; + + rgbVal = hsv2rgb(hsvVal); + + aNewColors[i] = RGB(rgbVal.r, rgbVal.g, rgbVal.b); } - SetSysColors(size, aElements, aNewColors); + SetSysColors(SYS_COLORS_SIZE, aElements, aNewColors); } \ No newline at end of file