MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / MakeNWidget

Function MakeNWidget

src/widget.cpp:3282–3311  ·  view source on GitHub ↗

* Make NWidget from an NWidgetPart. * @param nwid NWidgetPart. * @pre NWidgetPart must not be an attribute NWidgetPart nor WPT_ENDCONTAINER. * @return Pointer to created NWidget. */

Source from the content-addressed store, hash-verified

3280 * @return Pointer to created NWidget.
3281 */
3282static std::unique_ptr<NWidgetBase> MakeNWidget(const NWidgetPart &nwid)
3283{
3284 assert(!IsAttributeWidgetPartType(nwid.type));
3285 assert(nwid.type != WPT_ENDCONTAINER);
3286
3287 switch (nwid.type) {
3288 case NWID_SPACER: return std::make_unique<NWidgetSpacer>(0, 0);
3289
3290 case WWT_PANEL: [[fallthrough]];
3291 case WWT_INSET: [[fallthrough]];
3292 case WWT_FRAME: return std::make_unique<NWidgetBackground>(nwid.type, nwid.u.widget.colour, nwid.u.widget.index);
3293
3294 case NWID_HORIZONTAL: return std::make_unique<NWidgetHorizontal>(nwid.u.container.flags, nwid.u.container.index);
3295 case NWID_HORIZONTAL_LTR: return std::make_unique<NWidgetHorizontalLTR>(nwid.u.container.flags, nwid.u.container.index);
3296 case NWID_VERTICAL: return std::make_unique<NWidgetVertical>(nwid.u.container.flags, nwid.u.container.index);
3297 case NWID_SELECTION: return std::make_unique<NWidgetStacked>(nwid.u.widget.index);
3298 case NWID_MATRIX: return std::make_unique<NWidgetMatrix>(nwid.u.widget.colour, nwid.u.widget.index);
3299 case NWID_VIEWPORT: return std::make_unique<NWidgetViewport>(nwid.u.widget.index);
3300 case NWID_LAYER: return std::make_unique<NWidgetLayer>(nwid.u.widget.index);
3301
3302 case NWID_HSCROLLBAR: [[fallthrough]];
3303 case NWID_VSCROLLBAR: return std::make_unique<NWidgetScrollbar>(nwid.type, nwid.u.widget.colour, nwid.u.widget.index);
3304
3305 case WPT_FUNCTION: return nwid.u.func_ptr();
3306
3307 default:
3308 assert((nwid.type & WWT_MASK) < WWT_LAST || (nwid.type & WWT_MASK) == NWID_BUTTON_DROPDOWN);
3309 return std::make_unique<NWidgetLeaf>(nwid.type, nwid.u.widget.colour, nwid.u.widget.index, WidgetData{}, STR_NULL);
3310 }
3311}
3312
3313/**
3314 * Construct a single nested widget in \a *dest from its parts.

Callers 1

MakeWidgetTreeFunction · 0.85

Calls 4

IsContainerWidgetTypeFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected