mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-05-15 14:16:07 -06:00
Core: Another attempt at DarkTheme improvement
This commit is contained in:
parent
6739989e2a
commit
80946710cd
4 changed files with 91 additions and 11 deletions
|
|
@ -242,6 +242,47 @@ int Grayscale2(const Color& c)
|
|||
return (c.GetR() + c.GetG() + c.GetB()) / 3;
|
||||
}
|
||||
|
||||
#if 1
|
||||
|
||||
double C_R = 0.32;
|
||||
double C_G = 0.5;
|
||||
double C_B = 0.2;
|
||||
|
||||
Color DarkTheme(Color color)
|
||||
{
|
||||
double r = color.GetR();
|
||||
double g = color.GetG();
|
||||
double b = color.GetB();
|
||||
|
||||
double saturation = min(r, g, b);
|
||||
|
||||
r -= saturation;
|
||||
g -= saturation;
|
||||
b -= saturation;
|
||||
|
||||
auto Val = [&] {
|
||||
return C_R * r + C_G * g + C_B * b;
|
||||
};
|
||||
|
||||
double target = 255 - Saturate255(Val() + saturation);
|
||||
double ratio = target / 128;
|
||||
|
||||
double m = max(r, g, b);
|
||||
|
||||
if(m * ratio >= 255)
|
||||
ratio = 255 / m;
|
||||
|
||||
r *= ratio;
|
||||
g *= ratio;
|
||||
b *= ratio;
|
||||
saturation = target - Val();
|
||||
|
||||
return Color(Saturate255(r + saturation), Saturate255(g + saturation), Saturate255(b + saturation));
|
||||
}
|
||||
|
||||
|
||||
#else // older worse algorithm
|
||||
|
||||
double DarkTheme_c[3] = { 0.3, 0.5, 0.2 };
|
||||
int DarkTheme_middle = 155;
|
||||
|
||||
|
|
@ -315,6 +356,8 @@ Color DarkTheme(Color color)
|
|||
return Color((int)v[0], (int)v[1], (int)v[2]);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Color DarkThemeCached(Color c)
|
||||
{
|
||||
const int N = 8;
|
||||
|
|
|
|||
|
|
@ -161,6 +161,8 @@ inline dword FoldHash(dword h)
|
|||
|
||||
#endif
|
||||
|
||||
inline byte Saturate255(int x) { return byte(~(x >> 24) & (x | (-(x >> 8) >> 24)) & 0xff); }
|
||||
|
||||
force_inline
|
||||
int SignificantBits(dword x)
|
||||
{ // basically log2(x) + 1 except that for 0 this is 0, number of significant bits of x
|
||||
|
|
|
|||
|
|
@ -61,7 +61,6 @@ String PackRLE(const RGBA *s, int len);
|
|||
|
||||
inline int Grayscale(int r, int g, int b) { return (77 * r + 151 * g + 28 * b) >> 8; }
|
||||
inline int Grayscale(const RGBA& c) { return Grayscale(c.r, c.g, c.b); }
|
||||
inline byte Saturate255(int x) { return byte(~(x >> 24) & (x | (-(x >> 8) >> 24)) & 0xff); }
|
||||
|
||||
class Image;
|
||||
|
||||
|
|
|
|||
|
|
@ -24,8 +24,9 @@ struct MyApp : TopWindow {
|
|||
};
|
||||
|
||||
namespace Upp {
|
||||
extern double DarkTheme_c[];
|
||||
extern int DarkTheme_middle;
|
||||
extern double C_R;
|
||||
extern double C_G;
|
||||
extern double C_B;
|
||||
};
|
||||
|
||||
void MyApp::Paint(Draw& w)
|
||||
|
|
@ -53,7 +54,7 @@ void MyApp::Paint(Draw& w)
|
|||
<< LtCyan()
|
||||
;
|
||||
|
||||
w.DrawRect(GetSize(), Color(20, 20, 20));
|
||||
w.DrawRect(GetSize(), Black());
|
||||
for(int i = 0; i < col.GetCount(); i++) {
|
||||
w.DrawRect(i * 32, 0, 32, 32, col[i]);
|
||||
w.DrawRect(i * 32, 35, 32, 32, DarkTheme(col[i]));
|
||||
|
|
@ -68,12 +69,29 @@ void MyApp::Paint(Draw& w)
|
|||
}
|
||||
|
||||
Size tsz = GetTextSize("Test", StdFont());
|
||||
int y = 200;
|
||||
w.DrawRect(0, 200, tsz.cx * col.GetCount(), tsz.cy, White());
|
||||
for(int i = 0; i < col.GetCount(); i++)
|
||||
w.DrawText(i * tsz.cx, 200, "Text", StdFont(), col[i]);
|
||||
w.DrawText(i * tsz.cx, y, "Text", StdFont(), col[i]);
|
||||
y += tsz.cy;
|
||||
|
||||
for(int i = 0; i < col.GetCount(); i++)
|
||||
w.DrawText(i * tsz.cx, 200 + tsz.cy, "Text", StdFont(), DarkTheme(col[i]));
|
||||
w.DrawText(i * tsz.cx, y, "Text", StdFont(), DarkTheme(col[i]));
|
||||
y += tsz.cy;
|
||||
/*
|
||||
for(int i = 0; i < col.GetCount(); i++)
|
||||
w.DrawText(i * tsz.cx, y, "Text", StdFont(), DarkTheme2(col[i]));
|
||||
y += tsz.cy;
|
||||
*/
|
||||
y += tsz.cy;
|
||||
|
||||
for(Color c : col) {
|
||||
w.DrawRect(0, y, tsz.cy, tsz.cy, c);
|
||||
c = DarkTheme(c);
|
||||
w.DrawRect(tsz.cy + 10, y, tsz.cy, tsz.cy, c);
|
||||
w.DrawText(2 * (tsz.cy + 10), y, AsString(c), StdFont(), White());
|
||||
y += tsz.cy;
|
||||
}
|
||||
|
||||
int x = tsz.cx * 32 + 50;
|
||||
w.DrawImage(x, 0, DarkImg::ide());
|
||||
|
|
@ -84,7 +102,6 @@ void MyApp::Paint(Draw& w)
|
|||
void MyApp::Sync()
|
||||
{
|
||||
ret.Retrieve();
|
||||
DarkTheme_c[2] = 1 - DarkTheme_c[0] - DarkTheme_c[1];
|
||||
Refresh();
|
||||
}
|
||||
|
||||
|
|
@ -98,18 +115,37 @@ MyApp::MyApp()
|
|||
w << [=] { Sync(); };
|
||||
};
|
||||
|
||||
Add(r.SetInc(0.02).MinMax(0, 1));
|
||||
Add(g.SetInc(0.02).MinMax(0, 1));
|
||||
Add(r.SetInc(0.01).MinMax(0, 1));
|
||||
Add(g.SetInc(0.01).MinMax(0, 1));
|
||||
Add(b.SetInc(0.01).MinMax(0, 1));
|
||||
Add(middle);
|
||||
|
||||
/*
|
||||
ret(r, DarkTheme_c[0])
|
||||
(g, DarkTheme_c[1])
|
||||
(middle, DarkTheme_middle);
|
||||
*/
|
||||
|
||||
ret(r, C_R)
|
||||
(g, C_G)
|
||||
(b, C_B)
|
||||
;
|
||||
|
||||
Sizeable();
|
||||
};
|
||||
|
||||
GUI_APP_MAIN
|
||||
{
|
||||
DDUMP(DarkTheme(LtYellow()));
|
||||
DDUMP(DarkTheme(Yellow()));
|
||||
DDUMP(DarkTheme(Brown()));
|
||||
DDUMP(DarkTheme(LtRed()));
|
||||
DDUMP(DarkTheme(Black()));
|
||||
DDUMP(DarkTheme(LtBlue()));
|
||||
DDUMP(DarkTheme(LtBlue()));
|
||||
DDUMP(DarkTheme(LtGreen()));
|
||||
|
||||
DDUMP(DarkTheme(LtRed()));
|
||||
DDUMP(DarkTheme(LtBlue()));
|
||||
MyApp().Run();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue