[Change] No idea why I even made them while(1) in the first place..

This commit is contained in:
Allanis 2014-02-11 05:02:57 +00:00
parent 5fcf3bbc92
commit 3b3450213a

View File

@ -34,7 +34,7 @@ static void glFontMakeDList(FT_Face face, char ch,
GLuint list_base, GLuint* tex_base, GLuint list_base, GLuint* tex_base,
int* width_base); int* width_base);
static int font_limitSize(const glFont* ft_font, int* width, static int font_limitSize(const glFont* ft_font, int* width,
char* text, const int max); char* txt, const int max);
/** /**
* @brief Limits the text to max. * @brief Limits the text to max.
@ -70,7 +70,7 @@ static int font_limitSize(const glFont* ft_font, int* width,
* @param width Width to match. * @param width Width to match.
* @return Number of characters that fit. * @return Number of characters that fit.
*/ */
int gl_printWidthForText(const glFont* ft_font, char* text, int gl_printWidthForText(const glFont* ft_font, char* txt,
const int width) { const int width) {
int i, n, lastspace; int i, n, lastspace;
@ -81,30 +81,28 @@ int gl_printWidthForText(const glFont* ft_font, char* text,
lastspace = 0; /* last ' ' or '\n' in the text. */ lastspace = 0; /* last ' ' or '\n' in the text. */
n = 0; /* Current width. */ n = 0; /* Current width. */
i = 0; /* Current position. */ i = 0; /* Current position. */
while(1) { while((txt[i] != '\n') && (txt[i] != '\0')) {
/* Check if we found an EOL character. */
if((text[i] == '\n') || (text[i] == '\0'))
return i;
/* Characters we should ignore. */ /* Characters we should ignore. */
if(text[i] == '\t') if(txt[i] == '\t') {
i++;
continue; continue;
}
/* Increase size. */ /* Increase size. */
n += ft_font->w[(int)text[i]]; n += ft_font->w[(int)txt[i]];
/* Save last space. */ /* Save last space. */
if(text[i] == ' ') if(txt[i] == ' ')
lastspace = i; lastspace = i;
/* Check if out of bounds. */ /* Check if out of bounds. */
if(n > width) if(n > width)
break; return lastspace;
/* Check next character. */ /* Check next character. */
i++; i++;
} }
return lastspace; return i;
} }
/** /**
@ -314,7 +312,7 @@ int gl_printText(const glFont* ft_font, const int width, const int height,
else COLOUR(*c); else COLOUR(*c);
p = 0; /* Where we last drew up to. */ p = 0; /* Where we last drew up to. */
while(1) { while(by - y < 0) {
i = gl_printWidthForText(ft_font, &txt[p], width); i = gl_printWidthForText(ft_font, &txt[p], width);
glMatrixMode(GL_MODELVIEW); /* Using MODELVIEW, PROJECTION gets full fast. */ glMatrixMode(GL_MODELVIEW); /* Using MODELVIEW, PROJECTION gets full fast. */
@ -329,8 +327,6 @@ int gl_printText(const glFont* ft_font, const int width, const int height,
break; break;
p += i + 1; p += i + 1;
y -= 1.5*(double)ft_font->h; /* Move position down. */ y -= 1.5*(double)ft_font->h; /* Move position down. */
if(by - y > (double)height)
break;
} }
glDisable(GL_TEXTURE_2D); glDisable(GL_TEXTURE_2D);