Added TV & Rosette Magic tools.
This commit is contained in:
parent
1765e36292
commit
6c3893fd41
4 changed files with 344 additions and 1 deletions
|
|
@ -8,7 +8,7 @@ http://www.tuxpaint.org/
|
|||
|
||||
$Id$
|
||||
|
||||
2008.August.14 (0.9.21)
|
||||
2008.August.18 (0.9.21)
|
||||
* New Starters:
|
||||
-------------
|
||||
* Silver Frame
|
||||
|
|
@ -37,6 +37,8 @@ $Id$
|
|||
* + Confetti - Paints random confetti bits on the canvas.
|
||||
+ Fold - Folds the corners of the image up, like a piece of paper.
|
||||
+ Rails - Draws train tracks / rails over the image.
|
||||
+ TV - Adds television (CRT) interlacing lines over the image.
|
||||
+ Rosette - Paints at 3 points on the screen, in a rosette shape.
|
||||
By Adam 'foo-script' Rakowski <foo-script@o2.pl>
|
||||
(Part of Tux4Kids' participation in Google Summer of Code 2008)
|
||||
|
||||
|
|
|
|||
206
magic/src/rosette.c
Normal file
206
magic/src/rosette.c
Normal file
|
|
@ -0,0 +1,206 @@
|
|||
/*
|
||||
rosette.c
|
||||
|
||||
Rosette Magic Tools Plugin + Picasso Magic Tools Plugin
|
||||
Tux Paint - A simple drawing program for children.
|
||||
|
||||
Credits: Adam 'foo-script' Rakowski <foo-script@o2.pl>
|
||||
|
||||
Copyright (c) 2002-2008 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)
|
||||
*/
|
||||
|
||||
#include "tp_magic_api.h"
|
||||
#include "SDL_image.h"
|
||||
#include "SDL_mixer.h"
|
||||
#include <math.h> //for sin, cos, ...
|
||||
#define ROSETTE_R 8 //circle's diameter
|
||||
|
||||
static int xmid, ymid;
|
||||
|
||||
struct rosette_rgb
|
||||
{
|
||||
Uint8 r, g, b;
|
||||
};
|
||||
|
||||
struct rosette_rgb rosette_colors;
|
||||
|
||||
Mix_Chunk * rosette_snd;
|
||||
|
||||
// Housekeeping functions
|
||||
|
||||
void rosette_drag(magic_api * api, int which, SDL_Surface * canvas,
|
||||
SDL_Surface * snapshot, int ox, int oy, int x, int y,
|
||||
SDL_Rect * update_rect);
|
||||
|
||||
Uint32 rosette_api_version(void)
|
||||
{
|
||||
return(TP_MAGIC_API_VERSION);
|
||||
}
|
||||
|
||||
void rosette_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b) //get the colors from API and store it in structure
|
||||
{
|
||||
rosette_colors.r=r;
|
||||
rosette_colors.g=g;
|
||||
rosette_colors.b=b;
|
||||
}
|
||||
|
||||
int rosette_init(magic_api * api)
|
||||
{
|
||||
char fname[1024];
|
||||
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/rosette.wav", api->data_directory);
|
||||
rosette_snd = Mix_LoadWAV(fname);
|
||||
|
||||
return(1);
|
||||
}
|
||||
|
||||
int rosette_get_tool_count(magic_api * api)
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
SDL_Surface * rosette_get_icon(magic_api * api, int which)
|
||||
{
|
||||
char fname[1024];
|
||||
|
||||
if (!which)
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/rosette.png", api->data_directory);
|
||||
else snprintf(fname, sizeof(fname), "%s/images/magic/picasso.png", api->data_directory);
|
||||
|
||||
return(IMG_Load(fname));
|
||||
}
|
||||
|
||||
char * rosette_get_name(magic_api * api, int which) { if (!which) return strdup(gettext_noop("Rosette")); else return strdup(gettext_noop("Picasso"));}
|
||||
|
||||
char * rosette_get_description(magic_api * api, int which, int mode)
|
||||
{
|
||||
if (!which)
|
||||
return strdup(gettext_noop("Click and start drawing your rosette"));
|
||||
else
|
||||
return strdup(gettext_noop("You can draw just like Picasso!"));
|
||||
}
|
||||
|
||||
int rosette_requires_colors(magic_api * api, int which) { return 1; }
|
||||
|
||||
void rosette_release(magic_api * api, int which,
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot,
|
||||
int x, int y, SDL_Rect * update_rect)
|
||||
{
|
||||
api->playsound(rosette_snd, (x * 255) / canvas->w, 255);
|
||||
}
|
||||
|
||||
void rosette_shutdown(magic_api * api)
|
||||
{ Mix_FreeChunk(rosette_snd); }
|
||||
|
||||
// Interactivity functions
|
||||
|
||||
void rosette_circle(void * ptr, int which,
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot,
|
||||
int x, int y)
|
||||
{
|
||||
magic_api * api = (magic_api *) ptr;
|
||||
|
||||
int xx, yy;
|
||||
|
||||
for (yy = y - ROSETTE_R; yy < y + ROSETTE_R; yy++)
|
||||
for (xx = x - ROSETTE_R; xx < x + ROSETTE_R; xx++)
|
||||
if (api->in_circle(xx - x , yy - y , ROSETTE_R/2))
|
||||
api->putpixel(canvas, xx, yy, SDL_MapRGB(canvas->format, rosette_colors.r, rosette_colors.g, rosette_colors.b));
|
||||
|
||||
}
|
||||
|
||||
void rosette_draw(void * ptr, int which, SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y)
|
||||
{
|
||||
magic_api * api = (magic_api *) ptr;
|
||||
|
||||
double angle, angle_ph;
|
||||
double xx, yy; //distance to the center of the image
|
||||
int x1, y1, x2, y2;
|
||||
|
||||
xx=(double)(xmid-x);
|
||||
yy=(double)(y-ymid);
|
||||
|
||||
if (which==0)
|
||||
{
|
||||
angle=2*M_PI/3; //an angle between brushes
|
||||
|
||||
x1=(int)(xx*cos(angle)-yy*sin(angle));
|
||||
y1=(int)(xx*sin(angle)+yy*cos(angle));
|
||||
|
||||
x2=(int)(xx*cos(2*angle)-yy*sin(2*angle));
|
||||
y2=(int)(xx*sin(2*angle)+yy*cos(2*angle));
|
||||
}
|
||||
else
|
||||
{
|
||||
angle=atan(yy/xx);
|
||||
|
||||
if ((xx<0) && (yy>0)) angle+=M_PI;
|
||||
|
||||
if ((xx<0) && (yy<0)) angle+=M_PI;
|
||||
|
||||
if ((xx>0) && (yy<0)) angle+=2*M_PI;
|
||||
|
||||
if ((y==ymid) && (xx<0)) angle=M_PI;
|
||||
|
||||
x1=(int)(xx*cos(2*angle)-yy*sin(2*angle));
|
||||
y1=(int)(xx*sin(2*angle)-yy*cos(angle));
|
||||
|
||||
x2=(int)(xx*cos(2*angle)-yy*sin(2*angle));
|
||||
y2=(int)(xx*sin(2*angle)+yy*cos(2*angle));
|
||||
}
|
||||
|
||||
rosette_circle(api, which, canvas, snapshot, x, y);
|
||||
rosette_circle(api, which, canvas, snapshot, (-1)*(x1-xmid), y1+ymid);
|
||||
rosette_circle(api, which, canvas, snapshot, (-1)*(x2-xmid), y2+ymid);
|
||||
}
|
||||
|
||||
void rosette_drag(magic_api * api, int which, SDL_Surface * canvas,
|
||||
SDL_Surface * snapshot, int ox, int oy, int x, int y,
|
||||
SDL_Rect * update_rect)
|
||||
{
|
||||
api->line((void *) api, which, canvas, snapshot, ox, oy, x, y, 1, rosette_draw);
|
||||
|
||||
update_rect->x=update_rect->y=0;
|
||||
update_rect->w=canvas->w;
|
||||
update_rect->h=canvas->h;
|
||||
}
|
||||
|
||||
void rosette_click(magic_api * api, int which, int mode,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y, SDL_Rect * update_rect)
|
||||
{
|
||||
rosette_drag(api, which, canvas, last, x, y, x, y, update_rect);
|
||||
}
|
||||
|
||||
void rosette_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas)
|
||||
{
|
||||
xmid=canvas->w/2;
|
||||
ymid=canvas->h/2;
|
||||
}
|
||||
|
||||
void rosette_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
int rosette_modes(magic_api * api, int which)
|
||||
{
|
||||
return(MODE_PAINT);
|
||||
}
|
||||
133
magic/src/tv.c
Normal file
133
magic/src/tv.c
Normal file
|
|
@ -0,0 +1,133 @@
|
|||
/*
|
||||
tv.c
|
||||
|
||||
TV Magic Tools Plugin
|
||||
Tux Paint - A simple drawing program for children.
|
||||
|
||||
Credits: Adam 'foo-script' Rakowski <foo-script@o2.pl>
|
||||
|
||||
Copyright (c) 2002-2008 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)
|
||||
*/
|
||||
|
||||
#include "tp_magic_api.h"
|
||||
#include "SDL_image.h"
|
||||
#include "SDL_mixer.h"
|
||||
|
||||
Mix_Chunk * tv_snd;
|
||||
|
||||
// Housekeeping functions
|
||||
|
||||
Uint32 tv_api_version(void)
|
||||
{
|
||||
return(TP_MAGIC_API_VERSION);
|
||||
}
|
||||
|
||||
void tv_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b) //get the colors from API and store it in structure
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
int tv_init(magic_api * api)
|
||||
{
|
||||
char fname[1024];
|
||||
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/tv.wav", api->data_directory);
|
||||
tv_snd = Mix_LoadWAV(fname);
|
||||
|
||||
return(1);
|
||||
}
|
||||
|
||||
int tv_get_tool_count(magic_api * api)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
SDL_Surface * tv_get_icon(magic_api * api, int which)
|
||||
{
|
||||
char fname[1024];
|
||||
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/tv.png",
|
||||
api->data_directory);
|
||||
|
||||
return(IMG_Load(fname));
|
||||
}
|
||||
|
||||
char * tv_get_name(magic_api * api, int which) { return strdup(gettext_noop("TV")); }
|
||||
|
||||
char * tv_get_description(magic_api * api, int which, int mode) { return strdup(gettext_noop("Your picture will look like in television")); }
|
||||
|
||||
int tv_requires_colors(magic_api * api, int which) { return 0; }
|
||||
|
||||
void tv_release(magic_api * api, int which,
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot,
|
||||
int x, int y, SDL_Rect * update_rect)
|
||||
{
|
||||
api->playsound(tv_snd, x * 255,255);
|
||||
}
|
||||
|
||||
void tv_shutdown(magic_api * api)
|
||||
{ Mix_FreeChunk(tv_snd); }
|
||||
|
||||
// Interactivity functions
|
||||
|
||||
void tv_do_tv(void * ptr_to_api, int which_tool,
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y)
|
||||
{
|
||||
magic_api * api = (magic_api *) ptr_to_api;
|
||||
|
||||
api->putpixel(canvas, x, y, SDL_MapRGB(canvas->format, 128, 128, 165));
|
||||
//api->putpixel(canvas, x, y, SDL_MapRGB(canvas->format, 0, 0, 255));
|
||||
}
|
||||
|
||||
void tv_drag(magic_api * api, int which, SDL_Surface * canvas,
|
||||
SDL_Surface * snapshot, int ox, int oy, int x, int y,
|
||||
SDL_Rect * update_rect)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i=0; i<canvas->h; i+=2)
|
||||
api->line(api, which, canvas, snapshot, 0, i, canvas->w, i, 1, tv_do_tv);
|
||||
|
||||
update_rect->w=canvas->w;
|
||||
update_rect->h=canvas->h;
|
||||
update_rect->x=update_rect->y=0;
|
||||
}
|
||||
|
||||
void tv_click(magic_api * api, int which, int mode,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y, SDL_Rect * update_rect)
|
||||
{
|
||||
tv_drag(api, which, canvas, last, x, y, x, y, update_rect);
|
||||
}
|
||||
|
||||
void tv_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void tv_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
int tv_modes(magic_api * api, int which)
|
||||
{
|
||||
return(MODE_FULLSCREEN);
|
||||
}
|
||||
|
|
@ -36,10 +36,12 @@ tuxpaint.desktop.in
|
|||
../magic/src/rain.c
|
||||
../magic/src/rainbow.c
|
||||
../magic/src/ripples.c
|
||||
../magic/src/rosette.c
|
||||
../magic/src/sharpen.c
|
||||
../magic/src/shift.c
|
||||
../magic/src/smudge.c
|
||||
../magic/src/snow.c
|
||||
../magic/src/tint.c
|
||||
../magic/src/tv.c
|
||||
../magic/src/toothpaste.c
|
||||
../magic/src/waves.c
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue