[Tux4kids-commits] r538 - in tuxmath/branches/mathcards_newarch: doc src

cheezmeister-guest at alioth.debian.org cheezmeister-guest at alioth.debian.org
Fri Jun 20 16:28:35 UTC 2008


Author: cheezmeister-guest
Date: 2008-06-20 16:28:34 +0000 (Fri, 20 Jun 2008)
New Revision: 538

Modified:
   tuxmath/branches/mathcards_newarch/doc/changelog
   tuxmath/branches/mathcards_newarch/src/highscore.c
   tuxmath/branches/mathcards_newarch/src/mathcards.c
   tuxmath/branches/mathcards_newarch/src/mathcards.h
   tuxmath/branches/mathcards_newarch/src/setup.c
   tuxmath/branches/mathcards_newarch/src/titlescreen.c
   tuxmath/branches/mathcards_newarch/src/titlescreen.h
Log:
Branch: More centralized organization of mathcards options

Modified: tuxmath/branches/mathcards_newarch/doc/changelog
===================================================================
--- tuxmath/branches/mathcards_newarch/doc/changelog	2008-06-19 17:29:04 UTC (rev 537)
+++ tuxmath/branches/mathcards_newarch/doc/changelog	2008-06-20 16:28:34 UTC (rev 538)
@@ -1,3 +1,10 @@
+2008.June.19 (svn.debian.org/tux4kids - revision 537)
+      Code:
+        Tweaked menu locations for larger screens and fixed a number of
+	issues redrawing upon returning to the menu from a game.
+
+      Brendan Luchen
+
 2008.June.14 (svn.debian.org/tux4kids - revision 521)
       Graphics:
         New 1280x1024 versions of background images (from Debian Etch at

Modified: tuxmath/branches/mathcards_newarch/src/highscore.c
===================================================================
--- tuxmath/branches/mathcards_newarch/src/highscore.c	2008-06-19 17:29:04 UTC (rev 537)
+++ tuxmath/branches/mathcards_newarch/src/highscore.c	2008-06-20 16:28:34 UTC (rev 538)
@@ -166,8 +166,8 @@
     if (diff_level != old_diff_level)
     {
       /* Draw background: */
-      if (current_bkg)
-        SDL_BlitSurface( current_bkg, NULL, screen, NULL );
+      if (current_bkg())
+        SDL_BlitSurface( current_bkg(), NULL, screen, NULL );
       /* FIXME maybe add image of trophy or similar pic */
       /* Draw Tux: */
       if (Tux && Tux->frame[0]) /* make sure sprite has at least one frame */
@@ -383,8 +383,8 @@
 
 
   /* Draw background: */
-  if (current_bkg)
-    SDL_BlitSurface(current_bkg, NULL, screen, NULL);
+  if (current_bkg())
+    SDL_BlitSurface(current_bkg(), NULL, screen, NULL);
 
   /* Red "Stop" circle in upper right corner to go back to main menu: */
   if (images[IMG_STOP])
@@ -524,7 +524,7 @@
             /* Redraw background and shading in area where we drew text last time: */ 
             if (!first_draw)
             {
-              SDL_BlitSurface(current_bkg, &redraw_rect, screen, &redraw_rect);
+              SDL_BlitSurface(current_bkg(), &redraw_rect, screen, &redraw_rect);
               DrawButton(&redraw_rect, 0, REG_RGBA);
               SDL_UpdateRect(screen,
                              redraw_rect.x,

Modified: tuxmath/branches/mathcards_newarch/src/mathcards.c
===================================================================
--- tuxmath/branches/mathcards_newarch/src/mathcards.c	2008-06-19 17:29:04 UTC (rev 537)
+++ tuxmath/branches/mathcards_newarch/src/mathcards.c	2008-06-20 16:28:34 UTC (rev 538)
@@ -3103,117 +3103,6 @@
       return i;
   printf("Sorry, don't recognize option '%s'\n", text);
   return NOT_VALID_OPTION;
-/*
-  if (!strcasecmp(text,"PLAY_THROUGH_LIST")
-    return PLAY_THROUGH_LIST;
-  if (!strcasecmp(text,"REPEAT_WRONGS")
-    return REPEAT_WRONGS;
-  if (!strcasecmp(text,"COPIES_REPEATED_WRONGS")
-    return COPIES_REPEATED_WRONGS;
-  if (!strcasecmp(text,"ALLOW_NEGATIVES")
-    return ALLOW_NEGATIVES;
-  if (!strcasecmp(text,"MAX_ANSWER")
-    return MAX_ANSWER;
-  if (!strcasecmp(text,"MAX_QUESTIONS")
-    return MAX_QUESTIONS;
-  if (!strcasecmp(text,"QUESTION_COPIES")
-    return QUESTION_COPIES;
-  if (!strcasecmp(text,"RANDOMIZE")
-    return RANDOMIZE;
-  if (!strcasecmp(text,"FRACTION_TO_KEEP")
-    return NOT_VALID_OPTION; //FRACTION_TO_KEEP is a float!
-
-
-  if (!strcasecmp(text,"FORMAT_ANSWER_LAST")
-    return  FORMAT_ANSWER_LAST;
-  if (!strcasecmp(text,"FORMAT_ANSWER_FIRST")
-    return  FORMAT_ANSWER_FIRST;
-  if (!strcasecmp(text,"FORMAT_ANSWER_MIDDLE")
-    return  FORMAT_ANSWER_MIDDLE;
-  if (!strcasecmp(text,"FORMAT_ADD_ANSWER_LAST")
-    return  FORMAT_ADD_ANSWER_LAST;
-  if (!strcasecmp(text,"FORMAT_ADD_ANSWER_FIRST")
-    return  FORMAT_ADD_ANSWER_FIRST;
-  if (!strcasecmp(text,"FORMAT_ADD_ANSWER_MIDDLE")
-    return  FORMAT_ADD_ANSWER_MIDDLE;
-  if (!strcasecmp(text,"FORMAT_SUB_ANSWER_LAST")
-    return  FORMAT_SUB_ANSWER_LAST;
-  if (!strcasecmp(text,"FORMAT_SUB_ANSWER_FIRST")
-    return  FORMAT_SUB_ANSWER_FIRST;
-  if (!strcasecmp(text,"FORMAT_SUB_ANSWER_MIDDLE")
-    return  FORMAT_SUB_ANSWER_MIDDLE;
-  if (!strcasecmp(text,"FORMAT_MULT_ANSWER_LAST")
-    return  FORMAT_MULT_ANSWER_LAST;
-  if (!strcasecmp(text,"FORMAT_MULT_ANSWER_FIRST")
-    return  FORMAT_MULT_ANSWER_FIRST;
-  if (!strcasecmp(text,"FORMAT_MULT_ANSWER_MIDDLE")
-    return  FORMAT_MULT_ANSWER_MIDDLE;
-  if (!strcasecmp(text,"FORMAT_DIV_ANSWER_LAST")
-    return  FORMAT_DIV_ANSWER_LAST;
-  if (!strcasecmp(text,"FORMAT_DIV_ANSWER_FIRST")
-    return  FORMAT_DIV_ANSWER_FIRST;
-  if (!strcasecmp(text,"FORMAT_DIV_ANSWER_MIDDLE")
-    return  FORMAT_DIV_ANSWER_MIDDLE;
-
-  if (!strcasecmp(text,"ADDITION_ALLOWED")
-    return  ADDITION_ALLOWED;
-  if (!strcasecmp(text,"SUBTRACTION_ALLOWED")
-    return  SUBTRACTION_ALLOWED;
-  if (!strcasecmp(text,"MULTIPLICATION_ALLOWED")
-    return  MULTIPLICATION_ALLOWED;
-  if (!strcasecmp(text,"DIVISION_ALLOWED")
-    return  DIVISION_ALLOWED;
-  if (!strcasecmp(text,"TYPING_PRACTICE_ALLOWED")
-    return  TYPING_PRACTICE_ALLOWED;
-
-  if (!strcasecmp(text,"MIN_AUGEND")
-    return  MIN_AUGEND;
-  if (!strcasecmp(text,"MAX_AUGEND")
-    return MAX_AUGEND;
-  if (!strcasecmp(text,"MIN_ADDEND")
-    return  MIN_ADDEND;
-  if (!strcasecmp(text,"MAX_ADDEND")
-    return  MAX_ADDEND;
-
-  if (!strcasecmp(text,"MIN_MINUEND")
-    return  MIN_MINUEND;
-  if (!strcasecmp(text,"MAX_MINUEND")
-    return  MAX_MINUEND;
-  if (!strcasecmp(text,"MIN_SUBTRAHEND")
-    return  MIN_SUBTRAHEND;
-  if (!strcasecmp(text,"MAX_SUBTRAHEND")
-    return  MAX_SUBTRAHEND;
-   
-  if (!strcasecmp(text,"MIN_MULTIPLIER")
-    return  MIN_MULTIPLIER;
-  if (!strcasecmp(text,"MAX_MULTIPLIER")
-    return  MAX_MULTIPLIER;
-  if (!strcasecmp(text,"MIN_MULTIPLICAND")
-    return  MIN_MULTIPLICAND;
-  if (!strcasecmp(text,"MAX_MULTIPLICAND")
-    return  MAX_MULTIPLICAND;
-
-  if (!strcasecmp(text,"MIN_DIVISOR")
-    return  MIN_DIVISOR;
-  if (!strcasecmp(text,"MAX_DIVISOR")
-    return  MAX_DIVISOR;
-  if (!strcasecmp(text,"MIN_QUOTIENT")
-    return  MIN_QUOTIENT;
-  if (!strcasecmp(text,"MAX_QUOTIENT")
-    return  MAX_QUOTIENT;
-
-  if (!strcasecmp(text,"MIN_TYPING_NUM")
-    return  MIN_TYPING_NUM;
-  if (!strcasecmp(text,"MAX_TYPING_NUM")
-    return  MAX_TYPING_NUM;
-    
-  if (!strcasecmp(text,"MIN_FORMULA_NUMS")
-    return  MIN_FORMULA_NUMS;
-  if (!strcasecmp(text,"MAX_FORMULA_NUMS")
-    return MAX_FORMULA_NUMS;
-    
-  return NOT_VALID_OPTION;
-*/
 }
 
 void MC_SetOpt(unsigned int index, int val)
@@ -3226,7 +3115,7 @@
   opts.iopts[index] = val;
 }
 
-void MC_SetOpt(const char* param, int val);
+void MC_SetOpt(const char* param, int val)
 {
   MC_SetOpt(MC_MapTextToIndex(param), val);
 }
@@ -3236,8 +3125,14 @@
   if (index >= NOPTS)
   {
     printf("Invalid option index: %du\n", index);
-    return 0;
+    return MC_MATH_OPTS_INVALID;
   }  
+  if (!opts)
+  {
+    printf("Invalid options list!\n");
+    return MC_MATH_OPTS_INVALID;
+  }
+  return opts->iopts[index];
 }
 
 int MC_GetOpt(const char* param)
@@ -3247,11 +3142,17 @@
 
 void MC_SetFractionToKeep(float val)
 {
-  opts.fraction_to_keep = val;
+  opts->fraction_to_keep = val;
 }
 
 float MC_GetFractionToKeep(void)
 {
-  return opts.fraction_to_keep;
+  return opts->fraction_to_keep;
 }
+
+int MC_VerifyOptionListSane(void)
+{
+  return MC_OPTION_TEXT[NOPTS] == "END_OF_OPTS";
+}
+
 #endif

Modified: tuxmath/branches/mathcards_newarch/src/mathcards.h
===================================================================
--- tuxmath/branches/mathcards_newarch/src/mathcards.h	2008-06-19 17:29:04 UTC (rev 537)
+++ tuxmath/branches/mathcards_newarch/src/mathcards.h	2008-06-20 16:28:34 UTC (rev 538)
@@ -38,6 +38,7 @@
   MC_FORMAT_ANS_MIDDLE    /* a + ? = c */
 };
 
