[Tux4kids-commits] r927 - tuxtype/trunk/src

dbruce-guest at alioth.debian.org dbruce-guest at alioth.debian.org
Thu Mar 5 20:16:07 UTC 2009


Author: dbruce-guest
Date: 2009-03-05 20:16:07 +0000 (Thu, 05 Mar 2009)
New Revision: 927

Modified:
   tuxtype/trunk/src/SDL_extras.c
   tuxtype/trunk/src/SDL_extras.h
   tuxtype/trunk/src/globals.h
   tuxtype/trunk/src/main.c
   tuxtype/trunk/src/practice.c
   tuxtype/trunk/src/setup.c
Log:
use correct font when locale changes



Modified: tuxtype/trunk/src/SDL_extras.c
===================================================================
--- tuxtype/trunk/src/SDL_extras.c	2009-03-05 13:21:28 UTC (rev 926)
+++ tuxtype/trunk/src/SDL_extras.c	2009-03-05 20:16:07 UTC (rev 927)
@@ -590,8 +590,8 @@
 /*-- file-scope variables and local file prototypes for SDL_Pango-based code: */
 #ifdef HAVE_LIBSDL_PANGO
 #include "SDL_Pango.h"
+
 SDLPango_Context* context = NULL;
-static int current_pango_font_size = 0;
 static SDLPango_Matrix* SDL_Colour_to_SDLPango_Matrix(const SDL_Color* cl);
 static int Set_SDL_Pango_Font_Size(int size);
 /*-- file-scope variables and local file prototypes for SDL_ttf-based code: */
@@ -874,15 +874,20 @@
 
 #ifdef HAVE_LIBSDL_PANGO
 
-/* Local functions when using SDL_Pango: -------------------------------   */
+/* Local functions when using SDL_Pango: -------------------------------      */
 
-/* FIXME the '0.7' a few lines down is to compensate for the larger font size   */
-/* that SDL_Pango generates relative to a TTF_Font of the same numerical size - */
-/* this was picked by trial and error, ought to understand this better - DSB    */
+/* NOTE the scaling by 3/4 a few lines down represents a conversion from      */
+/* the usual text dpi of 72 to the typical screen dpi of 96. It gives         */
+/* font sizes fairly similar to a SDL_ttf font with the same numerical value. */
 static int Set_SDL_Pango_Font_Size(int size)
 {
-  /* Do nothing unless we need to change size: */
-  if (size == current_pango_font_size)
+  /* static so we can "remember" values from previous time through: */
+  static int prev_pango_font_size;
+  static char prev_font_name[FNLEN];
+  /* Do nothing unless we need to change size or font: */
+  if ((size == prev_pango_font_size)
+      &&
+      (0 == strncmp(prev_font_name, settings.theme_font_name, sizeof(prev_font_name))))
     return 1;
   else
   {
@@ -891,7 +896,7 @@
     if(context != NULL)
       SDLPango_FreeContext(context);
     context = NULL;
-    snprintf(buf, sizeof(buf), "%s %d", DEFAULT_FONT_NAME, (int)(size * 0.7));
+    snprintf(buf, sizeof(buf), "%s %d", settings.theme_font_name, (int)((size * 3)/4));
     context =  SDLPango_CreateContext_GivenFontDesc(buf);
   }
 
@@ -899,7 +904,8 @@
     return 0;
   else
   {
-    current_pango_font_size = size;
+    prev_pango_font_size = size;
+    strncpy(prev_font_name, settings.theme_font_name, sizeof(prev_font_name));
     return 1;
   }
 }
@@ -950,14 +956,13 @@
 
 
 
-/* FIXME - could combine this with load_font() below, also we */
-/* will want to support a "current_font" setting rather than  */
-/* always using DEFAULT_FONT_NAME                             */
 /* Loads and caches fonts in each size as they are requested: */
 /* We use the font size as an array index, keeping each size  */
 /* font in memory once loaded until cleanup.                  */
 static TTF_Font* get_font(int size)
 {
+  static char prev_font_name[FNLEN];
+
   if (size < 0)
   {
     fprintf(stderr, "Error - requested font size %d is negative\n", size);
@@ -971,8 +976,16 @@
     size = MAX_FONT_SIZE;
   }
 
+  /* If the font has changed, we need to wipe out the old ones: */
+  if (0 != strncmp(prev_font_name, settings.theme_font_name, FNLEN))
+  {
+    free_font_list();
+    strncpy(prev_font_name, settings.theme_font_name, sizeof(prev_font_name));
+  }
+
+  /* If we can't load the font, this will return NULL: */
   if(font_list[size] == NULL)
-    font_list[size] = load_font(DEFAULT_FONT_NAME, size);
+    font_list[size] = load_font(settings.theme_font_name, size);
   return font_list[size];
 }
 

