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

Function getMaxStringWidth

src/OpenLoco/src/Graphics/TextRenderer.cpp:1818–1905  ·  view source on GitHub ↗

* 0x004955BC * * @param buffer @ * @return width @ */

Source from the content-addressed store, hash-verified

1816 * @return width @<cx>
1817 */
1818 static uint16_t getMaxStringWidth(Font font, const char* str)
1819 {
1820 uint16_t width = 0;
1821 uint16_t maxWidth = 0;
1822
1823 while (*str != '\0')
1824 {
1825 const auto chr = static_cast<uint8_t>(*str);
1826 str++;
1827
1828 if (chr >= 32)
1829 {
1830 width += Gfx::getCharacterWidth(font, chr);
1831 continue;
1832 }
1833
1834 switch (chr)
1835 {
1836 case ControlCodes::moveX:
1837 maxWidth = std::max(width, maxWidth);
1838 width = *str;
1839 str++;
1840 break;
1841
1842 case ControlCodes::adjustPalette:
1843 case 3:
1844 case 4:
1845 str++;
1846 break;
1847
1848 case ControlCodes::newline:
1849 case ControlCodes::newlineSmaller:
1850 continue;
1851
1852 case ControlCodes::Font::small:
1853 font = Font::small;
1854 break;
1855
1856 case ControlCodes::Font::large:
1857 font = Font::large;
1858 break;
1859
1860 case ControlCodes::Font::bold:
1861 font = Font::medium_bold;
1862 break;
1863
1864 case ControlCodes::Font::regular:
1865 font = Font::medium_normal;
1866 break;
1867
1868 case ControlCodes::Font::outline:
1869 case ControlCodes::Font::outlineOff:
1870 case ControlCodes::windowColour1:
1871 case ControlCodes::windowColour2:
1872 case ControlCodes::windowColour3:
1873 case ControlCodes::windowColour4:
1874 break;
1875

Callers 2

showTextFunction · 0.85
getMaxStringWidthMethod · 0.85

Calls 2

getCharacterWidthFunction · 0.85
getG1ElementFunction · 0.85

Tested by

no test coverage detected