[Tux4kids-commits] r273 - tuxmath/trunk/src
dbruce-guest at alioth.debian.org
dbruce-guest at alioth.debian.org
Tue Sep 25 15:22:45 UTC 2007
Author: dbruce-guest
Date: 2007-09-25 15:22:45 +0000 (Tue, 25 Sep 2007)
New Revision: 273
Modified:
tuxmath/trunk/src/ConvertUTF.c
tuxmath/trunk/src/fileops.c
tuxmath/trunk/src/game.c
tuxmath/trunk/src/highscore.c
tuxmath/trunk/src/highscore.h
tuxmath/trunk/src/titlescreen.c
tuxmath/trunk/src/titlescreen.h
tuxmath/trunk/src/tuxmath.h
Log:
High score table work; improved draw_button() function;
Modified: tuxmath/trunk/src/ConvertUTF.c
===================================================================
--- tuxmath/trunk/src/ConvertUTF.c 2007-09-21 19:14:39 UTC (rev 272)
+++ tuxmath/trunk/src/ConvertUTF.c 2007-09-25 15:22:45 UTC (rev 273)
@@ -600,14 +600,20 @@
int i = 0;
ConversionResult result;
- UTF8 temp_UTF8[BUF_LENGTH] = {'\0'};
- UTF32 temp_UTF32[BUF_LENGTH] = {'\0'};
+ UTF8 temp_UTF8[BUF_LENGTH];
+ UTF32 temp_UTF32[BUF_LENGTH];
const UTF32* UTF32_Start = temp_UTF32;
const UTF32* UTF32_End = &temp_UTF32[BUF_LENGTH - 1];
UTF8* UTF8_Start = temp_UTF8;
UTF8* UTF8_End = &temp_UTF8[BUF_LENGTH - 1];
+ for (i = 0; i < BUF_LENGTH; i++)
+ {
+ temp_UTF8[i] = '\0';
+ temp_UTF32[i] = '\0';
+ }
+
wcsncpy((wchar_t*)temp_UTF32, wide_word, BUF_LENGTH);
result = ConvertUTF32toUTF8(&UTF32_Start, UTF32_End,
Modified: tuxmath/trunk/src/fileops.c
===================================================================
--- tuxmath/trunk/src/fileops.c 2007-09-21 19:14:39 UTC (rev 272)
+++ tuxmath/trunk/src/fileops.c 2007-09-25 15:22:45 UTC (rev 273)
@@ -25,6 +25,7 @@
* Copyright: See COPYING file that comes with this distribution (briefly, GNU GPL)
*
*/
+
/* Tuxmath includes: */
#include "tuxmath.h"
#include "fileops.h"
@@ -92,9 +93,9 @@
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: */
+/* FIXME copied this prototype here because titlescreen.h */
+/* has an 'evil macro named 'rewind' that generates a name */
+/* collision with rewind() in read_config_file(): */
TTF_Font* LoadFont(const unsigned char* font_name, int font_size);
Modified: tuxmath/trunk/src/game.c
===================================================================
--- tuxmath/trunk/src/game.c 2007-09-21 19:14:39 UTC (rev 272)
+++ tuxmath/trunk/src/game.c 2007-09-25 15:22:45 UTC (rev 273)
@@ -2382,11 +2382,11 @@
/* Draw a single pixel into the surface: */
-void putpixel(SDL_Surface * surface, int x, int y, Uint32 pixel)
+void putpixel(SDL_Surface* surface, int x, int y, Uint32 pixel)
{
#ifdef PUTPIXEL_RAW
int bpp;
- Uint8 * p;
+ Uint8* p;
/* Determine bytes-per-pixel for the surface in question: */
@@ -2403,7 +2403,7 @@
/* Assuming the X/Y values are within the bounds of this surface... */
- if (x >= 0 && y >= 0 && x < surface -> w && y < surface -> h)
+ if (x >= 0 && y >= 0 && x < surface->w && y < surface->h)
{
/* Set the (correctly-sized) piece of data in the surface's RAM
to the pixel value sent in: */
Modified: tuxmath/trunk/src/highscore.c
===================================================================
--- tuxmath/trunk/src/highscore.c 2007-09-21 19:14:39 UTC (rev 272)
+++ tuxmath/trunk/src/highscore.c 2007-09-25 15:22:45 UTC (rev 273)
@@ -12,7 +12,11 @@
#include <string.h>
#include "highscore.h"
+#include "titlescreen.h"
#include "tuxmath.h"
+#include "fileops.h"
+#include "setup.h"
+#include "options.h"
typedef struct high_score_entry {
int score;
@@ -24,6 +28,564 @@
/* Local function prototypes: */
+
+
+/* Display high scores: */
+void DisplayHighScores(int level)
+{
+ int i = 0;
+ int finished = 0;
+ int tux_frame = 0;
+ Uint32 frame = 0;
+ Uint32 start = 0;
+
+ int diff_level = level;
+ int old_diff_level = -1; //So table gets refreshed first time through
+ /* Surfaces, char buffers, and rects for table: */
+ SDL_Surface* score_surfs[HIGH_SCORES_SAVED] = {NULL};
+
+ /* 10 spaces should be enough room for place and score on each line: */
+ unsigned char score_strings[HIGH_SCORES_SAVED][HIGH_SCORE_NAME_LENGTH + 10] = {{'\0'}};
+
+ SDL_Rect score_rects[HIGH_SCORES_SAVED];
+ SDL_Rect leftRect, rightRect, stopRect, TuxRect;
+
+ SDL_Rect dest,
+ Titledest,
+ cursor;
+
+ int max_width = 300;
+ int score_table_y = 100;
+ const int diff_level_y = 50;
+
+ sprite* Tux = LoadSprite("tux/bigtux", IMG_ALPHA);
+
+ /* --- Set up the rects for drawing various things: ----------- */
+
+ /* Put arrow buttons in right lower corner, inset by 20 pixels */
+ /* with a 10 pixel space between: */
+ if (images[IMG_RIGHT])
+ {
+ rightRect.w = images[IMG_RIGHT]->w;
+ rightRect.h = images[IMG_RIGHT]->h;
+ rightRect.x = screen->w - images[IMG_RIGHT]->w - 20;
+ rightRect.y = screen->h - images[IMG_RIGHT]->h - 20;
+ }
+
+ if (images[IMG_LEFT])
+ {
+ leftRect.w = images[IMG_LEFT]->w;
+ leftRect.h = images[IMG_LEFT]->h;
+ leftRect.x = rightRect.x - 10 - images[IMG_LEFT]->w;
+ leftRect.y = screen->h - images[IMG_LEFT]->h - 20;
+ }
+
+ /* Red "Stop" circle in upper right corner to go back to main menu: */
+ if (images[IMG_STOP])
+ {
+ stopRect.w = images[IMG_STOP]->w;
+ stopRect.h = images[IMG_STOP]->h;
+ stopRect.x = screen->w - images[IMG_STOP]->w;
+ stopRect.y = 0;
+ }
+
+ if (Tux && Tux->frame[0]) /* make sure sprite has at least one frame */
+ {
+ TuxRect.w = Tux->frame[0]->w;
+ TuxRect.h = Tux->frame[0]->h;
+ TuxRect.x = 0;
+ TuxRect.y = screen->h - Tux->frame[0]->h;
+ }
+
+
+ while (!finished)
+ {
+ start = SDL_GetTicks();
+
+ /* Check for user events: */
+ while (SDL_PollEvent(&event))
+ {
+ switch (event.type)
+ {
+ case SDL_QUIT:
+ {
+ cleanup();
+ }
+
+ case SDL_MOUSEBUTTONDOWN:
+ /* "Stop" button - go to main menu: */
+ {
+ if (inRect(stopRect, event.button.x, event.button.y ))
+ {
+ finished = 1;
+ tuxtype_playsound(sounds[SND_TOCK]);
+ }
+
+ /* "Left" button - go to previous page: */
+ if (inRect(leftRect, event.button.x, event.button.y))
+ {
+ if (diff_level > CADET_HIGH_SCORE)
+ {
+ diff_level--;
+ if (Opts_MenuSound())
+ {
+ tuxtype_playsound(sounds[SND_TOCK]);
+ }
+ }
+ }
+
+ /* "Right" button - go to next page: */
+ if (inRect( rightRect, event.button.x, event.button.y ))
+ {
+ if (diff_level < ACE_HIGH_SCORE)
+ {
+ diff_level++;
+ if (Opts_MenuSound())
+ {
+ tuxtype_playsound(sounds[SND_TOCK]);
+ }
+ }
+ }
+ break;
+ }
+
+
+ case SDL_KEYDOWN:
+ {
+ finished = 1;
+ tuxtype_playsound(sounds[SND_TOCK]);
+ }
+ }
+ }
+
+
+ /* If needed, redraw: */
+ if (diff_level != old_diff_level)
+ {
+ /* Draw background & title: */
+ if (images[IMG_MENU_BKG])
+ SDL_BlitSurface( images[IMG_MENU_BKG], NULL, screen, NULL );
+ if (images[IMG_MENU_TITLE])
+ SDL_BlitSurface(images[IMG_MENU_TITLE], NULL, screen, &Titledest);
+ /* Draw Tux: */
+ if (Tux && Tux->frame[0]) /* make sure sprite has at least one frame */
+ SDL_BlitSurface(Tux->frame[0], NULL, screen, &TuxRect);
+ /* Draw controls: */
+ if (images[IMG_STOP])
+ SDL_BlitSurface(images[IMG_STOP], NULL, screen, &stopRect);
+ /* Draw regular or grayed-out left arrow: */
+ if (diff_level == CADET_HIGH_SCORE)
+ {
+ if (images[IMG_LEFT_GRAY])
+ SDL_BlitSurface(images[IMG_LEFT_GRAY], NULL, screen, &leftRect);
+ }
+ else
+ {
+ if (images[IMG_LEFT])
+ SDL_BlitSurface(images[IMG_LEFT], NULL, screen, &leftRect);
+ }
+ /* Draw regular or grayed-out right arrow: */
+ if (diff_level == ACE_HIGH_SCORE)
+ {
+ if (images[IMG_RIGHT_GRAY])
+ SDL_BlitSurface(images[IMG_RIGHT_GRAY], NULL, screen, &rightRect);
+ }
+ else
+ {
+ if (images[IMG_RIGHT])
+ SDL_BlitSurface(images[IMG_RIGHT], NULL, screen, &rightRect);
+ }
+
+ /* Draw difficulty level heading: */
+ {
+ SDL_Surface* srfc = NULL;
+ SDL_Rect diffRect;
+ TTF_Font* title_font = LoadFont(DEFAULT_FONT_NAME, 32);
+
+ if (title_font)
+ srfc = black_outline(_("Hall Of Fame"), title_font, &yellow);
+ if (srfc)
+ {
+ diffRect.x = (screen->w)/2 - (srfc->w)/2;
+ diffRect.y = diff_level_y - srfc->h;
+ diffRect.w = srfc->w;
+ diffRect.h = srfc->h;
+ SDL_BlitSurface(srfc, NULL, screen, &diffRect);
+ SDL_FreeSurface(srfc);
+ srfc = NULL;
+ }
+
+ if (title_font)
+ {
+ switch (diff_level)
+ {
+ case CADET_HIGH_SCORE:
+ srfc = black_outline(_("Space Cadet"), title_font, &white);
+ break;
+ case SCOUT_HIGH_SCORE:
+ srfc = black_outline(_("Scout"), title_font, &white);
+ break;
+ case RANGER_HIGH_SCORE:
+ srfc = black_outline(_("Ranger"), title_font, &white);
+ break;
+ case ACE_HIGH_SCORE:
+ srfc = black_outline(_("Ace"), title_font, &white);
+ break;
+ default:
+ srfc = black_outline(_("Space Cadet"), title_font, &white);
+ }
+ }
+
+ if (srfc)
+ {
+ diffRect.x = (screen->w)/2 - (srfc->w)/2;
+ diffRect.y = diff_level_y;
+ diffRect.w = srfc->w;
+ diffRect.h = srfc->h;
+ SDL_BlitSurface(srfc, NULL, screen, &diffRect);
+ SDL_FreeSurface(srfc);
+ srfc = NULL;
+ }
+ }
+
+
+ /* Generate and draw desired table: */
+
+ for (i = 0; i < HIGH_SCORES_SAVED; i++)
+ {
+ /* Get data for entries: */
+ sprintf(score_strings[i],
+ "%d.\t%d\t%s",
+ i + 1, /* Add one to get common-language place number */
+ HS_Score(diff_level, i),
+ HS_Name(diff_level, i));
+
+ /* Clear out old surfaces and update: */
+ if (score_surfs[i]) /* this should not happen! */
+ SDL_FreeSurface(score_surfs[i]);
+
+ score_surfs[i] = black_outline(N_(score_strings[i]), default_font, &white);
+
+ /* Get out if black_outline() fails: */
+ if (!score_surfs[i])
+ continue;
+
+ /* Set up entries in vertical column: */
+ if (0 == i)
+ score_rects[i].y = score_table_y;
+ else
+ score_rects[i].y = score_rects[i - 1].y + score_rects[i - 1].h;
+
+ score_rects[i].x = (screen->w)/2 - max_width/2;
+ score_rects[i].h = score_surfs[i]->h;
+ score_rects[i].w = max_width;
+
+ SDL_BlitSurface(score_surfs[i], NULL, screen, &score_rects[i]);
+ SDL_FreeSurface(score_surfs[i]);
+ score_surfs[i] = NULL;
+ }
+ /* Update screen: */
+ SDL_UpdateRect(screen, 0, 0, 0, 0);
+
+ old_diff_level = diff_level;
+ }
+
+
+ /* --- make tux blink --- */
+ switch (frame % TUX6)
+ {
+ case 0: tux_frame = 1; break;
+ case TUX1: tux_frame = 2; break;
+ case TUX2: tux_frame = 3; break;
+ case TUX3: tux_frame = 4; break;
+ case TUX4: tux_frame = 3; break;
+ case TUX5: tux_frame = 2; break;
+ default: tux_frame = 0;
+ }
+
+ if (Tux && tux_frame)
+ {
+ SDL_BlitSurface(Tux->frame[tux_frame - 1], NULL, screen, &TuxRect);
+ SDL_UpdateRect(screen, TuxRect.x+37, TuxRect.y+40, 70, 45);
+ }
+
+
+ /* Wait so we keep frame rate constant: */
+ while ((SDL_GetTicks() - start) < 33)
+ {
+ SDL_Delay(20);
+ }
+ frame++;
+ } // End of while (!finished) loop
+
+ FreeSprite(Tux);
+}
+
+
+/* Display screen to allow player to enter name for high score table: */
+/* The pl_name argument *must* point to a validly allocated string array */
+/* at least three times HIGH_SCORE_NAME_LENGTH because UTF-8 is a */
+/* multibyte encoding. */
+void HighScoreNameEntry(unsigned char* pl_name)
+{
+ SDL_Surface *s1, *s2, *s3, *s4;
+ SDL_Rect loc;
+ SDL_Rect redraw_rect;
+ SDL_Rect dest,
+ Tuxdest,
+ Titledest,
+ stopRect,
+ cursor;
+
+ int redraw = 0;
+ int first_draw = 1;
+ int finished = 0;
+ int tux_frame = 0;
+ Uint32 frame = 0;
+ Uint32 start = 0;
+ char* str1, *str2, *str3, *str4;
+ wchar_t wchar_buf[HIGH_SCORE_NAME_LENGTH + 1] = {'\0'};
+ unsigned char UTF8_buf[HIGH_SCORE_NAME_LENGTH * 3] = {'\0'};
+ TTF_Font* name_font = NULL;
+ const int NAME_FONT_SIZE = 32;
+
+ sprite* Tux = LoadSprite("tux/bigtux", IMG_ALPHA);
+
+ if (!pl_name)
+ return;
+
+ 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);
+
+#ifdef TUXMATH_DEBUG
+ fprintf(stderr, "\nEnter HighScoreNameEntry()\n" );
+#endif
+
+ str1 = _("Great Score - You Are In The Hall of Fame!");
+ str2 = _("Enter Your Name:");
+
+ if (str1)
+ s1 = black_outline(str1, default_font, &white);
+ if (str2)
+ s2 = black_outline(str2, default_font, &white);
+ if (str3)
+ s3 = black_outline(str3, default_font, &white);
+ /* When we get going with i18n may need to modify following - see below: */
+ if (str4)
+ s4 = black_outline(str4, default_font, &white);
+
+
+ /* Redraw background: */
+ if (images[IMG_MENU_BKG])
+ SDL_BlitSurface( images[IMG_MENU_BKG], NULL, screen, NULL );
+
+ /* Red "Stop" circle in upper right corner to go back to main menu: */
+ if (images[IMG_STOP])
+ {
+ stopRect.w = images[IMG_STOP]->w;
+ stopRect.h = images[IMG_STOP]->h;
+ stopRect.x = screen->w - images[IMG_STOP]->w;
+ stopRect.y = 0;
+ SDL_BlitSurface(images[IMG_STOP], NULL, screen, &stopRect);
+ }
+
+ if (Tux && Tux->num_frames) /* make sure sprite has at least one frame */
+ {
+ SDL_BlitSurface(Tux->frame[0], NULL, screen, &Tuxdest);
+ }
+
+ /* Draw lines of text (do after drawing Tux so text is in front): */
+ if (s1)
+ {
+ loc.x = 320 - (s1->w/2); loc.y = 10;
+ SDL_BlitSurface( s1, NULL, screen, &loc);
+ }
+ if (s2)
+ {
+ loc.x = 320 - (s2->w/2); loc.y = 60;
+ SDL_BlitSurface( s2, NULL, screen, &loc);
+ }
+ if (s3)
+ {
+ loc.x = 320 - (s3->w/2); loc.y = 300;
+ SDL_BlitSurface( s3, NULL, screen, &loc);
+ }
+ if (s4)
+ {
+ loc.x = 320 - (s4->w/2); loc.y = 340;
+ SDL_BlitSurface( s4, NULL, screen, &loc);
+ }
+
+ /* and update: */
+ SDL_UpdateRect(screen, 0, 0, 0, 0);
+
+
+
+ while (!finished)
+ {
+ start = SDL_GetTicks();
+
+ while (SDL_PollEvent(&event))
+ {
+ switch (event.type)
+ {
+ case SDL_QUIT:
+ {
+ cleanup();
+ }
+
+ case SDL_MOUSEBUTTONDOWN:
+ /* "Stop" button - go to main menu: */
+ {
+ if (inRect(stopRect, event.button.x, event.button.y ))
+ {
+ finished = 1;
+ tuxtype_playsound(sounds[SND_TOCK]);
+ break;
+ }
+ }
+ case SDL_KEYDOWN:
+ {
+#ifdef TUXMATH_DEBUG
+ fprintf(stderr, "Before keypress, string is %S\tlength = %d\n",
+ wchar_buf, (int)wcslen(wchar_buf));
+#endif
+ switch (event.key.keysym.sym)
+ {
+ case SDLK_ESCAPE:
+ case SDLK_RETURN:
+ case SDLK_KP_ENTER:
+ {
+ finished = 1;
+ tuxtype_playsound(sounds[SND_TOCK]);
+ break;
+ }
+ case SDLK_BACKSPACE:
+ {
+ if (wcslen(wchar_buf) > 0)
+ wchar_buf[(int)wcslen(wchar_buf) - 1] = '\0';
+ redraw = 1;
+ break;
+ }
+
+
+ /* For any other keys, if the key has a Unicode value, */
+ /* we add it to our string: */
+ default:
+ {
+ if ((event.key.keysym.unicode > 0)
+ && (wcslen(wchar_buf) < HIGH_SCORE_NAME_LENGTH))
+ {
+ wchar_buf[(int)wcslen(wchar_buf)] = event.key.keysym.unicode;
+ redraw = 1;
+ }
+ }
+ } /* end 'switch (event.key.keysym.sym)' */
+
+#ifdef TUXMATH_DEBUG
+ fprintf(stderr, "After keypress, string is %S\tlength = %d\n",
+ wchar_buf, (int)wcslen(wchar_buf));
+#endif
+ /* Now draw name, if needed: */
+ if (redraw)
+ {
+ redraw = 0;
+ /* Redraw background in area where we drew text last time: */
+ if (!first_draw)
+ {
+ SDL_BlitSurface(images[IMG_MENU_BKG], &redraw_rect, screen, &redraw_rect);
+ SDL_UpdateRect(screen,
+ redraw_rect.x,
+ redraw_rect.y,
+ redraw_rect.w,
+ redraw_rect.h);
+ }
+
+ /* Convert text to UTF-8: */
+ //Unicode_to_UTF8((const wchar_t*)buf, player_name);
+ wcstombs((char*) UTF8_buf, wchar_buf, HIGH_SCORE_NAME_LENGTH * 3);
+
+ s3 = black_outline(UTF8_buf, name_font, &yellow);
+ if (s3)
+ {
+ loc.x = 320 - (s3->w/2);
+ loc.y = 300;
+ SDL_BlitSurface( s3, NULL, screen, &loc);
+
+ /* for some reason we need to update a little beyond s3 to get clean image */
+ redraw_rect.x = loc.x - 20;
+ redraw_rect.y = loc.y - 10;
+ redraw_rect.h = s3->h + 20;
+ redraw_rect.w = s3->w + 40;
+ first_draw = 0;
+
+ SDL_UpdateRect(screen,
+ redraw_rect.x,
+ redraw_rect.y,
+ redraw_rect.w,
+ redraw_rect.h);
+ SDL_FreeSurface(s3);
+ s3 = NULL;
+ }
+
+ }
+ }
+ }
+ }
+
+ /* --- make tux blink --- */
+ switch (frame % TUX6)
+ {
+ case 0: tux_frame = 1; break;
+ case TUX1: tux_frame = 2; break;
+ case TUX2: tux_frame = 3; break;
+ case TUX3: tux_frame = 4; break;
+ case TUX4: tux_frame = 3; break;
+ case TUX5: tux_frame = 2; break;
+ default: tux_frame = 0;
+ }
+
+ if (Tux && tux_frame)
+ {
+ SDL_BlitSurface(Tux->frame[tux_frame - 1], NULL, screen, &Tuxdest);
+ SDL_UpdateRect(screen, Tuxdest.x+37, Tuxdest.y+40, 70, 45);
+ }
+
+
+
+
+ /* Wait so we keep frame rate constant: */
+ while ((SDL_GetTicks() - start) < 33)
+ {
+ SDL_Delay(20);
+ }
+ frame++;
+ } // End of while (!finished) loop
+
+ SDL_FreeSurface(s1);
+ SDL_FreeSurface(s2);
+ SDL_FreeSurface(s3);
+ SDL_FreeSurface(s4);
+ TTF_CloseFont(name_font);
+ FreeSprite(Tux);
+
+ /* Turn off SDL Unicode lookup (because has some overhead): */
+ SDL_EnableUNICODE(SDL_DISABLE);
+
+ /* Now copy name into location pointed to by arg: */
+ strncpy((char*)pl_name, (char*)UTF8_buf, HIGH_SCORE_NAME_LENGTH * 3);
+}
+
+
+
+
/* Zero-out the array before use: */
void initialize_scores(void)
{
@@ -162,8 +724,11 @@
return 0;
}
+/* FIXME work-around to prevent name collision until we get rid of rewind macro */
+#undef rewind
/* make sure we start at beginning: */
rewind(fp);
+#define rewind(SPRITE) (SPRITE)->cur = 0;
/* read in a line at a time: */
while (fgets (buf, PATH_MAX, fp))
Modified: tuxmath/trunk/src/highscore.h
===================================================================
--- tuxmath/trunk/src/highscore.h 2007-09-21 19:14:39 UTC (rev 272)
+++ tuxmath/trunk/src/highscore.h 2007-09-25 15:22:45 UTC (rev 273)
@@ -16,6 +16,8 @@
#include "tuxmath.h"
+void DisplayHighScores(int level);
+void HighScoreNameEntry(unsigned char* pl_name);
int check_score_place(int diff_level, int new_score);
Modified: tuxmath/trunk/src/titlescreen.c
===================================================================
--- tuxmath/trunk/src/titlescreen.c 2007-09-21 19:14:39 UTC (rev 272)
+++ tuxmath/trunk/src/titlescreen.c 2007-09-25 15:22:45 UTC (rev 273)
@@ -51,7 +51,7 @@
} blits[MAX_UPDATES];
// Lessons available for play
-lesson_entry *lesson_list = NULL;
+lesson_entry* lesson_list = NULL;
int num_lessons = 0;
// globals from tuxtype's globals.h defined outside of titlescreen.c (in tuxtype):
@@ -130,8 +130,6 @@
SDL_Surface* sel_text[TITLE_MENU_ITEMS + 1][TITLE_MENU_DEPTH + 1] = {{NULL}};
/* reg and sel are used to create the translucent button backgrounds. */
-sprite* reg = NULL;
-sprite* sel = NULL;
sprite* Tux = NULL;
/* keep track of the width of each menu: */
@@ -157,19 +155,17 @@
cursor;
/* Local function prototypes: */
-void draw_button(SDL_Rect* target_rect, int width, sprite* s);
void TitleScreen_load_menu(void);
void TitleScreen_unload_menu(void);
void TitleScreen_load_media(void);
void TitleScreen_unload_media(void);
void NotImplemented(void);
-void HighScoreScreen(void);
-void HighScoreNameEntry(unsigned char* name_buf);
void TransWipe(SDL_Surface* newbkg, int type, int var1, int var2);
void UpdateScreen(int* frame);
void AddRect(SDL_Rect* src, SDL_Rect* dst);
void InitEngine(void);
void ShowMessage(char* str1, char* str2, char* str3, char* str4);
+void round_corners(SDL_Surface* s, Uint16 radius);
/***********************************************************/
/* */
@@ -637,11 +633,17 @@
audioMusicUnload();
game();
/* See if player made high score list! */
- if (check_score_place(ACE_HIGH_SCORE, Opts_LastScore()) < HIGH_SCORES_SAVED)
+ if (check_score_place(CADET_HIGH_SCORE, Opts_LastScore()) < HIGH_SCORES_SAVED)
{
- /* (Get name string from player) */
- insert_score("Cadet (temporary)", CADET_HIGH_SCORE, Opts_LastScore());
+ unsigned char player_name[HIGH_SCORE_NAME_LENGTH * 3];
+
+ /* Get name from player: */
+ HighScoreNameEntry(&player_name[0]);
+ insert_score(player_name, CADET_HIGH_SCORE, Opts_LastScore());
+ DisplayHighScores(CADET_HIGH_SCORE);
+ /* save to disk: */
write_high_scores();
+
#ifdef TUXMATH_DEBUG
print_high_scores(stderr);
#endif
@@ -671,11 +673,17 @@
audioMusicUnload();
game();
/* See if player made high score list! */
- if (check_score_place(ACE_HIGH_SCORE, Opts_LastScore()) < HIGH_SCORES_SAVED)
+ if (check_score_place(SCOUT_HIGH_SCORE, Opts_LastScore()) < HIGH_SCORES_SAVED)
{
- /* (Get name string from player) */
- insert_score("Scout (temporary)", SCOUT_HIGH_SCORE, Opts_LastScore());
+ unsigned char player_name[HIGH_SCORE_NAME_LENGTH * 3];
+
+ /* Get name from player: */
+ HighScoreNameEntry(&player_name[0]);
+ insert_score(player_name, SCOUT_HIGH_SCORE, Opts_LastScore());
+ DisplayHighScores(SCOUT_HIGH_SCORE);
+ /* save to disk: */
write_high_scores();
+
#ifdef TUXMATH_DEBUG
print_high_scores(stderr);
#endif
@@ -706,11 +714,17 @@
audioMusicUnload();
game();
/* See if player made high score list! */
- if (check_score_place(ACE_HIGH_SCORE, Opts_LastScore()) < HIGH_SCORES_SAVED)
+ if (check_score_place(RANGER_HIGH_SCORE, Opts_LastScore()) < HIGH_SCORES_SAVED)
{
- /* (Get name string from player) */
- insert_score("Ranger (temporary)", RANGER_HIGH_SCORE, Opts_LastScore());
+ unsigned char player_name[HIGH_SCORE_NAME_LENGTH * 3];
+
+ /* Get name from player: */
+ HighScoreNameEntry(&player_name[0]);
+ insert_score(player_name, RANGER_HIGH_SCORE, Opts_LastScore());
+ DisplayHighScores(RANGER_HIGH_SCORE);
+ /* save to disk: */
write_high_scores();
+
#ifdef TUXMATH_DEBUG
print_high_scores(stderr);
#endif
@@ -746,9 +760,15 @@
/* See if player made high score list! */
if (check_score_place(ACE_HIGH_SCORE, Opts_LastScore()) < HIGH_SCORES_SAVED)
{
- /* (Get name string from player) */
- insert_score("Ace (temporary)", ACE_HIGH_SCORE, Opts_LastScore());
+ unsigned char player_name[HIGH_SCORE_NAME_LENGTH * 3];
+
+ /* Get name from player: */
+ HighScoreNameEntry(&player_name[0]);
+ insert_score(player_name, ACE_HIGH_SCORE, Opts_LastScore());
+ DisplayHighScores(ACE_HIGH_SCORE);
+ /* save to disk: */
write_high_scores();
+
#ifdef TUXMATH_DEBUG
print_high_scores(stderr);
#endif
@@ -767,10 +787,10 @@
break;
}
- /* Go back to main menu: */
+ /* Show High Scores: */
case HIGH_SCORES:
{
- HighScoreScreen();
+ DisplayHighScores(CADET_HIGH_SCORE);
redraw = 1;
break;
}
@@ -876,14 +896,14 @@
text_dst[i].w = reg_text[i][menu_depth]->w;
text_dst[i].h = reg_text[i][menu_depth]->h;
SDL_BlitSurface(images[IMG_MENU_BKG], &menu_button[i], screen, &menu_button[i]);
- menu_button[i].w = menu_width[menu_depth] + (2 * reg->frame[2]->w);
+ menu_button[i].w = menu_width[menu_depth] + 20;
}
/* --- draw the full menu --- */
for (j = 1; j <= TITLE_MENU_ITEMS; j++)
{
- draw_button(&menu_button[j], menu_width[menu_depth], reg);
+ DrawButton(&menu_button[j], 15, REG_RGBA);
SDL_BlitSurface(reg_text[j][menu_depth], NULL, screen, &text_dst[j]);
SDL_BlitSurface(menu_sprites[j][menu_depth]->default_img, NULL, screen, &menu_sprite_dest[j]);
}
@@ -934,7 +954,7 @@
if (old_key_menu && (key_menu != old_key_menu))
{
SDL_BlitSurface(images[IMG_MENU_BKG], &menu_button[old_key_menu], screen, &menu_button[old_key_menu]);
- draw_button(&menu_button[old_key_menu], menu_width[menu_depth], reg );
+ DrawButton(&menu_button[old_key_menu], 15, REG_RGBA);
SDL_BlitSurface(reg_text[old_key_menu][menu_depth], NULL, screen, &text_dst[old_key_menu]);
SDL_BlitSurface(menu_sprites[old_key_menu][menu_depth]->default_img, NULL, screen, &menu_sprite_dest[old_key_menu]);
}
@@ -952,7 +972,7 @@
}
SDL_BlitSurface(images[IMG_MENU_BKG], &menu_button[key_menu], screen, &menu_button[key_menu]);
- draw_button(&menu_button[key_menu], menu_width[menu_depth], sel );
+ DrawButton(&menu_button[key_menu], 15, SEL_RGBA);
SDL_BlitSurface(sel_text[key_menu][menu_depth], NULL, screen, &text_dst[key_menu]);
SDL_BlitSurface(menu_sprites[key_menu][menu_depth]->frame[menu_sprites[key_menu][menu_depth]->cur], NULL, screen, &menu_sprite_dest[key_menu]);
@@ -1089,8 +1109,6 @@
// titlepic = LoadImage("title/title1.png", IMG_ALPHA);
// bkg = LoadImage( "title/main_bkg.jpg", IMG_REGULAR );
- sel = LoadSprite("sprites/sel", IMG_ALPHA);
- reg = LoadSprite("sprites/reg", IMG_ALPHA);
Tux = LoadSprite("tux/bigtux", IMG_ALPHA);
//font = LoadFont(menu_font, menu_font_size);
@@ -1144,8 +1162,7 @@
menu_button[1].w = menu_width[1]; //calc from width of widest menu item
/* Must be sure sel has been loaded before checking height: */
- if (sel && sel->frame[1])
- menu_button[1].h = sel->frame[1]->h; //height of button shading
+ menu_button[1].h = 50;//sel->frame[1]->h; //height of button shading
menu_sprite_dest[1].x = menu_button[1].x + 6; // inset graphic by (6, 4) */
menu_sprite_dest[1].y = menu_button[1].y + 4;
@@ -1181,39 +1198,121 @@
/* fill in the rect with the desired translucent color and */
/* give it nice, rounded ends. */
/* FIXME make it match target_rect more precisely */
-void draw_button(SDL_Rect* target_rect, int width, sprite* s )
+void DrawButton(SDL_Rect* target_rect, int radius, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
{
- SDL_Rect button;
+ SDL_Surface* tmp_surf = SDL_CreateRGBSurface(SDL_SWSURFACE|SDL_SRCALPHA,
+ target_rect->w,
+ target_rect->h,
+ BPP,
+ rmask, gmask, bmask, amask);
+ Uint32 color = SDL_MapRGBA(tmp_surf->format, r, g, b, a);
+ SDL_FillRect(tmp_surf, NULL, color);
+ round_corners(tmp_surf, radius);
- /* Segfault prevention: */
- if (! target_rect
- || !s
- || !s->frame[0]
- || !s->frame[1])
- {
+ SDL_BlitSurface(tmp_surf, NULL, screen, target_rect);
+ SDL_FreeSurface(tmp_surf);
+// SDL_UpdateRect(screen, 0, 0, 0, 0);
+
+ SDL_UpdateRect(screen, target_rect->x, target_rect->y, target_rect->w, target_rect->h);
+
+}
+
+void round_corners(SDL_Surface* s, Uint16 radius)
+{
+ int y = 0;
+ int x_dist, y_dist;
+ Uint32* p = NULL;
+ Uint32 alpha_mask;
+ int bytes_per_pix;
+
+ if (!s)
return;
+ if (SDL_LockSurface(s) == -1)
+ return;
+
+ bytes_per_pix = s->format->BytesPerPixel;
+ if (bytes_per_pix != 4)
+ return;
+
+ /* radius cannot be more than half of width or height: */
+ if (radius > (s->w)/2)
+ radius = (s->w)/2;
+ if (radius > (s->h)/2)
+ radius = (s->h)/2;
+
+
+ alpha_mask = s->format->Amask;
+
+ /* Now round off corners: */
+ /* upper left: */
+ for (y = 0; y < radius; y++)
+ {
+ p = (Uint32*)(s->pixels + (y * s->pitch));
+ x_dist = radius;
+ y_dist = radius - y;
+
+ while (((x_dist * x_dist) + (y_dist * y_dist)) > (radius * radius))
+ {
+ /* (make pixel (x,y) transparent) */
+ *p = *p & ~alpha_mask;
+ p++;
+ x_dist--;
+ }
}
- button.x = target_rect->x;
- button.y = target_rect->y;
- button.w = s->frame[0]->w;
- button.h = s->frame[0]->h;
+ /* upper right: */
+ for (y = 0; y < radius; y++)
+ {
+ /* start at end of top row: */
+ p = (Uint32*)(s->pixels + ((y + 1) * s->pitch) - bytes_per_pix);
- SDL_BlitSurface(s->frame[0], NULL, screen, &button);
- button.w = s->frame[1]->w;
+ x_dist = radius;
+ y_dist = radius - y;
- for (button.x += s->frame[0]->w;
- button.x < (target_rect->x + width);
- button.x += s->frame[1]->w)
+ while (((x_dist * x_dist) + (y_dist * y_dist)) > (radius * radius))
+ {
+ /* (make pixel (x,y) transparent) */
+ *p = *p & ~alpha_mask;
+ p--;
+ x_dist--;
+ }
+ }
- {
- SDL_BlitSurface(s->frame[1], NULL, screen, &button);
+ /* bottom left: */
+ for (y = (s->h - 1); y > (s->h - radius); y--)
+ {
+ /* start at beginning of bottom row */
+ p = (Uint32*)(s->pixels + (y * s->pitch));
+ x_dist = radius;
+ y_dist = y - (s->h - radius);
+
+ while (((x_dist * x_dist) + (y_dist * y_dist)) > (radius * radius))
+ {
+ /* (make pixel (x,y) transparent) */
+ *p = *p & ~alpha_mask;
+ p++;
+ x_dist--;
+ }
}
- button.w = s->frame[2]->w;
- SDL_BlitSurface(s->frame[2], NULL, screen, &button);
-}
+ /* bottom right: */
+ for (y = (s->h - 1); y > (s->h - radius); y--)
+ {
+ /* start at end of bottom row */
+ p = (Uint32*)(s->pixels + ((y + 1) * s->pitch) - bytes_per_pix);
+ x_dist = radius;
+ y_dist = y - (s->h - radius);
+ while (((x_dist * x_dist) + (y_dist * y_dist)) > (radius * radius))
+ {
+ /* (make pixel (x,y) transparent) */
+ *p = *p & ~alpha_mask;
+ p--;
+ x_dist--;
+ }
+ }
+ SDL_UnlockSurface(s);
+}
@@ -1252,8 +1351,8 @@
// SDL_FreeSurface(titlepic);
// SDL_FreeSurface(bkg);
- FreeSprite(sel);
- FreeSprite(reg);
+// FreeSprite(sel);
+// FreeSprite(reg);
FreeSprite(Tux);
@@ -1275,490 +1374,11 @@
-/* Display high scores: */
-void HighScoreScreen(void)
-{
- int i = 0;
- int finished = 0;
- int tux_frame = 0;
- Uint32 frame = 0;
- Uint32 start = 0;
- int diff_level = CADET_HIGH_SCORE;
- int old_diff_level = SCOUT_HIGH_SCORE; //So table gets refreshed first time through
- char* diff_level_name = _("Space Cadet");
- /* Surfaces, char buffers, and rects for table: */
- SDL_Surface* score_entries[HIGH_SCORES_SAVED] = {NULL};
- /* 20 spaces should be enough room for place and score on each line: */
- char score_texts[HIGH_SCORES_SAVED][HIGH_SCORE_NAME_LENGTH + 20] = {{'\0'}};
- unsigned char player_name[HIGH_SCORE_NAME_LENGTH * 3] = {'\0'};
- SDL_Rect score_rects[HIGH_SCORES_SAVED];
- SDL_Rect leftRect, rightRect;
- int score_table_x = 240;
- int score_table_y = 100;
- /* Draw background & title: */
- if (images[IMG_MENU_BKG])
- SDL_BlitSurface( images[IMG_MENU_BKG], NULL, screen, NULL );
- if (images[IMG_MENU_TITLE])
- SDL_BlitSurface(images[IMG_MENU_TITLE], NULL, screen, &Titledest);
-
- /* Put arrow buttons in right lower corner, inset by 20 pixels */
- /* with a 10 pixel space between: */
- if (images[IMG_RIGHT])
- {
- rightRect.w = images[IMG_RIGHT]->w;
- rightRect.h = images[IMG_RIGHT]->h;
- rightRect.x = screen->w - images[IMG_RIGHT]->w - 20;
- rightRect.y = screen->h - images[IMG_RIGHT]->h - 20;
- SDL_BlitSurface(images[IMG_RIGHT], NULL, screen, &rightRect);
- }
-
- if (images[IMG_LEFT])
- {
- leftRect.w = images[IMG_LEFT]->w;
- leftRect.h = images[IMG_LEFT]->h;
- leftRect.x = rightRect.x - 10 - images[IMG_LEFT]->w;
- leftRect.y = screen->h - images[IMG_LEFT]->h - 20;
- SDL_BlitSurface(images[IMG_LEFT_GRAY], NULL, screen, &leftRect);
- }
-
- /* Red "Stop" circle in upper right corner to go back to main menu: */
- if (images[IMG_STOP])
- {
- stopRect.w = images[IMG_STOP]->w;
- stopRect.h = images[IMG_STOP]->h;
- stopRect.x = screen->w - images[IMG_STOP]->w;
- stopRect.y = 0;
- SDL_BlitSurface(images[IMG_STOP], NULL, screen, &stopRect);
- }
-
- if (Tux && Tux->num_frames) /* make sure sprite has at least one frame */
- {
- SDL_BlitSurface(Tux->frame[0], NULL, screen, &Tuxdest);
- }
- SDL_UpdateRect(screen, 0, 0, 0, 0);
-
- while (!finished)
- {
- start = SDL_GetTicks();
-
- /* Check for user events: */
- while (SDL_PollEvent(&event))
- {
- switch (event.type)
- {
- case SDL_QUIT:
- {
- cleanup();
- }
-
- case SDL_MOUSEBUTTONDOWN:
- /* "Stop" button - go to main menu: */
- {
- if (inRect(stopRect, event.button.x, event.button.y ))
- {
- finished = 1;
- tuxtype_playsound(sounds[SND_TOCK]);
- }
-
- /* "Left" button - go to previous page: */
- if (inRect(leftRect, event.button.x, event.button.y))
- {
- if (diff_level > CADET_HIGH_SCORE)
- {
- diff_level--;
- if (Opts_MenuSound())
- {
- tuxtype_playsound(sounds[SND_TOCK]);
- }
- }
- }
-
- /* "Right" button - go to next page: */
- if (inRect( rightRect, event.button.x, event.button.y ))
- {
- if (diff_level < ACE_HIGH_SCORE)
- {
- diff_level++;
- if (Opts_MenuSound())
- {
- tuxtype_playsound(sounds[SND_TOCK]);
- }
- }
- }
- break;
- }
-
-
- case SDL_KEYDOWN:
- {
- finished = 1;
- tuxtype_playsound(sounds[SND_TOCK]);
- }
- }
- }
-
-
- /* If needed, redraw: */
- if (diff_level != old_diff_level)
- {
- /* Draw background & title: */
- if (images[IMG_MENU_BKG])
- SDL_BlitSurface( images[IMG_MENU_BKG], NULL, screen, NULL );
- if (images[IMG_MENU_TITLE])
- SDL_BlitSurface(images[IMG_MENU_TITLE], NULL, screen, &Titledest);
- /* Draw Tux: */
- if (Tux && Tux->num_frames) /* make sure sprite has at least one frame */
- SDL_BlitSurface(Tux->frame[0], NULL, screen, &Tuxdest);
- /* Draw controls: */
- if (images[IMG_STOP])
- SDL_BlitSurface(images[IMG_STOP], NULL, screen, &stopRect);
- /* Draw regular or grayed-out left arrow: */
- if (diff_level == CADET_HIGH_SCORE)
- {
- if (images[IMG_LEFT_GRAY])
- SDL_BlitSurface(images[IMG_LEFT_GRAY], NULL, screen, &leftRect);
- }
- else
- {
- if (images[IMG_LEFT])
- SDL_BlitSurface(images[IMG_LEFT], NULL, screen, &leftRect);
- }
- /* Draw regular or grayed-out right arrow: */
- if (diff_level == ACE_HIGH_SCORE)
- {
- if (images[IMG_RIGHT_GRAY])
- SDL_BlitSurface(images[IMG_RIGHT_GRAY], NULL, screen, &rightRect);
- }
- else
- {
- if (images[IMG_RIGHT])
- SDL_BlitSurface(images[IMG_RIGHT], NULL, screen, &rightRect);
- }
-
- /* Generate and draw desired table: */
- for (i = 0; i < HIGH_SCORES_SAVED; i++)
- {
- /* Get data for entries: */
- sprintf(score_texts[i],
- "%d.\t%d\t%s",
- i + 1, /* Add one to get common-language place number */
- HS_Score(diff_level, i),
- HS_Name(diff_level, i));
-
- /* Clear out old surfaces and update: */
- if (score_entries[i])
- SDL_FreeSurface(score_entries[i]);
-
- score_entries[i] = black_outline(N_(score_texts[i]), default_font, &white);
-
- /* Get out if black_outline() fails: */
- if (!score_entries[i])
- continue;
-
- /* Set up entries in vertical column: */
- if (0 == i)
- score_rects[i].y = score_table_y;
- else
- score_rects[i].y = score_rects[i -1].y + score_rects[i -1].h;
-
- score_rects[i].x = score_table_x;
- score_rects[i].h = score_entries[i]->h;
- score_rects[i].w = score_entries[i]->w;
-
- SDL_BlitSurface(score_entries[i], NULL, screen, &score_rects[i]);
- }
- /* Update screen: */
- SDL_UpdateRect(screen, 0, 0, 0, 0);
-
- old_diff_level = diff_level;
- }
-
-
- /* --- make tux blink --- */
- switch (frame % TUX6)
- {
- case 0: tux_frame = 1; break;
- case TUX1: tux_frame = 2; break;
- case TUX2: tux_frame = 3; break;
- case TUX3: tux_frame = 4; break;
- case TUX4: tux_frame = 3; break;
- case TUX5: tux_frame = 2; break;
- default: tux_frame = 0;
- }
-
- if (Tux && tux_frame)
- {
- SDL_BlitSurface(Tux->frame[tux_frame - 1], NULL, screen, &Tuxdest);
- SDL_UpdateRect(screen, Tuxdest.x+37, Tuxdest.y+40, 70, 45);
- }
-
-
- /* Wait so we keep frame rate constant: */
- while ((SDL_GetTicks() - start) < 33)
- {
- SDL_Delay(20);
- }
- frame++;
- } // End of while (!finished) loop
- HighScoreNameEntry(player_name);
-}
-
-/* Display screen to allow player to enter name for high score table: */
-/* The name_buf argument *must* point to a validly allocated string array */
-/* at least three times HIGH_SCORE_NAME_LENGTH because UTF-8 is a */
-/* multibyte encoding. */
-void HighScoreNameEntry(unsigned char* name_buf)
-{
- SDL_Surface *s1, *s2, *s3, *s4;
- SDL_Rect loc;
- SDL_Rect redraw_rect;
- int redraw = 0;
- int first_draw = 1;
- int finished = 0;
- int tux_frame = 0;
- Uint32 frame = 0;
- Uint32 start = 0;
- 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;
-
- 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);
-
-#ifdef TUXMATH_DEBUG
- fprintf(stderr, "\nEnter HighScoreNameEntry()\n" );
-#endif
-
- str1 = _("Great Score - You Are In The Hall of Fame!");
- str2 = _("Enter Your Name:");
-
- if (str1)
- s1 = black_outline(str1, default_font, &white);
- if (str2)
- s2 = black_outline(str2, default_font, &white);
- if (str3)
- s3 = black_outline(str3, default_font, &white);
- /* When we get going with i18n may need to modify following - see below: */
- if (str4)
- s4 = black_outline(str4, default_font, &white);
-
-
- /* Redraw background: */
- if (images[IMG_MENU_BKG])
- SDL_BlitSurface( images[IMG_MENU_BKG], NULL, screen, NULL );
-
- /* Red "Stop" circle in upper right corner to go back to main menu: */
- if (images[IMG_STOP])
- {
- stopRect.w = images[IMG_STOP]->w;
- stopRect.h = images[IMG_STOP]->h;
- stopRect.x = screen->w - images[IMG_STOP]->w;
- stopRect.y = 0;
- SDL_BlitSurface(images[IMG_STOP], NULL, screen, &stopRect);
- }
-
- if (Tux && Tux->num_frames) /* make sure sprite has at least one frame */
- {
- SDL_BlitSurface(Tux->frame[0], NULL, screen, &Tuxdest);
- }
-
- /* Draw lines of text (do after drawing Tux so text is in front): */
- if (s1)
- {
- loc.x = 320 - (s1->w/2); loc.y = 10;
- SDL_BlitSurface( s1, NULL, screen, &loc);
- }
- if (s2)
- {
- loc.x = 320 - (s2->w/2); loc.y = 60;
- SDL_BlitSurface( s2, NULL, screen, &loc);
- }
- if (s3)
- {
- loc.x = 320 - (s3->w/2); loc.y = 300;
- SDL_BlitSurface( s3, NULL, screen, &loc);
- }
- if (s4)
- {
- loc.x = 320 - (s4->w/2); loc.y = 340;
- SDL_BlitSurface( s4, NULL, screen, &loc);
- }
-
- /* and update: */
- SDL_UpdateRect(screen, 0, 0, 0, 0);
-
-
-
- while (!finished)
- {
- start = SDL_GetTicks();
-
- while (SDL_PollEvent(&event))
- {
- switch (event.type)
- {
- case SDL_QUIT:
- {
- cleanup();
- }
-
- case SDL_MOUSEBUTTONDOWN:
- /* "Stop" button - go to main menu: */
- {
- if (inRect(stopRect, event.button.x, event.button.y ))
- {
- finished = 1;
- tuxtype_playsound(sounds[SND_TOCK]);
- break;
- }
- }
- case SDL_KEYDOWN:
- {
-#ifdef TUXMATH_DEBUG
- fprintf(stderr, "Before keypress, string is %S\tlength = %d\n",
- buf, (int)wcslen(buf));
-#endif
- switch (event.key.keysym.sym)
- {
- case SDLK_ESCAPE:
- case SDLK_RETURN:
- case SDLK_KP_ENTER:
- {
- finished = 1;
- tuxtype_playsound(sounds[SND_TOCK]);
- break;
- }
- case SDLK_BACKSPACE:
- {
- if (wcslen(buf) > 0)
- buf[(int)wcslen(buf) - 1] = '\0';
- redraw = 1;
- break;
- }
-
-
- /* For any other keys, if the key has a Unicode value, */
- /* we add it to our string: */
- default:
- {
- if ((event.key.keysym.unicode > 0)
- && (wcslen(buf) < HIGH_SCORE_NAME_LENGTH))
- {
- buf[(int)wcslen(buf)] = event.key.keysym.unicode;
- redraw = 1;
- }
- }
- } /* end 'switch (event.key.keysym.sym)' */
-
-#ifdef TUXMATH_DEBUG
- fprintf(stderr, "After keypress, string is %S\tlength = %d\n",
- buf, (int)wcslen(buf));
-#endif
- /* Now draw name, if needed: */
- if (redraw)
- {
- redraw = 0;
- /* Redraw background in area where we drew text last time: */
- if (!first_draw)
- {
- SDL_BlitSurface(images[IMG_MENU_BKG], &redraw_rect, screen, &redraw_rect);
- SDL_UpdateRect(screen,
- redraw_rect.x,
- redraw_rect.y,
- redraw_rect.w,
- redraw_rect.h);
- }
-
- /* Convert text to UTF-8: */
- //Unicode_to_UTF8((const wchar_t*)buf, player_name);
- wcstombs((char*) player_name, buf, HIGH_SCORE_NAME_LENGTH * 3);
-
- s3 = black_outline(player_name, name_font, &yellow);
- if (s3)
- {
- loc.x = 320 - (s3->w/2);
- loc.y = 300;
- SDL_BlitSurface( s3, NULL, screen, &loc);
-
- /* for some reason we need to update a little beyond s3 to get clean image */
- redraw_rect.x = loc.x - 20;
- redraw_rect.y = loc.y - 10;
- redraw_rect.h = s3->h + 20;
- redraw_rect.w = s3->w + 40;
- first_draw = 0;
-
- SDL_UpdateRect(screen,
- redraw_rect.x,
- redraw_rect.y,
- redraw_rect.w,
- redraw_rect.h);
- SDL_FreeSurface(s3);
- s3 = NULL;
- }
-
- }
- }
- }
- }
-
- /* --- make tux blink --- */
- switch (frame % TUX6)
- {
- case 0: tux_frame = 1; break;
- case TUX1: tux_frame = 2; break;
- case TUX2: tux_frame = 3; break;
- case TUX3: tux_frame = 4; break;
- case TUX4: tux_frame = 3; break;
- case TUX5: tux_frame = 2; break;
- default: tux_frame = 0;
- }
-
- if (Tux && tux_frame)
- {
- SDL_BlitSurface(Tux->frame[tux_frame - 1], NULL, screen, &Tuxdest);
- SDL_UpdateRect(screen, Tuxdest.x+37, Tuxdest.y+40, 70, 45);
- }
-
-
-
-
- /* Wait so we keep frame rate constant: */
- while ((SDL_GetTicks() - start) < 33)
- {
- SDL_Delay(20);
- }
- frame++;
- } // End of while (!finished) loop
-
- SDL_FreeSurface(s1);
- 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);
-}
-
-
-
/* FIXME add some background shading to improve legibility */
void ShowMessage(char* str1, char* str2, char* str3, char* str4)
{
@@ -2313,18 +1933,18 @@
/* Now set up mouse button rects: */
lesson_menu_button[i % 8].x = titleRects[i % 8].x - 15;
- lesson_menu_button[i % 8].y = titleRects[i % 8].y - 15;
- lesson_menu_button[i % 8].h = titleRects[i % 8].h + 30;
+ lesson_menu_button[i % 8].y = titleRects[i % 8].y;
+ lesson_menu_button[i % 8].h = titleRects[i % 8].h;
lesson_menu_button[i % 8].w = titleRects[i % 8].w + 30;
if (i == loc) //Draw text in yellow
{
- draw_button(&lesson_menu_button[i % 8], lesson_menu_button[i % 8].w, sel);
+ DrawButton(&lesson_menu_button[i % 8], 15, SEL_RGBA);
SDL_BlitSurface(select[loc], NULL, screen, &titleRects[i % 8]);
}
else //Draw text in white
{
- draw_button(&lesson_menu_button[i % 8], lesson_menu_button[i % 8].w, reg);
+ DrawButton(&lesson_menu_button[i % 8], 15, REG_RGBA);
SDL_BlitSurface(titles[i], NULL, screen, &titleRects[i % 8]);
}
}
@@ -2623,7 +2243,7 @@
but add a rect to be updated next
update
*******************************/
-void AddRect(SDL_Rect * src, SDL_Rect * dst) {
+void AddRect(SDL_Rect* src, SDL_Rect* dst) {
/*borrowed from SL's alien (and modified)*/
struct blit *update;
Modified: tuxmath/trunk/src/titlescreen.h
===================================================================
--- tuxmath/trunk/src/titlescreen.h 2007-09-21 19:14:39 UTC (rev 272)
+++ tuxmath/trunk/src/titlescreen.h 2007-09-25 15:22:45 UTC (rev 273)
@@ -65,6 +65,7 @@
#include "tuxmath.h"
+/* FIXME get rid of these evil macros! */
#define next_frame(SPRITE) if ((SPRITE)->num_frames) (SPRITE)->cur = (((SPRITE)->cur)+1) % (SPRITE)->num_frames;
#define rewind(SPRITE) (SPRITE)->cur = 0;
@@ -247,6 +248,7 @@
void TitleScreen( void );
void switch_screen_mode( void );
int choose_config_file(void); //FIXME really should be in fileops.c
+void DrawButton(SDL_Rect* target_rect, int radius, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
/* in theme.c (from tuxtype): */
void chooseTheme(void);
Modified: tuxmath/trunk/src/tuxmath.h
===================================================================
--- tuxmath/trunk/src/tuxmath.h 2007-09-21 19:14:39 UTC (rev 272)
+++ tuxmath/trunk/src/tuxmath.h 2007-09-25 15:22:45 UTC (rev 273)
@@ -111,6 +111,8 @@
#define HIGH_SCORES_SAVED 10
#define HIGH_SCORE_NAME_LENGTH 32
+#define REG_RGBA 64,64,128,128
+#define SEL_RGBA 64,64,128,192
enum {
CADET_HIGH_SCORE,
SCOUT_HIGH_SCORE,
More information about the Tux4kids-commits
mailing list