mirror of https://github.com/OpenTTD/OpenTTD
(svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
parent
72eb6ae278
commit
2cd25ed2ca
|
@ -184,17 +184,16 @@ void DrawFrameRect(int left, int top, int right, int bottom, int ctab, FrameFlag
|
||||||
void DrawWindowWidgets(const Window *w)
|
void DrawWindowWidgets(const Window *w)
|
||||||
{
|
{
|
||||||
const DrawPixelInfo* dpi = _cur_dpi;
|
const DrawPixelInfo* dpi = _cur_dpi;
|
||||||
Rect r;
|
|
||||||
uint i;
|
|
||||||
|
|
||||||
for (i = 0; i < w->widget_count; i++) {
|
for (uint i = 0; i < w->widget_count; i++) {
|
||||||
const Widget *wi = &w->widget[i];
|
const Widget *wi = &w->widget[i];
|
||||||
bool clicked = IsWindowWidgetLowered(w, i);
|
bool clicked = IsWindowWidgetLowered(w, i);
|
||||||
|
Rect r;
|
||||||
|
|
||||||
if (dpi->left > (r.right=/*w->left + */wi->right) ||
|
if (dpi->left > (r.right = wi->right) ||
|
||||||
dpi->left + dpi->width <= (r.left=wi->left/* + w->left*/) ||
|
dpi->left + dpi->width <= (r.left = wi->left) ||
|
||||||
dpi->top > (r.bottom=/*w->top +*/ wi->bottom) ||
|
dpi->top > (r.bottom = wi->bottom) ||
|
||||||
dpi->top + dpi->height <= (r.top = /*w->top +*/ wi->top) ||
|
dpi->top + dpi->height <= (r.top = wi->top) ||
|
||||||
IsWindowWidgetHidden(w, i)) {
|
IsWindowWidgetHidden(w, i)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -202,7 +201,7 @@ void DrawWindowWidgets(const Window *w)
|
||||||
switch (wi->type & WWT_MASK) {
|
switch (wi->type & WWT_MASK) {
|
||||||
case WWT_IMGBTN:
|
case WWT_IMGBTN:
|
||||||
case WWT_IMGBTN_2: {
|
case WWT_IMGBTN_2: {
|
||||||
int img = wi->data;
|
SpriteID img = wi->data;
|
||||||
assert(img != 0);
|
assert(img != 0);
|
||||||
DrawFrameRect(r.left, r.top, r.right, r.bottom, wi->color, (clicked) ? FR_LOWERED : FR_NONE);
|
DrawFrameRect(r.left, r.top, r.right, r.bottom, wi->color, (clicked) ? FR_LOWERED : FR_NONE);
|
||||||
|
|
||||||
|
@ -234,14 +233,14 @@ void DrawWindowWidgets(const Window *w)
|
||||||
}
|
}
|
||||||
|
|
||||||
case WWT_TEXT: {
|
case WWT_TEXT: {
|
||||||
StringID str = wi->data;
|
const StringID str = wi->data;
|
||||||
|
|
||||||
if (str != STR_NULL) DrawStringTruncated(r.left, r.top, str, wi->color, r.right - r.left);
|
if (str != STR_NULL) DrawStringTruncated(r.left, r.top, str, wi->color, r.right - r.left);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case WWT_INSET: {
|
case WWT_INSET: {
|
||||||
StringID str = wi->data;
|
const StringID str = wi->data;
|
||||||
DrawFrameRect(r.left, r.top, r.right, r.bottom, wi->color, FR_LOWERED | FR_DARKENED);
|
DrawFrameRect(r.left, r.top, r.right, r.bottom, wi->color, FR_LOWERED | FR_DARKENED);
|
||||||
|
|
||||||
if (str != STR_NULL) DrawStringTruncated(r.left + 2, r.top + 1, str, TC_FROMSTRING, r.right - r.left - 10);
|
if (str != STR_NULL) DrawStringTruncated(r.left + 2, r.top + 1, str, TC_FROMSTRING, r.right - r.left - 10);
|
||||||
|
@ -297,6 +296,7 @@ void DrawWindowWidgets(const Window *w)
|
||||||
Point pt;
|
Point pt;
|
||||||
int c1, c2;
|
int c1, c2;
|
||||||
|
|
||||||
|
assert(wi->data == 0);
|
||||||
assert(r.right - r.left == 11); // XXX - to ensure the same sizes are used everywhere!
|
assert(r.right - r.left == 11); // XXX - to ensure the same sizes are used everywhere!
|
||||||
|
|
||||||
/* draw up/down buttons */
|
/* draw up/down buttons */
|
||||||
|
@ -329,6 +329,7 @@ void DrawWindowWidgets(const Window *w)
|
||||||
Point pt;
|
Point pt;
|
||||||
int c1, c2;
|
int c1, c2;
|
||||||
|
|
||||||
|
assert(wi->data == 0);
|
||||||
assert(r.right - r.left == 11); // XXX - to ensure the same sizes are used everywhere!
|
assert(r.right - r.left == 11); // XXX - to ensure the same sizes are used everywhere!
|
||||||
|
|
||||||
/* draw up/down buttons */
|
/* draw up/down buttons */
|
||||||
|
@ -363,6 +364,7 @@ void DrawWindowWidgets(const Window *w)
|
||||||
Point pt;
|
Point pt;
|
||||||
int c1, c2;
|
int c1, c2;
|
||||||
|
|
||||||
|
assert(wi->data == 0);
|
||||||
assert(r.bottom - r.top == 11); // XXX - to ensure the same sizes are used everywhere!
|
assert(r.bottom - r.top == 11); // XXX - to ensure the same sizes are used everywhere!
|
||||||
|
|
||||||
clicked = ((w->flags4 & (WF_SCROLL_UP | WF_HSCROLL)) == (WF_SCROLL_UP | WF_HSCROLL));
|
clicked = ((w->flags4 & (WF_SCROLL_UP | WF_HSCROLL)) == (WF_SCROLL_UP | WF_HSCROLL));
|
||||||
|
@ -394,10 +396,11 @@ void DrawWindowWidgets(const Window *w)
|
||||||
}
|
}
|
||||||
|
|
||||||
case WWT_FRAME: {
|
case WWT_FRAME: {
|
||||||
|
const StringID str = wi->data;
|
||||||
int c1, c2;
|
int c1, c2;
|
||||||
int x2 = r.left; // by default the left side is the left side of the widget
|
int x2 = r.left; // by default the left side is the left side of the widget
|
||||||
|
|
||||||
if (wi->data != 0) x2 = DrawString(r.left + 6, r.top, wi->data, TC_FROMSTRING);
|
if (str != STR_NULL) x2 = DrawString(r.left + 6, r.top, str, TC_FROMSTRING);
|
||||||
|
|
||||||
c1 = _colour_gradient[wi->color][3];
|
c1 = _colour_gradient[wi->color][3];
|
||||||
c2 = _colour_gradient[wi->color][7];
|
c2 = _colour_gradient[wi->color][7];
|
||||||
|
@ -425,6 +428,7 @@ void DrawWindowWidgets(const Window *w)
|
||||||
}
|
}
|
||||||
|
|
||||||
case WWT_STICKYBOX: {
|
case WWT_STICKYBOX: {
|
||||||
|
assert(wi->data == 0);
|
||||||
assert(r.right - r.left == 11); // XXX - to ensure the same sizes are used everywhere!
|
assert(r.right - r.left == 11); // XXX - to ensure the same sizes are used everywhere!
|
||||||
|
|
||||||
clicked = !!(w->flags4 & WF_STICKY);
|
clicked = !!(w->flags4 & WF_STICKY);
|
||||||
|
@ -434,6 +438,7 @@ void DrawWindowWidgets(const Window *w)
|
||||||
}
|
}
|
||||||
|
|
||||||
case WWT_RESIZEBOX: {
|
case WWT_RESIZEBOX: {
|
||||||
|
assert(wi->data == 0);
|
||||||
assert(r.right - r.left == 11); // XXX - to ensure the same sizes are used everywhere!
|
assert(r.right - r.left == 11); // XXX - to ensure the same sizes are used everywhere!
|
||||||
|
|
||||||
clicked = !!(w->flags4 & WF_SIZING);
|
clicked = !!(w->flags4 & WF_SIZING);
|
||||||
|
@ -443,10 +448,13 @@ void DrawWindowWidgets(const Window *w)
|
||||||
}
|
}
|
||||||
|
|
||||||
case WWT_CLOSEBOX: {
|
case WWT_CLOSEBOX: {
|
||||||
|
const StringID str = wi->data;
|
||||||
|
|
||||||
|
assert(str == STR_00C5 || str == STR_00C6); // black or silver cross
|
||||||
assert(r.right - r.left == 10); // ensure the same sizes are used everywhere
|
assert(r.right - r.left == 10); // ensure the same sizes are used everywhere
|
||||||
|
|
||||||
DrawFrameRect(r.left, r.top, r.right, r.bottom, wi->color, FR_NONE);
|
DrawFrameRect(r.left, r.top, r.right, r.bottom, wi->color, FR_NONE);
|
||||||
DrawString(r.left + 2, r.top + 2, STR_00C5, TC_FROMSTRING);
|
DrawString(r.left + 2, r.top + 2, str, TC_FROMSTRING);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -470,7 +478,6 @@ draw_default:;
|
||||||
|
|
||||||
|
|
||||||
if (w->flags4 & WF_WHITE_BORDER_MASK) {
|
if (w->flags4 & WF_WHITE_BORDER_MASK) {
|
||||||
//DrawFrameRect(w->left, w->top, w->left + w->width-1, w->top+w->height-1, 0xF, 0x10);
|
|
||||||
DrawFrameRect(0, 0, w->width - 1, w->height - 1, 0xF, FR_BORDERONLY);
|
DrawFrameRect(0, 0, w->width - 1, w->height - 1, 0xF, FR_BORDERONLY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue