MCPcopy Create free account
hub / github.com/OpenDUNE/OpenDUNE / GUI_SplitText

Function GUI_SplitText

src/gui/gui.c:873–894  ·  view source on GitHub ↗

* Splits the given text in lines of maxwidth width using the given delimiter. * @param str The text to split. * @param maxwidth The maximum width the text will have. * @param delimiter The char used as delimiter. * @return The number of lines. */

Source from the content-addressed store, hash-verified

871 * @return The number of lines.
872 */
873uint16 GUI_SplitText(char *str, uint16 maxwidth, char delimiter)
874{
875 uint16 lines = 0;
876
877 if (str == NULL) return 0;
878
879 while (*str != '\0') {
880 uint16 width = 0;
881
882 lines++;
883
884 while (width < maxwidth && *str != delimiter && *str != '\r' && *str != '\0') width += Font_GetCharWidth(*str++);
885
886 if (width >= maxwidth) {
887 while (*str != 0x20 && *str != delimiter && *str != '\r' && *str != '\0') width -= Font_GetCharWidth(*str--);
888 }
889
890 if (*str != '\0') *str++ = delimiter;
891 }
892
893 return lines;
894}
895
896/**
897 * Draws a sprite.

Callers 2

GUI_DisplayModalMessageFunction · 0.85
GUI_Mentat_LoopFunction · 0.85

Calls 1

Font_GetCharWidthFunction · 0.85

Tested by

no test coverage detected