Update of /cvsroot/netrek/client/netrekxp/src
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19533/src

Modified Files:
	beeplite.c data.c defaults.c mswindow.c redraw.c 
Log Message:
Rewrote TTS centering/refresh code so that text is properly centered and clears properly when the message expires.
The old code used an average text width that was not so good, resulting in poor centering for long messages.  The new code measures the length of the message directly.
Also, the W_ClearArea function was not catching the 3 left-most pixels for whatever reason, so the call to this function slightly extends the area to clear. 
Updated COW manual to reflect change of tts_pos variable to tts_ypos.
This patch could be applied to other windows clients as well.

Index: redraw.c
===================================================================
RCS file: /cvsroot/netrek/client/netrekxp/src/redraw.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- redraw.c	18 Apr 2006 13:41:48 -0000	1.3
+++ redraw.c	19 Apr 2006 13:02:33 -0000	1.4
@@ -102,29 +102,24 @@
 #ifdef BEEPLITE
     if (tts_timer)
     {
-        static int last_width;
-
         tts_timer--;
         if (!tts_timer)
 	{
 	    /* timed out */
-	    W_EraseTTSText(w, WINSIDE, tts_pos, last_width);
-	    last_width = 0;
+	    W_EraseTTSText(w, last_tts_xpos, tts_ypos, last_tts_width);
+	    last_tts_width = 0;
 	}
-        else if (tts_timer == tts_time - 1 && last_width)
+        else if (tts_timer == tts_time - 1 && last_tts_width)
 	{
 	    /* first draw -- erase previous */
-	    W_EraseTTSText(w, WINSIDE, tts_pos, last_width);
+	    W_EraseTTSText(w, last_tts_xpos, tts_ypos, last_tts_width);
 	    /* draw new */
-	    W_WriteTTSText(w, WINSIDE, tts_pos, tts_width, lastIn,
-			 tts_len);
-	    last_width = tts_width;
+	    W_WriteTTSText(w, WINSIDE, tts_ypos, lastIn, tts_len);
 	}
         else
 	{
 	    /* regular draw */
-	    W_WriteTTSText(w, WINSIDE, tts_pos, tts_width, lastIn, tts_len);
-	    last_width = tts_width;
+	    W_WriteTTSText(w, WINSIDE, tts_ypos, lastIn, tts_len);
 	}
     }
 #endif

Index: mswindow.c
===================================================================
RCS file: /cvsroot/netrek/client/netrekxp/src/mswindow.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- mswindow.c	18 Apr 2006 13:41:48 -0000	1.5
+++ mswindow.c	19 Apr 2006 13:02:33 -0000	1.6
@@ -27,6 +27,7 @@
 #include <limits.h>
 #include <string.h>
 
+
 #include "copyright2.h"
 #include "config.h"
 #include "Wlib.h"
@@ -4580,30 +4581,26 @@
 }
 
 #ifdef BEEPLITE
-void W_EraseTTSText(W_Window window, int max_width, int y, int width)
+void W_EraseTTSText(W_Window window, int last_tts_xpos, int tts_ypos, int last_tts_width)
 {
-    register int x = (max_width - width) / 2;
+    tts_ypos -= W_Textheight;
 
-    if (x < 0)
-        x = 4;
-    y -= W_Textheight;
+    last_tts_xpos -= 3;
+    last_tts_width += 3;
 
-    W_ClearArea(window, x, y, width, W_Textheight);
+    W_ClearArea(window, last_tts_xpos, tts_ypos, last_tts_width, W_Textheight);
 }
 
