diff --git a/src/dialogue.c b/src/dialogue.c index 8661ee2..98475af 100644 --- a/src/dialogue.c +++ b/src/dialogue.c @@ -82,18 +82,35 @@ static void dialogue_alertClose(unsigned int wid, char* str) { * @param[out] w Get the width needed. * @param[out] h Get the height needed. */ -static glFont* dialogue_getSize(char* msg, int* w, int* h) { +static glFont* dialogue_getSize(char* msg, int* width, int* height) { glFont* font; + double w, h, d; + int len; - font = &gl_smallFont; /* Try to use small font. */ + w = 300; /* Default width to try. */ + len = strlen(msg); - (*h) = gl_printHeight(font, (*w)-40, msg); - if(strlen(msg) > 100) { /* Make font bigger for large texts. */ + /* First we split by text length. */ + if(len < 50) { font = &gl_defFont; - (*h) = gl_printHeight(font, (*w)-40, msg); - if((*h) > 200) (*w) += MIN((*h)-200, 600); /* Too big, so we make it wider. */ - (*h) = gl_printHeight(font, (*w)-40, msg); + h = gl_printHeight(font, w-40, msg); + } else { + /* Now we look at proportion. */ + font = &gl_smallFont; + h = gl_printHeight(font, w-40, msg); + + d = ((double)w/(double)h) * (2./4.); /* Deformation factor. */ + if(fabs(d) > 0.3) { + if(h > w) + w = h; + h = gl_printHeight(font, w-40, msg); + } } + + /* Set values. */ + (*width) = w; + (*height) = h; + return font; } @@ -117,7 +134,6 @@ void dialogue_msg(char* caption, const char* fmt, ...) { va_end(ap); } - w = 300; /* Default width. */ font = dialogue_getSize(msg, &w, &h); /* Create the window. */ @@ -154,7 +170,6 @@ int dialogue_YesNo(char* caption, const char* fmt, ...) { va_end(ap); } - w = 300; font = dialogue_getSize(msg, &w, &h); /* Create the window. */