mirror of https://github.com/OpenTTD/OpenTTD
Codechange: split widget_data into its actual components
parent
df6e2d7aa4
commit
99d790c4bb
|
@ -89,17 +89,17 @@ class NWidgetServerListHeader : public NWidgetContainer {
|
|||
public:
|
||||
NWidgetServerListHeader() : NWidgetContainer(NWID_HORIZONTAL)
|
||||
{
|
||||
auto leaf = std::make_unique<NWidgetLeaf>(WWT_PUSHTXTBTN, COLOUR_WHITE, WID_NG_NAME, STR_NETWORK_SERVER_LIST_GAME_NAME, STR_NETWORK_SERVER_LIST_GAME_NAME_TOOLTIP);
|
||||
auto leaf = std::make_unique<NWidgetLeaf>(WWT_PUSHTXTBTN, COLOUR_WHITE, WID_NG_NAME, WidgetData{.string = STR_NETWORK_SERVER_LIST_GAME_NAME}, STR_NETWORK_SERVER_LIST_GAME_NAME_TOOLTIP);
|
||||
leaf->SetResize(1, 0);
|
||||
leaf->SetFill(1, 0);
|
||||
this->Add(std::move(leaf));
|
||||
|
||||
this->Add(std::make_unique<NWidgetLeaf>(WWT_PUSHTXTBTN, COLOUR_WHITE, WID_NG_CLIENTS, STR_NETWORK_SERVER_LIST_CLIENTS_CAPTION, STR_NETWORK_SERVER_LIST_CLIENTS_CAPTION_TOOLTIP));
|
||||
this->Add(std::make_unique<NWidgetLeaf>(WWT_PUSHTXTBTN, COLOUR_WHITE, WID_NG_MAPSIZE, STR_NETWORK_SERVER_LIST_MAP_SIZE_CAPTION, STR_NETWORK_SERVER_LIST_MAP_SIZE_CAPTION_TOOLTIP));
|
||||
this->Add(std::make_unique<NWidgetLeaf>(WWT_PUSHTXTBTN, COLOUR_WHITE, WID_NG_DATE, STR_NETWORK_SERVER_LIST_DATE_CAPTION, STR_NETWORK_SERVER_LIST_DATE_CAPTION_TOOLTIP));
|
||||
this->Add(std::make_unique<NWidgetLeaf>(WWT_PUSHTXTBTN, COLOUR_WHITE, WID_NG_YEARS, STR_NETWORK_SERVER_LIST_PLAY_TIME_CAPTION, STR_NETWORK_SERVER_LIST_PLAY_TIME_CAPTION_TOOLTIP));
|
||||
this->Add(std::make_unique<NWidgetLeaf>(WWT_PUSHTXTBTN, COLOUR_WHITE, WID_NG_CLIENTS, WidgetData{.string = STR_NETWORK_SERVER_LIST_CLIENTS_CAPTION}, STR_NETWORK_SERVER_LIST_CLIENTS_CAPTION_TOOLTIP));
|
||||
this->Add(std::make_unique<NWidgetLeaf>(WWT_PUSHTXTBTN, COLOUR_WHITE, WID_NG_MAPSIZE, WidgetData{.string = STR_NETWORK_SERVER_LIST_MAP_SIZE_CAPTION}, STR_NETWORK_SERVER_LIST_MAP_SIZE_CAPTION_TOOLTIP));
|
||||
this->Add(std::make_unique<NWidgetLeaf>(WWT_PUSHTXTBTN, COLOUR_WHITE, WID_NG_DATE, WidgetData{.string = STR_NETWORK_SERVER_LIST_DATE_CAPTION}, STR_NETWORK_SERVER_LIST_DATE_CAPTION_TOOLTIP));
|
||||
this->Add(std::make_unique<NWidgetLeaf>(WWT_PUSHTXTBTN, COLOUR_WHITE, WID_NG_YEARS, WidgetData{.string = STR_NETWORK_SERVER_LIST_PLAY_TIME_CAPTION}, STR_NETWORK_SERVER_LIST_PLAY_TIME_CAPTION_TOOLTIP));
|
||||
|
||||
leaf = std::make_unique<NWidgetLeaf>(WWT_PUSHTXTBTN, COLOUR_WHITE, WID_NG_INFO, STR_EMPTY, STR_NETWORK_SERVER_LIST_INFO_ICONS_TOOLTIP);
|
||||
leaf = std::make_unique<NWidgetLeaf>(WWT_PUSHTXTBTN, COLOUR_WHITE, WID_NG_INFO, WidgetData{.string = STR_EMPTY}, STR_NETWORK_SERVER_LIST_INFO_ICONS_TOOLTIP);
|
||||
leaf->SetFill(0, 1);
|
||||
this->Add(std::move(leaf));
|
||||
}
|
||||
|
|
|
@ -222,7 +222,7 @@ static const int KEY_PADDING = 6; // Vertical padding for remaining key rows
|
|||
* @param widdata Data value of the key widget.
|
||||
* @note Key width is measured in 1/2 keys to allow for 1/2 key shifting between rows.
|
||||
*/
|
||||
static void AddKey(std::unique_ptr<NWidgetHorizontal> &hor, int pad_y, int num_half, WidgetType widtype, WidgetID widnum, uint16_t widdata)
|
||||
static void AddKey(std::unique_ptr<NWidgetHorizontal> &hor, int pad_y, int num_half, WidgetType widtype, WidgetID widnum, const WidgetData &widdata)
|
||||
{
|
||||
int key_width = HALF_KEY_WIDTH + (INTER_KEY_SPACE + HALF_KEY_WIDTH) * (num_half - 1);
|
||||
|
||||
|
@ -244,9 +244,9 @@ static std::unique_ptr<NWidgetBase> MakeTopKeys()
|
|||
auto hor = std::make_unique<NWidgetHorizontal>();
|
||||
hor->SetPIP(0, INTER_KEY_SPACE, 0);
|
||||
|
||||
AddKey(hor, TOP_KEY_PADDING, 6 * 2, WWT_TEXTBTN, WID_OSK_CANCEL, STR_BUTTON_CANCEL);
|
||||
AddKey(hor, TOP_KEY_PADDING, 6 * 2, WWT_TEXTBTN, WID_OSK_OK, STR_BUTTON_OK );
|
||||
AddKey(hor, TOP_KEY_PADDING, 2 * 2, WWT_PUSHIMGBTN, WID_OSK_BACKSPACE, SPR_OSK_BACKSPACE);
|
||||
AddKey(hor, TOP_KEY_PADDING, 6 * 2, WWT_TEXTBTN, WID_OSK_CANCEL, WidgetData{.string = STR_BUTTON_CANCEL});
|
||||
AddKey(hor, TOP_KEY_PADDING, 6 * 2, WWT_TEXTBTN, WID_OSK_OK, WidgetData{.string = STR_BUTTON_OK});
|
||||
AddKey(hor, TOP_KEY_PADDING, 2 * 2, WWT_PUSHIMGBTN, WID_OSK_BACKSPACE, WidgetData{.sprite = SPR_OSK_BACKSPACE});
|
||||
return hor;
|
||||
}
|
||||
|
||||
|
@ -257,7 +257,7 @@ static std::unique_ptr<NWidgetBase> MakeNumberKeys()
|
|||
hor->SetPIP(0, INTER_KEY_SPACE, 0);
|
||||
|
||||
for (WidgetID widnum = WID_OSK_NUMBERS_FIRST; widnum <= WID_OSK_NUMBERS_LAST; widnum++) {
|
||||
AddKey(hor, KEY_PADDING, 2, WWT_PUSHBTN, widnum, 0x0);
|
||||
AddKey(hor, KEY_PADDING, 2, WWT_PUSHBTN, widnum, {});
|
||||
}
|
||||
return hor;
|
||||
}
|
||||
|
@ -268,11 +268,11 @@ static std::unique_ptr<NWidgetBase> MakeQwertyKeys()
|
|||
std::unique_ptr<NWidgetHorizontal> hor = std::make_unique<NWidgetHorizontalLTR>();
|
||||
hor->SetPIP(0, INTER_KEY_SPACE, 0);
|
||||
|
||||
AddKey(hor, KEY_PADDING, 3, WWT_PUSHIMGBTN, WID_OSK_SPECIAL, SPR_OSK_SPECIAL);
|
||||
AddKey(hor, KEY_PADDING, 3, WWT_PUSHIMGBTN, WID_OSK_SPECIAL, WidgetData{.sprite = SPR_OSK_SPECIAL});
|
||||
for (WidgetID widnum = WID_OSK_QWERTY_FIRST; widnum <= WID_OSK_QWERTY_LAST; widnum++) {
|
||||
AddKey(hor, KEY_PADDING, 2, WWT_PUSHBTN, widnum, 0x0);
|
||||
AddKey(hor, KEY_PADDING, 2, WWT_PUSHBTN, widnum, {});
|
||||
}
|
||||
AddKey(hor, KEY_PADDING, 1, NWID_SPACER, 0, 0);
|
||||
AddKey(hor, KEY_PADDING, 1, NWID_SPACER, 0, {});
|
||||
return hor;
|
||||
}
|
||||
|
||||
|
@ -282,9 +282,9 @@ static std::unique_ptr<NWidgetBase> MakeAsdfgKeys()
|
|||
std::unique_ptr<NWidgetHorizontal> hor = std::make_unique<NWidgetHorizontalLTR>();
|
||||
hor->SetPIP(0, INTER_KEY_SPACE, 0);
|
||||
|
||||
AddKey(hor, KEY_PADDING, 4, WWT_IMGBTN, WID_OSK_CAPS, SPR_OSK_CAPS);
|
||||
AddKey(hor, KEY_PADDING, 4, WWT_IMGBTN, WID_OSK_CAPS, WidgetData{.sprite = SPR_OSK_CAPS});
|
||||
for (WidgetID widnum = WID_OSK_ASDFG_FIRST; widnum <= WID_OSK_ASDFG_LAST; widnum++) {
|
||||
AddKey(hor, KEY_PADDING, 2, WWT_PUSHBTN, widnum, 0x0);
|
||||
AddKey(hor, KEY_PADDING, 2, WWT_PUSHBTN, widnum, {});
|
||||
}
|
||||
return hor;
|
||||
}
|
||||
|
@ -295,11 +295,11 @@ static std::unique_ptr<NWidgetBase> MakeZxcvbKeys()
|
|||
std::unique_ptr<NWidgetHorizontal> hor = std::make_unique<NWidgetHorizontalLTR>();
|
||||
hor->SetPIP(0, INTER_KEY_SPACE, 0);
|
||||
|
||||
AddKey(hor, KEY_PADDING, 3, WWT_IMGBTN, WID_OSK_SHIFT, SPR_OSK_SHIFT);
|
||||
AddKey(hor, KEY_PADDING, 3, WWT_IMGBTN, WID_OSK_SHIFT, WidgetData{.sprite = SPR_OSK_SHIFT});
|
||||
for (WidgetID widnum = WID_OSK_ZXCVB_FIRST; widnum <= WID_OSK_ZXCVB_LAST; widnum++) {
|
||||
AddKey(hor, KEY_PADDING, 2, WWT_PUSHBTN, widnum, 0x0);
|
||||
AddKey(hor, KEY_PADDING, 2, WWT_PUSHBTN, widnum, {});
|
||||
}
|
||||
AddKey(hor, KEY_PADDING, 1, NWID_SPACER, 0, 0);
|
||||
AddKey(hor, KEY_PADDING, 1, NWID_SPACER, 0, {});
|
||||
return hor;
|
||||
}
|
||||
|
||||
|
@ -309,11 +309,11 @@ static std::unique_ptr<NWidgetBase> MakeSpacebarKeys()
|
|||
auto hor = std::make_unique<NWidgetHorizontal>();
|
||||
hor->SetPIP(0, INTER_KEY_SPACE, 0);
|
||||
|
||||
AddKey(hor, KEY_PADDING, 8, NWID_SPACER, 0, 0);
|
||||
AddKey(hor, KEY_PADDING, 13, WWT_PUSHTXTBTN, WID_OSK_SPACE, STR_EMPTY);
|
||||
AddKey(hor, KEY_PADDING, 3, NWID_SPACER, 0, 0);
|
||||
AddKey(hor, KEY_PADDING, 2, WWT_PUSHIMGBTN, WID_OSK_LEFT, SPR_OSK_LEFT);
|
||||
AddKey(hor, KEY_PADDING, 2, WWT_PUSHIMGBTN, WID_OSK_RIGHT, SPR_OSK_RIGHT);
|
||||
AddKey(hor, KEY_PADDING, 8, NWID_SPACER, 0, {});
|
||||
AddKey(hor, KEY_PADDING, 13, WWT_PUSHTXTBTN, WID_OSK_SPACE, WidgetData{.string = STR_EMPTY});
|
||||
AddKey(hor, KEY_PADDING, 3, NWID_SPACER, 0, {});
|
||||
AddKey(hor, KEY_PADDING, 2, WWT_PUSHIMGBTN, WID_OSK_LEFT, WidgetData{.sprite = SPR_OSK_LEFT});
|
||||
AddKey(hor, KEY_PADDING, 2, WWT_PUSHIMGBTN, WID_OSK_RIGHT, WidgetData{.sprite = SPR_OSK_RIGHT});
|
||||
return hor;
|
||||
}
|
||||
|
||||
|
|
|
@ -2194,7 +2194,7 @@ static std::unique_ptr<NWidgetBase> MakeMainToolbar()
|
|||
hor->Add(std::make_unique<NWidgetSpacer>(0, 0));
|
||||
break;
|
||||
}
|
||||
auto leaf = std::make_unique<NWidgetLeaf>(i == WID_TN_SAVE ? WWT_IMGBTN_2 : WWT_IMGBTN, COLOUR_GREY, i, toolbar_button_sprites[i], STR_TOOLBAR_TOOLTIP_PAUSE_GAME + i);
|
||||
auto leaf = std::make_unique<NWidgetLeaf>(i == WID_TN_SAVE ? WWT_IMGBTN_2 : WWT_IMGBTN, COLOUR_GREY, i, WidgetData{.sprite = toolbar_button_sprites[i]}, STR_TOOLBAR_TOOLTIP_PAUSE_GAME + i);
|
||||
leaf->SetMinimalSize(20, 20);
|
||||
hor->Add(std::move(leaf));
|
||||
}
|
||||
|
|
|
@ -1112,7 +1112,7 @@ void NWidgetResizeBase::AssignSizePosition(SizingType sizing, int x, int y, uint
|
|||
* @param widget_data Data component of the widget. @see Widget::data
|
||||
* @param tool_tip Tool tip of the widget. @see Widget::tooltips
|
||||
*/
|
||||
NWidgetCore::NWidgetCore(WidgetType tp, Colours colour, WidgetID index, uint fill_x, uint fill_y, uint32_t widget_data, StringID tool_tip) : NWidgetResizeBase(tp, fill_x, fill_y), index(index)
|
||||
NWidgetCore::NWidgetCore(WidgetType tp, Colours colour, WidgetID index, uint fill_x, uint fill_y, const WidgetData &widget_data, StringID tool_tip) : NWidgetResizeBase(tp, fill_x, fill_y), index(index)
|
||||
{
|
||||
this->colour = colour;
|
||||
this->widget_data = widget_data;
|
||||
|
@ -1129,7 +1129,7 @@ NWidgetCore::NWidgetCore(WidgetType tp, Colours colour, WidgetID index, uint fil
|
|||
*/
|
||||
void NWidgetCore::SetString(StringID string)
|
||||
{
|
||||
this->widget_data = string;
|
||||
this->widget_data.string = string;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1149,7 +1149,7 @@ void NWidgetCore::SetStringTip(StringID string, StringID tool_tip)
|
|||
*/
|
||||
void NWidgetCore::SetSprite(SpriteID sprite)
|
||||
{
|
||||
this->widget_data = sprite;
|
||||
this->widget_data.sprite = sprite;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1170,7 +1170,7 @@ void NWidgetCore::SetSpriteTip(SpriteID sprite, StringID tool_tip)
|
|||
*/
|
||||
void NWidgetCore::SetMatrixDimension(uint8_t columns, uint8_t rows)
|
||||
{
|
||||
this->widget_data = static_cast<uint32_t>((rows << MAT_ROW_START) | (columns << MAT_COL_START));
|
||||
this->widget_data.matrix = static_cast<uint32_t>((rows << MAT_ROW_START) | (columns << MAT_COL_START));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1179,7 +1179,7 @@ void NWidgetCore::SetMatrixDimension(uint8_t columns, uint8_t rows)
|
|||
*/
|
||||
void NWidgetCore::SetResizeWidgetType(ResizeWidgetValues type)
|
||||
{
|
||||
this->widget_data = type;
|
||||
this->widget_data.resize_widget_type = type;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1226,7 +1226,7 @@ void NWidgetCore::SetAlignment(StringAlignment align)
|
|||
*/
|
||||
StringID NWidgetCore::GetString() const
|
||||
{
|
||||
return this->widget_data;
|
||||
return this->widget_data.string;
|
||||
}
|
||||
|
||||
void NWidgetCore::FillWidgetLookup(WidgetLookup &widget_lookup)
|
||||
|
@ -2162,7 +2162,7 @@ void NWidgetMatrix::GetScrollOffsets(int &start_x, int &start_y, int &base_offs_
|
|||
* vertical container will be inserted while adding the first
|
||||
* child widget.
|
||||
*/
|
||||
NWidgetBackground::NWidgetBackground(WidgetType tp, Colours colour, WidgetID index, std::unique_ptr<NWidgetPIPContainer> &&child) : NWidgetCore(tp, colour, index, 1, 1, 0x0, STR_NULL)
|
||||
NWidgetBackground::NWidgetBackground(WidgetType tp, Colours colour, WidgetID index, std::unique_ptr<NWidgetPIPContainer> &&child) : NWidgetCore(tp, colour, index, 1, 1, {}, STR_NULL)
|
||||
{
|
||||
assert(tp == WWT_PANEL || tp == WWT_INSET || tp == WWT_FRAME);
|
||||
this->child = std::move(child);
|
||||
|
@ -2324,7 +2324,6 @@ void NWidgetBackground::Draw(const Window *w)
|
|||
|
||||
switch (this->type) {
|
||||
case WWT_PANEL:
|
||||
assert(this->widget_data == 0);
|
||||
DrawFrameRect(r.left, r.top, r.right, r.bottom, this->colour, this->IsLowered() ? FR_LOWERED : FR_NONE);
|
||||
break;
|
||||
|
||||
|
@ -2370,7 +2369,7 @@ NWidgetBase *NWidgetBackground::GetWidgetOfType(WidgetType tp)
|
|||
return nwid;
|
||||
}
|
||||
|
||||
NWidgetViewport::NWidgetViewport(WidgetID index) : NWidgetCore(NWID_VIEWPORT, INVALID_COLOUR, index, 1, 1, 0x0, STR_NULL)
|
||||
NWidgetViewport::NWidgetViewport(WidgetID index) : NWidgetCore(NWID_VIEWPORT, INVALID_COLOUR, index, 1, 1, {}, STR_NULL)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -2559,7 +2558,7 @@ Rect ScrollRect(Rect r, const Scrollbar &sb, int resize_step)
|
|||
* @param colour Colour of the scrollbar.
|
||||
* @param index Index of the widget.
|
||||
*/
|
||||
NWidgetScrollbar::NWidgetScrollbar(WidgetType tp, Colours colour, WidgetID index) : NWidgetCore(tp, colour, index, 1, 1, 0x0, STR_NULL), Scrollbar(tp != NWID_HSCROLLBAR)
|
||||
NWidgetScrollbar::NWidgetScrollbar(WidgetType tp, Colours colour, WidgetID index) : NWidgetCore(tp, colour, index, 1, 1, {}, STR_NULL), Scrollbar(tp != NWID_HSCROLLBAR)
|
||||
{
|
||||
assert(tp == NWID_HSCROLLBAR || tp == NWID_VSCROLLBAR);
|
||||
|
||||
|
@ -2684,7 +2683,7 @@ Dimension NWidgetLeaf::dropdown_dimension = {0, 0};
|
|||
* @param data Data of the widget.
|
||||
* @param tip Tooltip of the widget.
|
||||
*/
|
||||
NWidgetLeaf::NWidgetLeaf(WidgetType tp, Colours colour, WidgetID index, uint32_t data, StringID tip) : NWidgetCore(tp, colour, index, 1, 1, data, tip)
|
||||
NWidgetLeaf::NWidgetLeaf(WidgetType tp, Colours colour, WidgetID index, const WidgetData &data, StringID tip) : NWidgetCore(tp, colour, index, 1, 1, data, tip)
|
||||
{
|
||||
assert(index >= 0 || tp == WWT_LABEL || tp == WWT_TEXT || tp == WWT_CAPTION || tp == WWT_RESIZEBOX || tp == WWT_SHADEBOX || tp == WWT_DEFSIZEBOX || tp == WWT_DEBUGBOX || tp == WWT_STICKYBOX || tp == WWT_CLOSEBOX);
|
||||
this->min_x = 0;
|
||||
|
@ -2877,8 +2876,8 @@ void NWidgetLeaf::SetupSmallestSize(Window *w)
|
|||
case WWT_IMGBTN_2:
|
||||
case WWT_PUSHIMGBTN: {
|
||||
padding = {WidgetDimensions::scaled.imgbtn.Horizontal(), WidgetDimensions::scaled.imgbtn.Vertical()};
|
||||
Dimension d2 = GetScaledSpriteSize(this->widget_data);
|
||||
if (this->type == WWT_IMGBTN_2) d2 = maxdim(d2, GetScaledSpriteSize(this->widget_data + 1));
|
||||
Dimension d2 = GetScaledSpriteSize(this->widget_data.sprite);
|
||||
if (this->type == WWT_IMGBTN_2) d2 = maxdim(d2, GetScaledSpriteSize(this->widget_data.sprite + 1));
|
||||
d2.width += padding.width;
|
||||
d2.height += padding.height;
|
||||
size = maxdim(size, d2);
|
||||
|
@ -2987,14 +2986,13 @@ void NWidgetLeaf::Draw(const Window *w)
|
|||
break;
|
||||
|
||||
case WWT_PUSHBTN:
|
||||
assert(this->widget_data == 0);
|
||||
DrawFrameRect(r.left, r.top, r.right, r.bottom, this->colour, (clicked) ? FR_LOWERED : FR_NONE);
|
||||
break;
|
||||
|
||||
case WWT_IMGBTN:
|
||||
case WWT_PUSHIMGBTN:
|
||||
case WWT_IMGBTN_2:
|
||||
DrawImageButtons(r, this->type, this->colour, clicked, this->widget_data, this->align);
|
||||
DrawImageButtons(r, this->type, this->colour, clicked, this->widget_data.sprite, this->align);
|
||||
break;
|
||||
|
||||
case WWT_TEXTBTN:
|
||||
|
@ -3008,7 +3006,7 @@ void NWidgetLeaf::Draw(const Window *w)
|
|||
case WWT_ARROWBTN:
|
||||
case WWT_PUSHARROWBTN: {
|
||||
SpriteID sprite;
|
||||
switch (this->widget_data) {
|
||||
switch (this->widget_data.arrow_widget_type) {
|
||||
case AWV_DECREASE: sprite = _current_text_dir != TD_RTL ? SPR_ARROW_LEFT : SPR_ARROW_RIGHT; break;
|
||||
case AWV_INCREASE: sprite = _current_text_dir == TD_RTL ? SPR_ARROW_LEFT : SPR_ARROW_RIGHT; break;
|
||||
case AWV_LEFT: sprite = SPR_ARROW_LEFT; break;
|
||||
|
@ -3030,7 +3028,7 @@ void NWidgetLeaf::Draw(const Window *w)
|
|||
break;
|
||||
|
||||
case WWT_MATRIX:
|
||||
DrawMatrix(r, this->colour, clicked, this->widget_data, this->resize_x, this->resize_y);
|
||||
DrawMatrix(r, this->colour, clicked, this->widget_data.matrix, this->resize_x, this->resize_y);
|
||||
break;
|
||||
|
||||
case WWT_EDITBOX: {
|
||||
|
@ -3045,7 +3043,6 @@ void NWidgetLeaf::Draw(const Window *w)
|
|||
break;
|
||||
|
||||
case WWT_SHADEBOX:
|
||||
assert(this->widget_data == 0);
|
||||
DrawShadeBox(r, this->colour, w->IsShaded());
|
||||
break;
|
||||
|
||||
|
@ -3054,17 +3051,15 @@ void NWidgetLeaf::Draw(const Window *w)
|
|||
break;
|
||||
|
||||
case WWT_STICKYBOX:
|
||||
assert(this->widget_data == 0);
|
||||
DrawStickyBox(r, this->colour, !!(w->flags & WF_STICKY));
|
||||
break;
|
||||
|
||||
case WWT_DEFSIZEBOX:
|
||||
assert(this->widget_data == 0);
|
||||
DrawDefSizeBox(r, this->colour, clicked);
|
||||
break;
|
||||
|
||||
case WWT_RESIZEBOX:
|
||||
DrawResizeBox(r, this->colour, this->pos_x < (w->width / 2), !!(w->flags & WF_SIZING), this->widget_data == 0);
|
||||
DrawResizeBox(r, this->colour, this->pos_x < (w->width / 2), !!(w->flags & WF_SIZING), this->widget_data.resize_widget_type == RWV_SHOW_BEVEL);
|
||||
break;
|
||||
|
||||
case WWT_CLOSEBOX:
|
||||
|
@ -3265,7 +3260,7 @@ static std::unique_ptr<NWidgetBase> MakeNWidget(const NWidgetPart &nwid)
|
|||
|
||||
default:
|
||||
assert((nwid.type & WWT_MASK) < WWT_LAST || (nwid.type & WWT_MASK) == NWID_BUTTON_DROPDOWN);
|
||||
return std::make_unique<NWidgetLeaf>(nwid.type, nwid.u.widget.colour, nwid.u.widget.index, 0x0, STR_NULL);
|
||||
return std::make_unique<NWidgetLeaf>(nwid.type, nwid.u.widget.colour, nwid.u.widget.index, WidgetData{}, STR_NULL);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -364,13 +364,22 @@ enum NWidgetDisplay {
|
|||
};
|
||||
DECLARE_ENUM_AS_BIT_SET(NWidgetDisplay)
|
||||
|
||||
/** Container with the data associated to a single widget. */
|
||||
struct WidgetData {
|
||||
StringID string{};
|
||||
SpriteID sprite{};
|
||||
ArrowWidgetValues arrow_widget_type{};
|
||||
ResizeWidgetValues resize_widget_type{};
|
||||
uint32_t matrix{};
|
||||
};
|
||||
|
||||
/**
|
||||
* Base class for a 'real' widget.
|
||||
* @ingroup NestedWidgets
|
||||
*/
|
||||
class NWidgetCore : public NWidgetResizeBase {
|
||||
public:
|
||||
NWidgetCore(WidgetType tp, Colours colour, WidgetID index, uint fill_x, uint fill_y, uint32_t widget_data, StringID tool_tip);
|
||||
NWidgetCore(WidgetType tp, Colours colour, WidgetID index, uint fill_x, uint fill_y, const WidgetData &widget_data, StringID tool_tip);
|
||||
|
||||
void SetString(StringID string);
|
||||
void SetStringTip(StringID string, StringID tool_tip);
|
||||
|
@ -399,7 +408,7 @@ public:
|
|||
NWidgetDisplay disp_flags; ///< Flags that affect display and interaction with the widget.
|
||||
Colours colour; ///< Colour of this widget.
|
||||
const WidgetID index; ///< Index of the nested widget (\c -1 means 'not used').
|
||||
uint32_t widget_data; ///< Data of the widget. @see Widget::data
|
||||
WidgetData widget_data; ///< Data of the widget. @see Widget::data
|
||||
StringID tool_tip; ///< Tooltip of the widget. @see Widget::tootips
|
||||
WidgetID scrollbar_index; ///< Index of an attached scrollbar.
|
||||
TextColour highlight_colour; ///< Colour of highlight.
|
||||
|
@ -923,7 +932,7 @@ private:
|
|||
*/
|
||||
class NWidgetLeaf : public NWidgetCore {
|
||||
public:
|
||||
NWidgetLeaf(WidgetType tp, Colours colour, WidgetID index, uint32_t data, StringID tip);
|
||||
NWidgetLeaf(WidgetType tp, Colours colour, WidgetID index, const WidgetData &data, StringID tip);
|
||||
|
||||
void SetupSmallestSize(Window *w) override;
|
||||
void Draw(const Window *w) override;
|
||||
|
@ -1010,7 +1019,7 @@ inline uint ComputeMaxSize(uint base, uint max_space, uint step)
|
|||
* @ingroup NestedWidgetParts
|
||||
*/
|
||||
struct NWidgetPartDataTip {
|
||||
uint32_t data; ///< Data value of the widget.
|
||||
WidgetData data; ///< Data value of the widget.
|
||||
StringID tooltip; ///< Tooltip of the widget.
|
||||
};
|
||||
|
||||
|
@ -1209,7 +1218,7 @@ constexpr NWidgetPart EndContainer()
|
|||
*/
|
||||
constexpr NWidgetPart SetStringTip(StringID string, StringID tip = {})
|
||||
{
|
||||
return NWidgetPart{WPT_DATATIP, NWidgetPartDataTip{string, tip}};
|
||||
return NWidgetPart{WPT_DATATIP, NWidgetPartDataTip{{.string = string}, tip}};
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1220,7 +1229,7 @@ constexpr NWidgetPart SetStringTip(StringID string, StringID tip = {})
|
|||
*/
|
||||
constexpr NWidgetPart SetSpriteTip(SpriteID sprite, StringID tip = {})
|
||||
{
|
||||
return NWidgetPart{WPT_DATATIP, NWidgetPartDataTip{sprite, tip}};
|
||||
return NWidgetPart{WPT_DATATIP, NWidgetPartDataTip{{.sprite = sprite}, tip}};
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1231,7 +1240,7 @@ constexpr NWidgetPart SetSpriteTip(SpriteID sprite, StringID tip = {})
|
|||
*/
|
||||
constexpr NWidgetPart SetArrowWidgetTypeTip(ArrowWidgetValues widget_type, StringID tip = {})
|
||||
{
|
||||
return NWidgetPart{WPT_DATATIP, NWidgetPartDataTip{widget_type, tip}};
|
||||
return NWidgetPart{WPT_DATATIP, NWidgetPartDataTip{{.arrow_widget_type = widget_type}, tip}};
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1242,7 +1251,7 @@ constexpr NWidgetPart SetArrowWidgetTypeTip(ArrowWidgetValues widget_type, Strin
|
|||
*/
|
||||
constexpr NWidgetPart SetResizeWidgetTypeTip(ResizeWidgetValues widget_type, StringID tip)
|
||||
{
|
||||
return NWidgetPart{WPT_DATATIP, NWidgetPartDataTip{widget_type, tip}};
|
||||
return NWidgetPart{WPT_DATATIP, NWidgetPartDataTip{{.resize_widget_type = widget_type}, tip}};
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1254,7 +1263,7 @@ constexpr NWidgetPart SetResizeWidgetTypeTip(ResizeWidgetValues widget_type, Str
|
|||
*/
|
||||
constexpr NWidgetPart SetMatrixDataTip(uint8_t cols, uint8_t rows, StringID tip = {})
|
||||
{
|
||||
return NWidgetPart{WPT_DATATIP, NWidgetPartDataTip{static_cast<uint32_t>((rows << MAT_ROW_START) | (cols << MAT_COL_START)), tip}};
|
||||
return NWidgetPart{WPT_DATATIP, NWidgetPartDataTip{{.matrix = static_cast<uint32_t>((rows << MAT_ROW_START) | (cols << MAT_COL_START))}, tip}};
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1264,7 +1273,7 @@ constexpr NWidgetPart SetMatrixDataTip(uint8_t cols, uint8_t rows, StringID tip
|
|||
*/
|
||||
constexpr NWidgetPart SetToolTip(StringID tip)
|
||||
{
|
||||
return NWidgetPart{WPT_DATATIP, NWidgetPartDataTip{0x0, tip}};
|
||||
return NWidgetPart{WPT_DATATIP, NWidgetPartDataTip{{}, tip}};
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue