From 17e7dafa2a216681a80d3732ac5fe43dc59d421e Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Mon, 21 Apr 2025 17:08:10 +0100 Subject: [PATCH] Change: Add alternate_colour widget data for boolean button. Allows boolean button to have different background and button colours. --- src/widget.cpp | 4 +++- src/widget_type.h | 12 ++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/widget.cpp b/src/widget.cpp index e62d1ba63e..eddbc807b6 100644 --- a/src/widget.cpp +++ b/src/widget.cpp @@ -3002,7 +3002,9 @@ void NWidgetLeaf::Draw(const Window *w) case WWT_BOOLBTN: { Point pt = GetAlignedPosition(r, Dimension(SETTING_BUTTON_WIDTH, SETTING_BUTTON_HEIGHT), this->align); - DrawBoolButton(pt.x, pt.y, this->colour, this->colour, clicked, !this->IsDisabled()); + Colours button_colour = this->widget_data.alternate_colour; + if (button_colour == INVALID_COLOUR) button_colour = this->colour; + DrawBoolButton(pt.x, pt.y, button_colour, this->colour, clicked, !this->IsDisabled()); break; } diff --git a/src/widget_type.h b/src/widget_type.h index cb5c8b8787..4d43c93107 100644 --- a/src/widget_type.h +++ b/src/widget_type.h @@ -353,6 +353,7 @@ struct WidgetData { SpriteID sprite{}; ArrowWidgetValues arrow_widget_type{}; ResizeWidgetValues resize_widget_type{}; + Colours alternate_colour = INVALID_COLOUR; Dimension matrix{}; }; @@ -1242,6 +1243,17 @@ constexpr NWidgetPart SetResizeWidgetTypeTip(ResizeWidgetValues widget_type, Str return NWidgetPart{WPT_DATATIP, NWidgetPartDataTip{{.resize_widget_type = widget_type}, tip}}; } +/** + * Widget part function for setting the alternate colour and tooltip. + * @param colour Alternate colour of the widget. + * @param tip Tooltip of the widget. + * @ingroup NestedWidgetParts + */ +constexpr NWidgetPart SetAlternateColourTip(Colours colour, StringID tip) +{ + return NWidgetPart{WPT_DATATIP, NWidgetPartDataTip{{.alternate_colour = colour}, tip}}; +} + /** * Widget part function for setting the data and tooltip of WWT_MATRIX widgets * @param cols Number of columns. \c 0 means to use draw columns with width according to the resize step size.