summaryrefslogtreecommitdiff
path: root/alf/alfwindow.cpp
diff options
context:
space:
mode:
authorJonas Kümmerlin <jonas@kuemmerlin.eu>2020-04-18 17:34:55 +0200
committerJonas Kümmerlin <jonas@kuemmerlin.eu>2020-04-18 17:34:55 +0200
commit479d1226faaa937ef6820b14f36099ef3f575883 (patch)
tree10e5560fb8bae6c317ca06564c9609c3c498503e /alf/alfwindow.cpp
parent4054b17c661d2e709895e8235e9dce6edaa61e4f (diff)
implement background color
reduce flickering by keeping pixels if we know the background didn't change panel text is now gone, it would require us to redraw every transparent widget on top, which is a bad tradeoff since that panel text isn't very useful anyway.
Diffstat (limited to 'alf/alfwindow.cpp')
-rw-r--r--alf/alfwindow.cpp46
1 files changed, 45 insertions, 1 deletions
diff --git a/alf/alfwindow.cpp b/alf/alfwindow.cpp
index 0b395b6..c3f8573 100644
--- a/alf/alfwindow.cpp
+++ b/alf/alfwindow.cpp
@@ -9,6 +9,7 @@ typedef struct {
WORD defid;
HWND hwndFocus;
HFONT font;
+ ALFColor bgcolor;
} ALFWindowPriv;
static void
@@ -17,6 +18,7 @@ ALF_InitializeWindowPriv(HWND hwnd, ALFWindowPriv *priv, void *closure)
priv->vtbl = (ALFWindowVTable*)GetClassLongPtr(hwnd, 0);
priv->closure = closure;
priv->defid = (WORD)-1;
+ priv->bgcolor = ALF_COLOR_SYS(COLOR_BTNFACE);
ALF_Layout_Init(&priv->layout);
}
@@ -148,6 +150,13 @@ ALF_WindowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
}
}
+static void
+ALF_Window_Paint(ALFWindowPriv *priv, HWND hwnd, HDC dc, RECT *r)
+{
+ (void)hwnd;
+ ALF_FillRect(dc, r, priv->bgcolor);
+}
+
LRESULT
ALF_DefWindowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
@@ -184,6 +193,41 @@ ALF_DefWindowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
// fallthrough to layout, will propagate font to children
}
+ if (msg == ALF_WM_SETBGCOLOR) {
+ priv->bgcolor = (ALFColor)wparam;
+
+ InvalidateRect(hwnd, NULL, TRUE);
+
+ // fallthrough to layout, will propagate color to children
+ }
+
+ if (msg == ALF_WM_GETBGCOLOR) {
+ return (LRESULT)priv->bgcolor;
+ }
+
+ if (msg == WM_ERASEBKGND) {
+ return TRUE; // handled in WM_PAINT
+ }
+
+ if (msg == WM_PRINTCLIENT) {
+ RECT r = { 0, 0, 0, 0 };
+ GetClientRect(hwnd, &r);
+
+ ALF_Window_Paint(priv, hwnd, (HDC)wparam, &r);
+ return TRUE;
+ }
+
+ if (msg == WM_PAINT) {
+ PAINTSTRUCT ps;
+ HDC dc = BeginPaint(hwnd, &ps);
+
+ ALF_Window_Paint(priv, hwnd, dc, &ps.rcPaint);
+
+ EndPaint(hwnd, &ps);
+
+ return 0;
+ }
+
if (msg == WM_GETFONT) {
return (LRESULT)priv->font;
}
@@ -390,7 +434,7 @@ ALF_RegisterWindowClass(HINSTANCE hInstance, const ALFWindowClassParams *params)
cls.style = params->classStyle;
cls.hInstance = hInstance;
cls.hCursor = LoadCursor(NULL, (LPTSTR)IDC_ARROW);
- cls.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1);
+ cls.hbrBackground = NULL;
cls.lpszClassName = classNamePtr;
cls.cbWndExtra = sizeof(void*);
cls.cbClsExtra = sizeof(void*);