Reduce flicker on updates.

This commit is contained in:
Alexandre Julliard 2002-08-13 18:08:45 +00:00
parent 06effbf07a
commit 473f3de872
1 changed files with 77 additions and 43 deletions

View File

@ -47,40 +47,53 @@ typedef struct
"(%04x): wp=%04x lp=%08lx\n", msg, wParam, lParam); "(%04x): wp=%04x lp=%08lx\n", msg, wParam, lParam);
/*********************************************************************** /***********************************************************************
* PROGRESS_EraseBackground * PROGRESS_Invalidate
*
* Invalide the range between old and new pos.
*/ */
static void PROGRESS_EraseBackground(PROGRESS_INFO *infoPtr, WPARAM wParam) static void PROGRESS_Invalidate( PROGRESS_INFO *infoPtr, INT old, INT new )
{ {
LONG style = GetWindowLongW (infoPtr->Self, GWL_STYLE);
RECT rect; RECT rect;
HBRUSH hbrBk; int oldPos, newPos, ledWidth;
HDC hdc = wParam ? (HDC)wParam : GetDC(infoPtr->Self);
/* get the required background brush */ GetClientRect (infoPtr->Self, &rect);
if(infoPtr->ColorBk == CLR_DEFAULT) InflateRect(&rect, -1, -1);
hbrBk = GetSysColorBrush(COLOR_3DFACE);
if (style & PBS_VERTICAL)
{
oldPos = rect.bottom - MulDiv (old - infoPtr->MinVal, rect.bottom - rect.top,
infoPtr->MaxVal - infoPtr->MinVal);
newPos = rect.bottom - MulDiv (new - infoPtr->MinVal, rect.bottom - rect.top,
infoPtr->MaxVal - infoPtr->MinVal);
ledWidth = MulDiv (rect.right - rect.left, 2, 3);
rect.top = min( oldPos, newPos );
rect.bottom = max( oldPos, newPos );
if (!(style & PBS_SMOOTH)) rect.top -= ledWidth;
InvalidateRect( infoPtr->Self, &rect, oldPos < newPos );
}
else else
hbrBk = CreateSolidBrush(infoPtr->ColorBk); {
oldPos = rect.left + MulDiv (old - infoPtr->MinVal, rect.right - rect.left,
/* get client rectangle */ infoPtr->MaxVal - infoPtr->MinVal);
GetClientRect(infoPtr->Self, &rect); newPos = rect.left + MulDiv (new - infoPtr->MinVal, rect.right - rect.left,
infoPtr->MaxVal - infoPtr->MinVal);
/* draw the background */ ledWidth = MulDiv (rect.bottom - rect.top, 2, 3);
FillRect(hdc, &rect, hbrBk); rect.left = min( oldPos, newPos );
rect.right = max( oldPos, newPos );
/* delete background brush */ if (!(style & PBS_SMOOTH)) rect.right += ledWidth;
if(infoPtr->ColorBk != CLR_DEFAULT) InvalidateRect( infoPtr->Self, &rect, oldPos > newPos );
DeleteObject (hbrBk); }
if(!wParam) ReleaseDC(infoPtr->Self, hdc);
} }
/*********************************************************************** /***********************************************************************
* PROGRESS_Draw * PROGRESS_Draw
* Draws the progress bar. * Draws the progress bar.
*/ */
static LRESULT PROGRESS_Draw (PROGRESS_INFO *infoPtr, HDC hdc) static LRESULT PROGRESS_Draw (PROGRESS_INFO *infoPtr, HDC hdc)
{ {
HBRUSH hbrBar; HBRUSH hbrBar, hbrBk;
int rightBar, rightMost, ledWidth; int rightBar, rightMost, ledWidth;
RECT rect; RECT rect;
DWORD dwStyle; DWORD dwStyle;
@ -93,9 +106,14 @@ static LRESULT PROGRESS_Draw (PROGRESS_INFO *infoPtr, HDC hdc)
else else
hbrBar = CreateSolidBrush (infoPtr->ColorBar); hbrBar = CreateSolidBrush (infoPtr->ColorBar);
if (infoPtr->ColorBk == CLR_DEFAULT)
hbrBk = GetSysColorBrush(COLOR_3DFACE);
else
hbrBk = CreateSolidBrush(infoPtr->ColorBk);
/* get client rectangle */ /* get client rectangle */
GetClientRect (infoPtr->Self, &rect); GetClientRect (infoPtr->Self, &rect);
FrameRect( hdc, &rect, hbrBk );
InflateRect(&rect, -1, -1); InflateRect(&rect, -1, -1);
/* get the window style */ /* get the window style */
@ -119,12 +137,26 @@ static LRESULT PROGRESS_Draw (PROGRESS_INFO *infoPtr, HDC hdc)
} }
/* now draw the bar */ /* now draw the bar */
if (dwStyle & PBS_SMOOTH) { if (dwStyle & PBS_SMOOTH)
{
if (dwStyle & PBS_VERTICAL) if (dwStyle & PBS_VERTICAL)
rect.top = rightBar; {
INT old_top = rect.top;
rect.top = rightBar;
FillRect(hdc, &rect, hbrBar);
rect.bottom = rect.top;
rect.top = old_top;
FillRect(hdc, &rect, hbrBk);
}
else else
rect.right = rightBar; {
FillRect(hdc, &rect, hbrBar); INT old_right = rect.right;
rect.right = rightBar;
FillRect(hdc, &rect, hbrBar);
rect.left = rect.right;
rect.right = old_right;
FillRect(hdc, &rect, hbrBk);
}
} else { } else {
if (dwStyle & PBS_VERTICAL) { if (dwStyle & PBS_VERTICAL) {
while(rect.bottom > rightBar) { while(rect.bottom > rightBar) {
@ -132,22 +164,34 @@ static LRESULT PROGRESS_Draw (PROGRESS_INFO *infoPtr, HDC hdc)
if (rect.top < rightMost) if (rect.top < rightMost)
rect.top = rightMost; rect.top = rightMost;
FillRect(hdc, &rect, hbrBar); FillRect(hdc, &rect, hbrBar);
rect.bottom = rect.top - LED_GAP; rect.bottom = rect.top;
rect.top -= LED_GAP;
if (rect.top <= rightBar) break;
FillRect(hdc, &rect, hbrBk);
rect.bottom = rect.top;
} }
rect.top = rightMost;
FillRect(hdc, &rect, hbrBk);
} else { } else {
while(rect.left < rightBar) { while(rect.left < rightBar) {
rect.right = rect.left + ledWidth; rect.right = rect.left + ledWidth;
if (rect.right > rightMost) if (rect.right > rightMost)
rect.right = rightMost; rect.right = rightMost;
FillRect(hdc, &rect, hbrBar); FillRect(hdc, &rect, hbrBar);
rect.left = rect.right + LED_GAP; rect.left = rect.right;
rect.right += LED_GAP;
if (rect.right >= rightBar) break;
FillRect(hdc, &rect, hbrBk);
rect.left = rect.right;
} }
rect.right = rightMost;
FillRect(hdc, &rect, hbrBk);
} }
} }
/* delete bar brush */ /* delete bar brush */
if (infoPtr->ColorBar != CLR_DEFAULT) if (infoPtr->ColorBar != CLR_DEFAULT) DeleteObject (hbrBar);
DeleteObject (hbrBar); if (infoPtr->ColorBk != CLR_DEFAULT) DeleteObject (hbrBk);
return 0; return 0;
} }
@ -257,10 +301,6 @@ static LRESULT WINAPI ProgressWindowProc(HWND hwnd, UINT message,
SetWindowLongW(hwnd, 0, 0); SetWindowLongW(hwnd, 0, 0);
return 0; return 0;
case WM_ERASEBKGND:
PROGRESS_EraseBackground(infoPtr, wParam);
return TRUE;
case WM_GETFONT: case WM_GETFONT:
return (LRESULT)infoPtr->Font; return (LRESULT)infoPtr->Font;
@ -276,12 +316,10 @@ static LRESULT WINAPI ProgressWindowProc(HWND hwnd, UINT message,
if(lParam) UNKNOWN_PARAM(PBM_DELTAPOS, wParam, lParam); if(lParam) UNKNOWN_PARAM(PBM_DELTAPOS, wParam, lParam);
oldVal = infoPtr->CurVal; oldVal = infoPtr->CurVal;
if(wParam != 0) { if(wParam != 0) {
BOOL bErase;
infoPtr->CurVal += (INT)wParam; infoPtr->CurVal += (INT)wParam;
PROGRESS_CoercePos (infoPtr); PROGRESS_CoercePos (infoPtr);
TRACE("PBM_DELTAPOS: current pos changed from %d to %d\n", oldVal, infoPtr->CurVal); TRACE("PBM_DELTAPOS: current pos changed from %d to %d\n", oldVal, infoPtr->CurVal);
bErase = (oldVal > infoPtr->CurVal); PROGRESS_Invalidate( infoPtr, oldVal, infoPtr->CurVal );
InvalidateRect(hwnd, NULL, bErase);
} }
return oldVal; return oldVal;
} }
@ -292,12 +330,10 @@ static LRESULT WINAPI ProgressWindowProc(HWND hwnd, UINT message,
if (lParam) UNKNOWN_PARAM(PBM_SETPOS, wParam, lParam); if (lParam) UNKNOWN_PARAM(PBM_SETPOS, wParam, lParam);
oldVal = infoPtr->CurVal; oldVal = infoPtr->CurVal;
if(oldVal != wParam) { if(oldVal != wParam) {
BOOL bErase;
infoPtr->CurVal = (INT)wParam; infoPtr->CurVal = (INT)wParam;
PROGRESS_CoercePos(infoPtr); PROGRESS_CoercePos(infoPtr);
TRACE("PBM_SETPOS: current pos changed from %d to %d\n", oldVal, infoPtr->CurVal); TRACE("PBM_SETPOS: current pos changed from %d to %d\n", oldVal, infoPtr->CurVal);
bErase = (oldVal > infoPtr->CurVal); PROGRESS_Invalidate( infoPtr, oldVal, infoPtr->CurVal );
InvalidateRect(hwnd, NULL, bErase);
} }
return oldVal; return oldVal;
} }
@ -325,10 +361,8 @@ static LRESULT WINAPI ProgressWindowProc(HWND hwnd, UINT message,
infoPtr->CurVal = infoPtr->MinVal; infoPtr->CurVal = infoPtr->MinVal;
if(oldVal != infoPtr->CurVal) if(oldVal != infoPtr->CurVal)
{ {
BOOL bErase;
TRACE("PBM_STEPIT: current pos changed from %d to %d\n", oldVal, infoPtr->CurVal); TRACE("PBM_STEPIT: current pos changed from %d to %d\n", oldVal, infoPtr->CurVal);
bErase = (oldVal > infoPtr->CurVal); PROGRESS_Invalidate( infoPtr, oldVal, infoPtr->CurVal );
InvalidateRect(hwnd, NULL, bErase);
} }
return oldVal; return oldVal;
} }