Change: Rename text colour NWidgetPart to SetTextStyle and add font size.

This allows to set both text colour and size for any widget with default
drawing.
This commit is contained in:
Peter Nelson 2023-04-28 17:59:14 +01:00 committed by PeterN
parent ba3de0383a
commit 35ba49bfb4
6 changed files with 63 additions and 51 deletions

View File

@ -1280,81 +1280,81 @@ static const NWidgetPart _nested_select_company_manager_face_widgets[] = {
NWidget(NWID_SPACER), SetMinimalSize(0, 4),
NWidget(NWID_HORIZONTAL),
NWidget(WWT_TEXT, INVALID_COLOUR, WID_SCMF_HAS_MOUSTACHE_EARRING_TEXT), SetFill(1, 0), SetPadding(WidgetDimensions::unscaled.framerect),
SetDataTip(STR_FACE_EYECOLOUR, STR_NULL), SetTextColour(TC_GOLD), SetAlignment(SA_VERT_CENTER | SA_RIGHT),
SetDataTip(STR_FACE_EYECOLOUR, STR_NULL), SetTextStyle(TC_GOLD), SetAlignment(SA_VERT_CENTER | SA_RIGHT),
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SCMF_HAS_MOUSTACHE_EARRING), SetDataTip(STR_WHITE_STRING, STR_FACE_MOUSTACHE_EARRING_TOOLTIP),
EndContainer(),
NWidget(NWID_HORIZONTAL),
NWidget(WWT_TEXT, INVALID_COLOUR, WID_SCMF_HAS_GLASSES_TEXT), SetFill(1, 0), SetPadding(WidgetDimensions::unscaled.framerect),
SetDataTip(STR_FACE_GLASSES, STR_NULL), SetTextColour(TC_GOLD), SetAlignment(SA_VERT_CENTER | SA_RIGHT),
SetDataTip(STR_FACE_GLASSES, STR_NULL), SetTextStyle(TC_GOLD), SetAlignment(SA_VERT_CENTER | SA_RIGHT),
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SCMF_HAS_GLASSES), SetDataTip(STR_WHITE_STRING, STR_FACE_GLASSES_TOOLTIP),
EndContainer(),
NWidget(NWID_SPACER), SetMinimalSize(0, 2), SetFill(1, 0),
NWidget(NWID_HORIZONTAL),
NWidget(WWT_TEXT, INVALID_COLOUR, WID_SCMF_HAIR_TEXT), SetFill(1, 0), SetPadding(WidgetDimensions::unscaled.framerect),
SetDataTip(STR_FACE_HAIR, STR_NULL), SetTextColour(TC_GOLD), SetAlignment(SA_VERT_CENTER | SA_RIGHT),
SetDataTip(STR_FACE_HAIR, STR_NULL), SetTextStyle(TC_GOLD), SetAlignment(SA_VERT_CENTER | SA_RIGHT),
NWidget(WWT_PUSHARROWBTN, COLOUR_GREY, WID_SCMF_HAIR_L), SetDataTip(AWV_DECREASE, STR_FACE_HAIR_TOOLTIP),
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SCMF_HAIR), SetDataTip(STR_WHITE_STRING, STR_FACE_HAIR_TOOLTIP),
NWidget(WWT_PUSHARROWBTN, COLOUR_GREY, WID_SCMF_HAIR_R), SetDataTip(AWV_INCREASE, STR_FACE_HAIR_TOOLTIP),
EndContainer(),
NWidget(NWID_HORIZONTAL),
NWidget(WWT_TEXT, INVALID_COLOUR, WID_SCMF_EYEBROWS_TEXT), SetFill(1, 0), SetPadding(WidgetDimensions::unscaled.framerect),
SetDataTip(STR_FACE_EYEBROWS, STR_NULL), SetTextColour(TC_GOLD), SetAlignment(SA_VERT_CENTER | SA_RIGHT),
SetDataTip(STR_FACE_EYEBROWS, STR_NULL), SetTextStyle(TC_GOLD), SetAlignment(SA_VERT_CENTER | SA_RIGHT),
NWidget(WWT_PUSHARROWBTN, COLOUR_GREY, WID_SCMF_EYEBROWS_L), SetDataTip(AWV_DECREASE, STR_FACE_EYEBROWS_TOOLTIP),
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SCMF_EYEBROWS), SetDataTip(STR_WHITE_STRING, STR_FACE_EYEBROWS_TOOLTIP),
NWidget(WWT_PUSHARROWBTN, COLOUR_GREY, WID_SCMF_EYEBROWS_R), SetDataTip(AWV_INCREASE, STR_FACE_EYEBROWS_TOOLTIP),
EndContainer(),
NWidget(NWID_HORIZONTAL),
NWidget(WWT_TEXT, INVALID_COLOUR, WID_SCMF_EYECOLOUR_TEXT), SetFill(1, 0), SetPadding(WidgetDimensions::unscaled.framerect),
SetDataTip(STR_FACE_EYECOLOUR, STR_NULL), SetTextColour(TC_GOLD), SetAlignment(SA_VERT_CENTER | SA_RIGHT),
SetDataTip(STR_FACE_EYECOLOUR, STR_NULL), SetTextStyle(TC_GOLD), SetAlignment(SA_VERT_CENTER | SA_RIGHT),
NWidget(WWT_PUSHARROWBTN, COLOUR_GREY, WID_SCMF_EYECOLOUR_L), SetDataTip(AWV_DECREASE, STR_FACE_EYECOLOUR_TOOLTIP),
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SCMF_EYECOLOUR), SetDataTip(STR_WHITE_STRING, STR_FACE_EYECOLOUR_TOOLTIP),
NWidget(WWT_PUSHARROWBTN, COLOUR_GREY, WID_SCMF_EYECOLOUR_R), SetDataTip(AWV_INCREASE, STR_FACE_EYECOLOUR_TOOLTIP),
EndContainer(),
NWidget(NWID_HORIZONTAL),
NWidget(WWT_TEXT, INVALID_COLOUR, WID_SCMF_GLASSES_TEXT), SetFill(1, 0), SetPadding(WidgetDimensions::unscaled.framerect),
SetDataTip(STR_FACE_GLASSES, STR_NULL), SetTextColour(TC_GOLD), SetAlignment(SA_VERT_CENTER | SA_RIGHT),
SetDataTip(STR_FACE_GLASSES, STR_NULL), SetTextStyle(TC_GOLD), SetAlignment(SA_VERT_CENTER | SA_RIGHT),
NWidget(WWT_PUSHARROWBTN, COLOUR_GREY, WID_SCMF_GLASSES_L), SetDataTip(AWV_DECREASE, STR_FACE_GLASSES_TOOLTIP_2),
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SCMF_GLASSES), SetDataTip(STR_WHITE_STRING, STR_FACE_GLASSES_TOOLTIP_2),
NWidget(WWT_PUSHARROWBTN, COLOUR_GREY, WID_SCMF_GLASSES_R), SetDataTip(AWV_INCREASE, STR_FACE_GLASSES_TOOLTIP_2),
EndContainer(),
NWidget(NWID_HORIZONTAL),
NWidget(WWT_TEXT, INVALID_COLOUR, WID_SCMF_NOSE_TEXT), SetFill(1, 0), SetPadding(WidgetDimensions::unscaled.framerect),
SetDataTip(STR_FACE_NOSE, STR_NULL), SetTextColour(TC_GOLD), SetAlignment(SA_VERT_CENTER | SA_RIGHT),
SetDataTip(STR_FACE_NOSE, STR_NULL), SetTextStyle(TC_GOLD), SetAlignment(SA_VERT_CENTER | SA_RIGHT),
NWidget(WWT_PUSHARROWBTN, COLOUR_GREY, WID_SCMF_NOSE_L), SetDataTip(AWV_DECREASE, STR_FACE_NOSE_TOOLTIP),
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SCMF_NOSE), SetDataTip(STR_WHITE_STRING, STR_FACE_NOSE_TOOLTIP),
NWidget(WWT_PUSHARROWBTN, COLOUR_GREY, WID_SCMF_NOSE_R), SetDataTip(AWV_INCREASE, STR_FACE_NOSE_TOOLTIP),
EndContainer(),
NWidget(NWID_HORIZONTAL),
NWidget(WWT_TEXT, INVALID_COLOUR, WID_SCMF_LIPS_MOUSTACHE_TEXT), SetFill(1, 0), SetPadding(WidgetDimensions::unscaled.framerect),
SetDataTip(STR_FACE_MOUSTACHE, STR_NULL), SetTextColour(TC_GOLD), SetAlignment(SA_VERT_CENTER | SA_RIGHT),
SetDataTip(STR_FACE_MOUSTACHE, STR_NULL), SetTextStyle(TC_GOLD), SetAlignment(SA_VERT_CENTER | SA_RIGHT),
NWidget(WWT_PUSHARROWBTN, COLOUR_GREY, WID_SCMF_LIPS_MOUSTACHE_L), SetDataTip(AWV_DECREASE, STR_FACE_LIPS_MOUSTACHE_TOOLTIP),
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SCMF_LIPS_MOUSTACHE), SetDataTip(STR_WHITE_STRING, STR_FACE_LIPS_MOUSTACHE_TOOLTIP),
NWidget(WWT_PUSHARROWBTN, COLOUR_GREY, WID_SCMF_LIPS_MOUSTACHE_R), SetDataTip(AWV_INCREASE, STR_FACE_LIPS_MOUSTACHE_TOOLTIP),
EndContainer(),
NWidget(NWID_HORIZONTAL),
NWidget(WWT_TEXT, INVALID_COLOUR, WID_SCMF_CHIN_TEXT), SetFill(1, 0), SetPadding(WidgetDimensions::unscaled.framerect),
SetDataTip(STR_FACE_CHIN, STR_NULL), SetTextColour(TC_GOLD), SetAlignment(SA_VERT_CENTER | SA_RIGHT),
SetDataTip(STR_FACE_CHIN, STR_NULL), SetTextStyle(TC_GOLD), SetAlignment(SA_VERT_CENTER | SA_RIGHT),
NWidget(WWT_PUSHARROWBTN, COLOUR_GREY, WID_SCMF_CHIN_L), SetDataTip(AWV_DECREASE, STR_FACE_CHIN_TOOLTIP),
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SCMF_CHIN), SetDataTip(STR_WHITE_STRING, STR_FACE_CHIN_TOOLTIP),
NWidget(WWT_PUSHARROWBTN, COLOUR_GREY, WID_SCMF_CHIN_R), SetDataTip(AWV_INCREASE, STR_FACE_CHIN_TOOLTIP),
EndContainer(),
NWidget(NWID_HORIZONTAL),
NWidget(WWT_TEXT, INVALID_COLOUR, WID_SCMF_JACKET_TEXT), SetFill(1, 0), SetPadding(WidgetDimensions::unscaled.framerect),
SetDataTip(STR_FACE_JACKET, STR_NULL), SetTextColour(TC_GOLD), SetAlignment(SA_VERT_CENTER | SA_RIGHT),
SetDataTip(STR_FACE_JACKET, STR_NULL), SetTextStyle(TC_GOLD), SetAlignment(SA_VERT_CENTER | SA_RIGHT),
NWidget(WWT_PUSHARROWBTN, COLOUR_GREY, WID_SCMF_JACKET_L), SetDataTip(AWV_DECREASE, STR_FACE_JACKET_TOOLTIP),
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SCMF_JACKET), SetDataTip(STR_WHITE_STRING, STR_FACE_JACKET_TOOLTIP),
NWidget(WWT_PUSHARROWBTN, COLOUR_GREY, WID_SCMF_JACKET_R), SetDataTip(AWV_INCREASE, STR_FACE_JACKET_TOOLTIP),
EndContainer(),
NWidget(NWID_HORIZONTAL),
NWidget(WWT_TEXT, INVALID_COLOUR, WID_SCMF_COLLAR_TEXT), SetFill(1, 0), SetPadding(WidgetDimensions::unscaled.framerect),
SetDataTip(STR_FACE_COLLAR, STR_NULL), SetTextColour(TC_GOLD), SetAlignment(SA_VERT_CENTER | SA_RIGHT),
SetDataTip(STR_FACE_COLLAR, STR_NULL), SetTextStyle(TC_GOLD), SetAlignment(SA_VERT_CENTER | SA_RIGHT),
NWidget(WWT_PUSHARROWBTN, COLOUR_GREY, WID_SCMF_COLLAR_L), SetDataTip(AWV_DECREASE, STR_FACE_COLLAR_TOOLTIP),
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SCMF_COLLAR), SetDataTip(STR_WHITE_STRING, STR_FACE_COLLAR_TOOLTIP),
NWidget(WWT_PUSHARROWBTN, COLOUR_GREY, WID_SCMF_COLLAR_R), SetDataTip(AWV_INCREASE, STR_FACE_COLLAR_TOOLTIP),
EndContainer(),
NWidget(NWID_HORIZONTAL),
NWidget(WWT_TEXT, INVALID_COLOUR, WID_SCMF_TIE_EARRING_TEXT), SetFill(1, 0), SetPadding(WidgetDimensions::unscaled.framerect),
SetDataTip(STR_FACE_EARRING, STR_NULL), SetTextColour(TC_GOLD), SetAlignment(SA_VERT_CENTER | SA_RIGHT),
SetDataTip(STR_FACE_EARRING, STR_NULL), SetTextStyle(TC_GOLD), SetAlignment(SA_VERT_CENTER | SA_RIGHT),
NWidget(WWT_PUSHARROWBTN, COLOUR_GREY, WID_SCMF_TIE_EARRING_L), SetDataTip(AWV_DECREASE, STR_FACE_TIE_EARRING_TOOLTIP),
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SCMF_TIE_EARRING), SetDataTip(STR_WHITE_STRING, STR_FACE_TIE_EARRING_TOOLTIP),
NWidget(WWT_PUSHARROWBTN, COLOUR_GREY, WID_SCMF_TIE_EARRING_R), SetDataTip(AWV_INCREASE, STR_FACE_TIE_EARRING_TOOLTIP),

View File

@ -245,7 +245,7 @@ static const NWidgetPart _nested_heightmap_load_widgets[] = {
EndContainer(),
/* All other columns. */
NWidget(NWID_VERTICAL), SetPIP(0, 4, 0),
NWidget(WWT_TEXT, COLOUR_ORANGE, WID_GL_HEIGHTMAP_NAME_TEXT), SetTextColour(TC_ORANGE), SetDataTip(STR_JUST_RAW_STRING, STR_EMPTY), SetFill(1, 0),
NWidget(WWT_TEXT, COLOUR_ORANGE, WID_GL_HEIGHTMAP_NAME_TEXT), SetTextStyle(TC_ORANGE), SetDataTip(STR_JUST_RAW_STRING, STR_EMPTY), SetFill(1, 0),
NWidget(NWID_HORIZONTAL), SetPIP(0, 5, 0),
/* Left half widgets (global column 2) */
NWidget(NWID_VERTICAL, NC_EQUALSIZE), SetPIP(0, 4, 0),

View File

@ -422,7 +422,7 @@ struct NewsWindow : Window {
{
switch (widget) {
case WID_N_CAPTION:
DrawCaption(r, COLOUR_LIGHT_BLUE, this->owner, TC_FROMSTRING, STR_NEWS_MESSAGE_CAPTION, SA_CENTER);
DrawCaption(r, COLOUR_LIGHT_BLUE, this->owner, TC_FROMSTRING, STR_NEWS_MESSAGE_CAPTION, SA_CENTER, FS_NORMAL);
break;
case WID_N_PANEL:

View File

@ -486,15 +486,16 @@ static inline void DrawImageButtons(const Rect &r, WidgetType type, Colours colo
* @param colour Colour of the text.
* @param str Text to draw.
* @param align Alignment of the text.
* @param fs Font size of the text.
*/
static inline void DrawLabel(const Rect &r, WidgetType type, bool clicked, TextColour colour, StringID str, StringAlignment align)
static inline void DrawLabel(const Rect &r, WidgetType type, bool clicked, TextColour colour, StringID str, StringAlignment align, FontSize fs)
{
if (str == STR_NULL) return;
if ((type & WWT_MASK) == WWT_TEXTBTN_2 && clicked) str++;
Dimension d = GetStringBoundingBox(str);
Dimension d = GetStringBoundingBox(str, fs);
Point p = GetAlignedPosition(r, d, align);
int o = clicked ? WidgetDimensions::scaled.pressed : 0;
DrawString(r.left + o, r.right + o, p.y + o, str, colour, align);
DrawString(r.left + o, r.right + o, p.y + o, str, colour, align, false, fs);
}
/**
@ -503,12 +504,13 @@ static inline void DrawLabel(const Rect &r, WidgetType type, bool clicked, TextC
* @param colour Colour of the text.
* @param str Text to draw.
* @param align Alignment of the text.
* @param fs Font size of the text.
*/
static inline void DrawText(const Rect &r, TextColour colour, StringID str, StringAlignment align)
static inline void DrawText(const Rect &r, TextColour colour, StringID str, StringAlignment align, FontSize fs)
{
Dimension d = GetStringBoundingBox(str);
Dimension d = GetStringBoundingBox(str, fs);
Point p = GetAlignedPosition(r, d, align);
if (str != STR_NULL) DrawString(r.left, r.right, p.y, str, colour, align);
if (str != STR_NULL) DrawString(r.left, r.right, p.y, str, colour, align, fs);
}
/**
@ -518,11 +520,12 @@ static inline void DrawText(const Rect &r, TextColour colour, StringID str, Stri
* @param text_colour Colour of the text.
* @param str Text to draw.
* @param align Alignment of the text.
* @param fs Font size of the text.
*/
static inline void DrawInset(const Rect &r, Colours colour, TextColour text_colour, StringID str, StringAlignment align)
static inline void DrawInset(const Rect &r, Colours colour, TextColour text_colour, StringID str, StringAlignment align, FontSize fs)
{
DrawFrameRect(r.left, r.top, r.right, r.bottom, colour, FR_LOWERED | FR_DARKENED);
if (str != STR_NULL) DrawString(r.Shrink(WidgetDimensions::scaled.inset), str, text_colour, align);
if (str != STR_NULL) DrawString(r.Shrink(WidgetDimensions::scaled.inset), str, text_colour, align, false, fs);
}
/**
@ -672,12 +675,13 @@ static inline void DrawHorizontalScrollbar(const Rect &r, Colours colour, bool l
* @param text_colour Colour of the text.
* @param str Text of the frame.
* @param align Alignment of the text in the frame.
* @param fs Font size of the text.
*/
static inline void DrawFrame(const Rect &r, Colours colour, TextColour text_colour, StringID str, StringAlignment align)
static inline void DrawFrame(const Rect &r, Colours colour, TextColour text_colour, StringID str, StringAlignment align, FontSize fs)
{
int x2 = r.left; // by default the left side is the left side of the widget
if (str != STR_NULL) x2 = DrawString(r.left + WidgetDimensions::scaled.frametext.left, r.right - WidgetDimensions::scaled.frametext.right, r.top, str, text_colour, align);
if (str != STR_NULL) x2 = DrawString(r.left + WidgetDimensions::scaled.frametext.left, r.right - WidgetDimensions::scaled.frametext.right, r.top, str, text_colour, align, false, fs);
int c1 = _colour_gradient[colour][3];
int c2 = _colour_gradient[colour][7];
@ -801,8 +805,9 @@ static inline void DrawCloseBox(const Rect &r, Colours colour)
* @param text_colour Colour of the text.
* @param str Text to draw in the bar.
* @param align Alignment of the text.
* @param fs Font size of the text.
*/
void DrawCaption(const Rect &r, Colours colour, Owner owner, TextColour text_colour, StringID str, StringAlignment align)
void DrawCaption(const Rect &r, Colours colour, Owner owner, TextColour text_colour, StringID str, StringAlignment align, FontSize fs)
{
bool company_owned = owner < MAX_COMPANIES;
@ -817,7 +822,7 @@ void DrawCaption(const Rect &r, Colours colour, Owner owner, TextColour text_col
if (str != STR_NULL) {
Dimension d = GetStringBoundingBox(str);
Point p = GetAlignedPosition(r, d, align);
DrawString(r.left + WidgetDimensions::scaled.captiontext.left, r.right - WidgetDimensions::scaled.captiontext.left, p.y, str, text_colour, align);
DrawString(r.left + WidgetDimensions::scaled.captiontext.left, r.right - WidgetDimensions::scaled.captiontext.left, p.y, str, text_colour, align, false, fs);
}
}
@ -1168,6 +1173,7 @@ NWidgetCore::NWidgetCore(WidgetType tp, Colours colour, uint fill_x, uint fill_y
this->tool_tip = tool_tip;
this->scrollbar_index = -1;
this->text_colour = TC_BLACK;
this->text_size = FS_NORMAL;
this->align = SA_CENTER;
}
@ -1193,12 +1199,14 @@ void NWidgetCore::SetDataTip(uint32 widget_data, StringID tool_tip)
}
/**
* Set the text colour of the nested widget.
* Set the text style of the nested widget.
* @param colour TextColour to use.
* @param size Font size to use.
*/
void NWidgetCore::SetTextColour(TextColour colour)
void NWidgetCore::SetTextStyle(TextColour colour, FontSize size)
{
this->text_colour = colour;
this->text_size = size;
}
/**
@ -2175,7 +2183,7 @@ void NWidgetBackground::SetupSmallestSize(Window *w, bool init_array)
this->smallest_y += this->child->padding.Vertical();
if (this->index >= 0) w->SetStringParameters(this->index);
this->smallest_x = std::max(this->smallest_x, GetStringBoundingBox(this->widget_data).width + WidgetDimensions::scaled.frametext.Horizontal());
this->smallest_x = std::max(this->smallest_x, GetStringBoundingBox(this->widget_data, this->text_size).width + WidgetDimensions::scaled.frametext.Horizontal());
} else if (this->type == WWT_INSET) {
/* Apply automatic padding for bevel thickness. */
this->child->padding = WidgetDimensions::scaled.bevel;
@ -2190,7 +2198,7 @@ void NWidgetBackground::SetupSmallestSize(Window *w, bool init_array)
if (w != nullptr) { // A non-nullptr window pointer acts as switch to turn dynamic widget size on.
if (this->type == WWT_FRAME || this->type == WWT_INSET) {
if (this->index >= 0) w->SetStringParameters(this->index);
Dimension background = GetStringBoundingBox(this->widget_data);
Dimension background = GetStringBoundingBox(this->widget_data, this->text_size);
background.width += (this->type == WWT_FRAME) ? (WidgetDimensions::scaled.frametext.Horizontal()) : (WidgetDimensions::scaled.inset.Horizontal());
d = maxdim(d, background);
}
@ -2249,12 +2257,12 @@ void NWidgetBackground::Draw(const Window *w)
case WWT_FRAME:
if (this->index >= 0) w->SetStringParameters(this->index);
DrawFrame(r, this->colour, this->text_colour, this->widget_data, this->align);
DrawFrame(r, this->colour, this->text_colour, this->widget_data, this->align, this->text_size);
break;
case WWT_INSET:
if (this->index >= 0) w->SetStringParameters(this->index);
DrawInset(r, this->colour, this->text_colour, this->widget_data, this->align);
DrawInset(r, this->colour, this->text_colour, this->widget_data, this->align, this->text_size);
break;
default:
@ -2793,7 +2801,7 @@ void NWidgetLeaf::SetupSmallestSize(Window *w, bool init_array)
case WWT_TEXTBTN_2: {
padding = {WidgetDimensions::scaled.framerect.Horizontal(), WidgetDimensions::scaled.framerect.Vertical()};
if (this->index >= 0) w->SetStringParameters(this->index);
Dimension d2 = GetStringBoundingBox(this->widget_data);
Dimension d2 = GetStringBoundingBox(this->widget_data, this->text_size);
d2.width += padding.width;
d2.height += padding.height;
size = maxdim(size, d2);
@ -2802,13 +2810,13 @@ void NWidgetLeaf::SetupSmallestSize(Window *w, bool init_array)
case WWT_LABEL:
case WWT_TEXT: {
if (this->index >= 0) w->SetStringParameters(this->index);
size = maxdim(size, GetStringBoundingBox(this->widget_data));
size = maxdim(size, GetStringBoundingBox(this->widget_data, this->text_size));
break;
}
case WWT_CAPTION: {
padding = {WidgetDimensions::scaled.captiontext.Horizontal(), WidgetDimensions::scaled.captiontext.Vertical()};
if (this->index >= 0) w->SetStringParameters(this->index);
Dimension d2 = GetStringBoundingBox(this->widget_data);
Dimension d2 = GetStringBoundingBox(this->widget_data, this->text_size);
d2.width += padding.width;
d2.height += padding.height;
size = maxdim(size, d2);
@ -2824,7 +2832,7 @@ void NWidgetLeaf::SetupSmallestSize(Window *w, bool init_array)
}
padding = {WidgetDimensions::scaled.dropdowntext.Horizontal() + NWidgetLeaf::dropdown_dimension.width + WidgetDimensions::scaled.fullbevel.Horizontal(), WidgetDimensions::scaled.dropdowntext.Vertical()};
if (this->index >= 0) w->SetStringParameters(this->index);
Dimension d2 = GetStringBoundingBox(this->widget_data);
Dimension d2 = GetStringBoundingBox(this->widget_data, this->text_size);
d2.width += padding.width;
d2.height = std::max(d2.height + padding.height, NWidgetLeaf::dropdown_dimension.height);
size = maxdim(size, d2);
@ -2881,7 +2889,7 @@ void NWidgetLeaf::Draw(const Window *w)
case WWT_TEXTBTN_2:
if (this->index >= 0) w->SetStringParameters(this->index);
DrawFrameRect(r.left, r.top, r.right, r.bottom, this->colour, (clicked) ? FR_LOWERED : FR_NONE);
DrawLabel(r, this->type, clicked, this->text_colour, this->widget_data, this->align);
DrawLabel(r, this->type, clicked, this->text_colour, this->widget_data, this->align, this->text_size);
break;
case WWT_ARROWBTN:
@ -2900,12 +2908,12 @@ void NWidgetLeaf::Draw(const Window *w)
case WWT_LABEL:
if (this->index >= 0) w->SetStringParameters(this->index);
DrawLabel(r, this->type, clicked, this->text_colour, this->widget_data, this->align);
DrawLabel(r, this->type, clicked, this->text_colour, this->widget_data, this->align, this->text_size);
break;
case WWT_TEXT:
if (this->index >= 0) w->SetStringParameters(this->index);
DrawText(r, this->text_colour, this->widget_data, this->align);
DrawText(r, this->text_colour, this->widget_data, this->align, this->text_size);
break;
case WWT_MATRIX:
@ -2920,7 +2928,7 @@ void NWidgetLeaf::Draw(const Window *w)
case WWT_CAPTION:
if (this->index >= 0) w->SetStringParameters(this->index);
DrawCaption(r, this->colour, w->owner, this->text_colour, this->widget_data, this->align);
DrawCaption(r, this->colour, w->owner, this->text_colour, this->widget_data, this->align, this->text_size);
break;
case WWT_SHADEBOX:
@ -3096,10 +3104,10 @@ static int MakeNWidget(const NWidgetPart *parts, int count, NWidgetBase **dest,
break;
}
case WPT_TEXTCOLOUR: {
case WPT_TEXTSTYLE: {
NWidgetCore *nwc = dynamic_cast<NWidgetCore *>(*dest);
if (nwc != nullptr) {
nwc->SetTextColour(parts->u.colour.colour);
nwc->SetTextStyle(parts->u.text_style.colour, parts->u.text_style.size);
}
break;
}

View File

@ -89,7 +89,7 @@ enum WidgetType {
WPT_DATATIP, ///< Widget part for specifying data and tooltip.
WPT_PADDING, ///< Widget part for specifying a padding.
WPT_PIPSPACE, ///< Widget part for specifying pre/inter/post space for containers.
WPT_TEXTCOLOUR, ///< Widget part for specifying text colour.
WPT_TEXTSTYLE, ///< Widget part for specifying text colour.
WPT_ALIGNMENT, ///< Widget part for specifying text/image alignment.
WPT_ENDCONTAINER, ///< Widget part to denote end of a container.
WPT_FUNCTION, ///< Widget part for calling a user function.
@ -320,7 +320,7 @@ public:
void SetIndex(int index);
void SetDataTip(uint32 widget_data, StringID tool_tip);
void SetToolTip(StringID tool_tip);
void SetTextColour(TextColour colour);
void SetTextStyle(TextColour colour, FontSize size);
void SetAlignment(StringAlignment align);
inline void SetLowered(bool lowered);
@ -342,6 +342,7 @@ public:
int scrollbar_index; ///< Index of an attached scrollbar.
TextColour highlight_colour; ///< Colour of highlight.
TextColour text_colour; ///< Colour of text within widget.
FontSize text_size; ///< Size of text within widget.
StringAlignment align; ///< Alignment of text/image within widget.
};
@ -948,8 +949,9 @@ struct NWidgetPartTextLines {
* Widget part for storing text colour.
* @ingroup NestedWidgetParts
*/
struct NWidgetPartTextColour {
struct NWidgetPartTextStyle {
TextColour colour; ///< TextColour for DrawString.
FontSize size; ///< Font size of text.
};
/**
@ -981,7 +983,7 @@ struct NWidgetPart {
NWidgetPartPaddings padding; ///< Part with paddings.
NWidgetPartPIP pip; ///< Part with pre/inter/post spaces.
NWidgetPartTextLines text_lines; ///< Part with text line data.
NWidgetPartTextColour colour; ///< Part with text colour data.
NWidgetPartTextStyle text_style; ///< Part with text style data.
NWidgetPartAlignment align; ///< Part with internal alignment.
NWidgetFunctionType *func_ptr; ///< Part with a function call.
NWidContainerFlags cont_flags; ///< Part with container flags.
@ -1042,16 +1044,18 @@ static inline NWidgetPart SetMinimalTextLines(uint8 lines, uint8 spacing, FontSi
}
/**
* Widget part function for setting the text colour.
* Widget part function for setting the text style.
* @param colour Colour to draw string within widget.
* @param size Font size to draw string within widget.
* @ingroup NestedWidgetParts
*/
static inline NWidgetPart SetTextColour(TextColour colour)
static inline NWidgetPart SetTextStyle(TextColour colour, FontSize size = FS_NORMAL)
{
NWidgetPart part;
part.type = WPT_TEXTCOLOUR;
part.u.colour.colour = colour;
part.type = WPT_TEXTSTYLE;
part.u.text_style.colour = colour;
part.u.text_style.size = size;
return part;
}

View File

@ -76,7 +76,7 @@ static inline void DrawFrameRect(const Rect &r, Colours colour, FrameFlags flags
DrawFrameRect(r.left, r.top, r.right, r.bottom, colour, flags);
}
void DrawCaption(const Rect &r, Colours colour, Owner owner, TextColour text_colour, StringID str, StringAlignment align);
void DrawCaption(const Rect &r, Colours colour, Owner owner, TextColour text_colour, StringID str, StringAlignment align, FontSize fs);
/* window.cpp */
using WindowList = std::list<Window *>;