+#ifndef MC_USE_NEWARC
 /* This struct contains all options that determine what */
 /* math questions are asked during a game */
 typedef struct MC_Options {
@@ -98,10 +99,141 @@
   int max_typing_num;
 
 } MC_Options;
+#else
+typedef struct _MC_Options 
+{
+  int iopts[NOPTS];
+  float fraction_to_keep;
+}
+#endif
 
-///* options for new mathcards architecture */
-//  int min_formula_nums;
-//  int max_formula_nums;
+/*
+Indices for the various integer options. These are NOT the actual values!
+Actual values are accessed as such: options.iopts[PLAY_THROUGH_LIST] = val;
+Creating additional [integral] options is now centralized--this should be 
+the only place where it's necessary to add code. (Besides actually using 
+the new options!)
+*/
+
+#define PLAY_THROUGH_LIST         0  
+#define REPEAT_WRONGS             1  
+#define COPIES_REPEATED_WRONGS    2  
+#define ALLOW_NEGATIVES           3  
+#define MAX_ANSWER                4  
+#define MAX_QUESTIONS             5  
+#define QUESTION_COPIES           6  /* # times each question is put in list */
+#define MAX_FORMULA_NUMS          7  
+#define MIN_FORMULA_NUMS          8  
+
+#define FORMAT_ANSWER_LAST        9                     
+#define FORMAT_ANSWER_FIRST       10 
+#define FORMAT_ANSWER_MIDDLE      11 
+#define FORMAT_ADD_ANSWER_LAST    12 /* a + b = ?    */ 
+#define FORMAT_ADD_ANSWER_FIRST   13 /* ? + b = c    */
+#define FORMAT_ADD_ANSWER_MIDDLE  14 /* a + ? = c    */
+#define FORMAT_SUB_ANSWER_LAST    15 /* a - b = ?    */ 
+#define FORMAT_SUB_ANSWER_FIRST   16 /* ? - b = c    */
+#define FORMAT_SUB_ANSWER_MIDDLE  17 /* a - ? = c    */
+#define FORMAT_MULT_ANSWER_LAST   18 /* a * b = ?    */ 
+#define FORMAT_MULT_ANSWER_FIRST  19 /* ? * b = c    */
+#define FORMAT_MULT_ANSWER_MIDDLE 20 /* a * ? = c    */
+#define FORMAT_DIV_ANSWER_LAST    21 /* a / b = ?    */ 
+#define FORMAT_DIV_ANSWER_FIRST   22 /* ? / b = c    */
+#define FORMAT_DIV_ANSWER_MIDDLE  23 /* a / ? = c    */
+
+#define ADDITION_ALLOWED          24 
+#define SUBTRACTION_ALLOWED       25 
+#define MULTIPLICATION_ALLOWED    26 
+#define DIVISION_ALLOWED          27 
+#define TYPING_PRACTICE_ALLOWED   28 
+
+#define MIN_AUGEND                29 
+#define MAX_AUGEND                30 
+#define MIN_ADDEND                31 
+#define MAX_ADDEND                32 
+
+#define MIN_MINUEND               33 /* minuend - subtrahend = difference */
+#define MAX_MINUEND               34 
+#define MIN_SUBTRAHEND            35 
+#define MAX_SUBTRAHEND            36 
+
+#define MIN_MULTIPLIER            37 
+#define MAX_MULTIPLIER            38 
+#define MIN_MULTIPLICAND          39 /* multiplier * multiplicand = product */
+#define MAX_MULTIPLICAND          40 
+
+#define MIN_DIVISOR               41 /* dividend/divisor = quotient */
+#define MAX_DIVISOR               42 
+#define MIN_QUOTIENT              43 
+#define MAX_QUOTIENT              44 
+
+#define MIN_TYPING_NUM            45 
+#define MAX_TYPING_NUM            46 
+
+#define RANDOMIZE                 47 /* whether to shuffle cards */
+
+#define NOPTS                     48 
+
+const char** MC_OPTION_TEXT = {
+"PLAY_THROUGH_LIST",
+"REPEAT_WRONGS",
+"COPIES_REPEATED_WRONGS",
+"ALLOW_NEGATIVES",
+"MAX_ANSWER",
+"MAX_QUESTIONS",
+"QUESTION_COPIES",
+"MAX_FORMULA_NUMS",
+"MIN_FORMULA_NUMS",
+
+"FORMAT_ANSWER_LAST",
+"FORMAT_ANSWER_FIRST",
+"FORMAT_ANSWER_MIDDLE",
+"FORMAT_ADD_ANSWER_LAST",
+"FORMAT_ADD_ANSWER_FIRST",
+"FORMAT_ADD_ANSWER_MIDDLE",
+"FORMAT_SUB_ANSWER_LAST",
+"FORMAT_SUB_ANSWER_FIRST",
+"FORMAT_SUB_ANSWER_MIDDLE",
+"FORMAT_MULT_ANSWER_LAST",
+"FORMAT_MULT_ANSWER_FIRST",
+"FORMAT_MULT_ANSWER_MIDDLE",
+"FORMAT_DIV_ANSWER_LAST",
+"FORMAT_DIV_ANSWER_FIRST",
+"FORMAT_DIV_ANSWER_MIDDLE",
+
+"ADDITION_ALLOWED",
+"SUBTRACTION_ALLOWED",
+"MULTIPLICATION_ALLOWED",
+"DIVISION_ALLOWED",
+"TYPING_PRACTICE_ALLOWED",
+
+"MIN_AUGEND",
+"MAX_AUGEND",
+"MIN_ADDEND",
+"MAX_ADDEND",
+
+"MIN_MINUEND",
+"MAX_MINUEND",
+"MIN_SUBTRAHEND",
+"MAX_SUBTRAHEND",
+ 
+"MIN_MULTIPLIER",
+"MAX_MULTIPLIER",
+"MIN_MULTIPLICAND",
+"MAX_MULTIPLICAND",
+
+"MIN_DIVISOR",
+"MAX_DIVISOR",
+"MIN_QUOTIENT",
+"MAX_QUOTIENT",
+
+"MIN_TYPING_NUM",
+"MAX_TYPING_NUM",
+
+"RANDOMIZE",
+
+"END_OF_OPTS"
+};
   
 /* default values for math_options */
 #define MC_GLOBAL_MAX 999                 /* this is the largest absolute value that */
