[Tux4kids-commits] r1628 - tuxtype/trunk/src
David Bruce
dbruce-guest at alioth.debian.org
Sun Nov 1 22:08:26 UTC 2009
Author: dbruce-guest
Date: 2009-11-01 22:08:26 +0000 (Sun, 01 Nov 2009)
New Revision: 1628
Modified:
tuxtype/trunk/src/editor.c
tuxtype/trunk/src/globals.h
tuxtype/trunk/src/scripting.c
Log:
code cleanup in editor
Modified: tuxtype/trunk/src/editor.c
===================================================================
--- tuxtype/trunk/src/editor.c 2009-10-29 14:35:48 UTC (rev 1627)
+++ tuxtype/trunk/src/editor.c 2009-11-01 22:08:26 UTC (rev 1628)
@@ -4,7 +4,8 @@
// Description: Implementation of word- and phrase list-editing functionality for
// Tux Typing
//
-// Author: Sarah Frisk <ssfrisk at gmail.com> and David Bruce <davidstuartbruce at gmail.com>, (C) 2009
+// Authors: Sarah Frisk <ssfrisk at gmail.com> and
+// David Bruce <davidstuartbruce at gmail.com>, (C) 2009
//
// Written for Google Summer of Code 2009
//
@@ -19,10 +20,7 @@
#include "SDL_image.h"
#include "convert_utf.h"
#include "editor.h"
-#include <stdio.h>
-/* NOTE ChooseFile() is the function to pick custom word lists to edit. */
-/* We should change the name to something more descriptive. */
void ChooseListToEdit(void)
{
@@ -154,25 +152,22 @@
/* Draw the initial text and images that won't change as list is examined: */
-
- directions_Rect[0].x = screen->w/2 - (directions[0]->w/2);
- directions_Rect[0].y = 10;
- directions_Rect[0].w = directions[0]->w;
- directions_Rect[0].h = directions[0]->h;
+ directions_Rect[0].x = screen->w/2 - (directions[0]->w/2);
+ directions_Rect[0].y = 10;
+ directions_Rect[0].w = directions[0]->w;
+ directions_Rect[0].h = directions[0]->h;
- j = 30;
-
- for (i = 1; i < 5; i++)
- {
- j += 20;
- directions_Rect[i].x = screen->w/2 - (directions[i]->w/2);
- directions_Rect[i].y = j;
- directions_Rect[i].w = directions[i]->w;
- directions_Rect[i].h = directions[i]->h;
- }
+ j = 30;
+ for (i = 1; i < 5; i++)
+ {
+ j += 20;
+ directions_Rect[i].x = screen->w/2 - (directions[i]->w/2);
+ directions_Rect[i].y = j;
+ directions_Rect[i].w = directions[i]->w;
+ directions_Rect[i].h = directions[i]->h;
+ }
-
button_rect[New].x = screen->w - new_button->w - 20;
button_rect[New].y = screen->h/3;
button_text_rect[New].x = screen->w - new_button->w - 20 + (new_button->w/2 - NEW->w/2);
@@ -212,7 +207,7 @@
titleRects[i].x = screen->w / 10;
}
- SDL_UpdateRect(screen, 0, 0, 0, 0);
+ SDL_UpdateRect(screen, 0, 0, 0, 0);
/* Event loop for this screen: */
while (!stop)
@@ -228,49 +223,49 @@
break;
case SDL_MOUSEBUTTONDOWN:
+ if (inRect(leftRect, event.button.x, event.button.y))
+ if (loc - (loc % 8) - 8 >= 0)
+ {
+ loc = loc - (loc % 8) - 8;
+ break;
+ }
- 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 < num_lists)
+ {
+ loc = loc - (loc % 8) + 8;
+ break;
+ }
- if (inRect(rightRect, event.button.x, event.button.y))
- if (loc - (loc % 8) + 8 < num_lists)
- {
- loc = loc - (loc % 8) + 8;
- break;
- }
-
- if (inRect(button_rect[New], event.button.x, event.button.y))
- {
- change = CreateNewWordList();
- if (!change)
- redraw = 1;
- }
+ if (inRect(button_rect[New], event.button.x, event.button.y))
+ {
+ change = CreateNewWordList();
+ if (!change)
+ redraw = 1;
+ }
- if (inRect(button_rect[Remove], event.button.x, event.button.y))
- {
- //pop up something?
- ChooseRemoveList(list_titles[loc], file_names[loc]);
- change = 1;
- }
-
- if (inRect(button_rect[Done], event.button.x, event.button.y))
- {
- stop = 1;
- break;
- }
+ if (inRect(button_rect[Remove], event.button.x, event.button.y))
+ {
+ //pop up something?
+ ChooseRemoveList(list_titles[loc], file_names[loc]);
+ change = 1;
+ }
+
+ if (inRect(button_rect[Done], event.button.x, event.button.y))
+ {
+ stop = 1;
+ break;
+ }
break;
case SDL_KEYDOWN:
- if (event.key.keysym.sym == SDLK_BACKSPACE)
- {
- //Remove wordlist
- ChooseRemoveList(list_titles[loc], file_names[loc]);
- change = 1;
- }
+ if (event.key.keysym.sym == SDLK_BACKSPACE)
+ {
+ //Remove wordlist
+ ChooseRemoveList(list_titles[loc], file_names[loc]);
+ change = 1;
+ }
+
if (event.key.keysym.sym == SDLK_ESCAPE)
{
stop = 1;
@@ -283,7 +278,7 @@
{
EditWordList(file_names[loc]);
loc = 0;
- redraw = 1;
+ redraw = 1;
break;
}
// Go to top of previous page:
@@ -315,120 +310,119 @@
}
} //End of user event handling
- /* reload the list if it has been changed */
- if (change)
- {
+ /* reload the list if it has been changed */
+ if (change)
+ {
+ num_lists = 0;
+ //Try to open directory for modifiable word lists:
+ sprintf(fn , "%s" , settings.var_data_path);
+ lists_dir = opendir(fn);
- num_lists = 0;
- //Try to open directory for modifiable word lists:
- sprintf(fn , "%s" , settings.var_data_path);
- lists_dir = opendir(fn);
+ if (!lists_dir)
+ {
+ LOG("ChooseListToEdit() - cannot open custom word list directory!\n");
+ return;
+ }
- if (!lists_dir)
- {
- fprintf(stderr, "ChooseListToEdit() - cannot open custom word list directory!\n");
- return;
- }
+ //FIXME we should use scandir() for this - DSB
+ //Now scan through directory and gather file names and list titles:
+ while (1)
+ {
+ list_dirent = readdir(lists_dir);
+ if (!list_dirent)
+ break;
- //Now scan through directory and gather file names and list titles:
- while (1)
- {
- list_dirent = readdir(lists_dir);
- if (!list_dirent)
- break;
+ /* we ignore any hidden file and CVS */
+ if (list_dirent->d_name[0] == '.')
+ continue;
+ if (strcmp("CVS", list_dirent->d_name) == 0)
+ continue;
- /* we ignore any hidden file and CVS */
+ snprintf(fn, FNLEN, "%s/%s" , settings.var_data_path, list_dirent->d_name);
- if (list_dirent->d_name[0] == '.')
- continue;
+ /* CheckFile() returns 2 if dir, 1 if file, 0 if neither: */
+ if (CheckFile(fn) == 1)
+ {
+ /* We know it opens safely because CheckFile() returned 1 */
+ fp = fopen(fn,"r");
+ /* HACK: we should get the names from file :) */
+ if (EOF ==fscanf(fp, "%[^\n]\n", list_titles[num_lists]))
+ continue;
+ /* Make sure list title is capitalized: */
+ list_titles[num_lists][0] = toupper(list_titles[num_lists][0]);
+ fclose(fp);
+ strncpy(file_names[num_lists++], list_dirent->d_name, FNLEN-1);
+ }
+ }
+ closedir(lists_dir);
- if (strcmp("CVS", list_dirent->d_name) == 0)
- continue;
- snprintf(fn, FNLEN, "%s/%s" , settings.var_data_path, list_dirent->d_name);
+ // white_titles_surf[MAX_WORD_LISTS] = {NULL};
+ // yellow_titles_surf[MAX_WORD_LISTS] = {NULL};
- /* CheckFile() returns 2 if dir, 1 if file, 0 if neither: */
- if (CheckFile(fn) == 1)
- {
- /* We know it opens safely because CheckFile() returned 1 */
- fp = fopen(fn,"r");
- /* HACK: we should get the names from file :) */
- if (EOF ==fscanf(fp, "%[^\n]\n", list_titles[num_lists]))
- continue;
- /* Make sure list title is capitalized: */
- list_titles[num_lists][0] = toupper(list_titles[num_lists][0]);
- fclose(fp);
- strncpy(file_names[num_lists++], list_dirent->d_name, FNLEN-1);
- }
- }
- closedir(lists_dir);
+ /* Render SDL_Surfaces of title text for later blitting: */
+ for (i = 0; i < num_lists; i++)
+ {
+ white_titles_surf[i] = BlackOutline(list_titles[i],
+ DEFAULT_MENU_FONT_SIZE, &white);
+ yellow_titles_surf[i] = BlackOutline(list_titles[i],
+ DEFAULT_MENU_FONT_SIZE, &yellow);
+ }
- // white_titles_surf[MAX_WORD_LISTS] = {NULL};
- // yellow_titles_surf[MAX_WORD_LISTS] = {NULL};
+ change = 0;
+ redraw = 1;
+ }
- /* Render SDL_Surfaces of title text for later blitting: */
- for (i = 0; i < num_lists; i++)
- {
- white_titles_surf[i] = BlackOutline(list_titles[i], DEFAULT_MENU_FONT_SIZE, &white);
- yellow_titles_surf[i] = BlackOutline(list_titles[i], DEFAULT_MENU_FONT_SIZE, &yellow);
- }
- change = 0;
- redraw = 1;
- }
-
-
/* Redraw if a different menu entry is selected: */
if (old_loc != loc || redraw == 1)
{
int start;
-
if(CurrentBkgd())
- SDL_BlitSurface(CurrentBkgd(), NULL, screen, NULL);
+ SDL_BlitSurface(CurrentBkgd(), NULL, screen, NULL);
- /*FIXME: simplify this into a function*/
+ /*FIXME: simplify this into a function*/
+ for (i = 0; i < 5; i++)
+ SDL_BlitSurface( directions[i], NULL, screen, &directions_Rect[i]);
- for (i = 0; i < 5; i++)
- SDL_BlitSurface( directions[i], NULL, screen, &directions_Rect[i]);
+ SDL_BlitSurface(new_button, NULL, screen, &button_rect[New]);
+ SDL_BlitSurface(NEW, NULL, screen, &button_text_rect[New]);
+ SDL_BlitSurface(remove_button, NULL, screen, &button_rect[Remove]);
+ SDL_BlitSurface(REMOVE, NULL, screen, &button_text_rect[Remove]);
+ SDL_BlitSurface(done_button, NULL, screen, &button_rect[Done]);
+ SDL_BlitSurface(DONE, NULL, screen, &button_text_rect[Done]);
-
- SDL_BlitSurface(new_button, NULL, screen, &button_rect[New]);
- SDL_BlitSurface(NEW, NULL, screen, &button_text_rect[New]);
- SDL_BlitSurface(remove_button, NULL, screen, &button_rect[Remove]);
- SDL_BlitSurface(REMOVE, NULL, screen, &button_text_rect[Remove]);
- SDL_BlitSurface(done_button, NULL, screen, &button_rect[Done]);
- SDL_BlitSurface(DONE, NULL, screen, &button_text_rect[Done]);
-
start = loc - (loc % 8);
for (i = start; i < MIN (start + 8, num_lists); i++)
{
//titleRects[i % 8].x = 320 - (white_titles_surf[i]->w/2);
if (i == loc)
- SDL_BlitSurface(yellow_titles_surf[loc], NULL, screen, &titleRects[i % 8]);
+ SDL_BlitSurface(yellow_titles_surf[loc], NULL, screen, &titleRects[i % 8]);
else
- SDL_BlitSurface(white_titles_surf[i], NULL, screen, &titleRects[i % 8]);
- SDL_UpdateRect(screen, titleRects[i%8].x, titleRects[i%8].y, titleRects[i%8].w, titleRects[i%8].h);
- }
-
- /* --- draw right and left arrow buttons --- */
- if (start > 0)
- SDL_BlitSurface( left, NULL, screen, &leftRect );
- if (start + 8 < num_lists)
- SDL_BlitSurface(right, NULL, screen, &rightRect);
-
-
- SDL_UpdateRect(screen, 0, 0, 0, 0);
- redraw = 0;
-
+ SDL_BlitSurface(white_titles_surf[i], NULL, screen, &titleRects[i % 8]);
+ SDL_UpdateRect(screen, titleRects[i%8].x, titleRects[i%8].y,
+ titleRects[i%8].w, titleRects[i%8].h);
+ }
+
+ /* --- draw right and left arrow buttons --- */
+ if (start > 0)
+ SDL_BlitSurface( left, NULL, screen, &leftRect );
+ if (start + 8 < num_lists)
+ SDL_BlitSurface(right, NULL, screen, &rightRect);
+
+ SDL_UpdateRect(screen, 0, 0, 0, 0);
+ redraw = 0;
}
SDL_Delay(40);
old_loc = loc;
}
+ /* Cleanup all dynamically-allocated memory: */
+
/* NOTE pointers going out of scope so don't need to set them to NULL, */
/* but we should do that if we move this into a cleanup function. */
/* --- clear graphics before quitting --- */
@@ -440,11 +434,11 @@
SDL_FreeSurface(yellow_titles_surf[i]);
}
- for (i = 0; i < 5; i ++)
- {
- if(directions[i])
- SDL_FreeSurface(directions[i]);
- }
+ for (i = 0; i < 5; i ++)
+ {
+ if(directions[i])
+ SDL_FreeSurface(directions[i]);
+ }
if(new_button)
SDL_FreeSurface(new_button);
@@ -453,15 +447,15 @@
if(done_button)
SDL_FreeSurface(done_button);
if(NEW)
- SDL_FreeSurface(NEW);
+ SDL_FreeSurface(NEW);
if(REMOVE)
- SDL_FreeSurface(REMOVE);
+ SDL_FreeSurface(REMOVE);
if(DONE)
- SDL_FreeSurface(DONE);
+ SDL_FreeSurface(DONE);
if(left)
- SDL_FreeSurface(left);
+ SDL_FreeSurface(left);
if(right)
- SDL_FreeSurface(right);
+ SDL_FreeSurface(right);
}
@@ -485,31 +479,28 @@
int stop = 0;
int loc = 0;
int old_loc = 1;
-
+
FILE* fp = NULL;
int start, number_of_words = 0;
-int i,len,j = 0;
+ int i, len, j = 0;
int listening_for_new_word = 0;
char fn[FNLEN];
char words_in_list[MAX_NUM_WORDS][MAX_WORD_SIZE + 1];
wchar_t temp[MAX_WORD_SIZE + 1];
-
//We should be able to use GenerateWordList() in place of this next block:
- //NOTE: Works originally, but upon returning to editorlist, the word selected
- // is not there, since all words in the wordlist are deleted
- sprintf(fn , "%s/%s", settings.var_data_path, words_file);
- fp = fopen(fn,"r");
- number_of_words = 0;
- while(!feof(fp))
- if (EOF ==fscanf(fp, "%[^\n]\n", words_in_list[number_of_words++]))
- continue;
- fclose(fp);
+ //NOTE: Works originally, but upon returning to editorlist, the word selected
+ // is not there, since all words in the wordlist are deleted
+ sprintf(fn , "%s/%s", settings.var_data_path, words_file);
+ fp = fopen(fn,"r");
+ number_of_words = 0;
+ while(!feof(fp))
+ if (EOF ==fscanf(fp, "%[^\n]\n", words_in_list[number_of_words++]))
+ continue;
+ fclose(fp);
-
-
/* Prepare needed SDL_Surfaces: */
/* Render the words in white and yellow: */
@@ -521,15 +512,14 @@
left = LoadImage("left.png", IMG_ALPHA);
right = LoadImage("right.png", IMG_ALPHA);
- title = BlackOutline(gettext_noop("Word List Editor:"), 20, &yellow);
+ title = BlackOutline(_("Word List Editor:"), 20, &yellow);
wordlist_name = BlackOutline(words_in_list[0], 25, &white);
- directions[0] = BlackOutline(gettext_noop("To add a word, press 'RETURN' and start typing"), 11, &white);
- directions[1] = BlackOutline(gettext_noop("To edit a word, select the word using the arrow buttons and continue typing"), 11, &white);
- directions[2] = BlackOutline(gettext_noop("To delete a character, select the word you want to edit and press the 'DELETE' key"), 11, &white);
- directions[3] = BlackOutline(gettext_noop("To exit and save the word list, press 'ESC'"), 11, &white);
+ directions[0] = BlackOutline(_("To add a word, press 'RETURN' and start typing"), 11, &white);
+ directions[1] = BlackOutline(_("To edit a word, select the word using the arrow buttons and continue typing"), 11, &white);
+ directions[2] = BlackOutline(_("To delete a character, select the word you want to edit and press the 'DELETE' key"), 11, &white);
+ directions[3] = BlackOutline(_("To exit and save the word list, press 'ESC'"), 11, &white);
-
/* Set up SDL_Rect locations for later blitting: */
leftRect.w = left->w;
leftRect.h = left->h;
@@ -545,41 +535,36 @@
word_rects[0].w = word_rects[0].h = 0;
word_rects[0].x = screen->w / 10;
-
-
for (i = 1; i < 8; i++)
-
{
word_rects[i].y = word_rects[i - 1].y + 30;
- word_rects[i].w = word_rects[i].h = 0;
- word_rects[i].x = screen->w / 10;
+ word_rects[i].w = word_rects[i].h = 0;
+ word_rects[i].x = screen->w / 10;
}
- j = 10;
+ j = 10;
+ titleRect.x = screen->w/2 - (title->w/2);
+ titleRect.y = j;
+ titleRect.w = title->w;
+ titleRect.h = title->w;
- titleRect.x = screen->w/2 - (title->w/2);
- titleRect.y = j;
- titleRect.w = title->w;
- titleRect.h = title->w;
-
- j += 30;
+ j += 30;
+ wordlist_name_rect.w = wordlist_name->w;
+ wordlist_name_rect.h = wordlist_name->h;
+ wordlist_name_rect.y = j;
+ wordlist_name_rect.x = screen->w/2 - wordlist_name->w/2;
- wordlist_name_rect.w = wordlist_name->w;
- wordlist_name_rect.h = wordlist_name->h;
- wordlist_name_rect.y = j;
- wordlist_name_rect.x = screen->w/2 - wordlist_name->w/2;
-
- j = 50;
- for ( i = 0; i < 4; i++)
- {
- j += 20;
- directions_Rect[i].y = j;
- directions_Rect[i].x = screen->w/2 - directions[i]->w/2;
- directions_Rect[i].w = directions[i]->w;
- directions_Rect[i].h = directions[i]->h;
- }
-
+ j = 50;
+ for ( i = 0; i < 4; i++)
+ {
+ j += 20;
+ directions_Rect[i].y = j;
+ directions_Rect[i].x = screen->w/2 - directions[i]->w/2;
+ directions_Rect[i].w = directions[i]->w;
+ directions_Rect[i].h = directions[i]->h;
+ }
+
/* Main event loop for word editor: */
while (!stop)
{
@@ -638,50 +623,65 @@
}
else
{
- // we have to remove the word from the list //
- fprintf(stderr, "The number of words is %i\n", number_of_words);
- fprintf(stderr, "The length is %i \n", len);
+ // we have to remove the word from the list //
+ DEBUGCODE
+ {
+ fprintf(stderr, "The number of words is %i\n", number_of_words);
+ fprintf(stderr, "The length is %i \n", len);
+ }
-
- if (number_of_words > 1)
- {
- int x = 0;
- number_of_words --;
- fprintf(stderr, "There are current: %i words\n", number_of_words);
-
- for(x = loc; x <= number_of_words-1; x++)
- {
- if(x < number_of_words-1)
- {
- len = ConvertFromUTF8(temp, words_in_list[x+2], MAX_WORD_SIZE);
- fprintf(stderr, "X = %i\n", x);
- fprintf(stderr, "loc = %i\n", loc);
- fprintf(stderr, "word in list = %s\n", words_in_list[x+2]);
- // fprintf(stderr, "temp = %s\n", temp);
- len = ConvertToUTF8(temp, words_in_list[x+1], MAX_WORD_SIZE);
- fprintf(stderr, "word in list = %s\n", words_in_list[x+1]);
- white_words[x] = BlackOutline(words_in_list[x+1], DEFAULT_MENU_FONT_SIZE, &white );
- yellow_words[x] = BlackOutline(words_in_list[x+1], DEFAULT_MENU_FONT_SIZE, &yellow);
- }
- else
- {
- //words_in_list[x] = 0;
- white_words[x] = NULL;
- yellow_words[x] = NULL;
- }
- }
-
-
- if (loc == number_of_words)
- loc --;
+ if (number_of_words > 1)
+ {
+ int x = 0;
+ number_of_words --;
+ DEBUGCODE
+ { fprintf(stderr, "There are current: %i words\n", number_of_words); }
- fprintf(stderr, "There are current: %i words\n", number_of_words);
- }
- white_words[loc] = BlackOutline(words_in_list[loc+1], DEFAULT_MENU_FONT_SIZE, &white );
- yellow_words[loc] = BlackOutline(words_in_list[loc+1], DEFAULT_MENU_FONT_SIZE, &yellow);
+ for(x = loc; x <= number_of_words-1; x++)
+ {
+ if(x < number_of_words-1)
+ {
+ len = ConvertFromUTF8(temp, words_in_list[x+2], MAX_WORD_SIZE);
- //handle deleation of words better, right now don't really do that
+ DEBUGCODE
+ {
+ fprintf(stderr, "X = %i\n", x);
+ fprintf(stderr, "loc = %i\n", loc);
+ fprintf(stderr, "word in list = %s\n", words_in_list[x+2]);
+ }
+
+ len = ConvertToUTF8(temp, words_in_list[x+1], MAX_WORD_SIZE);
+
+ DEBUGCODE
+ { fprintf(stderr, "word in list = %s\n", words_in_list[x+1]); }
+
+ white_words[x] = BlackOutline(words_in_list[x+1],
+ DEFAULT_MENU_FONT_SIZE, &white );
+ yellow_words[x] = BlackOutline(words_in_list[x+1],
+ DEFAULT_MENU_FONT_SIZE, &yellow);
+ }
+ else
+ {
+ white_words[x] = NULL;
+ yellow_words[x] = NULL;
+ }
+ }
+
+
+ if (loc == number_of_words)
+ loc --;
+
+ DEBUGCODE
+ { fprintf(stderr, "There are current: %i words\n", number_of_words); }
+ }
+
+ white_words[loc] = BlackOutline(words_in_list[loc+1],
+ DEFAULT_MENU_FONT_SIZE, &white );
+ yellow_words[loc] = BlackOutline(words_in_list[loc+1],
+ DEFAULT_MENU_FONT_SIZE, &yellow);
+
+ //handle deletion of words better, right now don't really do that
}
break;
} // end of handling of SDLK_BACKSPACE
@@ -697,7 +697,8 @@
{
if (loc - (loc % 8) - 8 >= 0)
loc = loc - (loc % 8) - 8;
- fprintf(stderr, "loc = %i\n", loc);
+ DEBUGCODE
+ { fprintf(stderr, "loc = %i\n", loc); }
break;
}
@@ -706,7 +707,8 @@
{
if (loc - (loc % 8) + 8 < number_of_words-1)
loc = (loc - (loc % 8) + 8);
- fprintf(stderr, "loc = %i\n", loc);
+ DEBUGCODE
+ { fprintf(stderr, "loc = %i\n", loc); }
break;
}
@@ -714,7 +716,8 @@
{
if (loc > 0)
loc--;
- fprintf(stderr, "loc = %i\n", loc);
+ DEBUGCODE
+ { fprintf(stderr, "loc = %i\n", loc); }
break;
}
@@ -722,64 +725,72 @@
{
if (loc + 1 < number_of_words-1)
loc++;
- fprintf(stderr, "loc = %i\n", loc);
+ DEBUGCODE
+ { fprintf(stderr, "loc = %i\n", loc); }
break;
}
-
-
+
+ //FIXME this switch should include above cases, too
switch (event.key.keysym.sym)
- {
+ {
case SDLK_RETURN:
- fprintf(stderr, "number of words: %i", number_of_words);
+ DEBUGCODE
+ { fprintf(stderr, "number of words: %i", number_of_words); }
+
if (number_of_words < MAX_WORD_LISTS)
listening_for_new_word = 1;
- // else if (blank == 1)
- // loc = number_of_words;
- else
- fprintf(stderr, "Couldn't add new word, this wordlist is full.\n");
- case SDLK_CAPSLOCK:
- case SDLK_RALT:
- case SDLK_LALT:
- case SDLK_RSHIFT:
- case SDLK_LSHIFT:
- case SDLK_RCTRL:
- case SDLK_LCTRL:
- i = 0;
- break;
- default: // ignore any other keys
- {}
+ else
+ LOG("Couldn't add new word, this wordlist is full.\n");
+ case SDLK_CAPSLOCK:
+ case SDLK_RALT:
+ case SDLK_LALT:
+ case SDLK_RSHIFT:
+ case SDLK_LSHIFT:
+ case SDLK_RCTRL:
+ case SDLK_LCTRL:
+ i = 0;
+ break;
+ default: // ignore any other keys
+ {}
}
if(i) //FIXME what is i?
{
- fprintf(stderr, "loc = %i\n", loc);
- fprintf(stderr, "number of words = %i\n", number_of_words);
- // If it's listening for a new word, from having last pressed enter, create a whole new word
- // with a length of 0, else get the current length of the highlighted word
- if (listening_for_new_word)
- {
- loc = number_of_words-1;
- number_of_words++;
- listening_for_new_word = 0;
- len = 0;
- }
- else
- {
- len = ConvertFromUTF8(temp, words_in_list[loc+1], MAX_WORD_SIZE);
- }
- if (len < MAX_WORD_SIZE -1)
- {
- // Add the character to the end of the existing string
- temp[len] = toupper(event.key.keysym.unicode);
- temp[len + 1] = 0;
- ConvertToUTF8(temp,words_in_list[loc+1], MAX_WORD_SIZE);
+ DEBUGCODE
+ {
+ fprintf(stderr, "loc = %i\n", loc);
+ fprintf(stderr, "number of words = %i\n", number_of_words);
+ }
- // Copy back to the on-screen list
- white_words[loc] = BlackOutline(words_in_list[loc+1], DEFAULT_MENU_FONT_SIZE, &white );
- yellow_words[loc] = BlackOutline(words_in_list[loc+1], DEFAULT_MENU_FONT_SIZE, &yellow);
- }
- i = 0;
- break;
+ // If it's listening for a new word, from having last
+ // pressed enter, create a whole new word with a length
+ // of 0, else get the current length of the highlighted word
+ if (listening_for_new_word)
+ {
+ loc = number_of_words-1;
+ number_of_words++;
+ listening_for_new_word = 0;
+ len = 0;
+ }
+ else
+ {
+ len = ConvertFromUTF8(temp, words_in_list[loc+1], MAX_WORD_SIZE);
+ }
+ if (len < MAX_WORD_SIZE -1)
+ {
+ // Add the character to the end of the existing string
+ temp[len] = toupper(event.key.keysym.unicode);
+ temp[len + 1] = 0;
+ ConvertToUTF8(temp,words_in_list[loc+1], MAX_WORD_SIZE);
+
+ // Copy back to the on-screen list
+ white_words[loc] = BlackOutline(words_in_list[loc+1],
+ DEFAULT_MENU_FONT_SIZE, &white);
+ yellow_words[loc] = BlackOutline(words_in_list[loc+1],
+ DEFAULT_MENU_FONT_SIZE, &yellow);
+ }
+ i = 0;
+ break;
}
} // end of CASE SDL_KEYDOWN:
} // end of 'switch (event.type)'
@@ -800,14 +811,16 @@
else
SDL_BlitSurface(white_words[i], NULL, screen, &word_rects[i % 8]);
}
- for(i = 0; i < 4; i++)
- SDL_BlitSurface(directions[i], NULL, screen, &directions_Rect[i]);
-
- SDL_BlitSurface(title, NULL, screen, &titleRect);
- SDL_BlitSurface(wordlist_name, NULL, screen, &wordlist_name_rect);
+
+ for(i = 0; i < 4; i++)
+ SDL_BlitSurface(directions[i], NULL, screen, &directions_Rect[i]);
+
+ SDL_BlitSurface(title, NULL, screen, &titleRect);
+ SDL_BlitSurface(wordlist_name, NULL, screen, &wordlist_name_rect);
+
/* --- draw right and left arrow buttons --- */
if (start > 0)
- SDL_BlitSurface( left, NULL, screen, &leftRect );
+ SDL_BlitSurface(left, NULL, screen, &leftRect);
if (start + 8 < number_of_words-1)
SDL_BlitSurface(right, NULL, screen, &rightRect);
@@ -825,7 +838,7 @@
each of the new words in the saved file. This is fixed upon reloading the
word list*/
- /* Write changes to file, if possible: */
+ /* Write changes to file, if possible: */
fprintf(stderr, "In ChooseWord(), about to write changes\n");
fp = fopen(fn,"w");
@@ -833,23 +846,28 @@
{
fseek(fp, 0, SEEK_SET);
//fprintf(fp, "%s", str);
- i = 0;
- while(i < number_of_words)
+ DEBUGCODE
{
- fprintf(fp, "%s\n", words_in_list[i]);
- fprintf(stderr, "%s\n", words_in_list[i]);
- i++;
- }
+ i = 0;
+ while(i < number_of_words)
+ {
+ fprintf(fp, "%s\n", words_in_list[i]);
+ fprintf(stderr, "%s\n", words_in_list[i]);
+ i++;
+ }
+ }
+
fclose(fp);
fp = NULL;
- fprintf(stderr, "In ChooseWord(), changes written successfully\n");
+ LOG("In ChooseWord(), changes written successfully\n");
}
else
{
- fprintf(stderr, "In ChooseWord(), unable to open %s for writing\n", fn);
- }
-
+ DEBUGCODE
+ { fprintf(stderr, "In ChooseWord(), unable to open %s for writing\n", fn); }
+ }
+
/* --- clear graphics before quitting --- */
for (i = 0; i < MAX_WORD_LISTS; i++)
{
@@ -865,21 +883,22 @@
}
}
- for (i = 0; i < 4; i ++)
- {
- if(directions[i])
- SDL_FreeSurface(directions[i]);
- }
+ for (i = 0; i < 4; i ++)
+ {
+ if(directions[i])
+ SDL_FreeSurface(directions[i]);
+ }
-
- SDL_FreeSurface(left);
- SDL_FreeSurface(right);
+ if(left)
+ SDL_FreeSurface(left);
+ if(right)
+ SDL_FreeSurface(right);
/* the pointers are going out of scope so we don't */
/* have to worry about setting them to NULL */
}
-/** Private functions **/
+/* "Private" functions */
int CreateNewWordList(void)
{
fprintf(stderr, "Creating a New Word List!!!");
Modified: tuxtype/trunk/src/globals.h
===================================================================
--- tuxtype/trunk/src/globals.h 2009-10-29 14:35:48 UTC (rev 1627)
+++ tuxtype/trunk/src/globals.h 2009-11-01 22:08:26 UTC (rev 1628)
@@ -18,8 +18,26 @@
#ifndef GLOBALS_H
#define GLOBALS_H
+// Autoheader-derived defs in here:
#include "config.h"
+// C library includes:
+#include <string.h>
+#include <wchar.h>
+#include <math.h>
+#include <time.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/stat.h>
+#include <dirent.h>
+#include <locale.h>
+
+// SDL includes:
+#include "SDL.h"
+#include "SDL_image.h"
+#include "SDL_mixer.h"
+/* NOTE only SDL_extras.c/.h now knows about SDL_ttf or SDL_Pango. */
+
// Translation stuff:
#include "gettext.h"
#include <locale.h>
@@ -36,43 +54,24 @@
#define DATA_PREFIX "./data"
#endif
-
#ifdef WIN32
#define TUXLOCALE "./locale"
#else
#define TUXLOCALE LOCALEDIR
#endif
-
+// FIXME if we really need these, make them into functions rather than
+// "evil" macros
#define to_upper(c) (((c) >= 'a' && (c) <= 'z') ? (c) -32 : (c))
#define COL2RGB( col ) SDL_MapRGB( screen->format, col->r, col->g, col->b )
+#define MIN(x,y) ((x) < (y) ? (x) : (y))
+#define MAX(x,y) ((x) > (y) ? (x) : (y))
-#define FNLEN 256
-#define RES_X 640
-#define RES_Y 480
-#define BPP 32
-#include <string.h>
-#include <wchar.h>
-#include <math.h>
-#include <time.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <sys/stat.h>
-#include <dirent.h>
-#include <locale.h>
+#define FNLEN 256
-#include "SDL.h"
-#include "SDL_image.h"
-#include "SDL_mixer.h"
-/* NOTE only SDL_extras.c/.h now knows about SDL_ttf or SDL_Pango. */
-
-#define MIN(x,y) ((x) < (y) ? (x) : (y))
-#define MAX(x,y) ((x) > (y) ? (x) : (y))
-
-/* Goal is to have all global settings here */
/* (renamed from 'settings' to match tuxmath) */
typedef struct game_option_type{
char default_data_path[FNLEN]; // for static read-only data
@@ -99,6 +98,7 @@
int hidden; // Read the README file in the image directory for info on this ;)
} game_option_type;
+
/* Default values for game_option_type struct */
/* They can be changed in the struct to other values at run-time */
#define DEFAULT_FONT_NAME "AndikaDesRevG.ttf"
@@ -121,8 +121,20 @@
#define DEFAULT_HIDDEN 0
+/* Goal is to have all global settings here */
+/* FIXME get rid of as much global data as possible, esp. pointers */
+extern game_option_type settings;
+extern SDL_Surface* screen;
+extern SDL_Event event;
-/* LOGGING works as such:
+/* these will store the resolution used by the OS when we start, so we */
+/* can run fullscreen at the user's preferred resolution: */
+extern int fs_res_x;
+extern int fs_res_y;
+
+
+
+/* #defines for run-time debugging output:
*
* - Use LOG if you want to output a string LOG( "Hello World");
*
@@ -142,6 +154,15 @@
#define DOUT(x) if (settings.debug_on) fprintf(stderr, "%s = %d\n", #x, x);
+
+
+/* Various preprocessor constants: ------------------------- */
+
+
+#define RES_X 640
+#define RES_Y 480
+#define BPP 32
+
/* Limits on word list size, word length, and on the number of distinct characters */
/* that can be present within a word list: */
#define MAX_NUM_WORDS 500
@@ -153,13 +174,6 @@
#define FRAMES_PER_SEC 15
#define FULL_CIRCLE 140
-/* Menu Prototypes */
-enum Game_Type {
- QUIT_GAME, CASCADE, OPTIONS, LESSONS,
- INSTRUCT_CASCADE, CASCADE1, CASCADE2, CASCADE3, CASCADE4,
- INSTRUCT_LASER, LASER1, LASER2, LASER3, LASER4,
- PHRASE_TYPING, ASDF, ALL, MAIN, SET_LANGUAGE, PROJECT_INFO, NOT_CODED,
- LEVEL1, LEVEL2, LEVEL3, LEVEL4, LASER, INSTRUCT, EDIT_WORDLIST, NONE};
/* Title sequence constants */
#define PRE_ANIM_FRAMES 10
@@ -179,24 +193,20 @@
#define REG_RGBA 16,16,96,96
#define SEL_RGBA 16,16,128,128
+#define MUSIC_FADE_OUT_MS 80
+
+/* Menu Prototypes */
+enum Game_Type {
+ QUIT_GAME, CASCADE, OPTIONS, LESSONS,
+ INSTRUCT_CASCADE, CASCADE1, CASCADE2, CASCADE3, CASCADE4,
+ INSTRUCT_LASER, LASER1, LASER2, LASER3, LASER4,
+ PHRASE_TYPING, ASDF, ALL, MAIN, SET_LANGUAGE, PROJECT_INFO, NOT_CODED,
+ LEVEL1, LEVEL2, LEVEL3, LEVEL4, LASER, INSTRUCT, EDIT_WORDLIST, NONE};
+
//Game difficulty levels
enum { EASY, MEDIUM, HARD, INSANE, INF_PRACT };
#define NUM_LEVELS 4
-extern game_option_type settings;
-
-/* FIXME get rid of as much global data as possible, esp. pointers */
-
-extern SDL_Surface* screen;
-
-/* these will store the resolution used by the OS when we start, so we */
-/* can run fullscreen at the user's preferred resolution: */
-extern int fs_res_x;
-extern int fs_res_y;
-
-extern SDL_Event event;
-
-
enum
{
WIN_WAV,
@@ -210,7 +220,6 @@
NUM_WAVES
};
-#define MUSIC_FADE_OUT_MS 80
/* For TransWipe(): */
enum
Modified: tuxtype/trunk/src/scripting.c
===================================================================
--- tuxtype/trunk/src/scripting.c 2009-10-29 14:35:48 UTC (rev 1627)
+++ tuxtype/trunk/src/scripting.c 2009-11-01 22:08:26 UTC (rev 1628)
@@ -121,20 +121,16 @@
SDL_Rect leftRect, rightRect;
SDL_Rect titleRects[8];
- char* fgets_return_val;
int nchars;
struct dirent **script_list_dirents = NULL;
int i = 0;
int scriptIterator = 0; //Iterator over matching files in script dir
- int length = 0;
int scripts = 0; //Iterator over accepted (& parsed) script files
int num_scripts = 0;
char script_path[FNLEN];
char script_filenames[MAX_LESSONS][FNLEN];
char fn[FNLEN];
- DIR* script_dir = NULL;
- struct dirent* script_file = NULL;
int stop = 0;
int loc = 0;
int old_loc = 1;
More information about the Tux4kids-commits
mailing list