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

dbruce-guest at alioth.debian.org dbruce-guest at alioth.debian.org
Fri Sep 21 19:14:39 UTC 2007


Author: dbruce-guest
Date: 2007-09-21 19:14:39 +0000 (Fri, 21 Sep 2007)
New Revision: 272

Modified:
   tuxmath/trunk/src/fileops.c
   tuxmath/trunk/src/fileops.h
   tuxmath/trunk/src/loaders.c
   tuxmath/trunk/src/options.h
   tuxmath/trunk/src/titlescreen.c
   tuxmath/trunk/src/titlescreen.h
Log:
High score table work; more flexible LoadFonts function;


Modified: tuxmath/trunk/src/fileops.c
===================================================================
--- tuxmath/trunk/src/fileops.c	2007-09-21 11:34:35 UTC (rev 271)
+++ tuxmath/trunk/src/fileops.c	2007-09-21 19:14:39 UTC (rev 272)
@@ -25,22 +25,20 @@
 * Copyright: See COPYING file that comes with this distribution (briefly, GNU GPL)
 *
 */
+/* Tuxmath includes: */
+#include "tuxmath.h"
+#include "fileops.h"
+#include "setup.h"
+#include "mathcards.h"
+#include "options.h"
+#include "highscore.h"
+//#include "titlescreen.h"
 
 #ifndef MACOSX
 #include "../config.h"
 #endif
 
-/* Standard C includes: */
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <ctype.h>
 
-/* OS includes - NOTE: these may not be very portable */
-#include <dirent.h>  /* for opendir() */
-#include <sys/stat.h>/* for mkdir() */
-#include <unistd.h>  /* for getcwd() */
-
 /* SDL includes: */
 #include <SDL.h>
 
@@ -50,15 +48,19 @@
 
 #include <SDL_image.h>
 
+/* OS includes - NOTE: these may not be very portable */
+#include <dirent.h>  /* for opendir() */
+#include <sys/stat.h>/* for mkdir() */
+#include <unistd.h>  /* for getcwd() */
 
-/* Tuxmath includes: */
-#include "tuxmath.h"
-#include "fileops.h"
-#include "setup.h"
-#include "mathcards.h"
-#include "options.h"
-#include "highscore.h"
+/* Standard C includes: */
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
 
+
+
 /* Used by both write_pregame_summary() and */
 /* write_postgame_summary() so defined with */
 /* file scope:                              */
@@ -90,6 +92,10 @@
 static int write_config_file(FILE* fp, int verbose);
 static int is_lesson_file(const struct dirent *lfdirent);
 
+/* FIXME copied this prototype here because #include-ing titlescreen.h */
+/* generates error with rewind() in read_config_file(), probably some */
+/* type of name collistion:                                           */
+TTF_Font* LoadFont(const unsigned char* font_name, int font_size);
 
 
 /* fix HOME on windows */
@@ -2616,36 +2622,28 @@
 /* returns 1 if default font successfully loaded, 0 otherwise. */
 int load_default_font()
 {
-  char fontfile[PATH_MAX];
-  sprintf(fontfile, "%s/fonts/%s", DATA_PREFIX, DEFAULT_FONT_NAME);
+  default_font = LoadFont((const unsigned char*)DEFAULT_FONT_NAME,
+                           DEFAULT_MENU_FONT_SIZE);
 
-  default_font = TTF_OpenFont(fontfile, DEFAULT_MENU_FONT_SIZE);
-
-  /* HACK - better font searching needed! */
-  /* This should mean that font wasn't bundled into data path, which for  */
-  /* now means we are using Debian, so grab from Debian installation loc: */
-  if (!default_font)
-  { 
-    sprintf(fontfile, "/usr/share/fonts/truetype/ttf-sil-andika/AndikaDesRevG.ttf");
-    default_font = TTF_OpenFont(fontfile, DEFAULT_MENU_FONT_SIZE);
-  }
-
-
-  if (default_font != NULL)
+  if (default_font)
   {
 #ifdef TUXMATH_DEBUG
-    fprintf(stderr, "load_default_font(): %s loaded successfully\n\n", fontfile);
+    fprintf(stderr, "load_default_font(): %s loaded successfully\n\n",
+            DEFAULT_FONT_NAME);
 #endif
     return 1;
   }
   else
   {
-   fprintf(stderr, "LoadFont(): %s NOT loaded successfully.\n", fontfile);
-   return 0;
+    fprintf(stderr, "LoadFont(): %s NOT loaded successfully.\n",
+            DEFAULT_FONT_NAME);
+    return 0;
   }
 }
 
 
+
+
 #ifndef NOSOUND
 int load_sound_data(void)
 {

Modified: tuxmath/trunk/src/fileops.h
===================================================================
--- tuxmath/trunk/src/fileops.h	2007-09-21 11:34:35 UTC (rev 271)
+++ tuxmath/trunk/src/fileops.h	2007-09-21 19:14:39 UTC (rev 272)
@@ -240,10 +240,10 @@
 int write_pregame_summary(void);
 int write_postgame_summary(void);
 
-
 int load_image_data();
 int load_default_font();
 
+
 #ifndef NOSOUND
 int load_sound_data();
 #endif

Modified: tuxmath/trunk/src/loaders.c
===================================================================
--- tuxmath/trunk/src/loaders.c	2007-09-21 11:34:35 UTC (rev 271)
+++ tuxmath/trunk/src/loaders.c	2007-09-21 19:14:39 UTC (rev 272)
@@ -146,57 +146,41 @@
 
 /* FIXME: I think we need to provide a single default font with the program data, */
 /* then more flexible code to try to locate or load system fonts. DSB             */
-/* FIXME checkFile() not working right in Win32 - skipping. */
-TTF_Font *LoadFont(char *fontfile, int fontsize)
+/* Returns ptr to loaded font if successful, NULL otherwise. */
+TTF_Font* LoadFont(const unsigned char* font_name, int font_size)
 {
-  TTF_Font *loadedFont;
-  char fn[PATH_MAX];
+  TTF_Font* f;
+  char fontfile[PATH_MAX];
+  sprintf(fontfile, "%s/fonts/%s", DATA_PREFIX, font_name);
 
-  sprintf( fn, "%s/fonts/%s", DATA_PREFIX, fontfile );
-  loadedFont = TTF_OpenFont( fn, fontsize );
+  f = TTF_OpenFont(fontfile, font_size);
 
-  if (loadedFont != NULL)
-  {
-#ifdef TUXMATH_DEBUG
-    fprintf(stderr, "LoadFont(): %s loaded successfully\n\n", fn);
-#endif
-    return loadedFont;
+  /* HACK - better font searching needed! */
+  /* This should mean that font wasn't bundled into data path, which for  */
+  /* now means we are using Debian, so grab from Debian installation loc: */
+  if (!f)
+  { 
+    sprintf(fontfile, "/usr/share/fonts/truetype/ttf-sil-andika/AndikaDesRevG.ttf");
+    f = TTF_OpenFont(fontfile, font_size);
   }
 
-#ifdef TUXMATH_DEBUG                        
-  else
-    fprintf(stderr, "LoadFont(): %s NOT loaded successfully - trying other path.\n", fn);
-#endif
 
-  /* this works only on debian */ 
-  /* "fallback" (the above _will_ fall): load the font with fixed-path */
-
-  sprintf( fn, "/usr/share/fonts/truetype/ttf-sil-andika/%s", fontfile );
-
-
-
-  /* try to load the font, if successful, return font*/
-  loadedFont = TTF_OpenFont( fn, fontsize );
-  if (loadedFont != NULL)
+  if (f)
   {
 #ifdef TUXMATH_DEBUG
-    fprintf(stderr, "LoadFont(): %s loaded successfully\n\n", fn);
+    fprintf(stderr, "LoadFont(): %s loaded successfully\n\n", fontfile);
 #endif
-    return loadedFont;
+    return f;
   }
-#ifdef TUXMATH_DEBUG                        
   else
-    fprintf(stderr, "LoadFont(): %s NOT loaded successfully.\n", fn);
-#endif
-
-  /* FIXME maybe the program should not exit here, just return NULL. */
-  fprintf(stderr, "FATAL ERROR: couldn't load font: %s\n\n", fontfile);
-  cleanup_on_error();
-  exit(1);
-  return NULL;
+  {
+   fprintf(stderr, "LoadFont(): %s NOT loaded successfully.\n", fontfile);
+   return NULL;
+  }
 }
 
 
+
 /* FIXME checkFile() not working right in Win32 - skipping. */
 /***********************
 	LoadImage : Load an image and set transparent if requested

Modified: tuxmath/trunk/src/options.h
===================================================================
--- tuxmath/trunk/src/options.h	2007-09-21 11:34:35 UTC (rev 271)
+++ tuxmath/trunk/src/options.h	2007-09-21 19:14:39 UTC (rev 272)
@@ -13,6 +13,9 @@
   http://www.tux4kids.org/
       
   August 26, 2001 - February 21, 2003
+
+  Extensively revised by David Bruce
+  2004-2007
 */
 
 

Modified: tuxmath/trunk/src/titlescreen.c
===================================================================
--- tuxmath/trunk/src/titlescreen.c	2007-09-21 11:34:35 UTC (rev 271)
+++ tuxmath/trunk/src/titlescreen.c	2007-09-21 19:14:39 UTC (rev 272)
@@ -1526,6 +1526,8 @@
   char* str1, *str2, *str3, *str4;
   wchar_t buf[HIGH_SCORE_NAME_LENGTH + 1] = {'\0'};
   unsigned char player_name[HIGH_SCORE_NAME_LENGTH * 3] = {'\0'};
+  TTF_Font* name_font = NULL;
+  const int NAME_FONT_SIZE = 32;
 
   if (!name_buf)
     return;
@@ -1533,6 +1535,10 @@
   s1 = s2 = s3 = s4 = NULL;
   str1 = str2  = str3 = str4 = NULL;
 
+  name_font = LoadFont(DEFAULT_FONT_NAME, NAME_FONT_SIZE);
+  if (!name_font)
+    return;
+
   /* We need to get Unicode vals from SDL keysyms */
   SDL_EnableUNICODE(SDL_ENABLE);
 
@@ -1684,7 +1690,7 @@
             //Unicode_to_UTF8((const wchar_t*)buf, player_name);
             wcstombs((char*) player_name, buf, HIGH_SCORE_NAME_LENGTH * 3);
 
-            s3 = black_outline(player_name, default_font, &yellow);
+            s3 = black_outline(player_name, name_font, &yellow);
             if (s3)
             {
               loc.x = 320 - (s3->w/2);
@@ -1745,6 +1751,7 @@
   SDL_FreeSurface(s2);
   SDL_FreeSurface(s3);
   SDL_FreeSurface(s4);
+  TTF_CloseFont(name_font);
 
   /* Turn off SDL Unicode lookup (because has some overhead): */
   SDL_EnableUNICODE(SDL_DISABLE);

Modified: tuxmath/trunk/src/titlescreen.h
===================================================================
--- tuxmath/trunk/src/titlescreen.h	2007-09-21 11:34:35 UTC (rev 271)
+++ tuxmath/trunk/src/titlescreen.h	2007-09-21 19:14:39 UTC (rev 272)
@@ -244,48 +244,48 @@
 
 /*In titlescreen.c */
 
-extern void TitleScreen( void );
-extern void switch_screen_mode( void );
-extern int choose_config_file(void);  //FIXME really should be in fileops.c
+void TitleScreen( void );
+void switch_screen_mode( void );
+int choose_config_file(void);  //FIXME really should be in fileops.c
 
 /* in theme.c (from tuxtype): */
-extern void chooseTheme(void);
-extern void setupTheme( char *dirname );
+void chooseTheme(void);
+void setupTheme( char *dirname );
 
 /* in loaders.c (from tuxtype): */
-extern int         checkFile( const char *file );
-extern TTF_Font    *LoadFont( char *fontfile, int fontsize );
-extern void         LoadLang( void );
-extern Mix_Chunk   *LoadSound( char *datafile );
-extern SDL_Surface *LoadImage( char *datafile, int mode );
-extern sprite      *LoadSprite( char *name, int MODE );
-extern sprite      *FlipSprite( sprite *in, int X, int Y );
-extern void         FreeSprite( sprite *gfx );
-extern Mix_Music   *LoadMusic( char *datafile );
-extern SDL_Surface* flip( SDL_Surface *in, int x, int y );
+int         checkFile( const char *file );
+TTF_Font* LoadFont(const unsigned char* font_name, int font_size);
+void         LoadLang( void );
+Mix_Chunk   *LoadSound( char *datafile );
+SDL_Surface *LoadImage( char *datafile, int mode );
+sprite      *LoadSprite( char *name, int MODE );
+sprite      *FlipSprite( sprite *in, int X, int Y );
+void         FreeSprite( sprite *gfx );
+Mix_Music   *LoadMusic( char *datafile );
+SDL_Surface* flip( SDL_Surface *in, int x, int y );
 
 /* in alphabet.c (from tuxtype) */
-extern void LoadKeyboard( void );
-extern void set_letters( unsigned char *t );
-extern unsigned char get_letter( void );
-extern void custom_letter_setup( void );
-extern void show_letters( void );
-extern SDL_Surface* black_outline( unsigned char *t, TTF_Font* font, SDL_Color* c );
-extern void WORDS_init( void );
-extern void WORDS_use_alphabet( void );
-extern void WORDS_use( char *wordFn );
-extern unsigned char* WORDS_get( void );
+void LoadKeyboard( void );
+void set_letters( unsigned char *t );
+unsigned char get_letter( void );
+void custom_letter_setup( void );
+void show_letters( void );
+SDL_Surface* black_outline( unsigned char *t, TTF_Font* font, SDL_Color* c );
+void WORDS_init( void );
+void WORDS_use_alphabet( void );
+void WORDS_use( char *wordFn );
+unsigned char* WORDS_get( void );
 
 /* in pause.c * (from tuxtype): */
-extern int  Pause( void );
-extern void pause_load_media( void );
-extern void pause_unload_media( void );
-extern int  inRect( SDL_Rect r, int x, int y);
+int  Pause( void );
+void pause_load_media( void );
+void pause_unload_media( void );
+int  inRect( SDL_Rect r, int x, int y);
 
 /* in audio.c  (from tuxtype): */
-extern void tuxtype_playsound( Mix_Chunk *snd );
-extern void audioMusicLoad( char *musicFilename, int repeatQty );
-extern void audioMusicUnload( void );
-extern void audioMusicPlay( Mix_Music *musicData, int repeatQty );
+void tuxtype_playsound( Mix_Chunk *snd );
+void audioMusicLoad( char *musicFilename, int repeatQty );
+void audioMusicUnload( void );
+void audioMusicPlay( Mix_Music *musicData, int repeatQty );
 
 #endif //TITLESCREEN_H




More information about the Tux4kids-commits mailing list