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
|
|
@ -1,35 +1,40 @@
|
|||
# Makefile for magic plugins
|
||||
|
||||
SDL_CFLAGS=$(shell sdl-config --cflags)
|
||||
CFLAGS=-g -Wall $(SDL_CFLAGS) -DDATA_PREFIX=\"$(DATA_PREFIX)\"
|
||||
#-fPIC ?
|
||||
# Places to pick up Tux Paint Magic Plugin Dev header and SDL headers
|
||||
# (can't assume plugin dev stuff has been installed yet, since we're
|
||||
# part of Tux Paint base, so "install-plugin-dev" probably hasn't
|
||||
# been run yet; hence "-I../src/" to find 'tp_magic_api.h')
|
||||
|
||||
all: negative.so
|
||||
SO_TYPE=so
|
||||
|
||||
TP_MAGIC_CFLAGS=$(shell sdl-config --cflags) \
|
||||
-I../src/ \
|
||||
$(shell tp-magic-config --cflags)
|
||||
CFLAGS=-g -Wall $(TP_MAGIC_CFLAGS)
|
||||
|
||||
|
||||
all: negative.$(SO_TYPE) \
|
||||
fade_darken.$(SO_TYPE) \
|
||||
mirror_flip.$(SO_TYPE) \
|
||||
|
||||
clean:
|
||||
@echo
|
||||
@echo "Cleaning up the Magic plug-ins directory ($(PWD))"
|
||||
@-rm -f *.so
|
||||
@-rm -f obj/*
|
||||
@-rm -f *.$(SO_TYPE)
|
||||
|
||||
|
||||
# Negative tool
|
||||
# ------------------------------------------------------------------------
|
||||
# Shared objects:
|
||||
# ---------------
|
||||
|
||||
negative.so: obj obj/negative.o obj/magic_helpers.o
|
||||
@echo "Linking Negative magic tool"
|
||||
@$(CC) -shared -o negative.so obj/negative.o obj/magic_helpers.o
|
||||
negative.$(SO_TYPE): src/negative.c
|
||||
@echo "Building Negative magic tool"
|
||||
@$(CC) $(CFLAGS) -shared -o negative.$(SO_TYPE) src/negative.c
|
||||
|
||||
obj/negative.o: src/negative.c src/magic_helpers.h
|
||||
@echo "Compiling Negative magic tool"
|
||||
@$(CC) $(CFLAGS) src/negative.c -c -o obj/negative.o
|
||||
fade_darken.$(SO_TYPE): src/fade_darken.c
|
||||
@echo "Building Fade and Darken magic tools"
|
||||
@$(CC) $(CFLAGS) -shared -o fade_darken.$(SO_TYPE) src/fade_darken.c
|
||||
|
||||
|
||||
|
||||
obj/magic_helpers.o: src/magic_helpers.c src/magic_helpers.h
|
||||
@echo "Compiling Magic tool helper routines"
|
||||
@$(CC) $(CFLAGS) src/magic_helpers.c -c -o obj/magic_helpers.o
|
||||
|
||||
obj:
|
||||
@-mkdir obj
|
||||
mirror_flip.$(SO_TYPE): src/mirror_flip.c
|
||||
@echo "Building Mirror and Flip magic tools"
|
||||
@$(CC) $(CFLAGS) -shared -o mirror_flip.$(SO_TYPE) src/mirror_flip.c
|
||||
|
||||
|
|
|
|||
131
magic/docs/README.txt
Normal file
131
magic/docs/README.txt
Normal file
|
|
@ -0,0 +1,131 @@
|
|||
Stub docs for Tux Paint Magic Plugin Development
|
||||
|
||||
#include "tp_magic_api.h"
|
||||
|
||||
|
||||
build plugins with:
|
||||
-------------------
|
||||
Linux/Unix:
|
||||
-----------
|
||||
$(CC) -shared `tp-magic-config --cflags` plugin.c -o plugin.so
|
||||
|
||||
Then install globally into: /usr/[local/]lib/tuxpaint/.
|
||||
Or locally into: ~/.tuxpaint/magic/ [[FIXME]]
|
||||
|
||||
Windows:
|
||||
--------
|
||||
??? [[FIXME]]
|
||||
|
||||
Mac OS X:
|
||||
---------
|
||||
??? [[FIXME]]
|
||||
|
||||
|
||||
magic plugins must provide:
|
||||
---------------------------
|
||||
NOTE: Each function name should be preceded with the name of the
|
||||
shared object file, e.g. "negative.so" or "negative.dll" would have
|
||||
a function called "negative_init()".
|
||||
|
||||
int get_tool_count(magic_api * api)
|
||||
return the number of Magic tools this plugin provides
|
||||
(used below as the 'which' values sent to each function)
|
||||
|
||||
char * get_name(magic_api * api, int which)
|
||||
return the name of a/the magic tool (for 'Magic' tool buttons in UI)
|
||||
Tux Paint will free() the string;
|
||||
example:
|
||||
return (strdup(gettext("Fun")));
|
||||
|
||||
SDL_Surface * get_icon(magic_api * api, int which)
|
||||
return the icon of a/the magic tool (for 'Magic' tool buttons in UI)
|
||||
Tux Paint will SDL_FreeSurface() the surface:
|
||||
example:
|
||||
sprintf(fname, "%s/images/magic/funtool.png", api->data_directory);
|
||||
return(IMG_Load(fname));
|
||||
|
||||
char * get_description(magic_api * api, int which)
|
||||
return the description of a/the magic tool (for Tux help text in UI);
|
||||
Tux Paint will free() the string;
|
||||
example:
|
||||
return (strdup(gettext("A fun tool")));
|
||||
|
||||
int requires_colors(magic_api * api, int which)
|
||||
return whether a/the magic tool accepts colors
|
||||
('1' for true; activates color palette in UI;
|
||||
'0' for false; disables color palette in UI)
|
||||
|
||||
void set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 g)
|
||||
accept the color palette choice from Tux Paint
|
||||
(only called if requires_colors() for the current tool returned true)
|
||||
|
||||
int init(magic_api * api)
|
||||
initialization function; called once, during Tux Paint startup
|
||||
return 1 if success;
|
||||
return 0 if failure (tool(s) will be disabled in Magic tool);
|
||||
|
||||
void shutdown(magic_api * api)
|
||||
cleanup function; should free any alloc'd memory, etc.;
|
||||
happens once, at Tux Paint shutdown
|
||||
|
||||
void click(magic_api * api, int which,
|
||||
SDL_Surface * snapshot, SDL_Surface * canvas,
|
||||
int x, int y)
|
||||
should affect 'canvas' at (x,y) location; may use 'snapshot' to fetch
|
||||
pixels from most recent undo buffer;
|
||||
Tux Paint's undo buffer is updated prior to this call
|
||||
|
||||
void drag(magic_api * api, int which,
|
||||
SDL_Surface * snapshot, SDL_Surface * canvas,
|
||||
int ox, int oy, int x, int y)
|
||||
should affect 'canvas' between (ox,oy) and (x,y) locations;
|
||||
may use 'snapshot' to fetch pixels from most recent undo buffer;
|
||||
Tux Paint's undo buffer is NOT updated prior to this call; the
|
||||
'snapshot' buffer will contain the same contents as when click() was
|
||||
last called
|
||||
|
||||
|
||||
tp provides, via magic_api structure ("api" arg to magic tool functions):
|
||||
-------------------------------------------------------------------------
|
||||
void putpixel(SDL_Surface * surf, int x, int y, Uint32 pixel)
|
||||
function that puts a pixel at an (x,y) position in a surface
|
||||
|
||||
Uint32 getpixel(SDL_Surface * surf, int x, int y)
|
||||
function that returns a pixel value from an (x,y) position on a surface
|
||||
|
||||
int in_circle(int x, int y, int radius)
|
||||
function that returns whether an x/y position (centered at (0,0)) is
|
||||
within a circle of 'radius'
|
||||
|
||||
void show_progress_bar(void)
|
||||
draws the Tux Paint progress bar animation; use while you're busy
|
||||
|
||||
void tuxpaint_version(int * major, int * minor, int * revision)
|
||||
returns the version of Tux Paint being used
|
||||
|
||||
void line(int which, SDL_Surface * canvas, SDL_Surface * snapshot,
|
||||
int x1, int y1, int x2, int y2, int step, FUNC callback)
|
||||
function that calls calculates a line between (x1,y1) and (x2,y2)
|
||||
and calls 'callback' every 'step' iterations;
|
||||
sends to the callback: Tux Paint's 'magic_api' structure, along with the
|
||||
'which', 'canvas' and 'snapshot' values sent to line(), and the (x,y)
|
||||
coordinates
|
||||
|
||||
|
||||
FIXME: Implement these:
|
||||
|
||||
void playsound(Mix_Chunk * snd, int pan, int dist)
|
||||
function that plays a sound, panned left/right 'pan'
|
||||
and at distance 'dist'. pan may be SNDPOS_LEFT, SNDPOS_CENTER or
|
||||
SNDPOS_RIGHT, and dist may be SNDDIST_NEAR.
|
||||
|
||||
void special_notify(int flag)
|
||||
notifies tux paint of special events; SPECIAL_FLIP and SPECIAL_MIRROR
|
||||
flags may be sent
|
||||
|
||||
float sRGB_to_linear_table[256]
|
||||
sRGB-to-linear look-up table
|
||||
|
||||
unsigned char linear_to_sRGB(float linear)
|
||||
linear-to-sRGB look-up helper function
|
||||
|
||||
BIN
magic/sounds/blur.wav
Normal file
BIN
magic/sounds/blur.wav
Normal file
Binary file not shown.
BIN
magic/sounds/brick.wav
Normal file
BIN
magic/sounds/brick.wav
Normal file
Binary file not shown.
BIN
magic/sounds/cartoon.wav
Normal file
BIN
magic/sounds/cartoon.wav
Normal file
Binary file not shown.
BIN
magic/sounds/chalk.wav
Normal file
BIN
magic/sounds/chalk.wav
Normal file
Binary file not shown.
BIN
magic/sounds/darken.wav
Normal file
BIN
magic/sounds/darken.wav
Normal file
Binary file not shown.
BIN
magic/sounds/drip.wav
Normal file
BIN
magic/sounds/drip.wav
Normal file
Binary file not shown.
BIN
magic/sounds/fade.wav
Normal file
BIN
magic/sounds/fade.wav
Normal file
Binary file not shown.
BIN
magic/sounds/flip.wav
Normal file
BIN
magic/sounds/flip.wav
Normal file
Binary file not shown.
BIN
magic/sounds/grass.wav
Normal file
BIN
magic/sounds/grass.wav
Normal file
Binary file not shown.
BIN
magic/sounds/mirror.wav
Normal file
BIN
magic/sounds/mirror.wav
Normal file
Binary file not shown.
BIN
magic/sounds/negative.wav
Normal file
BIN
magic/sounds/negative.wav
Normal file
Binary file not shown.
BIN
magic/sounds/rainbow.wav
Normal file
BIN
magic/sounds/rainbow.wav
Normal file
Binary file not shown.
BIN
magic/sounds/smudge.wav
Normal file
BIN
magic/sounds/smudge.wav
Normal file
Binary file not shown.
BIN
magic/sounds/sparkles1.wav
Normal file
BIN
magic/sounds/sparkles1.wav
Normal file
Binary file not shown.
BIN
magic/sounds/sparkles2.wav
Normal file
BIN
magic/sounds/sparkles2.wav
Normal file
Binary file not shown.
BIN
magic/sounds/thick.wav
Normal file
BIN
magic/sounds/thick.wav
Normal file
Binary file not shown.
BIN
magic/sounds/thin.wav
Normal file
BIN
magic/sounds/thin.wav
Normal file
Binary file not shown.
BIN
magic/sounds/tint.wav
Normal file
BIN
magic/sounds/tint.wav
Normal file
Binary file not shown.
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