Update of /cvsroot/netrek/client/netrekxp/src
In directory sc8-pr-cvs16:/tmp/cvs-serv16255/src

Modified Files:
	local.c map.c mswindow.c 
Log Message:
Several bug fixes related to resizing map and local windows to very
small and even to 0 size.
Resizing map and local now only lets you size the windows as
squares.

Index: mswindow.c
===================================================================
RCS file: /cvsroot/netrek/client/netrekxp/src/mswindow.c,v
retrieving revision 1.65
retrieving revision 1.66
diff -u -d -r1.65 -r1.66
--- mswindow.c	10 Apr 2007 11:07:08 -0000	1.65
+++ mswindow.c	11 Apr 2007 01:10:05 -0000	1.66
@@ -1951,16 +1951,21 @@
 
     case WM_EXITSIZEMOVE:
         //Disable possibility to move internal windows
+        {   // have to add bracket to be able to declare variables
+        int width, height;
+        RECT winRect;   // current window rectangle       
+
         GET_STRUCT_PTR;
 
-        // Adjust TWINSIDE and GWINSIDE
         // Reinitialize whatever is necessary (so many things are created based on
         // a fixed TWINSIDE)
+        // Adjust window to be square
+        // Adjust TWINSIDE and GWINSIDE
         // Redo critical windows
         // Clear window
         if (windowMove && (Window *) w != NULL && win->hwnd == ((Window *) w)->hwnd)
         { 
-            TWINSIDE = MAX(win->ClipRect.bottom, win->ClipRect.right) + win->border;
+            GetWindowRect (((Window *) w)->hwnd, &winRect);
 
             // Have to reinitialize SDB
             SelectObject (localSDB->mem_dc, localSDB->old_bmp);
@@ -1972,6 +1977,22 @@
             // and stars
             initStars();
 
+            // Keep window square
+            width = winRect.right - winRect.left;
+            height = winRect.bottom - winRect.top;
+            if (width > height)
+                width = height;
+            else
+                height = width;
+            TWINSIDE = width - 2 * win->border;
+
+            /* In case of WS_CAPTION (titlebar on) we have to subtract caption size */
+            if (GetWindowLongPtr (((Window *) baseWin)->hwnd, GWL_STYLE) & WS_CAPTION)
+                winRect.top -= GetSystemMetrics (SM_CYCAPTION);
+ 
+            MoveWindow (((Window *) w)->hwnd, winRect.left - win->border, winRect.top - win->border,
+                        width, height, TRUE);
+ 
             // All windows based on TWINSIDE are out of position now, but the team
             // select/quit windows are now the wrong size too, so we need to redo them
             for (i = 0; i < 4; i++)
@@ -1980,6 +2001,7 @@
                 teamWin[i] = W_MakeWindow (teamshort[1 << i], i * (TWINSIDE / 5), TWINSIDE - (TWINSIDE / 5),
                                            (TWINSIDE / 5), (TWINSIDE / 5), w, 1, foreColor);
             }
+
             W_UnmapWindow (qwin);
             qwin = W_MakeWindow ("quit", 4 * (TWINSIDE / 5), TWINSIDE - (TWINSIDE / 5), (TWINSIDE / 5),
                                  (TWINSIDE / 5), w, 1, foreColor);
@@ -1990,7 +2012,7 @@
         }
         else if (windowMove && (Window *) mapw != NULL && win->hwnd == ((Window *) mapw)->hwnd)
         {
-            GWINSIDE = MAX(win->ClipRect.bottom, win->ClipRect.right) + win->border;
+            GetWindowRect (((Window *) mapw)->hwnd, &winRect);
 
             // Have to reinitialize SDB
             SelectObject (mapSDB->mem_dc, mapSDB->old_bmp);
@@ -2000,6 +2022,22 @@
             free (mapSDB);
             mapSDB = W_InitSDB (mapw);
 
+            // Keep window square
+            width = winRect.right - winRect.left;
+            height = winRect.bottom - winRect.top;
+            if (width > height)
+                width = height;
+            else
+                height = width;
+            GWINSIDE = width - 2 * win->border;
+            
+            /* In case of WS_CAPTION (titlebar on) we have to subtract caption size */
+            if (GetWindowLongPtr (((Window *) baseWin)->hwnd, GWL_STYLE) & WS_CAPTION)
+                winRect.top -= GetSystemMetrics (SM_CYCAPTION);
+
+            MoveWindow (((Window *) mapw)->hwnd, winRect.left - win->border, winRect.top - win->border,
+                        width, height, TRUE);
+
             redrawall = 1;
         }
 
