Merge branch 'master' into sdl2.0

Merging master 2019-september-24 into sdl2.0 branch
This commit is contained in:
Pere Pujal i Carabantes 2019-09-24 14:52:40 +02:00
commit a1c778135d
52 changed files with 921 additions and 803 deletions

View file

@ -1,12 +1,12 @@
/*
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
Copyright (c) 2002-2019 by Bill Kendrick and others; see AUTHORS.txt
bill@newbreedsoftware.com
http://www.tuxpaint.org/
@ -25,7 +25,7 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
(See COPYING.txt)
Last updated: June 6, 2008
Last updated: August 29, 2019
$Id$
*/
@ -168,9 +168,6 @@ static void do_alien_pixel(void *ptr, int which ATTRIBUTE_UNUSED,
// 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++)

View file

@ -4,7 +4,7 @@
Calligraphy Magic Tool Plugin
Tux Paint - A simple drawing program for children.
Copyright (c) 2002-2008 by Bill Kendrick and others; see AUTHORS.txt
Copyright (c) 2002-2019 by Bill Kendrick and others; see AUTHORS.txt
bill@newbreedsoftware.com
http://www.tuxpaint.org/
@ -23,7 +23,7 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
(See COPYING.txt)
Last updated: July 8, 2008
Last updated: August 29, 2019
$Id$
*/
@ -137,7 +137,6 @@ void calligraphy_drag(magic_api * api, int which ATTRIBUTE_UNUSED, SDL_Surface *
{
Point2D *curve;
int i, n_points, thick, new_thick;
Uint32 colr;
SDL_Rect src, dest;
// if (SDL_GetTicks() < calligraphy_last_time + 5)
@ -184,8 +183,6 @@ void calligraphy_drag(magic_api * api, int which ATTRIBUTE_UNUSED, SDL_Surface *
calligraphy_ComputeBezier(calligraphy_control_points, n_points, curve);
colr = SDL_MapRGB(canvas->format, calligraphy_r, calligraphy_g, calligraphy_b);
new_thick = 40 - min((n_points /* / 2 */ ), 32);
for (i = 0; i < n_points - 1; i++)
@ -218,23 +215,6 @@ void calligraphy_drag(magic_api * api, int which ATTRIBUTE_UNUSED, SDL_Surface *
dest.y = y;
SDL_BlitSurface(calligraphy_colored_brush, &src, canvas, &dest);
/* Old way; using putpixel:
SDL_LockSurface(canvas);
for (j = -(thick / 2); j < (thick / 2) + 1; j++)
{
x = curve[i].x + j;
y = curve[i].y - (j / 2); // 30 degrees
api->putpixel(canvas, x, y, colr);
api->putpixel(canvas, x + 1, y, colr);
api->putpixel(canvas, x, y + 1, colr);
api->putpixel(canvas, x + 1, y + 1, colr);
}
SDL_UnlockSurface(canvas);
*/
}
calligraphy_old_thick = (calligraphy_old_thick + new_thick) / 2;

View file

@ -4,7 +4,7 @@
Emboss Magic Tool Plugin
Tux Paint - A simple drawing program for children.
Copyright (c) 2002-2008 by Bill Kendrick and others; see AUTHORS.txt
Copyright (c) 2002-2019 by Bill Kendrick and others; see AUTHORS.txt
bill@newbreedsoftware.com
http://www.tuxpaint.org/
@ -23,7 +23,7 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
(See COPYING.txt)
Last updated: July 8, 2008
Last updated: August 29, 2019
$Id$
*/
@ -114,7 +114,7 @@ static void do_emboss(void *ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canva
magic_api *api = (magic_api *) ptr;
int xx, yy;
Uint8 r1, g1, b1, r2, g2, b2;
int r, g, b;
int r;
float h, s, v;
int avg1, avg2;
@ -139,7 +139,6 @@ static void do_emboss(void *ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canva
r = 0;
if (r > 255)
r = 255;
g = b = r;
v = (r / 255.0);

View file

@ -1,268 +0,0 @@
/*
fill.c
Fill Magic Tool Plugin
Tux Paint - A simple drawing program for children.
Copyright (c) 2002-2008 by Bill Kendrick and others; see AUTHORS.txt
bill@newbreedsoftware.com
http://www.tuxpaint.org/
Flood fill code based on Wikipedia example:
http://www.wikipedia.org/wiki/Flood_fill/C_example
by Damian Yerrick - http://www.wikipedia.org/wiki/Damian_Yerrick
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: July 8, 2008
$Id$
*/
#include <stdio.h>
#include <string.h>
#include "tp_magic_api.h"
#include "SDL_image.h"
/* Our globals: */
static Mix_Chunk *fill_snd;
static Uint8 fill_r, fill_g, fill_b;
/* Local function prototypes: */
static int colors_close(magic_api * api, SDL_Surface * canvas, Uint32 c1, Uint32 c2);
static void do_flood_fill(magic_api * api, SDL_Surface * canvas, int x, int y, Uint32 cur_colr, Uint32 old_colr);
int fill_modes(magic_api * api, int which);
void fill_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
void fill_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas);
int fill_requires_colors(magic_api * api, int which);
void fill_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
void fill_shutdown(magic_api * api);
void fill_release(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void fill_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void fill_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect);
char *fill_get_description(magic_api * api, int which, int mode);
char *fill_get_name(magic_api * api, int which);
int fill_get_tool_count(magic_api * api);
SDL_Surface *fill_get_icon(magic_api * api, int which);
Uint32 fill_api_version(void);
int fill_init(magic_api * api);
// No setup required:
int fill_init(magic_api * api)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%ssounds/magic/fill.wav", api->data_directory);
fill_snd = Mix_LoadWAV(fname);
return (1);
}
Uint32 fill_api_version(void)
{
return (TP_MAGIC_API_VERSION);
}
// We have multiple tools:
int fill_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
{
return (1);
}
// Load our icons:
SDL_Surface *fill_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%simages/magic/fill.png", api->data_directory);
return (IMG_Load(fname));
}
// Return our names, localized:
char *fill_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return (strdup(gettext_noop("Fill")));
}
// Return our descriptions, localized:
char *fill_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
{
return (strdup(gettext_noop("Click in the picture to fill that area with color.")));
}
// Affect the canvas on drag:
void fill_drag(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED,
SDL_Surface * last ATTRIBUTE_UNUSED, int ox ATTRIBUTE_UNUSED, int oy ATTRIBUTE_UNUSED,
int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
}
// Affect the canvas on click:
void fill_click(magic_api * api, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED,
int x, int y, SDL_Rect * update_rect)
{
do_flood_fill(api, canvas, x, y, SDL_MapRGB(canvas->format, fill_r, fill_g, fill_b), api->getpixel(canvas, x, y));
update_rect->x = 0;
update_rect->y = 0;
update_rect->w = canvas->w;
update_rect->h = canvas->h;
}
void fill_release(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED,
int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
}
void fill_shutdown(magic_api * api ATTRIBUTE_UNUSED)
{
Mix_FreeChunk(fill_snd);
}
// Record the color from Tux Paint:
void fill_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r, Uint8 g, Uint8 b)
{
fill_r = r;
fill_g = g;
fill_b = b;
}
// Use colors:
int fill_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return 1;
}
static int colors_close(magic_api * api, SDL_Surface * canvas, Uint32 c1, Uint32 c2)
{
Uint8 r1, g1, b1, r2, g2, b2;
if (c1 == c2)
{
/* Get it over with quick, if possible! */
return 1;
}
else
{
double r, g, b;
SDL_GetRGB(c1, canvas->format, &r1, &g1, &b1);
SDL_GetRGB(c2, canvas->format, &r2, &g2, &b2);
// use distance in linear RGB space
r = api->sRGB_to_linear(r1) - api->sRGB_to_linear(r2);
r *= r;
g = api->sRGB_to_linear(g1) - api->sRGB_to_linear(g2);
g *= g;
b = api->sRGB_to_linear(b1) - api->sRGB_to_linear(b2);
b *= b;
// easy to confuse:
// dark grey, brown, purple
// light grey, tan
// red, orange
return r + g + b < 0.04;
}
}
static void do_flood_fill(magic_api * api, SDL_Surface * canvas, int x, int y, Uint32 cur_colr, Uint32 old_colr)
{
int fillL, fillR, i, in_line;
static unsigned char prog_anim;
if (cur_colr == old_colr || colors_close(api, canvas, cur_colr, old_colr))
return;
fillL = x;
fillR = x;
prog_anim++;
if ((prog_anim % 4) == 0)
{
api->update_progress_bar();
api->playsound(fill_snd, (x * 255) / canvas->w, 255);
}
/* Find left side, filling along the way */
in_line = 1;
while (in_line)
{
api->putpixel(canvas, fillL, y, cur_colr);
fillL--;
in_line = (fillL < 0) ? 0 : colors_close(api, canvas, api->getpixel(canvas, fillL, y), old_colr);
}
fillL++;
/* Find right side, filling along the way */
in_line = 1;
while (in_line)
{
api->putpixel(canvas, fillR, y, cur_colr);
fillR++;
in_line = (fillR >= canvas->w) ? 0 : colors_close(api, canvas, api->getpixel(canvas, fillR, y), old_colr);
}
fillR--;
/* Search top and bottom */
for (i = fillL; i <= fillR; i++)
{
if (y > 0 && colors_close(api, canvas, api->getpixel(canvas, i, y - 1), old_colr))
do_flood_fill(api, canvas, i, y - 1, cur_colr, old_colr);
if (y < canvas->h && colors_close(api, canvas, api->getpixel(canvas, i, y + 1), old_colr))
do_flood_fill(api, canvas, i, y + 1, cur_colr, old_colr);
}
}
void fill_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
void fill_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
int fill_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return (MODE_PAINT);
}

