Skip to content

Commit 5e32a09

Browse files
committed
Store current accent HSL values as POD
1 parent ffbce0d commit 5e32a09

File tree

4 files changed

+42
-42
lines changed

4 files changed

+42
-42
lines changed

AccentColorizer/AccentColorHelper.cpp

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,15 @@
33
#include <cmath>
44

55
COLORREF g_dwAccent;
6-
int g_hslAccentH;
7-
double g_hslAccentS;
8-
double g_oldhslAccentS;
6+
//
7+
hsl_t g_hslAccent;
8+
hsl_t g_hslDefaultAccent;
9+
//
910
double g_balance1hslAccentS;
1011
double g_balance2hslAccentS;
11-
double g_hslAccentL;
12+
//
1213
double g_oldhslAccentL;
13-
double g_defaulthslAccentH;
14-
double g_defaulthslAccentS;
15-
double g_defaulthslAccentL;
14+
double g_oldhslAccentS;
1615

1716
bool UpdateAccentColor()
1817
{
@@ -29,24 +28,24 @@ bool UpdateAccentColor()
2928
}
3029

3130
if (accentColorChanges >= 1) {
32-
g_oldhslAccentS = g_hslAccentS;
31+
g_oldhslAccentS = g_hslAccent.s;
3332
if (g_oldhslAccentS <= 0.0666) {
3433
g_oldhslAccentS = 0.0666;
3534
}
3635
}
3736
else g_oldhslAccentS = 1;
3837

3938
if (accentColorChanges >= 1) {
40-
g_oldhslAccentL = g_hslAccentL;
39+
g_oldhslAccentL = g_hslAccent.l;
4140
}
4241
else g_oldhslAccentL = 0;
4342

4443
g_dwAccent = dwAccent;
4544
if ((double)GetRValue(dwAccent) == (double)GetGValue(dwAccent) && (double)GetGValue(dwAccent) == (double)GetBValue(dwAccent)) {
46-
g_hslAccentH = 210.0;
45+
g_hslAccent.h = 210.0;
4746
}
4847
else {
49-
g_hslAccentH = rgb2hsl({
48+
g_hslAccent.h = rgb2hsl({
5049
(double)GetRValue(dwAccent) / 255,
5150
(double)GetGValue(dwAccent) / 255,
5251
(double)GetBValue(dwAccent) / 255 }).h;
@@ -61,36 +60,36 @@ bool UpdateAccentColor()
6160

6261
g_dwAccent = dwAccent;
6362
if ((double)GetRValue(dwAccent) == (double)GetGValue(dwAccent) && (double)GetGValue(dwAccent) == (double)GetBValue(dwAccent)) {
64-
g_hslAccentS = 0.0667;
63+
g_hslAccent.s = 0.0667;
6564
}
6665
else {
67-
g_hslAccentS = pow(double(rgb2hsl({
66+
g_hslAccent.s = pow(double(rgb2hsl({
6867
(double)GetRValue(dwAccent) / 254.999999999,
6968
(double)GetGValue(dwAccent) / 254.999999999,
7069
(double)GetBValue(dwAccent) / 254.999999999 }).s), double(0.85));
7170
}
7271

7372

74-
g_balance1hslAccentS = g_hslAccentS;
75-
g_balance2hslAccentS = (1 - g_hslAccentS);
73+
g_balance1hslAccentS = g_hslAccent.s;
74+
g_balance2hslAccentS = (1 - g_hslAccent.s);
7675

77-
g_defaulthslAccentH = 207;
78-
g_defaulthslAccentS = 1;
79-
g_defaulthslAccentL = (double)(rgb2hsl({
76+
g_hslDefaultAccent.h = 207;
77+
g_hslDefaultAccent.s = 1;
78+
g_hslDefaultAccent.l = (double)(rgb2hsl({
8079
(double)0 / 254.999999999,
8180
(double)120 / 254.999999999,
8281
(double)215 / 254.999999999 }).l);
8382

84-
if (g_hslAccentS < 0.0666) {
85-
g_hslAccentS = 0.0666;
83+
if (g_hslAccent.s < 0.0666) {
84+
g_hslAccent.s = 0.0666;
8685
}
8786
if (accentColorChanges >= 1) {
88-
if (g_hslAccentS > 1) {
89-
g_hslAccentS = g_balance1hslAccentS + g_balance2hslAccentS;
87+
if (g_hslAccent.s > 1) {
88+
g_hslAccent.s = g_balance1hslAccentS + g_balance2hslAccentS;
9089
}
9190
}
9291

93-
g_hslAccentL = ((double)(rgb2hsl({
92+
g_hslAccent.l = ((double)(rgb2hsl({
9493
(double)GetRValue(dwAccent) / 254.999999999,
9594
(double)GetGValue(dwAccent) / 254.999999999,
9695
(double)GetBValue(dwAccent) / 254.999999999 }).l) -

AccentColorizer/AccentColorHelper.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
#pragma once
22
#include "framework.h"
3+
#include "ColorHelper.h"
34

45
extern COLORREF g_dwAccent;
5-
extern int g_hslAccentH;
6-
extern double g_hslAccentS;
7-
extern double g_oldhslAccentS;
6+
//
7+
extern hsl_t g_hslAccent;
8+
extern hsl_t g_hslDefaultAccent;
9+
//
810
extern double g_balance1hslAccentS;
911
extern double g_balance2hslAccentS;
10-
extern double g_hslAccentL;
12+
//
1113
extern double g_oldhslAccentL;
12-
extern double g_defaulthslAccentH;
13-
extern double g_defaulthslAccentS;
14-
extern double g_defaulthslAccentL;
14+
extern double g_oldhslAccentS;
15+
//
1516
extern int accentColorChanges;
1617

1718
bool UpdateAccentColor();

AccentColorizer/StyleModifier.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ void StandardBitmapPixelHandler(int& r, int& g, int& b, int& a)
1717
rgb_t rgbVal = { r, g, b };
1818
hsl_t hslVal = rgb2hsl(rgbVal);
1919

20-
hslVal.h = g_defaulthslAccentH;
21-
hslVal.s = (double)hslVal.s * (double)(1 / (double)g_oldhslAccentS) * (double)g_defaulthslAccentS;
20+
hslVal.h = g_hslDefaultAccent.h;
21+
hslVal.s = hslVal.s * (1.0 / g_oldhslAccentS) * g_hslDefaultAccent.s;
2222

23-
hslVal.l = hslVal.l - (g_oldhslAccentL * hslVal.s * (a / static_cast<double>(255))) + (g_hslAccentL * hslVal.s * (a / static_cast<double>(255))) - (g_defaulthslAccentL * hslVal.s);
23+
hslVal.l = hslVal.l - (g_oldhslAccentL * hslVal.s * (a / static_cast<double>(255))) + (g_hslAccent.l * hslVal.s * (a / static_cast<double>(255))) - (g_hslDefaultAccent.l * hslVal.s);
2424

25-
hslVal.h = g_hslAccentH;
26-
hslVal.s = (double)hslVal.s * (double)g_hslAccentS;
25+
hslVal.h = g_hslAccent.h;
26+
hslVal.s = hslVal.s * g_hslAccent.s;
2727

2828
rgbVal = hsl2rgb(hslVal);
2929

@@ -37,8 +37,8 @@ void StandardColorHandler(int& r, int& g, int& b) // dummy code
3737
rgb_t rgbVal = { 255, 128, 128 };
3838
hsl_t hslVal = rgb2hsl(rgbVal);
3939

40-
hslVal.h = g_hslAccentH;
41-
hslVal.s = hslVal.s * (1 / g_oldhslAccentS) * g_hslAccentS;
40+
hslVal.h = g_hslAccent.h;
41+
hslVal.s = hslVal.s * (1 / g_oldhslAccentS) * g_hslAccent.s;
4242

4343
rgbVal = hsl2rgb(hslVal);
4444
}

AccentColorizer/SysColorsModifier.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ void ModifySysColors()
3737
};
3838
hslVal = rgb2hsl(rgbVal);
3939

40-
hslVal.h = g_defaulthslAccentH;
41-
hslVal.s = (double)hslVal.s * (double)(1 / (double)g_oldhslAccentS) * (double)g_defaulthslAccentS;
40+
hslVal.h = g_hslDefaultAccent.h;
41+
hslVal.s = hslVal.s * (1 / g_oldhslAccentS) * g_hslDefaultAccent.s;
4242

43-
hslVal.l = hslVal.l - (g_oldhslAccentL * hslVal.s) + (g_hslAccentL * hslVal.s) - (g_defaulthslAccentL * hslVal.s);
43+
hslVal.l = hslVal.l - (g_oldhslAccentL * hslVal.s) + (g_hslAccent.l * hslVal.s) - (g_hslDefaultAccent.l * hslVal.s);
4444

45-
hslVal.h = g_hslAccentH;
46-
hslVal.s = (double)hslVal.s * (double)g_hslAccentS;
45+
hslVal.h = g_hslAccent.h;
46+
hslVal.s = hslVal.s * g_hslAccent.s;
4747

4848

4949

0 commit comments

Comments
 (0)