From 535220e9213c6838c14f8e28290b55cc9af50857 Mon Sep 17 00:00:00 2001 From: William Kendrick Date: Fri, 6 Jul 2007 19:34:47 +0000 Subject: [PATCH] Finished Fade, Darken, Mirror, Flip and Negative Magic tools as plugins. --- magic/src/fade_darken.c | 21 ++++++++++++++++++--- magic/src/mirror_flip.c | 20 ++++++++++++++++++++ magic/src/negative.c | 15 ++++++++++++++- 3 files changed, 52 insertions(+), 4 deletions(-) diff --git a/magic/src/fade_darken.c b/magic/src/fade_darken.c index 18c3b5c04..95ea5b74d 100644 --- a/magic/src/fade_darken.c +++ b/magic/src/fade_darken.c @@ -3,6 +3,7 @@ #include #include "tp_magic_api.h" #include "SDL_image.h" +#include "SDL_mixer.h" enum { TOOL_FADE, @@ -10,12 +11,21 @@ enum { NUM_TOOLS }; -#define min(a,b) ((a) < (b) ? (a) : (b)) -#define max(a,b) ((a) > (b) ? (a) : (b)) +Mix_Chunk * snd_effects[NUM_TOOLS]; + -// No setup required: int fade_darken_init(magic_api * api) { + char fname[1024]; + + snprintf(fname, sizeof(fname), "%s/sounds/magic/fade.wav", + api->data_directory); + snd_effects[TOOL_FADE] = Mix_LoadWAV(fname); + + snprintf(fname, sizeof(fname), "%s/sounds/magic/darken.wav", + api->data_directory); + snd_effects[TOOL_DARKEN] = Mix_LoadWAV(fname); + return(1); } @@ -112,6 +122,7 @@ void fade_darken_drag(magic_api * api, int which, SDL_Surface * canvas, SDL_LockSurface(canvas); api->line(which, canvas, last, ox, oy, x, y, 1, do_fade_darken); + api->playsound(snd_effects[which], (x * 255) / canvas->w, 255); SDL_UnlockSurface(canvas); SDL_UnlockSurface(last); @@ -129,6 +140,10 @@ void fade_darken_click(magic_api * api, int which, // No setup happened: void fade_darken_shutdown(magic_api * api) { + if (snd_effects[0] != NULL) + Mix_FreeChunk(snd_effects[0]); + if (snd_effects[1] != NULL) + Mix_FreeChunk(snd_effects[1]); } // We don't use colors diff --git a/magic/src/mirror_flip.c b/magic/src/mirror_flip.c index 8f37f39a3..ddeb38479 100644 --- a/magic/src/mirror_flip.c +++ b/magic/src/mirror_flip.c @@ -3,6 +3,7 @@ #include #include "tp_magic_api.h" #include "SDL_image.h" +#include "SDL_mixer.h" /* What tools we contain: */ @@ -12,9 +13,22 @@ enum { NUM_TOOLS }; +Mix_Chunk * snd_effects[NUM_TOOLS]; + + // No setup required: int mirror_flip_init(magic_api * api) { + char fname[1024]; + + snprintf(fname, sizeof(fname), "%s/sounds/magic/mirror.wav", + api->data_directory); + snd_effects[TOOL_MIRROR] = Mix_LoadWAV(fname); + + snprintf(fname, sizeof(fname), "%s/sounds/magic/flip.wav", + api->data_directory); + snd_effects[TOOL_FLIP] = Mix_LoadWAV(fname); + return(1); } @@ -116,11 +130,17 @@ void mirror_flip_click(magic_api * api, int which, api->special_notify(SPECIAL_FLIP); } + + api->playsound(snd_effects[which], 128, 255); } // No setup happened: void mirror_flip_shutdown(magic_api * api) { + if (snd_effects[0] != NULL) + Mix_FreeChunk(snd_effects[0]); + if (snd_effects[1] != NULL) + Mix_FreeChunk(snd_effects[1]); } // We don't use colors: diff --git a/magic/src/negative.c b/magic/src/negative.c index 569b94158..a2c2b6c28 100644 --- a/magic/src/negative.c +++ b/magic/src/negative.c @@ -3,10 +3,20 @@ #include #include "tp_magic_api.h" #include "SDL_image.h" +#include "SDL_mixer.h" + +Mix_Chunk * negative_snd; // No setup required: int negative_init(magic_api * api) { + char fname[1024]; + + snprintf(fname, sizeof(fname), "%s/sounds/magic/negative.wav", + api->data_directory); + + negative_snd = Mix_LoadWAV(fname); + return(1); } @@ -74,6 +84,8 @@ void negative_drag(magic_api * api, int which, SDL_Surface * canvas, SDL_LockSurface(canvas); api->line(which, canvas, last, ox, oy, x, y, 1, do_negative); + + api->playsound(negative_snd, (x * 255) / canvas->w, 255); SDL_UnlockSurface(canvas); SDL_UnlockSurface(last); @@ -88,9 +100,10 @@ void negative_click(magic_api * api, int which, } -// No setup happened: void negative_shutdown(magic_api * api) { + if (negative_snd != NULL) + Mix_FreeChunk(negative_snd); } // We don't use colors