[Tux4kids-commits] r1309 - branches/commonification/tux4kids-common/trunk/src
Bolesław Kulbabiński
bolekk-guest at alioth.debian.org
Fri Jul 31 19:24:21 UTC 2009
Author: bolekk-guest
Date: 2009-07-31 19:24:21 +0000 (Fri, 31 Jul 2009)
New Revision: 1309
Added:
branches/commonification/tux4kids-common/trunk/src/t4k-compiler.h
branches/commonification/tux4kids-common/trunk/src/t4k-pixels.c
Modified:
branches/commonification/tux4kids-common/trunk/src/t4k-audio.c
branches/commonification/tux4kids-common/trunk/src/t4k-globals.h
branches/commonification/tux4kids-common/trunk/src/t4k-loaders.c
branches/commonification/tux4kids-common/trunk/src/t4k-main.c
branches/commonification/tux4kids-common/trunk/src/t4k-menu.c
branches/commonification/tux4kids-common/trunk/src/t4k-sdl.c
branches/commonification/tux4kids-common/trunk/src/tux4kids-common.h
Log:
further imports into tux4kids-common
Modified: branches/commonification/tux4kids-common/trunk/src/t4k-audio.c
===================================================================
--- branches/commonification/tux4kids-common/trunk/src/t4k-audio.c 2009-07-31 17:36:34 UTC (rev 1308)
+++ branches/commonification/tux4kids-common/trunk/src/t4k-audio.c 2009-07-31 19:24:21 UTC (rev 1309)
@@ -24,42 +24,43 @@
#include "tux4kids-common.h"
#include "t4k-globals.h"
+Mix_Music *default_music;
+
+void audioMusicUnload();
+
void playsound(Mix_Chunk* sound)
{
Mix_PlayChannel(-1, sound, 0);
}
-Mix_Music *defaultMusic = NULL; // holds music for audioMusicLoad/unload
-
-/* audioMusicLoad attempts to load and play the music file
+/* audioMusicLoad attempts to load and play the music file
* Note: loops == -1 means forever
*/
void audioMusicLoad(Mix_Music* music, int loops)
{
audioMusicUnload(); // make sure defaultMusic is clear
- defaultMusic = music;
- Mix_PlayMusic(defaultMusic, loops);
+ default_music = music;
+ Mix_PlayMusic(default_music, loops);
}
-
/* audioMusicUnload attempts to unload any music data that was
* loaded using the audioMusicLoad function
*/
-void audioMusicUnload( void ) {
-
- if ( defaultMusic )
- Mix_FreeMusic( defaultMusic );
-
- defaultMusic=NULL;
+void audioMusicUnload()
+{
+ if(default_music)
+ Mix_FreeMusic(default_music);
+ default_music = NULL;
}
-/* audioMusicPlay attempts to play the passed music data.
+/* audioMusicPlay attempts to play the passed music data.
* if a music file was loaded using the audioMusicLoad
* it will be stopped and unloaded
* Note: loops == -1 means forever
*/
-void audioMusicPlay( Mix_Music *musicData, int loops ) {
+void audioMusicPlay(Mix_Music *musicData, int loops)
+{
+ audioMusicUnload();
+ Mix_PlayMusic(musicData, loops);
+}
- audioMusicUnload();
- Mix_PlayMusic( musicData, loops );
-}
Added: branches/commonification/tux4kids-common/trunk/src/t4k-compiler.h
===================================================================
--- branches/commonification/tux4kids-common/trunk/src/t4k-compiler.h (rev 0)
+++ branches/commonification/tux4kids-common/trunk/src/t4k-compiler.h 2009-07-31 19:24:21 UTC (rev 1309)
@@ -0,0 +1,157 @@
+/*
+ compiler.h
+
+ Compiler-specific #defines and such
+ for Tux Paint
+
+ Mostly by Albert Cahalan <albert at users.sf.net>
+ Copyright (c) 2002-2006
+
+ http://www.newbreedsoftware.com/tuxpaint/
+
+ 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.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ (See COPYING.txt)
+
+ June 14, 2002 - February 18, 2006
+ $Id: compiler.h,v 1.5 2006/08/27 21:00:55 wkendrick Exp $
+
+ June 09, 2008:
+ Brought into TuxMath by Brendan Luchen as part of pixel-manipulation
+ code, with blessings of Bill Kendrick.
+
+*/
+
+#ifdef WIN32
+/* Horrible, dangerous macros. */
+/*
+ The SDL stderr redirection trick doesn't seem to work for perror().
+ This does pretty much the same thing.
+*/
+#define perror(str) ({ \
+ if ( (str) && *(str) ) \
+ fprintf(stderr,"%s : ",(str)); \
+ fprintf(stderr, \
+ "%s [%d]\n", \
+ (errno<_sys_nerr)?_sys_errlist[errno]:"unknown",errno ); \
+})
+
+/*
+ MinGW implementation of isspace() crashes on some Win98 boxes
+ if c is 'out-of-range'.
+*/
+#define isspace(c) (((c) == 0x20) || ((c) >= 0x09 && (c) <= 0x0D))
+
+/*
+ WIN32 and MINGW don't have strcasestr().
+*/
+#define NOMINMAX
+#include "shlwapi.h"
+#define strcasestr StrStrI
+#endif /* WIN32 */
+
+
+
+
+#ifdef __GNUC__
+// This version has strict type checking for safety.
+// See the "unnecessary" pointer comparison. (from Linux)
+#define min(x,y) ({ \
+ typeof(x) _x = (x); \
+ typeof(y) _y = (y); \
+ (void) (&_x == &_y); \
+ _x < _y ? _x : _y; })
+#define max(x,y) ({ \
+ typeof(x) _x = (x); \
+ typeof(y) _y = (y); \
+ (void) (&_x == &_y); \
+ _x > _y ? _x : _y; })
+#else
+#define min(a,b) (((a) < (b)) ? (a) : (b))
+#define max(a,b) (((a) > (b)) ? (a) : (b))
+#endif
+
+#define clamp(lo,value,hi) (min(max(value,lo),hi))
+
+
+// since gcc-2.5
+#ifdef __GNUC__
+#define NORETURN __attribute__((__noreturn__))
+#define FUNCTION __attribute__((__const__)) // no access to global mem, even via ptr, and no side effect
+#else
+#define NORETURN
+#define FUNCTION
+#endif
+
+#if !defined(restrict) && __STDC_VERSION__ < 199901
+#if __GNUC__ > 2 || __GNUC_MINOR__ >= 92
+#define restrict __restrict__
+#else
+#warning No restrict keyword?
+#define restrict
+#endif
+#endif
+
+
+#if __GNUC__ > 2 || __GNUC_MINOR__ >= 96
+// won't alias anything, and aligned enough for anything
+#define MALLOC __attribute__ ((__malloc__))
+// no side effect, may read globals
+#ifndef WIN32
+#define PURE __attribute__ ((__pure__))
+#endif
+// tell gcc what to expect: if(unlikely(err)) die(err);
+#define likely(x) __builtin_expect(!!(x),1)
+#define unlikely(x) __builtin_expect(!!(x),0)
+#define expected(x,y) __builtin_expect((x),(y))
+#else
+#define MALLOC
+#define PURE
+#define likely(x) (x)
+#define unlikely(x) (x)
+#define expected(x,y) (x)
+#endif
+
+
+#ifdef __powerpc__
+// Ticks at 1/4 the memory bus clock (24.907667 MHz on Albert's Mac Cube)
+// This is good for 80-second diff or 160-second total.
+#define CLOCK_ASM(tbl) asm volatile("mftb %0" : "=r" (tbl))
+#define CLOCK_TYPE unsigned long
+#ifndef CLOCK_SPEED
+// #warning Benchmark times are based on a 99.63 MHz memory bus.
+#define CLOCK_SPEED 24907667.0
+#endif
+#endif
+
+#ifdef __i386__
+#define CLOCK_ASM(tbl) asm volatile("rdtsc" : "=A" (tbl))
+#define CLOCK_TYPE unsigned long long
+#ifndef CLOCK_SPEED
+// #warning Benchmark times are based on a 450 MHz CPU.
+#define CLOCK_SPEED 450000000.0
+#endif
+#endif
+
+#ifndef CLOCK_ASM
+// #warning No idea how to read CPU cycles for you, sorry.
+#define CLOCK_ASM(tbl)
+#define CLOCK_TYPE unsigned long
+#define CLOCK_SPEED 1000000000.0
+#endif
+
+#ifdef NO_ASM
+#undef CLOCK_ASM
+#define CLOCK_ASM(x) x=42
+#endif
Modified: branches/commonification/tux4kids-common/trunk/src/t4k-globals.h
===================================================================
--- branches/commonification/tux4kids-common/trunk/src/t4k-globals.h 2009-07-31 17:36:34 UTC (rev 1308)
+++ branches/commonification/tux4kids-common/trunk/src/t4k-globals.h 2009-07-31 19:24:21 UTC (rev 1309)
@@ -10,15 +10,18 @@
#ifndef GLOBALS_H
#define GLOBALS_H
+#include "SDL.h"
+
typedef enum { false, true } bool;
-#define min(a,b) (((a) < (b)) ? (a) : (b))
-#define max(a,b) (((a) > (b)) ? (a) : (b))
-
#define REG_RGBA 16,16,96,96
#define SEL_RGBA 16,16,128,128
#define MAX_FPS 30
+#define PIXEL_BITS 32
+#define DEFAULT_FONT_NAME "AndikaDesRevG.ttf"
+#define PATH_MAX 1024
+#define FONT_NAME_LENGTH 64
extern int dbg_status;
@@ -30,8 +33,24 @@
extern char* data_prefix;
+extern SDL_Color red, yellow, white, black;
/* debug macros */
#define DEBUGCODE(mask) if((mask) & dbg_status)
#define DEBUGMSG(mask, ...) if((mask) & dbg_status){ fprintf(stderr, __VA_ARGS__); fflush(stderr); }
+void putpixel8(SDL_Surface * surface, int x, int y, Uint32 pixel);
+void putpixel16(SDL_Surface * surface, int x, int y, Uint32 pixel);
+void putpixel24(SDL_Surface * surface, int x, int y, Uint32 pixel);
+void putpixel32(SDL_Surface * surface, int x, int y, Uint32 pixel);
+
+extern void (*putpixels[]) (SDL_Surface *, int, int, Uint32);
+
+Uint32 getpixel8(SDL_Surface * surface, int x, int y);
+Uint32 getpixel16(SDL_Surface * surface, int x, int y);
+Uint32 getpixel24(SDL_Surface * surface, int x, int y);
+Uint32 getpixel32(SDL_Surface * surface, int x, int y);
+
+extern Uint32(*getpixels[]) (SDL_Surface *, int, int);
+
+
#endif
Modified: branches/commonification/tux4kids-common/trunk/src/t4k-loaders.c
===================================================================
--- branches/commonification/tux4kids-common/trunk/src/t4k-loaders.c 2009-07-31 17:36:34 UTC (rev 1308)
+++ branches/commonification/tux4kids-common/trunk/src/t4k-loaders.c 2009-07-31 19:24:21 UTC (rev 1309)
@@ -29,8 +29,6 @@
#include<librsvg/rsvg-cairo.h>
#endif
-#define PATH_MAX 1024
-
/* local functions */
int check_file(const char* file);
Modified: branches/commonification/tux4kids-common/trunk/src/t4k-main.c
===================================================================
--- branches/commonification/tux4kids-common/trunk/src/t4k-main.c 2009-07-31 17:36:34 UTC (rev 1308)
+++ branches/commonification/tux4kids-common/trunk/src/t4k-main.c 2009-07-31 19:24:21 UTC (rev 1309)
@@ -16,8 +16,6 @@
int dbg_status;
-char* data_prefix;
-
/* these values have to match those used in games */
const int dbg_loaders = 1 << 2;
const int dbg_menu = 1 << 4;
@@ -25,12 +23,20 @@
const int dbg_sdl = 1 << 10;
const int dbg_all = ~0;
-void SetDebugMode(int dbg_flags)
+char* data_prefix;
+
+SDL_Color red, yellow, white, black;
+
+
+/* set global variables */
+void InitT4KCommon(int debug_flags, char* data_pref)
{
- dbg_status = dbg_flags;
+ dbg_status = debug_flags;
+ data_prefix = data_pref;
+
+ black.r = 0x00; black.g = 0x00; black.b = 0x00;
+ red.r = 0xff; red.g = 0x00; red.b = 0x00;
+ white.r = 0xff; white.g = 0xff; white.b = 0xff;
+ yellow.r = 0xff; yellow.g = 0xff; yellow.b = 0x00;
}
-void SetDataPrefix(char* pref)
-{
- data_prefix = pref;
-}
Modified: branches/commonification/tux4kids-common/trunk/src/t4k-menu.c
===================================================================
--- branches/commonification/tux4kids-common/trunk/src/t4k-menu.c 2009-07-31 17:36:34 UTC (rev 1308)
+++ branches/commonification/tux4kids-common/trunk/src/t4k-menu.c 2009-07-31 19:24:21 UTC (rev 1309)
@@ -54,7 +54,6 @@
int n_of_activities;
char** activities;
-SDL_Color red, yellow, white, black;
Mix_Chunk* snd_click;
Mix_Chunk* snd_hover;
@@ -63,12 +62,18 @@
#define N_OF_MENUS 10
MenuNode* menus[N_OF_MENUS];
+/* font size used in current resolution */
+int curr_font_size;
+
+/* buffer size used when reading attributes or names */
+const int buf_size = 128;
+
/* actions available while viewing the menu */
enum { NONE, CLICK, PAGEUP, PAGEDOWN, STOP_ESC, RESIZED };
/* stop button, left and right arrow positions do not
depend on currently displayed menu */
-SDL_Rect menu_rect, stop_rect, prev_rect, next_rect;
+SDL_Rect menu_rect, stop_rect, prev_rect, next_rect, menu_title_rect;
SDL_Surface *stop_button, *prev_arrow, *next_arrow, *prev_gray, *next_gray;
/*TODO: move these constants into a config file (maybe together with
@@ -85,17 +90,8 @@
const float button_gap = 0.2, text_h_gap = 0.4, text_w_gap = 0.5, button_radius = 0.27;
const int min_font_size = 8, default_font_size = 20, max_font_size = 40;
-/* font size used in current resolution */
-int curr_font_size;
-/* menu title rect */
-SDL_Rect menu_title_rect;
-/* buffer size used when reading attributes or names */
-const int buf_size = 128;
-
-
-
/* local functions */
MenuNode* create_empty_node();
char* get_attribute_name(const char* token);
@@ -113,7 +109,20 @@
void prerender_all();
+/* initialization of menu module */
+void SetActivitiesList(int num, char** acts)
+{
+ n_of_activities = num;
+ activities = acts;
+}
+void SetMenuSounds(Mix_Music* music, Mix_Chunk* click, Mix_Chunk* hover)
+{
+ snd_click = click;
+ snd_hover = hover;
+ menu_music = music;
+}
+
/*
functions responsible for parsing menu files
and creating menu trees
@@ -291,27 +300,8 @@
return menu;
}
-void SetActivitiesList(int num, char** acts)
-{
- n_of_activities = num;
- activities = acts;
-}
-void SetMenuSounds(Mix_Music* music, Mix_Chunk* click, Mix_Chunk* hover)
-{
- snd_click = click;
- snd_hover = hover;
- menu_music = music;
-}
-void InitMenu()
-{
- black.r = 0x00; black.g = 0x00; black.b = 0x00;
- red.r = 0xff; red.g = 0x00; red.b = 0x00;
- white.r = 0xff; white.g = 0xff; white.b = 0xff;
- yellow.r = 0xff; yellow.g = 0xff; yellow.b = 0x00;
-}
-
/* Display the menu and run the event loop.
if return_choice = true then return chosen value instead of
running handle_activity()
Added: branches/commonification/tux4kids-common/trunk/src/t4k-pixels.c
===================================================================
--- branches/commonification/tux4kids-common/trunk/src/t4k-pixels.c (rev 0)
+++ branches/commonification/tux4kids-common/trunk/src/t4k-pixels.c 2009-07-31 19:24:21 UTC (rev 1309)
@@ -0,0 +1,257 @@
+/*
+ pixels.c
+
+ For Tux Paint
+ Pixel read/write functions
+
+ Copyright (c) 2002-2006 by Bill Kendrick and others
+ bill at newbreedsoftware.com
+ http://www.newbreedsoftware.com/tuxpaint/
+
+ 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.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ (See COPYING.txt)
+
+ June 14, 2002 - February 17, 2006
+ $Id: pixels.c,v 1.3 2006/08/27 21:00:55 wkendrick Exp $
+*/
+
+#include "tux4kids-common.h"
+#include "t4k-globals.h"
+#include "t4k-compiler.h"
+
+/* Draw a single pixel into the surface: */
+void putpixel8(SDL_Surface * surface, int x, int y, Uint32 pixel)
+{
+ Uint8 *p;
+
+ /* Assuming the X/Y values are within the bounds of this surface... */
+ if (likely
+ (likely((unsigned) x < (unsigned) surface->w)
+ && likely((unsigned) y < (unsigned) surface->h)))
+ {
+ // Set a pointer to the exact location in memory of the pixel
+ p = (Uint8 *) (((Uint8 *) surface->pixels) + /* Start: beginning of RAM */
+ (y * surface->pitch) + /* Go down Y lines */
+ x); /* Go in X pixels */
+
+
+ /* Set the (correctly-sized) piece of data in the surface's RAM
+ * to the pixel value sent in: */
+
+ *p = pixel;
+ }
+}
+
+/* Draw a single pixel into the surface: */
+void putpixel16(SDL_Surface * surface, int x, int y, Uint32 pixel)
+{
+ Uint8 *p;
+
+ /* Assuming the X/Y values are within the bounds of this surface... */
+ if (likely
+ (likely((unsigned) x < (unsigned) surface->w)
+ && likely((unsigned) y < (unsigned) surface->h)))
+ {
+ // Set a pointer to the exact location in memory of the pixel
+ p = (Uint8 *) (((Uint8 *) surface->pixels) + /* Start: beginning of RAM */
+ (y * surface->pitch) + /* Go down Y lines */
+ (x * 2)); /* Go in X pixels */
+
+
+ /* Set the (correctly-sized) piece of data in the surface's RAM
+ * to the pixel value sent in: */
+
+ *(Uint16 *) p = pixel;
+ }
+}
+
+/* Draw a single pixel into the surface: */
+void putpixel24(SDL_Surface * surface, int x, int y, Uint32 pixel)
+{
+ Uint8 *p;
+
+ /* Assuming the X/Y values are within the bounds of this surface... */
+ if (likely
+ (likely((unsigned) x < (unsigned) surface->w)
+ && likely((unsigned) y < (unsigned) surface->h)))
+ {
+ // Set a pointer to the exact location in memory of the pixel
+ p = (Uint8 *) (((Uint8 *) surface->pixels) + /* Start: beginning of RAM */
+ (y * surface->pitch) + /* Go down Y lines */
+ (x * 3)); /* Go in X pixels */
+
+
+ /* Set the (correctly-sized) piece of data in the surface's RAM
+ * to the pixel value sent in: */
+
+ if (SDL_BYTEORDER == SDL_BIG_ENDIAN)
+ {
+ p[0] = (pixel >> 16) & 0xff;
+ p[1] = (pixel >> 8) & 0xff;
+ p[2] = pixel & 0xff;
+ }
+ else
+ {
+ p[0] = pixel & 0xff;
+ p[1] = (pixel >> 8) & 0xff;
+ p[2] = (pixel >> 16) & 0xff;
+ }
+
+ }
+}
+
+/* Draw a single pixel into the surface: */
+void putpixel32(SDL_Surface * surface, int x, int y, Uint32 pixel)
+{
+ Uint8 *p;
+
+ /* Assuming the X/Y values are within the bounds of this surface... */
+ if (likely
+ (likely((unsigned) x < (unsigned) surface->w)
+ && likely((unsigned) y < (unsigned) surface->h)))
+ {
+ // Set a pointer to the exact location in memory of the pixel
+ p = (Uint8 *) (((Uint8 *) surface->pixels) + /* Start: beginning of RAM */
+ (y * surface->pitch) + /* Go down Y lines */
+ (x * 4)); /* Go in X pixels */
+
+
+ /* Set the (correctly-sized) piece of data in the surface's RAM
+ * to the pixel value sent in: */
+
+ *(Uint32 *) p = pixel; // 32-bit display
+ }
+}
+
+/* Get a pixel: */
+Uint32 getpixel8(SDL_Surface * surface, int x, int y)
+{
+ Uint8 *p;
+
+ /* get the X/Y values within the bounds of this surface */
+ if (unlikely((unsigned) x > (unsigned) surface->w - 1u))
+ x = (x < 0) ? 0 : surface->w - 1;
+ if (unlikely((unsigned) y > (unsigned) surface->h - 1u))
+ y = (y < 0) ? 0 : surface->h - 1;
+
+ /* Set a pointer to the exact location in memory of the pixel
+ in question: */
+
+ p = (Uint8 *) (((Uint8 *) surface->pixels) + /* Start at top of RAM */
+ (y * surface->pitch) + /* Go down Y lines */
+ x); /* Go in X pixels */
+
+
+ /* Return the correctly-sized piece of data containing the
+ * pixel's value (an 8-bit palette value, or a 16-, 24- or 32-bit
+ * RGB value) */
+
+ return (*p);
+}
+
+/* Get a pixel: */
+Uint32 getpixel16(SDL_Surface * surface, int x, int y)
+{
+ Uint8 *p;
+
+ /* get the X/Y values within the bounds of this surface */
+ if (unlikely((unsigned) x > (unsigned) surface->w - 1u))
+ x = (x < 0) ? 0 : surface->w - 1;
+ if (unlikely((unsigned) y > (unsigned) surface->h - 1u))
+ y = (y < 0) ? 0 : surface->h - 1;
+
+ /* Set a pointer to the exact location in memory of the pixel
+ in question: */
+
+ p = (Uint8 *) (((Uint8 *) surface->pixels) + /* Start at top of RAM */
+ (y * surface->pitch) + /* Go down Y lines */
+ (x * 2)); /* Go in X pixels */
+
+
+ /* Return the correctly-sized piece of data containing the
+ * pixel's value (an 8-bit palette value, or a 16-, 24- or 32-bit
+ * RGB value) */
+
+ return (*(Uint16 *) p);
+}
+
+/* Get a pixel: */
+Uint32 getpixel24(SDL_Surface * surface, int x, int y)
+{
+ Uint8 *p;
+ Uint32 pixel;
+
+ /* get the X/Y values within the bounds of this surface */
+ if (unlikely((unsigned) x > (unsigned) surface->w - 1u))
+ x = (x < 0) ? 0 : surface->w - 1;
+ if (unlikely((unsigned) y > (unsigned) surface->h - 1u))
+ y = (y < 0) ? 0 : surface->h - 1;
+
+ /* Set a pointer to the exact location in memory of the pixel
+ in question: */
+
+ p = (Uint8 *) (((Uint8 *) surface->pixels) + /* Start at top of RAM */
+ (y * surface->pitch) + /* Go down Y lines */
+ (x * 3)); /* Go in X pixels */
+
+
+ /* Return the correctly-sized piece of data containing the
+ * pixel's value (an 8-bit palette value, or a 16-, 24- or 32-bit
+ * RGB value) */
+
+ /* Depending on the byte-order, it could be stored RGB or BGR! */
+
+ if (SDL_BYTEORDER == SDL_BIG_ENDIAN)
+ pixel = p[0] << 16 | p[1] << 8 | p[2];
+ else
+ pixel = p[0] | p[1] << 8 | p[2] << 16;
+
+ return pixel;
+}
+
+/* Get a pixel: */
+Uint32 getpixel32(SDL_Surface * surface, int x, int y)
+{
+ Uint8 *p;
+
+ /* get the X/Y values within the bounds of this surface */
+ if (unlikely((unsigned) x > (unsigned) surface->w - 1u))
+ x = (x < 0) ? 0 : surface->w - 1;
+ if (unlikely((unsigned) y > (unsigned) surface->h - 1u))
+ y = (y < 0) ? 0 : surface->h - 1;
+
+ /* Set a pointer to the exact location in memory of the pixel
+ in question: */
+
+ p = (Uint8 *) (((Uint8 *) surface->pixels) + /* Start at top of RAM */
+ (y * surface->pitch) + /* Go down Y lines */
+ (x * 4)); /* Go in X pixels */
+
+
+ /* Return the correctly-sized piece of data containing the
+ * pixel's value (an 8-bit palette value, or a 16-, 24- or 32-bit
+ * RGB value) */
+
+ return *(Uint32 *) p; // 32-bit display
+}
+
+void (*putpixels[]) (SDL_Surface *, int, int, Uint32) =
+{
+putpixel8, putpixel8, putpixel16, putpixel24, putpixel32};
+
+
+Uint32(*getpixels[])(SDL_Surface *, int, int) =
+{
+getpixel8, getpixel8, getpixel16, getpixel24, getpixel32};
Modified: branches/commonification/tux4kids-common/trunk/src/t4k-sdl.c
===================================================================
--- branches/commonification/tux4kids-common/trunk/src/t4k-sdl.c 2009-07-31 17:36:34 UTC (rev 1308)
+++ branches/commonification/tux4kids-common/trunk/src/t4k-sdl.c 2009-07-31 19:24:21 UTC (rev 1309)
@@ -175,11 +175,6 @@
SDL_UnlockSurface(s);
}
-/**
- * TODO ***Migrate other functions! Oh, and test on Win/Mac
- */
-
-#if 0
/**********************
Flip:
input: a SDL_Surface, x, y
@@ -431,6 +426,7 @@
#elif PIXEL_BITS == 16
Uint16* p;
#else
+ Uint16* p;
return;
#endif
Uint32 rm = screen->format->Rmask;
@@ -458,6 +454,7 @@
}
}
+#if 0
/* change window size (works only in windowed mode) */
void ChangeWindowSize(int new_res_x, int new_res_y)
{
@@ -479,7 +476,7 @@
}
else
{
- DEBUGMSG(debug_sdl, "ChangeWindowSize(): Changed window size to %d x %d\n", screen->w, screen->h);
+ DEBUGMSG(dbg_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;
@@ -487,7 +484,7 @@
}
}
else
- DEBUGMSG(debug_sdl, "ChangeWindowSize() can be run only in windowed mode !");
+ DEBUGMSG(dbg_sdl, "ChangeWindowSize() can be run only in windowed mode !");
}
/* switch between fullscreen and windowed mode */
@@ -514,12 +511,12 @@
else
{
//success, no need to free the old video surface
- DEBUGMSG(debug_sdl, "Switched screen mode to %s\n", window ? "windowed" : "fullscreen");
+ DEBUGMSG(dbg_sdl, "Switched screen mode to %s\n", window ? "windowed" : "fullscreen");
oldscreen = NULL;
SDL_UpdateRect(screen, 0, 0, 0, 0);
}
}
-
+#endif
/*
Block application until SDL receives an appropriate event. Events can be
a single or OR'd combination of event masks.
@@ -566,7 +563,7 @@
Uint8 r4, g4, b4, a4;
Uint8 r, g, b, a;
- DEBUGMSG(debug_sdl, "Entering zoom():\n");
+ DEBUGMSG(dbg_sdl, "Entering zoom():\n");
/* Create surface for zoom: */
@@ -587,9 +584,9 @@
// exit(1);
}
- DEBUGMSG(debug_sdl, "zoom(): orig surface %dx%d, %d bytes per pixel\n",
+ DEBUGMSG(dbg_sdl, "zoom(): orig surface %dx%d, %d bytes per pixel\n",
src->w, src->h, src->format->BytesPerPixel);
- DEBUGMSG(debug_sdl, "zoom(): new surface %dx%d, %d bytes per pixel\n",
+ DEBUGMSG(dbg_sdl, "zoom(): new surface %dx%d, %d bytes per pixel\n",
s->w, s->h, s->format->BytesPerPixel);
/* Now assign function pointers to correct functions based */
@@ -664,7 +661,7 @@
SDL_UnlockSurface(s);
SDL_UnlockSurface(src);
- DEBUGMSG(debug_sdl, "Leaving zoom():\n");
+ DEBUGMSG(dbg_sdl, "Leaving zoom():\n");
return s;
}
@@ -697,8 +694,8 @@
/* We cache fonts here once loaded to improve performance: */
TTF_Font* font_list[MAX_FONT_SIZE + 1] = {NULL};
static void free_font_list(void);
-static TTF_Font* get_font(int size);
-static TTF_Font* load_font(const char* font_name, int font_size);
+//static TTF_Font* get_font(int size);
+//static TTF_Font* load_font(const char* font_name, int font_size);
#endif
@@ -712,7 +709,7 @@
{
#ifdef HAVE_LIBSDL_PANGO
- DEBUGMSG(debug_sdl, "Setup_SDL_Text() - using SDL_Pango\n");
+ DEBUGMSG(dbg_sdl, "Setup_SDL_Text() - using SDL_Pango\n");
SDLPango_Init();
if (!Set_SDL_Pango_Font_Size(DEFAULT_MENU_FONT_SIZE))
@@ -724,7 +721,7 @@
#else
/* using SDL_ttf: */
- DEBUGMSG(debug_sdl, "Setup_SDL_Text() - using SDL_ttf\n");
+ DEBUGMSG(dbg_sdl, "Setup_SDL_Text() - using SDL_ttf\n");
if (TTF_Init() < 0)
{
@@ -793,8 +790,8 @@
return NULL;
}
- DEBUGMSG(debug_sdl, "Entering BlackOutline():\n");
- DEBUGMSG(debug_sdl, "BlackOutline of \"%s\"\n", t );
+ DEBUGMSG(dbg_sdl, "Entering BlackOutline():\n");
+ DEBUGMSG(dbg_sdl, "BlackOutline of \"%s\"\n", t );
#ifdef HAVE_LIBSDL_PANGO
Set_SDL_Pango_Font_Size(size);
@@ -867,7 +864,7 @@
out = SDL_DisplayFormatAlpha(bg);
SDL_FreeSurface(bg);
- DEBUGMSG(debug_sdl, "\nLeaving BlackOutline(): \n");
+ DEBUGMSG(dbg_sdl, "\nLeaving BlackOutline(): \n");
return out;
}
@@ -1001,7 +998,7 @@
{
char buf[64];
- DEBUGMSG(debug_sdl, "Setting font size to %d\n", size);
+ DEBUGMSG(dbg_sdl, "Setting font size to %d\n", size);
if(context != NULL)
SDLPango_FreeContext(context);
@@ -1064,6 +1061,7 @@
}
}
+#if 0
/* FIXME - could combine this with load_font() below: */
/* Loads and caches fonts in each size as they are requested: */
/* We use the font size as an array index, keeping each size */
@@ -1096,7 +1094,6 @@
return font_list[size];
}
-
/* FIXME: I think we need to provide a single default font with the program data, */
/* then more flexible code to try to locate or load system fonts. DSB */
/* Returns ptr to loaded font if successful, NULL otherwise. */
@@ -1104,7 +1101,7 @@
{
TTF_Font* f;
char fontfile[PATH_MAX];
- sprintf(fontfile, "%s/fonts/%s", DATA_PREFIX, font_name);
+ sprintf(fontfile, "%s/fonts/%s", data_prefix, font_name);
f = TTF_OpenFont(fontfile, font_size);
@@ -1120,7 +1117,7 @@
if (f)
{
- DEBUGMSG(debug_sdl, "LoadFont(): %s loaded successfully\n\n", fontfile);
+ DEBUGMSG(dbg_sdl, "LoadFont(): %s loaded successfully\n\n", fontfile);
return f;
}
else
@@ -1130,5 +1127,4 @@
}
}
#endif
-
#endif
Modified: branches/commonification/tux4kids-common/trunk/src/tux4kids-common.h
===================================================================
--- branches/commonification/tux4kids-common/trunk/src/tux4kids-common.h 2009-07-31 17:36:34 UTC (rev 1308)
+++ branches/commonification/tux4kids-common/trunk/src/tux4kids-common.h 2009-07-31 19:24:21 UTC (rev 1309)
@@ -56,6 +56,29 @@
SDL_Surface* CreateButton(int w, int h, int radius, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
void RoundCorners(SDL_Surface* s, Uint16 radius);
+SDL_Surface* Flip(SDL_Surface *in, int x, int y);
+SDL_Surface* Blend(SDL_Surface *S1, SDL_Surface *S2, float gamma);
+
+void FreeSurfaceArray(SDL_Surface** surfs, int length);
+int inRect(SDL_Rect r, int x, int y);
+void SetRect(SDL_Rect* rect, const float* pos);
+void UpdateRect(SDL_Surface* surf, SDL_Rect* rect);
+
+void DarkenScreen(Uint8 bits);
+//void ChangeWindowSize(int new_res_x, int new_res_y);
+//void SwitchScreenMode(void);
+
+SDL_EventType WaitForEvent(SDL_EventMask events);
+SDL_Surface* zoom(SDL_Surface* src, int new_w, int new_h);
+
+/*Text rendering functions: */
+int Setup_SDL_Text(void);
+void Cleanup_SDL_Text(void);
+SDL_Surface* BlackOutline(const char* t, int size, SDL_Color* c);
+SDL_Surface* SimpleText(const char *t, int size, SDL_Color* col);
+SDL_Surface* SimpleTextWithOffset(const char *t, int size, SDL_Color* col, int *glyph_offset);
+
+
/* functions from tk4-loaders.c */
#define IMG_REGULAR 0x01
#define IMG_COLORKEY 0x02
More information about the Tux4kids-commits
mailing list