From 479d1226faaa937ef6820b14f36099ef3f575883 Mon Sep 17 00:00:00 2001 From: Jonas Kümmerlin Date: Sat, 18 Apr 2020 17:34:55 +0200 Subject: 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. --- alf/alfpanel.cpp | 44 ++++++++++++++++++++------------------------ 1 file changed, 20 insertions(+), 24 deletions(-) (limited to 'alf/alfpanel.cpp') 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; } -- cgit v1.2.3