[Add] gl_printHeight.

This commit is contained in:
Allanis 2013-03-30 20:58:52 +00:00
parent 0890ce4a2e
commit ccbb8f1c2c
2 changed files with 48 additions and 0 deletions

View File

@ -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!
// ================

View File

@ -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, ...);