Added Magic tool API version API.
This commit is contained in:
parent
abf6a2a1bb
commit
73b8464b75
22 changed files with 85 additions and 172 deletions
|
|
@ -19,7 +19,6 @@ enum {
|
|||
Mix_Chunk * snd_effect[NUM_TOOLS];
|
||||
|
||||
|
||||
// No setup required:
|
||||
int blocks_chalk_drip_init(magic_api * api)
|
||||
{
|
||||
char fname[1024];
|
||||
|
|
@ -39,6 +38,9 @@ int blocks_chalk_drip_init(magic_api * api)
|
|||
return(1);
|
||||
}
|
||||
|
||||
Uint32 blocks_chalk_drip_api_version(void) { return(TP_MAGIC_API_VERSION); }
|
||||
|
||||
|
||||
// We have multiple tools:
|
||||
int blocks_chalk_drip_get_tool_count(magic_api * api)
|
||||
{
|
||||
|
|
@ -100,8 +102,9 @@ char * blocks_chalk_drip_get_description(magic_api * api, int which)
|
|||
|
||||
// Do the effect:
|
||||
|
||||
void do_example(void * ptr, int which, SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y)
|
||||
void blocks_chalk_drip_linecb(void * ptr, int which,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y)
|
||||
{
|
||||
magic_api * api = (magic_api *) ptr;
|
||||
int xx, yy;
|
||||
|
|
@ -210,7 +213,7 @@ void do_example(void * ptr, int which, SDL_Surface * canvas, SDL_Surface * last,
|
|||
void blocks_chalk_drip_drag(magic_api * api, int which, SDL_Surface * canvas,
|
||||
SDL_Surface * last, int ox, int oy, int x, int y)
|
||||
{
|
||||
api->line(which, canvas, last, ox, oy, x, y, 1, do_example);
|
||||
api->line(which, canvas, last, ox, oy, x, y, 1, blocks_chalk_drip_linecb);
|
||||
|
||||
api->playsound(snd_effect[which], (x * 255) / canvas->w, 255);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,6 +22,8 @@ int blur_init(magic_api * api)
|
|||
return(1);
|
||||
}
|
||||
|
||||
Uint32 blur_api_version(void) { return(TP_MAGIC_API_VERSION); }
|
||||
|
||||
int blur_get_tool_count(magic_api * api)
|
||||
{
|
||||
return(1);
|
||||
|
|
|
|||
|
|
@ -38,6 +38,8 @@ int bricks_init(magic_api * api)
|
|||
return(1);
|
||||
}
|
||||
|
||||
Uint32 bricks_api_version(void) { return(TP_MAGIC_API_VERSION); }
|
||||
|
||||
// We have multiple tools:
|
||||
int bricks_get_tool_count(magic_api * api)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -26,6 +26,8 @@ int cartoon_init(magic_api * api)
|
|||
return(1);
|
||||
}
|
||||
|
||||
Uint32 cartoon_api_version(void) { return(TP_MAGIC_API_VERSION); }
|
||||
|
||||
// We have multiple tools:
|
||||
int cartoon_get_tool_count(magic_api * api)
|
||||
{
|
||||
|
|
|
|||
156
magic/src/drip.c
156
magic/src/drip.c
|
|
@ -1,156 +0,0 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <libintl.h>
|
||||
#include "tp_magic_api.h"
|
||||
#include "SDL_image.h"
|
||||
#include "SDL_mixer.h"
|
||||
|
||||
/* What tools we contain: */
|
||||
|
||||
enum {
|
||||
TOOL_ONE,
|
||||
TOOL_TWO,
|
||||
NUM_TOOLS
|
||||
};
|
||||
|
||||
|
||||
/* Our globals: */
|
||||
|
||||
Mix_Chunk * snd_effect[NUM_TOOLS];
|
||||
Uint8 example_r, example_g, example_b;
|
||||
|
||||
|
||||
// No setup required:
|
||||
int example_init(magic_api * api)
|
||||
{
|
||||
char fname[1024];
|
||||
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/one.wav",
|
||||
api->data_directory);
|
||||
snd_effect[0] = Mix_LoadWAV(fname);
|
||||
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/two.wav",
|
||||
api->data_directory);
|
||||
snd_effect[1] = Mix_LoadWAV(fname);
|
||||
|
||||
return(1);
|
||||
}
|
||||
|
||||
// We have multiple tools:
|
||||
int example_get_tool_count(magic_api * api)
|
||||
{
|
||||
return(NUM_TOOLS);
|
||||
}
|
||||
|
||||
// Load our icons:
|
||||
SDL_Surface * example_get_icon(magic_api * api, int which)
|
||||
{
|
||||
char fname[1024];
|
||||
|
||||
if (which == TOOL_ONE)
|
||||
{
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/one.png",
|
||||
api->data_directory);
|
||||
}
|
||||
else if (which == TOOL_TWO)
|
||||
{
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/two.png",
|
||||
api->data_directory);
|
||||
}
|
||||
|
||||
return(IMG_Load(fname));
|
||||
}
|
||||
|
||||
// Return our names, localized:
|
||||
char * example_get_name(magic_api * api, int which)
|
||||
{
|
||||
if (which == TOOL_ONE)
|
||||
return(strdup(gettext("One")));
|
||||
else if (which == TOOL_TWO)
|
||||
return(strdup(gettext("Two")));
|
||||
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
// Return our descriptions, localized:
|
||||
char * example_get_description(magic_api * api, int which)
|
||||
{
|
||||
if (which == TOOL_ONE)
|
||||
return(strdup(gettext("Tool one.")));
|
||||
else
|
||||
return(strdup(gettext("Tool two.")));
|
||||
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
// Do the effect:
|
||||
|
||||
void do_example(void * ptr, int which, SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y)
|
||||
{
|
||||
magic_api * api = (magic_api *) ptr;
|
||||
int xx, yy;
|
||||
|
||||
if (which == TOOL_ONE)
|
||||
{
|
||||
api->putpixel(canvas, x, y, SDL_MapRGB(canvas->format,
|
||||
example_r,
|
||||
example_g,
|
||||
example_b));
|
||||
}
|
||||
else if (which == TOOL_TWO)
|
||||
{
|
||||
for (yy = -4; yy < 4; yy++)
|
||||
{
|
||||
for (xx = -4; xx < 4; xx++)
|
||||
{
|
||||
api->putpixel(canvas, x + xx, y + yy,
|
||||
api->getpixel(last,
|
||||
canvas->w - x - xx,
|
||||
canvas->h - y - yy));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Affect the canvas on drag:
|
||||
void example_drag(magic_api * api, int which, SDL_Surface * canvas,
|
||||
SDL_Surface * last, int ox, int oy, int x, int y)
|
||||
{
|
||||
api->line(which, canvas, last, ox, oy, x, y, 1, do_example);
|
||||
|
||||
api->playsound(snd_effect[which], (x * 255) / canvas->w, 255);
|
||||
}
|
||||
|
||||
// Affect the canvas on click:
|
||||
void example_click(magic_api * api, int which,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y)
|
||||
{
|
||||
example_drag(api, which, canvas, last, x, y, x, y);
|
||||
}
|
||||
|
||||
// No setup happened:
|
||||
void example_shutdown(magic_api * api)
|
||||
{
|
||||
if (snd_effect[0] != NULL)
|
||||
Mix_FreeChunk(snd_effect[0]);
|
||||
|
||||
if (snd_effect[1] != NULL)
|
||||
Mix_FreeChunk(snd_effect[1]);
|
||||
}
|
||||
|
||||
// Record the color from Tux Paint:
|
||||
void example_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b)
|
||||
{
|
||||
example_r = r;
|
||||
example_g = g;
|
||||
example_b = b;
|
||||
}
|
||||
|
||||
// Use colors:
|
||||
int example_requires_colors(magic_api * api, int which)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
@ -29,6 +29,8 @@ int fade_darken_init(magic_api * api)
|
|||
return(1);
|
||||
}
|
||||
|
||||
Uint32 fade_darken_api_version(void) { return(TP_MAGIC_API_VERSION); }
|
||||
|
||||
// Multiple tools:
|
||||
int fade_darken_get_tool_count(magic_api * api)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -30,6 +30,8 @@ int fill_init(magic_api * api)
|
|||
return(1);
|
||||
}
|
||||
|
||||
Uint32 fill_api_version(void) { return(TP_MAGIC_API_VERSION); }
|
||||
|
||||
// We have multiple tools:
|
||||
int fill_get_tool_count(magic_api * api)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -37,6 +37,8 @@ int grass_init(magic_api * api)
|
|||
return(1);
|
||||
}
|
||||
|
||||
Uint32 grass_api_version(void) { return(TP_MAGIC_API_VERSION); }
|
||||
|
||||
// We have multiple tools:
|
||||
int grass_get_tool_count(magic_api * api)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -32,6 +32,8 @@ int mirror_flip_init(magic_api * api)
|
|||
return(1);
|
||||
}
|
||||
|
||||
Uint32 mirror_flip_api_version(void) { return(TP_MAGIC_API_VERSION); }
|
||||
|
||||
// We have multiple tools:
|
||||
int mirror_flip_get_tool_count(magic_api * api)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -20,6 +20,8 @@ int negative_init(magic_api * api)
|
|||
return(1);
|
||||
}
|
||||
|
||||
Uint32 negative_api_version(void) { return(TP_MAGIC_API_VERSION); }
|
||||
|
||||
// Only one tool:
|
||||
int negative_get_tool_count(magic_api * api)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -54,6 +54,8 @@ int rainbow_init(magic_api * api)
|
|||
return(1);
|
||||
}
|
||||
|
||||
Uint32 rainbow_api_version(void) { return(TP_MAGIC_API_VERSION); }
|
||||
|
||||
// We have multiple tools:
|
||||
int rainbow_get_tool_count(magic_api * api)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -23,6 +23,8 @@ int smudge_init(magic_api * api)
|
|||
return(1);
|
||||
}
|
||||
|
||||
Uint32 smudge_api_version(void) { return(TP_MAGIC_API_VERSION); }
|
||||
|
||||
// We have multiple tools:
|
||||
int smudge_get_tool_count(magic_api * api)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -24,6 +24,8 @@ int tint_init(magic_api * api)
|
|||
return(1);
|
||||
}
|
||||
|
||||
Uint32 tint_api_version(void) { return(TP_MAGIC_API_VERSION); }
|
||||
|
||||
// We have multiple tools:
|
||||
int tint_get_tool_count(magic_api * api)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue