[Tux4kids-commits] r686 - in tuxtype/trunk: . src

mobin-guest at alioth.debian.org mobin-guest at alioth.debian.org
Wed Aug 27 12:31:44 UTC 2008


Author: mobin-guest
Date: 2008-08-27 12:31:43 +0000 (Wed, 27 Aug 2008)
New Revision: 686

Modified:
   tuxtype/trunk/ChangeLog
   tuxtype/trunk/ChangeLog~
   tuxtype/trunk/src/titlescreen.c
Log:
Recommit: GUI for editing wordlist

Modified: tuxtype/trunk/ChangeLog
===================================================================
--- tuxtype/trunk/ChangeLog	2008-08-27 10:35:35 UTC (rev 685)
+++ tuxtype/trunk/ChangeLog	2008-08-27 12:31:43 UTC (rev 686)
@@ -7,6 +7,10 @@
         - Using GNU iconv() instead of Unicode Inc.'s conversion code
         - SDL_extras brought in from tuxmath for DrawButton(), streamlined BlackOutline(), etc.
 
+18 Aug 2008 -svn revision 652
+[ Mobin Mohan <mobinmohan at gmail.com> ]
+	-GUI for editing wordlist Implemented
+
 18 Aug 2008 - svn revision 647
 [ Sreyas Kurumanghat <k.sreyas at gmail.com ]
 	- Added features to practice game. Now pressing the down arrow presents the next phrase for practice and the escape key quits from the game.
@@ -15,13 +19,16 @@
 [ Sreyas Kurumanghat <k.sreyas at gmail.com ]
 	- Added pango support and rendering to practice game.
 
+14 Aug 2008 -svn revision 622
+[ Mobin Mohan <mobinmohan at gmail.com> ]
+	-gettextize  <bug-gnu-gettext at gnu.org>
+	-Added GNU Gettext Support
+	-Removed lang.po and created .po file for each theme in po directory
+
 3 Aug 2008 - svn revision 599
 [ Sreyas Kurumanghat <k.sreyas at gmail.com ]
 	- Added keypress details for wrong key pressed in practice.
 
-2008-07-09  gettextize  <bug-gnu-gettext at gnu.org>
-
-
 3 Aug 2008 - svn revision 580
 [ Sreyas Kurumanghat <k.sreyas at gmail.com ]
 	- Added automatic keyboard layout generation in practice.c.

Modified: tuxtype/trunk/ChangeLog~
===================================================================
--- tuxtype/trunk/ChangeLog~	2008-08-27 10:35:35 UTC (rev 685)
+++ tuxtype/trunk/ChangeLog~	2008-08-27 12:31:43 UTC (rev 686)
@@ -1,3 +1,12 @@
+22 Aug 2008 - svn revision 668
+[ David Bruce <davidstuartbruce at gmail.com> ]
+        - Extensive revision to support fullscreen mode at resolution of OS rather than only 640x480.
+          Menu system and comet zap work, fish cascade now works in fullscreen but cannot handle
+          toggle of resolution in midstream; practice and lessons still need to be fixed to 
+          handle new fullscreen mode.
+        - Using GNU iconv() instead of Unicode Inc.'s conversion code
+        - SDL_extras brought in from tuxmath for DrawButton(), streamlined BlackOutline(), etc.
+
 18 Aug 2008 - svn revision 647
 [ Sreyas Kurumanghat <k.sreyas at gmail.com ]
 	- Added features to practice game. Now pressing the down arrow presents the next phrase for practice and the escape key quits from the game.
@@ -6,13 +15,16 @@
 [ Sreyas Kurumanghat <k.sreyas at gmail.com ]
 	- Added pango support and rendering to practice game.
 
+14 Aug 2008 -svn revision 622
+[ Mobin Mohan <mobinmohan at gmail.com> ]
+	-gettextize  <bug-gnu-gettext at gnu.org>
+	-Added GNU Gettext Support
+	-Removed lang.po and created .po file for each theme in po directory
+
 3 Aug 2008 - svn revision 599
 [ Sreyas Kurumanghat <k.sreyas at gmail.com ]
 	- Added keypress details for wrong key pressed in practice.
 
-2008-07-09  gettextize  <bug-gnu-gettext at gnu.org>
-
-
 3 Aug 2008 - svn revision 580
 [ Sreyas Kurumanghat <k.sreyas at gmail.com ]
 	- Added automatic keyboard layout generation in practice.c.

Modified: tuxtype/trunk/src/titlescreen.c
===================================================================
--- tuxtype/trunk/src/titlescreen.c	2008-08-27 10:35:35 UTC (rev 685)
+++ tuxtype/trunk/src/titlescreen.c	2008-08-27 12:31:43 UTC (rev 686)
@@ -61,7 +61,8 @@
 static void load_menu(void);
 static void recalc_rects(void);
 static int chooseWordlist(void);
-static void not_implemented(void);
+static void ChooseWord(char *words_file);
+static void ChooseFile(void);
 static void unload_media(void);
 static void unload_menu(void);
 
@@ -70,7 +71,7 @@
 /* --- define menu structure --- */
 /* (these values are all in the Game_Type enum in globals.h) */
 const int menu_item[][6]= {{0, 0,         0,         0,          0},
-			   {0, CASCADE,   LEVEL1,    LEVEL1,  NOT_CODED },
+			   {0, CASCADE,   LEVEL1,    LEVEL1,  EDIT_WORDLIST },
 			   {0, LASER,     LEVEL2,    LEVEL2,  FREETYPE   },
 			   {0, LESSONS,  LEVEL3,    LEVEL3,  PROJECT_INFO },
 			   {0, OPTIONS,   INSTRUCT,  LEVEL4,  SET_LANGUAGE},
@@ -495,9 +496,9 @@
     }
 
 
-    if (menu_opt == NOT_CODED)
+    if (menu_opt == EDIT_WORDLIST)
     {
-      not_implemented();
+      ChooseFile();
       redraw = 1;
     }
 
@@ -1540,3 +1541,459 @@
 }
 
 
