diff options
| author | Jonas Kümmerlin <jonas@kuemmerlin.eu> | 2020-04-18 17:34:55 +0200 |
|---|---|---|
| committer | Jonas Kümmerlin <jonas@kuemmerlin.eu> | 2020-04-18 17:34:55 +0200 |
| commit | 479d1226faaa937ef6820b14f36099ef3f575883 (patch) | |
| tree | 10e5560fb8bae6c317ca06564c9609c3c498503e /alf/alfpanel.cpp | |
| parent | 4054b17c661d2e709895e8235e9dce6edaa61e4f (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/alfpanel.cpp')
| -rw-r--r-- | alf/alfpanel.cpp | 44 |
1 files changed, 20 insertions, 24 deletions
diff --git a/alf/alfpanel.cpp b/alf/alfpanel.cpp index 9496e43..2f39ef1 100644 --- a/alf/alfpanel.cpp +++ b/alf/alfpanel.cpp @@ -4,6 +4,7 @@ TCHAR *_alf_panelClass = NULL; typedef struct { ALFLayout layout; + ALFColor bgcolor; HFONT font; } ALFPanelPriv; @@ -11,6 +12,7 @@ static void ALF_Panel_IntializePriv(ALFPanelPriv *priv) { ALF_Layout_Init(&priv->layout); + priv->bgcolor = ALF_COLOR_TRANSPARENT; } static void @@ -22,29 +24,11 @@ ALF_Panel_ClearPriv(ALFPanelPriv *priv) static void ALF_Panel_Paint(ALFPanelPriv *priv, HWND hwnd, HDC dc, RECT *r) { - (void)priv; - ALF_Compat_DrawThemeParentBackground(hwnd, dc, r); - - int textlen = GetWindowTextLength(hwnd); - if (textlen < 1) - return; - - TCHAR *textbuf = ALF_New(TCHAR, (SIZE_T)textlen + 1); - GetWindowText(hwnd, textbuf, textlen+1); - - HFONT oldFont = SelectFont(dc, priv->font); - - SetTextColor(dc, GetSysColor(COLOR_BTNTEXT)); - SetBkMode(dc, TRANSPARENT); - - RECT rc; - GetClientRect(hwnd, &rc); - - DrawText(dc, textbuf, -1, &rc, DT_SINGLELINE | DT_EXPANDTABS | DT_HIDEPREFIX | DT_CENTER | DT_VCENTER); - - ALF_Free(textbuf); - - SelectFont(dc, oldFont); + if (priv->bgcolor == ALF_COLOR_TRANSPARENT) { + ALF_Compat_DrawThemeParentBackground(hwnd, dc, r); + } else { + ALF_FillRect(dc, r, priv->bgcolor); + } } static LRESULT WINAPI @@ -78,6 +62,18 @@ ALF__PanelWindowProc(HWND window, UINT msg, WPARAM wparam, LPARAM lparam) // fallthrough to layout, will propagate font to children } + if (msg == ALF_WM_GETBGCOLOR) { + return (LRESULT)priv->bgcolor; + } + + if (msg == ALF_WM_SETBGCOLOR) { + priv->bgcolor = (ALFColor)wparam; + + InvalidateRect(window, NULL, TRUE); + + // fallthrough to layout, will propagate color to children + } + if (msg == WM_GETFONT) { return (LRESULT)priv->font; } @@ -160,7 +156,7 @@ ALF_AddPanel(HWND parent, WORD id, int x, int y) { HWND hwndPanel = ALF_CreatePanelWindow(parent, id); - ALF_AddWidget(parent, x, y, hwndPanel, 0, 0, ALF_LAYOUT_SIZE_QUERY | ALF_LAYOUT_INHERITFONT); + ALF_AddWidget(parent, x, y, hwndPanel, 0, 0, ALF_LAYOUT_SIZE_QUERY | ALF_LAYOUT_INHERITFONT | ALF_LAYOUT_INHERITBGCOLOR); return hwndPanel; } |
