From c83ac7600db761020804b2ca1cd5a788d0b1c741 Mon Sep 17 00:00:00 2001 From: Stanislav Motylkov Date: Wed, 24 Oct 2018 19:16:22 +0300 Subject: [PATCH] [SHIMGVW] Fix image flickering when rendering animations --- dll/win32/shimgvw/shimgvw.c | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/dll/win32/shimgvw/shimgvw.c b/dll/win32/shimgvw/shimgvw.c index 683e9b3c7e4..c65410b2fdd 100644 --- a/dll/win32/shimgvw/shimgvw.c +++ b/dll/win32/shimgvw/shimgvw.c @@ -587,8 +587,10 @@ ImageView_DrawImage(HWND hwnd) UINT ImageWidth, ImageHeight; INT ZoomedWidth, ZoomedHeight, x, y; PAINTSTRUCT ps; - RECT rect; + RECT rect, margin; HDC hdc; + HBRUSH white; + HGDIOBJ hbrOld; hdc = BeginPaint(hwnd, &ps); if (!hdc) @@ -609,14 +611,31 @@ ImageView_DrawImage(HWND hwnd) if (GetClientRect(hwnd, &rect)) { - FillRect(hdc, &rect, (HBRUSH)GetStockObject(WHITE_BRUSH)); - ZoomedWidth = (ImageWidth * ZoomPercents) / 100; ZoomedHeight = (ImageHeight * ZoomPercents) / 100; x = (rect.right - ZoomedWidth) / 2; y = (rect.bottom - ZoomedHeight) / 2; + white = GetStockObject(WHITE_BRUSH); + // Fill top part + margin = rect; + margin.bottom = y - 1; + FillRect(hdc, &margin, white); + // Fill bottom part + margin.top = y + ZoomedHeight + 1; + margin.bottom = rect.bottom; + FillRect(hdc, &margin, white); + // Fill left part + margin.top = y - 1; + margin.bottom = y + ZoomedHeight + 1; + margin.right = x - 1; + FillRect(hdc, &margin, white); + // Fill right part + margin.left = x + ZoomedWidth + 1; + margin.right = rect.right; + FillRect(hdc, &margin, white); + DPRINT("x = %d, y = %d, ImageWidth = %u, ImageHeight = %u\n"); DPRINT("rect.right = %ld, rect.bottom = %ld\n", rect.right, rect.bottom); DPRINT("ZoomPercents = %d, ZoomedWidth = %d, ZoomedHeight = %d\n", @@ -633,7 +652,9 @@ ImageView_DrawImage(HWND hwnd) GdipSetSmoothingMode(graphics, SmoothingModeHighQuality); } + hbrOld = SelectObject(hdc, GetStockObject(NULL_BRUSH)); Rectangle(hdc, x - 1, y - 1, x + ZoomedWidth + 1, y + ZoomedHeight + 1); + SelectObject(hdc, hbrOld); GdipDrawImageRectI(graphics, image, x, y, ZoomedWidth, ZoomedHeight); } GdipDeleteGraphics(graphics); @@ -749,7 +770,7 @@ static void ImageView_OnTimer(HWND hwnd) DWORD dwDelay; KillTimer(hwnd, ANIME_TIMER_ID); - InvalidateRect(hwnd, NULL, TRUE); + InvalidateRect(hwnd, NULL, FALSE); if (Anime_Step(&dwDelay)) {