From 2f29e8aef1bf8eb9d4e235f8e43e535263a4b576 Mon Sep 17 00:00:00 2001 From: William Kendrick Date: Mon, 13 Feb 2006 08:18:53 +0000 Subject: [PATCH] Sparkles can now be different colors. --- docs/CHANGES.txt | 4 +++ src/magic.h | 6 ++-- src/tuxpaint.c | 81 ++++++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 86 insertions(+), 5 deletions(-) diff --git a/docs/CHANGES.txt b/docs/CHANGES.txt index 4097c9d7a..75d32fcdc 100644 --- a/docs/CHANGES.txt +++ b/docs/CHANGES.txt @@ -19,6 +19,10 @@ $Id$ back into 16-bit unicode characters to satisfy SDL_ttf. Tested on Windows and Linux.) John Popplewell + + * Magic tool improvements: + ------------------------ + * Sparkles can now be different colors. * Translation Updates: -------------------- diff --git a/src/magic.h b/src/magic.h index b11a5a562..7f4d730ef 100644 --- a/src/magic.h +++ b/src/magic.h @@ -4,11 +4,11 @@ For Tux Paint List of available tools. - Copyright (c) 2004 by Bill Kendrick + Copyright (c) 2002-2006 by Bill Kendrick bill@newbreedsoftware.com http://www.newbreedsoftware.com/tuxpaint/ - June 29, 2002 - December 11, 2004 + June 29, 2002 - February 13, 2006 $Id$ */ @@ -57,7 +57,7 @@ const int magic_colors[] = { COLORSEL_ENABLE, // small bricks COLORSEL_DISABLE, - COLORSEL_DISABLE, + COLORSEL_ENABLE, // sparkles COLORSEL_DISABLE, COLORSEL_DISABLE, diff --git a/src/tuxpaint.c b/src/tuxpaint.c index 3dbe72894..75217d426 100644 --- a/src/tuxpaint.c +++ b/src/tuxpaint.c @@ -1547,7 +1547,7 @@ static SDL_Surface * img_scroll_up_off, * img_scroll_down_off; static SDL_Surface * img_grow, * img_shrink; static SDL_Surface * img_bold, * img_italic; -static SDL_Surface * img_sparkles; +static SDL_Surface * img_sparkles, * img_sparkles_color; static SDL_Surface * img_grass; static SDL_Surface * img_title_on, * img_title_off, @@ -2377,6 +2377,7 @@ static Uint32 (*getpixels[])(SDL_Surface *, int, int) = { static void do_undo(void); static void do_redo(void); static void render_brush(void); +static void render_sparkles(void); static void playsound(int chan, int s, int override); static void line_xor(int x1, int y1, int x2, int y2); static void rect_xor(int x1, int y1, int x2, int y2); @@ -2747,6 +2748,7 @@ int main(int argc, char * argv[]) img_cur_brush = NULL; render_brush(); + render_sparkles(); brush_scroll = 0; stamp_scroll = 0; @@ -3899,6 +3901,7 @@ static void mainloop(void) playsound(1, SND_BUBBLE, 1); draw_colors(COLORSEL_REFRESH); render_brush(); + render_sparkles(); draw_tux_text(TUX_KISS, color_names[cur_color], 1); if (cur_tool == TOOL_TEXT) @@ -6271,7 +6274,7 @@ static void blit_magic(int x, int y, int button_down) dest.x = x - 16; dest.y = y - 16; - SDL_BlitSurface(img_sparkles, &src, canvas, &dest); + SDL_BlitSurface(img_sparkles_color, &src, canvas, &dest); } } else if (cur_magic == MAGIC_GRASS) @@ -10889,6 +10892,79 @@ static void render_brush(void) } +/* Create the sparkles in the current color: */ + +static void render_sparkles(void) +{ + Uint32 amask; + int x, y; + Uint8 r, g, b, a; + Uint32 (*getpixel_sparkles)(SDL_Surface *, int, int) = getpixels[img_sparkles->format->BytesPerPixel]; + void (*putpixel_sparkles)(SDL_Surface *, int, int, Uint32) = putpixels[img_sparkles->format->BytesPerPixel]; + + + /* Free the old rendered brush (if any): */ + + if (img_sparkles_color != NULL) + { + SDL_FreeSurface(img_sparkles_color); + } + + + /* Create a surface to render into: */ + + amask = ~(img_sparkles->format->Rmask | + img_sparkles->format->Gmask | + img_sparkles->format->Bmask); + + img_sparkles_color = + SDL_CreateRGBSurface(SDL_SWSURFACE, + img_sparkles->w, + img_sparkles->h, + img_sparkles->format->BitsPerPixel, + img_sparkles->format->Rmask, + img_sparkles->format->Gmask, + img_sparkles->format->Bmask, + amask); + + if (img_sparkles_color == NULL) + { + fprintf(stderr, "\nError: Can't render sparkles!\n" + "The Simple DirectMedia Layer error that occurred was:\n" + "%s\n\n", SDL_GetError()); + + cleanup(); + exit(1); + } + + + /* Render the colored sparkles: */ + + SDL_LockSurface(img_sparkles); + SDL_LockSurface(img_sparkles_color); + + for (y = 0; y < img_sparkles->h; y++) + { + for (x = 0; x < img_sparkles->w; x++) + { + SDL_GetRGBA(getpixel_sparkles(img_sparkles, x, y), + img_sparkles->format, + &r, &g, &b, &a); + + putpixel_sparkles(img_sparkles_color, x, y, + SDL_MapRGBA(img_sparkles_color->format, + color_hexes[cur_color][0], + color_hexes[cur_color][1], + color_hexes[cur_color][2], + a)); + } + } + + SDL_UnlockSurface(img_sparkles_color); + SDL_UnlockSurface(img_sparkles); +} + + /* Play a sound: */ static void playsound(int chan, int s, int override) @@ -12766,6 +12842,7 @@ static void cleanup(void) free_surface( &img_italic ); free_surface( &img_sparkles ); + free_surface( &img_sparkles_color ); free_surface( &img_grass ); free_surface_array( undo_bufs, NUM_UNDO_BUFS );