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

Modified Files:
	local.c main.c mswindow.c 
Log Message:
Fixed issue with borders not redrawing with extraalertborders off and doublebuffering on - since borders drawn at the login window aren't transfered to the game window with doublebuffering mode on, instead we will redraw the noncolored local
and map borders at the same time we execute the extraalertborder checks.
Fixed hard to find bug with extra alert borders being drawn 1 pixel too short on local window (was from setting graphics mode to GM_ADVANCED for SetWorldTransform and not changing back to GM_COMPATIBLE afterwards).
Tidied up WriteScaleBitmap and OverlayScaleBitmap to only go through the angular rigamole if the angle is nonzero (saves cpu power for drawing planets and such that don't need rotation).
Gave up on trying to figure out border conditions with rotated scale bitmaps, instead they will sometimes overwrite alert border but this gets refreshed pretty often anyways.  Something to fix in the future.  Redrawing border every screen refresh too cpu intensive unfortunately to be practical.
Fixed some tab/spacing issues in one of the mswindow functions.

Index: mswindow.c
===================================================================
RCS file: /cvsroot/netrek/client/netrekxp/src/mswindow.c,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -d -r1.26 -r1.27
--- mswindow.c	22 May 2006 08:27:53 -0000	1.26
+++ mswindow.c	28 May 2006 06:28:14 -0000	1.27
@@ -1201,9 +1201,9 @@
         }
     }
 
-	/* Here we have name and parent, so let's set them */
-	strcpy (window->name, name);
-	window->parent = parentwin;
+    /* Here we have name and parent, so let's set them */
+    strcpy (window->name, name);
+    window->parent = parentwin;
 
     //Actually create the window
     //Hacked to allow negative create locations -SAC
@@ -1870,7 +1870,7 @@
     short wheel;
     struct Icon *icon;
     RECT r;
-	WORD lwParam;
+    WORD lwParam;
 #if defined(MOTION_MOUSE) || defined(XTRA_MESSAGE_UI)
     static POINTS prev_pos;
     static HWND LastPressHwnd;
@@ -2123,46 +2123,45 @@
 
         STORE_EVENT_MOUSE;
         LastPressHwnd = hwnd;
-
-		lwParam = LOWORD (wParam);
+        lwParam = LOWORD (wParam);
 
 #ifdef SHIFTED_MOUSE
         if (shiftedMouse)
         {
             if ((lwParam & MK_SHIFT) && (lwParam & MK_CONTROL))
-    		{
-	    		if (lwParam & MK_XBUTTON1)
-		    		EventQueue[EventTail].key = W_XBUTTON1_4;
-			    else if (lwParam & MK_XBUTTON2)
-				    EventQueue[EventTail].key = W_XBUTTON2_4;
-		    }
+            {
+            	if (lwParam & MK_XBUTTON1)
+            	    EventQueue[EventTail].key = W_XBUTTON1_4;
+            	else if (lwParam & MK_XBUTTON2)
+            	    EventQueue[EventTail].key = W_XBUTTON2_4;
+            }
             else if (lwParam & MK_SHIFT)
-	    	{
-		    	if (lwParam & MK_XBUTTON1)
-			    	EventQueue[EventTail].key = W_XBUTTON1_2;
-    			else if (lwParam & MK_XBUTTON2)
-	    			EventQueue[EventTail].key = W_XBUTTON2_2;
-		    }
+            {
+            	if (lwParam & MK_XBUTTON1)
+            	    EventQueue[EventTail].key = W_XBUTTON1_2;
+            	else if (lwParam & MK_XBUTTON2)
+            	    EventQueue[EventTail].key = W_XBUTTON2_2;
+            }
             else if (lwParam & MK_CONTROL)
-	    	{
-		    	if (lwParam & MK_XBUTTON1)
-			    	EventQueue[EventTail].key = W_XBUTTON1_3;
-    			else if (lwParam & MK_XBUTTON2)
-	    			EventQueue[EventTail].key = W_XBUTTON2_3;
-		    }
+            {
+            	if (lwParam & MK_XBUTTON1)
+            	    EventQueue[EventTail].key = W_XBUTTON1_3;
+            	else if (lwParam & MK_XBUTTON2)
+            	    EventQueue[EventTail].key = W_XBUTTON2_3;
+            }
             else
-    		{
-	    		if (lwParam & MK_XBUTTON1)
-		    		EventQueue[EventTail].key = W_XBUTTON1;
-			    else if (lwParam & MK_XBUTTON2)
-				    EventQueue[EventTail].key = W_XBUTTON2;
-    		}
+            {
+            	if (lwParam & MK_XBUTTON1)
+            	    EventQueue[EventTail].key = W_XBUTTON1;
+            	else if (lwParam & MK_XBUTTON2)
+            	    EventQueue[EventTail].key = W_XBUTTON2;
+            }
         }
         else
