[Tux4kids-commits] r872 - in tuxmath/trunk: doc src

tholy-guest at alioth.debian.org tholy-guest at alioth.debian.org
Fri Feb 6 18:15:28 UTC 2009


Author: tholy-guest
Date: 2009-02-06 18:15:27 +0000 (Fri, 06 Feb 2009)
New Revision: 872

Modified:
   tuxmath/trunk/doc/changelog
   tuxmath/trunk/src/SDL_extras.c
   tuxmath/trunk/src/SDL_extras.h
   tuxmath/trunk/src/campaign.h
   tuxmath/trunk/src/fileops_media.c
   tuxmath/trunk/src/game.c
   tuxmath/trunk/src/setup.c
   tuxmath/trunk/src/titlescreen.c
   tuxmath/trunk/src/tuxmath.h
Log:
Allow "SCORE" and "WAVE" to be translated, if you build with
-DREPLACE_WAVESCORE.  (Disabled by default.)


Modified: tuxmath/trunk/doc/changelog
===================================================================
--- tuxmath/trunk/doc/changelog	2009-02-06 17:36:45 UTC (rev 871)
+++ tuxmath/trunk/doc/changelog	2009-02-06 18:15:27 UTC (rev 872)
@@ -1,3 +1,10 @@
+2009.Feb.06 (svn.debian.org/tux4kids - revision 872)
+        Add the facility to use translatable versions of "SCORE" and
+	"WAVE".  To enable, define REPLACE_WAVESCORE upon compliation
+	(disabled by default, because they don't look as nice).
+
+	Tim Holy <holy at wustl.edu>
+	
 2009.Feb.06 (svn.debian.org/tux4kids - revision 871)
 	Moved linewrapping source files into main src directory and
 	adjusted autotools files accordingly. Note - plan to combine most of

Modified: tuxmath/trunk/src/SDL_extras.c
===================================================================
--- tuxmath/trunk/src/SDL_extras.c	2009-02-06 17:36:45 UTC (rev 871)
+++ tuxmath/trunk/src/SDL_extras.c	2009-02-06 18:15:27 UTC (rev 872)
@@ -476,28 +476,72 @@
 SDL_Surface* SimpleText(const char *t, TTF_Font* font, SDL_Color* col)
 {
   SDL_Surface* surf = NULL;
+  int using_pango = 0;
 
 #ifdef HAVE_LIBSDL_PANGO
+  using_pango = (context != NULL);
+#endif
+
+  if (using_pango) {
+#ifdef HAVE_LIBSDL_PANGO
   SDLPango_Matrix colormatrix = {
     col->r,  col->r,  0,  0,
     col->g,  col->g,  0,  0,
     col->b,  col->b,  0,  0,
     0,      255,      0,  0,
   };
-
-  if(context != NULL)
-  {
-    SDLPango_SetDefaultColor(context, &colormatrix );
-    SDLPango_SetText(context, t, -1);
-    surf = SDLPango_CreateSurfaceDraw(context);
+  SDLPango_SetDefaultColor(context, &colormatrix );
+  SDLPango_SetText(context, t, -1);
+  surf = SDLPango_CreateSurfaceDraw(context);
+#endif
   }
   else {
     surf = TTF_RenderUTF8_Blended(font, t, *col);
   }
-#else
-  surf = TTF_RenderUTF8_Blended(font, t, *col);
+
+  return surf;
+}
+
+
+/* This (fast) function just returns a non-outlined surf */
+/* using SDL_Pango if available, SDL_ttf as fallback     */
+SDL_Surface* SimpleTextWithOffset(const char *t, TTF_Font* font, SDL_Color* col, int *glyph_offset)
+{
+  SDL_Surface* surf = NULL;
+  int using_pango = 0;
+
+#ifdef HAVE_LIBSDL_PANGO
+  using_pango = (context != NULL);
 #endif
 
+  if (using_pango) {
+#ifdef HAVE_LIBSDL_PANGO
+  SDLPango_Matrix colormatrix = {
+    col->r,  col->r,  0,  0,
+    col->g,  col->g,  0,  0,
+    col->b,  col->b,  0,  0,
+    0,      255,      0,  0,
+  };
+  SDLPango_SetDefaultColor(context, &colormatrix );
+  SDLPango_SetText(context, t, -1);
+  surf = SDLPango_CreateSurfaceDraw(context);
+  *glyph_offset = 0; // fixme?
+#endif
+  }
+  else {
+    surf = TTF_RenderUTF8_Blended(font, t, *col);
+    int h;
+    int hmax = 0;
+    int len = strlen(t);
+    int i;
+    for (i = 0; i < len; i++) {
+      TTF_GlyphMetrics(font, t[i], NULL, NULL, NULL, &h, NULL);
+      if (h > hmax)
+	hmax = h;
+    }
+    *glyph_offset = hmax - TTF_FontAscent(font);
+  }
+
   return surf;
 }
 

Modified: tuxmath/trunk/src/SDL_extras.h
===================================================================
--- tuxmath/trunk/src/SDL_extras.h	2009-02-06 17:36:45 UTC (rev 871)
+++ tuxmath/trunk/src/SDL_extras.h	2009-02-06 18:15:27 UTC (rev 872)
@@ -39,6 +39,7 @@
 SDL_Surface* Flip(SDL_Surface *in, int x, int y);
 SDL_Surface* BlackOutline(const char *t, TTF_Font* font, SDL_Color* c);
 SDL_Surface* SimpleText(const char *t, TTF_Font* font, SDL_Color* col);
+SDL_Surface* SimpleTextWithOffset(const char *t, TTF_Font* font, SDL_Color* col, int *glyph_offset);
 int  inRect(SDL_Rect r, int x, int y);
 void DarkenScreen(Uint8 bits);
 void SwitchScreenMode(void);

Modified: tuxmath/trunk/src/campaign.h
===================================================================
--- tuxmath/trunk/src/campaign.h	2009-02-06 17:36:45 UTC (rev 871)
+++ tuxmath/trunk/src/campaign.h	2009-02-06 18:15:27 UTC (rev 872)
@@ -18,6 +18,11 @@
 
 /* NOTE this has to be static to be in a header file or it will cause */
 /* multiple definition errors if included in more than one file.      */
+
+/* NOTE: the convention has changed. Use " " for a blank line (note
+   the space), and use "" (rather than NULL) for the termination
+   string. This is a consequence of the linewrapping code.  TEH Feb
+   2009. */
 static const char* briefings[NUM_STAGES][20] = {
   //cadet
   {

Modified: tuxmath/trunk/src/fileops_media.c
===================================================================
--- tuxmath/trunk/src/fileops_media.c	2009-02-06 17:36:45 UTC (rev 871)
+++ tuxmath/trunk/src/fileops_media.c	2009-02-06 18:15:27 UTC (rev 872)
@@ -2,11 +2,12 @@
 #include "fileops.h"
 #include "loaders.h"
 #include "options.h"
+#include "SDL_extras.h"
 
 TTF_Font  *default_font;
 TTF_Font  *help_font;
+int glyph_offset;
 
-
 /*****************************************************************/
 /*   Loading of data files for images and sounds.                */
 /*   These functions also draw some user feedback to             */
@@ -178,6 +179,21 @@
       return 0;
     }
   }
+
+  glyph_offset = 0;
+
+#ifdef REPLACE_WAVESCORE  
+  /* Replace the "WAVE" and "SCORE" with translate-able versions */
+  TTF_Font *wavescore_font;
+  wavescore_font = LoadFont(DEFAULT_FONT_NAME, 28);
+  SDL_FreeSurface(images[IMG_WAVE]);
+  images[IMG_WAVE] = SimpleTextWithOffset(_("WAVE"), wavescore_font, &white, &glyph_offset);
+  SDL_FreeSurface(images[IMG_SCORE]);
+  images[IMG_SCORE] = SimpleTextWithOffset(_("SCORE"), wavescore_font, &white, &glyph_offset);
+  glyph_offset++;
+  TTF_CloseFont(wavescore_font);
+#endif
+
   /* If we make it to here OK, return 1: */
   return 1;
 }

Modified: tuxmath/trunk/src/game.c
===================================================================
--- tuxmath/trunk/src/game.c	2009-02-06 17:36:45 UTC (rev 871)
+++ tuxmath/trunk/src/game.c	2009-02-06 18:15:27 UTC (rev 872)
@@ -2166,7 +2166,7 @@
     offset = 0;
 
   dest.x = offset;
-  dest.y = 0;
+  dest.y = glyph_offset;
   dest.w = images[IMG_WAVE]->w;
   dest.h = images[IMG_WAVE]->h;
 
@@ -2181,7 +2181,7 @@
     dest.x = (screen->w - ((images[IMG_NUMBERS]->w / 10) * 7) -
                   images[IMG_SCORE]->w -
                   images[IMG_STOP]->w - 5);
-    dest.y = 0;
+    dest.y = glyph_offset;
     dest.w = images[IMG_SCORE]->w;
     dest.h = images[IMG_SCORE]->h;
     SDL_BlitSurface(images[IMG_SCORE], NULL, screen, &dest);

Modified: tuxmath/trunk/src/setup.c
===================================================================
--- tuxmath/trunk/src/setup.c	2009-02-06 17:36:45 UTC (rev 871)
+++ tuxmath/trunk/src/setup.c	2009-02-06 18:15:27 UTC (rev 872)
@@ -557,18 +557,21 @@
 
     SDL_WM_SetCaption("Tux, of Math Command", "TuxMath");
   }
