Completed Negative Magic tool as a plugin (except sound).
Created Mirror and Flip Magic tools as plugins (except sound); hooks added to Magic plugin API to allow starter and starter-undo mirror/flip. Created Fade and Darken Magic tools as plugins. Moved magic tool sounds to 'magic'. Added flip and mirror icons to main Tux Paint UI (used to share magic tools') Created 'tp-magic-config.sh' to get CFLAGS for compiling magic tool plugins. Improved magic tool plugin API. Committed some documentation on magic tool plugin API.
This commit is contained in:
parent
c6aa0af0a9
commit
47e44cb80f
32 changed files with 917 additions and 729 deletions
144
magic/src/fade_darken.c
Normal file
144
magic/src/fade_darken.c
Normal file
|
|
@ -0,0 +1,144 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <libintl.h>
|
||||
#include "tp_magic_api.h"
|
||||
#include "SDL_image.h"
|
||||
|
||||
enum {
|
||||
TOOL_FADE,
|
||||
TOOL_DARKEN,
|
||||
NUM_TOOLS
|
||||
};
|
||||
|
||||
#define min(a,b) ((a) < (b) ? (a) : (b))
|
||||
#define max(a,b) ((a) > (b) ? (a) : (b))
|
||||
|
||||
// No setup required:
|
||||
int fade_darken_init(magic_api * api)
|
||||
{
|
||||
return(1);
|
||||
}
|
||||
|
||||
// Multiple tools:
|
||||
int fade_darken_get_tool_count(magic_api * api)
|
||||
{
|
||||
return(NUM_TOOLS);
|
||||
}
|
||||
|
||||
// Load our icon:
|
||||
SDL_Surface * fade_darken_get_icon(magic_api * api, int which)
|
||||
{
|
||||
char fname[1024];
|
||||
|
||||
if (which == TOOL_FADE)
|
||||
{
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/fade.png",
|
||||
api->data_directory);
|
||||
}
|
||||
else if (which == TOOL_DARKEN)
|
||||
{
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/darken.png",
|
||||
api->data_directory);
|
||||
}
|
||||
|
||||
return(IMG_Load(fname));
|
||||
}
|
||||
|
||||
// Return our name, localized:
|
||||
char * fade_darken_get_name(magic_api * api, int which)
|
||||
{
|
||||
if (which == TOOL_FADE)
|
||||
return(strdup(gettext("Lighten")));
|
||||
else if (which == TOOL_DARKEN)
|
||||
return(strdup(gettext("Darken")));
|
||||
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
// Return our description, localized:
|
||||
char * fade_darken_get_description(magic_api * api, int which)
|
||||
{
|
||||
if (which == TOOL_FADE)
|
||||
return(strdup(
|
||||
gettext("Click and move to fade the colors.")));
|
||||
else if (which == TOOL_DARKEN)
|
||||
return(strdup(
|
||||
gettext("Click and move to darken the colors.")));
|
||||
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
// Callback that does the fade_darken color effect on a circle centered around x,y
|
||||
void do_fade_darken(void * ptr, int which,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y)
|
||||
{
|
||||
int xx, yy;
|
||||
Uint8 r, g, b;
|
||||
magic_api * api = (magic_api *) ptr;
|
||||
|
||||
for (yy = y - 16; yy < y + 16; yy++)
|
||||
{
|
||||
for (xx = x - 16; xx < x + 16; xx++)
|
||||
{
|
||||
if (api->in_circle(xx - x, yy - y, 16))
|
||||
{
|
||||
SDL_GetRGB(api->getpixel(last, xx, yy), last->format, &r, &g, &b);
|
||||
|
||||
if (which == TOOL_FADE)
|
||||
{
|
||||
r = min(r + 48, 255);
|
||||
g = min(g + 48, 255);
|
||||
b = min(b + 48, 255);
|
||||
}
|
||||
else if (which == TOOL_DARKEN)
|
||||
{
|
||||
r = max(r - 48, 0);
|
||||
g = max(g - 48, 0);
|
||||
b = max(b - 48, 0);
|
||||
}
|
||||
|
||||
api->putpixel(canvas, xx, yy, SDL_MapRGB(canvas->format, r, g, b));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Ask Tux Paint to call our 'do_fade_darken()' callback over a line
|
||||
void fade_darken_drag(magic_api * api, int which, SDL_Surface * canvas,
|
||||
SDL_Surface * last, int ox, int oy, int x, int y)
|
||||
{
|
||||
SDL_LockSurface(last);
|
||||
SDL_LockSurface(canvas);
|
||||
|
||||
api->line(which, canvas, last, ox, oy, x, y, 1, do_fade_darken);
|
||||
|
||||
SDL_UnlockSurface(canvas);
|
||||
SDL_UnlockSurface(last);
|
||||
}
|
||||
|
||||
// Ask Tux Paint to call our 'do_fade_darken()' callback at a single point
|
||||
void fade_darken_click(magic_api * api, int which,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y)
|
||||
{
|
||||
fade_darken_drag(api, which, canvas, last, x, y, x, y);
|
||||
}
|
||||
|
||||
|
||||
// No setup happened:
|
||||
void fade_darken_shutdown(magic_api * api)
|
||||
{
|
||||
}
|
||||
|
||||
// We don't use colors
|
||||
void fade_darken_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b)
|
||||
{
|
||||
}
|
||||
|
||||
// We don't use colors
|
||||
int fade_darken_requires_colors(magic_api * api, int which)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -1,238 +0,0 @@
|
|||
#include "../../src/compiler.h"
|
||||
#include "magic_helpers.h"
|
||||
|
||||
int MAGIC_in_circle(int x, int y, int radius)
|
||||
{
|
||||
if ((x * x) + (y * y) - (radius * radius) < 0)
|
||||
return (1);
|
||||
else
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
/* Draw a single pixel into the surface: */
|
||||
|
||||
void MAGIC_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 MAGIC_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 MAGIC_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 MAGIC_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 MAGIC_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 MAGIC_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 MAGIC_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 MAGIC_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 (*MAGIC_putpixels[]) (SDL_Surface *, int, int, Uint32) =
|
||||
{
|
||||
MAGIC_putpixel8, MAGIC_putpixel8, MAGIC_putpixel16, MAGIC_putpixel24, MAGIC_putpixel32};
|
||||
|
||||
|
||||
Uint32(*MAGIC_getpixels[])(SDL_Surface *, int, int) =
|
||||
{
|
||||
MAGIC_getpixel8, MAGIC_getpixel8, MAGIC_getpixel16, MAGIC_getpixel24, MAGIC_getpixel32};
|
||||
|
||||
|
|
@ -1,23 +0,0 @@
|
|||
#ifndef MAGIC_HELPERS_H
|
||||
#define MAGIC_HELPERS_H
|
||||
|
||||
#include "SDL.h"
|
||||
#include <libintl.h>
|
||||
|
||||
int MAGIC_in_circle(int x, int y, int radius);
|
||||
|
||||
void MAGIC_putpixel8(SDL_Surface * surface, int x, int y, Uint32 pixel);
|
||||
void MAGIC_putpixel16(SDL_Surface * surface, int x, int y, Uint32 pixel);
|
||||
void MAGIC_putpixel24(SDL_Surface * surface, int x, int y, Uint32 pixel);
|
||||
void MAGIC_putpixel32(SDL_Surface * surface, int x, int y, Uint32 pixel);
|
||||
|
||||
extern void (*MAGIC_putpixels[]) (SDL_Surface *, int, int, Uint32);
|
||||
|
||||
Uint32 MAGIC_getpixel8(SDL_Surface * surface, int x, int y);
|
||||
Uint32 MAGIC_getpixel16(SDL_Surface * surface, int x, int y);
|
||||
Uint32 MAGIC_getpixel24(SDL_Surface * surface, int x, int y);
|
||||
Uint32 MAGIC_getpixel32(SDL_Surface * surface, int x, int y);
|
||||
|
||||
extern Uint32(*MAGIC_getpixels[]) (SDL_Surface *, int, int);
|
||||
|
||||
#endif
|
||||
136
magic/src/mirror_flip.c
Normal file
136
magic/src/mirror_flip.c
Normal file
|
|
@ -0,0 +1,136 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <libintl.h>
|
||||
#include "tp_magic_api.h"
|
||||
#include "SDL_image.h"
|
||||
|
||||
/* What tools we contain: */
|
||||
|
||||
enum {
|
||||
TOOL_MIRROR,
|
||||
TOOL_FLIP,
|
||||
NUM_TOOLS
|
||||
};
|
||||
|
||||
// No setup required:
|
||||
int mirror_flip_init(magic_api * api)
|
||||
{
|
||||
return(1);
|
||||
}
|
||||
|
||||
// We have multiple tools:
|
||||
int mirror_flip_get_tool_count(magic_api * api)
|
||||
{
|
||||
return(NUM_TOOLS);
|
||||
}
|
||||
|
||||
// Load our icons:
|
||||
SDL_Surface * mirror_flip_get_icon(magic_api * api, int which)
|
||||
{
|
||||
char fname[1024];
|
||||
|
||||
if (which == TOOL_MIRROR)
|
||||
{
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/mirror.png",
|
||||
api->data_directory);
|
||||
}
|
||||
else if (which == TOOL_FLIP)
|
||||
{
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/flip.png",
|
||||
api->data_directory);
|
||||
}
|
||||
|
||||
return(IMG_Load(fname));
|
||||
}
|
||||
|
||||
// Return our names, localized:
|
||||
char * mirror_flip_get_name(magic_api * api, int which)
|
||||
{
|
||||
if (which == TOOL_MIRROR)
|
||||
return(strdup(gettext("Mirror")));
|
||||
else if (which == TOOL_FLIP)
|
||||
return(strdup(gettext("Flip")));
|
||||
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
// Return our descriptions, localized:
|
||||
char * mirror_flip_get_description(magic_api * api, int which)
|
||||
{
|
||||
if (which == TOOL_MIRROR)
|
||||
return(strdup(
|
||||
gettext("Click to flip the picture upside-down.")));
|
||||
else
|
||||
return(strdup(
|
||||
gettext("Click to make a mirror image.")));
|
||||
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
// We affect the whole canvas, so only do things on click, not drag:
|
||||
void mirror_flip_drag(magic_api * api, int which, SDL_Surface * canvas,
|
||||
SDL_Surface * last, int ox, int oy, int x, int y)
|
||||
{
|
||||
// No-op
|
||||
}
|
||||
|
||||
// Affect the canvas on click:
|
||||
void mirror_flip_click(magic_api * api, int which,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y)
|
||||
{
|
||||
int xx, yy;
|
||||
SDL_Rect src, dest;
|
||||
|
||||
if (which == TOOL_MIRROR)
|
||||
{
|
||||
for (xx = 0; xx < canvas->w; xx++)
|
||||
{
|
||||
src.x = xx;
|
||||
src.y = 0;
|
||||
src.w = 1;
|
||||
src.h = canvas->h;
|
||||
|
||||
dest.x = canvas->w - xx - 1;
|
||||
dest.y = 0;
|
||||
|
||||
SDL_BlitSurface(last, &src, canvas, &dest);
|
||||
}
|
||||
|
||||
api->special_notify(SPECIAL_MIRROR);
|
||||
}
|
||||
else if (which == TOOL_FLIP)
|
||||
{
|
||||
for (yy = 0; yy < canvas->h; yy++)
|
||||
{
|
||||
src.x = 0;
|
||||
src.y = yy;
|
||||
src.w = canvas->w;
|
||||
src.h = 1;
|
||||
|
||||
dest.x = 0;
|
||||
dest.y = canvas->h - yy - 1;
|
||||
|
||||
SDL_BlitSurface(last, &src, canvas, &dest);
|
||||
}
|
||||
|
||||
api->special_notify(SPECIAL_FLIP);
|
||||
}
|
||||
}
|
||||
|
||||
// No setup happened:
|
||||
void mirror_flip_shutdown(magic_api * api)
|
||||
{
|
||||
}
|
||||
|
||||
// We don't use colors:
|
||||
void mirror_flip_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b)
|
||||
{
|
||||
}
|
||||
|
||||
// We don't use colors:
|
||||
int mirror_flip_requires_colors(magic_api * api, int which)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -1,111 +1,106 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <libintl.h>
|
||||
#include "tp_magic_api.h"
|
||||
#include "SDL_image.h"
|
||||
#include "magic_helpers.h"
|
||||
|
||||
void init()
|
||||
// No setup required:
|
||||
int negative_init(magic_api * api)
|
||||
{
|
||||
printf("negative plugin initializing\n");
|
||||
}
|
||||
|
||||
int get_tool_count(void)
|
||||
{
|
||||
printf("negative tool reporting tool count: 1\n");
|
||||
return(1);
|
||||
}
|
||||
|
||||
SDL_Surface * get_icon(int which)
|
||||
// Only one tool:
|
||||
int negative_get_tool_count(magic_api * api)
|
||||
{
|
||||
printf("Loading icon: " DATA_PREFIX "/images/magic/negative.png\n");
|
||||
return(IMG_Load(DATA_PREFIX "/images/magic/negative.png"));
|
||||
return(1);
|
||||
}
|
||||
|
||||
char * get_name(int which)
|
||||
// Load our icon:
|
||||
SDL_Surface * negative_get_icon(magic_api * api, int which)
|
||||
{
|
||||
/* Only 1 tool; ignoring 'which' */
|
||||
char fname[1024];
|
||||
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/negative.png",
|
||||
api->data_directory);
|
||||
return(IMG_Load(fname));
|
||||
}
|
||||
|
||||
// Return our name, localized:
|
||||
char * negative_get_name(magic_api * api, int which)
|
||||
{
|
||||
return(strdup(gettext("Negative")));
|
||||
}
|
||||
|
||||
char * get_description(int which)
|
||||
// Return our description, localized:
|
||||
char * negative_get_description(magic_api * api, int which)
|
||||
{
|
||||
/* Only 1 tool; ignoring 'which' */
|
||||
|
||||
return(strdup(gettext("Click and move the mouse around to draw a negative.")));
|
||||
return(strdup(
|
||||
gettext("Click and move the mouse around to draw a negative.")));
|
||||
}
|
||||
|
||||
void drag(int which, SDL_Surface * canvas, SDL_Surface * last, int ox, int oy, int x, int y);
|
||||
|
||||
void click(int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y)
|
||||
{
|
||||
/*
|
||||
SDL_Rect src, dest;
|
||||
|
||||
src.x = x - 12;
|
||||
src.y = y - 12;
|
||||
src.w = 16;
|
||||
src.h = 16;
|
||||
|
||||
dest.x = x - 8;
|
||||
dest.y = y - 8;
|
||||
dest.w = 16;
|
||||
dest.h = 16;
|
||||
|
||||
SDL_BlitSurface(last, &src, canvas, &dest);
|
||||
*/
|
||||
|
||||
drag(which, canvas, last, x, y, x, y);
|
||||
}
|
||||
|
||||
void drag(int which, SDL_Surface * canvas, SDL_Surface * last, int ox, int oy, int x, int y)
|
||||
// Callback that does the negative color effect on a circle centered around x,y
|
||||
void do_negative(void * ptr, int which,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y)
|
||||
{
|
||||
int xx, yy;
|
||||
Uint8 r, g, b;
|
||||
void (*putpixel) (SDL_Surface *, int, int, Uint32) =
|
||||
MAGIC_putpixels[canvas->format->BytesPerPixel];
|
||||
Uint32(*getpixel_last) (SDL_Surface *, int, int);
|
||||
|
||||
getpixel_last = MAGIC_getpixels[last->format->BytesPerPixel];
|
||||
|
||||
|
||||
SDL_LockSurface(last);
|
||||
SDL_LockSurface(canvas);
|
||||
magic_api * api = (magic_api *) ptr;
|
||||
|
||||
for (yy = y - 16; yy < y + 16; yy++)
|
||||
{
|
||||
for (xx = x - 16; xx < x + 16; xx++)
|
||||
{
|
||||
if (MAGIC_in_circle(xx - x, yy - y, 16))
|
||||
if (api->in_circle(xx - x, yy - y, 16))
|
||||
{
|
||||
SDL_GetRGB(getpixel_last(last, xx, yy), last->format, &r, &g, &b);
|
||||
SDL_GetRGB(api->getpixel(last, xx, yy), last->format, &r, &g, &b);
|
||||
|
||||
r = 0xFF - r;
|
||||
g = 0xFF - g;
|
||||
b = 0xFF - b;
|
||||
|
||||
putpixel(canvas, xx, yy, SDL_MapRGB(canvas->format, r, g, b));
|
||||
api->putpixel(canvas, xx, yy, SDL_MapRGB(canvas->format, r, g, b));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Ask Tux Paint to call our 'do_negative()' callback over a line
|
||||
void negative_drag(magic_api * api, int which, SDL_Surface * canvas,
|
||||
SDL_Surface * last, int ox, int oy, int x, int y)
|
||||
{
|
||||
SDL_LockSurface(last);
|
||||
SDL_LockSurface(canvas);
|
||||
|
||||
api->line(which, canvas, last, ox, oy, x, y, 1, do_negative);
|
||||
|
||||
SDL_UnlockSurface(canvas);
|
||||
SDL_UnlockSurface(last);
|
||||
}
|
||||
|
||||
void shutdown()
|
||||
// Ask Tux Paint to call our 'do_negative()' callback at a single point
|
||||
void negative_click(magic_api * api, int which,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y)
|
||||
{
|
||||
printf("negative plugin shutting down\n");
|
||||
negative_drag(api, which, canvas, last, x, y, x, y);
|
||||
}
|
||||
|
||||
void set_color(Uint8 r, Uint8 g, Uint8 b)
|
||||
|
||||
// No setup happened:
|
||||
void negative_shutdown(magic_api * api)
|
||||
{
|
||||
/* Doesn't use color; ignoring */
|
||||
}
|
||||
|
||||
int requires_colors(int which)
|
||||
// We don't use colors
|
||||
void negative_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b)
|
||||
{
|
||||
/* (Only 1 tool; ignoring 'which') */
|
||||
|
||||
return 0; // Don't need a color palette
|
||||
}
|
||||
|
||||
// We don't use colors
|
||||
int negative_requires_colors(magic_api * api, int which)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue