Added alien magic tool. Added missing description text for some magic tools.
This commit is contained in:
parent
fd65f98abc
commit
d0d5e16b00
9 changed files with 257 additions and 16 deletions
|
|
@ -46,7 +46,7 @@ $Id$
|
|||
implied warranty.
|
||||
|
||||
Blur ('entire image' mode), Sharpen, Trace Contour, Silhouette,
|
||||
Snow Flake, Snow Ball, Black & White, Threshold,
|
||||
Snow Flake, Snow Ball, Black & White, Threshold, Alien,
|
||||
Tint ('Brush' mode), Noise, Rain and Mosaic Magic Tools.
|
||||
Jigsaw 3x3 and Jigsaw 5x5 starter images.
|
||||
by Andrew 'akanewbie' Corcoran <akanewbie@gmail.com>
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ $Id$
|
|||
* New Magic Tools:
|
||||
----------------
|
||||
* + Blur (entire image mode) - Blurs entire image
|
||||
+ Alien - Modifies the colours in the image to give an "alien" apperance.
|
||||
+ Sharpen - Sharpens entire image
|
||||
+ Trace Contour - Traces the edges of the image, over a white background.
|
||||
+ Silhouette - Creates an outline of the image, over a black background.
|
||||
|
|
|
|||
237
magic/src/alien.c
Normal file
237
magic/src/alien.c
Normal file
|
|
@ -0,0 +1,237 @@
|
|||
/*
|
||||
alien.c
|
||||
|
||||
alien, Modifies the colours of the image.
|
||||
Tux Paint - A simple drawing program for children.
|
||||
|
||||
Credits: Andrew Corcoran <akanewbie@gmail.com> inspired by the Alien Map GIMP plugin
|
||||
|
||||
Copyright (c) 2002-2007 by Bill Kendrick and others; see AUTHORS.txt
|
||||
bill@newbreedsoftware.com
|
||||
http://www.tuxpaint.org/
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
(See COPYING.txt)
|
||||
|
||||
Last updated: June 6, 2008
|
||||
$Id$
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <libintl.h>
|
||||
#include "tp_magic_api.h"
|
||||
#include "SDL_image.h"
|
||||
#include "SDL_mixer.h"
|
||||
#include <math.h>
|
||||
#include <limits.h>
|
||||
#include <time.h>
|
||||
|
||||
#ifndef gettext_noop
|
||||
#define gettext_noop(String) String
|
||||
#endif
|
||||
|
||||
static const double alien_ANGLE[] = {0,0,0};
|
||||
static const double alien_FREQUENCY[] = {1,1,1};
|
||||
static const int alien_RADIUS = 16;
|
||||
|
||||
enum {
|
||||
TOOL_alien,
|
||||
alien_NUM_TOOLS
|
||||
};
|
||||
|
||||
static Mix_Chunk * alien_snd_effect[alien_NUM_TOOLS];
|
||||
|
||||
const char * alien_snd_filenames[alien_NUM_TOOLS] = {
|
||||
"flip.wav",
|
||||
};
|
||||
const char * alien_icon_filenames[alien_NUM_TOOLS] = {
|
||||
"flip.png",
|
||||
};
|
||||
const char * alien_names[alien_NUM_TOOLS] = {
|
||||
gettext_noop("Alien"),
|
||||
};
|
||||
const char * alien_descs[alien_NUM_TOOLS][2] = {
|
||||
{gettext_noop("Click and move the mouse to give the image an \"alien\" appearance."),
|
||||
gettext_noop("Click to give the entire image an \"alien\" appearance."),},
|
||||
};
|
||||
|
||||
Uint32 alien_api_version(void) { return(TP_MAGIC_API_VERSION); }
|
||||
|
||||
//Load sounds
|
||||
int alien_init(magic_api * api){
|
||||
srand(time(0));
|
||||
|
||||
int i;
|
||||
char fname[1024];
|
||||
|
||||
for (i = 0; i < alien_NUM_TOOLS; i++){
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/%s", api->data_directory, alien_snd_filenames[i]);
|
||||
alien_snd_effect[i] = Mix_LoadWAV(fname);
|
||||
if (alien_snd_effect[i]==NULL){
|
||||
return(0);
|
||||
}
|
||||
}
|
||||
return(1);
|
||||
}
|
||||
|
||||
int alien_get_tool_count(magic_api * api){
|
||||
return(alien_NUM_TOOLS);
|
||||
}
|
||||
|
||||
// Load our icons:
|
||||
SDL_Surface * alien_get_icon(magic_api * api, int which){
|
||||
char fname[1024];
|
||||
snprintf(fname, sizeof(fname), "%simages/magic/%s", api->data_directory, alien_icon_filenames[which]);
|
||||
return(IMG_Load(fname));
|
||||
}
|
||||
|
||||
// Return our names, localized:
|
||||
char * alien_get_name(magic_api * api, int which){
|
||||
return(strdup(gettext(alien_names[which])));
|
||||
}
|
||||
|
||||
// Return our descriptions, localized:
|
||||
char * alien_get_description(magic_api * api, int which, int mode){
|
||||
return(strdup(gettext(alien_descs[which][mode-1])));
|
||||
}
|
||||
|
||||
//Do the effect for one pixel
|
||||
static void do_alien_pixel(void * ptr, int which,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y){
|
||||
magic_api * api = (magic_api *) ptr;
|
||||
|
||||
Uint8 temp[3];
|
||||
double temp2[3];
|
||||
|
||||
SDL_GetRGB(api->getpixel(canvas,x, y), canvas->format, &temp[0], &temp[1], &temp[2]);
|
||||
int k;
|
||||
for (k =0;k<3;k++){
|
||||
temp2[k] = clamp(0,127.5 * (1.0 + sin (((temp[k] / 127.5 - 1.0) * alien_FREQUENCY[k] + alien_ANGLE[k] / 180.0) * M_PI)),255);
|
||||
}
|
||||
api->putpixel(canvas, x, y, SDL_MapRGB(canvas->format, temp2[0], temp2[1], temp2[2]));
|
||||
|
||||
}
|
||||
|
||||
// Do the effect for the full image
|
||||
static void do_alien_full(void * ptr,SDL_Surface * canvas, SDL_Surface * last, int which){
|
||||
|
||||
magic_api * api = (magic_api *) ptr;
|
||||
|
||||
int x,y;
|
||||
|
||||
for (y = 0; y < last->h; y++){
|
||||
for (x=0; x < last->w; x++){
|
||||
do_alien_pixel(ptr, which, canvas, last, x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//do the effect for the brush
|
||||
static void do_alien_brush(void * ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y){
|
||||
int xx, yy;
|
||||
magic_api * api = (magic_api *) ptr;
|
||||
|
||||
for (yy = y - alien_RADIUS; yy < y + alien_RADIUS; yy++)
|
||||
{
|
||||
for (xx = x - alien_RADIUS; xx < x + alien_RADIUS; xx++)
|
||||
{
|
||||
if (api->in_circle(xx - x, yy - y, alien_RADIUS) &&
|
||||
!api->touched(xx, yy))
|
||||
{
|
||||
do_alien_pixel(api, which, canvas, last, xx, yy);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Affect the canvas on drag:
|
||||
void alien_drag(magic_api * api, int which, SDL_Surface * canvas,
|
||||
SDL_Surface * last, int ox, int oy, int x, int y,
|
||||
SDL_Rect * update_rect){
|
||||
|
||||
api->line((void *) api, which, canvas, last, ox, oy, x, y, 1, do_alien_brush);
|
||||
|
||||
api->playsound(alien_snd_effect[which], (x * 255) / canvas->w, 255);
|
||||
|
||||
if (ox > x) { int tmp = ox; ox = x; x = tmp; }
|
||||
if (oy > y) { int tmp = oy; oy = y; y = tmp; }
|
||||
|
||||
update_rect->x = ox - alien_RADIUS;
|
||||
update_rect->y = oy - alien_RADIUS;
|
||||
update_rect->w = (x + alien_RADIUS) - update_rect->x;
|
||||
update_rect->h = (y + alien_RADIUS) - update_rect->y;
|
||||
}
|
||||
|
||||
// Affect the canvas on click:
|
||||
void alien_click(magic_api * api, int which, int mode,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y, SDL_Rect * update_rect){
|
||||
if (mode == MODE_PAINT)
|
||||
alien_drag(api, which, canvas, last, x, y, x, y, update_rect);
|
||||
else{
|
||||
update_rect->x = 0;
|
||||
update_rect->y = 0;
|
||||
update_rect->w = canvas->w;
|
||||
update_rect->h = canvas->h;
|
||||
do_alien_full(api, canvas, last, which);
|
||||
api->playsound(alien_snd_effect[which], 128, 255);
|
||||
}
|
||||
}
|
||||
|
||||
// Affect the canvas on release:
|
||||
void alien_release(magic_api * api, int which,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y, SDL_Rect * update_rect)
|
||||
{
|
||||
}
|
||||
|
||||
// No setup happened:
|
||||
void alien_shutdown(magic_api * api)
|
||||
{
|
||||
//Clean up sounds
|
||||
int i;
|
||||
for(i=0; i<alien_NUM_TOOLS; i++){
|
||||
if(alien_snd_effect[i] != NULL){
|
||||
Mix_FreeChunk(alien_snd_effect[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Record the color from Tux Paint:
|
||||
void alien_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b)
|
||||
{
|
||||
}
|
||||
|
||||
// Use colors:
|
||||
int alien_requires_colors(magic_api * api, int which)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void alien_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas)
|
||||
{
|
||||
}
|
||||
|
||||
void alien_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas)
|
||||
{
|
||||
}
|
||||
|
||||
int alien_modes(magic_api * api, int which)
|
||||
{
|
||||
return(MODE_FULLSCREEN|MODE_PAINT);
|
||||
}
|
||||
|
||||
|
|
@ -57,7 +57,8 @@ const char * blur_names[blur_NUM_TOOLS] = {
|
|||
gettext_noop("Blur"),
|
||||
};
|
||||
const char * blur_descs[blur_NUM_TOOLS][2] = {
|
||||
{gettext_noop("Click and move the mouse around to blur the image."), gettext_noop("Click to blur the whole image.")},
|
||||
{gettext_noop("Click and move the mouse around to blur the image."),
|
||||
gettext_noop("Click to blur the entire image.")},
|
||||
};
|
||||
|
||||
Uint32 blur_api_version(void) { return(TP_MAGIC_API_VERSION); }
|
||||
|
|
|
|||
|
|
@ -70,8 +70,9 @@ const char * mosaic_icon_filenames[mosaic_NUM_TOOLS] = {
|
|||
const char * mosaic_names[mosaic_NUM_TOOLS] = {
|
||||
gettext_noop("Mosaic"),
|
||||
};
|
||||
const char * mosaic_descs[mosaic_NUM_TOOLS] = {
|
||||
gettext_noop("Click to add a mosaic effect to the image."),
|
||||
const char * mosaic_descs[mosaic_NUM_TOOLS][2] = {
|
||||
{gettext_noop("Click and move the mouse to add a mosaic effect to the image."),
|
||||
gettext_noop("Click to add a mosaic effect to the entire image."),},
|
||||
};
|
||||
|
||||
Uint32 mosaic_api_version(void) { return(TP_MAGIC_API_VERSION); }
|
||||
|
|
@ -110,8 +111,8 @@ char * mosaic_get_name(magic_api * api, int which){
|
|||
}
|
||||
|
||||
// Return our descriptions, localized:
|
||||
char * mosaic_get_description(magic_api * api, int which){
|
||||
return(strdup(gettext(mosaic_descs[which])));
|
||||
char * mosaic_get_description(magic_api * api, int which, int mode){
|
||||
return(strdup(gettext(mosaic_descs[which][mode-1])));
|
||||
}
|
||||
|
||||
//Calculates the grey scale value for a rgb pixel
|
||||
|
|
|
|||
|
|
@ -62,8 +62,9 @@ const char * noise_icon_filenames[noise_NUM_TOOLS] = {
|
|||
const char * noise_names[noise_NUM_TOOLS] = {
|
||||
gettext_noop("Noise"),
|
||||
};
|
||||
const char * noise_descs[noise_NUM_TOOLS] = {
|
||||
gettext_noop("Click to add noise to the image."),
|
||||
const char * noise_descs[noise_NUM_TOOLS][2] = {
|
||||
{gettext_noop("Click and move the mouse to add noise to the image."),
|
||||
gettext_noop("Click to add noise to the entire image."),},
|
||||
};
|
||||
|
||||
Uint32 noise_api_version(void) { return(TP_MAGIC_API_VERSION); }
|
||||
|
|
@ -102,8 +103,8 @@ char * noise_get_name(magic_api * api, int which){
|
|||
}
|
||||
|
||||
// Return our descriptions, localized:
|
||||
char * noise_get_description(magic_api * api, int which){
|
||||
return(strdup(gettext(noise_descs[which])));
|
||||
char * noise_get_description(magic_api * api, int which, int mode){
|
||||
return(strdup(gettext(noise_descs[which][mode-1])));
|
||||
}
|
||||
|
||||
//Do the effect for one pixel
|
||||
|
|
|
|||
|
|
@ -78,9 +78,9 @@ const char * sharpen_descs[sharpen_NUM_TOOLS][2] = {
|
|||
{gettext_noop("Click and move the mouse to trace the edges of objects in the image."),
|
||||
gettext_noop("Click to trace the edges of objects in the image."),},
|
||||
{gettext_noop("Click and move the mouse to sharpen the image."),
|
||||
gettext_noop("Click to sharpen the image."),},
|
||||
gettext_noop("Click to sharpen the entire image."),},
|
||||
{gettext_noop("Click and move the mouse to create a black and white silhouette of the image."),
|
||||
gettext_noop("Click to create a black and white silhouette of the image.")},
|
||||
gettext_noop("Click to create a black and white silhouette of the entire image.")},
|
||||
};
|
||||
|
||||
Uint32 sharpen_api_version(void) { return(TP_MAGIC_API_VERSION); }
|
||||
|
|
|
|||
|
|
@ -69,8 +69,8 @@ const char * snow_names[snow_NUM_TOOLS] = {
|
|||
gettext_noop("Snow Flake"),
|
||||
};
|
||||
const char * snow_descs[snow_NUM_TOOLS] = {
|
||||
gettext_noop("Click to add snow to the image."),
|
||||
gettext_noop("Click to add snow to the image."),
|
||||
gettext_noop("Click to add snow to the entire image."),
|
||||
gettext_noop("Click to add snow to the entire image."),
|
||||
};
|
||||
|
||||
Uint32 snow_api_version(void) { return(TP_MAGIC_API_VERSION); }
|
||||
|
|
|
|||
|
|
@ -69,9 +69,9 @@ const char * tint_names[tint_NUM_TOOLS] = {
|
|||
};
|
||||
const char * tint_descs[tint_NUM_TOOLS][2] = {
|
||||
{gettext_noop("Click and move the mouse around to change the color of parts of the picture."),
|
||||
gettext_noop("Click to change the entire picture’s color."),},
|
||||
gettext_noop("Click to change the colour of the entire image."),},
|
||||
{gettext_noop("Click and move the mouse around to threshold the image into pure colour and white regions."),
|
||||
gettext_noop("Click to threshold the image into pure colour and white regions.")}
|
||||
gettext_noop("Click to threshold the entire image into pure colour and white regions.")}
|
||||
};
|
||||
|
||||
Uint32 tint_api_version(void) { return(TP_MAGIC_API_VERSION); }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue