[Tux4kids-commits] r312 - in tuxmath/trunk: docs src

dbruce-guest at alioth.debian.org dbruce-guest at alioth.debian.org
Wed Oct 31 11:21:15 UTC 2007


Author: dbruce-guest
Date: 2007-10-31 11:21:15 +0000 (Wed, 31 Oct 2007)
New Revision: 312

Modified:
   tuxmath/trunk/docs/changelog
   tuxmath/trunk/src/SDL_extras.c
   tuxmath/trunk/src/setup.c
   tuxmath/trunk/src/tuxmath.h
Log:
Now using 32 bit pixel depth; DarkenScreen() works properly.


Modified: tuxmath/trunk/docs/changelog
===================================================================
--- tuxmath/trunk/docs/changelog	2007-10-30 18:15:55 UTC (rev 311)
+++ tuxmath/trunk/docs/changelog	2007-10-31 11:21:15 UTC (rev 312)
@@ -4,7 +4,10 @@
       * Uncrufting! - eliminated tuxtype_playsound(), moved playsound() to audio.c,
         and removed playsound.c and .h; eliminated alphabet.c; moved DarkenScreen()
         to SDL_extras.c and eliminated pause.c; moved SwitchScreenMode() to SDL_extras.c.
-
+  Graphics:
+      * Change to using 32 bits/pixel, however all functions that need this info now
+        use PIXEL_BITS #define'd in tuxmath.h - recompiling for 16 BPP only requires
+        changing this def (confirmed that both settings work, at least in Linux).
       David Bruce <dbruce at tampabay.rr.com>
 
 2007.Oct.29 (svn.debian.org/tux4kids - revision 310)

Modified: tuxmath/trunk/src/SDL_extras.c
===================================================================
--- tuxmath/trunk/src/SDL_extras.c	2007-10-30 18:15:55 UTC (rev 311)
+++ tuxmath/trunk/src/SDL_extras.c	2007-10-31 11:21:15 UTC (rev 312)
@@ -9,20 +9,19 @@
 * Copyright: GPL v3 or later
 *
 */
-/* DrawButton() creates and draws a translucent button with */
-/* rounded ends.  The location and size are taken from the */
-/* SDL_Rect* and width arguments.  The sprite is used to   */
-/* fill in the rect with the desired translucent color and */
-/* give it nice, rounded ends.                             */
-/* FIXME make it match target_rect more precisely          */
 
 #include "SDL_extras.h"
 #include "tuxmath.h"
 
+
+/* DrawButton() creates and draws a translucent button with */
+/* rounded ends.  All colors and alpha values are supported.*/
 void DrawButton(SDL_Rect* target_rect,
                 int radius,
                 Uint8 r, Uint8 g, Uint8 b, Uint8 a)
 {
+  /* NOTE - we use a 32-bit temp surface even if we have a 16-bit */
+  /* screen - it gets converted during blitting.                  */
   SDL_Surface* tmp_surf = SDL_CreateRGBSurface(SDL_SWSURFACE|SDL_SRCALPHA,
                                           target_rect->w,
                                           target_rect->h,
@@ -34,10 +33,6 @@
 
   SDL_BlitSurface(tmp_surf, NULL, screen, target_rect);
   SDL_FreeSurface(tmp_surf);
-//  SDL_UpdateRect(screen, 0, 0, 0, 0); 
-
-  //SDL_UpdateRect(screen, target_rect->x, target_rect->y, target_rect->w, target_rect->h); 
-
 }
 
 
@@ -323,10 +318,20 @@
 /* Darkens the screen by a factor of 2^bits */
 void DarkenScreen(Uint8 bits)
 {
+#if PIXEL_BITS == 32
+  Uint32 rm = screen->format->Rmask;
+  Uint32 gm = screen->format->Gmask;
+  Uint32 bm = screen->format->Bmask;
+  Uint32* p; 
+#elif PIXEL_BITS == 16
   Uint16 rm = screen->format->Rmask;
   Uint16 gm = screen->format->Gmask;
   Uint16 bm = screen->format->Bmask;
-  Uint16 *p; 
+  Uint16* p; 
+#else
+  return;
+#endif
+
   int x, y;
 
   /* (realistically, 1 and 2 are the only useful values) */
@@ -366,7 +371,7 @@
       SDL_SWSURFACE,
       RES_X,
       RES_Y,
-      BPP,
+      PIXEL_BITS,
 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
       0xff000000,
       0x00ff0000,
@@ -386,17 +391,23 @@
   }
 
   SDL_BlitSurface(screen,&src,tmp,&dst);
-  SDL_UpdateRect(tmp,0,0,RES_X,RES_Y);
+  SDL_UpdateRect(tmp, 0, 0, RES_X, RES_Y);
   SDL_FreeSurface(screen);
   screen = NULL;
 
   if (window)
   {
-    screen = SDL_SetVideoMode(RES_X,RES_Y,BPP, SDL_SWSURFACE|SDL_HWPALETTE);
+    screen = SDL_SetVideoMode(RES_X,
+                              RES_Y,
+                              PIXEL_BITS,
+                              SDL_SWSURFACE|SDL_HWPALETTE);
   }
   else
   {
-    screen = SDL_SetVideoMode(RES_X,RES_Y,BPP, SDL_SWSURFACE|SDL_HWPALETTE|SDL_FULLSCREEN);
+    screen = SDL_SetVideoMode(RES_X,
+                              RES_Y,
+                              PIXEL_BITS,
+                              SDL_SWSURFACE|SDL_HWPALETTE|SDL_FULLSCREEN);
   }
 
   SDL_BlitSurface(tmp,&src,screen,&dst);

Modified: tuxmath/trunk/src/setup.c
===================================================================
--- tuxmath/trunk/src/setup.c	2007-10-30 18:15:55 UTC (rev 311)
+++ tuxmath/trunk/src/setup.c	2007-10-31 11:21:15 UTC (rev 312)
@@ -440,56 +440,58 @@
   }
   
   #endif
