(svn r18168) -Codechange: Adjust a frame's child's padding to account for text height, and draw the top bar appropriately.

This commit is contained in:
peter1138 2009-11-18 18:17:27 +00:00
parent 964f2ca7fe
commit f7722d8a2b

View File

@ -418,31 +418,36 @@ static inline void DrawFrame(const Rect &r, Colours colour, StringID str)
int c1 = _colour_gradient[colour][3]; int c1 = _colour_gradient[colour][3];
int c2 = _colour_gradient[colour][7]; int c2 = _colour_gradient[colour][7];
/* If the frame has text, adjust the top bar to fit half-way through */
int dy1 = 4;
if (str != STR_NULL) dy1 = FONT_HEIGHT_NORMAL / 2 - 1;
int dy2 = dy1 + 1;
if (_dynlang.text_dir == TD_LTR) { if (_dynlang.text_dir == TD_LTR) {
/* Line from upper left corner to start of text */ /* Line from upper left corner to start of text */
GfxFillRect(r.left, r.top + 4, r.left + 4, r.top + 4, c1); GfxFillRect(r.left, r.top + dy1, r.left + 4, r.top + dy1, c1);
GfxFillRect(r.left + 1, r.top + 5, r.left + 4, r.top + 5, c2); GfxFillRect(r.left + 1, r.top + dy2, r.left + 4, r.top + dy2, c2);
/* Line from end of text to upper right corner */ /* Line from end of text to upper right corner */
GfxFillRect(x2, r.top + 4, r.right - 1, r.top + 4, c1); GfxFillRect(x2, r.top + dy1, r.right - 1, r.top + dy1, c1);
GfxFillRect(x2, r.top + 5, r.right - 2, r.top + 5, c2); GfxFillRect(x2, r.top + dy2, r.right - 2, r.top + dy2, c2);
} else { } else {
/* Line from upper left corner to start of text */ /* Line from upper left corner to start of text */
GfxFillRect(r.left, r.top + 4, x2 - 2, r.top + 4, c1); GfxFillRect(r.left, r.top + dy1, x2 - 2, r.top + dy1, c1);
GfxFillRect(r.left + 1, r.top + 5, x2 - 2, r.top + 5, c2); GfxFillRect(r.left + 1, r.top + dy2, x2 - 2, r.top + dy2, c2);
/* Line from end of text to upper right corner */ /* Line from end of text to upper right corner */
GfxFillRect(r.right - 5, r.top + 4, r.right - 1, r.top + 4, c1); GfxFillRect(r.right - 5, r.top + dy1, r.right - 1, r.top + dy1, c1);
GfxFillRect(r.right - 5, r.top + 5, r.right - 2, r.top + 5, c2); GfxFillRect(r.right - 5, r.top + dy2, r.right - 2, r.top + dy2, c2);
} }
/* Line from upper left corner to bottom left corner */ /* Line from upper left corner to bottom left corner */
GfxFillRect(r.left, r.top + 5, r.left, r.bottom - 1, c1); GfxFillRect(r.left, r.top + dy2, r.left, r.bottom - 1, c1);
GfxFillRect(r.left + 1, r.top + 6, r.left + 1, r.bottom - 2, c2); GfxFillRect(r.left + 1, r.top + dy2 + 1, r.left + 1, r.bottom - 2, c2);
/* Line from upper right corner to bottom right corner */ /* Line from upper right corner to bottom right corner */
GfxFillRect(r.right - 1, r.top + 5, r.right - 1, r.bottom - 2, c1); GfxFillRect(r.right - 1, r.top + dy2, r.right - 1, r.bottom - 2, c1);
GfxFillRect(r.right, r.top + 4, r.right, r.bottom - 1, c2); GfxFillRect(r.right, r.top + dy1, r.right, r.bottom - 1, c2);
GfxFillRect(r.left + 1, r.bottom - 1, r.right - 1, r.bottom - 1, c1); GfxFillRect(r.left + 1, r.bottom - 1, r.right - 1, r.bottom - 1, c1);
GfxFillRect(r.left, r.bottom, r.right, r.bottom, c2); GfxFillRect(r.left, r.bottom, r.right, r.bottom, c2);
@ -1458,6 +1463,14 @@ void NWidgetBackground::SetupSmallestSize(Window *w, bool init_array)
if (w != NULL && this->type == WWT_FRAME) { if (w != NULL && this->type == WWT_FRAME) {
if (this->index >= 0) w->SetStringParameters(this->index); if (this->index >= 0) w->SetStringParameters(this->index);
this->smallest_x = max(this->smallest_x, GetStringBoundingBox(this->widget_data).width + WD_FRAMETEXT_LEFT + WD_FRAMETEXT_RIGHT); this->smallest_x = max(this->smallest_x, GetStringBoundingBox(this->widget_data).width + WD_FRAMETEXT_LEFT + WD_FRAMETEXT_RIGHT);
if (this->widget_data != STR_NULL) {
/* Adjust child's padding to fit text. We assume that the
* original padding is designed around the 10 pixel high
* sprite font. */
int y = FONT_HEIGHT_NORMAL - 10;
this->child->padding_top += y;
this->smallest_y += y;
}
} }
} else { } else {
Dimension d = {this->min_x, this->min_y}; Dimension d = {this->min_x, this->min_y};