-       		if (lwParam & MK_XBUTTON1)
-	    		EventQueue[EventTail].key = W_XBUTTON1;
-		    else if (lwParam & MK_XBUTTON2)
-			    EventQueue[EventTail].key = W_XBUTTON2;
+            if (lwParam & MK_XBUTTON1)
+                EventQueue[EventTail].key = W_XBUTTON1;
+            else if (lwParam & MK_XBUTTON2)
+                EventQueue[EventTail].key = W_XBUTTON2;
 #else
         if (lwParam & MK_XBUTTON1)
             EventQueue[EventTail].key = W_XBUTTON1;
@@ -4002,71 +4001,122 @@
     srcy = 0;
     x += border;
     y += border;
- 
-    if (x < border)
-    {
-        newwidth = destwidth - (border - x);
-        srcx += border - x;
-        x = border;
-    }
-    else if ((newwidth = (usebitmaphwnd ? bitmap->ClipRectAddr->right : win->ClipRect.right) - x) > destwidth)
-        newwidth = destwidth;
-    if (y < border)
-    {
-        newheight = destheight - (border - y);
-        srcy += (border - y);
-        y = border;
-    }
-    else if ((newheight = (usebitmaphwnd? bitmap->ClipRectAddr->bottom : win->ClipRect.bottom) - y) > destheight)
-        newheight = destheight;
-
+    
     if (NetrekPalette)
     {
         SelectPalette (hdc, NetrekPalette, FALSE);
         RealizePalette (hdc);
     }
-
     //Set the color of the bitmap
     //(oddly enough, 1-bit = bk color, 0-bit = text (fg) color)
     SetBkColor (hdc, colortable[color].rgb);
     SetTextColor (hdc, colortable[BLACK].rgb);
- 
-    //Convert angle to radians 
-    radians=(2*3.14159*angle/360);
 
