[Tux4kids-commits] r311 - in tuxmath/trunk: docs src
dbruce-guest at alioth.debian.org
dbruce-guest at alioth.debian.org
Tue Oct 30 18:15:56 UTC 2007
Author: dbruce-guest
Date: 2007-10-30 18:15:55 +0000 (Tue, 30 Oct 2007)
New Revision: 311
Removed:
tuxmath/trunk/src/alphabet.c
tuxmath/trunk/src/pause.c
tuxmath/trunk/src/playsound.c
tuxmath/trunk/src/playsound.h
Modified:
tuxmath/trunk/docs/changelog
tuxmath/trunk/src/Makefile.am
tuxmath/trunk/src/Makefile.in
tuxmath/trunk/src/SDL_extras.c
tuxmath/trunk/src/SDL_extras.h
tuxmath/trunk/src/audio.c
tuxmath/trunk/src/game.c
tuxmath/trunk/src/highscore.c
tuxmath/trunk/src/options.c
tuxmath/trunk/src/titlescreen.c
tuxmath/trunk/src/titlescreen.h
tuxmath/trunk/src/tuxmath.h
Log:
Removing dead and redundant code.
Modified: tuxmath/trunk/docs/changelog
===================================================================
--- tuxmath/trunk/docs/changelog 2007-10-29 12:28:38 UTC (rev 310)
+++ tuxmath/trunk/docs/changelog 2007-10-30 18:15:55 UTC (rev 311)
@@ -1,3 +1,12 @@
+2007.Oct.30 (svn.debian.org/tux4kids - revision 311)
+
+ Code:
+ * Uncrufting! - eliminated tuxtype_playsound(), moved playsound() to audio.c,
+ and removed playsound.c and .h; eliminated alphabet.c; moved DarkenScreen()
+ to SDL_extras.c and eliminated pause.c; moved SwitchScreenMode() to SDL_extras.c.
+
+ David Bruce <dbruce at tampabay.rr.com>
+
2007.Oct.29 (svn.debian.org/tux4kids - revision 310)
Version 1.5.7
Modified: tuxmath/trunk/src/Makefile.am
===================================================================
--- tuxmath/trunk/src/Makefile.am 2007-10-29 12:28:38 UTC (rev 310)
+++ tuxmath/trunk/src/Makefile.am 2007-10-30 18:15:55 UTC (rev 311)
@@ -16,12 +16,9 @@
game.c \
options.c \
credits.c \
- playsound.c \
highscore.c \
theme.c \
loaders.c \
- alphabet.c \
- pause.c \
audio.c \
mathcards.c \
fileops.c \
@@ -37,7 +34,6 @@
highscore.h \
mathcards.h \
options.h \
- playsound.h \
setup.h \
titlescreen.h \
tuxmath.h \
Modified: tuxmath/trunk/src/Makefile.in
===================================================================
--- tuxmath/trunk/src/Makefile.in 2007-10-29 12:28:38 UTC (rev 310)
+++ tuxmath/trunk/src/Makefile.in 2007-10-30 18:15:55 UTC (rev 311)
@@ -68,9 +68,8 @@
PROGRAMS = $(bin_PROGRAMS)
am__objects_1 = tuxmath.$(OBJEXT) setup.$(OBJEXT) \
titlescreen.$(OBJEXT) game.$(OBJEXT) options.$(OBJEXT) \
- credits.$(OBJEXT) playsound.$(OBJEXT) highscore.$(OBJEXT) \
- theme.$(OBJEXT) loaders.$(OBJEXT) alphabet.$(OBJEXT) \
- pause.$(OBJEXT) audio.$(OBJEXT) mathcards.$(OBJEXT) \
+ credits.$(OBJEXT) highscore.$(OBJEXT) theme.$(OBJEXT) \
+ loaders.$(OBJEXT) audio.$(OBJEXT) mathcards.$(OBJEXT) \
fileops.$(OBJEXT) ConvertUTF.$(OBJEXT) SDL_extras.$(OBJEXT) \
lessons.$(OBJEXT)
am_TuxMath_OBJECTS = $(am__objects_1)
@@ -78,9 +77,8 @@
TuxMath_LDADD = $(LDADD)
am_tuxmath_OBJECTS = tuxmath.$(OBJEXT) setup.$(OBJEXT) \
titlescreen.$(OBJEXT) game.$(OBJEXT) options.$(OBJEXT) \
- credits.$(OBJEXT) playsound.$(OBJEXT) highscore.$(OBJEXT) \
- theme.$(OBJEXT) loaders.$(OBJEXT) alphabet.$(OBJEXT) \
- pause.$(OBJEXT) audio.$(OBJEXT) mathcards.$(OBJEXT) \
+ credits.$(OBJEXT) highscore.$(OBJEXT) theme.$(OBJEXT) \
+ loaders.$(OBJEXT) audio.$(OBJEXT) mathcards.$(OBJEXT) \
fileops.$(OBJEXT) ConvertUTF.$(OBJEXT) SDL_extras.$(OBJEXT) \
lessons.$(OBJEXT)
tuxmath_OBJECTS = $(am_tuxmath_OBJECTS)
@@ -254,12 +252,9 @@
game.c \
options.c \
credits.c \
- playsound.c \
highscore.c \
theme.c \
loaders.c \
- alphabet.c \
- pause.c \
audio.c \
mathcards.c \
fileops.c \
@@ -274,7 +269,6 @@
highscore.h \
mathcards.h \
options.h \
- playsound.h \
setup.h \
titlescreen.h \
tuxmath.h \
@@ -360,7 +354,6 @@
@AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/ConvertUTF.Po at am__quote@
@AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/SDL_extras.Po at am__quote@
- at 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@
@AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/credits.Po at am__quote@
@AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/fileops.Po at am__quote@
@@ -370,8 +363,6 @@
@AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/loaders.Po at am__quote@
@AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/mathcards.Po at am__quote@
@AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/options.Po at am__quote@
- at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/pause.Po at am__quote@
- at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/playsound.Po at am__quote@
@AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/setup.Po at am__quote@
@AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/theme.Po at am__quote@
@AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/titlescreen.Po at am__quote@
Modified: tuxmath/trunk/src/SDL_extras.c
===================================================================
--- tuxmath/trunk/src/SDL_extras.c 2007-10-29 12:28:38 UTC (rev 310)
+++ tuxmath/trunk/src/SDL_extras.c 2007-10-30 18:15:55 UTC (rev 311)
@@ -312,3 +312,95 @@
return out;
}
+
+
+int inRect( SDL_Rect r, int x, int y) {
+ if ((x < r.x) || (y < r.y) || (x > r.x + r.w) || (y > r.y + r.h))
+ return 0;
+ return 1;
+}
+
+/* Darkens the screen by a factor of 2^bits */
+void DarkenScreen(Uint8 bits)
+{
+ Uint16 rm = screen->format->Rmask;
+ Uint16 gm = screen->format->Gmask;
+ Uint16 bm = screen->format->Bmask;
+ Uint16 *p;
+ int x, y;
+
+ /* (realistically, 1 and 2 are the only useful values) */
+ if (bits > 8 || bits < 0)
+ return;
+
+ p = screen->pixels;
+
+ for (y = 0; y < RES_Y; y++)
+ {
+ for (x = 0; x < RES_X; x++)
+ {
+ *p = (((*p&rm)>>bits)&rm)
+ | (((*p&gm)>>bits)&gm)
+ | (((*p&bm)>>bits)&bm);
+ p++;
+ }
+ }
+}
+
+
+void SwitchScreenMode(void)
+{
+ SDL_Surface *tmp;
+ SDL_Rect src, dst;
+
+ int window = 0;
+
+ src.x = 0;
+ src.y = 0;
+ src.w = RES_X;
+ src.h = RES_Y;
+ dst.x = 0;
+ dst.y = 0;
+
+ tmp = SDL_CreateRGBSurface(
+ SDL_SWSURFACE,
+ RES_X,
+ RES_Y,
+ BPP,
+#if SDL_BYTEORDER == SDL_BIG_ENDIAN
+ 0xff000000,
+ 0x00ff0000,
+ 0x0000ff00,
+ 0x000000ff
+#else
+ 0x000000ff,
+ 0x0000ff00,
+ 0x00ff0000,
+ 0xff000000
+#endif
+ );
+
+ if (screen->flags & SDL_FULLSCREEN)
+ {
+ window = 1;
+ }
+
+ SDL_BlitSurface(screen,&src,tmp,&dst);
+ SDL_UpdateRect(tmp,0,0,RES_X,RES_Y);
+ SDL_FreeSurface(screen);
+ screen = NULL;
+
+ if (window)
+ {
+ screen = SDL_SetVideoMode(RES_X,RES_Y,BPP, SDL_SWSURFACE|SDL_HWPALETTE);
+ }
+ else
+ {
+ screen = SDL_SetVideoMode(RES_X,RES_Y,BPP, SDL_SWSURFACE|SDL_HWPALETTE|SDL_FULLSCREEN);
+ }
+
+ SDL_BlitSurface(tmp,&src,screen,&dst);
+ SDL_UpdateRect(tmp,0,0,RES_X,RES_Y);
+ SDL_FreeSurface(tmp);
+}
+
Modified: tuxmath/trunk/src/SDL_extras.h
===================================================================
--- tuxmath/trunk/src/SDL_extras.h 2007-10-29 12:28:38 UTC (rev 310)
+++ tuxmath/trunk/src/SDL_extras.h 2007-10-30 18:15:55 UTC (rev 311)
@@ -32,5 +32,8 @@
void RoundCorners(SDL_Surface* s, Uint16 radius);
SDL_Surface* Flip(SDL_Surface *in, int x, int y);
SDL_Surface* BlackOutline(unsigned char *t, TTF_Font* font, SDL_Color* c);
+int inRect(SDL_Rect r, int x, int y);
+void DarkenScreen(Uint8 bits);
+void SwitchScreenMode(void);
#endif
Deleted: tuxmath/trunk/src/alphabet.c
===================================================================
--- tuxmath/trunk/src/alphabet.c 2007-10-29 12:28:38 UTC (rev 310)
+++ tuxmath/trunk/src/alphabet.c 2007-10-30 18:15:55 UTC (rev 311)
@@ -1,338 +0,0 @@
-/***************************************************************************
- alphabet.c
- - description: Init SDL
- -------------------
- begin : Jan 6 2003
- copyright : (C) 2003 by Jesse Andrews
- email : jdandr2 at tux4kids.net
-
- Modified for use in tuxmath by David Bruce - 2006.
- email : <dbruce at tampabay.rr.com>grep
- <tuxmath-devel at lists.sourceforge.net>
-***************************************************************************/
-
-/***************************************************************************
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. *
- * *
- ***************************************************************************/
-
-#include "tuxmath.h"
-#include "titlescreen.h"
-#include "SDL_extras.h"
-
-/* the colors we use throughout the game */
-
-SDL_Color black;
-SDL_Color gray;
-SDL_Color dark_blue;
-SDL_Color red;
-SDL_Color white;
-SDL_Color yellow;
-
-/* Used for word list functions (see below): */
-static int WORD_qty;
-unsigned char WORDS[MAX_NUM_WORDS][MAX_WORD_SIZE+1];
-
-/* --- setup the alphabet --- */
-void set_letters(unsigned char *t) {
- int i;
-
- ALPHABET_SIZE = 0;
- for (i=0; i<256; i++)
- ALPHABET[i]=0;
-
- for (i=0; i<strlen(t); i++)
- if (t[i]!=' ') {
- ALPHABET[(int)t[i]]=1;
- ALPHABET_SIZE++;
- }
-}
-
-void clear_keyboard( void ) {
- int i,j;
-
- ALPHABET_SIZE = 0;
- for (i=0; i<256; i++) {
- ALPHABET[i]=0;
- for (j=0; j<10; j++)
- FINGER[i][j]=0;
- KEYMAP[i]=i;
- }
-}
-
-void LoadKeyboard( void ) {
- unsigned char fn[PATH_MAX];
- int l;
-
- clear_keyboard();
-
- for (l=useEnglish; l<2; l++) {
- sprintf( fn , "%s/keyboard.lst", realPath[l]);
- if ( checkFile(fn) ) {
- unsigned char str[255];
- FILE *f;
- int i,j;
-
- f = fopen( fn, "r" );
-
- if (f == NULL)
- continue;
-
- do {
- fscanf( f, "%[^\n]\n", str);
- if (strlen(str) > 3) {
-
- /* format is: FINGER(s)|Char(s) Upper/Lower */
-
- /* advance past the fingers */
-
- for (i=0; i<strlen(str) && str[i] != '|'; i++);
-
- i++; // pass the '|'
- j = i;
- ALPHABET[(int)str[j]] = 1; // first character is default
-
- for (i++; i<strlen(str); i++)
- KEYMAP[(int)str[i]] = str[j];
-
- /* set the fingers for this letter */
-
- for (i=0; i<j-1; i++)
- if (str[i]>='0' && str[i]<='9')
- FINGER[str[j]][(int)(str[i]-'0')]=1;
-
- ALPHABET_SIZE++;
- }
-
- } while (!feof(f));
-
- fclose(f);
-
- return;
- }
- }
-
- fprintf( stderr, "Error finding file for keyboard setup!\n" );
-}
-
-
-
-
-void show_letters( void ) {
- int i, l=0;
- SDL_Surface *abit;
- SDL_Rect dst;
- int stop = 0;
- unsigned char t[255];
-
- for (i=0; i<256; i++)
- if (ALPHABET[i])
- t[l++]=i;
-
- t[l] = 0;
-
- abit = BlackOutline(t, default_font, &white);
-
- dst.x = 320 - (abit->w / 2);
- dst.y = 275;
- dst.w = abit->w;
- dst.h = abit->h;
-
- SDL_BlitSurface(abit, NULL, screen, &dst);
-
- SDL_FreeSurface(abit);
-
- abit = BlackOutline("Alphabet Set To:", default_font, &white);
- dst.x = 320 - (abit->w / 2);
- dst.y = 200;
- dst.w = abit->w;
- dst.h = abit->h;
-
- SDL_BlitSurface(abit, NULL, screen, &dst);
-
- SDL_UpdateRect(screen, 0, 0, 0 ,0);
-
- while (!stop)
- while (SDL_PollEvent(&event))
- switch (event.type) {
- case SDL_QUIT:
- exit(0);
- case SDL_KEYDOWN:
- case SDL_MOUSEBUTTONDOWN:
- stop = 1;
- }
-
- SDL_FreeSurface(abit);
-}
-
-/* --- get a letter --- */
-unsigned char get_letter(void) {
- static int last = -1; // we don't want to return same letter twice in a row
- int letter;
- do {
- letter = rand() % 255;
- } while ((letter == last && ALPHABET_SIZE > 1) || ALPHABET[letter] == 0);
-
- last = letter;
-
- return letter;
-}
-
-/******************************************************************************
-* WORD FILE & DATA STRUCTURE *
-******************************************************************************/
-
-
-
-/* WORDS_init: clears the number of words
- */
-void WORDS_init( void ) {
- WORD_qty = 0;
-}
-
-/* WORDS_use_alphabet: setups the WORDS so that it really
- * returns a LETTER when WORDS_get() is called
- */
-void WORDS_use_alphabet( void ) {
- int i;
-
- LOG("Entering WORDS_use_alphabet()\n");
-
- WORD_qty = 0;
- /* This totally mucks up i18n abilities :( */
- for (i=65; i<90; i++)
- {
- if (ALPHABET[i]) {
- WORDS[WORD_qty][0] = (unsigned char)i;
- WORDS[WORD_qty][1] = '\0';
- WORD_qty++;
-
- DEBUGCODE { fprintf(stderr, "Adding %c\n", (unsigned char)i); }
- }
- }
- /* Make sure list is terminated with null character */
- WORDS[WORD_qty][0] = '\0';
-
- DOUT(WORD_qty);
- LOG("Leaving WORDS_use_alphabet()\n");
-}
-
-/* WORDS_get: returns a random word that wasn't returned
- * the previous time (unless there is only 1 word!!!)
- */
-unsigned char* WORDS_get( void ) {
- static int last_choice = -1;
- int choice;
-
- LOG("Entering WORDS_get()\n");
- DEBUGCODE { fprintf(stderr, "WORD_qty is: %d\n", WORD_qty); }
-
- /* Now count list to make sure WORD_qty is correct: */
-
- WORD_qty = 0;
- while (WORDS[WORD_qty][0] != '\0')
- {
- WORD_qty++;
- }
-
- DEBUGCODE { fprintf(stderr, "After count, WORD_qty is: %d\n", WORD_qty); }
-
- if (0 == WORD_qty)
- {
- LOG("No words in list\n");
- return NULL;
- }
-
- if (WORD_qty > MAX_NUM_WORDS)
- {
- LOG("Error: WORD_qty greater than array size\n");
- return NULL;
- }
-
- if (WORD_qty < 0)
- {
- LOG("Error: WORD_qty negative\n");
- return NULL;
- }
-
- do {
- choice = (rand() % WORD_qty);
- } while ((choice == last_choice) || (WORD_qty < 2));
-
- last_choice = choice;
-
- DEBUGCODE { fprintf(stderr, "Selected word is: %s\n", WORDS[choice]); }
- return WORDS[choice];
-}
-
-
-
-/* WORDS_use: adds the words from a given wordlist
- * it ignores any words too long or that has bad
- * character (such as #)
- */
-void WORDS_use( char *wordFn ) {
- int j;
- unsigned char temp_word[PATH_MAX];
- FILE *wordFile=NULL;
-
- DEBUGCODE { fprintf(stderr, "Entering WORDS_use() for file: %s\n", wordFn); }
-
- WORD_qty = 0;
-
- /* --- open the file --- */
-
- wordFile = fopen( wordFn, "r" );
-
- if ( wordFile == NULL ) {
- fprintf(stderr, "ERROR: could not load wordlist: %s\n", wordFn );
- fprintf(stderr, "Using ALPHABET instead\n");
- WORDS_use_alphabet( );
- return;
- }
-
-
- /* --- load words for this curlevel --- */
-
-
- DEBUGCODE { fprintf(stderr, "WORD FILE OPENNED @ %s\n", wordFn); }
-
- /* ignore the title */
- fscanf( wordFile, "%[^\n]\n", temp_word);
-
- while (!feof(wordFile) && (WORD_qty < MAX_NUM_WORDS)) {
- fscanf( wordFile, "%[^\n]\n", temp_word);
-
- for (j = 0; j < strlen(temp_word); j++)
- if (temp_word[j] == '\n' || temp_word[j] == '\r')
- temp_word[j] = '\0';
-
- /* --- check its size, if too big, ignore it --- */
-
- if (strlen(temp_word) >= 1 && strlen(temp_word) <= MAX_WORD_SIZE) {
-
- /* --- add word --- */
- if (WORD_qty < MAX_NUM_WORDS)
- {
- strcpy( WORDS[WORD_qty], temp_word );
- WORD_qty++;
- }
- }
- }
-
- /* Make sure list is terminated with null character */
- WORDS[WORD_qty][0] = '\0';
-
- DOUT(WORD_qty);
-
- if (WORD_qty == 0)
- WORDS_use_alphabet( );
-
- fclose(wordFile);
-
- LOG("Leaving WORDS_use()\n");
-}
Modified: tuxmath/trunk/src/audio.c
===================================================================
--- tuxmath/trunk/src/audio.c 2007-10-29 12:28:38 UTC (rev 310)
+++ tuxmath/trunk/src/audio.c 2007-10-30 18:15:55 UTC (rev 311)
@@ -29,10 +29,12 @@
Mix_Chunk *sound[NUM_WAVES];
Mix_Music *music;
-void tuxtype_playsound(Mix_Chunk *snd) {
- if (!Opts_UsingSound()) return;
-
- Mix_PlayChannel(-1, snd, 0);
+void playsound(int snd)
+{
+#ifndef NOSOUND
+ if (Opts_UsingSound())
+ Mix_PlayChannel(-1, sounds[snd], 0);
+#endif
}
Mix_Music *defaultMusic = NULL; // holds music for audioMusicLoad/unload
Modified: tuxmath/trunk/src/game.c
===================================================================
--- tuxmath/trunk/src/game.c 2007-10-29 12:28:38 UTC (rev 310)
+++ tuxmath/trunk/src/game.c 2007-10-30 18:15:55 UTC (rev 311)
@@ -32,7 +32,6 @@
#include "game.h"
#include "fileops.h"
#include "setup.h"
-#include "playsound.h"
#include "tuxmath.h"
#include "mathcards.h"
#include "titlescreen.h"
@@ -2566,9 +2565,10 @@
dest.y = (screen->h - images[IMG_PAUSED]->h) / 2;
dest.w = images[IMG_PAUSED]->w;
dest.h = images[IMG_PAUSED]->h;
-
+
+ DarkenScreen(1); // cut all channels by half
SDL_BlitSurface(images[IMG_PAUSED], NULL, screen, &dest);
- SDL_Flip(screen);
+ SDL_UpdateRect(screen, 0, 0, 0, 0);
#ifndef NOSOUND
@@ -3053,7 +3053,7 @@
/* Toggle screen mode: */
else if (key == SDLK_F10)
{
- switch_screen_mode();
+ SwitchScreenMode();
}
/* Toggle music: */
Modified: tuxmath/trunk/src/highscore.c
===================================================================
--- tuxmath/trunk/src/highscore.c 2007-10-29 12:28:38 UTC (rev 310)
+++ tuxmath/trunk/src/highscore.c 2007-10-30 18:15:55 UTC (rev 311)
@@ -121,7 +121,7 @@
if (inRect(stopRect, event.button.x, event.button.y ))
{
finished = 1;
- tuxtype_playsound(sounds[SND_TOCK]);
+ playsound(SND_TOCK);
}
/* "Left" button - go to previous page: */
@@ -132,7 +132,7 @@
diff_level--;
if (Opts_MenuSound())
{
- tuxtype_playsound(sounds[SND_TOCK]);
+ playsound(SND_TOCK);
}
}
}
@@ -145,7 +145,7 @@
diff_level++;
if (Opts_MenuSound())
{
- tuxtype_playsound(sounds[SND_TOCK]);
+ playsound(SND_TOCK);
}
}
}
@@ -156,7 +156,7 @@
case SDL_KEYDOWN:
{
finished = 1;
- tuxtype_playsound(sounds[SND_TOCK]);
+ playsound(SND_TOCK);
}
}
}
@@ -467,7 +467,7 @@
if (inRect(stopRect, event.button.x, event.button.y ))
{
finished = 1;
- tuxtype_playsound(sounds[SND_TOCK]);
+ playsound(SND_TOCK);
break;
}
}
@@ -484,7 +484,7 @@
case SDLK_KP_ENTER:
{
finished = 1;
- tuxtype_playsound(sounds[SND_TOCK]);
+ playsound(SND_TOCK);
break;
}
case SDLK_BACKSPACE:
Modified: tuxmath/trunk/src/options.c
===================================================================
--- tuxmath/trunk/src/options.c 2007-10-29 12:28:38 UTC (rev 310)
+++ tuxmath/trunk/src/options.c 2007-10-30 18:15:55 UTC (rev 311)
@@ -29,7 +29,6 @@
#include "options.h"
#include "fileops.h"
#include "setup.h"
-#include "playsound.h"
#include "game.h"
#include "tuxmath.h"
Deleted: tuxmath/trunk/src/pause.c
===================================================================
--- tuxmath/trunk/src/pause.c 2007-10-29 12:28:38 UTC (rev 310)
+++ tuxmath/trunk/src/pause.c 2007-10-30 18:15:55 UTC (rev 311)
@@ -1,346 +0,0 @@
-/***************************************************************************
-pause.c
-- description: pause screen for the games
--------------------
-begin : Jan 22, 2003
-copyright : (C) 2003 by Jesse Andrews
-email : jdandr2 at uky.edu
-
- Modified for use in tuxmath by David Bruce - 2006.
- email : <dbruce at tampabay.rr.com>
- <tuxmath-devel at lists.sourceforge.net>
-***************************************************************************/
-
-/***************************************************************************
-* *
-* This program is free software; you can redistribute it and/or modify *
-* it under the terms of the GNU General Public License as published by *
-* the Free Software Foundation; either version 2 of the License, or *
-* (at your option) any later version. *
-* *
-***************************************************************************/
-// For gettext support:
-#include "tuxmath.h"
-// For tuxtype-related stuff:
-#include "titlescreen.h"
-
-// For Opts_UsingSound()
-#include "options.h"
-#include "SDL_extras.h"
-
-Mix_Chunk *pause_sfx;
-SDL_Surface *up, *down, *left, *right;
-SDL_Rect rectUp, rectDown, rectLeft, rectRight;
-TTF_Font *f1, *f2;
-extern settings localsettings;
-
-void pause_load_media(void) {
- if (Opts_UsingSound())
- pause_sfx = LoadSound( "tock.wav" );
-
- up = LoadImage("up.png", IMG_ALPHA);
- rectUp.w = up->w; rectUp.h = up->h;
-
- down = LoadImage("down.png", IMG_ALPHA);
- rectDown.w = down->w; rectDown.h = down->h;
-
- left = LoadImage("left.png", IMG_ALPHA);
- rectLeft.w = left->w; rectLeft.h = left->h;
-
- right = LoadImage("right.png", IMG_ALPHA);
- rectRight.w = right->w; rectRight.h = right->h;
-
- f1 = LoadFont( ttf_font, 24 );
- f2 = LoadFont( ttf_font, 36 );
-}
-
-void pause_unload_media(void) {
- if (Opts_UsingSound())
- Mix_FreeChunk(pause_sfx);
- SDL_FreeSurface(up);
- SDL_FreeSurface(down);
- SDL_FreeSurface(left);
- SDL_FreeSurface(right);
- TTF_CloseFont(f1);
- TTF_CloseFont(f2);
-}
-
-void pause_draw_info(void) {
- SDL_Rect s;
- SDL_Surface *t;
-
- rectLeft.y = rectRight.y = 200;
- rectDown.y = rectUp.y = 300;
-
- rectLeft.x = rectDown.x = 320 - (7*16) - rectLeft.w - 4;
- rectRight.x = rectUp.x = 320 + (7*16) + 4;
-
- if (Opts_UsingSound()) {
-
- SDL_BlitSurface(left, NULL, screen, &rectLeft);
- SDL_BlitSurface(right, NULL, screen, &rectRight);
-
- SDL_BlitSurface(down, NULL, screen, &rectDown);
- SDL_BlitSurface(up, NULL, screen, &rectUp);
- }
-
- if (Opts_UsingSound()) {
-
- t = BlackOutline(_("Sound Effects Volume"), f1, &white);
- s.y = 160;
- s.x = 320 - t->w/2;
- SDL_BlitSurface(t, NULL, screen, &s);
- SDL_FreeSurface(t);
-
- t = BlackOutline(_("Music Volume"), f1, &white);
- s.y = 260;
- s.x = 320 - t->w/2;
- SDL_BlitSurface(t, NULL, screen, &s);
- SDL_FreeSurface(t);
-
- } else {
-
- t = BlackOutline(_("Sound & Music Disabled"), f1, &white);
- s.y = 160;
- s.x = 320 - t->w/2;
- SDL_BlitSurface(t, NULL, screen, &s);
- SDL_FreeSurface(t);
- }
-
- t = BlackOutline(_("Paused!"), f2, &white);
- s.y = 60;
- s.x = 320 - t->w/2;
- SDL_BlitSurface(t, NULL, screen, &s);
- SDL_FreeSurface(t);
-
- t = BlackOutline(_("Press escape again to return to menu"), f1, &white);
- s.y = 400;
- s.x = 320 - t->w/2;
- SDL_BlitSurface(t, NULL, screen, &s);
- SDL_FreeSurface(t);
-
- t = BlackOutline(_("Press space bar to return to game"), f1, &white);
- s.y = 440;
- s.x = 320 - t->w/2;
- SDL_BlitSurface(t, NULL, screen, &s);
- SDL_FreeSurface(t);
-}
-
-void draw_vols(int sfx, int mus) {
- SDL_Rect s,m;
- int i;
-
- s.y = rectLeft.y;
- m.y = rectDown.y;
- m.w = s.w = 5;
- s.x = rectLeft.x + rectLeft.w + 5;
- m.x = rectDown.x + rectDown.w + 5;
- m.h = s.h = 40;
-
- for (i = 1; i<=32; i++){
- if (sfx >= i*4)
- SDL_FillRect(screen, &s, SDL_MapRGB(screen->format, 0, 0, 127+sfx));
- else
- SDL_FillRect(screen, &s, SDL_MapRGB(screen->format, 0, 0, 0));
-
- if (mus >= i*4)
- SDL_FillRect(screen, &m, SDL_MapRGB(screen->format, 0, 0, 127+mus));
- else
- SDL_FillRect(screen, &m, SDL_MapRGB(screen->format, 0, 0, 0));
-
- m.x = s.x += 7;
- }
-}
-
-/* ==== fillscreen ====
- * RESULT: it will darken the screen by a factor of 4
- * WARNING: only works on 16bit screens right now!
- */
-void darkenscreen( void ){
- Uint16 rm = screen->format->Rmask;
- Uint16 gm = screen->format->Gmask;
- Uint16 bm = screen->format->Bmask;
- Uint16 *p;
- int x, y;
-
- p = screen->pixels;
-
- for (y = 0; y<480; y++)
- for (x = 0; x<640; x++) {
- *p = (((*p&rm)>>2)&rm) | (((*p&gm)>>2)&gm) | (((*p&bm)>>2)&bm); p++;
- }
-}
-
-int inRect( SDL_Rect r, int x, int y) {
- if ((x < r.x) || (y < r.y) || (x > r.x + r.w) || (y > r.y + r.h))
- return 0;
- return 1;
-}
-
-// QUESTION: For usability sake, should escape return to the game
-// and the user have to choose to quit the game, or ???
-/**********************
-Pause : Pause the game
-***********************/
-int Pause( void ) {
- int paused = 1;
- int sfx_volume=0;
- int old_sfx_volume;
- int mus_volume=0;
- int old_mus_volume;
- int mousePressed = 0;
- int quit=0;
- int tocks=0; // used for keeping track of when a tock has happened
- SDL_Event event;
-
- LOG( "---GAME PAUSED---\n" );
-
- /* --- stop all sounds, play pause noise --- */
-
- if (Opts_UsingSound()) {
- Mix_Pause(-1);
- Mix_PlayChannel(-1, pause_sfx, 0);
- sfx_volume = Mix_Volume(-1, -1); // get sfx volume w/o changing it
- mus_volume = Mix_VolumeMusic(-1); // get mus volume w/o changing it
- }
-
- /* --- show the pause screen --- */
-
- SDL_ShowCursor(1);
-
- // Darken the screen...
- darkenscreen();
-
- pause_draw_info();
- if (Opts_UsingSound()) {
- draw_vols(sfx_volume, mus_volume);
- }
-
- SDL_Flip(screen);
-
- SDL_EnableKeyRepeat( 1, 20 );
-
- /* --- wait for space, click, or exit --- */
-
- while (paused) {
- old_sfx_volume = sfx_volume;
- old_mus_volume = mus_volume;
- while (SDL_PollEvent(&event))
- switch (event.type) {
- case SDL_QUIT:
- exit(0);
- break;
- case SDL_KEYUP:
- if (Opts_UsingSound() &&
- ((event.key.keysym.sym == SDLK_RIGHT) ||
- (event.key.keysym.sym == SDLK_LEFT)))
- tocks = 0;
- break;
- case SDL_KEYDOWN:
- if (event.key.keysym.sym == SDLK_SPACE)
- paused = 0;
- if (event.key.keysym.sym == SDLK_ESCAPE) {
- paused = 0;
- quit = 1;
- }
- if (Opts_UsingSound()) {
- if (event.key.keysym.sym == SDLK_RIGHT)
- sfx_volume += 4;
- if (event.key.keysym.sym == SDLK_LEFT)
- sfx_volume -= 4;
- if (event.key.keysym.sym == SDLK_UP)
- mus_volume += 4;
- if (event.key.keysym.sym == SDLK_DOWN)
- mus_volume -= 4;
- }
- break;
- case SDL_MOUSEBUTTONDOWN:
- mousePressed = 1;
- tocks = 0;
- break;
- case SDL_MOUSEBUTTONUP:
- mousePressed = 0;
- break;
-
- break;
- }
- if (Opts_UsingSound() && mousePressed) {
- int x, y;
-
- SDL_GetMouseState(&x, &y);
- /* check to see if they clicked on a button */
-
- if (inRect(rectUp, x, y)) {
- mus_volume += 4;
- } else if (inRect(rectDown, x, y)) {
- mus_volume -= 4;
- } else if (inRect(rectRight, x, y)) {
- sfx_volume += 4;
- } else if (inRect(rectLeft, x, y)) {
- sfx_volume -= 4;
- } else {
-
- /* check to see if they clicked a bar */
-
- if ((x > rectLeft.x + rectLeft.w) && (x < rectRight.x)) {
- if ((y >= rectLeft.y) && (y <= rectLeft.y + rectLeft.h)) {
- sfx_volume = 4+(int)(128.0 * ((x - rectLeft.x - rectLeft.w - 1.0) / (rectRight.x - rectLeft.x - rectLeft.w - 2.0)));
- }
- if ((y >= rectDown.y) && (y <= rectDown.y + rectDown.h)) {
- mus_volume = 4+(int)(128.0 * ((x - rectLeft.x - rectLeft.w - 1.0) / (rectRight.x - rectLeft.x - rectLeft.w - 2.0)));
- }
-
- }
- }
- }
-
- if (Opts_UsingSound()) {
-
- if (sfx_volume > MIX_MAX_VOLUME)
- sfx_volume = MIX_MAX_VOLUME;
- if (sfx_volume < 0)
- sfx_volume = 0;
- if (mus_volume > MIX_MAX_VOLUME)
- mus_volume = MIX_MAX_VOLUME;
- if (mus_volume < 0)
- mus_volume = 0;
-
- if ((mus_volume != old_mus_volume) ||
- (sfx_volume != old_sfx_volume)) {
-
- if (mus_volume != old_mus_volume)
- Mix_VolumeMusic(mus_volume);
-
- if (sfx_volume != old_sfx_volume) {
- Mix_Volume(-1,sfx_volume);
- if (tocks%4==0)
- Mix_PlayChannel(-1, pause_sfx, 0);
- tocks++;
- }
-
- draw_vols(sfx_volume, mus_volume);
- localsettings.mus_volume=mus_volume;
- localsettings.sfx_volume=sfx_volume;
- SDL_Flip(screen);
- }
- }
-
- SDL_Delay(33);
- }
-
- /* --- Return to previous state --- */
-
- SDL_EnableKeyRepeat( 0, SDL_DEFAULT_REPEAT_INTERVAL );
-
- SDL_ShowCursor(0);
-
- if (Opts_UsingSound()) {
- Mix_PlayChannel(-1, pause_sfx, 0);
- Mix_Resume(-1);
- }
-
- LOG( "---GAME RESUMED---\n" );
-
- return (quit);
-}
-
Deleted: tuxmath/trunk/src/playsound.c
===================================================================
--- tuxmath/trunk/src/playsound.c 2007-10-29 12:28:38 UTC (rev 310)
+++ tuxmath/trunk/src/playsound.c 2007-10-30 18:15:55 UTC (rev 311)
@@ -1,33 +0,0 @@
-/*
- playsound.c
-
- For TuxMath
- Plays a sound (if sound support is enabled)
-
- by Bill Kendrick
- bill at newbreedsoftware.com
- http://www.newbreedsoftware.com/
-
- Part of "Tux4Kids" Project
- http://www.tux4kids.org/
-
- August 28, 2001 - September 6, 2001
-*/
-
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <SDL.h>
-#ifndef NOSOUND
-#include <SDL_mixer.h>
-#endif
-#include "options.h"
-#include "tuxmath.h"
-
-void playsound(int snd)
-{
-#ifndef NOSOUND
- if (Opts_UsingSound())
- Mix_PlayChannel(-1, sounds[snd], 0);
-#endif
-}
Deleted: tuxmath/trunk/src/playsound.h
===================================================================
--- tuxmath/trunk/src/playsound.h 2007-10-29 12:28:38 UTC (rev 310)
+++ tuxmath/trunk/src/playsound.h 2007-10-30 18:15:55 UTC (rev 311)
@@ -1,23 +0,0 @@
-/*
- playsound.h
-
- For TuxMath
- Plays a sound (if sound support is enabled)
-
- by Bill Kendrick
- bill at newbreedsoftware.com
- http://www.newbreedsoftware.com/
-
- Part of "Tux4Kids" Project
- http://www.tux4kids.org/
-
- August 28, 2001 - August 28, 2001
-*/
-
-
-#ifndef PLAYSOUND_H
-#define PLAYSOUND_H
-
-void playsound(int snd);
-
-#endif
Modified: tuxmath/trunk/src/titlescreen.c
===================================================================
--- tuxmath/trunk/src/titlescreen.c 2007-10-29 12:28:38 UTC (rev 310)
+++ tuxmath/trunk/src/titlescreen.c 2007-10-30 18:15:55 UTC (rev 311)
@@ -43,6 +43,14 @@
SDL_Rect dstupdate[MAX_UPDATES];
int numupdates = 0; // tracks how many blits to be done
+// Colors we use:
+SDL_Color black;
+SDL_Color gray;
+SDL_Color dark_blue;
+SDL_Color red;
+SDL_Color white;
+SDL_Color yellow;
+
// Type needed for TransWipe():
struct blit {
SDL_Surface *src;
@@ -329,64 +337,8 @@
}
-void switch_screen_mode(void)
-{
- SDL_Surface *tmp;
- SDL_Rect src, dst;
- int window = 0;
- src.x = 0;
- src.y = 0;
- src.w = RES_X;
- src.h = RES_Y;
- dst.x = 0;
- dst.y = 0;
-
- tmp = SDL_CreateRGBSurface(
- SDL_SWSURFACE,
- RES_X,
- RES_Y,
- BPP,
-#if SDL_BYTEORDER == SDL_BIG_ENDIAN
- 0xff000000,
- 0x00ff0000,
- 0x0000ff00,
- 0x000000ff
-#else
- 0x000000ff,
- 0x0000ff00,
- 0x00ff0000,
- 0xff000000
-#endif
- );
-
- if (screen->flags & SDL_FULLSCREEN)
- {
- window = 1;
- }
-
- SDL_BlitSurface(screen,&src,tmp,&dst);
- SDL_UpdateRect(tmp,0,0,RES_X,RES_Y);
- SDL_FreeSurface(screen);
- screen = NULL;
-
- if (window)
- {
- screen = SDL_SetVideoMode(RES_X,RES_Y,BPP, SDL_SWSURFACE|SDL_HWPALETTE);
- }
- else
- {
- screen = SDL_SetVideoMode(RES_X,RES_Y,BPP, SDL_SWSURFACE|SDL_HWPALETTE|SDL_FULLSCREEN);
- }
-
- SDL_BlitSurface(tmp,&src,screen,&dst);
- SDL_UpdateRect(tmp,0,0,RES_X,RES_Y);
- SDL_FreeSurface(tmp);
-}
-
-
-
/***********************************************************/
/* */
/* "Private functions" (callable only from this file) */
@@ -575,14 +527,14 @@
if (inRect(stopRect, event.button.x, event.button.y ))
{
finished = 1;
- tuxtype_playsound(sounds[SND_TOCK]);
+ playsound(SND_TOCK);
break;
}
}
case SDL_KEYDOWN:
{
finished = 1;
- tuxtype_playsound(sounds[SND_TOCK]);
+ playsound(SND_TOCK);
}
}
}
@@ -916,7 +868,7 @@
while (chosen_lesson >= 0)
{
if (Opts_MenuSound())
- {tuxtype_playsound(sounds[SND_POP]);}
+ playsound(SND_POP);
/* Re-read global settings first in case any settings were */
/* clobbered by other lesson or arcade games this session: */
@@ -1171,7 +1123,7 @@
// Play sound if loc is being changed:
if (Opts_MenuSound() && (old_loc != loc_screen_start + i))
{
- tuxtype_playsound(sounds[SND_TOCK]);
+ playsound(SND_TOCK);
}
loc = loc_screen_start + i;
break; /* from for loop */
@@ -1185,7 +1137,7 @@
{
if (Opts_MenuSound() && click_flag)
{
- tuxtype_playsound(sounds[SND_TOCK]);
+ playsound(SND_TOCK);
click_flag = 0;
}
}
@@ -1199,7 +1151,7 @@
{
if (Opts_MenuSound() && click_flag)
{
- tuxtype_playsound(sounds[SND_TOCK]);
+ playsound(SND_TOCK);
click_flag = 0;
}
}
@@ -1222,7 +1174,7 @@
{
if (Opts_MenuSound())
{
- tuxtype_playsound(sounds[SND_POP]);
+ playsound(SND_POP);
}
loc = loc_screen_start + i;
@@ -1241,7 +1193,7 @@
loc = -1; // nothing selected
if (Opts_MenuSound())
{
- tuxtype_playsound(sounds[SND_TOCK]);
+ playsound(SND_TOCK);
}
break;
}
@@ -1257,7 +1209,7 @@
loc = -1; // nothing selected
if (Opts_MenuSound())
{
- tuxtype_playsound(sounds[SND_TOCK]);
+ playsound(SND_TOCK);
}
break;
}
@@ -1267,7 +1219,7 @@
if (inRect(stopRect, event.button.x, event.button.y ))
{
stop = 2;
- tuxtype_playsound(sounds[SND_TOCK]);
+ playsound(SND_TOCK);
break;
}
} /* End of case SDL_MOUSEDOWN */
@@ -1289,7 +1241,7 @@
case SDLK_KP_ENTER:
{
if (Opts_MenuSound())
- {tuxtype_playsound(sounds[SND_POP]);}
+ playsound(SND_POP);
stop = 1;
break;
}
@@ -1300,7 +1252,7 @@
case SDLK_PAGEUP:
{
if (Opts_MenuSound())
- {tuxtype_playsound(sounds[SND_TOCK]);}
+ playsound(SND_TOCK);
if (loc_screen_start - n_entries_per_screen >= 0) {
loc_screen_start -= n_entries_per_screen;
loc = -1;
@@ -1315,7 +1267,7 @@
case SDLK_PAGEDOWN:
{
if (Opts_MenuSound())
- {tuxtype_playsound(sounds[SND_TOCK]);}
+ playsound(SND_TOCK);
if (loc_screen_start + n_entries_per_screen < n_menu_entries) {
loc_screen_start += n_entries_per_screen;
loc = -1;
@@ -1328,7 +1280,7 @@
case SDLK_UP:
{
if (Opts_MenuSound())
- {tuxtype_playsound(sounds[SND_TOCK]);}
+ playsound(SND_TOCK);
if (loc > 0)
{loc--;}
else if (n_menu_entries <= n_entries_per_screen) {
@@ -1348,7 +1300,7 @@
case SDLK_DOWN:
{
if (Opts_MenuSound())
- {tuxtype_playsound(sounds[SND_TOCK]);}
+ playsound(SND_TOCK);
if (loc >= 0 && loc + 1 < n_menu_entries)
{loc++;}
else if (n_menu_entries <= n_entries_per_screen)
@@ -1364,7 +1316,7 @@
/* Toggle screen mode: */
case SDLK_F10:
{
- switch_screen_mode();
+ SwitchScreenMode();
redraw = 1;
break;
}
Modified: tuxmath/trunk/src/titlescreen.h
===================================================================
--- tuxmath/trunk/src/titlescreen.h 2007-10-29 12:28:38 UTC (rev 310)
+++ tuxmath/trunk/src/titlescreen.h 2007-10-30 18:15:55 UTC (rev 311)
@@ -28,11 +28,6 @@
//#define FNLEN 200
-#define RES_X 640
-#define RES_Y 480
-#define BPP 32
-
-
#define MAX_SPRITE_FRAMES 30
#include <string.h>
@@ -234,7 +229,6 @@
/*In titlescreen.c */
void TitleScreen( void );
-void switch_screen_mode( void );
int ChooseMission(void); //FIXME really should be in fileops.c
int choose_menu_item(const unsigned char**,sprite**,int,menu_options);
void set_default_menu_options(menu_options *);
@@ -255,25 +249,8 @@
Mix_Music *LoadMusic( char *datafile );
void next_frame(sprite* s);
-/* in alphabet.c (from tuxtype) */
-void LoadKeyboard( void );
-void set_letters( unsigned char *t );
-unsigned char get_letter( void );
-void custom_letter_setup( void );
-void show_letters( void );
-void WORDS_init( void );
-void WORDS_use_alphabet( void );
-void WORDS_use( char *wordFn );
-unsigned char* WORDS_get( void );
-
-/* in pause.c * (from tuxtype): */
-int Pause( void );
-void pause_load_media( void );
-void pause_unload_media( void );
-int inRect( SDL_Rect r, int x, int y);
-
/* in audio.c (from tuxtype): */
-void tuxtype_playsound( Mix_Chunk *snd );
+void playsound(int snd);
void audioMusicLoad( char *musicFilename, int repeatQty );
void audioMusicUnload( void );
void audioMusicPlay( Mix_Music *musicData, int repeatQty );
Modified: tuxmath/trunk/src/tuxmath.h
===================================================================
--- tuxmath/trunk/src/tuxmath.h 2007-10-29 12:28:38 UTC (rev 310)
+++ tuxmath/trunk/src/tuxmath.h 2007-10-30 18:15:55 UTC (rev 311)
@@ -115,6 +115,11 @@
#define REG_RGBA 16,16,96,96
#define SEL_RGBA 16,16,128,128
+
+#define RES_X 640
+#define RES_Y 480
+#define BPP 32
+
enum {
CADET_HIGH_SCORE,
SCOUT_HIGH_SCORE,
More information about the Tux4kids-commits
mailing list