Commit 54de6149 authored by Frank Richter's avatar Frank Richter Committed by Alexandre Julliard

Split up the drawing code into a set of smaller functions and also

moved some common computations into helper functions. All that to facilitate the implementation of the forthcoming theming support.
parent 132af0a1
...@@ -62,6 +62,33 @@ typedef struct ...@@ -62,6 +62,33 @@ typedef struct
#define MARQUEE_LEDS 5 #define MARQUEE_LEDS 5
#define ID_MARQUEE_TIMER 1 #define ID_MARQUEE_TIMER 1
/* Helper to compute size of a progress bar chunk ("led"). */
static inline int get_led_size ( PROGRESS_INFO *infoPtr, LONG style,
const RECT* rect)
{
if (style & PBS_VERTICAL)
return MulDiv (rect->right - rect->left, 2, 3);
else
return MulDiv (rect->bottom - rect->top, 2, 3);
}
/* Compute the extend of the bar */
static inline int get_bar_size( LONG style, const RECT* rect )
{
if (style & PBS_VERTICAL)
return rect->bottom - rect->top;
else
return rect->right - rect->left;
}
/* Compute the pixel position of a progress value */
static inline int get_bar_position( PROGRESS_INFO *infoPtr, LONG style,
const RECT* rect, INT value )
{
return MulDiv (value - infoPtr->MinVal, get_bar_size (style, rect),
infoPtr->MaxVal - infoPtr->MinVal);
}
/*********************************************************************** /***********************************************************************
* PROGRESS_Invalidate * PROGRESS_Invalidate
* *
...@@ -71,37 +98,138 @@ static void PROGRESS_Invalidate( PROGRESS_INFO *infoPtr, INT old, INT new ) ...@@ -71,37 +98,138 @@ static void PROGRESS_Invalidate( PROGRESS_INFO *infoPtr, INT old, INT new )
{ {
LONG style = GetWindowLongW (infoPtr->Self, GWL_STYLE); LONG style = GetWindowLongW (infoPtr->Self, GWL_STYLE);
RECT rect; RECT rect;
int oldPos, newPos, ledWidth; int oldPos, newPos;
GetClientRect (infoPtr->Self, &rect); GetClientRect (infoPtr->Self, &rect);
InflateRect(&rect, -1, -1); InflateRect(&rect, -1, -1);
oldPos = get_bar_position( infoPtr, style, &rect, old );
newPos = get_bar_position( infoPtr, style, &rect, new );
if (style & PBS_VERTICAL) if (style & PBS_VERTICAL)
{ {
oldPos = rect.bottom - MulDiv (old - infoPtr->MinVal, rect.bottom - rect.top, rect.top = rect.bottom - max( oldPos, newPos );
infoPtr->MaxVal - infoPtr->MinVal); rect.bottom = rect.bottom - min( oldPos, newPos );
newPos = rect.bottom - MulDiv (new - infoPtr->MinVal, rect.bottom - rect.top, if (!(style & PBS_SMOOTH)) rect.top -=
infoPtr->MaxVal - infoPtr->MinVal); get_led_size (infoPtr, style, &rect);
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
{ {
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.left = min( oldPos, newPos );
rect.right = max( oldPos, newPos ); rect.right = max( oldPos, newPos );
if (!(style & PBS_SMOOTH)) rect.right += ledWidth; if (!(style & PBS_SMOOTH)) rect.right +=
InvalidateRect( infoPtr->Self, &rect, oldPos > newPos ); get_led_size (infoPtr, style, &rect);
} }
InvalidateRect( infoPtr->Self, &rect, oldPos > newPos );
} }
/* Information for a progress bar drawing helper */
typedef struct tagProgressDrawInfo
{
HDC hdc;
RECT rect;
HBRUSH hbrBar;
HBRUSH hbrBk;
int ledW;
} ProgressDrawInfo;
typedef void (*ProgressDrawProc)(const ProgressDrawInfo* di, int start, int end);
/* draw solid horizontal bar from 'start' to 'end' */
static void draw_solid_bar_H (const ProgressDrawInfo* di, int start, int end)
{
RECT r;
r.left = di->rect.left + start;
r.top = di->rect.top;
r.right = di->rect.left + end;
r.bottom = di->rect.bottom;
FillRect (di->hdc, &r, di->hbrBar);
}
/* draw solid horizontal background from 'start' to 'end' */
static void draw_solid_bkg_H (const ProgressDrawInfo* di, int start, int end)
{
RECT r;
r.left = di->rect.left + start;
r.top = di->rect.top;
r.right = di->rect.left + end;
r.bottom = di->rect.bottom;
FillRect (di->hdc, &r, di->hbrBk);
}
/* draw solid vertical bar from 'start' to 'end' */
static void draw_solid_bar_V (const ProgressDrawInfo* di, int start, int end)
{
RECT r;
r.left = di->rect.left;
r.top = di->rect.bottom - end;
r.right = di->rect.right;
r.bottom = di->rect.bottom - start;
FillRect (di->hdc, &r, di->hbrBar);
}
/* draw solid vertical background from 'start' to 'end' */
static void draw_solid_bkg_V (const ProgressDrawInfo* di, int start, int end)
{
RECT r;
r.left = di->rect.left;
r.top = di->rect.bottom - end;
r.right = di->rect.right;
r.bottom = di->rect.bottom - start;
FillRect (di->hdc, &r, di->hbrBk);
}
/* draw chunky horizontal bar from 'start' to 'end' */
static void draw_chunk_bar_H (const ProgressDrawInfo* di, int start, int end)
{
RECT r;
int right = di->rect.left + end;
r.left = di->rect.left + start;
r.top = di->rect.top;
r.bottom = di->rect.bottom;
while (r.left < right)
{
r.right = min (r.left + di->ledW, right);
FillRect (di->hdc, &r, di->hbrBar);
r.left = r.right;
r.right = min (r.left + LED_GAP, right);
FillRect (di->hdc, &r, di->hbrBk);
r.left = r.right;
}
}
/* draw chunky vertical bar from 'start' to 'end' */
static void draw_chunk_bar_V (const ProgressDrawInfo* di, int start, int end)
{
RECT r;
int top = di->rect.bottom - end;
r.left = di->rect.left;
r.right = di->rect.right;
r.bottom = di->rect.bottom - start;
while (r.bottom > top)
{
r.top = max (r.bottom - di->ledW, top);
FillRect (di->hdc, &r, di->hbrBar);
r.bottom = r.top;
r.top = max (r.bottom - LED_GAP, top);
FillRect (di->hdc, &r, di->hbrBk);
r.bottom = r.top;
}
}
/* drawing functions for "classic" style */
static const ProgressDrawProc drawProcClassic[8] = {
/* Smooth */
/* Horizontal */
draw_solid_bar_H, draw_solid_bkg_H,
/* Vertical */
draw_solid_bar_V, draw_solid_bkg_V,
/* Chunky */
/* Horizontal */
draw_chunk_bar_H, draw_solid_bkg_H,
/* Vertical */
draw_chunk_bar_V, draw_solid_bkg_V,
};
/*********************************************************************** /***********************************************************************
* PROGRESS_Draw * PROGRESS_Draw
...@@ -109,269 +237,89 @@ static void PROGRESS_Invalidate( PROGRESS_INFO *infoPtr, INT old, INT new ) ...@@ -109,269 +237,89 @@ static void PROGRESS_Invalidate( PROGRESS_INFO *infoPtr, INT old, INT new )
*/ */
static LRESULT PROGRESS_Draw (PROGRESS_INFO *infoPtr, HDC hdc) static LRESULT PROGRESS_Draw (PROGRESS_INFO *infoPtr, HDC hdc)
{ {
HBRUSH hbrBar, hbrBk; int barSize;
int rightBar, rightMost, ledWidth;
RECT rect;
DWORD dwStyle; DWORD dwStyle;
BOOL barSmooth;
const ProgressDrawProc* drawProcs;
ProgressDrawInfo pdi;
TRACE("(infoPtr=%p, hdc=%p)\n", infoPtr, hdc); TRACE("(infoPtr=%p, hdc=%p)\n", infoPtr, hdc);
pdi.hdc = hdc;
/* get the required bar brush */ /* get the required bar brush */
if (infoPtr->ColorBar == CLR_DEFAULT) if (infoPtr->ColorBar == CLR_DEFAULT)
hbrBar = GetSysColorBrush(COLOR_HIGHLIGHT); pdi.hbrBar = GetSysColorBrush(COLOR_HIGHLIGHT);
else else
hbrBar = CreateSolidBrush (infoPtr->ColorBar); pdi.hbrBar = CreateSolidBrush (infoPtr->ColorBar);
if (infoPtr->ColorBk == CLR_DEFAULT) if (infoPtr->ColorBk == CLR_DEFAULT)
hbrBk = GetSysColorBrush(COLOR_3DFACE); pdi.hbrBk = GetSysColorBrush(COLOR_3DFACE);
else else
hbrBk = CreateSolidBrush(infoPtr->ColorBk); pdi.hbrBk = CreateSolidBrush(infoPtr->ColorBk);
/* get client rectangle */
GetClientRect (infoPtr->Self, &rect);
FrameRect( hdc, &rect, hbrBk );
InflateRect(&rect, -1, -1);
/* get the window style */ /* get the window style */
dwStyle = GetWindowLongW (infoPtr->Self, GWL_STYLE); dwStyle = GetWindowLongW (infoPtr->Self, GWL_STYLE);
/* compute extent of progress bar */ /* get client rectangle */
if (dwStyle & PBS_VERTICAL) { GetClientRect (infoPtr->Self, &pdi.rect);
rightBar = rect.bottom - FrameRect( hdc, &pdi.rect, pdi.hbrBk );
MulDiv (infoPtr->CurVal - infoPtr->MinVal, InflateRect(&pdi.rect, -1, -1);
rect.bottom - rect.top,
infoPtr->MaxVal - infoPtr->MinVal); /* compute some drawing parameters */
ledWidth = MulDiv (rect.right - rect.left, 2, 3); barSmooth = (dwStyle & PBS_SMOOTH);
rightMost = rect.top; drawProcs = &(drawProcClassic[(barSmooth ? 0 : 4)
} else { + ((dwStyle & PBS_VERTICAL) ? 2 : 0)]);
rightBar = rect.left + barSize = get_bar_size( dwStyle, &pdi.rect );
MulDiv (infoPtr->CurVal - infoPtr->MinVal,
rect.right - rect.left, if (!barSmooth)
infoPtr->MaxVal - infoPtr->MinVal); pdi.ledW = get_led_size( infoPtr, dwStyle, &pdi.rect);
ledWidth = MulDiv (rect.bottom - rect.top, 2, 3);
rightMost = rect.right;
}
/* now draw the bar */ /* now draw the bar */
if (dwStyle & PBS_SMOOTH) if (dwStyle & PBS_MARQUEE)
{ {
if (dwStyle & PBS_VERTICAL) const int ledW = !barSmooth ? (pdi.ledW + LED_GAP) : 1;
const int leds = (barSize + ledW - 1) / ledW;
const int ledMEnd = infoPtr->MarqueePos + MARQUEE_LEDS;
if (ledMEnd > leds)
{ {
if (dwStyle & PBS_MARQUEE) /* case 1: the marquee bar extends over the end and wraps around to
{ * the start */
INT old_top, old_bottom, ledMStart, leds; const int gapStart = max((ledMEnd - leds) * ledW, 0);
old_top = rect.top; const int gapEnd = min(infoPtr->MarqueePos * ledW, barSize);
old_bottom = rect.bottom;
drawProcs[0]( &pdi, 0, gapStart);
leds = rect.bottom - rect.top; drawProcs[1]( &pdi, gapStart, gapEnd);
ledMStart = (infoPtr->MarqueePos + MARQUEE_LEDS) - leds; drawProcs[0]( &pdi, gapEnd, barSize);
if(ledMStart > 0)
{
rect.top = max(rect.bottom - ledMStart, old_top);
FillRect(hdc, &rect, hbrBar);
rect.bottom = rect.top;
}
if(infoPtr->MarqueePos > 0)
{
rect.top = max(old_bottom - infoPtr->MarqueePos, old_top);
FillRect(hdc, &rect, hbrBk);
rect.bottom = rect.top;
}
if(rect.top >= old_top)
{
rect.top = max(rect.bottom - MARQUEE_LEDS, old_top);
FillRect(hdc, &rect, hbrBar);
rect.bottom = rect.top;
}
if(rect.top >= old_top)
{
rect.top = old_top;
FillRect(hdc, &rect, hbrBk);
}
}
else
{
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
{ {
if (dwStyle & PBS_MARQUEE) /* case 2: the marquee bar is between start and end */
{ const int barStart = infoPtr->MarqueePos * ledW;
INT old_left, old_right, ledMStart, leds; const int barEnd = min (ledMEnd * ledW, barSize);
old_left = rect.left;
old_right = rect.right; drawProcs[1]( &pdi, 0, barStart);
drawProcs[0]( &pdi, barStart, barEnd);
leds = rect.right - rect.left; drawProcs[1]( &pdi, barEnd, barSize);
ledMStart = (infoPtr->MarqueePos + MARQUEE_LEDS) - leds;
rect.right = rect.left;
if(ledMStart > 0)
{
rect.right = min(rect.left + ledMStart, old_right);
FillRect(hdc, &rect, hbrBar);
rect.left = rect.right;
}
if(infoPtr->MarqueePos > 0)
{
rect.right = min(old_left + infoPtr->MarqueePos, old_right);
FillRect(hdc, &rect, hbrBk);
rect.left = rect.right;
}
if(rect.right < old_right)
{
rect.right = min(rect.left + MARQUEE_LEDS, old_right);
FillRect(hdc, &rect, hbrBar);
rect.left = rect.right;
}
if(rect.right < old_right)
{
rect.right = old_right;
FillRect(hdc, &rect, hbrBk);
}
}
else
{
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 { }
if (dwStyle & PBS_VERTICAL) { else
if (dwStyle & PBS_MARQUEE) {
{ int barEnd = get_bar_position( infoPtr, dwStyle, &pdi.rect,
INT i, old_top, old_bottom, ledMStart, leds; infoPtr->CurVal);
old_top = rect.top; if (!barSmooth)
old_bottom = rect.bottom; {
const int ledW = pdi.ledW + LED_GAP;
leds = ((rect.bottom - rect.top) + (ledWidth + LED_GAP) - 1) / (ledWidth + LED_GAP); barEnd = min (((barEnd + ledW - 1) / ledW) * ledW, barSize);
ledMStart = (infoPtr->MarqueePos + MARQUEE_LEDS) - leds;
while(ledMStart > 0)
{
rect.top = max(rect.bottom - ledWidth, old_top);
FillRect(hdc, &rect, hbrBar);
rect.bottom = rect.top;
rect.top -= LED_GAP;
if (rect.top <= old_top) break;
FillRect(hdc, &rect, hbrBk);
rect.bottom = rect.top;
ledMStart--;
}
if(infoPtr->MarqueePos > 0)
{
rect.top = max(old_bottom - (infoPtr->MarqueePos * (ledWidth + LED_GAP)), old_top);
FillRect(hdc, &rect, hbrBk);
rect.bottom = rect.top;
}
for(i = 0; i < MARQUEE_LEDS && rect.top >= old_top; i++)
{
rect.top = max(rect.bottom - ledWidth, old_top);
FillRect(hdc, &rect, hbrBar);
rect.bottom = rect.top;
rect.top -= LED_GAP;
if (rect.top <= old_top) break;
FillRect(hdc, &rect, hbrBk);
rect.bottom = rect.top;
}
if(rect.top >= old_top)
{
rect.top = old_top;
FillRect(hdc, &rect, hbrBk);
}
}
else
{
while(rect.bottom > rightBar) {
rect.top = rect.bottom - ledWidth;
if (rect.top < rightMost)
rect.top = rightMost;
FillRect(hdc, &rect, hbrBar);
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 {
if (dwStyle & PBS_MARQUEE)
{
INT i, old_right, old_left, ledMStart, leds;
old_left = rect.left;
old_right = rect.right;
leds = ((rect.right - rect.left) + ledWidth - 1) / (ledWidth + LED_GAP);
ledMStart = (infoPtr->MarqueePos + MARQUEE_LEDS) - leds;
rect.right = rect.left;
while(ledMStart > 0)
{
rect.right = min(rect.left + ledWidth, old_right);
FillRect(hdc, &rect, hbrBar);
rect.left = rect.right;
rect.right += LED_GAP;
if (rect.right > old_right) break;
FillRect(hdc, &rect, hbrBk);
rect.left = rect.right;
ledMStart--;
}
if(infoPtr->MarqueePos > 0)
{
rect.right = min(old_left + (infoPtr->MarqueePos * (ledWidth + LED_GAP)), old_right);
FillRect(hdc, &rect, hbrBk);
rect.left = rect.right;
}
for(i = 0; i < MARQUEE_LEDS && rect.right < old_right; i++)
{
rect.right = min(rect.left + ledWidth, old_right);
FillRect(hdc, &rect, hbrBar);
rect.left = rect.right;
rect.right += LED_GAP;
if (rect.right > old_right) break;
FillRect(hdc, &rect, hbrBk);
rect.left = rect.right;
}
if(rect.right < old_right)
{
rect.right = old_right;
FillRect(hdc, &rect, hbrBk);
}
}
else
{
while(rect.left < rightBar) {
rect.right = rect.left + ledWidth;
if (rect.right > rightMost)
rect.right = rightMost;
FillRect(hdc, &rect, hbrBar);
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);
}
} }
drawProcs[0]( &pdi, 0, barEnd);
drawProcs[1]( &pdi, barEnd, barSize);
} }
/* delete bar brush */ /* delete bar brush */
if (infoPtr->ColorBar != CLR_DEFAULT) DeleteObject (hbrBar); if (infoPtr->ColorBar != CLR_DEFAULT) DeleteObject (pdi.hbrBar);
if (infoPtr->ColorBk != CLR_DEFAULT) DeleteObject (hbrBk); if (infoPtr->ColorBk != CLR_DEFAULT) DeleteObject (pdi.hbrBk);
return 0; return 0;
} }
...@@ -406,45 +354,22 @@ static LRESULT PROGRESS_Timer (PROGRESS_INFO *infoPtr, INT idTimer) ...@@ -406,45 +354,22 @@ static LRESULT PROGRESS_Timer (PROGRESS_INFO *infoPtr, INT idTimer)
int ledWidth, leds; int ledWidth, leds;
GetClientRect (infoPtr->Self, &rect); GetClientRect (infoPtr->Self, &rect);
InflateRect(&rect, -1, -1);
if(!(style & PBS_SMOOTH)) if(!(style & PBS_SMOOTH))
{ ledWidth = get_led_size( infoPtr, style, &rect ) + LED_GAP;
int width, height;
if(style & PBS_VERTICAL)
{
width = rect.bottom - rect.top;
height = rect.right - rect.left;
}
else
{
height = rect.bottom - rect.top;
width = rect.right - rect.left;
}
ledWidth = MulDiv (height, 2, 3);
leds = (width + ledWidth - 1) / (ledWidth + LED_GAP);
}
else else
{
ledWidth = 1; ledWidth = 1;
if(style & PBS_VERTICAL)
{ leds = (get_bar_size( style, &rect ) + ledWidth - 1) /
leds = rect.bottom - rect.top; ledWidth;
}
else
{
leds = rect.right - rect.left;
}
}
/* increment the marquee progress */ /* increment the marquee progress */
if(++infoPtr->MarqueePos >= leds) if(++infoPtr->MarqueePos > leds)
{ {
infoPtr->MarqueePos = 0; infoPtr->MarqueePos = 0;
} }
InvalidateRect(infoPtr->Self, &rect, TRUE); InvalidateRect(infoPtr->Self, &rect, FALSE);
} }
return 0; return 0;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment