mirror of https://github.com/OpenTTD/OpenTTD
Codechange: Add widget text colour override property.
parent
636e37d183
commit
51b4bd6c38
|
@ -422,7 +422,7 @@ struct NewsWindow : Window {
|
||||||
{
|
{
|
||||||
switch (widget) {
|
switch (widget) {
|
||||||
case WID_N_CAPTION:
|
case WID_N_CAPTION:
|
||||||
DrawCaption(r, COLOUR_LIGHT_BLUE, this->owner, STR_NEWS_MESSAGE_CAPTION, SA_HOR_CENTER);
|
DrawCaption(r, COLOUR_LIGHT_BLUE, this->owner, TC_FROMSTRING, STR_NEWS_MESSAGE_CAPTION, SA_HOR_CENTER);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WID_N_PANEL:
|
case WID_N_PANEL:
|
||||||
|
|
|
@ -257,16 +257,17 @@ static inline void DrawImageButtons(const Rect &r, WidgetType type, Colours colo
|
||||||
* @param r Rectangle of the label background.
|
* @param r Rectangle of the label background.
|
||||||
* @param type Widget type (#WWT_TEXTBTN, #WWT_TEXTBTN_2, or #WWT_LABEL).
|
* @param type Widget type (#WWT_TEXTBTN, #WWT_TEXTBTN_2, or #WWT_LABEL).
|
||||||
* @param clicked Label is rendered lowered.
|
* @param clicked Label is rendered lowered.
|
||||||
|
* @param colour Colour of the text.
|
||||||
* @param str Text to draw.
|
* @param str Text to draw.
|
||||||
* @param align Alignment of the text.
|
* @param align Alignment of the text.
|
||||||
*/
|
*/
|
||||||
static inline void DrawLabel(const Rect &r, WidgetType type, bool clicked, StringID str, StringAlignment align)
|
static inline void DrawLabel(const Rect &r, WidgetType type, bool clicked, TextColour colour, StringID str, StringAlignment align)
|
||||||
{
|
{
|
||||||
if (str == STR_NULL) return;
|
if (str == STR_NULL) return;
|
||||||
if ((type & WWT_MASK) == WWT_TEXTBTN_2 && clicked) str++;
|
if ((type & WWT_MASK) == WWT_TEXTBTN_2 && clicked) str++;
|
||||||
Dimension d = GetStringBoundingBox(str);
|
Dimension d = GetStringBoundingBox(str);
|
||||||
Point p = GetAlignedPosition(r, d, align);
|
Point p = GetAlignedPosition(r, d, align);
|
||||||
DrawString(r.left + clicked, r.right + clicked, p.y + clicked, str, TC_FROMSTRING, align);
|
DrawString(r.left + clicked, r.right + clicked, p.y + clicked, str, colour, align);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -287,13 +288,14 @@ static inline void DrawText(const Rect &r, TextColour colour, StringID str, Stri
|
||||||
* Draw an inset widget.
|
* Draw an inset widget.
|
||||||
* @param r Rectangle of the background.
|
* @param r Rectangle of the background.
|
||||||
* @param colour Colour of the inset.
|
* @param colour Colour of the inset.
|
||||||
|
* @param text_colour Colour of the text.
|
||||||
* @param str Text to draw.
|
* @param str Text to draw.
|
||||||
* @param align Alignment of the text.
|
* @param align Alignment of the text.
|
||||||
*/
|
*/
|
||||||
static inline void DrawInset(const Rect &r, Colours colour, StringID str, StringAlignment align)
|
static inline void DrawInset(const Rect &r, Colours colour, TextColour text_colour, StringID str, StringAlignment align)
|
||||||
{
|
{
|
||||||
DrawFrameRect(r.left, r.top, r.right, r.bottom, colour, FR_LOWERED | FR_DARKENED);
|
DrawFrameRect(r.left, r.top, r.right, r.bottom, colour, FR_LOWERED | FR_DARKENED);
|
||||||
if (str != STR_NULL) DrawString(r.left + WD_INSET_LEFT, r.right - WD_INSET_RIGHT, r.top + WD_INSET_TOP, str, TC_FROMSTRING, align);
|
if (str != STR_NULL) DrawString(r.left + WD_INSET_LEFT, r.right - WD_INSET_RIGHT, r.top + WD_INSET_TOP, str, text_colour, align);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -436,14 +438,15 @@ static inline void DrawHorizontalScrollbar(const Rect &r, Colours colour, bool l
|
||||||
* Draw a frame widget.
|
* Draw a frame widget.
|
||||||
* @param r Rectangle of the frame.
|
* @param r Rectangle of the frame.
|
||||||
* @param colour Colour of the frame.
|
* @param colour Colour of the frame.
|
||||||
|
* @param text_colour Colour of the text.
|
||||||
* @param str Text of the frame.
|
* @param str Text of the frame.
|
||||||
* @param align Alignment of the text in the frame.
|
* @param align Alignment of the text in the frame.
|
||||||
*/
|
*/
|
||||||
static inline void DrawFrame(const Rect &r, Colours colour, StringID str, StringAlignment align)
|
static inline void DrawFrame(const Rect &r, Colours colour, TextColour text_colour, StringID str, StringAlignment align)
|
||||||
{
|
{
|
||||||
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 (str != STR_NULL) x2 = DrawString(r.left + WD_FRAMETEXT_LEFT, r.right - WD_FRAMETEXT_RIGHT, r.top, str, TC_FROMSTRING, align);
|
if (str != STR_NULL) x2 = DrawString(r.left + WD_FRAMETEXT_LEFT, r.right - WD_FRAMETEXT_RIGHT, r.top, str, text_colour, align);
|
||||||
|
|
||||||
int c1 = _colour_gradient[colour][3];
|
int c1 = _colour_gradient[colour][3];
|
||||||
int c2 = _colour_gradient[colour][7];
|
int c2 = _colour_gradient[colour][7];
|
||||||
|
@ -566,10 +569,11 @@ static inline void DrawCloseBox(const Rect &r, Colours colour)
|
||||||
* @param r Rectangle of the bar.
|
* @param r Rectangle of the bar.
|
||||||
* @param colour Colour of the window.
|
* @param colour Colour of the window.
|
||||||
* @param owner 'Owner' of the window.
|
* @param owner 'Owner' of the window.
|
||||||
|
* @param text_colour Colour of the text.
|
||||||
* @param str Text to draw in the bar.
|
* @param str Text to draw in the bar.
|
||||||
* @param align Alignment of the text.
|
* @param align Alignment of the text.
|
||||||
*/
|
*/
|
||||||
void DrawCaption(const Rect &r, Colours colour, Owner owner, StringID str, StringAlignment align)
|
void DrawCaption(const Rect &r, Colours colour, Owner owner, TextColour text_colour, StringID str, StringAlignment align)
|
||||||
{
|
{
|
||||||
bool company_owned = owner < MAX_COMPANIES;
|
bool company_owned = owner < MAX_COMPANIES;
|
||||||
|
|
||||||
|
@ -583,7 +587,7 @@ void DrawCaption(const Rect &r, Colours colour, Owner owner, StringID str, Strin
|
||||||
if (str != STR_NULL) {
|
if (str != STR_NULL) {
|
||||||
Dimension d = GetStringBoundingBox(str);
|
Dimension d = GetStringBoundingBox(str);
|
||||||
Point p = GetAlignedPosition(r, d, align);
|
Point p = GetAlignedPosition(r, d, align);
|
||||||
DrawString(r.left + WD_CAPTIONTEXT_LEFT, r.right - WD_CAPTIONTEXT_RIGHT, p.y, str, TC_FROMSTRING, align);
|
DrawString(r.left + WD_CAPTIONTEXT_LEFT, r.right - WD_CAPTIONTEXT_RIGHT, p.y, str, text_colour, align);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -908,6 +912,7 @@ NWidgetCore::NWidgetCore(WidgetType tp, Colours colour, uint fill_x, uint fill_y
|
||||||
this->widget_data = widget_data;
|
this->widget_data = widget_data;
|
||||||
this->tool_tip = tool_tip;
|
this->tool_tip = tool_tip;
|
||||||
this->scrollbar_index = -1;
|
this->scrollbar_index = -1;
|
||||||
|
this->text_colour = TC_FROMSTRING;
|
||||||
this->align = SA_CENTER;
|
this->align = SA_CENTER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -932,6 +937,15 @@ void NWidgetCore::SetDataTip(uint32 widget_data, StringID tool_tip)
|
||||||
this->tool_tip = tool_tip;
|
this->tool_tip = tool_tip;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the text colour of the nested widget.
|
||||||
|
* @param colour TextColour to use.
|
||||||
|
*/
|
||||||
|
void NWidgetCore::SetTextColour(TextColour colour)
|
||||||
|
{
|
||||||
|
this->text_colour = colour;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the tool tip of the nested widget.
|
* Set the tool tip of the nested widget.
|
||||||
* @param tool_tip Tool tip string to use.
|
* @param tool_tip Tool tip string to use.
|
||||||
|
@ -1905,12 +1919,12 @@ void NWidgetBackground::Draw(const Window *w)
|
||||||
|
|
||||||
case WWT_FRAME:
|
case WWT_FRAME:
|
||||||
if (this->index >= 0) w->SetStringParameters(this->index);
|
if (this->index >= 0) w->SetStringParameters(this->index);
|
||||||
DrawFrame(r, this->colour, this->widget_data, this->align);
|
DrawFrame(r, this->colour, this->text_colour, this->widget_data, this->align);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WWT_INSET:
|
case WWT_INSET:
|
||||||
if (this->index >= 0) w->SetStringParameters(this->index);
|
if (this->index >= 0) w->SetStringParameters(this->index);
|
||||||
DrawInset(r, this->colour, this->widget_data, this->align);
|
DrawInset(r, this->colour, this->text_colour, this->widget_data, this->align);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -2553,7 +2567,7 @@ void NWidgetLeaf::Draw(const Window *w)
|
||||||
case WWT_TEXTBTN_2:
|
case WWT_TEXTBTN_2:
|
||||||
if (this->index >= 0) w->SetStringParameters(this->index);
|
if (this->index >= 0) w->SetStringParameters(this->index);
|
||||||
DrawFrameRect(r.left, r.top, r.right, r.bottom, this->colour, (clicked) ? FR_LOWERED : FR_NONE);
|
DrawFrameRect(r.left, r.top, r.right, r.bottom, this->colour, (clicked) ? FR_LOWERED : FR_NONE);
|
||||||
DrawLabel(r, this->type, clicked, this->widget_data, this->align);
|
DrawLabel(r, this->type, clicked, this->text_colour, this->widget_data, this->align);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WWT_ARROWBTN:
|
case WWT_ARROWBTN:
|
||||||
|
@ -2572,12 +2586,12 @@ void NWidgetLeaf::Draw(const Window *w)
|
||||||
|
|
||||||
case WWT_LABEL:
|
case WWT_LABEL:
|
||||||
if (this->index >= 0) w->SetStringParameters(this->index);
|
if (this->index >= 0) w->SetStringParameters(this->index);
|
||||||
DrawLabel(r, this->type, clicked, this->widget_data, this->align);
|
DrawLabel(r, this->type, clicked, this->text_colour, this->widget_data, this->align);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WWT_TEXT:
|
case WWT_TEXT:
|
||||||
if (this->index >= 0) w->SetStringParameters(this->index);
|
if (this->index >= 0) w->SetStringParameters(this->index);
|
||||||
DrawText(r, (TextColour)this->colour, this->widget_data, this->align);
|
DrawText(r, this->text_colour, this->widget_data, this->align);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WWT_MATRIX:
|
case WWT_MATRIX:
|
||||||
|
@ -2592,7 +2606,7 @@ void NWidgetLeaf::Draw(const Window *w)
|
||||||
|
|
||||||
case WWT_CAPTION:
|
case WWT_CAPTION:
|
||||||
if (this->index >= 0) w->SetStringParameters(this->index);
|
if (this->index >= 0) w->SetStringParameters(this->index);
|
||||||
DrawCaption(r, this->colour, w->owner, this->widget_data, this->align);
|
DrawCaption(r, this->colour, w->owner, this->text_colour, this->widget_data, this->align);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WWT_SHADEBOX:
|
case WWT_SHADEBOX:
|
||||||
|
@ -2770,6 +2784,14 @@ static int MakeNWidget(const NWidgetPart *parts, int count, NWidgetBase **dest,
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case WPT_TEXTCOLOUR: {
|
||||||
|
NWidgetCore *nwc = dynamic_cast<NWidgetCore *>(*dest);
|
||||||
|
if (nwc != nullptr) {
|
||||||
|
nwc->SetTextColour(parts->u.colour.colour);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case WPT_ALIGNMENT: {
|
case WPT_ALIGNMENT: {
|
||||||
NWidgetCore *nwc = dynamic_cast<NWidgetCore *>(*dest);
|
NWidgetCore *nwc = dynamic_cast<NWidgetCore *>(*dest);
|
||||||
if (nwc != nullptr) {
|
if (nwc != nullptr) {
|
||||||
|
|
|
@ -89,6 +89,7 @@ enum WidgetType {
|
||||||
WPT_DATATIP, ///< Widget part for specifying data and tooltip.
|
WPT_DATATIP, ///< Widget part for specifying data and tooltip.
|
||||||
WPT_PADDING, ///< Widget part for specifying a padding.
|
WPT_PADDING, ///< Widget part for specifying a padding.
|
||||||
WPT_PIPSPACE, ///< Widget part for specifying pre/inter/post space for containers.
|
WPT_PIPSPACE, ///< Widget part for specifying pre/inter/post space for containers.
|
||||||
|
WPT_TEXTCOLOUR, ///< Widget part for specifying text colour.
|
||||||
WPT_ALIGNMENT, ///< Widget part for specifying text/image alignment.
|
WPT_ALIGNMENT, ///< Widget part for specifying text/image alignment.
|
||||||
WPT_ENDCONTAINER, ///< Widget part to denote end of a container.
|
WPT_ENDCONTAINER, ///< Widget part to denote end of a container.
|
||||||
WPT_FUNCTION, ///< Widget part for calling a user function.
|
WPT_FUNCTION, ///< Widget part for calling a user function.
|
||||||
|
@ -297,6 +298,7 @@ public:
|
||||||
void SetIndex(int index);
|
void SetIndex(int index);
|
||||||
void SetDataTip(uint32 widget_data, StringID tool_tip);
|
void SetDataTip(uint32 widget_data, StringID tool_tip);
|
||||||
void SetToolTip(StringID tool_tip);
|
void SetToolTip(StringID tool_tip);
|
||||||
|
void SetTextColour(TextColour colour);
|
||||||
void SetAlignment(StringAlignment align);
|
void SetAlignment(StringAlignment align);
|
||||||
|
|
||||||
inline void SetLowered(bool lowered);
|
inline void SetLowered(bool lowered);
|
||||||
|
@ -317,6 +319,7 @@ public:
|
||||||
StringID tool_tip; ///< Tooltip of the widget. @see Widget::tootips
|
StringID tool_tip; ///< Tooltip of the widget. @see Widget::tootips
|
||||||
int scrollbar_index; ///< Index of an attached scrollbar.
|
int scrollbar_index; ///< Index of an attached scrollbar.
|
||||||
TextColour highlight_colour; ///< Colour of highlight.
|
TextColour highlight_colour; ///< Colour of highlight.
|
||||||
|
TextColour text_colour; ///< Colour of text within widget.
|
||||||
StringAlignment align; ///< Alignment of text/image within widget.
|
StringAlignment align; ///< Alignment of text/image within widget.
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -908,6 +911,14 @@ struct NWidgetPartTextLines {
|
||||||
FontSize size; ///< Font size of text lines.
|
FontSize size; ///< Font size of text lines.
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Widget part for storing text colour.
|
||||||
|
* @ingroup NestedWidgetParts
|
||||||
|
*/
|
||||||
|
struct NWidgetPartTextColour {
|
||||||
|
TextColour colour; ///< TextColour for DrawString.
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Widget part for setting text/image alignment within a widget.
|
* Widget part for setting text/image alignment within a widget.
|
||||||
* @ingroup NestedWidgetParts
|
* @ingroup NestedWidgetParts
|
||||||
|
@ -937,6 +948,7 @@ struct NWidgetPart {
|
||||||
NWidgetPartPaddings padding; ///< Part with paddings.
|
NWidgetPartPaddings padding; ///< Part with paddings.
|
||||||
NWidgetPartPIP pip; ///< Part with pre/inter/post spaces.
|
NWidgetPartPIP pip; ///< Part with pre/inter/post spaces.
|
||||||
NWidgetPartTextLines text_lines; ///< Part with text line data.
|
NWidgetPartTextLines text_lines; ///< Part with text line data.
|
||||||
|
NWidgetPartTextColour colour; ///< Part with text colour data.
|
||||||
NWidgetPartAlignment align; ///< Part with internal alignment.
|
NWidgetPartAlignment align; ///< Part with internal alignment.
|
||||||
NWidgetFunctionType *func_ptr; ///< Part with a function call.
|
NWidgetFunctionType *func_ptr; ///< Part with a function call.
|
||||||
NWidContainerFlags cont_flags; ///< Part with container flags.
|
NWidContainerFlags cont_flags; ///< Part with container flags.
|
||||||
|
@ -996,6 +1008,21 @@ static inline NWidgetPart SetMinimalTextLines(uint8 lines, uint8 spacing, FontSi
|
||||||
return part;
|
return part;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Widget part function for setting the text colour.
|
||||||
|
* @param colour Colour to draw string within widget.
|
||||||
|
* @ingroup NestedWidgetParts
|
||||||
|
*/
|
||||||
|
static inline NWidgetPart SetTextColour(TextColour colour)
|
||||||
|
{
|
||||||
|
NWidgetPart part;
|
||||||
|
|
||||||
|
part.type = WPT_TEXTCOLOUR;
|
||||||
|
part.u.colour.colour = colour;
|
||||||
|
|
||||||
|
return part;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Widget part function for setting the alignment of text/images.
|
* Widget part function for setting the alignment of text/images.
|
||||||
* @param align Alignment of text/image within widget.
|
* @param align Alignment of text/image within widget.
|
||||||
|
|
|
@ -140,7 +140,7 @@ enum WidgetDrawDistances {
|
||||||
|
|
||||||
/* widget.cpp */
|
/* widget.cpp */
|
||||||
void DrawFrameRect(int left, int top, int right, int bottom, Colours colour, FrameFlags flags);
|
void DrawFrameRect(int left, int top, int right, int bottom, Colours colour, FrameFlags flags);
|
||||||
void DrawCaption(const Rect &r, Colours colour, Owner owner, StringID str, StringAlignment align);
|
void DrawCaption(const Rect &r, Colours colour, Owner owner, TextColour text_colour, StringID str, StringAlignment align);
|
||||||
|
|
||||||
/* window.cpp */
|
/* window.cpp */
|
||||||
extern Window *_z_front_window;
|
extern Window *_z_front_window;
|
||||||
|
|
Loading…
Reference in New Issue