-    cosine=(float)cos(radians);
-    sine=(float)sin(radians);
-    
-    // Scale used to find bitmap center
-    xscale = (float)(newwidth/2);
-    yscale = (float)(newheight/2);
+    if (angle != 0)
+    {
+        //Convert angle to radians 
+        radians=(2*3.14159*angle/360);
 
-    eDx = x + xscale - cosine*(xscale) + sine*(yscale);
-    eDy = y + yscale - cosine*(yscale) - sine*(xscale);
-    SetGraphicsMode(hdc,GM_ADVANCED);
+        cosine=(float)cos(radians);
+        sine=(float)sin(radians);
+        
+        /*  Can't get this to work
+         *  Feel free to try and fix it - BB
 
-    xForm.eM11=cosine;
-    xForm.eM12=sine;
-    xForm.eM21=-sine;
-    xForm.eM22=cosine;
-    xForm.eDx = eDx;
-    xForm.eDy = eDy;
+        int x1, x2, x3, y1, y2, y3, minx, maxx, miny, maxy, w, h;
 
-    SetWorldTransform(hdc,&xForm);
-    BitBlt(hdc, 0, 0, newwidth, newheight, GlobalMemDC2, srcx, srcy, SRCPAINT);
-   
-    // Reset xForm
-    xForm.eM11 = (FLOAT) 1.0; 
-    xForm.eM12 = (FLOAT) 0.0; 
-    xForm.eM21 = (FLOAT) 0.0; 
-    xForm.eM22 = (FLOAT) 1.0; 
-    xForm.eDx  = (FLOAT) 0.0; 
-    xForm.eDy  = (FLOAT) 0.0; 
+        // Time to find out the new width and height of the rotated bitmap!
+        // First get the coordinates of the 3 corners (assume 1 corner at 0,0)
+        x1 = (int)(destheight * sine);
+        y1 = (int)(destheight * cosine);
+        x2 = (int)(destwidth * cosine + destheight * sine);
+        y2 = (int)(destheight * cosine - destwidth * sine);
+        x3 = (int)(destwidth * cosine);
+        y3 = (int)(-destwidth * sine);
+        
+        minx = min(0,min(x1, min(x2,x3)));
+        miny = min(0,min(y1, min(y2,y3)));
+        maxx = max(0,max(x1, max(x2,x3)));
+        maxy = max(0,max(y1, max(y2,y3)));
+        
+        w = abs (maxx - minx);
+        h = abs (maxy - miny);
+
+        // Calculate border constraints with rotated bitmap width/height
+        if (x < border)
+        {
+            newwidth = w - (border - x);
+            srcx += border - x;
+            x = border;
+        }
+        else if ((newwidth = (usebitmaphwnd ? bitmap->ClipRectAddr->right : win->ClipRect.right) - x) > w)
+            newwidth = w;
+        if (y < border)
+        {
+            newheight = h - (border - y);
+            srcy += (border - y);
+            y = border;
+        }
+        else if ((newheight = (usebitmaphwnd ? bitmap->ClipRectAddr->bottom : win->ClipRect.bottom) - y) > h)
+            newheight = h;
+        */
+        newwidth = destwidth;
+        newheight = destheight;
+
+        // Scale used to find bitmap center
+        xscale = (float)(destwidth/2);
+        yscale = (float)(destheight/2);
+
+        eDx = x + xscale - cosine*(xscale) + sine*(yscale);
+        eDy = y + yscale - cosine*(yscale) - sine*(xscale);
+        SetGraphicsMode(hdc,GM_ADVANCED);
+
+        xForm.eM11=cosine;
+        xForm.eM12=sine;
+        xForm.eM21=-sine;
+        xForm.eM22=cosine;
+        xForm.eDx = eDx;
+        xForm.eDy = eDy;
+
+        SetWorldTransform(hdc,&xForm);
+        BitBlt(hdc, 0, 0, newwidth, newheight, GlobalMemDC2, srcx, srcy, SRCPAINT);
+
+        // Reset xForm
+        xForm.eM11 = (FLOAT) 1.0; 
+        xForm.eM12 = (FLOAT) 0.0; 
+        xForm.eM21 = (FLOAT) 0.0; 
+        xForm.eM22 = (FLOAT) 1.0; 
+        xForm.eDx  = (FLOAT) 0.0; 
+        xForm.eDy  = (FLOAT) 0.0; 
+
+        SetWorldTransform(hdc,&xForm); 
+        SetGraphicsMode(hdc,GM_COMPATIBLE);
+    }
+    else
+    {
+    	// Calculate border constraints with bitmap width/height
+        if (x < border)
+        {
+            newwidth = destwidth - (border - x);
+            srcx += border - x;
+            x = border;
+        }
+        else if ((newwidth = (usebitmaphwnd ? bitmap->ClipRectAddr->right : win->ClipRect.right) - x) > destwidth)
+            newwidth = destwidth;
+        if (y < border)
+        {
+            newheight = destheight - (border - y);
+            srcy += (border - y);
+            y = border;
+        }
+        else if ((newheight = (usebitmaphwnd? bitmap->ClipRectAddr->bottom : win->ClipRect.bottom) - y) > destheight)
+            newheight = destheight;
+
+        BitBlt(hdc, x, y, newwidth, newheight, GlobalMemDC2, srcx, srcy, SRCPAINT);
+    }
 
-    SetWorldTransform(hdc,&xForm); 
-    
     DeleteObject (newbmp);
-    
+
     if (!sdb || !doubleBuffering || !ingame)
     {
     	if (usebitmaphwnd)
@@ -5008,10 +5058,8 @@
                 int b)
 {
     HDC hdc;
-
     FNHEADER_VOID;
 
-
     b;                          /* Makes compiler happy -SAC */
     if (win->type == WIN_SCROLL)
     {
@@ -5114,12 +5162,12 @@
     
     SelectObject (GlobalMemDC, bitmap->bm);
     SelectObject (GlobalMemDC2, newbmp);
-  
+
     // Copy selected section of main bitmap into newbmp before rotation
     SetStretchBltMode(GlobalMemDC2, COLORONCOLOR);
     StretchBlt(GlobalMemDC2, 0, 0, destwidth, destheight, GlobalMemDC,
                srcx, srcy, srcwidth, srcheight, SRCPAINT);
-    
+
     //Fast (I hope) rectangle intersection, don't overwrite our borders
     if (usebitmaphwnd)
         border = bitmap->ClipRectAddr->top;
@@ -5131,69 +5179,80 @@
     srcy = 0;
     x += border;
     y += border;
- 
-    if (x < border)
-    {
-        newwidth = destwidth - (border - x);
-        srcx += border - x;
-        x = border;
-    }
-    else if ((newwidth = (usebitmaphwnd ? bitmap->ClipRectAddr->right: win->ClipRect.right) - x) > destwidth)
-        newwidth = destwidth;
-    if (y < border)
-    {
-        newheight = destheight - (border - y);
-        srcy += (border - y);
-        y = border;
-    }
-    else if ((newheight = (usebitmaphwnd ? bitmap->ClipRectAddr->bottom : win->ClipRect.bottom) - y) > destheight)
-        newheight = destheight;
 
     if (NetrekPalette)
     {
         SelectPalette (hdc, NetrekPalette, FALSE);
         RealizePalette (hdc);
     }
-
     //Set the color of the bitmap
     //(oddly enough, 1-bit = bk color, 0-bit = text (fg) color)
     SetBkColor (hdc, colortable[color].rgb);
     SetTextColor (hdc, colortable[BLACK].rgb);
+    
+    if (angle != 0)
+    {
+        //Convert angle to radians 
+        radians=(2*3.14159*angle/360);
 
-    //Convert angle to radians 
-    radians=(2*3.14159*angle/360);
+        cosine=(float)cos(radians);
+        sine=(float)sin(radians);
 
-    cosine=(float)cos(radians);
-    sine=(float)sin(radians);
-    
-    // Scale used to find bitmap center
-    xscale = (float)(newwidth/2);
-    yscale = (float)(newheight/2);
+        newwidth = destwidth;
+        newheight = destheight;
 
-    eDx = x + xscale - cosine*(xscale) + sine*(yscale);
-    eDy = y + yscale - cosine*(yscale) - sine*(xscale);
-    SetGraphicsMode(hdc,GM_ADVANCED);
+        // Scale used to find bitmap center
+        xscale = (float)(destwidth/2);
+        yscale = (float)(destheight/2);
 
-    xForm.eM11=cosine;
-    xForm.eM12=sine;
-    xForm.eM21=-sine;
-    xForm.eM22=cosine;
-    xForm.eDx = eDx;
-    xForm.eDy = eDy;
+        eDx = x + xscale - cosine*(xscale) + sine*(yscale);
+        eDy = y + yscale - cosine*(yscale) - sine*(xscale);
+        SetGraphicsMode(hdc,GM_ADVANCED);
 
-    SetWorldTransform(hdc,&xForm);
+        xForm.eM11=cosine;
+        xForm.eM12=sine;
+        xForm.eM21=-sine;
+        xForm.eM22=cosine;
+        xForm.eDx = eDx;
+        xForm.eDy = eDy;
 
-    BitBlt(hdc, 0, 0, newwidth, newheight, GlobalMemDC2, srcx, srcy, SRCAND);
+        SetWorldTransform(hdc,&xForm);
 
-    // Reset xForm
-    xForm.eM11 = (FLOAT) 1.0; 
-    xForm.eM12 = (FLOAT) 0.0; 
-    xForm.eM21 = (FLOAT) 0.0; 
-    xForm.eM22 = (FLOAT) 1.0; 
-    xForm.eDx  = (FLOAT) 0.0; 
-    xForm.eDy  = (FLOAT) 0.0; 
+        BitBlt(hdc, 0, 0, newwidth, newheight, GlobalMemDC2, srcx, srcy, SRCAND);
+    
+        // Reset xForm
+        xForm.eM11 = (FLOAT) 1.0; 
+        xForm.eM12 = (FLOAT) 0.0; 
+        xForm.eM21 = (FLOAT) 0.0; 
+        xForm.eM22 = (FLOAT) 1.0; 
+        xForm.eDx  = (FLOAT) 0.0; 
+        xForm.eDy  = (FLOAT) 0.0; 
 
-    SetWorldTransform(hdc,&xForm); 
+        SetWorldTransform(hdc,&xForm); 
+        SetGraphicsMode(hdc,GM_COMPATIBLE);
+    }
+    else
+    {
+    	// Calculate border constraints with bitmap width/height
+        if (x < border)
+        {
+            newwidth = destwidth - (border - x);
+            srcx += border - x;
+            x = border;
+        }
+        else if ((newwidth = (usebitmaphwnd ? bitmap->ClipRectAddr->right : win->ClipRect.right) - x) > destwidth)
+            newwidth = destwidth;
+        if (y < border)
+        {
+            newheight = destheight - (border - y);
+            srcy += (border - y);
+            y = border;
+        }
+        else if ((newheight = (usebitmaphwnd? bitmap->ClipRectAddr->bottom : win->ClipRect.bottom) - y) > destheight)
+            newheight = destheight;
+
+        BitBlt(hdc, x, y, newwidth, newheight, GlobalMemDC2, srcx, srcy, SRCAND);
+    }
 
     DeleteObject (newbmp);
     

Index: main.c
===================================================================
RCS file: /cvsroot/netrek/client/netrekxp/src/main.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- main.c	26 May 2006 06:58:19 -0000	1.7
+++ main.c	28 May 2006 06:28:14 -0000	1.8
@@ -86,7 +86,7 @@
 {
     int usage = 0;
     int err = 0;
-    int	hideConsole = 1;
+    int hideConsole = 1;
     char *name, *ptr;
     int i;
 

Index: local.c
===================================================================
RCS file: /cvsroot/netrek/client/netrekxp/src/local.c,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -d -r1.33 -r1.34
--- local.c	26 May 2006 06:58:19 -0000	1.33
+++ local.c	28 May 2006 06:28:14 -0000	1.34
@@ -2334,7 +2334,6 @@
     }
 
     /* Change border color to signify alert status */
-
     if (oldalert != (me->p_flags & (PFGREEN | PFYELLOW | PFRED)))
     {
         oldalert = (me->p_flags & (PFGREEN | PFYELLOW | PFRED));
@@ -2343,13 +2342,13 @@
         case PFGREEN:
             if (extraAlertBorder)
             {
-#ifndef DOUBLE_BUFFERING
                 W_ChangeBorder (w, gColor);
                 W_ChangeBorder (mapw, gColor);
-#else
-                W_ChangeBorderDB (localSDB, gColor);
-                W_ChangeBorderDB (mapSDB, gColor);
-#endif
+            }
+            else
+            {
+                W_ChangeBorder (w, W_White);
+                W_ChangeBorder (mapw, W_White);
             }
             W_ChangeBorder (baseWin, gColor);
 
@@ -2368,13 +2367,13 @@
         case PFYELLOW:
             if (extraAlertBorder)
             {
-#ifndef DOUBLE_BUFFERING
                 W_ChangeBorder (w, yColor);
                 W_ChangeBorder (mapw, yColor);
-#else
-                W_ChangeBorderDB (localSDB, yColor);
-                W_ChangeBorderDB (mapSDB, yColor);
-#endif
+            }
+            else
+            {
+                W_ChangeBorder (w, W_White);
+                W_ChangeBorder (mapw, W_White);
             }
             W_ChangeBorder (baseWin, yColor);
 
@@ -2397,13 +2396,13 @@
         case PFRED:
             if (extraAlertBorder)
             {
-#ifndef DOUBLE_BUFFERING
                 W_ChangeBorder (w, rColor);
                 W_ChangeBorder (mapw, rColor);
-#else
-                W_ChangeBorderDB (localSDB, rColor);
-                W_ChangeBorderDB (mapSDB, rColor);
-#endif
+            }
+            else
+            {
+                W_ChangeBorder (w, W_White);
+                W_ChangeBorder (mapw, W_White);
             }
             W_ChangeBorder (baseWin, rColor);