[Add] gl_printHeight.
This commit is contained in:
parent
0890ce4a2e
commit
ccbb8f1c2c
45
src/font.c
45
src/font.c
@ -277,6 +277,51 @@ int gl_printWidth(const glFont* ft_font, const char* fmt, ...) {
|
||||
return n;
|
||||
}
|
||||
|
||||
int gl_printHeight(const glFont* ft_font, const int width,
|
||||
const char* fmt, ...) {
|
||||
|
||||
char txt[1024]; // Holds the string.
|
||||
va_list ap;
|
||||
int p, i, n, len, lastspace;
|
||||
double x, y;
|
||||
|
||||
if(ft_font == NULL) ft_font = &gl_defFont;
|
||||
|
||||
if(fmt == NULL) return -1;
|
||||
else {
|
||||
// Convert the symbols to text.
|
||||
va_start(ap, fmt);
|
||||
vsprintf(txt, fmt, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
x = 0.;
|
||||
y = 0.;
|
||||
|
||||
len = (int) strlen(txt);
|
||||
// Limit the size per line.
|
||||
lastspace = -1; // Last ' ' or '\n' in the text.
|
||||
n = 0; // Current width.
|
||||
i = 0; // Current position.
|
||||
p = -1; // Where we last drew up to.
|
||||
|
||||
while(i < len+1) {
|
||||
n += ft_font->w[(int)txt[i]];
|
||||
|
||||
if((txt[i] == ' ') || (txt[i] == '\n') || (txt[i] == '\0')) lastspace = i;
|
||||
|
||||
if(((n > width) && (p != lastspace)) ||
|
||||
(txt[i] == '\n') || (txt[i] == '\0')) {
|
||||
|
||||
p = lastspace;
|
||||
n = 0;
|
||||
i = lastspace;
|
||||
y += 1.5*(double)ft_font->h; // Move position down.
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return (int)y;
|
||||
}
|
||||
|
||||
// ================
|
||||
// FONT!
|
||||
// ================
|
||||
|
@ -36,3 +36,6 @@ int gl_printText(const glFont* ft_font, const int width, const int height,
|
||||
// Get the width of the text that you wish to print.
|
||||
int gl_printWidth(const glFont* ft_font, const char* fmt, ...);
|
||||
|
||||
int gl_printHeight(const glFont* ft_font, const int width,
|
||||
const char* fmt, ...);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user