MCPcopy Create free account
hub / github.com/OpenRCT2/OpenRCT2 / WidgetTextCentred

Function WidgetTextCentred

src/openrct2-ui/interface/Widget.cpp:356–403  ·  view source on GitHub ↗

* * rct2: 0x006EBC41 */

Source from the content-addressed store, hash-verified

354 * rct2: 0x006EBC41
355 */
356 static void WidgetTextCentred(RenderTarget& rt, WindowBase& w, WidgetIndex widgetIndex)
357 {
358 // Get the widget
359 const auto& widget = w.widgets[widgetIndex];
360
361 if (widget.text == kStringIdNone)
362 return;
363
364 auto colour = w.colours[widget.colour];
365 colour.flags.set(ColourFlag::translucent, false);
366 if (widgetIsDisabled(w, widgetIndex))
367 colour.flags.set(ColourFlag::inset, true);
368
369 // Resolve the absolute ltrb
370 auto topLeft = w.windowPos + ScreenCoordsXY{ widget.left, 0 };
371 int32_t r = w.windowPos.x + widget.right;
372
373 if (widget.type == WidgetType::button || widget.type == WidgetType::tableHeader)
374 {
375 // Optical alignment for dropdown glyph
376 if (widget.text == STR_DROPDOWN_GLYPH)
377 topLeft.y += widget.top + (widget.height() / 2) - 5;
378 else
379 topLeft.y += widget.textTop();
380 }
381 else
382 {
383 topLeft.y += widget.top;
384 }
385
386 auto stringId = widget.text;
387 auto ft = Formatter();
388 if (widget.flags.has(WidgetFlag::textIsString))
389 {
390 stringId = STR_STRING;
391 ft.Add<utf8*>(widget.string);
392 }
393
394 ScreenCoordsXY coords = { (topLeft.x + r + 1) / 2 - 1, topLeft.y };
395 if (widget.type == WidgetType::labelCentred)
396 {
397 drawTextWrapped(rt, coords, widget.width() - 3, stringId, ft, { colour, TextAlignment::centre });
398 }
399 else
400 {
401 drawTextEllipsised(rt, coords, widget.width() - 3, stringId, ft, { colour, TextAlignment::centre });
402 }
403 }
404
405 /**
406 *

Callers 2

widgetDrawFunction · 0.85
WidgetTextButtonFunction · 0.85

Calls 9

widgetIsDisabledFunction · 0.85
drawTextWrappedFunction · 0.85
drawTextEllipsisedFunction · 0.85
heightMethod · 0.80
textTopMethod · 0.80
widthMethod · 0.80
FormatterClass · 0.70
setMethod · 0.65
hasMethod · 0.65

Tested by

no test coverage detected