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

Function ChatHistoryDrawString

src/openrct2/interface/Chat.cpp:290–312  ·  view source on GitHub ↗

This method is the same as gfx_draw_string_left_wrapped. But this adjusts the initial Y coordinate depending of the number of lines.

Source from the content-addressed store, hash-verified

288// This method is the same as gfx_draw_string_left_wrapped.
289// But this adjusts the initial Y coordinate depending of the number of lines.
290static int32_t ChatHistoryDrawString(RenderTarget& rt, const char* text, const ScreenCoordsXY& screenCoords, int32_t width)
291{
292 int32_t numLines;
293 u8string wrappedString;
294 wrapString(FormatString("{OUTLINE}{WHITE}{STRING}", text), width, FontStyle::medium, &wrappedString, &numLines);
295 auto lineHeight = FontGetLineHeight(FontStyle::medium);
296
297 int32_t expectedY = screenCoords.y - (numLines * lineHeight);
298 if (expectedY < 50)
299 {
300 return (numLines * lineHeight); // Skip drawing, return total height.
301 }
302
303 const utf8* bufferPtr = wrappedString.data();
304 int32_t lineY = screenCoords.y;
305 for (int32_t line = 0; line <= numLines; ++line)
306 {
307 drawText(rt, { screenCoords.x, lineY - (numLines * lineHeight) }, bufferPtr, { OpenRCT2::Drawing::kColourNull });
308 bufferPtr = GetStringEnd(bufferPtr) + 1;
309 lineY += lineHeight;
310 }
311 return lineY - screenCoords.y;
312}
313
314// Wrap string without drawing, useful to get the height of a wrapped string.
315// Almost the same as gfx_draw_string_left_wrapped

Callers 1

ChatDrawFunction · 0.85

Calls 6

wrapStringFunction · 0.85
FormatStringFunction · 0.85
FontGetLineHeightFunction · 0.85
drawTextFunction · 0.85
GetStringEndFunction · 0.85
dataMethod · 0.45

Tested by

no test coverage detected