@@ -165,6 +297,7 @@
 #define DEFAULT_MAX_TYPING_NUM 12          /* just learning to use keyboard.          */
 
 
+#ifndef MC_USE_NEWARC
 /* struct for individual "flashcard" */
 typedef struct MC_FlashCard {
   int num1;
@@ -175,15 +308,15 @@
   char formula_string[MC_FORMULA_LEN];
   char answer_string[MC_ANSWER_LEN];
 } MC_FlashCard;
-
+#else
 /* experimental struct for a more generalized flashcard */
 typedef struct _MC_Flashcard {
   char* formula_string;
   char* answer_string;
   int answer;
 } MC_Flashcard;
+#endif
 
-
 /* struct for node in math "flashcard" list */
 typedef struct MC_MathQuestion {
   MC_FlashCard card;
@@ -427,8 +560,14 @@
 int MC_TypeMax(void);
 
 /* public functions for experimental mathcards architecture */
-void MC_SetMinFormulaNums(int opt);
-void MC_SetMaxFormulaNums(int opt);
-int MC_MinFormulaNums(void);
-int MC_MaxFormulaNums(void);
+MC_Flashcard MC_CreateFlashcard(void);
+void MC_FreeFlashcard(MC_Flashcard* fc);
+unsigned int MC_MapTextToIndex(const char* text);
+void MC_SetOpt(unsigned int index, int val);
+void MC_SetOpt(const char* param, int val);
+int MC_GetOpt(unsigned int index);
+int MC_GetOpt(const char* param);
+void MC_SetFractionToKeep(float val);
+float MC_GetFractionToKeep(void);
+int MC_VerifyOptionListSane(void);
 #endif

Modified: tuxmath/branches/mathcards_newarch/src/setup.c
===================================================================
--- tuxmath/branches/mathcards_newarch/src/setup.c	2008-06-19 17:29:04 UTC (rev 537)
+++ tuxmath/branches/mathcards_newarch/src/setup.c	2008-06-20 16:28:34 UTC (rev 538)
@@ -510,15 +510,11 @@
       tmdprintf("SW mode\n");
     }
 
