From 5fd278a859d5754a2ed5820c8a6ddadd6e77f2ad Mon Sep 17 00:00:00 2001
From: Allanis <allanis@saracraft.net>
Date: Tue, 4 Mar 2014 02:36:06 +0000
Subject: [PATCH] [Change] Tweaked dialogue behaviour a bit.

---
 src/dialogue.c | 33 ++++++++++++++++++++++++---------
 1 file changed, 24 insertions(+), 9 deletions(-)

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. */