Skip to content

Commit

Permalink
Fix colorization with marginal accent color (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
krlvm committed Jul 13, 2022
1 parent 5935270 commit 00c5a6c
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 15 deletions.
3 changes: 0 additions & 3 deletions AccentColorizer/AccentColorHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ bool InitializeDwmApi()
return TRUE;
}

#include <io.h>
#include <fcntl.h>

COLORREF accent;
COLORREF accentOpaque;
bool accentOpaqueAvailable;
Expand Down
11 changes: 11 additions & 0 deletions AccentColorizer/ColorHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
4 changes: 3 additions & 1 deletion AccentColorizer/ColorHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ typedef struct {
} hsv;

hsv rgb2hsv(rgb in);
rgb hsv2rgb(hsv in);
rgb hsv2rgb(hsv in);

int GetHSVh(COLORREF dwColor);
4 changes: 1 addition & 3 deletions AccentColorizer/StyleModifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
26 changes: 18 additions & 8 deletions AccentColorizer/SysColorsModifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,34 @@
#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,
COLOR_HIGHLIGHT,
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);
}

0 comments on commit 00c5a6c

Please sign in to comment.