-void W_WriteTTSText(W_Window window, int max_width, int y, int width, char *str, int len)
+void W_WriteTTSText(W_Window window, int max_width, int tts_ypos, char *str, int len)
 {
-    register int x = (max_width - width) / 2;
+    register int x;
     HDC hdc;
+    SIZE ext;
     FNHEADER_VOID;
 
-    if (x < 0)
-        x = 4;
-
-    y -= W_Textheight;
+    tts_ypos -= W_Textheight;
 
     hdc = GetDC(win->hwnd);
-    
     if (NetrekPalette)
     {
         SelectPalette(hdc, NetrekPalette, FALSE);
@@ -4612,13 +4609,14 @@
   
     SetTextColor(hdc, colortable[GREY].rgb);
     SetBkMode(hdc, TRANSPARENT);
-    TextOut(hdc, x, y, str, len);
+    GetTextExtentPoint32 (hdc, str, len, &ext);
+    x = (max_width - ext.cx)/2; 
+    if (x < 0)
+        x = 4;
+    TextOut(hdc, x, tts_ypos, str, len);
     ReleaseDC(win->hwnd, hdc);
-}
-
-int W_TTSTextWidth(char *s, int len)
-{
-    return len*W_Textwidth;
+    last_tts_xpos = x;
+    last_tts_width = ext.cx;
 }
 #endif
 

Index: defaults.c
===================================================================
RCS file: /cvsroot/netrek/client/netrekxp/src/defaults.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- defaults.c	18 Apr 2006 13:41:48 -0000	1.4
+++ defaults.c	19 Apr 2006 13:02:33 -0000	1.5
@@ -1519,7 +1519,7 @@
 	
     tts_time = intDefault("tts_time", tts_time);
     tts_max_len = intDefault("tts_max_len", tts_max_len);
-    tts_pos = intDefault("tts_pos", tts_pos);
+    tts_ypos = intDefault("tts_ypos", tts_ypos);
 #endif /* BEEPLITE */
 
     shipdefaults[DEFAULTSHIP].keymap = (unsigned char *) stringDefault ("keymap");
@@ -1725,7 +1725,7 @@
         saveFile = stringDefault ("saveFile");
     if (!saveFile)
     {
-        saveFile = (char *) malloc (sizeof (char) * 12); 
+        saveFile = (char *) malloc (sizeof (char) * 13); 
         sprintf (saveFile, "%s", "netrekrc.sav");
     }
 

Index: data.c
===================================================================
RCS file: /cvsroot/netrek/client/netrekxp/src/data.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- data.c	18 Apr 2006 13:41:48 -0000	1.4
+++ data.c	19 Apr 2006 13:02:33 -0000	1.5
@@ -488,10 +488,11 @@
 
 int     tts_len = 0;
 int     tts_max_len = 40;
-int     tts_width = 0;
+int	last_tts_xpos = 0;
+int     last_tts_width = 0;
 int     tts_timer = 0;
 int     tts_time = 25;
-int     tts_pos = WINSIDE / 2 - 16;		 /* as found in redraw.c *
+int     tts_ypos = WINSIDE / 2 - 16;		 /* as found in redraw.c *
 
 						  * 
 						  * * originally */

Index: beeplite.c
===================================================================
RCS file: /cvsroot/netrek/client/netrekxp/src/beeplite.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- beeplite.c	18 Apr 2006 13:47:24 -0000	1.1
+++ beeplite.c	19 Apr 2006 13:02:33 -0000	1.2
@@ -1,6 +1,13 @@
 /* beeplite.c
  *
  * $Log$
+ * Revision 1.2  2006/04/19 13:02:33  modemhero
+ * Rewrote TTS centering/refresh code so that text is properly centered and clears properly when the message expires.
+ * The old code used an average text width that was not so good, resulting in poor centering for long messages.  The new code measures the length of the message directly.
+ * Also, the W_ClearArea function was not catching the 3 left-most pixels for whatever reason, so the call to this function slightly extends the area to clear.
+ * Updated COW manual to reflect change of tts_pos variable to tts_ypos.
+ * This patch could be applied to other windows clients as well.
+ *
  * Revision 1.1  2006/04/18 13:47:24  modemhero
  * First attempt at reimport of beeplite into NetrekXP.  Unresolved issue: improper text clearing on TTS beeplite messages.  Still to add: saving of beeplite settings in save_options.
  *
@@ -253,7 +260,6 @@
 		    for (tts_len = 0; (*pm != '|' && tts_len < tts_max_len); tts_len++)
 		      lastIn[tts_len] = *pm++;
 		    lastIn[tts_len] = '\0';
-		    tts_width = W_TTSTextWidth(lastIn, tts_len);
 		    tts_timer = tts_time;
 		}
 	        break;