+
+  /* --- Define the colors we use --- */
+  /* This was moved here because of wanting to replace some images
+     with fonts during setup */
+  black.r       = 0x00; black.g       = 0x00; black.b       = 0x00;
+  gray.r        = 0x80; gray.g        = 0x80; gray.b        = 0x80;
+  dark_blue.r   = 0x00; dark_blue.g   = 0x00; dark_blue.b   = 0x60;
+  red.r         = 0xff; red.g         = 0x00; red.b         = 0x00;
+  white.r       = 0xff; white.g       = 0xff; white.b       = 0xff;
+  yellow.r      = 0xff; yellow.g      = 0xff; yellow.b      = 0x00;
 }
 
 
 void load_data_files(void)
 {
-  if (!load_image_data())
-  {
-    fprintf(stderr, "\nCould not load image file - exiting!\n");
-    cleanup_on_error();
-    exit(1);
-  }
-
   if (!load_sound_data())
   {
     fprintf(stderr, "\nCould not load sound file - attempting to proceed without sound.\n");
@@ -581,6 +584,15 @@
     cleanup_on_error();
     exit(1);
   }
+   
+  /* This now has to come after loading the font, because it replaces
+     a couple of images with translatable versions. */
+  if (!load_image_data())
+  {
+    fprintf(stderr, "\nCould not load image file - exiting!\n");
+    cleanup_on_error();
+    exit(1);
+  }
 }
 
 

Modified: tuxmath/trunk/src/titlescreen.c
===================================================================
--- tuxmath/trunk/src/titlescreen.c	2009-02-06 17:36:45 UTC (rev 871)
+++ tuxmath/trunk/src/titlescreen.c	2009-02-06 18:15:27 UTC (rev 872)
@@ -223,16 +223,6 @@
 
   InitEngine();  //set up pointers for blitting structure.
 
-
-  /* --- setup colors we use --- */
-  black.r       = 0x00; black.g       = 0x00; black.b       = 0x00;
-  gray.r        = 0x80; gray.g        = 0x80; gray.b        = 0x80;
-  dark_blue.r   = 0x00; dark_blue.g   = 0x00; dark_blue.b   = 0x60;
-  red.r         = 0xff; red.g         = 0x00; red.b         = 0x00;
-  white.r       = 0xff; white.g       = 0xff; white.b       = 0xff;
-  yellow.r      = 0xff; yellow.g      = 0xff; yellow.b      = 0x00;
-
-
   start = SDL_GetTicks();
 
 

Modified: tuxmath/trunk/src/tuxmath.h
===================================================================
--- tuxmath/trunk/src/tuxmath.h	2009-02-06 17:36:45 UTC (rev 871)
+++ tuxmath/trunk/src/tuxmath.h	2009-02-06 18:15:27 UTC (rev 872)
@@ -68,6 +68,7 @@
 
 extern TTF_Font  *default_font;
 extern TTF_Font  *help_font;
+extern int glyph_offset;
 
 
 #ifndef NOSOUND




More information about the Tux4kids-commits mailing list