[Tux4kids-commits] r753 - tuxtype/trunk/src
dbruce-guest at alioth.debian.org
dbruce-guest at alioth.debian.org
Sat Sep 13 03:18:48 UTC 2008
Author: dbruce-guest
Date: 2008-09-13 03:18:47 +0000 (Sat, 13 Sep 2008)
New Revision: 753
Removed:
tuxtype/trunk/src/gettext.c
Modified:
tuxtype/trunk/src/Makefile.am
tuxtype/trunk/src/Makefile.in
tuxtype/trunk/src/alphabet.c
tuxtype/trunk/src/laser.c
tuxtype/trunk/src/playgame.c
tuxtype/trunk/src/practice.c
Log:
code cleanup and other work to make "Practice" fullscreen-compliant (practice.c);
correction of several errata in finger hint table (alphabet.c)
Modified: tuxtype/trunk/src/Makefile.am
===================================================================
--- tuxtype/trunk/src/Makefile.am 2008-09-08 11:36:51 UTC (rev 752)
+++ tuxtype/trunk/src/Makefile.am 2008-09-13 03:18:47 UTC (rev 753)
@@ -15,7 +15,6 @@
theme.c \
practice.c \
audio.c \
- gettext.c \
snow.c \
scripting.c \
SDL_extras.c \
Modified: tuxtype/trunk/src/Makefile.in
===================================================================
--- tuxtype/trunk/src/Makefile.in 2008-09-08 11:36:51 UTC (rev 752)
+++ tuxtype/trunk/src/Makefile.in 2008-09-13 03:18:47 UTC (rev 753)
@@ -54,10 +54,10 @@
am_tuxtype_OBJECTS = playgame.$(OBJEXT) main.$(OBJEXT) \
titlescreen.$(OBJEXT) loaders.$(OBJEXT) setup.$(OBJEXT) \
laser.$(OBJEXT) alphabet.$(OBJEXT) theme.$(OBJEXT) \
- practice.$(OBJEXT) audio.$(OBJEXT) gettext.$(OBJEXT) \
- snow.$(OBJEXT) scripting.$(OBJEXT) SDL_extras.$(OBJEXT) \
- pixels.$(OBJEXT) pause.$(OBJEXT) ConvertUTF.$(OBJEXT) \
- options.$(OBJEXT) iconv_string.$(OBJEXT)
+ practice.$(OBJEXT) audio.$(OBJEXT) snow.$(OBJEXT) \
+ scripting.$(OBJEXT) SDL_extras.$(OBJEXT) pixels.$(OBJEXT) \
+ pause.$(OBJEXT) ConvertUTF.$(OBJEXT) options.$(OBJEXT) \
+ iconv_string.$(OBJEXT)
tuxtype_OBJECTS = $(am_tuxtype_OBJECTS)
tuxtype_LDADD = $(LDADD)
tuxtype_LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(tuxtype_LDFLAGS) \
@@ -204,7 +204,6 @@
theme.c \
practice.c \
audio.c \
- gettext.c \
snow.c \
scripting.c \
SDL_extras.c \
@@ -299,7 +298,6 @@
@AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/SDL_extras.Po at am__quote@
@AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/alphabet.Po at am__quote@
@AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/audio.Po at am__quote@
- at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/gettext.Po at am__quote@
@AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/iconv_string.Po at am__quote@
@AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/laser.Po at am__quote@
@AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/loaders.Po at am__quote@
Modified: tuxtype/trunk/src/alphabet.c
===================================================================
--- tuxtype/trunk/src/alphabet.c 2008-09-08 11:36:51 UTC (rev 752)
+++ tuxtype/trunk/src/alphabet.c 2008-09-13 03:18:47 UTC (rev 753)
@@ -19,12 +19,6 @@
***************************************************************************/
-/* Needed to handle rendering issues for Indic languages*/
-//#ifndef WIN32
-//#ifndef MACOSX
-//#include <SDL_Pango.h>
-//#endif
-//#endif
/* Needed to convert UTF-8 under Windows because we don't have glibc: */
#include "ConvertUTF.h"
@@ -97,14 +91,8 @@
int check_needed_unicodes_str(const wchar_t* s);
int map_keys(wchar_t wide_char,kbd_char* keyboard_entry);
-//#ifndef WIN32
-//#ifndef MACOSX
-//static SDLPango_Matrix* SDL_Colour_to_SDLPango_Matrix(const SDL_Color* cl);
-//#endif
-//#endif
-
/*****************************************************/
/* */
/* "Public" Functions */
@@ -302,11 +290,13 @@
sprintf(buf,"keyboard/keyboard_%s.png", keyboard_list[index].keyname);
}
+
void GetWrongKeyPos(int index, char *buf)
{
sprintf(buf,"keyboard/keyboardN_%s.png", keyboard_list[index].keyname);
}
+
void GetKeyShift(int index, char *buf)
{
if(keyboard_list[index].shift==0)
@@ -317,13 +307,17 @@
else
sprintf(buf,"keyboard/keyboard_D12.png", settings.default_data_path);
}
+
+
wchar_t GetLastKey()
{
- if(!num_chars_used)
- return -1;
- else
- return keyboard_list[num_chars_used-1].unicode_value;
+ if(!num_chars_used)
+ return -1;
+ else
+ return keyboard_list[num_chars_used - 1].unicode_value;
}
+
+
int unicode_in_key_list(wchar_t uni_char)
{
int i = 0;
@@ -338,282 +332,9 @@
return 1;
}
-// /* NOTE if we can consistently use SDLPango on all platforms, we can simply */
-// /* rename the pango version to BlackOutline() and get rid of this one. */
-// /* The input for this function should be UTF-8. */
-// SDL_Surface* BlackOutline(const unsigned char* t, const TTF_Font* font, const SDL_Color* c)
-// {
-// SDL_Surface* out = NULL;
-// SDL_Surface* black_letters = NULL;
-// SDL_Surface* white_letters = NULL;
-// SDL_Surface* bg = NULL;
-// SDL_Rect dstrect;
-// Uint32 color_key;
-//
-// LOG("Entering BlackOutline()\n");
-//
-// /* Simply passthrough to SDLPango version if available (i.e. not under Windows):*/
-// #ifndef WIN32
-// #ifndef MACOSX
-// return BlackOutline_SDLPango(t, font, c);
-// #endif
-// #endif
-//
-//
-// if (!t || !font || !c)
-// {
-// fprintf(stderr, "BlackOutline(): invalid ptr parameter, returning.");
-// return NULL;
-// }
-//
-// black_letters = TTF_RenderUTF8_Blended((TTF_Font*)font, t, black);
-//
-// if (!black_letters)
-// {
-// fprintf (stderr, "Warning - BlackOutline() could not create image for %s\n", t);
-// return NULL;
-// }
-//
-// bg = SDL_CreateRGBSurface(SDL_SWSURFACE,
-// (black_letters->w) + 5,
-// (black_letters->h) + 5,
-// 32,
-// RMASK, GMASK, BMASK, AMASK);
-// /* Use color key for eventual transparency: */
-// color_key = SDL_MapRGB(bg->format, 10, 10, 10);
-// SDL_FillRect(bg, NULL, color_key);
-//
-// /* Now draw black outline/shadow 2 pixels on each side: */
-// dstrect.w = black_letters->w;
-// dstrect.h = black_letters->h;
-//
-// /* NOTE: can make the "shadow" more or less pronounced by */
-// /* changing the parameters of these loops. */
-// for (dstrect.x = 1; dstrect.x < 4; dstrect.x++)
-// for (dstrect.y = 1; dstrect.y < 3; dstrect.y++)
-// SDL_BlitSurface(black_letters , NULL, bg, &dstrect );
-//
-// SDL_FreeSurface(black_letters);
-//
-// /* --- Put the color version of the text on top! --- */
-// /* NOTE we cast away the 'const-ness' to keep compliler from complaining: */
-// white_letters = TTF_RenderUTF8_Blended((TTF_Font*)font, t, *c);
-// dstrect.x = 1;
-// dstrect.y = 1;
-// SDL_BlitSurface(white_letters, NULL, bg, &dstrect);
-// SDL_FreeSurface(white_letters);
-//
-// /* --- Convert to the screen format for quicker blits --- */
-// SDL_SetColorKey(bg, SDL_SRCCOLORKEY|SDL_RLEACCEL, color_key);
-// out = SDL_DisplayFormatAlpha(bg);
-// SDL_FreeSurface(bg);
-//
-// LOG("Leaving BlackOutline()\n");
-//
-// return out;
-// }
-//#ifndef WIN32
-//#ifndef MACOSX
-/*Convert SDL_Colour to SDLPango_Matrix*/
-
-// SDLPango_Matrix* SDL_Colour_to_SDLPango_Matrix(const SDL_Color *cl)
-// {
-// SDLPango_Matrix *colour;
-// colour=malloc(sizeof(SDLPango_Matrix));
-// int k;
-// for(k=0;k<4;k++){
-// (*colour).m[0][k]=(*cl).r;
-// (*colour).m[1][k]=(*cl).g;
-// (*colour).m[2][k]=(*cl).b;
-// }
-// (*colour).m[3][0]=0;
-// (*colour).m[3][1]=255;
-// (*colour).m[3][2]=0;
-// (*colour).m[3][3]=0;
-//
-// return colour;
-// }
-
-
-
-// /* This version basically uses the SDLPango lib instead of */
-// /* TTF_RenderUTF*_Blended() to properly render Indic text. */
-// SDL_Surface* BlackOutline_SDLPango(const unsigned char* t, const TTF_Font* font, const SDL_Color* c)
-// {
-// SDL_Surface* out = NULL;
-// SDL_Surface* black_letters = NULL;
-// SDL_Surface* white_letters = NULL;
-// SDL_Surface* bg = NULL;
-// SDL_Rect dstrect;
-// Uint32 color_key;
-// /* To covert SDL_Colour to SDLPango_Matrix */
-// SDLPango_Matrix* colour = NULL;
-// /* Create a context which contains Pango objects.*/
-// SDLPango_Context* context = NULL;
-//
-// LOG("\nEntering BlackOutline_SDLPango()\n");
-// DEBUGCODE{ fprintf(stderr, "will attempt to render: %s\n", t); }
-//
-// if (!t || !font || !c)
-// {
-// fprintf(stderr, "BlackOutline_SDLPango(): invalid ptr parameter, returning.");
-// return NULL;
-// }
-//
-// /* SDLPango crashes on 64 bit machines if passed empty string - Debian Bug#439071 */
-// if (*t == '\0')
-// {
-// fprintf(stderr, "BlackOutline_SDLPango(): empty string arg - must return to avoid segfault.");
-// return NULL;
-// }
-//
-// colour = SDL_Colour_to_SDLPango_Matrix(c);
-//
-// /* Create the context */
-// context = SDLPango_CreateContext();
-// SDLPango_SetDpi(context, 125.0, 125.0);
-// /* Set the color */
-// SDLPango_SetDefaultColor(context, MATRIX_TRANSPARENT_BACK_BLACK_LETTER );
-// SDLPango_SetBaseDirection(context, SDLPANGO_DIRECTION_LTR);
-// /* Set text to context */
-// SDLPango_SetMarkup(context, t, -1);
-//
-// if (!context)
-// {
-// fprintf (stderr, "In BlackOutline_SDLPango(), could not create context for %s", t);
-// return NULL;
-// }
-//
-// black_letters = SDLPango_CreateSurfaceDraw(context);
-//
-// if (!black_letters)
-// {
-// fprintf (stderr, "Warning - BlackOutline_SDLPango() could not create image for %s\n", t);
-// return NULL;
-// }
-//
-// bg = SDL_CreateRGBSurface(SDL_SWSURFACE,
-// (black_letters->w) + 5,
-// (black_letters->h) + 5,
-// 32,
-// RMASK, GMASK, BMASK, AMASK);
-// if (!bg)
-// {
-// fprintf (stderr, "Warning - BlackOutline()_SDLPango - bg creation failed\n");
-// SDL_FreeSurface(black_letters);
-// return NULL;
-// }
-//
-// /* Draw text on a existing surface */
-// SDLPango_Draw(context, bg, 0, 0);
-//
-// /* Use color key for eventual transparency: */
-// color_key = SDL_MapRGB(bg->format, 10, 10, 10);
-// SDL_FillRect(bg, NULL, color_key);
-//
-// /* Now draw black outline/shadow 2 pixels on each side: */
-// dstrect.w = black_letters->w;
-// dstrect.h = black_letters->h;
-//
-// /* NOTE: can make the "shadow" more or less pronounced by */
-// /* changing the parameters of these loops. */
-// for (dstrect.x = 1; dstrect.x < 4; dstrect.x++)
-// for (dstrect.y = 1; dstrect.y < 3; dstrect.y++)
-// SDL_BlitSurface(black_letters , NULL, bg, &dstrect );
-//
-// SDL_FreeSurface(black_letters);
-//
-// /* --- Put the color version of the text on top! --- */
-// SDLPango_SetDefaultColor(context, colour);
-// white_letters = SDLPango_CreateSurfaceDraw(context);
-// dstrect.x = 1;
-// dstrect.y = 1;
-// SDL_BlitSurface(white_letters, NULL, bg, &dstrect);
-// SDL_FreeSurface(white_letters);
-//
-// /* --- Convert to the screen format for quicker blits --- */
-// SDL_SetColorKey(bg, SDL_SRCCOLORKEY|SDL_RLEACCEL, color_key);
-// out = SDL_DisplayFormatAlpha(bg);
-// SDL_FreeSurface(bg);
-//
-// LOG("Leaving BlackOutline_SDLPango()\n\n");
-//
-// return out;
-// }
-
-//#endif
-//#endif
-/* End of win32-excluded coded */
-
-
-
-
-// /* This version takes a wide character string and renders it with the */
-// /* Unicode string versions of the SDL_ttf functions: */
-// SDL_Surface* BlackOutline_Unicode(const Uint16* t, const TTF_Font* font, const SDL_Color* c)
-// {
-// SDL_Surface* out = NULL;
-// SDL_Surface* black_letters = NULL;
-// SDL_Surface* white_letters = NULL;
-// SDL_Surface* bg = NULL;
-// SDL_Rect dstrect;
-// Uint32 color_key;
-//
-// if (!font || !c)
-// {
-// fprintf(stderr, "BlackOutline_wchar(): invalid ptr parameter, returning.");
-// return NULL;
-// }
-// /* (cast to stop compiler complaint) */
-// black_letters = TTF_RenderUNICODE_Blended((TTF_Font*)font, t, black);
-//
-// if (!black_letters)
-// {
-// fprintf (stderr, "Warning - BlackOutline_wchar() could not create image for %S\n", t);
-// return NULL;
-// }
-//
-// bg = SDL_CreateRGBSurface(SDL_SWSURFACE,
-// (black_letters->w) + 5,
-// (black_letters->h) + 5,
-// 32,
-// RMASK, GMASK, BMASK, AMASK);
-// /* Use color key for eventual transparency: */
-// color_key = SDL_MapRGB(bg->format, 10, 10, 10);
-// SDL_FillRect(bg, NULL, color_key);
-//
-// /* Now draw black outline/shadow 2 pixels on each side: */
-// dstrect.w = black_letters->w;
-// dstrect.h = black_letters->h;
-//
-// /* NOTE: can make the "shadow" more or less pronounced by */
-// /* changing the parameters of these loops. */
-// for (dstrect.x = 1; dstrect.x < 4; dstrect.x++)
-// for (dstrect.y = 1; dstrect.y < 3; dstrect.y++)
-// SDL_BlitSurface(black_letters , NULL, bg, &dstrect );
-//
-// SDL_FreeSurface(black_letters);
-//
-// /* --- Put the color version of the text on top! --- */
-// /* (cast to stop compiler complaint) */
-// white_letters = TTF_RenderUNICODE_Blended((TTF_Font*)font, t, *c);
-// dstrect.x = 1;
-// dstrect.y = 1;
-// SDL_BlitSurface(white_letters, NULL, bg, &dstrect);
-// SDL_FreeSurface(white_letters);
-//
-// /* --- Convert to the screen format for quicker blits --- */
-// SDL_SetColorKey(bg, SDL_SRCCOLORKEY|SDL_RLEACCEL, color_key);
-// out = SDL_DisplayFormatAlpha(bg);
-// SDL_FreeSurface(bg);
-//
-// return out;
-// }
-
-
/* FIXME dead code but could be useful*/
static void show_letters(void)
{
@@ -664,6 +385,7 @@
}
+
/* Returns a random Unicode char from the char_glyphs list: */
/* --- get a letter --- */
wchar_t GetRandLetter(void)
@@ -708,39 +430,8 @@
num_words = 0;
}
-/* FIXME need a better i18n-compatible way to do this: */
-/* UseAlphabet(): setups the word_list so that it really
- * returns a LETTER when GetWord() is called
- */
-// void UseAlphabet(void)
-// {
-// int i;
-//
-// LOG("Entering UseAlphabet()\n");
-//
-// num_words = 0;
-// /* This totally mucks up i18n abilities :( */
-// for (i=65; i<90; i++)
-// {
-// //if (ALPHABET[i])
-// {
-// word_list[num_words][0] = (unsigned char)i;
-// word_list[num_words][1] = '\0';
-// num_words++;
-//
-// DEBUGCODE { fprintf(stderr, "Adding %c\n", (unsigned char)i); }
-// }
-// }
-// /* Make sure list is terminated with null character */
-// word_list[num_words][0] = '\0';
-//
-// /* Make list of all unicode characters used in word list: */
-// gen_char_list();
-//
-// DOUT(num_words);
-// LOG("Leaving UseAlphabet()\n");
-// }
+
/* GetWord: returns a random word that wasn't returned
* the previous time (unless there is only 1 word!!!)
*/
@@ -1224,23 +915,23 @@
break;
case '5':strcpy(keyboard_entry->keyname,"A05");
keyboard_entry->shift=0;
- keyboard_entry->finger=4;
+ keyboard_entry->finger=3;
break;
case '%':strcpy(keyboard_entry->keyname,"A05");
keyboard_entry->shift=2;
- keyboard_entry->finger=4;
+ keyboard_entry->finger=3;
break;
case '6':strcpy(keyboard_entry->keyname,"A06");
keyboard_entry->shift=0;
- keyboard_entry->finger=5;
+ keyboard_entry->finger=6;
break;
case '^':strcpy(keyboard_entry->keyname,"A06");
keyboard_entry->shift=1;
- keyboard_entry->finger=5;
+ keyboard_entry->finger=6;
break;
case '7':strcpy(keyboard_entry->keyname,"A07");
keyboard_entry->shift=0;
- keyboard_entry->finger=7;
+ keyboard_entry->finger=6;
break;
case '&':strcpy(keyboard_entry->keyname,"A07");
keyboard_entry->shift=1;
@@ -1328,19 +1019,19 @@
break;
case 't':strcpy(keyboard_entry->keyname,"B05");
keyboard_entry->shift=0;
- keyboard_entry->finger=4;
+ keyboard_entry->finger=3;
break;
case 'T':strcpy(keyboard_entry->keyname,"B05");
keyboard_entry->shift=2;
- keyboard_entry->finger=4;
+ keyboard_entry->finger=3;
break;
case 'y':strcpy(keyboard_entry->keyname,"B06");
keyboard_entry->shift=0;
- keyboard_entry->finger=5;
+ keyboard_entry->finger=6;
break;
case 'Y':strcpy(keyboard_entry->keyname,"B06");
keyboard_entry->shift=1;
- keyboard_entry->finger=5;
+ keyboard_entry->finger=6;
break;
case 'u':strcpy(keyboard_entry->keyname,"B07");
keyboard_entry->shift=0;
@@ -1424,19 +1115,19 @@
break;
case 'g':strcpy(keyboard_entry->keyname,"C05");
keyboard_entry->shift=0;
- keyboard_entry->finger=4;
+ keyboard_entry->finger=3;
break;
case 'G':strcpy(keyboard_entry->keyname,"C05");
keyboard_entry->shift=1;
- keyboard_entry->finger=4;
+ keyboard_entry->finger=3;
break;
case 'h':strcpy(keyboard_entry->keyname,"C06");
keyboard_entry->shift=0;
- keyboard_entry->finger=5;
+ keyboard_entry->finger=6;
break;
case 'H':strcpy(keyboard_entry->keyname,"C06");
keyboard_entry->shift=1;
- keyboard_entry->finger=5;
+ keyboard_entry->finger=6;
break;
case 'j':strcpy(keyboard_entry->keyname,"C07");
keyboard_entry->shift=0;
@@ -1512,19 +1203,19 @@
break;
case 'b':strcpy(keyboard_entry->keyname,"D05");
keyboard_entry->shift=0;
- keyboard_entry->finger=4;
+ keyboard_entry->finger=3;
break;
case 'B':strcpy(keyboard_entry->keyname,"D05");
keyboard_entry->shift=2;
- keyboard_entry->finger=4;
+ keyboard_entry->finger=3;
break;
case 'n':strcpy(keyboard_entry->keyname,"D06");
keyboard_entry->shift=0;
- keyboard_entry->finger=5;
+ keyboard_entry->finger=6;
break;
case 'N':strcpy(keyboard_entry->keyname,"D06");
keyboard_entry->shift=1;
- keyboard_entry->finger=5;
+ keyboard_entry->finger=6;
break;
case 'm':strcpy(keyboard_entry->keyname,"D07");
keyboard_entry->shift=0;
@@ -1628,6 +1319,8 @@
TTF_CloseFont(smallfont);
DEBUGCODE { printf("Leaving GenerateKeyboard\n"); }
}
+
+
void updatekeylist(int key,char ch)
{
wchar_t;
@@ -1635,6 +1328,8 @@
wchar_t wtmp=ch;
map_keys(wtmp,&keyboard_list[key]);
}
+
+
void savekeyboard(void)
{
unsigned char fn[FNLEN];
@@ -1818,6 +1513,3 @@
keyboard_list[i].finger = -1;
}
}
-
-
-
Deleted: tuxtype/trunk/src/gettext.c
===================================================================
Modified: tuxtype/trunk/src/laser.c
===================================================================
--- tuxtype/trunk/src/laser.c 2008-09-08 11:36:51 UTC (rev 752)
+++ tuxtype/trunk/src/laser.c 2008-09-13 03:18:47 UTC (rev 753)
@@ -615,24 +615,29 @@
MusicPlay(musics[MUS_GAME + (rand() % NUM_MUSICS)], 0);
/* Pause (keep frame-rate event) */
-
+ DEBUGCODE
+ {
+ fprintf(stderr, "now_time = %d\tlast_time = %d, elapsed time = %d\n",
+ now_time, last_time, now_time - last_time);
+ }
+
now_time = SDL_GetTicks();
if (now_time < last_time + FPS)
SDL_Delay(last_time + FPS - now_time);
}
- while (!done && !quit);
+ while (!done && !quit);
/* Free backgrounds: */
FreeBothBkgds();
- /* Stop music: */
- if ((settings.sys_sound) && (Mix_PlayingMusic()))
- Mix_HaltMusic();
-
- laser_unload_data();
-
- return 1;
+ /* Stop music: */
+ if ((settings.sys_sound) && (Mix_PlayingMusic()))
+ Mix_HaltMusic();
+
+ laser_unload_data();
+
+ return 1;
}
Modified: tuxtype/trunk/src/playgame.c
===================================================================
--- tuxtype/trunk/src/playgame.c 2008-09-08 11:36:51 UTC (rev 752)
+++ tuxtype/trunk/src/playgame.c 2008-09-13 03:18:47 UTC (rev 753)
@@ -134,6 +134,7 @@
int temp_text_frames;
int temp_text_count;
Uint16 key_unicode;
+ Uint32 last_time, now_time;
DEBUGCODE
{
@@ -251,6 +252,8 @@
while (playing_level)
{
+ last_time = SDL_GetTicks();
+
oldlives = curlives;
oldfish_left = fish_left;
@@ -395,10 +398,31 @@
{
/* This does all the blits that we have queued up this frame: */
UpdateScreen(&frame);
+ }
- if (!settings.speed_up)
- WaitFrame();
+ /* Pause (keep frame-rate event) */
+ now_time = SDL_GetTicks();
+
+ DEBUGCODE
+ {
+ fprintf(stderr, "now_time = %d\tlast_time = %d, elapsed time = %d\n",
+ now_time, last_time, now_time - last_time);
}
+
+ if (now_time < last_time + 1000/FRAMES_PER_SEC)
+ {
+ //Prevent any possibility of a time wrap-around
+ // (this is a very unlikely problem unless there is an SDL bug
+ // or you leave tuxmath running for 49 days...)
+ now_time = (last_time + 1000/FRAMES_PER_SEC) - now_time; // this holds the delay
+ if (now_time > 1000/FRAMES_PER_SEC)
+ now_time = 1000/FRAMES_PER_SEC;
+ SDL_Delay(now_time);
+ }
+ else
+ {
+ fprintf(stderr, "Did not achieve desired frame rate!\n");
+ }
} /* End per-frame game loop - level completed */
@@ -861,14 +885,14 @@
{
if (blits[i].type == 'E')
{
- DEBUGCODE
- {
- fprintf(stderr, "Erasing blits[%d]\n", i);
- fprintf(stderr, "srcrect->x = %d\t srcrect->y = %d\t srcrect->w = %d\t srcrect->h = %d\n",
- blits[i].srcrect->x, blits[i].srcrect->y, blits[i].srcrect->w, blits[i].srcrect->h);
- fprintf(stderr, "dstrect->x = %d\t dstrect->y = %d\t dstrect->w = %d\t dstrect->h = %d\n",
- blits[i].dstrect->x, blits[i].dstrect->y, blits[i].dstrect->w, blits[i].dstrect->h);
- }
+// DEBUGCODE
+// {
+// fprintf(stderr, "Erasing blits[%d]\n", i);
+// fprintf(stderr, "srcrect->x = %d\t srcrect->y = %d\t srcrect->w = %d\t srcrect->h = %d\n",
+// blits[i].srcrect->x, blits[i].srcrect->y, blits[i].srcrect->w, blits[i].srcrect->h);
+// fprintf(stderr, "dstrect->x = %d\t dstrect->y = %d\t dstrect->w = %d\t dstrect->h = %d\n",
+// blits[i].dstrect->x, blits[i].dstrect->y, blits[i].dstrect->w, blits[i].dstrect->h);
+// }
SDL_LowerBlit(blits[i].src, blits[i].srcrect, screen, blits[i].dstrect);
}
@@ -883,14 +907,14 @@
{
if (blits[i].type == 'D')
{
- DEBUGCODE
- {
- fprintf(stderr, "drawing blits[%d]\n", i);
- fprintf(stderr, "srcrect->x = %d\t srcrect->y = %d\t srcrect->w = %d\t srcrect->h = %d\n",
- blits[i].srcrect->x, blits[i].srcrect->y, blits[i].srcrect->w, blits[i].srcrect->h);
- fprintf(stderr, "dstrect->x = %d\t dstrect->y = %d\t dstrect->w = %d\t dstrect->h = %d\n",
- blits[i].dstrect->x, blits[i].dstrect->y, blits[i].dstrect->w, blits[i].dstrect->h);
- }
+// DEBUGCODE
+// {
+// fprintf(stderr, "drawing blits[%d]\n", i);
+// fprintf(stderr, "srcrect->x = %d\t srcrect->y = %d\t srcrect->w = %d\t srcrect->h = %d\n",
+// blits[i].srcrect->x, blits[i].srcrect->y, blits[i].srcrect->w, blits[i].srcrect->h);
+// fprintf(stderr, "dstrect->x = %d\t dstrect->y = %d\t dstrect->w = %d\t dstrect->h = %d\n",
+// blits[i].dstrect->x, blits[i].dstrect->y, blits[i].dstrect->w, blits[i].dstrect->h);
+// }
SDL_BlitSurface(blits[i].src, blits[i].srcrect, screen, blits[i].dstrect);
}
Modified: tuxtype/trunk/src/practice.c
===================================================================
--- tuxtype/trunk/src/practice.c 2008-09-08 11:36:51 UTC (rev 752)
+++ tuxtype/trunk/src/practice.c 2008-09-13 03:18:47 UTC (rev 753)
@@ -24,7 +24,7 @@
#include "globals.h"
#include "funcs.h"
-static SDL_Surface* bg = NULL;
+//static SDL_Surface* bg = NULL;
static SDL_Surface* hands = NULL;
static SDL_Surface* hand_shift[3] = {NULL};
static SDL_Surface* keyboard = NULL;
@@ -56,7 +56,6 @@
/************************************************************************/
-/* FIXME this is not UTF-8/Unicode compatible */
int Phrases(wchar_t* pphrase )
{
@@ -70,32 +69,41 @@
Uint32 start = 0, a = 0;
int quit = 0,
i = 0,
- c = 0,
- wp = 0,
+ cursor = 0,
+ wrap_pt = 0,
z = 0,
total = 0,
state = 0;
- int key[100] = {0};
- int next_line=0;
- SDL_Rect dst, dst2, dst4, mydest;
- char keytime[20],
- totaltime[20];
+ int keytimes[100] = {0};
+ int next_line = 0;
+
+ /* Locations to draw strings: */
+ SDL_Rect user_text_rect;
+ SDL_Rect keytime_rect;
+ SDL_Rect totaltime_rect;
+ SDL_Rect congrats_rect;
+ SDL_Rect mydest;
+
+ char keytime_str[20],
+ totaltime_str[20];
SDL_Surface* srfc = NULL;
- SDL_Surface* tmpsurf = NULL;
-
+ SDL_Surface* tmpsurf = NULL;
+
+
if (!practice_load_media())
{
fprintf(stderr, "Phrases() - practice_load_media() failed, returning.\n");
return 0;
}
- SDL_BlitSurface(bg, NULL, screen, NULL);
+ SDL_BlitSurface(CurrentBkgd(), NULL, screen, NULL);
SDL_BlitSurface(keyboard, NULL, screen, &keyboard_loc);
- SDL_BlitSurface(screen, NULL, bg, NULL);
SDL_BlitSurface(hands, NULL, screen, &hand_loc);
SDL_Flip(screen);
- wp = get_phrase(pphrase);
+ /* FIXME get_phrase() does the blitting of the phrase to the screen - this */
+ /* is utterly perverse! */
+ wrap_pt = get_phrase(pphrase);
if (!wcsncmp(phrase[0], (wchar_t*)"", 1))
wcsncpy(pphrase, phrase[0], 80);
@@ -108,30 +116,35 @@
return 0;
}
- dst.x = 320 - (srfc->w/2);
- dst.y = 100;
- dst.w = srfc->w;
- dst.h = srfc->h;
+ /* FIXME Do these locations even need w and h???????? */
+ user_text_rect.x = 40;
+ user_text_rect.y = 100;
+// user_text_rect.w = srfc->w;
+// user_text_rect.h = srfc->h;
- dst2.x = 50;
- dst2.y = 400;
- dst2.w = srfc->w;
- dst2.h = srfc->h;
+ keytime_rect.x = 50;
+ keytime_rect.y = screen->h - 80;
+// keytime_rect.w = srfc->w;
+// keytime_rect.h = srfc->h;
- dst4.x = 480;
- dst4.y = 400;
- dst4.w = 240;
- dst4.h = 50;
+ totaltime_rect.x = screen->w - 160;
+ totaltime_rect.y = screen->h - 80;
+// totaltime_rect.w = 240;
+// totaltime_rect.h = 50;
- dst.x = 40;
+ congrats_rect.x = screen->w/2;
+ congrats_rect.y = 200;//screen->h - 80;
+ /* This is just a rectangle to redraw everything from the user's text on down: */
mydest.x = 0;
- mydest.y = dst.y;
+ mydest.y = user_text_rect.y;
mydest.w = screen->w;
mydest.h = screen->h-mydest.y;
start = SDL_GetTicks();
+
+ /* Begin main event loop for "Practice" activity: -------- */
do
{
switch (state)
@@ -149,21 +162,24 @@
/* Show finger hint, if available. Note that GetFinger() */
/* returns negative values on error and never returns a */
/* value greater than 9. */
- int key = GetIndex(pphrase[c]);
+ int key = GetIndex(pphrase[cursor]);
int fing = GetFinger(key);
int shift = GetShift(key);
keypress1= GetKeypress1(key);
keypress2= GetKeypress2(key);
+
if (!keypress1)
{
- fprintf(stderr, "Phrases() - GetKeypress1 failed, returning.\n");
- return 0;
+ fprintf(stderr, "Phrases() - GetKeypress1 failed, returning.\n");
+ return 0;
}
+
if(!keypress2)
{
- fprintf(stderr, "Phrases() - GetKeypress2 failed, returning.\n");
- return 0;
+ fprintf(stderr, "Phrases() - GetKeypress2 failed, returning.\n");
+ return 0;
}
+
SDL_BlitSurface(hands, NULL, screen, &hand_loc);
if (fing >= 0)
SDL_BlitSurface(hand[fing], NULL, screen, &hand_loc);
@@ -184,317 +200,360 @@
break;
case 3:
- SDL_BlitSurface(hands, NULL, screen, &hand_loc);
- SDL_BlitSurface(keyboard, NULL, screen, &keyboard_loc);
- state = 12;
- break;
+ SDL_BlitSurface(hands, NULL, screen, &hand_loc);
+ SDL_BlitSurface(keyboard, NULL, screen, &keyboard_loc);
+ state = 12;
+ break;
case 4:
+ {
+ int key = GetIndex(pphrase[cursor]);
+ int fing = GetFinger(key);
+ int shift = GetShift(key);
+ keypress1= GetKeypress1(key);
+ keypress2= GetKeypress2(key);
+
+ if (!keypress1)
{
- int key = GetIndex(pphrase[c]);
- int fing = GetFinger(key);
- int shift = GetShift(key);
- keypress1= GetKeypress1(key);
- keypress2= GetKeypress2(key);
- if (!keypress1)
- {
- fprintf(stderr, "Phrases() - GetKeypress1 failed, returning.\n");
- return 0;
- }
- if(!keypress2)
- {
- fprintf(stderr, "Phrases() - GetKeypress2 failed, returning.\n");
- return 0;
- }
- SDL_BlitSurface(hands, NULL, screen, &hand_loc);
- if (fing >= 0)
- SDL_BlitSurface(hand[fing], NULL, screen, &hand_loc);
- SDL_BlitSurface(hand_shift[shift], NULL, screen, &hand_loc);
- SDL_BlitSurface(keypress1, NULL, screen, &keyboard_loc);
- SDL_BlitSurface(keypress2, NULL, screen, &keyboard_loc);
- SDL_FreeSurface(keypress1);
- SDL_FreeSurface(keypress2);
- state = 11;
- break;
+ fprintf(stderr, "Phrases() - GetKeypress1 failed, returning.\n");
+ return 0;
}
+ if(!keypress2)
+ {
+ fprintf(stderr, "Phrases() - GetKeypress2 failed, returning.\n");
+ return 0;
+ }
+
+ SDL_BlitSurface(hands, NULL, screen, &hand_loc);
+ if (fing >= 0)
+ SDL_BlitSurface(hand[fing], NULL, screen, &hand_loc);
+ SDL_BlitSurface(hand_shift[shift], NULL, screen, &hand_loc);
+ SDL_BlitSurface(keypress1, NULL, screen, &keyboard_loc);
+ SDL_BlitSurface(keypress2, NULL, screen, &keyboard_loc);
+ SDL_FreeSurface(keypress1);
+ SDL_FreeSurface(keypress2);
+ state = 11;
+ break;
+ }
+
default:
state -= 2; // this is to make the flashing slower
- }
- next_letter(pphrase, c);
+ } /* ----------- End of switch(state) statement-------------- */
+
+ /* This blits "Next letter %c" onto the screen - confusing! */
+ next_letter(pphrase, cursor);
+
while (SDL_PollEvent(&event))
{
if (event.type == SDL_KEYDOWN)
{
+ int key = GetIndex((wchar_t)event.key.keysym.unicode);
+ int shift_pressed = event.key.keysym.mod&KMOD_SHIFT;
+ char tmp = -1;
+
+ /* TODO I must be missing something - why aren't we just looking at */
+ /* the event.key.keysym.unicode value instead of going through this */
+ /* giant switch statement? */
+
+ switch(event.key.keysym.sym)
+ {
+ case SDLK_ESCAPE:
+ quit = 1;
+ break;
+
+ case SDLK_DOWN: //practice next phase in list
+ quit = 2;
+ break;
+
+ case SDLK_BACKQUOTE:
+ if(shift_pressed)
+ tmp='~';
+ else
+ tmp='`';
+ break;
+
+ case SDLK_COMMA:
+ if(shift_pressed)
+ tmp='<';
+ else
+ tmp=',';
+ break;
+
+ case SDLK_MINUS:
+ if(shift_pressed)
+ tmp='_';
+ else
+ tmp='-';
+ break;
+
+ case SDLK_PERIOD:
+ if(shift_pressed)
+ tmp='>';
+ else
+ tmp='.';
+ break;
+
+ case SDLK_SLASH:
+ if(shift_pressed)
+ tmp='?';
+ else
+ tmp='/';
+ break;
+
+ case SDLK_0:
+ if(shift_pressed)
+ tmp=')';
+ else
+ tmp='0';
+ break;
+
+ case SDLK_1:
+ if(shift_pressed)
+ tmp='!';
+ else
+ tmp='1';
+ break;
+
+ case SDLK_2:
+ if(shift_pressed)
+ tmp='@';
+ else
+ tmp='2';
+ break;
+
+ case SDLK_3:
+ if(shift_pressed)
+ tmp='#';
+ else
+ tmp='3';
+ break;
+
+ case SDLK_4:
+ if(shift_pressed)
+ tmp='$';
+ else
+ tmp='4';
+ break;
+
+ case SDLK_5:
+ if(shift_pressed)
+ tmp='%';
+ else
+ tmp='5';
+ break;
+
+ case SDLK_6:
+ if(shift_pressed)
+ tmp='^';
+ else
+ tmp='6';
+ break;
+
+ case SDLK_7:
+ if(shift_pressed)
+ tmp='&';
+ else
+ tmp='7';
+ break;
+
+ case SDLK_8:
+ if(shift_pressed)
+ tmp='*';
+ else
+ tmp='8';
+ break;
+
+ case SDLK_9:
+ if(shift_pressed)
+ tmp='(';
+ else
+ tmp='9';
+ break;
+
+ case SDLK_SEMICOLON:
+ if(shift_pressed)
+ tmp=':';
+ else
+ tmp=';';
+ break;
+
+ case SDLK_EQUALS:
+ if(shift_pressed)
+ tmp='+';
+ else
+ tmp='=';
+ break;
+
+ case SDLK_LEFTBRACKET:
+ if(shift_pressed)
+ tmp='{';
+ else
+ tmp='[';
+ break;
+
+ case SDLK_BACKSLASH:
+ if(shift_pressed)
+ tmp='|';
+ else
+ tmp='\\';
+ break;
+
+ case SDLK_RIGHTBRACKET:
+ if(shift_pressed)
+ tmp='}';
+ else
+ tmp=']';
+ break;
+
+ case SDLK_QUOTE:
+ if(shift_pressed)
+ tmp='"';
+ else
+ tmp='\'';
+ break;
+
+ case SDLK_SPACE: tmp=' '; break;
+ case SDLK_a: tmp='a'; break;
+ case SDLK_b: tmp='b'; break;
+ case SDLK_c: tmp='c'; break;
+ case SDLK_d: tmp='d'; break;
+ case SDLK_e: tmp='e'; break;
+ case SDLK_f: tmp='f'; break;
+ case SDLK_g: tmp='g'; break;
+ case SDLK_h: tmp='h'; break;
+ case SDLK_i: tmp='i'; break;
+ case SDLK_j: tmp='j'; break;
+ case SDLK_k: tmp='k'; break;
+ case SDLK_l: tmp='l'; break;
+ case SDLK_m: tmp='m'; break;
+ case SDLK_n: tmp='n'; break;
+ case SDLK_o: tmp='o'; break;
+ case SDLK_p: tmp='p'; break;
+ case SDLK_q: tmp='q'; break;
+ case SDLK_r: tmp='r'; break;
+ case SDLK_s: tmp='s'; break;
+ case SDLK_t: tmp='t'; break;
+ case SDLK_u: tmp='u'; break;
+ case SDLK_v: tmp='v'; break;
+ case SDLK_w: tmp='w'; break;
+ case SDLK_x: tmp='x'; break;
+ case SDLK_y: tmp='y'; break;
+ case SDLK_z: tmp='z'; break;
+ }
+
+ /* Change to uppercase if shift used */
+ if(shift_pressed)
+ tmp=toupper(tmp);
+ updatekeylist(key,tmp);
+
+ /* Record elapsed time for this keypress and update running total: */
a = SDL_GetTicks();
- key[c] = a - start;
- total += key[c];
- sprintf(keytime, "%.2f", (float) key[c] / 1000);
- sprintf(totaltime, "%.2f", (float) total / 1000);
+ keytimes[cursor] = a - start;
+ total += keytimes[cursor];
+ sprintf(keytime_str, "%.2f", (float) keytimes[cursor] / 1000);
+ sprintf(totaltime_str, "%.2f", (float) total / 1000);
start = a;
- if (event.key.keysym.sym == SDLK_ESCAPE)
- quit = 1;
- else
- if (event.key.keysym.sym == SDLK_DOWN)
+
+ /****************************************************/
+ /* ---------- If user typed correct character, handle it: --------------- */
+ if (pphrase[cursor] == event.key.keysym.unicode)
{
- //practice next phase in list
- quit = 2;
- }
- else
- {
-/**************************************************/
- int key=GetIndex((wchar_t)event.key.keysym.unicode);
- char tmp=-1;
- switch(event.key.keysym.sym)
- {
- case SDLK_BACKQUOTE:
- if(event.key.keysym.mod&KMOD_SHIFT)
- tmp='~';
- else
- tmp='`';
- break;
- case SDLK_COMMA:
- if(event.key.keysym.mod&KMOD_SHIFT)
- tmp='<';
- else
- tmp=',';
- break;
- case SDLK_MINUS:
- if(event.key.keysym.mod&KMOD_SHIFT)
- tmp='_';
- else
- tmp='-';
- break;
- case SDLK_PERIOD:
- if(event.key.keysym.mod&KMOD_SHIFT)
- tmp='>';
- else
- tmp='.';
- break;
- case SDLK_SLASH:
- if(event.key.keysym.mod&KMOD_SHIFT)
- tmp='?';
- else
- tmp='/';
- break;
- case SDLK_0:
- if(event.key.keysym.mod&KMOD_SHIFT)
- tmp=')';
- else
- tmp='0';
- break;
- case SDLK_1:
- if(event.key.keysym.mod&KMOD_SHIFT)
- tmp='!';
- else
- tmp='1';
- break;
- case SDLK_2:
- if(event.key.keysym.mod&KMOD_SHIFT)
- tmp='@';
- else
- tmp='2';
- break;
- case SDLK_3:
- if(event.key.keysym.mod&KMOD_SHIFT)
- tmp='#';
- else
- tmp='3';
- break;
- case SDLK_4:
- if(event.key.keysym.mod&KMOD_SHIFT)
- tmp='$';
- else
- tmp='4';
- break;
- case SDLK_5:
- if(event.key.keysym.mod&KMOD_SHIFT)
- tmp='%';
- else
- tmp='5';
- break;
- case SDLK_6:
- if(event.key.keysym.mod&KMOD_SHIFT)
- tmp='^';
- else
- tmp='6';
- break;
- case SDLK_7:
- if(event.key.keysym.mod&KMOD_SHIFT)
- tmp='&';
- else
- tmp='7';
- break;
- case SDLK_8:
- if(event.key.keysym.mod&KMOD_SHIFT)
- tmp='*';
- else
- tmp='8';
- break;
- case SDLK_9:
- if(event.key.keysym.mod&KMOD_SHIFT)
- tmp='(';
- else
- tmp='9';
- break;
- case SDLK_SEMICOLON:
- if(event.key.keysym.mod&KMOD_SHIFT)
- tmp=':';
- else
- tmp=';';
- break;
- case SDLK_EQUALS:
- if(event.key.keysym.mod&KMOD_SHIFT)
- tmp='+';
- else
- tmp='=';
- break;
- case SDLK_LEFTBRACKET:
- if(event.key.keysym.mod&KMOD_SHIFT)
- tmp='{';
- else
- tmp='[';
- break;
- case SDLK_BACKSLASH:
- if(event.key.keysym.mod&KMOD_SHIFT)
- tmp='|';
- else
- tmp='\\';
- break;
- case SDLK_RIGHTBRACKET:
- if(event.key.keysym.mod&KMOD_SHIFT)
- tmp='}';
- else
- tmp=']';
- break;
- case SDLK_QUOTE:
- if(event.key.keysym.mod&KMOD_SHIFT)
- tmp='"';
- else
- tmp='\'';
- break;
- case SDLK_SPACE:tmp=' ';
- break;
- case SDLK_a:tmp='a';
- break;
- case SDLK_b:tmp='b';
- break;
- case SDLK_c:tmp='c';
- break;
- case SDLK_d:tmp='d';
- break;
- case SDLK_e:tmp='e';
- break;
- case SDLK_f:tmp='f';
- break;
- case SDLK_g:tmp='g';
- break;
- case SDLK_h:tmp='h';
- break;
- case SDLK_i:tmp='i';
- break;
- case SDLK_j:tmp='j';
- break;
- case SDLK_k:tmp='k';
- break;
- case SDLK_l:tmp='l';
- break;
- case SDLK_m:tmp='m';
- break;
- case SDLK_n:tmp='n';
- break;
- case SDLK_o:tmp='o';
- break;
- case SDLK_p:tmp='p';
- break;
- case SDLK_q:tmp='q';
- break;
- case SDLK_r:tmp='r';
- break;
- case SDLK_s:tmp='s';
- break;
- case SDLK_t:tmp='t';
- break;
- case SDLK_u:tmp='u';
- break;
- case SDLK_v:tmp='v';
- break;
- case SDLK_w:tmp='w';
- break;
- case SDLK_x:tmp='x';
- break;
- case SDLK_y:tmp='y';
- break;
- case SDLK_z:tmp='z';
- break;
- }
- if(event.key.keysym.mod&KMOD_SHIFT)
- tmp=toupper(tmp);
- updatekeylist(key,tmp);
-/****************************************************/
- if (pphrase[c]==event.key.keysym.unicode)
+ cursor++;
+ state = 0;
+
+ if (cursor == wrap_pt + 2) /* wrap onto next line */
{
- c++;
- state = 0;
- dst2.x = 40;
- dst4.x = 480;
-
- if (c==wp+2){
- //c++;
- dst.x=40;
- dst.y=dst.y+dst.h;
- mydest.y=dst.y;
- mydest.h=screen->h-mydest.y;
- next_line=1;
- }
- SDL_BlitSurface(bg, &mydest, screen, &mydest);
- SDL_Flip(screen);
- if(!next_line)
- tmpsurf = BlackOutline_w(pphrase, font, &white, c);
- else
- tmpsurf = BlackOutline_w(pphrase+wp+1, font, &white, c-(wp+1));
- SDL_BlitSurface(tmpsurf, NULL, screen, &dst);
- SDL_FreeSurface(tmpsurf);
- tmpsurf = NULL;
- tmpsurf = BlackOutline(keytime, font, &white);
- SDL_BlitSurface(tmpsurf, NULL, screen, &dst2);
- SDL_FreeSurface(tmpsurf);
- tmpsurf = NULL;
- tmpsurf = BlackOutline(totaltime, font, &white);
- SDL_BlitSurface(tmpsurf, NULL, screen, &dst4);
- SDL_FreeSurface(tmpsurf);
- tmpsurf = NULL;
- if (c==(wcslen(pphrase))){
- wchar_t buf[10];
- ConvertFromUTF8(buf, gettext("Great!"));
- print_at(buf, wcslen(buf), 275, 200);
- SDL_Flip(screen);
- SDL_Delay(2500);
- next_line=0;
- quit=2;
- }
- }
+ user_text_rect.x = 40;
+ user_text_rect.y = user_text_rect.y + user_text_rect.h;
+ mydest.y = user_text_rect.y;
+ mydest.h = screen->h - mydest.y;
+ next_line = 1;
+ }
+
+ /* Redraw everything below any "completed" lines of input text: */
+ SDL_BlitSurface(CurrentBkgd(), &mydest, screen, &mydest);
+ SDL_Flip(screen);
+
+ if(!next_line)
+ tmpsurf = BlackOutline_w(pphrase, font, &white, cursor);
else
+ tmpsurf = BlackOutline_w(pphrase + wrap_pt + 1,
+ font, &white,
+ cursor - (wrap_pt + 1));
+ if (tmpsurf)
{
- int key = GetIndex((wchar_t)event.key.keysym.unicode);
- keypress1= GetWrongKeypress(key);
- SDL_BlitSurface(keypress1, NULL, screen, &keyboard_loc);
- SDL_FreeSurface(keypress1);
- state=0;
-
- if (event.key.keysym.sym != SDLK_RSHIFT
- && event.key.keysym.sym != SDLK_LSHIFT)
- PlaySound(wrong);
+ SDL_BlitSurface(tmpsurf, NULL, screen, &user_text_rect);
+ SDL_FreeSurface(tmpsurf);
+ tmpsurf = NULL;
}
+
+
+ /* Draw strings for time displays: */
+ tmpsurf = BlackOutline(keytime_str, font, &white);
+ if (tmpsurf)
+ {
+ SDL_BlitSurface(tmpsurf, NULL, screen, &keytime_rect);
+ SDL_FreeSurface(tmpsurf);
+ tmpsurf = NULL;
+ }
+
+ tmpsurf = BlackOutline(totaltime_str, font, &white);
+ if (tmpsurf)
+ {
+ SDL_BlitSurface(tmpsurf, NULL, screen, &totaltime_rect);
+ SDL_FreeSurface(tmpsurf);
+ tmpsurf = NULL;
+ }
+
+ if (cursor==(wcslen(pphrase)))
+ {
+ tmpsurf = BlackOutline(gettext("Great!"), font, &white);
+ if (tmpsurf)
+ {
+ /* Center message on intended point: */
+ int save_x = congrats_rect.x;
+ congrats_rect.x -= tmpsurf->w/2;
+ SDL_BlitSurface(tmpsurf, NULL, screen, &congrats_rect);
+ SDL_FreeSurface(tmpsurf);
+ tmpsurf = NULL;
+ /* reset rect to prior value: */
+ congrats_rect.x = save_x;
+ }
+
+ SDL_Flip(screen);
+ SDL_Delay(2500);
+ next_line = 0;
+ quit = 2;
+ }
}
- }
- }
+ else /* -------- handle incorrect key press: -------------*/
+ {
+ int key = GetIndex((wchar_t)event.key.keysym.unicode);
+ keypress1= GetWrongKeypress(key);
+
+ if (keypress1) // avoid segfault if NULL
+ {
+ SDL_BlitSurface(keypress1, NULL, screen, &keyboard_loc);
+ SDL_FreeSurface(keypress1);
+ }
+ state=0;
+
+ if (event.key.keysym.sym != SDLK_RSHIFT
+ && event.key.keysym.sym != SDLK_LSHIFT)
+ PlaySound(wrong);
+ }
+
+ } /* End of "if(event.type == SDL_KEYDOWN)" block --*/
+
+ } /* ----- End of SDL_PollEvent() loop -------------- */
+
SDL_Flip(screen);
- SDL_Delay(30);
+ SDL_Delay(30); /* FIXME should keep frame rate constant */
- }while (!quit);
+ }while (!quit); /* ------- End of main event loop ------------- */
savekeyboard();
@@ -521,13 +580,14 @@
DEBUGCODE { printf("Entering practice_load_media\n"); }
LOG("Loading practice media\n");
+ LoadBothBkgds("main_bkg.png");
hands = LoadImage("hands/hands.png", IMG_ALPHA);
- hand_shift[0] = LoadImage("hands/none.png", IMG_ALPHA);
- hand_shift[1] = LoadImage("hands/lshift.png", IMG_ALPHA);
- hand_shift[2] = LoadImage("hands/rshift.png", IMG_ALPHA);
- keyboard = LoadImage("keyboard/keyboard.png", IMG_ALPHA);
- bg = LoadImage("main_bkg.png", IMG_ALPHA);
+ hand_shift[0] = LoadImage("hands/none.png", IMG_ALPHA);
+ hand_shift[1] = LoadImage("hands/lshift.png", IMG_ALPHA);
+ hand_shift[2] = LoadImage("hands/rshift.png", IMG_ALPHA);
+ keyboard = LoadImage("keyboard/keyboard.png", IMG_ALPHA);
+// bg = LoadImage("main_bkg.png", IMG_ALPHA);
wrong = LoadSound("tock.wav");
font = LoadFont(settings.theme_font_name, 30);
@@ -542,7 +602,7 @@
/* Get out if anything failed to load: */
if (load_failed
||!hands
- ||!bg
+ ||!CurrentBkgd()
||!wrong
||!font
||!keyboard
@@ -582,46 +642,59 @@
static void practice_unload_media(void)
{
- int i;
- SDL_FreeSurface(bg);
- bg = NULL;
- SDL_FreeSurface(hands);
- hands = NULL;
- for(i=0;i<3;i++)
- {
- SDL_FreeSurface(hand_shift[i]);
- hand_shift[i] = NULL;
- }
- SDL_FreeSurface(keyboard);
- keyboard = NULL;
- TTF_CloseFont(font);
- font = NULL;
- for (i=0; i<10; i++)
- {
- SDL_FreeSurface(hand[i]);
- hand[i] = NULL;
- }
-
+ int i;
- Mix_FreeChunk(wrong);
- wrong = NULL;
+ FreeBothBkgds();
+// SDL_FreeSurface(bg);
+// bg = NULL;
+
+ if (hands)
+ SDL_FreeSurface(hands);
+ hands = NULL;
+
+ for(i = 0; i < 3; i++)
+ {
+ if (hand_shift[i])
+ SDL_FreeSurface(hand_shift[i]);
+ hand_shift[i] = NULL;
+ }
+
+ if (keyboard)
+ SDL_FreeSurface(keyboard);
+ keyboard = NULL;
+
+ if (font)
+ TTF_CloseFont(font);
+ font = NULL;
+
+ for (i = 0; i < 10; i++)
+ {
+ if (hand[i])
+ SDL_FreeSurface(hand[i]);
+ hand[i] = NULL;
+ }
+
+ if (wrong)
+ Mix_FreeChunk(wrong);
+ wrong = NULL;
}
/* looks like dead code: */
static void show(unsigned char t)
{
- SDL_Rect dst;
- SDL_Surface* s = NULL;
+ SDL_Rect dst;
+ SDL_Surface* s = NULL;
- s= GetWhiteGlyph((int)t);
- if (!s)
- return;
- dst.x = 320 - (s->w/2);
- dst.y = 100;
- dst.w = s->w;
- dst.h = s->h;
- SDL_BlitSurface(s, NULL, screen, &dst);
+ s = GetWhiteGlyph((int)t);
+ if (!s)
+ return;
+
+ dst.x = 320 - (s->w/2);
+ dst.y = 100;
+ dst.w = s->w;
+ dst.h = s->h;
+ SDL_BlitSurface(s, NULL, screen, &dst);
}
@@ -630,7 +703,7 @@
{
int pc = 0; // 'phrase count' (?)
int pw[256] = { 0 };
- int wp = 0, i = 0, c = 0, z = 0;
+ int wrap_pt = 0, i = 0, cursor = 0, z = 0;
char fn[FNLEN];
int old_debug_on = settings.debug_on;
@@ -654,7 +727,7 @@
LOG("get_phrases(): trying to open phrases file\n");
pf = fopen( fn, "r" );
if (pf == NULL)
- return(wp); /* why not just 'return 0;' ??? */
+ return(wrap_pt); /* why not just 'return 0;' ??? */
/* So now copy each line into phrases array: */
while (!feof(pf) && pc < 256)
@@ -676,44 +749,44 @@
}
//Find wrapping point
- for (c = 0; c <= pc; c++)
+ for (cursor = 0; cursor <= pc; cursor++)
{
- if (pw[c] < 50) // If the phrase is less than 598 pixels wide
+ if (pw[cursor] < 50) // If the phrase is less than 598 pixels wide
{
- if (c == 0)
+ if (cursor == 0)
{
- wp = wcslen(phrase[c]);
- print_at(phrase[0], wp, 40, 10);
+ wrap_pt = wcslen(phrase[cursor]);
+ print_at(phrase[0], wrap_pt, 40, 10);
}
}
else
{
z = 0;
- wp = 0;
+ wrap_pt = 0;
- for (i = 0; i < wcslen(phrase[c]); i++)
+ for (i = 0; i < wcslen(phrase[cursor]); i++)
{
/* Should be safe (if no glyph, will have returned above) */
z ++;
- if (wp == 0 && z > 50)
+ if (wrap_pt == 0 && z > 50)
{
- wp = i - 1;
+ wrap_pt = i - 1;
break;
}
}
- for (i = wp; i >= 0; i--)
+ for (i = wrap_pt; i >= 0; i--)
{
- if (wcsncmp((wchar_t*)" ", &phrase[c][i], 1) == 0)
+ if (wcsncmp((wchar_t*)" ", &phrase[cursor][i], 1) == 0)
{
- wp = i-1;
+ wrap_pt = i-1;
break;
}
}
- if (c == 0)
+ if (cursor == 0)
{
- print_at(phrase[0], wp, 40, 10);
+ print_at(phrase[0], wrap_pt, 40, 10);
}
}
}
@@ -721,7 +794,7 @@
settings.debug_on = old_debug_on;
LOG("Leaving get_phrase()\n");
- return(wp);
+ return(wrap_pt);
}
static void print_at(const wchar_t *pphrase, int wrap, int x, int y)
More information about the Tux4kids-commits
mailing list