View file

@ -1,3 +1,9 @@
/*
* Folds the picture down from the corners.
*
* Last updated: 2019-08-29
*/
//optimized version soon :)
//when "folding" same corner many times it gives strange results. Now it's allowed. Let me know
//if you think it shouldn't be.
@ -142,25 +148,29 @@ void fold_draw(magic_api * api, int which,
right_step_y = (float)(y - left_arm_y) / (float)(left_arm_x - fold_ox);
left_step_x = (float)(x - right_arm_x) / (float)(right_arm_y - fold_oy);
left_step_y = (float)(y - right_arm_y) / (float)(right_arm_y - fold_oy);
left_y = (float)right_arm_y / left_arm_x * (left_arm_x - canvas->w);
right_x = (float)left_arm_x / right_arm_y * (right_arm_y - canvas->h);
for (w = 0; w < canvas->w; w += 0.5)
for (h = 0; h < canvas->h; h += 0.5)
{
dist_x = right_step_x * w + left_step_x * h;
dist_y = right_step_y * w + left_step_y * h;
api->putpixel(canvas, x - dist_x, y - dist_y, api->getpixel(temp, w, h));
}
{
for (h = 0; h < canvas->h; h += 0.5)
{
dist_x = right_step_x * w + left_step_x * h;
dist_y = right_step_y * w + left_step_y * h;
api->putpixel(canvas, x - dist_x, y - dist_y, api->getpixel(temp, w, h));
}
}
// Erasing the triangle.
// The 1 pixel in plus is a workaround for api-line not getting the end in some lines.
if (left_arm_x > canvas->w)
{
left_y = (float)right_arm_y / left_arm_x * (left_arm_x - canvas->w);
for (h = 0; h <= right_arm_y; h++)
api->line((void *)api, which, canvas, snapshot, canvas->w, left_y - h, -1, right_arm_y - h, 1, fold_erase);
}
else if (right_arm_y > canvas->h)
{
right_x = (float)left_arm_x / right_arm_y * (right_arm_y - canvas->h);
for (w = 0; w <= left_arm_x; w++)
api->line((void *)api, which, canvas, snapshot, left_arm_x - w, 0, right_x - w, canvas->h + 1, 1, fold_erase);
}

View file

@ -1,3 +1,9 @@
/*
* Draws fretwork
*
* Last updated: 2019-08-29
*/
#include "tp_magic_api.h"
#include "SDL_image.h"
#include "SDL_mixer.h"
@ -29,7 +35,7 @@
Mix_Chunk *fretwork_snd;
unsigned int img_w, img_h;
unsigned int fretwork_segments_x, fretwork_segments_y; //how many segments do we have?
static int fretwork_math_ceil(int x, int y); //ceil() in cstdlib returns float and is relative slow, so we'll use our one
inline int fretwork_math_ceil(int x, int y); //ceil() in cstdlib returns float and is relative slow, so we'll use our one
static Uint8 *fretwork_status_of_segments; //a place to store an info about bitmap used for selected segment
static char **fretwork_images; //the pathes to all the images needed
static unsigned int fretwork_segment_modified; //which segment was modified this time?
@ -243,7 +249,7 @@ void fretwork_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UN
// Interactivity functions
static int fretwork_math_ceil(int x, int y)
inline int fretwork_math_ceil(int x, int y)
{
int temp;

View file

@ -8,7 +8,7 @@
Credits: Andrew Corcoran <akanewbie@gmail.com>
Copyright (c) 2002-2009 by Bill Kendrick and others; see AUTHORS.txt
Copyright (c) 2002-2019 by Bill Kendrick and others; see AUTHORS.txt
bill@newbreedsoftware.com
http://www.tuxpaint.org/
@ -27,7 +27,7 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
(See COPYING.txt)
Last updated: May 6, 2009
Last updated: August 29, 2019
$Id$
*/
@ -86,9 +86,11 @@ void perspective_line(void *ptr_to_api, int which, SDL_Surface * canvas, SDL_Sur
/* Unused?
static const int perspective_AMOUNT = 300;
static const int perspective_RADIUS = 16;
static const double perspective_SHARPEN = 1.0;
*/
Uint8 perspective_r, perspective_g, perspective_b;
int corner;
int dash;
@ -396,12 +398,10 @@ void perspective_release(magic_api * api, int which,
}
else
{
int aux_x, aux_y, aux_h, aux_w;
int aux_h, aux_w;
aux_h = canvas->h * canvas->h / new_h;
aux_w = canvas->w * aux_h / canvas->h;
aux_x = canvas->w / 2 - aux_w / 2;
aux_y = canvas->h / 2 - aux_h / 2;
update_rect->x = canvas->w / 2 - aux_w / 2;
update_rect->y = canvas->h / 2 - aux_h / 2;

View file

@ -28,7 +28,7 @@
Mix_Chunk *rails_snd;
unsigned int img_w, img_h;
unsigned int rails_segments_x, rails_segments_y; //how many segments do we have?
static int rails_math_ceil(int x, int y); //ceil() in cstdlib returns float and is relative slow, so we'll use our one
inline int rails_math_ceil(int x, int y); //ceil() in cstdlib returns float and is relative slow, so we'll use our one
static Uint8 *rails_status_of_segments; //a place to store an info about bitmap used for selected segment
static char **rails_images; //the pathes to all the images needed
static unsigned int rails_segment_modified; //which segment was modified this time?
@ -55,7 +55,6 @@ void rails_release(magic_api * api, int which,
void rails_shutdown(magic_api * api);
void rails_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas);
void rails_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
static int rails_math_ceil(int x, int y);
inline unsigned int rails_get_segment(int x, int y);
inline void rails_extract_coords_from_segment(unsigned int segment, Sint16 * x, Sint16 * y);
static void rails_flip(void *ptr, SDL_Surface * dest, SDL_Surface * src);
@ -197,7 +196,7 @@ void rails_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSE
// Interactivity functions
static int rails_math_ceil(int x, int y)
inline int rails_math_ceil(int x, int y)
{
int temp;

View file

@ -1,3 +1,8 @@
/*
* Strings -- draws string art.
*
* Last modified: 2019-08-29
*/
#include "tp_magic_api.h"
#include "SDL_image.h"
#include "SDL_mixer.h"
@ -353,20 +358,9 @@ void string_draw_triangle_preview(magic_api * api, int which,
SDL_Rect * update_rect)
{
int middle_x, middle_y;
int w, h;
scale_coords(&ox, &oy, &x, &y);
w = max(string_ox, x) - min(string_ox, x);
h = max(string_oy, y) - min(string_oy, y);
/*
This is enouth if you move the mouse slowly, but if you move the mouse fast,
there are rests of old previews left around.
update_rect->w=max(max(string_ox,x),max(ox,x))-min(min(string_ox,x),min(ox,x)) +80;
update_rect->h=max(max(string_oy,y),max(oy,y))-min(min(string_oy,y),min(oy,y)) +80;
update_rect->x=min(string_ox,x) -40;
update_rect->y=min(string_oy,y) -40;
*/
update_rect->x = 0;
update_rect->y = 0;
update_rect->w = canvas->w;
@ -387,13 +381,9 @@ void string_draw_angle_preview(magic_api * api, int which,
int ox, __attribute__ ((unused))
int oy, int x, int y, SDL_Rect * update_rect)
{
int w, h;
int middle_x, middle_y;
int dx, dy;
w = max(string_ox, x) - min(string_ox, x);
h = max(string_oy, y) - min(string_oy, y);
update_rect->x = 0;
update_rect->y = 0;
update_rect->w = canvas->w;