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

Function ViewportAddString

src/viewport.cpp:1330–1349  ·  view source on GitHub ↗

* Add a string to draw in the current viewport. * @param dpi current viewport area * @param sign sign position and dimension * @param flags ViewportStringFlags to control the string's appearance. * @param colour colour of the sign background; or INVALID_COLOUR if transparent * @returns Pointer to std::string to filled with sign, or nullptr if string would be outside the viewport bounds. */

Source from the content-addressed store, hash-verified

1328 * @returns Pointer to std::string to filled with sign, or nullptr if string would be outside the viewport bounds.
1329 */
1330std::string *ViewportAddString(const DrawPixelInfo *dpi, const ViewportSign *sign, ViewportStringFlags flags, Colours colour)
1331{
1332 int left = dpi->left;
1333 int top = dpi->top;
1334 int right = left + dpi->width;
1335 int bottom = top + dpi->height;
1336
1337 bool small = flags.Test(ViewportStringFlag::Small);
1338 int sign_height = ScaleByZoom(WidgetDimensions::scaled.fullbevel.top + GetCharacterHeight(small ? FS_SMALL : FS_NORMAL) + WidgetDimensions::scaled.fullbevel.bottom, dpi->zoom);
1339 int sign_half_width = ScaleByZoom((small ? sign->width_small : sign->width_normal) / 2, dpi->zoom);
1340
1341 if (bottom < sign->top ||
1342 top > sign->top + sign_height ||
1343 right < sign->center - sign_half_width ||
1344 left > sign->center + sign_half_width) {
1345 return nullptr;
1346 }
1347
1348 return &AddStringToDraw(sign->center - sign_half_width, sign->top, colour, flags, small ? sign->width_small : sign->width_normal);
1349}
1350
1351static Rect ExpandRectWithViewportSignMargins(Rect r, ZoomLevel zoom)
1352{

Callers 4

DrawTextEffectsFunction · 0.85
ViewportAddTownStringsFunction · 0.85
ViewportAddSignStringsFunction · 0.85

Calls 3

ScaleByZoomFunction · 0.85
GetCharacterHeightFunction · 0.85
TestMethod · 0.80

Tested by

no test coverage detected