MCPcopy Create free account
hub / github.com/OpenLoco/OpenLoco / wrapStringTicker

Function wrapStringTicker

src/OpenLoco/src/Graphics/TextRenderer.cpp:1415–1539  ·  view source on GitHub ↗

0x0049544E Vanilla would also return maxWidth @ (breakCount-1) @ @return numLinesToDisplayAllChars @

Source from the content-addressed store, hash-verified

1413 // Vanilla would also return maxWidth @<cx> (breakCount-1) @<di>
1414 // @return numLinesToDisplayAllChars @<ax>
1415 static uint16_t wrapStringTicker(Font font, char* buffer, uint16_t stringWidth, uint16_t numCharacters)
1416 {
1417 // std::vector<const char*> wrap; TODO: refactor to return pointers to line starts
1418 uint16_t numLinesToDisplayAllChars = 1;
1419
1420 int16_t charNum = numCharacters;
1421 for (auto* ptr = buffer; *ptr != '\0';)
1422 {
1423 auto* startLine = ptr;
1424 uint16_t lineWidth = 0;
1425 auto lastWordCharNum = charNum;
1426 auto* wordStart = ptr;
1427 for (; *ptr != '\0' && lineWidth < stringWidth; ++ptr)
1428 {
1429 const auto chr = static_cast<uint8_t>(*ptr);
1430 if (chr >= ControlCodes::noArgBegin && chr < ControlCodes::noArgEnd)
1431 {
1432 bool forceEndl = false;
1433 switch (chr)
1434 {
1435 case ControlCodes::newline:
1436 {
1437 *ptr = '\0';
1438 forceEndl = true;
1439 ++ptr; // Skip over '\0' when forcing a new line
1440 // wrap.push_back(startLine); TODO: refactor to return pointers to line starts
1441 if (charNum > 0)
1442 {
1443 numLinesToDisplayAllChars++;
1444 }
1445 break;
1446 }
1447 case ControlCodes::Font::small:
1448 font = Font::small;
1449 break;
1450 case ControlCodes::Font::large:
1451 font = Font::large;
1452 break;
1453 case ControlCodes::Font::bold:
1454 font = Font::medium_bold;
1455 break;
1456 case ControlCodes::Font::regular:
1457 font = Font::medium_normal;
1458 break;
1459 }
1460 if (forceEndl)
1461 {
1462 break;
1463 }
1464 }
1465 else if (chr >= ControlCodes::oneArgBegin && chr < ControlCodes::oneArgEnd)
1466 {
1467 switch (*ptr)
1468 {
1469 case ControlCodes::moveX:
1470 lineWidth = static_cast<uint8_t>(ptr[1]);
1471 break;
1472 }

Callers 1

drawStringTickerFunction · 0.85

Calls 4

getG1ElementFunction · 0.85
getCharacterWidthFunction · 0.85
locoStrlenFunction · 0.85
getIndexMethod · 0.45

Tested by

no test coverage detected