@@ -2019,6 +2057,7 @@
                     movingr.right - movingr.left,
                     movingr.bottom - movingr.top,
                     TRUE);
+        }
         break;
 
     case WM_PAINT:

Index: map.c
===================================================================
RCS file: /cvsroot/netrek/client/netrekxp/src/map.c,v
retrieving revision 1.48
retrieving revision 1.49
diff -u -d -r1.48 -r1.49
--- map.c	10 Apr 2007 05:43:45 -0000	1.48
+++ map.c	11 Apr 2007 01:10:05 -0000	1.49
@@ -853,7 +853,7 @@
     static int viewx = 0, viewy = 0;
     static char clearviewbox = 0;
     static char viewboxcleared = 0;
-    int viewdist = (TWINSIDE / 2 * scaleFactor) / (GWIDTH / GWINSIDE);
+    int viewdist;
     int view = TWINSIDE * scaleFactor / 2;
     int mvx, mvy;
 
@@ -866,6 +866,10 @@
 #endif
     clearMap ();
 
+    if (GWINSIDE == 0)
+       return;
+ 
+    viewdist = (TWINSIDE / 2 * scaleFactor) / (GWIDTH / GWINSIDE);
     dx = (me->p_x) / (GWIDTH / GWINSIDE);
     dy = (me->p_y) / (GWIDTH / GWINSIDE);
 

Index: local.c
===================================================================
RCS file: /cvsroot/netrek/client/netrekxp/src/local.c,v
retrieving revision 1.92
retrieving revision 1.93
diff -u -d -r1.92 -r1.93
--- local.c	10 Apr 2007 11:07:08 -0000	1.92
+++ local.c	11 Apr 2007 01:10:04 -0000	1.93
@@ -124,6 +124,9 @@
     register int i, j, k;
     int imax, jmax, kmax;
     
+    if (TWINSIDE == 0)
+        return;
+
     imax = 5 * STARSIDE / TWINSIDE + 1;
     if (imax > MAXSECTORS)
         imax = MAXSECTORS;
@@ -156,12 +159,17 @@
        note: cpp symbols in expressions (TWINSIDE*SCALE) will be precalculated
        by any C optimizer
     */ 
-    int sectorx = me->p_x / (fullview);
-    int sectory = me->p_y / (fullview);
-    int sector_offx = me->p_x - sectorx * (fullview);
-    int sector_offy = me->p_y - sectory * (fullview);
+    int sectorx, sectory, sector_offx, sector_offy;
     int l = 0, r = 0, t = 0, b = 0;
     
+    if (fullview == 0)
+        return;
+        
+    sectorx = me->p_x / (fullview);
+    sectory = me->p_y / (fullview);
+    sector_offx = me->p_x - sectorx * (fullview);
+    sector_offy = me->p_y - sectory * (fullview);
+    
     if (warpStreaks && streaks_on)
     /* Streaks_on is toggled on by redrawStarSector with a change in warp state,
        and toggled off after certain conditions are met.  Only need to track
@@ -181,8 +189,6 @@
         sectory--;
         sector_offy += fullview; 
     }   
-
-#define MAXSECTOR   (5 * STARSIDE / TWINSIDE) + 1
   
     /* at worst we have to redraw 4 star sectors */
 
@@ -191,13 +197,13 @@
        check first to make sure it's valid.  This is mainly important for if
        it tries to redraw and we're already dead
     */
-    if (sectorx < 0 || sectory < 0 || sectorx > MAXSECTOR || sectory > MAXSECTOR )
+    if (sectorx < 0 || sectory < 0 || sectorx > MAXSECTORS || sectory > MAXSECTORS )
         return;
 
     l = sector_offx < view && sectorx > 0;
-    r = sector_offx > view && sectorx + 1 < MAXSECTOR;
+    r = sector_offx > view && sectorx + 1 < MAXSECTORS;
     t = sector_offy < view && sectory > 0;
-    b = sector_offy > view && sectory + 1 < MAXSECTOR;
+    b = sector_offy > view && sectory + 1 < MAXSECTORS;
 
     if (t) 
     {