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,32 +47,45 @@ 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 */
if(infoPtr->ColorBk == CLR_DEFAULT)
hbrBk = GetSysColorBrush(COLOR_3DFACE);
else
hbrBk = CreateSolidBrush(infoPtr->ColorBk);
/* get client rectangle */
GetClientRect (infoPtr->Self, &rect); GetClientRect (infoPtr->Self, &rect);
InflateRect(&rect, -1, -1);
/* draw the background */ if (style & PBS_VERTICAL)
FillRect(hdc, &rect, hbrBk); {
oldPos = rect.bottom - MulDiv (old - infoPtr->MinVal, rect.bottom - rect.top,
/* delete background brush */ infoPtr->MaxVal - infoPtr->MinVal);
if(infoPtr->ColorBk != CLR_DEFAULT) newPos = rect.bottom - MulDiv (new - infoPtr->MinVal, rect.bottom - rect.top,
DeleteObject (hbrBk); infoPtr->MaxVal - infoPtr->MinVal);
ledWidth = MulDiv (rect.right - rect.left, 2, 3);
if(!wParam) ReleaseDC(infoPtr->Self, hdc); rect.top = min( oldPos, newPos );
rect.bottom = max( oldPos, newPos );
if (!(style & PBS_SMOOTH)) rect.top -= ledWidth;
InvalidateRect( infoPtr->Self, &rect, oldPos < newPos );
} }
else
{
oldPos = rect.left + MulDiv (old - infoPtr->MinVal, rect.right - rect.left,
infoPtr->MaxVal - infoPtr->MinVal);
newPos = rect.left + MulDiv (new - infoPtr->MinVal, rect.right - rect.left,
infoPtr->MaxVal - infoPtr->MinVal);
ledWidth = MulDiv (rect.bottom - rect.top, 2, 3);
rect.left = min( oldPos, newPos );
rect.right = max( oldPos, newPos );
if (!(style & PBS_SMOOTH)) rect.right += ledWidth;
InvalidateRect( infoPtr->Self, &rect, oldPos > newPos );
}
}
/*********************************************************************** /***********************************************************************
* PROGRESS_Draw * PROGRESS_Draw
@ -80,7 +93,7 @@ static void PROGRESS_EraseBackground(PROGRESS_INFO *infoPtr, WPARAM wParam)
*/ */
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)
{
INT old_top = rect.top;
rect.top = rightBar; rect.top = rightBar;
FillRect(hdc, &rect, hbrBar);
rect.bottom = rect.top;
rect.top = old_top;
FillRect(hdc, &rect, hbrBk);
}
else else
{
INT old_right = rect.right;
rect.right = rightBar; rect.right = rightBar;
FillRect(hdc, &rect, hbrBar); 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;
} }