Modified: tuxtype/trunk/src/SDL_extras.h
===================================================================
--- tuxtype/trunk/src/SDL_extras.h	2009-03-05 13:21:28 UTC (rev 926)
+++ tuxtype/trunk/src/SDL_extras.h	2009-03-05 20:16:07 UTC (rev 927)
@@ -31,11 +31,19 @@
 #define amask 0xff000000
 #endif
 
+/* the colors we use throughout the game */
+static const SDL_Color black 		= {0x00, 0x00, 0x00, 0x00};
+static const SDL_Color gray 		= {0x80, 0x80, 0x80, 0x00};
+static const SDL_Color dark_blue	= {0x00, 0x00, 0x60, 0x00};
+static const SDL_Color red 		= {0xff, 0x00, 0x00, 0x00};
+static const SDL_Color white 		= {0xff, 0xff, 0xff, 0x00};
+static const SDL_Color yellow 		= {0xff, 0xff, 0x00, 0x00};
+
+
 /* "Public" function prototypes: */
 void DrawButton(SDL_Rect* target_rect, int radius, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
 void RoundCorners(SDL_Surface* s, Uint16 radius);
 SDL_Surface* Flip(SDL_Surface *in, int x, int y);
-
 int  inRect(SDL_Rect r, int x, int y);
 void DarkenScreen(Uint8 bits);
 void SwitchScreenMode(void);

Modified: tuxtype/trunk/src/globals.h
===================================================================
--- tuxtype/trunk/src/globals.h	2009-03-05 13:21:28 UTC (rev 926)
+++ tuxtype/trunk/src/globals.h	2009-03-05 20:16:07 UTC (rev 927)
@@ -219,21 +219,14 @@
 extern int fs_res_x;
 extern int fs_res_y;
 
-//extern TTF_Font* font;
 extern SDL_Event  event;
 
-extern SDL_Color black;
-extern SDL_Color gray;
-extern SDL_Color dark_blue;
-extern SDL_Color red;
-extern SDL_Color white;
-extern SDL_Color yellow;
 
-extern SDL_Surface* letters[255]; /* Will be going away */
+//extern SDL_Surface* letters[255]; /* Will be going away */
 
 /* These need some work to support Unicode & i18n: */
-extern wchar_t ALPHABET[256];
-extern int ALPHABET_SIZE;
+//extern wchar_t ALPHABET[256];
+//extern int ALPHABET_SIZE;
 
 
 enum {

Modified: tuxtype/trunk/src/main.c
===================================================================
--- tuxtype/trunk/src/main.c	2009-03-05 13:21:28 UTC (rev 926)
+++ tuxtype/trunk/src/main.c	2009-03-05 20:16:07 UTC (rev 927)
@@ -23,15 +23,9 @@
 SDL_Surface* screen;
 SDL_Event  event;
 
-/* the colors we use throughout the game */
-SDL_Color black;
-SDL_Color gray;
-SDL_Color dark_blue;
-SDL_Color red;
-SDL_Color white;
-SDL_Color yellow;
 
 
+
 /********************
   main : init stuff
 *********************/

Modified: tuxtype/trunk/src/practice.c
===================================================================
--- tuxtype/trunk/src/practice.c	2009-03-05 13:21:28 UTC (rev 926)
+++ tuxtype/trunk/src/practice.c	2009-03-05 20:16:07 UTC (rev 927)
@@ -100,6 +100,7 @@
 static int find_next_wrap(const wchar_t* wstr, int font_size, int width);
 static void recalc_positions(void);
 static void calc_font_sizes(void);
+static int create_labels(void);
 static void display_next_letter(wchar_t* str, Uint16 index);
 static int practice_load_media(void);
 static void practice_unload_media(void);
@@ -402,6 +403,7 @@
           case  SDLK_F10:
             SwitchScreenMode();
             recalc_positions();
+            create_labels();
             state = 1;
             break;
 
@@ -850,6 +852,7 @@
   int i;	
   char fn[FNLEN];
   int load_failed = 0;
+  int labels_ok = 0;
 
   DEBUGCODE { printf("Entering practice_load_media\n"); }
 
@@ -881,12 +884,7 @@
   calc_font_sizes();
 
   /* create labels: */
-  time_label_srfc = BlackOutline(_("Time"), fontsize, &yellow);
-  chars_label_srfc = BlackOutline(_("Chars"), fontsize, &yellow);
-  cpm_label_srfc = BlackOutline(_("CPM"), fontsize, &yellow);
-  wpm_label_srfc = BlackOutline(_("WPM"), fontsize, &yellow);
-  errors_label_srfc = BlackOutline(_("Errors"), fontsize, &yellow);
-  accuracy_label_srfc = BlackOutline(_("Accuracy"), fontsize, &yellow);
+  labels_ok = create_labels();
 
   /* Get out if anything failed to load (except sounds): */
   if (load_failed
@@ -898,12 +896,7 @@
     ||!hand_shift[0]
     ||!hand_shift[1]
     ||!hand_shift[2]
-    ||!time_label_srfc
-    ||!chars_label_srfc
-    ||!cpm_label_srfc
-    ||!wpm_label_srfc
-    ||!errors_label_srfc
-    ||!accuracy_label_srfc)
+    ||!labels_ok)
   {
     fprintf(stderr, "practice_load_media() - failed to load needed media \n");
     print_load_results();
@@ -962,8 +955,15 @@
 
 static void recalc_positions(void)
 {
-  int text_height = fontsize * 1.5;
+  int text_height;
+  calc_font_sizes();
+  text_height = fontsize * 1.5;
 
+  DEBUGCODE
+  {
+    fprintf(stderr, "Entering recalc_positions(), screen is %d x %d\n", screen->w, screen->h); 
+  }
+
   if (!keyboard
     ||!tux_win
     ||!tux_win->frame[0]
@@ -1425,3 +1425,40 @@
 	GetKeyShift(index, buf);
 	return (LoadImage(buf, IMG_ALPHA));
 }
+
+static int create_labels(void)
+{
+  if (time_label_srfc)
+    SDL_FreeSurface(time_label_srfc); 
+  time_label_srfc = BlackOutline(_("Time"), fontsize, &yellow);
+
+  if (chars_label_srfc)
+    SDL_FreeSurface(chars_label_srfc); 
+  chars_label_srfc = BlackOutline(_("Chars"), fontsize, &yellow);
+
+  if (cpm_label_srfc)
+    SDL_FreeSurface(cpm_label_srfc);
+  cpm_label_srfc = BlackOutline(_("CPM"), fontsize, &yellow);
+
+  if (wpm_label_srfc)
+    SDL_FreeSurface(wpm_label_srfc); 
+  wpm_label_srfc = BlackOutline(_("WPM"), fontsize, &yellow);
+
+  if (errors_label_srfc)
+    SDL_FreeSurface(errors_label_srfc); 
+  errors_label_srfc = BlackOutline(_("Errors"), fontsize, &yellow);
+
+  if (accuracy_label_srfc)
+    SDL_FreeSurface(accuracy_label_srfc); 
+  accuracy_label_srfc = BlackOutline(_("Accuracy"), fontsize, &yellow);
+
+  if (time_label_srfc
+   && chars_label_srfc
+   && cpm_label_srfc
+   && wpm_label_srfc
+   && errors_label_srfc
+   && accuracy_label_srfc)
+    return 1;
+  else
+    return 0;
+}
\ No newline at end of file

Modified: tuxtype/trunk/src/setup.c
===================================================================
--- tuxtype/trunk/src/setup.c	2009-03-05 13:21:28 UTC (rev 926)
+++ tuxtype/trunk/src/setup.c	2009-03-05 20:16:07 UTC (rev 927)
@@ -21,27 +21,7 @@
 #include "funcs.h"
 #include "SDL_extras.h"
 
-//NOTE this PATHS[] is an ugly hack which is no longer used.  We
-//now just confirm that DATA_PREFIX is valid, as it should be.
 
-//#define NUM_PATHS 2
-
-///* NOTE the correct path for a unix-type make install _should_ be */
-///* DATA_PREFIX, which is "$(PREFIX)/share/tuxtype". The "./data"  */
-///* path is for the Windows install, but this should really not be */
-///* necessary because DATA_PREFIX gets defined to this #ifdef WIN32 */
-///* So, the path to the default data should always be DATA_PREFIX  */
-///* unless something is screwed up - DSB                           */
-// const char PATHS[NUM_PATHS][FNLEN] = 
-// {
-// /*  DATA_PREFIX"/share/"PACKAGE"/data",
-//   "/usr/share/"PACKAGE"/data",
-//   "/usr/local/share/"PACKAGE"/data",
-//   "./data"*/
-//   DATA_PREFIX,
-//   "./data"
-// };
-
 int fs_res_x = 0;
 int fs_res_y = 0;
 
@@ -116,25 +96,10 @@
     exit(2);
   }
 
+  InitEngine();
 
-	LOG( "SDL_SetClipRect(screen, NULL):\n" );
 
-	SDL_SetClipRect(screen, NULL); // Let's set the appropriate clip rect  -- JA: is neccessary???  
 
-
-
-	/* --- setup color 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; 
-
-	InitEngine();
-
-
-
   DEBUGCODE 
   {
     video_info = SDL_GetVideoInfo();




More information about the Tux4kids-commits mailing list