[Tux4kids-commits] r522 - tuxmath/trunk/src

cheezmeister-guest at alioth.debian.org cheezmeister-guest at alioth.debian.org
Mon Jun 16 02:15:59 UTC 2008


Author: cheezmeister-guest
Date: 2008-06-16 02:15:58 +0000 (Mon, 16 Jun 2008)
New Revision: 522

Modified:
   tuxmath/trunk/src/game.c
   tuxmath/trunk/src/loaders.c
Log:
Fleshed out background scaling in-game.


Modified: tuxmath/trunk/src/game.c
===================================================================
--- tuxmath/trunk/src/game.c	2008-06-15 21:25:43 UTC (rev 521)
+++ tuxmath/trunk/src/game.c	2008-06-16 02:15:58 UTC (rev 522)
@@ -127,8 +127,12 @@
 
 static cloud_type cloud;
 static laser_type laser;
-static SDL_Surface* bkgd = NULL;
+static SDL_Surface* bkgd = NULL; //640x480 background (windowed)
+static SDL_Surface* scaled_bkgd = NULL; //native resolution (fullscreen)
 
+SDL_Surface* current_bkgd()
+  { return screen->flags & SDL_FULLSCREEN ? scaled_bkgd : bkgd; }
+
 static game_message s1, s2, s3, s4, s5;
 typedef struct {
   int x_is_blinking;
@@ -332,8 +336,8 @@
           }
         }
 
-        if (bkgd)
-          SDL_BlitSurface(bkgd, NULL, screen, NULL);
+        if (current_bkgd() )
+          SDL_BlitSurface(current_bkgd(), NULL, screen, NULL);
 
 
 
@@ -600,7 +604,7 @@
 
   /* Reset remaining stuff: */
 
-  bkgd = NULL;
+  bkgd = scaled_bkgd = NULL;
   last_bkgd = -1;
   reset_level();
   reset_comets();
@@ -636,6 +640,11 @@
     SDL_FreeSurface(bkgd);
     bkgd = NULL;
   }
+  if (scaled_bkgd != NULL)
+  {
+    SDL_FreeSurface(scaled_bkgd);
+    scaled_bkgd = NULL;
+  }
 
   /* Free dynamically-allocated items */
   free_on_exit();
@@ -1779,7 +1788,8 @@
     tmdprintf("Filling screen with color %d\n", bgcolor);
   }
 
-  if (bkgd == NULL || screen->flags & SDL_FULLSCREEN)
+  if (current_bkgd() == NULL || (current_bkgd()->w != screen->w && 
+                                 current_bkgd()->h != screen->h) )
   {
     dest.x = 0;
     dest.y = 0;
@@ -1795,11 +1805,11 @@
     SDL_FillRect(screen, &dest, fgcolor);
   }
 
-  if (bkgd)
+  if (current_bkgd())
   {
-    dest.x = (screen->w - bkgd->w) / 2;
-    dest.y = (screen->h - bkgd->h) / 2;
-    SDL_BlitSurface(bkgd, NULL, screen, &dest);
+    dest.x = (screen->w - current_bkgd()->w) / 2;
+    dest.y = (screen->h - current_bkgd()->h) / 2;
+    SDL_BlitSurface(current_bkgd(), NULL, screen, &dest);
   }
 }
 
@@ -2263,19 +2273,25 @@
 
   last_bkgd = i;
 
-  sprintf(fname, "%s/images/backgrounds/%d.jpg", DATA_PREFIX, i);
+  sprintf(fname, "backgrounds/%d.jpg", i);
 
   if (bkgd != NULL)
   {
     SDL_FreeSurface(bkgd);
     bkgd = NULL;
   }
+  if (scaled_bkgd != NULL)
+  {
+    SDL_FreeSurface(scaled_bkgd);
+    scaled_bkgd = NULL;
+  }
 
   if (Opts_UseBkgd())
   {
-    bkgd = LoadBkgd(fname);
+    LoadBothBkgds(fname, &scaled_bkgd, &bkgd);
+//    bkgd = LoadBkgd(fname);
 //    bkgd = LoadBkgd("/home/dbruce/red_test.jpg");
-    if (bkgd == NULL)
+    if (bkgd == NULL || scaled_bkgd == NULL)
     {
       fprintf(stderr,
 	      "\nWarning: Could not load background image:\n"

Modified: tuxmath/trunk/src/loaders.c
===================================================================
--- tuxmath/trunk/src/loaders.c	2008-06-15 21:25:43 UTC (rev 521)
+++ tuxmath/trunk/src/loaders.c	2008-06-16 02:15:58 UTC (rev 522)
@@ -251,8 +251,10 @@
   int ret = 0;
   SDL_Surface* orig = NULL;
   
+  tmdprintf("Entering LoadBothBkgds()\n");
   orig = LoadImage(datafile, IMG_REGULAR);
-  
+  tmdprintf("Scaling %dx%d to: %dx%d, %dx%d\n", 
+           orig->w, orig->h, RES_X, RES_Y, fs_res_x, fs_res_y);
   if (orig->w == RES_X && orig->h == RES_Y)
   {
     *win_bkgd = orig;
@@ -276,6 +278,7 @@
   if (ret == 2) //orig won't be used at all
     SDL_FreeSurface(orig);
     
+  tmdprintf("%d images scaled\nLeaving LoadBothBkgds()\n", ret);
   return ret;
 }
 




More information about the Tux4kids-commits mailing list