-{
-  SDL_VideoInfo *videoInfo;
-  Uint32 surfaceMode;
-  videoInfo = SDL_GetVideoInfo();
-  if (videoInfo->hw_available) {
-    surfaceMode = SDL_HWSURFACE;
-    #ifdef TUXMATH_DEBUG    
-    printf("HW mode\n");
-    #endif
-  }
-  else {
-    surfaceMode = SDL_SWSURFACE;
-    #ifdef TUXMATH_DEBUG    
-    printf("SW mode\n");
-    #endif
-  }
-
-  if (Opts_Fullscreen())
   {
-    screen = SDL_SetVideoMode(640, 480, 16, SDL_FULLSCREEN | surfaceMode);
-    if (screen == NULL)
+    SDL_VideoInfo *videoInfo;
+    Uint32 surfaceMode;
+    videoInfo = SDL_GetVideoInfo();
+    if (videoInfo->hw_available)
     {
-      fprintf(stderr,
+      surfaceMode = SDL_HWSURFACE;
+#ifdef TUXMATH_DEBUG    
+      printf("HW mode\n");
+#endif
+    }
+    else
+    {
+      surfaceMode = SDL_SWSURFACE;
+#ifdef TUXMATH_DEBUG    
+      printf("SW mode\n");
+#endif
+    }
+
+    if (Opts_Fullscreen())
+    {
+      screen = SDL_SetVideoMode(RES_X, RES_Y, PIXEL_BITS, SDL_FULLSCREEN | surfaceMode);
+      if (screen == NULL)
+      {
+        fprintf(stderr,
               "\nWarning: I could not open the display in fullscreen mode.\n"
 	      "The Simple DirectMedia error that occured was:\n"
 	      "%s\n\n", SDL_GetError());
-      Opts_SetFullscreen(0);
+        Opts_SetFullscreen(0);
+      }
     }
-  }
 
-  if (!Opts_Fullscreen())
-  {
-    screen = SDL_SetVideoMode(640, 480, 16, surfaceMode);
-  }
+    if (!Opts_Fullscreen())
+    {
+      screen = SDL_SetVideoMode(RES_X, RES_Y, PIXEL_BITS, surfaceMode);
+    }
 
-  if (screen == NULL)
-  {
-    fprintf(stderr,
+    if (screen == NULL)
+    {
+      fprintf(stderr,
             "\nError: I could not open the display.\n"
 	    "The Simple DirectMedia error that occured was:\n"
 	    "%s\n\n", SDL_GetError());
-    cleanup_on_error();
-    exit(1);
-  }
+      cleanup_on_error();
+      exit(1);
+    }
 
-  seticon();
+    seticon();
 
-  SDL_WM_SetCaption("Tux, of Math Command", "TuxMath");
+    SDL_WM_SetCaption("Tux, of Math Command", "TuxMath");
+  }
 }
-}
 
 
 void load_data_files(void)

Modified: tuxmath/trunk/src/tuxmath.h
===================================================================
--- tuxmath/trunk/src/tuxmath.h	2007-10-30 18:15:55 UTC (rev 311)
+++ tuxmath/trunk/src/tuxmath.h	2007-10-31 11:21:15 UTC (rev 312)
@@ -118,7 +118,7 @@
 
 #define RES_X	640
 #define RES_Y	480
-#define BPP	32	
+#define PIXEL_BITS 32	
 
 enum { 
   CADET_HIGH_SCORE,




More information about the Tux4kids-commits mailing list