|
|
@ -1448,36 +1448,38 @@ Rectangle GetGlyphAtlasRec(Font font, int codepoint) |
|
|
// Text strings management functions |
|
|
// Text strings management functions |
|
|
//---------------------------------------------------------------------------------- |
|
|
//---------------------------------------------------------------------------------- |
|
|
// Load text as separate lines ('\n') |
|
|
// Load text as separate lines ('\n') |
|
|
// WARNING: There is a limit set for number of lines and line-size |
|
|
|
|
|
|
|
|
// NOTE: Returned lines end with null terminator '\0' |
|
|
char **LoadTextLines(const char *text, int *count) |
|
|
char **LoadTextLines(const char *text, int *count) |
|
|
{ |
|
|
{ |
|
|
cp">#define MAX_TEXTLINES_COUNT 512 |
|
|
|
|
|
cp">#define MAX_TEXTLINES_LINE_LEN 512 |
|
|
|
|
|
|
|
|
kt">int lineCount = 1; |
|
|
|
|
|
kt">int textSize = strlen(text); |
|
|
|
|
|
|
|
|
char **lines = (char **)RL_CALLOC(MAX_TEXTLINES_COUNT, sizeof(char *)); |
|
|
|
|
|
for (int i = 0; i < MAX_TEXTLINES_COUNT; i++) lines[i] = (char *)RL_CALLOC(MAX_TEXTLINES_LINE_LEN, 1); |
|
|
|
|
|
int textSize = (int)strlen(text); |
|
|
|
|
|
int k = 0; |
|
|
|
|
|
|
|
|
// Text pass to get required line count |
|
|
|
|
|
for (int i = 0; i < textSize; i++) |
|
|
|
|
|
{ |
|
|
|
|
|
if (text[i] == '\n') lineCount++; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
for (int i = 0, len = 0; (i < textSize) && (k < MAX_TEXTLINES_COUNT); i++) |
|
|
|
|
|
|
|
|
char **lines = (char **)RL_CALLOC(lineCount, sizeof(char *)); |
|
|
|
|
|
for (int i = 0, l = 0, lineLen = 0; i < lineCount; i++, lineLen++) |
|
|
{ |
|
|
{ |
|
|
if (p">(text[i] == '\n') || (len == (MAX_TEXTLINES_LINE_LEN - 1))) |
|
|
|
|
|
|
|
|
if (text[i] == '\n') |
|
|
{ |
|
|
{ |
|
|
strncpy(lines[k], &text[i - len], len); |
|
|
|
|
|
len = 0; |
|
|
|
|
|
k++; |
|
|
|
|
|
|
|
|
lines[l] = (char *)RL_CALLOC(lineLen + 1, 1); |
|
|
|
|
|
strncpy(lines[l], &text[i - lineLen], lineLen); |
|
|
|
|
|
lineLen = 0; |
|
|
|
|
|
l++; |
|
|
} |
|
|
} |
|
|
else len++; |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
*count += k; |
|
|
|
|
|
|
|
|
*count = lineCount; |
|
|
return lines; |
|
|
return lines; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// Unload text lines |
|
|
// Unload text lines |
|
|
void UnloadTextLines(char **lines) |
|
|
|
|
|
|
|
|
void UnloadTextLines(char **lines, int lineCount) |
|
|
{ |
|
|
{ |
|
|
for (int i = 0; i < MAX_TEXTLINES_COUNT; i++) RL_FREE(lines[i]); |
|
|
|
|
|
|
|
|
for (int i = 0; i < lineCount; i++) RL_FREE(lines[i]); |
|
|
RL_FREE(lines); |
|
|
RL_FREE(lines); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|