[Tux4kids-commits] r274 - tuxmath/trunk/src
dbruce-guest at alioth.debian.org
dbruce-guest at alioth.debian.org
Tue Sep 25 20:22:46 UTC 2007
Author: dbruce-guest
Date: 2007-09-25 20:22:46 +0000 (Tue, 25 Sep 2007)
New Revision: 274
Added:
tuxmath/trunk/src/SDL_extras.c
tuxmath/trunk/src/SDL_extras.h
Modified:
tuxmath/trunk/src/Makefile.am
tuxmath/trunk/src/Makefile.in
tuxmath/trunk/src/alphabet.c
tuxmath/trunk/src/highscore.c
tuxmath/trunk/src/loaders.c
tuxmath/trunk/src/pause.c
tuxmath/trunk/src/setup.c
tuxmath/trunk/src/titlescreen.c
tuxmath/trunk/src/titlescreen.h
tuxmath/trunk/src/tuxmath.h
Log:
Rearranged some helpful functions into "SDL_extras.c"
Modified: tuxmath/trunk/src/Makefile.am
===================================================================
--- tuxmath/trunk/src/Makefile.am 2007-09-25 15:22:45 UTC (rev 273)
+++ tuxmath/trunk/src/Makefile.am 2007-09-25 20:22:46 UTC (rev 274)
@@ -13,12 +13,12 @@
TuxMath_SOURCES = tuxmath.c setup.c titlescreen.c game.c \
options.c credits.c playsound.c highscore.c \
theme.c loaders.c alphabet.c pause.c audio.c \
- mathcards.c fileops.c tuxmathrc.rc
+ mathcards.c fileops.c ConvertUTF.c tuxmathrc.rc
tuxmath_SOURCES = tuxmath.c setup.c titlescreen.c game.c \
options.c credits.c playsound.c highscore.c \
theme.c loaders.c alphabet.c pause.c audio.c \
- mathcards.c fileops.c ConvertUTF.c
+ mathcards.c fileops.c ConvertUTF.c SDL_extras.c
EXTRA_DIST = credits.h \
fileops.h \
@@ -30,7 +30,8 @@
setup.h \
titlescreen.h \
tuxmath.h \
- ConvertUTF.h
+ ConvertUTF.h \
+ SDL_extras.h
# SUBDIRS = po
Modified: tuxmath/trunk/src/Makefile.in
===================================================================
--- tuxmath/trunk/src/Makefile.in 2007-09-25 15:22:45 UTC (rev 273)
+++ tuxmath/trunk/src/Makefile.in 2007-09-25 20:22:46 UTC (rev 274)
@@ -55,7 +55,7 @@
credits.$(OBJEXT) playsound.$(OBJEXT) highscore.$(OBJEXT) \
theme.$(OBJEXT) loaders.$(OBJEXT) alphabet.$(OBJEXT) \
pause.$(OBJEXT) audio.$(OBJEXT) mathcards.$(OBJEXT) \
- fileops.$(OBJEXT)
+ fileops.$(OBJEXT) ConvertUTF.$(OBJEXT)
TuxMath_OBJECTS = $(am_TuxMath_OBJECTS)
TuxMath_LDADD = $(LDADD)
am_tuxmath_OBJECTS = tuxmath.$(OBJEXT) setup.$(OBJEXT) \
@@ -63,7 +63,7 @@
credits.$(OBJEXT) playsound.$(OBJEXT) highscore.$(OBJEXT) \
theme.$(OBJEXT) loaders.$(OBJEXT) alphabet.$(OBJEXT) \
pause.$(OBJEXT) audio.$(OBJEXT) mathcards.$(OBJEXT) \
- fileops.$(OBJEXT) ConvertUTF.$(OBJEXT)
+ fileops.$(OBJEXT) ConvertUTF.$(OBJEXT) SDL_extras.$(OBJEXT)
tuxmath_OBJECTS = $(am_tuxmath_OBJECTS)
tuxmath_LDADD = $(LDADD)
DEFAULT_INCLUDES = -I. -I$(top_builddir)@am__isrc@
@@ -203,12 +203,12 @@
TuxMath_SOURCES = tuxmath.c setup.c titlescreen.c game.c \
options.c credits.c playsound.c highscore.c \
theme.c loaders.c alphabet.c pause.c audio.c \
- mathcards.c fileops.c tuxmathrc.rc
+ mathcards.c fileops.c ConvertUTF.c tuxmathrc.rc
tuxmath_SOURCES = tuxmath.c setup.c titlescreen.c game.c \
options.c credits.c playsound.c highscore.c \
theme.c loaders.c alphabet.c pause.c audio.c \
- mathcards.c fileops.c ConvertUTF.c
+ mathcards.c fileops.c ConvertUTF.c SDL_extras.c
EXTRA_DIST = credits.h \
fileops.h \
@@ -220,7 +220,8 @@
setup.h \
titlescreen.h \
tuxmath.h \
- ConvertUTF.h
+ ConvertUTF.h \
+ SDL_extras.h
@BUILD_MINGW32_FALSE at DATA_PREFIX = ${pkgdatadir}
@BUILD_MINGW32_TRUE at DATA_PREFIX = @PACKAGE_DATA_DIR@
@@ -298,6 +299,7 @@
-rm -f *.tab.c
@AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/ConvertUTF.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/SDL_extras.Po at am__quote@
@AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/alphabet.Po at am__quote@
@AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/audio.Po at am__quote@
@AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/credits.Po at am__quote@
Added: tuxmath/trunk/src/SDL_extras.c
===================================================================
--- tuxmath/trunk/src/SDL_extras.c (rev 0)
+++ tuxmath/trunk/src/SDL_extras.c 2007-09-25 20:22:46 UTC (rev 274)
@@ -0,0 +1,314 @@
+/*
+* C Implementation: SDL_extras
+*
+* Description: a few handy functions for using SDL graphics.
+*
+*
+* Author: David Bruce,,, <dbruce at tampabay.rr.com>, (C) 2007
+*
+* Copyright: GPL v3 or later
+*
+*/
+/* DrawButton() creates and draws a translucent button with */
+/* rounded ends. The location and size are taken from the */
+/* SDL_Rect* and width arguments. The sprite is used to */
+/* fill in the rect with the desired translucent color and */
+/* give it nice, rounded ends. */
+/* FIXME make it match target_rect more precisely */
+
+#include "SDL_extras.h"
+#include "tuxmath.h"
+
+void DrawButton(SDL_Rect* target_rect,
+ int radius,
+ Uint8 r, Uint8 g, Uint8 b, Uint8 a)
+{
+ SDL_Surface* tmp_surf = SDL_CreateRGBSurface(SDL_SWSURFACE|SDL_SRCALPHA,
+ target_rect->w,
+ target_rect->h,
+ 32,
+ rmask, gmask, bmask, amask);
+ Uint32 color = SDL_MapRGBA(tmp_surf->format, r, g, b, a);
+ SDL_FillRect(tmp_surf, NULL, color);
+ RoundCorners(tmp_surf, radius);
+
+ SDL_BlitSurface(tmp_surf, NULL, screen, target_rect);
+ SDL_FreeSurface(tmp_surf);
+// SDL_UpdateRect(screen, 0, 0, 0, 0);
+
+ SDL_UpdateRect(screen, target_rect->x, target_rect->y, target_rect->w, target_rect->h);
+
+}
+
+
+
+void RoundCorners(SDL_Surface* s, Uint16 radius)
+{
+ int y = 0;
+ int x_dist, y_dist;
+ Uint32* p = NULL;
+ Uint32 alpha_mask;
+ int bytes_per_pix;
+
+ if (!s)
+ return;
+ if (SDL_LockSurface(s) == -1)
+ return;
+
+ bytes_per_pix = s->format->BytesPerPixel;
+ if (bytes_per_pix != 4)
+ return;
+
+ /* radius cannot be more than half of width or height: */
+ if (radius > (s->w)/2)
+ radius = (s->w)/2;
+ if (radius > (s->h)/2)
+ radius = (s->h)/2;
+
+
+ alpha_mask = s->format->Amask;
+
+ /* Now round off corners: */
+ /* upper left: */
+ for (y = 0; y < radius; y++)
+ {
+ p = (Uint32*)(s->pixels + (y * s->pitch));
+ x_dist = radius;
+ y_dist = radius - y;
+
+ while (((x_dist * x_dist) + (y_dist * y_dist)) > (radius * radius))
+ {
+ /* (make pixel (x,y) transparent) */
+ *p = *p & ~alpha_mask;
+ p++;
+ x_dist--;
+ }
+ }
+
+ /* upper right: */
+ for (y = 0; y < radius; y++)
+ {
+ /* start at end of top row: */
+ p = (Uint32*)(s->pixels + ((y + 1) * s->pitch) - bytes_per_pix);
+
+ x_dist = radius;
+ y_dist = radius - y;
+
+ while (((x_dist * x_dist) + (y_dist * y_dist)) > (radius * radius))
+ {
+ /* (make pixel (x,y) transparent) */
+ *p = *p & ~alpha_mask;
+ p--;
+ x_dist--;
+ }
+ }
+
+ /* bottom left: */
+ for (y = (s->h - 1); y > (s->h - radius); y--)
+ {
+ /* start at beginning of bottom row */
+ p = (Uint32*)(s->pixels + (y * s->pitch));
+ x_dist = radius;
+ y_dist = y - (s->h - radius);
+
+ while (((x_dist * x_dist) + (y_dist * y_dist)) > (radius * radius))
+ {
+ /* (make pixel (x,y) transparent) */
+ *p = *p & ~alpha_mask;
+ p++;
+ x_dist--;
+ }
+ }
+
+ /* bottom right: */
+ for (y = (s->h - 1); y > (s->h - radius); y--)
+ {
+ /* start at end of bottom row */
+ p = (Uint32*)(s->pixels + ((y + 1) * s->pitch) - bytes_per_pix);
+ x_dist = radius;
+ y_dist = y - (s->h - radius);
+
+ while (((x_dist * x_dist) + (y_dist * y_dist)) > (radius * radius))
+ {
+ /* (make pixel (x,y) transparent) */
+ *p = *p & ~alpha_mask;
+ p--;
+ x_dist--;
+ }
+ }
+ SDL_UnlockSurface(s);
+}
+
+
+/**********************
+ Flip:
+ input: a SDL_Surface, x, y
+ output: a copy of the SDL_Surface flipped via rules:
+
+ if x is a positive value, then flip horizontally
+ if y is a positive value, then flip vertically
+
+ note: you can have it flip both
+**********************/
+SDL_Surface* Flip( SDL_Surface *in, int x, int y ) {
+ SDL_Surface *out, *tmp;
+ SDL_Rect from_rect, to_rect;
+ Uint32 flags;
+ Uint32 colorkey=0;
+
+ /* --- grab the settings for the incoming pixmap --- */
+
+ SDL_LockSurface(in);
+ flags = in->flags;
+
+ /* --- change in's flags so ignore colorkey & alpha --- */
+
+ if (flags & SDL_SRCCOLORKEY) {
+ in->flags &= ~SDL_SRCCOLORKEY;
+ colorkey = in->format->colorkey;
+ }
+ if (flags & SDL_SRCALPHA) {
+ in->flags &= ~SDL_SRCALPHA;
+ }
+
+ SDL_UnlockSurface(in);
+
+ /* --- create our new surface --- */
+
+ out = SDL_CreateRGBSurface(
+ SDL_SWSURFACE,
+ in->w, in->h, 32, rmask, gmask, bmask, amask);
+
+ /* --- flip horizontally if requested --- */
+
+ if (x) {
+ from_rect.h = to_rect.h = in->h;
+ from_rect.w = to_rect.w = 1;
+ from_rect.y = to_rect.y = 0;
+ from_rect.x = 0;
+ to_rect.x = in->w - 1;
+
+ do {
+ SDL_BlitSurface(in, &from_rect, out, &to_rect);
+ from_rect.x++;
+ to_rect.x--;
+ } while (to_rect.x >= 0);
+ }
+
+ /* --- flip vertically if requested --- */
+
+ if (y) {
+ from_rect.h = to_rect.h = 1;
+ from_rect.w = to_rect.w = in->w;
+ from_rect.x = to_rect.x = 0;
+ from_rect.y = 0;
+ to_rect.y = in->h - 1;
+
+ do {
+ SDL_BlitSurface(in, &from_rect, out, &to_rect);
+ from_rect.y++;
+ to_rect.y--;
+ } while (to_rect.y >= 0);
+ }
+
+ /* --- restore colorkey & alpha on in and setup out the same --- */
+
+ SDL_LockSurface(in);
+
+ if (flags & SDL_SRCCOLORKEY) {
+ in->flags |= SDL_SRCCOLORKEY;
+ in->format->colorkey = colorkey;
+ tmp = SDL_DisplayFormat(out);
+ SDL_FreeSurface(out);
+ out = tmp;
+ out->flags |= SDL_SRCCOLORKEY;
+ out->format->colorkey = colorkey;
+ } else if (flags & SDL_SRCALPHA) {
+ in->flags |= SDL_SRCALPHA;
+ tmp = SDL_DisplayFormatAlpha(out);
+ SDL_FreeSurface(out);
+ out = tmp;
+ } else {
+ tmp = SDL_DisplayFormat(out);
+ SDL_FreeSurface(out);
+ out = tmp;
+ }
+
+ SDL_UnlockSurface(in);
+
+ return out;
+}
+
+
+/* BlackOutline() creates a surface containing text of the designated */
+/* foreground color, surrounded by a black shadow, on a transparent */
+/* background. The appearance can be tuned by adjusting the number of */
+/* background copies and the offset where the foreground text is */
+/* finally written (see below). */
+SDL_Surface* BlackOutline(unsigned char *t, TTF_Font *font, SDL_Color *c)
+{
+ SDL_Surface* out = NULL;
+ SDL_Surface* black_letters = NULL;
+ SDL_Surface* white_letters = NULL;
+ SDL_Surface* bg = NULL;
+ SDL_Rect dstrect;
+ Uint32 color_key;
+
+ if (!t || !font || !c)
+ {
+ fprintf(stderr, "BlackOutline(): invalid ptr parameter, returning.");
+ return NULL;
+ }
+
+#ifdef TUXMATH_DEBUG
+ fprintf( stderr, "\nEntering BlackOutline(): \n");
+ fprintf( stderr, "BlackOutline of \"%s\"\n", t );
+#endif
+
+ black_letters = TTF_RenderUTF8_Blended(font, t, black);
+
+ if (!black_letters)
+ {
+ fprintf (stderr, "Warning - BlackOutline() could not create image for %s\n", t);
+ return NULL;
+ }
+
+ bg = SDL_CreateRGBSurface(SDL_SWSURFACE,
+ (black_letters->w) + 5,
+ (black_letters->h) + 5,
+ 32,
+ rmask, gmask, bmask, amask);
+ /* Use color key for eventual transparency: */
+ color_key = SDL_MapRGB(bg->format, 01, 01, 01);
+ SDL_FillRect(bg, NULL, color_key);
+
+ /* Now draw black outline/shadow 2 pixels on each side: */
+ dstrect.w = black_letters->w;
+ dstrect.h = black_letters->h;
+
+ /* NOTE: can make the "shadow" more or less pronounced by */
+ /* changing the parameters of these loops. */
+ for (dstrect.x = 1; dstrect.x < 4; dstrect.x++)
+ for (dstrect.y = 1; dstrect.y < 3; dstrect.y++)
+ SDL_BlitSurface(black_letters , NULL, bg, &dstrect );
+
+ SDL_FreeSurface(black_letters);
+
+ /* --- Put the color version of the text on top! --- */
+ white_letters = TTF_RenderUTF8_Blended(font, t, *c);
+ dstrect.x = 1;
+ dstrect.y = 1;
+ SDL_BlitSurface(white_letters, NULL, bg, &dstrect);
+ SDL_FreeSurface(white_letters);
+
+ /* --- Convert to the screen format for quicker blits --- */
+ SDL_SetColorKey(bg, SDL_SRCCOLORKEY|SDL_RLEACCEL, color_key);
+ out = SDL_DisplayFormatAlpha(bg);
+ SDL_FreeSurface(bg);
+
+#ifdef TUXMATH_DEBUG
+ fprintf( stderr, "\nLeaving BlackOutline(): \n");
+#endif
+
+ return out;
+}
\ No newline at end of file
Added: tuxmath/trunk/src/SDL_extras.h
===================================================================
--- tuxmath/trunk/src/SDL_extras.h (rev 0)
+++ tuxmath/trunk/src/SDL_extras.h 2007-09-25 20:22:46 UTC (rev 274)
@@ -0,0 +1,36 @@
+//
+// C Interface: SDL_extras
+//
+// Description: A few handy functions for using SDL graphics.
+//
+//
+// Author: David Bruce,,, <dbruce at tampabay.rr.com>, (C) 2007
+//
+// Copyright: See COPYING file that comes with this distribution
+// (briefly, GPL v3 or later).
+//
+
+#ifndef SDL_EXTRAS_H
+#define SDL_EXTRAS_H
+
+#include "SDL.h"
+#include "SDL_ttf.h"
+
+#if SDL_BYTEORDER == SDL_BIG_ENDIAN
+#define rmask 0xff000000
+#define gmask 0x00ff0000
+#define bmask 0x0000ff00
+#define amask 0x000000ff
+#else
+#define rmask 0x000000ff
+#define gmask 0x0000ff00
+#define bmask 0x00ff0000
+#define amask 0xff000000
+#endif
+
+void DrawButton(SDL_Rect* target_rect, 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* BlackOutline(unsigned char *t, TTF_Font* font, SDL_Color* c);
+
+#endif
Modified: tuxmath/trunk/src/alphabet.c
===================================================================
--- tuxmath/trunk/src/alphabet.c 2007-09-25 15:22:45 UTC (rev 273)
+++ tuxmath/trunk/src/alphabet.c 2007-09-25 20:22:46 UTC (rev 274)
@@ -22,6 +22,7 @@
#include "tuxmath.h"
#include "titlescreen.h"
+#include "SDL_extras.h"
/* the colors we use throughout the game */
@@ -119,79 +120,8 @@
}
-/* black_outline() creates a surface containing text of the designated */
-/* foreground color, surrounded by a black shadow, on a transparent */
-/* background. The appearance can be tuned by adjusting the number of */
-/* background copies and the offset where the foreground text is */
-/* finally written (see below). */
-SDL_Surface* black_outline(unsigned char *t, TTF_Font *font, SDL_Color *c)
-{
- SDL_Surface* out = NULL;
- SDL_Surface* black_letters = NULL;
- SDL_Surface* white_letters = NULL;
- SDL_Surface* bg = NULL;
- SDL_Rect dstrect;
- Uint32 color_key;
- if (!t || !font || !c)
- {
- fprintf(stderr, "black_outline(): invalid ptr parameter, returning.");
- return NULL;
- }
-#ifdef TUXMATH_DEBUG
- fprintf( stderr, "\nEntering black_outline(): \n");
- fprintf( stderr, "black_outline of \"%s\"\n", t );
-#endif
-
- black_letters = TTF_RenderUTF8_Blended(font, t, black);
-
- if (!black_letters)
- {
- fprintf (stderr, "Warning - black_outline() could not create image for %s\n", t);
- return NULL;
- }
-
- bg = SDL_CreateRGBSurface(SDL_SWSURFACE,
- (black_letters->w) + 5,
- (black_letters->h) + 5,
- 32,
- rmask, gmask, bmask, amask);
- /* Use color key for eventual transparency: */
- color_key = SDL_MapRGB(bg->format, 01, 01, 01);
- SDL_FillRect(bg, NULL, color_key);
-
- /* Now draw black outline/shadow 2 pixels on each side: */
- dstrect.w = black_letters->w;
- dstrect.h = black_letters->h;
-
- /* NOTE: can make the "shadow" more or less pronounced by */
- /* changing the parameters of these loops. */
- for (dstrect.x = 1; dstrect.x < 4; dstrect.x++)
- for (dstrect.y = 1; dstrect.y < 3; dstrect.y++)
- SDL_BlitSurface(black_letters , NULL, bg, &dstrect );
-
- SDL_FreeSurface(black_letters);
-
- /* --- Put the color version of the text on top! --- */
- white_letters = TTF_RenderUTF8_Blended(font, t, *c);
- dstrect.x = 1;
- dstrect.y = 1;
- SDL_BlitSurface(white_letters, NULL, bg, &dstrect);
- SDL_FreeSurface(white_letters);
-
- /* --- Convert to the screen format for quicker blits --- */
- SDL_SetColorKey(bg, SDL_SRCCOLORKEY|SDL_RLEACCEL, color_key);
- out = SDL_DisplayFormatAlpha(bg);
- SDL_FreeSurface(bg);
-
-#ifdef TUXMATH_DEBUG
- fprintf( stderr, "\nLeaving black_outline(): \n");
-#endif
-
- return out;
-}
-
void show_letters( void ) {
int i, l=0;
SDL_Surface *abit;
@@ -205,7 +135,7 @@
t[l] = 0;
- abit = black_outline(t, default_font, &white);
+ abit = BlackOutline(t, default_font, &white);
dst.x = 320 - (abit->w / 2);
dst.y = 275;
@@ -216,7 +146,7 @@
SDL_FreeSurface(abit);
- abit = black_outline("Alphabet Set To:", default_font, &white);
+ abit = BlackOutline("Alphabet Set To:", default_font, &white);
dst.x = 320 - (abit->w / 2);
dst.y = 200;
dst.w = abit->w;
Modified: tuxmath/trunk/src/highscore.c
===================================================================
--- tuxmath/trunk/src/highscore.c 2007-09-25 15:22:45 UTC (rev 273)
+++ tuxmath/trunk/src/highscore.c 2007-09-25 20:22:46 UTC (rev 274)
@@ -17,7 +17,9 @@
#include "fileops.h"
#include "setup.h"
#include "options.h"
+#include "SDL_extras.h"
+
typedef struct high_score_entry {
int score;
char name[HIGH_SCORE_NAME_LENGTH];
@@ -203,7 +205,7 @@
TTF_Font* title_font = LoadFont(DEFAULT_FONT_NAME, 32);
if (title_font)
- srfc = black_outline(_("Hall Of Fame"), title_font, &yellow);
+ srfc = BlackOutline(_("Hall Of Fame"), title_font, &yellow);
if (srfc)
{
diffRect.x = (screen->w)/2 - (srfc->w)/2;
@@ -220,19 +222,19 @@
switch (diff_level)
{
case CADET_HIGH_SCORE:
- srfc = black_outline(_("Space Cadet"), title_font, &white);
+ srfc = BlackOutline(_("Space Cadet"), title_font, &white);
break;
case SCOUT_HIGH_SCORE:
- srfc = black_outline(_("Scout"), title_font, &white);
+ srfc = BlackOutline(_("Scout"), title_font, &white);
break;
case RANGER_HIGH_SCORE:
- srfc = black_outline(_("Ranger"), title_font, &white);
+ srfc = BlackOutline(_("Ranger"), title_font, &white);
break;
case ACE_HIGH_SCORE:
- srfc = black_outline(_("Ace"), title_font, &white);
+ srfc = BlackOutline(_("Ace"), title_font, &white);
break;
default:
- srfc = black_outline(_("Space Cadet"), title_font, &white);
+ srfc = BlackOutline(_("Space Cadet"), title_font, &white);
}
}
@@ -264,9 +266,9 @@
if (score_surfs[i]) /* this should not happen! */
SDL_FreeSurface(score_surfs[i]);
- score_surfs[i] = black_outline(N_(score_strings[i]), default_font, &white);
+ score_surfs[i] = BlackOutline(N_(score_strings[i]), default_font, &white);
- /* Get out if black_outline() fails: */
+ /* Get out if BlackOutline() fails: */
if (!score_surfs[i])
continue;
@@ -372,14 +374,14 @@
str2 = _("Enter Your Name:");
if (str1)
- s1 = black_outline(str1, default_font, &white);
+ s1 = BlackOutline(str1, default_font, &white);
if (str2)
- s2 = black_outline(str2, default_font, &white);
+ s2 = BlackOutline(str2, default_font, &white);
if (str3)
- s3 = black_outline(str3, default_font, &white);
+ s3 = BlackOutline(str3, default_font, &white);
/* When we get going with i18n may need to modify following - see below: */
if (str4)
- s4 = black_outline(str4, default_font, &white);
+ s4 = BlackOutline(str4, default_font, &white);
/* Redraw background: */
@@ -512,7 +514,7 @@
//Unicode_to_UTF8((const wchar_t*)buf, player_name);
wcstombs((char*) UTF8_buf, wchar_buf, HIGH_SCORE_NAME_LENGTH * 3);
- s3 = black_outline(UTF8_buf, name_font, &yellow);
+ s3 = BlackOutline(UTF8_buf, name_font, &yellow);
if (s3)
{
loc.x = 320 - (s3->w/2);
Modified: tuxmath/trunk/src/loaders.c
===================================================================
--- tuxmath/trunk/src/loaders.c 2007-09-25 15:22:45 UTC (rev 273)
+++ tuxmath/trunk/src/loaders.c 2007-09-25 20:22:46 UTC (rev 274)
@@ -44,106 +44,8 @@
return (n1 > n2 ? n1 : n2);
}
-/**********************
- Flip:
- input: a SDL_Surface, x, y
- output: a copy of the SDL_Surface flipped via rules:
- if x is a positive value, then flip horizontally
- if y is a positive value, then flip vertically
- note: you can have it flip both
-**********************/
-SDL_Surface* flip( SDL_Surface *in, int x, int y ) {
- SDL_Surface *out, *tmp;
- SDL_Rect from_rect, to_rect;
- Uint32 flags;
- Uint32 colorkey=0;
-
- /* --- grab the settings for the incoming pixmap --- */
-
- SDL_LockSurface(in);
- flags = in->flags;
-
- /* --- change in's flags so ignore colorkey & alpha --- */
-
- if (flags & SDL_SRCCOLORKEY) {
- in->flags &= ~SDL_SRCCOLORKEY;
- colorkey = in->format->colorkey;
- }
- if (flags & SDL_SRCALPHA) {
- in->flags &= ~SDL_SRCALPHA;
- }
-
- SDL_UnlockSurface(in);
-
- /* --- create our new surface --- */
-
- out = SDL_CreateRGBSurface(
- SDL_SWSURFACE,
- in->w, in->h, 32, rmask, gmask, bmask, amask);
-
- /* --- flip horizontally if requested --- */
-
- if (x) {
- from_rect.h = to_rect.h = in->h;
- from_rect.w = to_rect.w = 1;
- from_rect.y = to_rect.y = 0;
- from_rect.x = 0;
- to_rect.x = in->w - 1;
-
- do {
- SDL_BlitSurface(in, &from_rect, out, &to_rect);
- from_rect.x++;
- to_rect.x--;
- } while (to_rect.x >= 0);
- }
-
- /* --- flip vertically if requested --- */
-
- if (y) {
- from_rect.h = to_rect.h = 1;
- from_rect.w = to_rect.w = in->w;
- from_rect.x = to_rect.x = 0;
- from_rect.y = 0;
- to_rect.y = in->h - 1;
-
- do {
- SDL_BlitSurface(in, &from_rect, out, &to_rect);
- from_rect.y++;
- to_rect.y--;
- } while (to_rect.y >= 0);
- }
-
- /* --- restore colorkey & alpha on in and setup out the same --- */
-
- SDL_LockSurface(in);
-
- if (flags & SDL_SRCCOLORKEY) {
- in->flags |= SDL_SRCCOLORKEY;
- in->format->colorkey = colorkey;
- tmp = SDL_DisplayFormat(out);
- SDL_FreeSurface(out);
- out = tmp;
- out->flags |= SDL_SRCCOLORKEY;
- out->format->colorkey = colorkey;
- } else if (flags & SDL_SRCALPHA) {
- in->flags |= SDL_SRCALPHA;
- tmp = SDL_DisplayFormatAlpha(out);
- SDL_FreeSurface(out);
- out = tmp;
- } else {
- tmp = SDL_DisplayFormat(out);
- SDL_FreeSurface(out);
- out = tmp;
- }
-
- SDL_UnlockSurface(in);
-
- return out;
-}
-
-
/* 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. */
@@ -269,11 +171,11 @@
out = malloc(sizeof(sprite));
if (in->default_img != NULL)
- out->default_img = flip( in->default_img, X, Y );
+ 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->frame[out->num_frames] = Flip( in->frame[out->num_frames], X, Y );
out->cur = 0;
return out;
}
Modified: tuxmath/trunk/src/pause.c
===================================================================
--- tuxmath/trunk/src/pause.c 2007-09-25 15:22:45 UTC (rev 273)
+++ tuxmath/trunk/src/pause.c 2007-09-25 20:22:46 UTC (rev 274)
@@ -25,8 +25,8 @@
// 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;
@@ -85,13 +85,13 @@
if (Opts_UsingSound()) {
- t = black_outline(_("Sound Effects Volume"), f1, &white);
+ 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 = black_outline(_("Music Volume"), f1, &white);
+ t = BlackOutline(_("Music Volume"), f1, &white);
s.y = 260;
s.x = 320 - t->w/2;
SDL_BlitSurface(t, NULL, screen, &s);
@@ -99,26 +99,26 @@
} else {
- t = black_outline(_("Sound & Music Disabled"), f1, &white);
+ 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 = black_outline(_("Paused!"), f2, &white);
+ t = BlackOutline(_("Paused!"), f2, &white);
s.y = 60;
s.x = 320 - t->w/2;
SDL_BlitSurface(t, NULL, screen, &s);
SDL_FreeSurface(t);
- t = black_outline(_("Press escape again to return to menu"), f1, &white);
+ 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 = black_outline(_("Press space bar to return to game"), f1, &white);
+ 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);
Modified: tuxmath/trunk/src/setup.c
===================================================================
--- tuxmath/trunk/src/setup.c 2007-09-25 15:22:45 UTC (rev 273)
+++ tuxmath/trunk/src/setup.c 2007-09-25 20:22:46 UTC (rev 274)
@@ -47,8 +47,8 @@
#include "game.h"
#include "titlescreen.h"
#include "highscore.h"
+#include "SDL_extras.h"
-
/* Global data used in setup.c: */
/* (These are now 'extern'd in "tuxmath.h") */
SDL_Surface* screen;
@@ -567,7 +567,6 @@
/* Create flipped versions of certain images; also set up the flip
lookup table */
-/* FIXME where is flip() defined? */
void generate_flipped_images(void)
{
int i;
@@ -577,7 +576,7 @@
flipped_img_lookup[i] = 0;
for (i = 0; i < NUM_FLIPPED_IMAGES; i++) {
- flipped_images[i] = flip(images[flipped_img[i]],1,0);
+ flipped_images[i] = Flip(images[flipped_img[i]],1,0);
flipped_img_lookup[flipped_img[i]] = i;
}
}
Modified: tuxmath/trunk/src/titlescreen.c
===================================================================
--- tuxmath/trunk/src/titlescreen.c 2007-09-25 15:22:45 UTC (rev 273)
+++ tuxmath/trunk/src/titlescreen.c 2007-09-25 20:22:46 UTC (rev 274)
@@ -35,8 +35,8 @@
#include "credits.h"
#include "highscore.h"
#include "ConvertUTF.h" // for wide char to UTF-8 conversion
+#include "SDL_extras.h"
-
/* --- Data Structure for Dirty Blitting --- */
SDL_Rect srcupdate[MAX_UPDATES];
SDL_Rect dstupdate[MAX_UPDATES];
@@ -165,7 +165,6 @@
void AddRect(SDL_Rect* src, SDL_Rect* dst);
void InitEngine(void);
void ShowMessage(char* str1, char* str2, char* str3, char* str4);
-void round_corners(SDL_Surface* s, Uint16 radius);
/***********************************************************/
/* */
@@ -1135,8 +1134,8 @@
for (i = 1; i <= TITLE_MENU_ITEMS; i++)
{
/* --- create text surfaces --- */
- reg_text[i][j] = black_outline( _((unsigned char*)menu_text[i][j]), default_font, &white);
- sel_text[i][j] = black_outline( _((unsigned char*)menu_text[i][j]), default_font, &yellow);
+ reg_text[i][j] = BlackOutline( _((unsigned char*)menu_text[i][j]), default_font, &white);
+ sel_text[i][j] = BlackOutline( _((unsigned char*)menu_text[i][j]), default_font, &yellow);
/* Make sure we don't try to dereference NULL ptr: */
if (sel_text[i][j] && sel_text[i][j]->w > max)
@@ -1192,130 +1191,9 @@
}
}
-/* draw_button() creates and draws a translucent button with */
-/* rounded ends. The location and size are taken from the */
-/* SDL_Rect* and width arguments. The sprite is used to */
-/* fill in the rect with the desired translucent color and */
-/* give it nice, rounded ends. */
-/* FIXME make it match target_rect more precisely */
-void DrawButton(SDL_Rect* target_rect, int radius, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
-{
- SDL_Surface* tmp_surf = SDL_CreateRGBSurface(SDL_SWSURFACE|SDL_SRCALPHA,
- target_rect->w,
- target_rect->h,
- BPP,
- rmask, gmask, bmask, amask);
- Uint32 color = SDL_MapRGBA(tmp_surf->format, r, g, b, a);
- SDL_FillRect(tmp_surf, NULL, color);
- round_corners(tmp_surf, radius);
- SDL_BlitSurface(tmp_surf, NULL, screen, target_rect);
- SDL_FreeSurface(tmp_surf);
-// SDL_UpdateRect(screen, 0, 0, 0, 0);
- SDL_UpdateRect(screen, target_rect->x, target_rect->y, target_rect->w, target_rect->h);
-}
-
-void round_corners(SDL_Surface* s, Uint16 radius)
-{
- int y = 0;
- int x_dist, y_dist;
- Uint32* p = NULL;
- Uint32 alpha_mask;
- int bytes_per_pix;
-
- if (!s)
- return;
- if (SDL_LockSurface(s) == -1)
- return;
-
- bytes_per_pix = s->format->BytesPerPixel;
- if (bytes_per_pix != 4)
- return;
-
- /* radius cannot be more than half of width or height: */
- if (radius > (s->w)/2)
- radius = (s->w)/2;
- if (radius > (s->h)/2)
- radius = (s->h)/2;
-
-
- alpha_mask = s->format->Amask;
-
- /* Now round off corners: */
- /* upper left: */
- for (y = 0; y < radius; y++)
- {
- p = (Uint32*)(s->pixels + (y * s->pitch));
- x_dist = radius;
- y_dist = radius - y;
-
- while (((x_dist * x_dist) + (y_dist * y_dist)) > (radius * radius))
- {
- /* (make pixel (x,y) transparent) */
- *p = *p & ~alpha_mask;
- p++;
- x_dist--;
- }
- }
-
- /* upper right: */
- for (y = 0; y < radius; y++)
- {
- /* start at end of top row: */
- p = (Uint32*)(s->pixels + ((y + 1) * s->pitch) - bytes_per_pix);
-
- x_dist = radius;
- y_dist = radius - y;
-
- while (((x_dist * x_dist) + (y_dist * y_dist)) > (radius * radius))
- {
- /* (make pixel (x,y) transparent) */
- *p = *p & ~alpha_mask;
- p--;
- x_dist--;
- }
- }
-
- /* bottom left: */
- for (y = (s->h - 1); y > (s->h - radius); y--)
- {
- /* start at beginning of bottom row */
- p = (Uint32*)(s->pixels + (y * s->pitch));
- x_dist = radius;
- y_dist = y - (s->h - radius);
-
- while (((x_dist * x_dist) + (y_dist * y_dist)) > (radius * radius))
- {
- /* (make pixel (x,y) transparent) */
- *p = *p & ~alpha_mask;
- p++;
- x_dist--;
- }
- }
-
- /* bottom right: */
- for (y = (s->h - 1); y > (s->h - radius); y--)
- {
- /* start at end of bottom row */
- p = (Uint32*)(s->pixels + ((y + 1) * s->pitch) - bytes_per_pix);
- x_dist = radius;
- y_dist = y - (s->h - radius);
-
- while (((x_dist * x_dist) + (y_dist * y_dist)) > (radius * radius))
- {
- /* (make pixel (x,y) transparent) */
- *p = *p & ~alpha_mask;
- p--;
- x_dist--;
- }
- }
- SDL_UnlockSurface(s);
-}
-
-
-
void TitleScreen_unload_menu(void)
{
int i,j;
@@ -1396,14 +1274,14 @@
#endif
if (str1)
- s1 = black_outline(str1, default_font, &white);
+ s1 = BlackOutline(str1, default_font, &white);
if (str2)
- s2 = black_outline(str2, default_font, &white);
+ s2 = BlackOutline(str2, default_font, &white);
if (str3)
- s3 = black_outline(str3, default_font, &white);
+ s3 = BlackOutline(str3, default_font, &white);
/* When we get going with i18n may need to modify following - see below: */
if (str4)
- s4 = black_outline(str4, default_font, &white);
+ s4 = BlackOutline(str4, default_font, &white);
// /* we always want the URL in english */
// if (!useEnglish)
@@ -1579,8 +1457,8 @@
}
for (i = 0; i < num_lessons; i++)
{
- titles[i] = black_outline( _(lesson_list[i].display_name), default_font, &white );
- select[i] = black_outline( _(lesson_list[i].display_name), default_font, &yellow);
+ titles[i] = BlackOutline( _(lesson_list[i].display_name), default_font, &white );
+ select[i] = BlackOutline( _(lesson_list[i].display_name), default_font, &yellow);
}
// if (images[IMG_MENU_BKG])
Modified: tuxmath/trunk/src/titlescreen.h
===================================================================
--- tuxmath/trunk/src/titlescreen.h 2007-09-25 15:22:45 UTC (rev 273)
+++ tuxmath/trunk/src/titlescreen.h 2007-09-25 20:22:46 UTC (rev 274)
@@ -18,17 +18,6 @@
***************************************************************************/
-#if SDL_BYTEORDER == SDL_BIG_ENDIAN
-#define rmask 0xff000000
-#define gmask 0x00ff0000
-#define bmask 0x0000ff00
-#define amask 0x000000ff
-#else
-#define rmask 0x000000ff
-#define gmask 0x0000ff00
-#define bmask 0x00ff0000
-#define amask 0xff000000
-#endif
#ifndef TITLESCREEN_H
@@ -160,13 +149,8 @@
//extern TTF_Font *font;
extern SDL_Event event;
-extern SDL_Color black;
-extern SDL_Color gray;
-extern SDL_Color dark_blue;
-extern SDL_Color red;
-extern SDL_Color white;
-extern SDL_Color yellow;
+
extern SDL_Surface *bkg;
extern SDL_Surface *letters[255];
@@ -248,7 +232,6 @@
void TitleScreen( void );
void switch_screen_mode( void );
int choose_config_file(void); //FIXME really should be in fileops.c
-void DrawButton(SDL_Rect* target_rect, int radius, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
/* in theme.c (from tuxtype): */
void chooseTheme(void);
@@ -264,7 +247,6 @@
sprite *FlipSprite( sprite *in, int X, int Y );
void FreeSprite( sprite *gfx );
Mix_Music *LoadMusic( char *datafile );
-SDL_Surface* flip( SDL_Surface *in, int x, int y );
/* in alphabet.c (from tuxtype) */
void LoadKeyboard( void );
@@ -272,7 +254,6 @@
unsigned char get_letter( void );
void custom_letter_setup( void );
void show_letters( void );
-SDL_Surface* black_outline( unsigned char *t, TTF_Font* font, SDL_Color* c );
void WORDS_init( void );
void WORDS_use_alphabet( void );
void WORDS_use( char *wordFn );
Modified: tuxmath/trunk/src/tuxmath.h
===================================================================
--- tuxmath/trunk/src/tuxmath.h 2007-09-25 15:22:45 UTC (rev 273)
+++ tuxmath/trunk/src/tuxmath.h 2007-09-25 20:22:46 UTC (rev 274)
@@ -147,6 +147,12 @@
/* Global data gets 'externed' here: */
+extern SDL_Color black;
+extern SDL_Color gray;
+extern SDL_Color dark_blue;
+extern SDL_Color red;
+extern SDL_Color white;
+extern SDL_Color yellow;
extern SDL_Surface* screen; /* declared in setup.c; also used in game.c, options.c, fileops.c, credits.c, titlescreen.c */
extern SDL_Surface* images[]; /* declared in setup.c, used in same files as screen */
More information about the Tux4kids-commits
mailing list