+static void ChooseFile(void)
+{
+  SDL_Surface* titles[MAX_WORD_LISTS] = {NULL};
+  SDL_Surface* select[MAX_WORD_LISTS] = {NULL};
+  SDL_Surface *photo = NULL;
+  SDL_Surface* bkg = NULL;
+  TTF_Font* font = NULL;
+  SDL_Rect titleRects[8];
+  int stop = 0;
+  int loc = 0;
+  int old_loc = 1;
+
+  int themes = 0;
+  int i;
+  unsigned char fn[FNLEN];
+  unsigned char wordTypes[MAX_WORD_LISTS][FNLEN];
+  unsigned char fileNames[MAX_WORD_LISTS][FNLEN];
+
+  int old_use_english;
+  char old_theme_path[FNLEN];
+
+  FILE *fp;
+
+  DIR* themesDir = NULL;
+  struct dirent* themesFile = NULL;
+
+ /* save previous settings in case we back out: */
+  old_use_english = settings.use_english;
+  strncpy(old_theme_path, settings.theme_data_path, FNLEN - 1);
+
+if(settings.use_english){
+	sprintf(fn , "%s/words", settings.default_data_path);
+	fprintf(stderr , "%s/words", settings.default_data_path);
+}
+else{
+  sprintf(fn , "%s/words", settings.theme_data_path);
+  fprintf(stderr , "%s/words", settings.theme_data_path);
+}
+
+  themesDir = opendir(fn);
+
+  if (!themesDir)
+  {
+    fprintf(stderr, "Choosefile() - cannot open themes directory!");
+    return;
+  }
+
+  do
+  {
+	themesFile = readdir(themesDir);
+	if (!themesFile)
+		break;
+
+		/* we ignore any hidden file and CVS */
+
+	if (themesFile->d_name[0] == '.') 
+		continue;
+
+	if (strcmp("CVS", themesFile->d_name)==0)
+		continue;
+if(settings.use_english){
+	sprintf(fn, "%s/words/%s",settings.default_data_path, themesFile->d_name);
+}
+else{	
+	sprintf(fn, "%s/words/%s", settings.theme_data_path, themesFile->d_name);
+}
+
+		/* CheckFile() returns 2 if dir, 1 if file, 0 if neither: */
+	if (CheckFile(fn) == 1) {
+		fp=fopen(fn,"r");
+		    /* HACK: we should get the names from file :) */
+		fscanf(fp, "%[^\n]\n", wordTypes[themes]);
+		    /* Make sure theme name is capitalized: */
+                wordTypes[themes][0] = toupper(wordTypes[themes][0]);
+		fclose(fp);
+		strncpy( fileNames[themes++], themesFile->d_name, FNLEN-1 );
+		    
+	}
+  } while (1);
+
+  closedir(themesDir);
+
+  settings.use_english = 1;
+        // HACK: is font empty now???
+  font = LoadFont(settings.theme_font_name, MENU_FONT_SIZE);
+
+	
+  for (i = 0; i<themes; i++) {
+	titles[i] = BlackOutline( wordTypes[i], font, &white );
+	select[i] = BlackOutline( wordTypes[i], font, &yellow);
+  }
+
+	
+  TTF_CloseFont(font);
+  font = NULL;
+
+  settings.use_english = old_use_english;
+
+  bkg = LoadImage("main_bkg.png", IMG_REGULAR);
+
+	
+	/* set initial rect sizes */
+  titleRects[0].y = 150;
+  titleRects[0].w = titleRects[0].h = titleRects[0].x = 0;
+  for (i = 1; i<8; i++) {
+	titleRects[i].y = titleRects[i-1].y + 50;
+	titleRects[i].w = titleRects[i].h = titleRects[i].x = 0;
+  }
+	
+
+  while (!stop) {
+	while (SDL_PollEvent(&event)) 
+		switch (event.type) {
+			case SDL_QUIT:
+				exit(0);
+				break;
+			case SDL_MOUSEMOTION: 
+				for (i=0; (i<8) && (loc-(loc%8)+i<themes); i++)
+					if (inRect( titleRects[i], event.motion.x, event.motion.y )) {
+						loc = loc-(loc%8)+i;
+						break;
+					}
+				
+				break;
+			case SDL_MOUSEBUTTONDOWN: 
+				
+				for (i=0; (i<8) && (loc-(loc%8)+i<themes); i++) 
+					if (inRect(titleRects[i], event.button.x, event.button.y)) {
+						loc = loc-(loc%8)+i;
+						ChooseWord(fileNames[loc]);
+						break;
+					}
+					break;
+			case SDL_KEYDOWN:
+				if (event.key.keysym.sym == SDLK_ESCAPE) { 
+					settings.use_english = old_use_english;
+					strncpy(settings.theme_data_path, old_theme_path, FNLEN - 1);
+					stop = 1; 
+					break; 
+				}
+				if (event.key.keysym.sym == SDLK_RETURN) { 
+					ChooseWord(fileNames[loc]);
+					loc=0;
+					break;
+				
+	}
+
+				if ((event.key.keysym.sym == SDLK_LEFT) || (event.key.keysym.sym == SDLK_PAGEUP)) {
+					if (loc-(loc%8)-8 >= 0) 
+						loc=loc-(loc%8)-8;
+				}
+
+				if ((event.key.keysym.sym == SDLK_RIGHT) || (event.key.keysym.sym == SDLK_PAGEDOWN)) {
+					if (loc-(loc%8)+8 < themes)
+						loc=(loc-(loc%8)+8);
+				}
+
+				if (event.key.keysym.sym == SDLK_UP) {
+					if (loc > 0)
+						loc--;
+				}
+
+				if (event.key.keysym.sym == SDLK_DOWN) {
+					if (loc+1<themes)
+						loc++;
+				}
+		}
+
+	if (old_loc != loc) {
+		int start;
+
+		SDL_BlitSurface( bkg, NULL, screen, NULL );
+  
+		//if (loc) SetupPaths(fileNames[loc]); else SetupPaths(NULL);
+
+		start = loc - (loc % 8);
+		for (i = start; i<MIN(start+8,themes); i++) {
+			titleRects[i%8].x = 320 - (titles[i]->w/2);
+			if (i == loc)
+				SDL_BlitSurface(select[loc], NULL, screen, &titleRects[i%8]);
+			else
+				SDL_BlitSurface(titles[i], NULL, screen, &titleRects[i%8]);
+		}
+
+		SDL_UpdateRect(screen, 0, 0, 0 ,0);
+	}
+	SDL_Delay(40);
+	old_loc = loc;
+  }
+
+  /* --- clear graphics before quitting --- */ 
+
+  for (i = 0; i<themes; i++)
+  {
+    SDL_FreeSurface(titles[i]);
+    SDL_FreeSurface(select[i]);
+  }
+
+  
+  SDL_FreeSurface(bkg);
+ 
+  bkg = NULL;  /* the other pointers are going out of scope so we don't */
+               /* have to worry about setting them to NULL              */
+}
+
+
+static void ChooseWord(char *words_file)
+{
+  SDL_Surface* titles[MAX_WORD_LISTS] = {NULL};
+  SDL_Surface* select[MAX_WORD_LISTS] = {NULL};
+  SDL_Surface* left = NULL, *right = NULL;
+  SDL_Rect leftRect, rightRect;
+  SDL_Surface *photo = NULL;
+  SDL_Surface* bkg = NULL;
+  TTF_Font* font = NULL;
+  SDL_Rect worldRect, photoRect;
+  SDL_Rect titleRects[8];
+  int stop = 0;
+  int loc = 0;
+  int old_loc = 1;
+
+  FILE *fp;
+
+  int start,themes = 0;
+  int i,len;
+  unsigned char fn[FNLEN];
+  unsigned char str[FNLEN];
+  unsigned char editWordW[MAX_WORD_LISTS][FNLEN];
+  unsigned char editWordY[MAX_WORD_LISTS][FNLEN];
+
+  wchar_t temp[FNLEN];
+
+  int old_use_english;
+  char old_theme_path[FNLEN];
+
+  
+
+  /* save previous settings in case we back out: */
+  old_use_english = settings.use_english;
+  strncpy(old_theme_path, settings.theme_data_path, FNLEN - 1);
+
+if(settings.use_english){
+sprintf(fn , "%s/words/%s", settings.default_data_path,words_file);
+}
+else
+  sprintf(fn , "%s/words/%s", settings.theme_data_path,words_file);
+	
+  fp=fopen(fn,"r");
+  fscanf(fp, "%[^\n]\n", str);
+
+  while(!feof(fp))
+  {
+	/* HACK: we should get the strings from file :) */
+	fscanf(fp, "%[^\n]\n", editWordW[themes]);
+	strcpy(editWordY[themes++],editWordW[themes]);
+  }
+  
+  fclose(fp); 
+  
+  settings.use_english = 1;
+        // HACK: is font empty now???
+  font = LoadFont(settings.theme_font_name, MENU_FONT_SIZE);
+
+  for (i = 0; i<themes; i++) {
+	titles[i] = BlackOutline( editWordW[i], font, &white );
+	strcat(editWordY[i],"|");
+	select[i] = BlackOutline( editWordY[i], font, &yellow);
+  }
+
+  TTF_CloseFont(font);
+  font = NULL;
+
+  settings.use_english = old_use_english;
+  strncpy(settings.theme_data_path, old_theme_path, FNLEN - 1);
+
+  bkg = LoadImage("main_bkg.png", IMG_REGULAR);
+
+  left = LoadImage("left.png", IMG_ALPHA);
+  leftRect.w = left->w; leftRect.h = left->h;
+  leftRect.x = 320 - 100 - (leftRect.w/2); leftRect.y = 430;
+
+  right = LoadImage("right.png", IMG_ALPHA);
+  rightRect.w = right->w; rightRect.h = right->h;
+  rightRect.x = 320 + 100 - (rightRect.w/2); rightRect.y = 430;
+
+	/* set initial rect sizes */ 
+  titleRects[0].y = 30;
+  titleRects[0].w = titleRects[0].h = titleRects[0].x = 0;
+  for (i = 1; i<8; i++) {
+	titleRects[i].y = titleRects[i-1].y + 50;
+	titleRects[i].w = titleRects[i].h = titleRects[i].x = 0;
+  }
+	
+
+  while (!stop) {
+	while (SDL_PollEvent(&event)) 
+		switch (event.type) {
+			case SDL_QUIT:
+				exit(0);
+				break;
+			case SDL_MOUSEMOTION: 
+				if (inRect( leftRect, event.button.x, event.button.y )) 
+						if (loc-(loc%8)-8 >= 0) {
+							loc=loc-(loc%8)-8;
+							break;
+						}
+					if (inRect( rightRect, event.button.x, event.button.y )) 
+						if (loc-(loc%8)+8 < themes) {
+							loc=loc-(loc%8)+8;
+							break;
+						}
+				for (i=0; (i<8) && (loc-(loc%8)+i<themes); i++)
+					if (inRect( titleRects[i], event.motion.x, event.motion.y )) {
+						loc = loc-(loc%8)+i;
+						break;
+					}
+					
+				break;
+				
+			case SDL_KEYDOWN:
+				i=1;
+				if (event.key.keysym.sym == SDLK_BACKSPACE) {
+					font = LoadFont(settings.theme_font_name, MENU_FONT_SIZE);						
+					
+					len=ConvertFromUTF8(temp,editWordW[loc]);
+					temp[len-1]=temp[len];
+					len=ConvertToUTF8(temp,editWordW[loc]);
+					titles[loc] = BlackOutline(editWordW[loc], font, &white );						
+					len=ConvertFromUTF8(temp,editWordY[loc]);
+					temp[len-2]=temp[len-1];
+					temp[len-1]=temp[len];
+					len=ConvertToUTF8(temp,editWordY[loc]);
+					select[loc] = BlackOutline(editWordY[loc], font, &yellow);
+					TTF_CloseFont(font);
+        				font = NULL;
+					break;
+				}
+
+				if (event.key.keysym.sym == SDLK_ESCAPE) { 
+					settings.use_english = old_use_english;
+					strncpy(settings.theme_data_path, old_theme_path, FNLEN - 1);					
+					stop = 1; 
+					break; 
+				}
+					
+				if ((event.key.keysym.sym == SDLK_LEFT) || (event.key.keysym.sym == SDLK_PAGEUP)) {
+						if (loc-(loc%8)-8 >= 0) 
+							loc=loc-(loc%8)-8;
+						break;
+					}
+
+				if ((event.key.keysym.sym == SDLK_RIGHT) || (event.key.keysym.sym == SDLK_PAGEDOWN)) {
+					if (loc-(loc%8)+8 < themes)
+						loc=(loc-(loc%8)+8);
+					break;
+				}
+
+
+				if (event.key.keysym.sym == SDLK_UP) {
+					if (loc > 0)
+						loc--;
+					break;
+				}
+					
+				if (event.key.keysym.sym == SDLK_DOWN) {
+					if (loc+1<themes)
+						loc++;
+					break;
+				}
+				switch (event.key.keysym.sym){
+					case SDLK_RALT:
+					case SDLK_LALT:
+					case SDLK_RSHIFT:
+					case SDLK_LSHIFT:
+					case SDLK_RCTRL:
+					case SDLK_LCTRL:i=0;
+							break;
+				}
+				if(i){
+					
+					font = LoadFont(settings.theme_font_name, MENU_FONT_SIZE);						
+					
+					len=ConvertFromUTF8(temp,editWordW[loc]);
+					temp[len]=event.key.keysym.unicode;
+					temp[len+1]=0;
+					ConvertToUTF8(temp,editWordW[loc]);
+					titles[loc] = BlackOutline(editWordW[loc], font, &white );					
+						
+					len=ConvertFromUTF8(temp,editWordY[loc]);
+					temp[len+1]=0;
+					temp[len]=temp[len-1];
+					temp[len-1]=event.key.keysym.unicode;
+					ConvertToUTF8(temp,editWordY[loc]);
+					select[loc] = BlackOutline(editWordY[loc], font, &yellow);
+					TTF_CloseFont(font);
+        				font = NULL;
+					i=0;
+					break;
+				}	
+		}
+	if(!stop){
+	SDL_BlitSurface( bkg, NULL, screen, NULL );
+
+//	if (loc) SetupPaths(fileNames[loc]); else SetupPaths(NULL);	
+
+	start = loc - (loc % 8);
+	for (i = start; i<MIN(start+8,themes); i++) {
+		titleRects[i%8].x = 320 - (titles[i]->w/2);
+		if (i == loc)
+			SDL_BlitSurface(select[loc], NULL, screen, &titleRects[i%8]);
+		else
+			SDL_BlitSurface(titles[i], NULL, screen, &titleRects[i%8]);
+	}
+
+		/* --- draw buttons --- */
+
+	if (start>0) 
+		SDL_BlitSurface( left, NULL, screen, &leftRect );
+
+	if (start+8<themes) 
+		SDL_BlitSurface( right, NULL, screen, &rightRect );
+
+	SDL_UpdateRect(screen, 0, 0, 0 ,0);
+	}		
+	//SDL_Delay(40);
+	old_loc = loc;
+  }
+
+  
+  fp=fopen(fn,"w");
+  fseek(fp,0,SEEK_SET);
+  fprintf(fp, "%s\n", str);
+  i=0;
+
+  while(i<themes)
+  {
+	fprintf(fp, "%s\n", editWordW[i++]);
+	i++;
+  }
+  
+  fclose(fp); 
+  
+  /* --- clear graphics before quitting --- */ 
+
+  for (i = 0; i<themes; i++)
+  {
+    SDL_FreeSurface(titles[i]);
+    SDL_FreeSurface(select[i]);
+  }
+
+  SDL_FreeSurface(bkg);
+  SDL_FreeSurface(left);
+  SDL_FreeSurface(right);
+  bkg = NULL;  /* the other pointers are going out of scope so we don't */
+               /* have to worry about setting them to NULL              */
+}




More information about the Tux4kids-commits mailing list