-    //determine the best fullscreen resolution
-    int i;
-    SDL_Rect** modes = SDL_ListModes(videoInfo->vfmt, SDL_FULLSCREEN | surfaceMode);
-    if (modes != (SDL_Rect**)0 && modes != (SDL_Rect**)-1) //if there is a "best" resolution
-      {
-      fs_res_x = modes[0]->w;
-      fs_res_y = modes[0]->h;
-      tmdprintf("Optimal resolution is %dx%d\n", fs_res_x, fs_res_y);
-      }
+    // Determine the current resolution: this will be used as the
+    // fullscreen resolution, if the user wants fullscreen.
+    tmdprintf("Current resolution: w %d, h %d.\n",videoInfo->current_w,videoInfo->current_h);
+    fs_res_x = videoInfo->current_w;
+    fs_res_y = videoInfo->current_h;
 
     if (Opts_Fullscreen())
     {

Modified: tuxmath/branches/mathcards_newarch/src/titlescreen.c
===================================================================
--- tuxmath/branches/mathcards_newarch/src/titlescreen.c	2008-06-19 17:29:04 UTC (rev 537)
+++ tuxmath/branches/mathcards_newarch/src/titlescreen.c	2008-06-20 16:28:34 UTC (rev 538)
@@ -127,12 +127,13 @@
 SDL_Surface* bkg = NULL;
 /* The background image scaled to fullscreen dimensions */
 SDL_Surface* scaled_bkg = NULL;
-/* Set to bkg if windowed, scaled_bkgd if fullscreen. */
-SDL_Surface* current_bkg = NULL; //DON'T SDL_Free()!
 /* "Easter Egg" cursor */
 SDL_Surface* egg = NULL; 
 int egg_active = 0; //are we currently using the egg cursor?
 
+SDL_Surface* current_bkg()
+  { return screen->flags & SDL_FULLSCREEN ? scaled_bkg : bkg; }
+  
 /* Local function prototypes: */
 void TitleScreen_load_menu(void);
 void TitleScreen_unload_menu(void);
@@ -254,22 +255,18 @@
     return;
   }
 
-  if (screen->flags & SDL_FULLSCREEN)
-    current_bkg = scaled_bkg;
-  else
-    current_bkg = bkg;
   /* Draw background, if it loaded OK: */
-  if (current_bkg)
+  if (current_bkg() )
   {
-    Backrect.x = (screen->w - current_bkg->w) / 2;
-    Backrect.y = (screen->h - current_bkg->h) / 2;
-    Backrect.w = current_bkg->w;
-    Backrect.h = current_bkg->h;
+    Backrect.x = (screen->w - current_bkg()->w) / 2;
+    Backrect.y = (screen->h - current_bkg()->h) / 2;
+    Backrect.w = current_bkg()->w;
+    Backrect.h = current_bkg()->h;
     /* FIXME not sure TransWipe() works in Windows: */
-    TransWipe(current_bkg, RANDOM_WIPE, 10, 20);
+    TransWipe(current_bkg(), RANDOM_WIPE, 10, 20);
     /* Make sure background gets drawn (since TransWipe() doesn't */
     /* seem to work reliably as of yet):                          */
-    SDL_BlitSurface(current_bkg, NULL, screen, &Backrect);
+    SDL_BlitSurface(current_bkg(), NULL, screen, &Backrect);
 
   }
   /* Red "Stop" circle in upper right corner to go back to main menu: */
@@ -286,7 +283,7 @@
   /* --- Pull tux & logo onscreen --- */
   /* NOTE we wind up with Tuxdest.y == (screen->h)  - (Tux->frame[0]->h), */
   /* and Titledest.x == 0.                                                */
-  if (current_bkg
+  if (current_bkg()
    && images[IMG_MENU_TITLE]
    && images[IMG_STOP]
    && Tux && Tux->frame[0])
@@ -319,9 +316,9 @@
       start = SDL_GetTicks();
 
       //Draw the entire background, over a black screen if necessary
-      if (current_bkg->w != screen->w || current_bkg->h != screen->h)
+      if (current_bkg()->w != screen->w || current_bkg()->h != screen->h)
         SDL_FillRect(screen, &screen->clip_rect, 0);
-      SDL_BlitSurface(current_bkg, NULL, screen, &Backrect);
+      SDL_BlitSurface(current_bkg(), NULL, screen, &Backrect);
 
       Tuxdest.y -= TuxPixSkip;
       //Tuxback.y -= Tux->frame[0]->h / (PRE_ANIM_FRAMES * PRE_FRAME_MULT);
@@ -515,8 +512,8 @@
 #endif
 
   /* Redraw background: */
-  if (current_bkg)
-    SDL_BlitSurface( current_bkg, NULL, screen, &Backrect );
+  if (current_bkg() )
+    SDL_BlitSurface( current_bkg(), NULL, screen, &Backrect );
 
   /* Red "Stop" circle in upper right corner to go back to main menu: */
   if (images[IMG_STOP])
@@ -684,6 +681,7 @@
 	if (Opts_MenuMusic())  //Turn menu music off for game
 	  {audioMusicUnload();}
 	game();
+	RecalcTitlePositions();
 	if (Opts_MenuMusic()) //Turn menu music back on
 	  {audioMusicLoad( "tuxi.ogg", -1 );}
 	Opts_SetHelpMode(0);
@@ -806,6 +804,7 @@
       audioMusicUnload();
 
     game();
+    RecalcTitlePositions();
     write_user_config_file();
 
     if (Opts_MenuMusic())
@@ -866,6 +865,7 @@
       {
 	audioMusicUnload();
 	game();
+	RecalcTitlePositions();
 	if (Opts_MenuMusic()) {
 	  audioMusicLoad( "tuxi.ogg", -1 );
 	}
@@ -1323,8 +1323,8 @@
   }
 
   /**** Draw background, title, and Tux:                            ****/
-  if (current_bkg)
-    SDL_BlitSurface(current_bkg, NULL, screen, &Backrect);
+  if (current_bkg() )
+    SDL_BlitSurface(current_bkg(), NULL, screen, &Backrect);
   if (images[IMG_MENU_TITLE])
     SDL_BlitSurface(images[IMG_MENU_TITLE], NULL, screen, &Titledest);
   if (Tux && Tux->frame[0])
@@ -1627,10 +1627,10 @@
       tmdprintf("Updating entire screen\n");
       /* This is a full-screen redraw */
       /* Redraw background, title, stop button, and Tux: */
-      if (!current_bkg || screen->flags & SDL_FULLSCREEN )
+      if (!current_bkg() || screen->flags & SDL_FULLSCREEN )
         SDL_FillRect(screen, &screen->clip_rect, 0); //clear to black
-      if (current_bkg)
-        SDL_BlitSurface(current_bkg, NULL, screen, &Backrect);
+      if (current_bkg())
+        SDL_BlitSurface(current_bkg(), NULL, screen, &Backrect);
       if (images[IMG_MENU_TITLE])
         SDL_BlitSurface(images[IMG_MENU_TITLE], NULL, screen, &Titledest);
       if (images[IMG_STOP])
@@ -1698,11 +1698,11 @@
 	use_sprite = (menu_sprites != NULL && old_loc >= title_offset && menu_sprites[old_loc-title_offset] != NULL);
         temp_rect = menu_button_rect[imod];
         SDL_FillRect(screen, &temp_rect, 0);
-	SDL_BlitSurface(current_bkg, &back_button_rect[imod], screen, &temp_rect);   // redraw background
+	SDL_BlitSurface(current_bkg(), &back_button_rect[imod], screen, &temp_rect);   // redraw background
 	if (use_sprite) {
 	  // Some of the sprites extend beyond the menu button, so we
 	  // have to make sure we redraw in the sprite rects, too
-	  SDL_BlitSurface(current_bkg, &back_sprite_rect[imod], screen, &temp_rect);
+	  SDL_BlitSurface(current_bkg(), &back_sprite_rect[imod], screen, &temp_rect);
 	}
 	DrawButton(&menu_button_rect[imod], 10, REG_RGBA);  // draw button
 	//temp_rect = menu_text_rect[imod];
@@ -1745,7 +1745,7 @@
 	imod = loc-loc_screen_start;
 	//SDL_BlitSurface(current_bkg, &menu_button_rect[imod], screen, &menu_button_rect[imod]);
 	temp_rect = menu_sprite_rect[imod];
-	SDL_BlitSurface(current_bkg, &back_sprite_rect[imod], screen, &temp_rect);
+	SDL_BlitSurface(current_bkg(), &back_sprite_rect[imod], screen, &temp_rect);
 	DrawButton(&menu_button_rect[imod], 10, SEL_RGBA);
 	//SDL_BlitSurface(menu_item_selected[loc], NULL, screen, &menu_text_rect[imod]);
 	// Note: even though the whole button was redrawn, we don't
@@ -1790,7 +1790,7 @@
     if (Tux && tux_frame)
     {
       /* Redraw background to keep edges anti-aliased properly: */
-      SDL_BlitSurface(current_bkg,&Tuxdest, screen, &Tuxdest);
+      SDL_BlitSurface(current_bkg(),&Tuxdest, screen, &Tuxdest);
       SDL_BlitSurface(Tux->frame[tux_frame - 1], NULL, screen, &Tuxdest);
       SDL_UpdateRect(screen, Tuxdest.x, Tuxdest.y, Tuxdest.w, Tuxdest.h);
       //SDL_UpdateRect(screen, 0, 0, 0, 0);
@@ -2125,8 +2125,8 @@
 void set_default_menu_options(menu_options *menu_opts)
 {
   menu_opts->starting_entry = 0;
-  menu_opts->xleft = screen->w / 2 - 60;
-  menu_opts->ytop = (screen->h - current_bkg->h) / 2 + 100;
+  menu_opts->xleft = screen->w / 2 - screen->w * 3 / 32;
+  menu_opts->ytop = screen->h / 2 - 140;
   // Leave room for arrows at the bottom:
   menu_opts->ybottom = screen->h - images[IMG_LEFT]->h - 20;
   menu_opts->buttonheight = -1;
@@ -2139,11 +2139,7 @@
 /* Recalculate on-screen locations for title screen elements */
 void RecalcTitlePositions()
 {
-  if (screen->flags & SDL_FULLSCREEN)
-    current_bkg = scaled_bkg;
-  else
-    current_bkg = bkg;
-  Backrect = current_bkg->clip_rect;
+  Backrect = current_bkg()->clip_rect;
   Backrect.x = (screen->w - Backrect.w) / 2;
   Backrect.y = (screen->h - Backrect.h) / 2;
   
@@ -2312,7 +2308,7 @@
       {
       SDL_ShowCursor(SDL_ENABLE);
       //SDL_FillRect(screen, &cursor, 0);
-      SDL_BlitSurface(current_bkg, NULL, screen, &Backrect); //cover egg up once more
+      SDL_BlitSurface(current_bkg(), NULL, screen, &Backrect); //cover egg up once more
       SDL_WarpMouse(cursor.x, cursor.y);
       SDL_UpdateRect(screen, cursor.x, cursor.y, cursor.w, cursor.h); //egg->x, egg->y, egg->w, egg->h);
       egg_active = 0;

Modified: tuxmath/branches/mathcards_newarch/src/titlescreen.h
===================================================================
--- tuxmath/branches/mathcards_newarch/src/titlescreen.h	2008-06-19 17:29:04 UTC (rev 537)
+++ tuxmath/branches/mathcards_newarch/src/titlescreen.h	2008-06-20 16:28:34 UTC (rev 538)
@@ -113,7 +113,7 @@
 //extern TTF_Font  *font;
 extern SDL_Event  event;
 
-extern SDL_Surface *current_bkg;
+SDL_Surface* current_bkg(); //appropriate background for current video mode
 
 #define MUSIC_FADE_OUT_MS	80
 
@@ -163,7 +163,7 @@
 
 /* in loaders.c (from tuxtype): */
 int         checkFile( const char *file );
-TTF_Font* LoadFont(const unsigned char* font_name, int font_size);
+TTF_Font*    LoadFont(const unsigned char* font_name, int font_size);
 Mix_Chunk   *LoadSound( char* datafile );
 SDL_Surface *LoadImage( char* datafile, int mode );
 SDL_Surface* LoadBkgd(char* datafile);




More information about the Tux4kids-commits mailing list