[Tux4kids-commits] r1110 - tuxmath/trunk/src
Bolesław Kulbabiński
bolekk-guest at alioth.debian.org
Mon Jun 29 17:53:10 UTC 2009
Author: bolekk-guest
Date: 2009-06-29 17:53:08 +0000 (Mon, 29 Jun 2009)
New Revision: 1110
Modified:
tuxmath/trunk/src/SDL_extras.c
tuxmath/trunk/src/SDL_extras.h
tuxmath/trunk/src/fileops_media.c
tuxmath/trunk/src/game.c
tuxmath/trunk/src/globals.h
tuxmath/trunk/src/loaders.c
tuxmath/trunk/src/loaders.h
tuxmath/trunk/src/setup.c
tuxmath/trunk/src/titlescreen.c
tuxmath/trunk/src/tuxmath.h
Log:
cleanup in loaders and slight change in handling fullscreen/window dimensions
Modified: tuxmath/trunk/src/SDL_extras.c
===================================================================
--- tuxmath/trunk/src/SDL_extras.c 2009-06-29 16:03:58 UTC (rev 1109)
+++ tuxmath/trunk/src/SDL_extras.c 2009-06-29 17:53:08 UTC (rev 1110)
@@ -390,50 +390,46 @@
}
}
-void ChangeScreenSize(int new_res_x, int new_res_y)
+/* change window size (works only in windowed mode) */
+void ChangeWindowSize(int new_res_x, int new_res_y)
{
SDL_Surface* oldscreen = screen;
- screen = SDL_SetVideoMode(new_res_x,
- new_res_y,
- PIXEL_BITS,
- SDL_SWSURFACE|SDL_HWPALETTE);
-
- if(screen == NULL)
+ if(!(screen->flags & SDL_FULLSCREEN))
{
- fprintf(stderr,
- "\nError: I could not change screen mode into %d x %d.\n",
- new_res_x, new_res_y);
- screen = oldscreen;
+ screen = SDL_SetVideoMode(new_res_x,
+ new_res_y,
+ PIXEL_BITS,
+ SDL_SWSURFACE|SDL_HWPALETTE);
+
+ if(screen == NULL)
+ {
+ fprintf(stderr,
+ "\nError: I could not change screen mode into %d x %d.\n",
+ new_res_x, new_res_y);
+ screen = oldscreen;
+ }
+ else
+ {
+ DEBUGMSG(debug_sdl, "ChangeWindowSize(): Changed window size to %d x %d\n", screen->w, screen->h);
+ oldscreen = NULL;
+ win_res_x = screen->w;
+ win_res_y = screen->h;
+ SDL_UpdateRect(screen, 0, 0, 0, 0);
+ }
}
else
- {
- SDL_FreeSurface(oldscreen);
- oldscreen = NULL;
- SDL_UpdateRect(screen, 0, 0, 0, 0);
- RES_X = new_res_x;
- RES_Y = new_res_y;
- }
+ DEBUGMSG(debug_sdl, "ChangeWindowSize() can be run only in windowed mode !");
}
+/* switch between fullscreen and windowed mode */
void SwitchScreenMode(void)
{
int window = (screen->flags & SDL_FULLSCREEN);
SDL_Surface* oldscreen = screen;
- if (!window)
- {
- RES_X = fs_res_x;
- RES_Y = fs_res_y;
- }
- else
- {
- RES_X = 640;
- RES_Y = 480;
- }
-
- screen = SDL_SetVideoMode(RES_X,
- RES_Y,
+ screen = SDL_SetVideoMode(window ? win_res_x : fs_res_x,
+ window ? win_res_y : fs_res_y,
PIXEL_BITS,
screen->flags ^ SDL_FULLSCREEN);
@@ -446,8 +442,6 @@
window ? "windowed" : "fullscreen",
SDL_GetError());
screen = oldscreen;
- RES_X = screen->w;
- RES_Y = screen->h;
}
else
{
@@ -456,7 +450,6 @@
oldscreen = NULL;
SDL_UpdateRect(screen, 0, 0, 0, 0);
}
-
}
/*
Modified: tuxmath/trunk/src/SDL_extras.h
===================================================================
--- tuxmath/trunk/src/SDL_extras.h 2009-06-29 16:03:58 UTC (rev 1109)
+++ tuxmath/trunk/src/SDL_extras.h 2009-06-29 17:53:08 UTC (rev 1110)
@@ -35,7 +35,7 @@
int inRect(SDL_Rect r, int x, int y);
void DarkenScreen(Uint8 bits);
void SwitchScreenMode(void);
-void ChangeScreenSize(int new_res_x, int new_res_y);
+void ChangeWindowSize(int new_res_x, int new_res_y);
SDL_EventType WaitForEvent(SDL_EventMask events);
SDL_Surface* Blend(SDL_Surface *S1, SDL_Surface *S2,float gamma);
SDL_Surface* zoom(SDL_Surface* src, int new_w, int new_h);
Modified: tuxmath/trunk/src/fileops_media.c
===================================================================
--- tuxmath/trunk/src/fileops_media.c 2009-06-29 16:03:58 UTC (rev 1109)
+++ tuxmath/trunk/src/fileops_media.c 2009-06-29 17:53:08 UTC (rev 1110)
@@ -22,150 +22,150 @@
int i;
static char* image_filenames[NUM_IMAGES] = {
- DATA_PREFIX "/images/status/standby.png",
- DATA_PREFIX "/images/title/menu_bkg.jpg",
- DATA_PREFIX "/images/title/title1.png",
- DATA_PREFIX "/images/status/title.png",
- DATA_PREFIX "/images/status/left.png",
- DATA_PREFIX "/images/status/left_gray.png",
- DATA_PREFIX "/images/status/right.png",
- DATA_PREFIX "/images/status/right_gray.png",
- DATA_PREFIX "/images/status/tux4kids.png",
- DATA_PREFIX "/images/status/nbs.png",
- DATA_PREFIX "/images/cities/city-blue.png",
- DATA_PREFIX "/images/cities/csplode-blue-1.png",
- DATA_PREFIX "/images/cities/csplode-blue-2.png",
- DATA_PREFIX "/images/cities/csplode-blue-3.png",
- DATA_PREFIX "/images/cities/csplode-blue-4.png",
- DATA_PREFIX "/images/cities/csplode-blue-5.png",
- DATA_PREFIX "/images/cities/cdead-blue.png",
- DATA_PREFIX "/images/cities/city-green.png",
- DATA_PREFIX "/images/cities/csplode-green-1.png",
- DATA_PREFIX "/images/cities/csplode-green-2.png",
- DATA_PREFIX "/images/cities/csplode-green-3.png",
- DATA_PREFIX "/images/cities/csplode-green-4.png",
- DATA_PREFIX "/images/cities/csplode-green-5.png",
- DATA_PREFIX "/images/cities/cdead-green.png",
- DATA_PREFIX "/images/cities/city-orange.png",
- DATA_PREFIX "/images/cities/csplode-orange-1.png",
- DATA_PREFIX "/images/cities/csplode-orange-2.png",
- DATA_PREFIX "/images/cities/csplode-orange-3.png",
- DATA_PREFIX "/images/cities/csplode-orange-4.png",
- DATA_PREFIX "/images/cities/csplode-orange-5.png",
- DATA_PREFIX "/images/cities/cdead-orange.png",
- DATA_PREFIX "/images/cities/city-red.png",
- DATA_PREFIX "/images/cities/csplode-red-1.png",
- DATA_PREFIX "/images/cities/csplode-red-2.png",
- DATA_PREFIX "/images/cities/csplode-red-3.png",
- DATA_PREFIX "/images/cities/csplode-red-4.png",
- DATA_PREFIX "/images/cities/csplode-red-5.png",
- DATA_PREFIX "/images/cities/cdead-red.png",
- DATA_PREFIX "/images/cities/shields.png",
- DATA_PREFIX "/images/comets/comet1.png",
- DATA_PREFIX "/images/comets/comet2.png",
- DATA_PREFIX "/images/comets/comet3.png",
- DATA_PREFIX "/images/comets/cometex3.png",
- DATA_PREFIX "/images/comets/cometex3.png",
- DATA_PREFIX "/images/comets/cometex2.png",
- DATA_PREFIX "/images/comets/cometex2.png",
- DATA_PREFIX "/images/comets/cometex1a.png",
- DATA_PREFIX "/images/comets/cometex1a.png",
- DATA_PREFIX "/images/comets/cometex1.png",
- DATA_PREFIX "/images/comets/cometex1.png",
- DATA_PREFIX "/images/comets/mini_comet1.png",
- DATA_PREFIX "/images/comets/mini_comet2.png",
- DATA_PREFIX "/images/comets/mini_comet3.png",
- DATA_PREFIX "/images/comets/bonus_comet1.png",
- DATA_PREFIX "/images/comets/bonus_comet2.png",
- DATA_PREFIX "/images/comets/bonus_comet3.png",
- DATA_PREFIX "/images/comets/bonus_cometex3.png",
- DATA_PREFIX "/images/comets/bonus_cometex3.png",
- DATA_PREFIX "/images/comets/bonus_cometex2.png",
- DATA_PREFIX "/images/comets/bonus_cometex2.png",
- DATA_PREFIX "/images/comets/bonus_cometex1a.png",
- DATA_PREFIX "/images/comets/bonus_cometex1a.png",
- DATA_PREFIX "/images/comets/bonus_cometex1.png",
- DATA_PREFIX "/images/comets/bonus_cometex1.png",
- DATA_PREFIX "/images/status/nums.png",
- DATA_PREFIX "/images/status/lednums.png",
- DATA_PREFIX "/images/status/led_neg_sign.png",
- DATA_PREFIX "/images/status/paused.png",
- DATA_PREFIX "/images/status/demo.png",
- DATA_PREFIX "/images/status/demo-small.png",
- DATA_PREFIX "/images/status/keypad.png",
- DATA_PREFIX "/images/status/keypad_no_neg.png",
- DATA_PREFIX "/images/tux/console_led.png",
- DATA_PREFIX "/images/tux/console_bash.png",
- DATA_PREFIX "/images/tux/tux-console1.png",
- DATA_PREFIX "/images/tux/tux-console2.png",
- DATA_PREFIX "/images/tux/tux-console3.png",
- DATA_PREFIX "/images/tux/tux-console4.png",
- DATA_PREFIX "/images/tux/tux-relax1.png",
- DATA_PREFIX "/images/tux/tux-relax2.png",
- DATA_PREFIX "/images/tux/tux-egypt1.png",
- DATA_PREFIX "/images/tux/tux-egypt2.png",
- DATA_PREFIX "/images/tux/tux-egypt3.png",
- DATA_PREFIX "/images/tux/tux-egypt4.png",
- DATA_PREFIX "/images/tux/tux-drat.png",
- DATA_PREFIX "/images/tux/tux-yipe.png",
- DATA_PREFIX "/images/tux/tux-yay1.png",
- DATA_PREFIX "/images/tux/tux-yay2.png",
- DATA_PREFIX "/images/tux/tux-yes1.png",
- DATA_PREFIX "/images/tux/tux-yes2.png",
- DATA_PREFIX "/images/tux/tux-sit.png",
- DATA_PREFIX "/images/tux/tux-fist1.png",
- DATA_PREFIX "/images/tux/tux-fist2.png",
- DATA_PREFIX "/images/penguins/flapdown.png",
- DATA_PREFIX "/images/penguins/flapup.png",
- DATA_PREFIX "/images/penguins/incoming.png",
- DATA_PREFIX "/images/penguins/grumpy.png",
- DATA_PREFIX "/images/penguins/worried.png",
- DATA_PREFIX "/images/penguins/standing-up.png",
- DATA_PREFIX "/images/penguins/sitting-down.png",
- DATA_PREFIX "/images/penguins/walk-on1.png",
- DATA_PREFIX "/images/penguins/walk-on2.png",
- DATA_PREFIX "/images/penguins/walk-on3.png",
- DATA_PREFIX "/images/penguins/walk-off1.png",
- DATA_PREFIX "/images/penguins/walk-off2.png",
- DATA_PREFIX "/images/penguins/walk-off3.png",
- DATA_PREFIX "/images/igloos/melted3.png",
- DATA_PREFIX "/images/igloos/melted2.png",
- DATA_PREFIX "/images/igloos/melted1.png",
- DATA_PREFIX "/images/igloos/half.png",
- DATA_PREFIX "/images/igloos/intact.png",
- DATA_PREFIX "/images/igloos/rebuilding1.png",
- DATA_PREFIX "/images/igloos/rebuilding2.png",
- DATA_PREFIX "/images/igloos/steam1.png",
- DATA_PREFIX "/images/igloos/steam2.png",
- DATA_PREFIX "/images/igloos/steam3.png",
- DATA_PREFIX "/images/igloos/steam4.png",
- DATA_PREFIX "/images/igloos/steam5.png",
- DATA_PREFIX "/images/igloos/cloud.png",
- DATA_PREFIX "/images/igloos/snow1.png",
- DATA_PREFIX "/images/igloos/snow2.png",
- DATA_PREFIX "/images/igloos/snow3.png",
- DATA_PREFIX "/images/igloos/extra_life.png",
- DATA_PREFIX "/images/status/wave.png",
- DATA_PREFIX "/images/status/score.png",
- DATA_PREFIX "/images/status/stop.png",
- DATA_PREFIX "/images/status/numbers.png",
- DATA_PREFIX "/images/status/gameover.png",
- DATA_PREFIX "/images/status/gameover_won.png",
- DATA_PREFIX "/images/factoroids/gbstars.png",
- DATA_PREFIX "/images/factoroids/asteroid1.png",
- DATA_PREFIX "/images/factoroids/asteroid2.png",
- DATA_PREFIX "/images/factoroids/asteroid3.png",
- DATA_PREFIX "/images/factoroids/ship01.png",
- DATA_PREFIX "/images/factoroids/factoroids.png",
- DATA_PREFIX "/images/factoroids/factors.png",
- DATA_PREFIX "/images/factoroids/tux.png",
- DATA_PREFIX "/images/factoroids/good.png"
+ "status/standby.png",
+ "title/menu_bkg.jpg",
+ "title/title1.png",
+ "status/title.png",
+ "status/left.png",
+ "status/left_gray.png",
+ "status/right.png",
+ "status/right_gray.png",
+ "status/tux4kids.png",
+ "status/nbs.png",
+ "cities/city-blue.png",
+ "cities/csplode-blue-1.png",
+ "cities/csplode-blue-2.png",
+ "cities/csplode-blue-3.png",
+ "cities/csplode-blue-4.png",
+ "cities/csplode-blue-5.png",
+ "cities/cdead-blue.png",
+ "cities/city-green.png",
+ "cities/csplode-green-1.png",
+ "cities/csplode-green-2.png",
+ "cities/csplode-green-3.png",
+ "cities/csplode-green-4.png",
+ "cities/csplode-green-5.png",
+ "cities/cdead-green.png",
+ "cities/city-orange.png",
+ "cities/csplode-orange-1.png",
+ "cities/csplode-orange-2.png",
+ "cities/csplode-orange-3.png",
+ "cities/csplode-orange-4.png",
+ "cities/csplode-orange-5.png",
+ "cities/cdead-orange.png",
+ "cities/city-red.png",
+ "cities/csplode-red-1.png",
+ "cities/csplode-red-2.png",
+ "cities/csplode-red-3.png",
+ "cities/csplode-red-4.png",
+ "cities/csplode-red-5.png",
+ "cities/cdead-red.png",
+ "cities/shields.png",
+ "comets/comet1.svg",
+ "comets/comet2.svg",
+ "comets/comet3.svg",
+ "comets/cometex3.png",
+ "comets/cometex3.png",
+ "comets/cometex2.png",
+ "comets/cometex2.png",
+ "comets/cometex1a.png",
+ "comets/cometex1a.png",
+ "comets/cometex1.png",
+ "comets/cometex1.png",
+ "comets/mini_comet1.png",
+ "comets/mini_comet2.png",
+ "comets/mini_comet3.png",
+ "comets/bonus_comet1.png",
+ "comets/bonus_comet2.png",
+ "comets/bonus_comet3.png",
+ "comets/bonus_cometex3.png",
+ "comets/bonus_cometex3.png",
+ "comets/bonus_cometex2.png",
+ "comets/bonus_cometex2.png",
+ "comets/bonus_cometex1a.png",
+ "comets/bonus_cometex1a.png",
+ "comets/bonus_cometex1.png",
+ "comets/bonus_cometex1.png",
+ "status/nums.png",
+ "status/lednums.png",
+ "status/led_neg_sign.png",
+ "status/paused.png",
+ "status/demo.png",
+ "status/demo-small.png",
+ "status/keypad.png",
+ "status/keypad_no_neg.png",
+ "tux/console_led.png",
+ "tux/console_bash.png",
+ "tux/tux-console1.png",
+ "tux/tux-console2.png",
+ "tux/tux-console3.png",
+ "tux/tux-console4.png",
+ "tux/tux-relax1.png",
+ "tux/tux-relax2.png",
+ "tux/tux-egypt1.png",
+ "tux/tux-egypt2.png",
+ "tux/tux-egypt3.png",
+ "tux/tux-egypt4.png",
+ "tux/tux-drat.png",
+ "tux/tux-yipe.png",
+ "tux/tux-yay1.png",
+ "tux/tux-yay2.png",
+ "tux/tux-yes1.png",
+ "tux/tux-yes2.png",
+ "tux/tux-sit.png",
+ "tux/tux-fist1.png",
+ "tux/tux-fist2.png",
+ "penguins/flapdown.png",
+ "penguins/flapup.png",
+ "penguins/incoming.png",
+ "penguins/grumpy.png",
+ "penguins/worried.png",
+ "penguins/standing-up.png",
+ "penguins/sitting-down.png",
+ "penguins/walk-on1.png",
+ "penguins/walk-on2.png",
+ "penguins/walk-on3.png",
+ "penguins/walk-off1.png",
+ "penguins/walk-off2.png",
+ "penguins/walk-off3.png",
+ "igloos/melted3.png",
+ "igloos/melted2.png",
+ "igloos/melted1.png",
+ "igloos/half.png",
+ "igloos/intact.png",
+ "igloos/rebuilding1.png",
+ "igloos/rebuilding2.png",
+ "igloos/steam1.png",
+ "igloos/steam2.png",
+ "igloos/steam3.png",
+ "igloos/steam4.png",
+ "igloos/steam5.png",
+ "igloos/cloud.png",
+ "igloos/snow1.png",
+ "igloos/snow2.png",
+ "igloos/snow3.png",
+ "igloos/extra_life.png",
+ "status/wave.png",
+ "status/score.png",
+ "status/stop.png",
+ "status/numbers.png",
+ "status/gameover.png",
+ "status/gameover_won.png",
+ "factoroids/gbstars.png",
+ "factoroids/asteroid1.png",
+ "factoroids/asteroid2.png",
+ "factoroids/asteroid3.png",
+ "factoroids/ship01.png",
+ "factoroids/factoroids.png",
+ "factoroids/factors.png",
+ "factoroids/tux.png",
+ "factoroids/good.png"
};
/* Load images: */
for (i = 0; i < NUM_IMAGES; i++)
{
- images[i] = LoadImageFromFile(image_filenames[i]);
+ images[i] = LoadImage(image_filenames[i], IMG_ALPHA);
if (images[i] == NULL)
{
Modified: tuxmath/trunk/src/game.c
===================================================================
--- tuxmath/trunk/src/game.c 2009-06-29 16:03:58 UTC (rev 1109)
+++ tuxmath/trunk/src/game.c 2009-06-29 17:53:08 UTC (rev 1110)
@@ -467,10 +467,10 @@
void game_set_start_message(const char* m1, const char* m2,
const char* m3, const char* m4)
{
- game_set_message(&s1, m1, -1, RES_Y * 2 / 10);
- game_set_message(&s2, m2, screen->w / 2 - 40, RES_Y * 3 / 10);
- game_set_message(&s3, m3, screen->w / 2 - 40, RES_Y * 4 / 10);
- game_set_message(&s4, m4, screen->w / 2 - 40, RES_Y * 5 / 10);
+ game_set_message(&s1, m1, -1, screen->h * 2 / 10);
+ game_set_message(&s2, m2, screen->w / 2 - 40, screen->h * 3 / 10);
+ game_set_message(&s3, m3, screen->w / 2 - 40, screen->h * 4 / 10);
+ game_set_message(&s4, m4, screen->w / 2 - 40, screen->h * 5 / 10);
start_message_chosen = 1;
}
@@ -1327,12 +1327,12 @@
if (comets[i].bonus)
{
comets[i].y += speed * Opts_BonusSpeedRatio() *
- city_expl_height / (RES_Y - images[IMG_CITY_BLUE]->h);
+ city_expl_height / (screen->h - images[IMG_CITY_BLUE]->h);
}
else /* Regular comet: */
{
comets[i].y += speed *
- city_expl_height / (RES_Y - images[IMG_CITY_BLUE]->h);
+ city_expl_height / (screen->h - images[IMG_CITY_BLUE]->h);
}
/* Does it threaten a city? */
Modified: tuxmath/trunk/src/globals.h
===================================================================
--- tuxmath/trunk/src/globals.h 2009-06-29 16:03:58 UTC (rev 1109)
+++ tuxmath/trunk/src/globals.h 2009-06-29 17:53:08 UTC (rev 1110)
@@ -134,9 +134,6 @@
#define PIXEL_BITS 32
-extern int RES_X;
-extern int RES_Y;
-
enum {
CADET_HIGH_SCORE,
SCOUT_HIGH_SCORE,
Modified: tuxmath/trunk/src/loaders.c
===================================================================
--- tuxmath/trunk/src/loaders.c 2009-06-29 16:03:58 UTC (rev 1109)
+++ tuxmath/trunk/src/loaders.c 2009-06-29 17:53:08 UTC (rev 1110)
@@ -1,71 +1,60 @@
-/***************************************************************************
- - file: loaders.c
- - description: Functions to load multimedia for Tux Typing
- -------------------
- begin : Thu May 4 2000
- copyright : (C) 2000 by Sam Hart
- : (C) 2003 by Jesse Andrews
- email : tuxtype-dev at tux4kids.net
+/*
+ loaders.c
- Modified for use in tuxmath by David Bruce - 2006.
- email : <dbruce at tampabay.rr.com>
- <tuxmath-devel at lists.sourceforge.net>
- ***************************************************************************/
+ Functions responsible for loading multimedia.
-/***************************************************************************
- * *
- * 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. *
- * *
- ***************************************************************************/
+ begin : Thu May 4 2000
+ copyright : (C) 2000 by Sam Hart
+ : (C) 2003 by Jesse Andrews
+ email : tuxtype-dev at tux4kids.net
-//#include "globals.h"
-//#include "funcs.h"
+ Modified for use in tuxmath by David Bruce - 2006.
+ email : <dbruce at tampabay.rr.com>
+ <tuxmath-devel at lists.sourceforge.net>
-#include "tuxmath.h" // for TUXMATH_DEBUG
+ Modified to support SVG by Boleslaw Kulbabinski - 2009
+ email : <bkulbabinski at gmail.com>
+
+ Part of "Tux4Kids" Project
+ http://www.tux4kids.com/
+
+ Copyright: See COPYING file that comes with this distribution.
+*/
+
#include "loaders.h"
-#include "setup.h" // for cleanup_on_error()
+#include "globals.h"
+#include "tuxmath.h"
+#include "setup.h" // for cleanup_on_error()
#include "SDL_extras.h"
-/* FIXME Doesn't seem to work consistently on all versions of Windows */
+
/* check to see if file exists, if so return true */
// int checkFile( const char *file ) {
// static struct stat fileStats;
-//
// fileStats.st_mode = 0;
-//
// stat( file, &fileStats );
-//
// return (S_IFREG & fileStats.st_mode);
// }
/* Returns 1 if valid file, 2 if valid dir, 0 if neither: */
-int checkFile(const char* file)
+int check_file(const char* file)
{
FILE* fp = NULL;
DIR* dp = NULL;
if (!file)
{
- fprintf(stderr, "CheckFile(): invalid char* argument!");
+ fprintf(stderr, "check_file(): invalid char* argument!");
return 0;
}
-#ifdef TUXMATH_DEBUG
- fprintf(stderr, "CheckFile() - checking: %s\n", file);
-#endif
+ DEBUGMSG(debug_loaders, "check_file(): checking: %s\n", file);
dp = opendir(file);
if (dp)
{
-
-#ifdef TUXMATH_DEBUG
- fprintf(stderr, "Opened successfully as DIR\n");
-#endif
-
+ DEBUGMSG(debug_loaders, "check_file(): Opened successfully as DIR\n");
closedir(dp);
return 2;
}
@@ -73,31 +62,27 @@
fp = fopen(file, "r");
if (fp)
{
-
-#ifdef TUXMATH_DEBUG
- fprintf(stderr, "Opened successfully as FILE\n");
-#endif
-
+ DEBUGMSG(debug_loaders, "check_file(): Opened successfully as FILE\n");
fclose(fp);
return 1;
}
- fprintf(stderr, "Unable to open '%s' as either FILE or DIR\n", file);
+ fprintf(stderr, "check_file(): Unable to open '%s' as either FILE or DIR\n", file);
return 0;
}
#ifdef HAVE_RSVG
-/***********************
- SVG related functions
-************************/
+
#include<librsvg/rsvg.h>
#include<librsvg/rsvg-cairo.h>
-/* Load an SVG file and resize it to given dimensions.
- if width or height is set to 0 no resizing is applied
+/* Load a layer of SVG file and resize it to given dimensions.
+ If width or height is negative no resizing is applied.
+ If layer = NULL then the whole image is loaded.
+ Return NULL on failure.
(partly based on TuxPaint's SVG loading function) */
-SDL_Surface* LoadSVGOfDimensions(char* filename, int width, int height)
+SDL_Surface* load_svg(char* file_name, int width, int height, char* layer_name)
{
cairo_surface_t* temp_surf;
cairo_t* context;
@@ -106,31 +91,26 @@
SDL_Surface* dest;
float scale_x;
float scale_y;
- int bpp = 32;
Uint32 Rmask, Gmask, Bmask, Amask;
+ char* full_layer_name;
-#ifdef TUXMATH_DEBUG
- fprintf(stderr, "LoadSVGOfDimensions(): looking for %s\n", filename);
-#endif
+ DEBUGMSG(debug_loaders, "load_svg(): looking for %s\n", file_name);
rsvg_init();
- file_handle = rsvg_handle_new_from_file(filename, NULL);
+ file_handle = rsvg_handle_new_from_file(file_name, NULL);
if(file_handle == NULL)
{
-#ifdef TUXMATH_DEBUG
- fprintf(stderr, "LoadSVGOfDimensions(): file %s not found\n", filename);
-#endif
+ DEBUGMSG(debug_loaders, "load_svg(): file %s not found\n", file_name);
rsvg_term();
return NULL;
}
rsvg_handle_get_dimensions(file_handle, &dimensions);
-#ifdef TUXMATH_DEBUG
- fprintf(stderr, "SVG is %d x %d\n", dimensions.width, dimensions.height);
-#endif
- if(width <= 0 || height <= 0)
+ DEBUGMSG(debug_loaders, "load_svg(): SVG is %d x %d\n", dimensions.width, dimensions.height);
+
+ if(width < 0 || height < 0)
{
width = dimensions.width;
height = dimensions.height;
@@ -143,17 +123,20 @@
scale_y = (float)height / dimensions.height;
}
- /* FIXME: We assume that our bpp = 32 */
+ Rmask = screen->format->Rmask;
+ Gmask = screen->format->Gmask;
+ Bmask = screen->format->Bmask;
+ if(screen->format->Amask == 0)
+ /* find a free byte to use for Amask */
+ Amask = ~(Rmask | Gmask | Bmask);
+ else
+ Amask = screen->format->Amask;
- /* rmask, gmask, bmask, amask defined in SDL_extras.h do not work !
- are those (taken from TuxPaint) dependent on endianness ? */
- Rmask = 0x00ff0000;
- Gmask = 0x0000ff00;
- Bmask = 0x000000ff;
- Amask = 0xff000000;
+ DEBUGMSG(debug_loaders, "load_svg(): color masks: R=%u, G=%u, B=%u, A=%u ",
+ Rmask, Gmask, Bmask, Amask);
dest = SDL_CreateRGBSurface(SDL_SWSURFACE | SDL_SRCALPHA,
- width, height, bpp, Rmask, Gmask, Bmask, Amask);
+ width, height, screen->format->BitsPerPixel, Rmask, Gmask, Bmask, Amask);
SDL_LockSurface(dest);
temp_surf = cairo_image_surface_create_for_data(dest->pixels,
@@ -162,9 +145,7 @@
context = cairo_create(temp_surf);
if(cairo_status(context) != CAIRO_STATUS_SUCCESS)
{
-#ifdef TUXMATH_DEBUG
- fprintf(stderr, "LoadSVGOfDimensions(): error rendering SVG from %s\n", filename);
-#endif
+ DEBUGMSG(debug_loaders, "load_svg(): error rendering SVG from %s\n", file_name);
g_object_unref(file_handle);
cairo_surface_destroy(temp_surf);
rsvg_term();
@@ -172,8 +153,22 @@
}
cairo_scale(context, scale_x, scale_y);
- rsvg_handle_render_cairo(file_handle, context);
+ /* insert '#' symbol at the beginning of layername */
+ if(layer_name != NULL)
+ {
+ full_layer_name = malloc((strlen(layer_name) + 2) * sizeof(char));
+ sprintf(full_layer_name, "#%s", layer_name);
+ }
+ else
+ full_layer_name = NULL;
+
+ /* render appropriate layer */
+ rsvg_handle_render_cairo_sub(file_handle, context, full_layer_name);
+
+ if(full_layer_name != NULL)
+ free(full_layer_name);
+
SDL_UnlockSurface(dest);
g_object_unref(file_handle);
@@ -184,229 +179,179 @@
return dest;
}
-#endif
+#endif /* HAVE_RSVG */
-/***********************
- LoadImageFromFile : Simply load an image from given file
- or its SVG equivalent (if present). Return NULL if loading failed.
-************************/
-SDL_Surface* LoadImageFromFile(char *datafile)
+
+/* LoadScaledImage : Load an image and resize it to given dimensions.
+ If width or height is negative no resizing is applied.
+ The loader (load_svg() or IMG_Load()) is chosen depending on file extension,
+ If an SVG file is not found try to load its PNG equivalent
+ (unless IMG_NO_PNG_FALLBACK is set) */
+SDL_Surface* LoadScaledImage(char* file_name, int mode, int width, int height)
{
- SDL_Surface* tmp_pic = NULL;
+ SDL_Surface* loaded_pic = NULL;
+ SDL_Surface* final_pic = NULL;
+ char fn[PATH_MAX];
+ int fn_len;
-#ifdef HAVE_RSVG
- char svgfn[PATH_MAX];
-#endif
+ if(NULL == file_name)
+ {
+ DEBUGMSG(debug_loaders, "LoadScaledImage(): file_name is NULL, exiting.\n");
+ return NULL;
+ }
-#ifdef TUXMATH_DEBUG
- fprintf(stderr, "LoadImageFromFile(): looking in %s\n", datafile);
-#endif
+ /* run loader depending on file extension */
+ /* add path prefix */
+ sprintf(fn, "%s/images/%s", DATA_PREFIX, file_name);
+ fn_len = strlen(fn);
+
+ if(strcmp(fn + fn_len - 4, ".svg"))
+ {
+ DEBUGMSG(debug_loaders, "LoadScaledImage(): %s is not an SVG, loading using IMG_Load()\n", fn);
+ loaded_pic = IMG_Load(fn);
+ }
+ else
+ {
#ifdef HAVE_RSVG
- /* This is just an ugly workaround to test SVG
- before any scaling routines are implemented */
+ DEBUGMSG(debug_loaders, "LoadScaledImage(): trying to load %s as SVG.\n", fn);
+ loaded_pic = load_svg(fn, width, height, NULL);
+#endif
- /* change extension into .svg */
- char* dotpos = strrchr(datafile, '.');
- strncpy(svgfn, datafile, dotpos - datafile);
- svgfn[dotpos - datafile] = '\0';
- strcat(svgfn, ".svg");
-
- /* try to load an SVG equivalent */
- tmp_pic = LoadSVGOfDimensions(svgfn, 0, 0);
+ if(loaded_pic == NULL)
+ {
+#ifdef HAVE_RSVG
+ DEBUGMSG(debug_loaders, "LoadScaledImage(): failed to load %s as SVG.\n", fn);
+#else
+ DEBUGMSG(debug_loaders, "LoadScaledImage(): SVG support not available.\n");
#endif
+ if(mode & IMG_NO_PNG_FALLBACK)
+ {
+ DEBUGMSG(debug_loaders, "LoadScaledImage(): %s : IMG_NO_PNG_FALLBACK is set.\n", fn);
+ }
+ else
+ {
+ DEBUGMSG(debug_loaders, "LoadScaledImage(): Trying to load PNG eqivalent of %s\n", fn);
+ strcpy(fn + fn_len - 3, "png");
- if(tmp_pic == NULL)
- /* Try to load image with SDL_image: */
- tmp_pic = IMG_Load(datafile);
+ loaded_pic = IMG_Load(fn);
+ }
+ }
+ }
- return tmp_pic;
-}
-
-/* FIXME checkFile() not working right in Win32 - skipping. */
-/***********************
- LoadImage : Load an image and set transparent if requested
-************************/
-SDL_Surface* LoadImage( char *datafile, int mode )
-{
- SDL_Surface* tmp_pic = NULL;
- SDL_Surface* final_pic = NULL;
-
- char fn[PATH_MAX];
-
- sprintf( fn, "%s/images/%s", DATA_PREFIX, datafile );
-
-
- tmp_pic = LoadImageFromFile(fn);
-
- if (NULL == tmp_pic) /* Could not load image: */
+ if (NULL == loaded_pic) /* Could not load image: */
{
if (mode & IMG_NOT_REQUIRED)
- {
-#ifdef TUXMATH_DEBUG
- fprintf(stderr, "Warning: could not load optional graphics file %s\n", datafile);
-#endif
+ {
+ DEBUGMSG(debug_loaders, "LoadScaledImage(): Warning: could not load optional graphics file %s\n", file_name);
return NULL; /* Allow program to continue */
}
/* If image was required, exit from program: */
- fprintf(stderr, "ERROR could not load required graphics file %s\n", datafile);
+ fprintf(stderr, "LoadScaledImage(): ERROR could not load required graphics file %s\n", file_name);
fprintf(stderr, "%s", SDL_GetError() );
cleanup_on_error();
}
/* "else" - now setup the image to the proper format */
+ if(width >= 0 && height >= 0 &&
+ (loaded_pic->w != width || loaded_pic->h != height))
+ {
+ final_pic = zoom(loaded_pic, width, height);
+ SDL_FreeSurface(loaded_pic);
+ loaded_pic = final_pic;
+ final_pic = NULL;
+ }
+
switch (mode & IMG_MODES)
{
case IMG_REGULAR:
- {
-
- final_pic = SDL_DisplayFormat(tmp_pic);
- SDL_FreeSurface(tmp_pic);
+ {
+ DEBUGMSG(debug_loaders, "LoadScaledImage(): handling IMG_REGULAR mode.\n");
+ final_pic = SDL_DisplayFormat(loaded_pic);
+ SDL_FreeSurface(loaded_pic);
break;
}
case IMG_ALPHA:
{
-
- final_pic = SDL_DisplayFormatAlpha(tmp_pic);
- SDL_FreeSurface(tmp_pic);
+ DEBUGMSG(debug_loaders, "LoadScaledImage(): handling IMG_ALPHA mode.\n");
+ final_pic = SDL_DisplayFormatAlpha(loaded_pic);
+ SDL_FreeSurface(loaded_pic);
break;
}
case IMG_COLORKEY:
{
-
- SDL_LockSurface(tmp_pic);
- SDL_SetColorKey(tmp_pic, (SDL_SRCCOLORKEY | SDL_RLEACCEL),
- SDL_MapRGB(tmp_pic->format, 255, 255, 0));
- final_pic = SDL_DisplayFormat(tmp_pic);
- SDL_FreeSurface(tmp_pic);
+ DEBUGMSG(debug_loaders, "LoadScaledImage(): handling IMG_COLORKEY mode.\n");
+ SDL_LockSurface(loaded_pic);
+ SDL_SetColorKey(loaded_pic, (SDL_SRCCOLORKEY | SDL_RLEACCEL),
+ SDL_MapRGB(loaded_pic->format, 255, 255, 0));
+ final_pic = SDL_DisplayFormat(loaded_pic);
+ SDL_FreeSurface(loaded_pic);
break;
}
default:
{
-#ifdef TUXMATH_DEBUG
- fprintf(stderr, "Image mode not recognized\n");
-#endif
- SDL_FreeSurface(tmp_pic);
+ DEBUGMSG(debug_loaders, "LoadScaledImage(): Image mode not recognized\n");
+ SDL_FreeSurface(loaded_pic);
}
}
-#ifdef TUXMATH_DEBUG
- fprintf(stderr, "Leaving LoadImage()\n\n");
-#endif
+
+ DEBUGMSG(debug_loaders, "Leaving LoadScaledImage()\n\n");
+
return final_pic;
}
-/***********************
- LoadBkgd() : a wrapper for LoadImage() that scales the
- image to the size of the screen using zoom(), taken
- from TuxPaint
-************************/
-SDL_Surface* LoadBkgd(char* datafile)
+/* Load an image without scaling it */
+SDL_Surface* LoadImage(char* file_name, int mode)
{
- SDL_Surface* orig;
- orig = LoadImage(datafile, IMG_REGULAR);
-
- if (!orig)
- {
- tmdprintf("In LoadBkgd(), LoadImage() returned NULL on %s\n",
- datafile);
- return NULL;
- }
-
- if ((orig->w == screen->w)
- && (orig->h == screen->h))
- {
- tmdprintf("No zoom required - return bkgd as is\n");
- return orig;
- }
- else
- {
- tmdprintf("Image is %dx%d\n", orig->w, orig->h);
- tmdprintf("Screen is %dx%d\n", screen->w, screen->h);
- tmdprintf("Calling zoom() to rescale\n");
- return zoom(orig, screen->w, screen->h);
- }
+ return LoadScaledImage(file_name, mode, -1, -1);
}
-/**********************
-LoadBothBkgds() : loads two scaled images: one for the user's native
-resolution and one for 640x480 fullscreen.
-Returns: the number of images that were scaled
-Now we also optimize the format for best performance
-**********************/
-int LoadBothBkgds(char* datafile, SDL_Surface** fs_bkgd, SDL_Surface** win_bkgd)
+
+/* LoadBkgd() : a wrapper for LoadImage() that optimizes
+ the format of background image */
+SDL_Surface* LoadBkgd(char* file_name, int width, int height)
{
- int ret = 0;
SDL_Surface* orig = NULL;
- SDL_Surface* tmp = NULL;
+ SDL_Surface* final_pic = NULL;
- tmdprintf("Entering LoadBothBkgds()\n");
- orig = LoadImage(datafile, IMG_REGULAR);
- tmdprintf("Scaling %dx%d to: %dx%d, %dx%d\n",
- orig->w, orig->h, RES_X, RES_Y, fs_res_x, fs_res_y);
- if (orig->w == RES_X && orig->h == RES_Y)
- {
- *win_bkgd = orig;
- }
- else
- {
- *win_bkgd = zoom(orig, RES_X, RES_Y);
- ++ret;
- }
-
- if (orig->w == fs_res_x && orig->h == fs_res_y)
- {
- *fs_bkgd = orig;
- }
- else
- {
- *fs_bkgd = zoom(orig, fs_res_x, fs_res_y);
- ++ret;
- }
-
- if (ret == 2) //orig won't be used at all
- SDL_FreeSurface(orig);
+ orig = LoadScaledImage(file_name, IMG_REGULAR, width, height);
- // Optimize images before we leave:
- // turn off transparency, since it's the background:
- if (*fs_bkgd) //avoid segfault...
+ if (!orig)
{
- SDL_SetAlpha(*fs_bkgd, SDL_RLEACCEL,SDL_ALPHA_OPAQUE);
- tmp = SDL_DisplayFormat(*fs_bkgd); // optimize the format
- SDL_FreeSurface(*fs_bkgd);
- *fs_bkgd = tmp;
+ DEBUGMSG(debug_loaders, "In LoadBkgd(), LoadImage() returned NULL on %s\n",
+ file_name);
+ return NULL;
}
- if (*win_bkgd)
- {
- SDL_SetAlpha(*win_bkgd, SDL_RLEACCEL,SDL_ALPHA_OPAQUE);
- tmp = SDL_DisplayFormat(*win_bkgd); // optimize the format
- SDL_FreeSurface(*win_bkgd);
- *win_bkgd = tmp;
- }
- tmdprintf("%d images scaled\nLeaving LoadBothBkgds()\n", ret);
- return ret;
+ /* turn off transparency, since it's the background */
+ SDL_SetAlpha(orig, SDL_RLEACCEL, SDL_ALPHA_OPAQUE);
+ final_pic = SDL_DisplayFormat(orig); /* optimize the format */
+ SDL_FreeSurface(orig);
+
+ return final_pic;
}
+/* LoadBothBkgds() : loads two scaled images: one for the fullscreen mode
+ (fs_res_x,fs_rex_y) and one for the windowed mode (win_res_x,win_rex_y)
+ Now we also optimize the format for best performance */
+void LoadBothBkgds(char* file_name, SDL_Surface** fs_bkgd, SDL_Surface** win_bkgd)
+{
+ DEBUGMSG(debug_loaders, "Entering LoadBothBkgds()\n");
+ *fs_bkgd = LoadBkgd(file_name, fs_res_x, fs_res_y);
+ *win_bkgd = LoadBkgd(file_name, win_res_x, win_res_y);
+}
-sprite* FlipSprite( sprite *in, int X, int Y ) {
- sprite *out;
- out = malloc(sizeof(sprite));
- if (in->default_img != NULL)
- out->default_img = Flip( in->default_img, X, Y );
- else
- out->default_img = NULL;
- for ( out->num_frames=0; out->num_frames<in->num_frames; out->num_frames++ )
- out->frame[out->num_frames] = Flip( in->frame[out->num_frames], X, Y );
- out->cur = 0;
- return out;
+sprite* LoadSprite(char* name, int mode)
+{
+ return LoadScaledSprite(name, mode, -1, -1);
}
-
-sprite* LoadSprite( char* name, int MODE ) {
+sprite* LoadScaledSprite(char* name, int mode, int width, int height)
+{
sprite *new_sprite;
char fn[PATH_MAX];
int x;
@@ -415,35 +360,49 @@
new_sprite = malloc(sizeof(sprite));
- sprintf(fn, "%sd.png", name); // The 'd' means the default image
- new_sprite->default_img = LoadImage( fn, MODE|IMG_NOT_REQUIRED );
- for (x = 0; x < MAX_SPRITE_FRAMES; x++) {
- sprintf(fn, "%s%d.png", name, x);
- new_sprite->frame[x] = LoadImage( fn, MODE|IMG_NOT_REQUIRED );
- if ( new_sprite->frame[x] == NULL ) {
- new_sprite->cur = 0;
- new_sprite->num_frames = x;
- break;
- }
+ sprintf(fn, "%sd.svg", name); // The 'd' means the default image
+ new_sprite->default_img = LoadScaledImage(fn, mode | IMG_NOT_REQUIRED, width, height);
+
+ for(x = 0; x < MAX_SPRITE_FRAMES; x++)
+ {
+ sprintf(fn, "%s%d.svg", name, x);
+ new_sprite->frame[x] = LoadScaledImage(fn, mode | IMG_NOT_REQUIRED, width, height);
+ if( new_sprite->frame[x] == NULL)
+ {
+ new_sprite->cur = 0;
+ new_sprite->num_frames = x;
+ break;
+ }
}
-
-
return new_sprite;
}
+sprite* FlipSprite(sprite* in, int X, int Y)
+{
+ sprite *out;
+ out = malloc(sizeof(sprite));
+ if (in->default_img != NULL)
+ out->default_img = Flip( in->default_img, X, Y );
+ else
+ out->default_img = NULL;
+ for( out->num_frames=0; out->num_frames<in->num_frames; out->num_frames++ )
+ out->frame[out->num_frames] = Flip( in->frame[out->num_frames], X, Y );
+ out->cur = 0;
+ return out;
+}
-void FreeSprite(sprite* gfx )
+void FreeSprite(sprite* gfx)
{
int x;
if (!gfx)
return;
- tmdprintf("Freeing image at %p", gfx);
+ DEBUGMSG(debug_loaders, "Freeing image at %p", gfx);
for (x = 0; x < gfx->num_frames; x++)
{
- tmdprintf(".");
+ DEBUGMSG(debug_loaders, ".");
if (gfx->frame[x])
{
SDL_FreeSurface(gfx->frame[x]);
@@ -457,21 +416,21 @@
gfx->default_img = NULL;
}
- tmdprintf("FreeSprite() - done\n");
+ DEBUGMSG(debug_loaders, "FreeSprite() - done\n");
free(gfx);
}
-void next_frame(sprite* s)
+void NextFrame(sprite* s)
{
if (s && s->num_frames)
s->cur = (s->cur + 1) % s->num_frames;
}
-/***************************
- LoadSound : Load a sound/music patch from a file.
-****************************/
+
+
+/* LoadSound : Load a sound/music patch from a file. */
Mix_Chunk* LoadSound( char *datafile )
-{
+{
Mix_Chunk* tempChunk = NULL;
char fn[PATH_MAX];
@@ -485,17 +444,14 @@
return tempChunk;
}
-/************************
- LoadMusic : Load
- music from a datafile
-*************************/
+/* LoadMusic : Load music from a datafile */
Mix_Music *LoadMusic(char *datafile )
-{
+{
char fn[PATH_MAX];
Mix_Music* tempMusic = NULL;
sprintf( fn , "%s/sounds/%s", DATA_PREFIX, datafile );
- if (1 != checkFile(fn))
+ if (1 != check_file(fn))
{
fprintf(stderr, "LoadMusic(): %s not found\n\n", fn);
return NULL;
@@ -510,3 +466,4 @@
}
return tempMusic;
}
+
Modified: tuxmath/trunk/src/loaders.h
===================================================================
--- tuxmath/trunk/src/loaders.h 2009-06-29 16:03:58 UTC (rev 1109)
+++ tuxmath/trunk/src/loaders.h 2009-06-29 17:53:08 UTC (rev 1110)
@@ -1,17 +1,21 @@
-//
-// C++ Interface: loaders
-//
-// Description:
-//
-//
-// Author: David Bruce <davidstuartbruce at gmail.com>, (C) 2009
-//
-// Copyright: See COPYING file that comes with this distribution
-//
-//
-#ifndef LOADERS_C
-#define LOADERS_C
+/*
+ loaders.h
+ Functions responsible for loading multimedia.
+ (interface)
+
+ Author: David Bruce <davidstuartbruce at gmail.com>, (C) 2009
+ Boleslaw Kulbabinski <bkulbabinski at gmail.com>, (C) 2009
+
+ Part of "Tux4Kids" Project
+ http://www.tux4kids.com/
+
+ Copyright: See COPYING file that comes with this distribution.
+*/
+
+#ifndef LOADERS_H
+#define LOADERS_H
+
#include "tuxmath.h"
#include <string.h>
@@ -22,15 +26,16 @@
#include <sys/stat.h>
#include <dirent.h>
-#define MAX_SPRITE_FRAMES 30
+#define MAX_SPRITE_FRAMES 30
-#define IMG_REGULAR 0x01
-#define IMG_COLORKEY 0x02
-#define IMG_ALPHA 0x04
-#define IMG_MODES 0x07
-#define IMG_NOT_REQUIRED 0x10
-#define IMG_NO_THEME 0x20
+#define IMG_REGULAR 0x01
+#define IMG_COLORKEY 0x02
+#define IMG_ALPHA 0x04
+#define IMG_MODES 0x07
+#define IMG_NOT_REQUIRED 0x10
+#define IMG_NO_PNG_FALLBACK 0x20
+
typedef struct {
SDL_Surface *frame[MAX_SPRITE_FRAMES];
SDL_Surface *default_img;
@@ -39,18 +44,19 @@
} sprite;
-/* in loaders.c (from tuxtype): */
-int checkFile( const char *file );
+SDL_Surface* LoadImage(char* file_name, int mode);
+SDL_Surface* LoadScaledImage(char* file_name, int mode, int width, int height);
+
+SDL_Surface* LoadBkgd(char* file_name, int width, int height);
+void LoadBothBkgds(char* file_name, SDL_Surface** fs_bkgd, SDL_Surface** win_bkgd);
+
+sprite* LoadSprite(char* name, int mode);
+sprite* LoadScaledSprite(char* name, int mode, int width, int height);
+sprite* FlipSprite(sprite* in, int X, int Y);
+void FreeSprite(sprite* gfx);
+void NextFrame(sprite* s);
+
Mix_Chunk* LoadSound( char* datafile );
-SDL_Surface* LoadImage( char* datafile, int mode );
-SDL_Surface* LoadBkgd(char* datafile);
-int LoadBothBkgds(char* datafile,
- SDL_Surface** fs_bkgd,
- SDL_Surface** win_bkgd);
-sprite* LoadSprite( char* name, int MODE );
-sprite* FlipSprite( sprite* in, int X, int Y );
-void FreeSprite( sprite* gfx );
Mix_Music* LoadMusic( char *datafile );
-void next_frame(sprite* s);
-#endif
+#endif /* LOADERS_H */
Modified: tuxmath/trunk/src/setup.c
===================================================================
--- tuxmath/trunk/src/setup.c 2009-06-29 16:03:58 UTC (rev 1109)
+++ tuxmath/trunk/src/setup.c 2009-06-29 17:53:08 UTC (rev 1110)
@@ -58,11 +58,14 @@
/* Global data used in setup.c: */
/* (These are now 'extern'd in "tuxmath.h") */
-int RES_X = 640;
-int RES_Y = 480;
-int fs_res_x = 640;
-int fs_res_y = 480;
+/* window size */
+int win_res_x = 640;
+int win_res_y = 480;
+/* full screen size (set in initialize_SDL() ) */
+int fs_res_x = 0;
+int fs_res_y = 0;
+
SDL_Surface* screen;
SDL_Surface* images[NUM_IMAGES];
/* Need special handling to generate flipped versions of images. This
@@ -583,12 +586,9 @@
if (!Opts_GetGlobalOpt(FULLSCREEN))
{
- screen = SDL_SetVideoMode(RES_X, RES_Y, PIXEL_BITS, surfaceMode);
+ screen = SDL_SetVideoMode(win_res_x, win_res_y, PIXEL_BITS, surfaceMode);
}
- RES_X = screen->w;
- RES_Y = screen->h;
-
if (screen == NULL)
{
fprintf(stderr,
Modified: tuxmath/trunk/src/titlescreen.c
===================================================================
--- tuxmath/trunk/src/titlescreen.c 2009-06-29 16:03:58 UTC (rev 1109)
+++ tuxmath/trunk/src/titlescreen.c 2009-06-29 17:53:08 UTC (rev 1110)
@@ -163,7 +163,6 @@
/* This syntax makes my brain start to explode! */
{ return screen->flags & SDL_FULLSCREEN ? scaled_bkg : bkg; }
-
/* Local function prototypes: */
int TitleScreen_load_menu(void);
void TitleScreen_unload_menu(void);
@@ -381,13 +380,13 @@
{
SDL_Surface* new_bkg = NULL;
- if(curr_res_x != RES_X || curr_res_y != RES_Y)
+ if(curr_res_x != screen->w || curr_res_y != screen->h)
{
/* we need to rerender titlescreen items */
DEBUGMSG(debug_titlescreen, "Re-rendering titlescreen items.\n");
/* background */
- new_bkg = LoadBkgd("title/menu_bkg.jpg");
+ new_bkg = LoadBkgd("title/menu_bkg.jpg", screen->w, screen->h);
if(new_bkg == NULL)
{
DEBUGMSG(debug_titlescreen, "RenderTitleScreen(): Failed to load new background.\n");
@@ -449,8 +448,8 @@
- curr_res_x = RES_X;
- curr_res_y = RES_Y;
+ curr_res_x = screen->w;
+ curr_res_y = screen->h;
DEBUGMSG(debug_titlescreen, "Leaving RenderTitleScreen().\n");
}
@@ -1924,25 +1923,25 @@
case SDLK_F5:
{
/* decrease screen width */
- ChangeScreenSize(RES_X - 50, RES_Y);
+ ChangeWindowSize(win_res_x - 50, win_res_y);
break;
}
case SDLK_F6:
{
/* increase screen width */
- ChangeScreenSize(RES_X + 50, RES_Y);
+ ChangeWindowSize(win_res_x + 50, win_res_y);
break;
}
case SDLK_F7:
{
/* decrease screen height */
- ChangeScreenSize(RES_X, RES_Y - 50);
+ ChangeWindowSize(win_res_x, win_res_y - 50);
break;
}
case SDLK_F8:
{
/* increase screen height */
- ChangeScreenSize(RES_X, RES_Y + 50);
+ ChangeWindowSize(win_res_x, win_res_y + 50);
break;
}
default:
@@ -2166,7 +2165,7 @@
menu_sprites[loc-title_offset]->cur = 0; // start at beginning of animation sequence
SDL_BlitSurface(menu_sprites[loc-title_offset]->frame[menu_sprites[loc-title_offset]->cur], NULL, screen, &menu_sprite_rect[imod]);
SDL_UpdateRect(screen, menu_sprite_rect[imod].x, menu_sprite_rect[imod].y, menu_sprite_rect[imod].w, menu_sprite_rect[imod].h);
- next_frame(menu_sprites[loc-title_offset]);
+ NextFrame(menu_sprites[loc-title_offset]);
}
SDL_UpdateRect(screen, menu_button_rect[imod].x, menu_button_rect[imod].y, menu_button_rect[imod].w, menu_button_rect[imod].h);
DEBUGMSG(debug_menu, "Updating rect: %d %d %d %d\n", menu_button_rect[imod].x, menu_button_rect[imod].y, menu_button_rect[imod].w, menu_button_rect[imod].h);
@@ -2188,7 +2187,7 @@
// the two lines above
SDL_BlitSurface(menu_sprites[loc-title_offset]->frame[menu_sprites[loc-title_offset]->cur], NULL, screen, &menu_sprite_rect[imod]);
SDL_UpdateRect(screen, menu_sprite_rect[imod].x, menu_sprite_rect[imod].y, menu_sprite_rect[imod].w, menu_sprite_rect[imod].h);
- next_frame(menu_sprites[loc-title_offset]);
+ NextFrame(menu_sprites[loc-title_offset]);
}
}
Modified: tuxmath/trunk/src/tuxmath.h
===================================================================
--- tuxmath/trunk/src/tuxmath.h 2009-06-29 16:03:58 UTC (rev 1109)
+++ tuxmath/trunk/src/tuxmath.h 2009-06-29 17:53:08 UTC (rev 1110)
@@ -43,8 +43,14 @@
//#define NOSOUND
#include "globals.h"
+/* Global data gets 'externed' here: */
-/* Global data gets 'externed' here: */
+/* declared in setup.c */
+/* windowed mode screen size */
+extern int win_res_x;
+extern int win_res_y;
+
+/* full screen size */
extern int fs_res_x;
extern int fs_res_y;
More information about the Tux4kids-commits
mailing list