Merge branch 'master' into sdl2.0

Tons of bugfixes and improvements for Windows by Toyama Shin-Ichi
Angle rotation and some magic tools by Bill.
This commit is contained in:
Pere Pujal i Carabantes 2021-11-06 08:59:22 +01:00
commit 1afe9e155c
200 changed files with 16094 additions and 10127 deletions

View file

@ -23,7 +23,7 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
(See COPYING.txt)
Last updated: September 20, 2021
Last updated: October 27, 2021
$Id$
*/
@ -43,6 +43,8 @@ enum
NUM_TOOLS
};
#define EFFECT_REZ 4
/* Our globals: */
@ -143,14 +145,34 @@ int blocks_chalk_drip_get_group(magic_api * api ATTRIBUTE_UNUSED, int which ATTR
}
// Return our descriptions, localized:
char *blocks_chalk_drip_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode ATTRIBUTE_UNUSED)
char *blocks_chalk_drip_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode)
{
if (which == TOOL_BLOCKS)
return (strdup(gettext_noop("Click and drag the mouse around to make the picture blocky.")));
{
if (mode == MODE_PAINT)
{
return (strdup(gettext_noop("Click and drag the mouse around to make the picture blocky.")));
}
else
{
return (strdup(gettext_noop("Click to make the entire picture blocky.")));
}
}
else if (which == TOOL_CHALK)
return (strdup(gettext_noop("Click and drag the mouse around to turn the picture into a chalk drawing.")));
{
if (mode == MODE_PAINT)
{
return (strdup(gettext_noop("Click and drag the mouse around to turn the picture into a chalk drawing.")));
}
else
{
return (strdup(gettext_noop("Click to turn the entire picture into a chalk drawing.")));
}
}
else if (which == TOOL_DRIP)
return (strdup(gettext_noop("Click and drag the mouse around to make the picture drip.")));
{
return (strdup(gettext_noop("Click and drag the mouse around to make the picture drip.")));
}
return (NULL);
}
@ -170,19 +192,19 @@ static void blocks_chalk_drip_linecb(void *ptr, int which, SDL_Surface * canvas,
{
/* Put x/y on exact grid points: */
x = (x / 4) * 4;
y = (y / 4) * 4;
x = (x / EFFECT_REZ) * EFFECT_REZ;
y = (y / EFFECT_REZ) * EFFECT_REZ;
if (!api->touched(x, y))
{
for (yy = y - 8; yy < y + 8; yy = yy + 4)
for (yy = y - (EFFECT_REZ * 2); yy < y + (EFFECT_REZ * 2); yy = yy + EFFECT_REZ)
{
for (xx = x - 8; xx < x + 8; xx = xx + 4)
for (xx = x - (EFFECT_REZ * 2); xx < x + (EFFECT_REZ * 2); xx = xx + EFFECT_REZ)
{
Uint32 pix[16];
Uint32 pix[(EFFECT_REZ * EFFECT_REZ)];
Uint32 p_or = 0;
Uint32 p_and = ~0;
unsigned i = 16;
unsigned i = (EFFECT_REZ * EFFECT_REZ);
while (i--)
{
@ -203,7 +225,7 @@ static void blocks_chalk_drip_linecb(void *ptr, int which, SDL_Surface * canvas,
double g_sum = 0.0;
double b_sum = 0.0;
i = 16;
i = (EFFECT_REZ * EFFECT_REZ);
while (i--)
{
SDL_GetRGB(pix[i], last->format, &r, &g, &b);
@ -211,17 +233,17 @@ static void blocks_chalk_drip_linecb(void *ptr, int which, SDL_Surface * canvas,
g_sum += api->sRGB_to_linear(g);
b_sum += api->sRGB_to_linear(b);
}
r = api->linear_to_sRGB(r_sum / 16.0);
g = api->linear_to_sRGB(g_sum / 16.0);
b = api->linear_to_sRGB(b_sum / 16.0);
r = api->linear_to_sRGB(r_sum / (float) (EFFECT_REZ * EFFECT_REZ));
g = api->linear_to_sRGB(g_sum / (float) (EFFECT_REZ * EFFECT_REZ));
b = api->linear_to_sRGB(b_sum / (float) (EFFECT_REZ * EFFECT_REZ));
}
/* Draw block: */
dest.x = xx;
dest.y = yy;
dest.w = 4;
dest.h = 4;
dest.w = EFFECT_REZ;
dest.h = EFFECT_REZ;
SDL_FillRect(canvas, &dest, SDL_MapRGB(canvas->format, r, g, b));
}
@ -230,15 +252,14 @@ static void blocks_chalk_drip_linecb(void *ptr, int which, SDL_Surface * canvas,
}
else if (which == TOOL_CHALK)
{
for (yy = y - 8; yy <= y + 8; yy = yy + 4)
for (yy = y - (EFFECT_REZ * 2); yy <= y + (EFFECT_REZ * 2); yy = yy + EFFECT_REZ)
{
for (xx = x - 8; xx <= x + 8; xx = xx + 4)
for (xx = x - (EFFECT_REZ * 2); xx <= x + (EFFECT_REZ * 2); xx = xx + EFFECT_REZ)
{
dest.x = xx + ((rand() % 5) - 2);
dest.y = yy + ((rand() % 5) - 2);
dest.w = (rand() % 4) + 2;
dest.h = (rand() % 4) + 2;
dest.x = xx + ((rand() % (EFFECT_REZ + 1)) - (EFFECT_REZ / 2));
dest.y = yy + ((rand() % (EFFECT_REZ + 1)) - (EFFECT_REZ / 2));
dest.w = (rand() % EFFECT_REZ) + (EFFECT_REZ / 2);
dest.h = (rand() % EFFECT_REZ) + (EFFECT_REZ / 2);
colr = api->getpixel(last, clamp(0, xx, canvas->w - 1), clamp(0, yy, canvas->h - 1));
SDL_FillRect(canvas, &dest, colr);
@ -297,10 +318,22 @@ void blocks_chalk_drip_drag(magic_api * api, int which, SDL_Surface * canvas,
}
// Affect the canvas on click:
void blocks_chalk_drip_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
void blocks_chalk_drip_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect)
{
blocks_chalk_drip_drag(api, which, canvas, last, x, y, x, y, update_rect);
if (mode == MODE_PAINT) {
blocks_chalk_drip_drag(api, which, canvas, last, x, y, x, y, update_rect);
} else /* MODE_FULLSCREEN */ {
for (y = 0; y < canvas->h; y += EFFECT_REZ) {
for (x = 0; x < canvas->w; x += EFFECT_REZ) {
blocks_chalk_drip_linecb(api, which, canvas, last, x, y);
}
}
update_rect->x = 0;
update_rect->y = 0;
update_rect->w = canvas->w;
update_rect->h = canvas->h;
}
}
// Affect the canvas on release:
@ -342,7 +375,11 @@ void blocks_chalk_drip_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATT
{
}
int blocks_chalk_drip_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
int blocks_chalk_drip_modes(magic_api * api ATTRIBUTE_UNUSED, int which)
{
return (MODE_PAINT); /* FIXME - Blocks and Chalk, at least, can also be turned into a full-image effect */
if (which == TOOL_BLOCKS || TOOL_CHALK) {
return (MODE_PAINT | MODE_FULLSCREEN);
} else /* TOOL_DRIP */ {
return (MODE_PAINT);
}
}

View file

@ -23,7 +23,7 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
(See COPYING.txt)
Last updated: September 21, 2021
Last updated: November 4, 2021
$Id$
*/
@ -39,6 +39,7 @@
/* Our globals: */
static Mix_Chunk *cartoon_snd;
SDL_Surface * result_surf;
#define OUTLINE_THRESH 48
@ -50,6 +51,8 @@ SDL_Surface *cartoon_get_icon(magic_api * api, int which);
char *cartoon_get_name(magic_api * api, int which);
int cartoon_get_group(magic_api * api, int which);
char *cartoon_get_description(magic_api * api, int which, int mode);
void cartoon_apply_colors(magic_api * api, SDL_Surface * surf, int xx, int yy);
void cartoon_apply_outline(magic_api * api, int xx, int yy);
static void do_cartoon(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
void cartoon_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect);
@ -111,22 +114,71 @@ int cartoon_get_group(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUS
}
// Return our descriptions, localized:
char *cartoon_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
char *cartoon_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode)
{
return (strdup(gettext_noop("Click and drag the mouse around to turn the picture into a cartoon.")));
if (mode == MODE_PAINT)
{
return (strdup(gettext_noop("Click and drag the mouse around to turn the picture into a cartoon.")));
}
else
{
return (strdup(gettext_noop("Click to turn the entire picture into a cartoon.")));
}
}
// Do the effect:
static void do_cartoon(void *ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas, SDL_Surface * last, int x, int y)
{
magic_api *api = (magic_api *) ptr;
int xx, yy;
Uint8 r1, g1, b1, r2, g2, b2;
void cartoon_apply_colors(magic_api * api, SDL_Surface * surf, int xx, int yy) {
Uint8 r, g, b;
float hue, sat, val;
/* First, convert colors to more cartoony ones: */
SDL_GetRGB(api->getpixel(surf, xx, yy), surf->format, &r, &g, &b);
api->rgbtohsv(r, g, b, &hue, &sat, &val);
val = val - 0.5;
val = val * 4;
val = val + 0.5;
if (val < 0)
val = 0;
else if (val > 1.0)
val = 1.0;
val = floor(val * 4) / 4;
hue = floor(hue * 4) / 4;
sat = floor(sat * 4) / 4;
api->hsvtorgb(hue, sat, val, &r, &g, &b);
api->putpixel(result_surf, xx, yy, SDL_MapRGB(result_surf->format, r, g, b));
}
void cartoon_apply_outline(magic_api * api, int xx, int yy) {
Uint8 r, g, b;
Uint8 r1, g1, b1, r2, g2, b2;
SDL_GetRGB(api->getpixel(result_surf, xx, yy), result_surf->format, &r, &g, &b);
SDL_GetRGB(api->getpixel(result_surf, xx + 1, yy), result_surf->format, &r1, &g1, &b1);
SDL_GetRGB(api->getpixel(result_surf, xx + 1, yy + 1), result_surf->format, &r2, &g2, &b2);
if (abs(((r + g + b) / 3) - (r1 + g1 + b1) / 3) > OUTLINE_THRESH
|| abs(((r + g + b) / 3) - (r2 + g2 + b2) / 3) >
OUTLINE_THRESH || abs(r - r1) > OUTLINE_THRESH
|| abs(g - g1) > OUTLINE_THRESH
|| abs(b - b1) > OUTLINE_THRESH
|| abs(r - r2) > OUTLINE_THRESH || abs(g - g2) > OUTLINE_THRESH || abs(b - b2) > OUTLINE_THRESH)
{
api->putpixel(result_surf, xx - 1, yy, SDL_MapRGB(result_surf->format, 0, 0, 0));
api->putpixel(result_surf, xx, yy - 1, SDL_MapRGB(result_surf->format, 0, 0, 0));
api->putpixel(result_surf, xx - 1, yy - 1, SDL_MapRGB(result_surf->format, 0, 0, 0));
}
}
static void do_cartoon(void *ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas, SDL_Surface * last ATTRIBUTE_UNUSED, int x, int y)
{
magic_api *api = (magic_api *) ptr;
int xx, yy;
for (yy = y - 16; yy < y + 16; yy = yy + 1)
{
@ -134,60 +186,7 @@ static void do_cartoon(void *ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canv
{
if (api->in_circle(xx - x, yy - y, 16))
{
/* Get original color: */
SDL_GetRGB(api->getpixel(last, xx, yy), last->format, &r, &g, &b);
api->rgbtohsv(r, g, b, &hue, &sat, &val);
val = val - 0.5;
val = val * 4;
val = val + 0.5;
if (val < 0)
val = 0;
else if (val > 1.0)
val = 1.0;
val = floor(val * 4) / 4;
hue = floor(hue * 4) / 4;
sat = floor(sat * 4) / 4;
api->hsvtorgb(hue, sat, val, &r, &g, &b);
api->putpixel(canvas, xx, yy, SDL_MapRGB(canvas->format, r, g, b));
}
}
}
/* Then, draw dark outlines where there's a large contrast change */
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))
{
/* Get original color: */
SDL_GetRGB(api->getpixel(last, xx, yy), last->format, &r, &g, &b);
SDL_GetRGB(api->getpixel(last, xx + 1, yy), last->format, &r1, &g1, &b1);
SDL_GetRGB(api->getpixel(last, xx + 1, yy + 1), last->format, &r2, &g2, &b2);
if (abs(((r + g + b) / 3) - (r1 + g1 + b1) / 3) > OUTLINE_THRESH
|| abs(((r + g + b) / 3) - (r2 + g2 + b2) / 3) >
OUTLINE_THRESH || abs(r - r1) > OUTLINE_THRESH
|| abs(g - g1) > OUTLINE_THRESH
|| abs(b - b1) > OUTLINE_THRESH
|| abs(r - r2) > OUTLINE_THRESH || abs(g - g2) > OUTLINE_THRESH || abs(b - b2) > OUTLINE_THRESH)
{
api->putpixel(canvas, xx - 1, yy, SDL_MapRGB(canvas->format, 0, 0, 0));
api->putpixel(canvas, xx, yy - 1, SDL_MapRGB(canvas->format, 0, 0, 0));
api->putpixel(canvas, xx - 1, yy - 1, SDL_MapRGB(canvas->format, 0, 0, 0));
}
api->putpixel(canvas, xx, yy, api->getpixel(result_surf, xx, yy));
}
}
}
@ -197,8 +196,6 @@ static void do_cartoon(void *ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canv
void cartoon_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_cartoon);
if (ox > x)
{
int tmp = ox;
@ -214,6 +211,8 @@ void cartoon_drag(magic_api * api, int which, SDL_Surface * canvas,
y = tmp;
}
api->line((void *)api, which, canvas, last, ox, oy, x, y, 1, do_cartoon);
update_rect->x = ox - 16;
update_rect->y = oy - 16;
update_rect->w = (x + 16) - update_rect->x;
@ -223,10 +222,36 @@ void cartoon_drag(magic_api * api, int which, SDL_Surface * canvas,
}
// Affect the canvas on click:
void cartoon_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
void cartoon_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect)
{
cartoon_drag(api, which, canvas, last, x, y, x, y, update_rect);
for (y = 0; y < canvas->h; y++)
{
for (x = 0; x < canvas->w; x++)
{
cartoon_apply_colors(api, last, x, y);
}
}
for (y = 0; y < canvas->h; y++)
{
for (x = 0; x < canvas->w; x++)
{
cartoon_apply_outline(api, x, y);
}
}
if (mode == MODE_PAINT)
{
cartoon_drag(api, which, canvas, last, x, y, x, y, update_rect);
}
else
{
SDL_BlitSurface(result_surf, NULL, canvas, NULL);
update_rect->x = 0;
update_rect->y = 0;
update_rect->w = canvas->w;
update_rect->h = canvas->h;
}
}
// Affect the canvas on release:
@ -256,16 +281,27 @@ int cartoon_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUT
}
void cartoon_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
SDL_Surface * canvas)
{
Uint32 amask;
amask = ~(canvas->format->Rmask | canvas->format->Gmask | canvas->format->Bmask);
result_surf = SDL_CreateRGBSurface(SDL_SWSURFACE,
canvas->w,
canvas->h,
canvas->format->BitsPerPixel,
canvas->format->Rmask, canvas->format->Gmask, canvas->format->Bmask, amask);
}
void cartoon_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
if (result_surf != NULL)
SDL_FreeSurface(result_surf);
}
int cartoon_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return (MODE_PAINT); /* FIXME - Can also be turned into a full-image effect */
return (MODE_PAINT | MODE_FULLSCREEN);
}

405
magic/src/reflection.c Normal file
View file

@ -0,0 +1,405 @@
/*
reflection.c
Reflection Magic Tool Plugin
Tux Paint - A simple drawing program for children.
Copyright (c) 2021-2021 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: November 5, 2021
$Id$
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include "tp_magic_api.h"
#include "SDL_image.h"
#include "SDL_mixer.h"
#define REFLECTION_XOR_SIZE 10
/* Our globals: */
static Mix_Chunk *reflection_snd;
int reflection_x1, reflection_y1;
enum reflection_sides
{
REFLECTION_SIDE_TOP,
REFLECTION_SIDE_LEFT,
REFLECTION_SIDE_BOTTOM,
REFLECTION_SIDE_RIGHT
};
int reflection_side_old;
/* Local function prototypes: */
int reflection_init(magic_api * api);
Uint32 reflection_api_version(void);
int reflection_get_tool_count(magic_api * api);
SDL_Surface *reflection_get_icon(magic_api * api, int which);
char *reflection_get_name(magic_api * api, int which);
int reflection_get_group(magic_api * api, int which);
char *reflection_get_description(magic_api * api, int which, int mode);
void reflection_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect);
void do_reflection(magic_api * api, SDL_Surface * canvas,
SDL_Surface * last, int x, int y, SDL_Rect * update_rect, int show_origin);
void reflection_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void reflection_release(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void reflection_shutdown(magic_api * api);
void reflection_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
int reflection_requires_colors(magic_api * api, int which);
void reflection_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas);
void reflection_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
int reflection_modes(magic_api * api, int which);
int reflection_init(magic_api * api)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%s/sounds/magic/reflection.ogg", api->data_directory);
reflection_snd = Mix_LoadWAV(fname);
return (1);
}
Uint32 reflection_api_version(void)
{
return (TP_MAGIC_API_VERSION);
}
int reflection_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
{
return (1);
}
SDL_Surface *reflection_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%s/images/magic/reflection.png", api->data_directory); /* FIXME */
return (IMG_Load(fname));
}
char *reflection_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return (strdup(gettext_noop("Reflection")));
}
int reflection_get_group(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return MAGIC_TYPE_PICTURE_WARPS;
}
char *reflection_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
{
return (strdup(gettext_noop("Click and drag the mouse around to add a reflection to your picture.")));
}
void reflection_drag(magic_api * api, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas,
SDL_Surface * last, int ox ATTRIBUTE_UNUSED, int oy ATTRIBUTE_UNUSED, int x, int y,
SDL_Rect * update_rect)
{
do_reflection(api, canvas, last, x, y, update_rect, 1);
}
void do_reflection(magic_api * api, SDL_Surface * canvas,
SDL_Surface * last, int x, int y, SDL_Rect * update_rect, int show_origin)
{
float scale;
int xx, yy;
SDL_Rect src, dest;
int reflection_side;
int update_all = 0;
if (x <= 0)
x = 1;
else if (x >= canvas->w)
x = canvas->w - 1;
if (y <= 0)
y = 1;
else if (y >= canvas->h)
y = canvas->h - 1;
/* Determine what direction to go */
if (abs(x - reflection_x1) < 32)
{
/* +/-32 pixels of wiggle room before we switch from vertical to horizontal */
if (y > reflection_y1)
reflection_side = REFLECTION_SIDE_BOTTOM;
else
reflection_side = REFLECTION_SIDE_TOP;
}
else
{
if (x < reflection_x1)
reflection_side = REFLECTION_SIDE_LEFT;
else
reflection_side = REFLECTION_SIDE_RIGHT;
}
/* If we've changed direction, reset the canvas back
to the snapshot before proceeding */
if (reflection_side != reflection_side_old)
{
SDL_BlitSurface(last, NULL, canvas, NULL);
reflection_side_old = reflection_side;
update_all = 1;
}
/* Note: This isn't very good, and I basically
brute-forced the code until it seemed to work
well enough. There's a ton of room for improvement!
-bjk 2021.11.05 */
if (reflection_side == REFLECTION_SIDE_BOTTOM)
{
/* Starting from `reflection_y1` and moving down,
we'll copy from `reflection_y1` and moving up */
scale = (float) reflection_y1 / (float) y;
for (yy = reflection_y1; yy < canvas->h; yy++)
{
dest.x = 0;
dest.y = yy;
dest.w = canvas->w;
dest.h = 1;
src.x = 0;
src.y = (reflection_y1 * scale) + ((y - yy) * scale);
src.w = canvas->w;
src.h = 1;
if (src.y < 0)
{
src.y = yy;
}
SDL_BlitSurface(last, &src, canvas, &dest);
}
update_rect->x = 0;
update_rect->y = reflection_y1;
update_rect->w = canvas->w;
update_rect->h = canvas->h - reflection_y1 + 1;
}
else if (reflection_side == REFLECTION_SIDE_TOP)
{
/* Starting from `reflection_y1` and moving up,
we'll copy from `reflection_y1` and moving down */
scale = ((float) reflection_y1 / (float) y);
for (yy = reflection_y1; yy >= 0; yy--)
{
dest.x = 0;
dest.y = yy;
dest.w = canvas->w;
dest.h = 1;
src.x = 0;
src.y = (reflection_y1 / scale) + (y * scale) - (yy / scale);
src.w = canvas->w;
src.h = 1;
if (src.y >= canvas->h)
{
src.y = yy;
}
SDL_BlitSurface(last, &src, canvas, &dest);
}
update_rect->x = 0;
update_rect->y = 0;
update_rect->w = canvas->w;
update_rect->h = reflection_y1;
}
else if (reflection_side == REFLECTION_SIDE_RIGHT)
{
/* Starting from `reflection_x1` and moving right,
we'll copy from `reflection_x1` and moving left */
scale = (float) reflection_x1 / (float) x;
for (xx = reflection_x1; xx < canvas->w; xx++)
{
dest.x = xx;
dest.y = 0;
dest.w = 1;
dest.h = canvas->h;
src.x = (reflection_x1 * scale) + ((x - xx) * scale);
src.y = 0;
src.w = 1;
src.h = canvas->h;
if (src.x < 0)
{
src.x = xx;
}
SDL_BlitSurface(last, &src, canvas, &dest);
}
update_rect->x = reflection_x1;
update_rect->y = 0;
update_rect->w = canvas->w - reflection_x1 + 1;
update_rect->h = canvas->h;
}
else if (reflection_side == REFLECTION_SIDE_LEFT)
{
/* Starting from `reflection_x1` and left up,
we'll copy from `reflection_x1` and right down */
scale = (float) reflection_x1 / (float) x;
for (xx = reflection_x1; xx >= 0; xx--)
{
dest.x = xx;
dest.y = 0;
dest.w = 1;
dest.h = canvas->h;
src.x = (reflection_x1 / scale) + (x * scale) - (xx / scale);
src.y = 0;
src.w = 1;
src.h = canvas->h;
if (src.x >= canvas->w)
{
src.x = xx;
}
SDL_BlitSurface(last, &src, canvas, &dest);
}
update_rect->x = 0;
update_rect->y = 0;
update_rect->w = reflection_x1;
update_rect->h = canvas->h;
}
/* TODO: Support reflecting at arbitrary angles!
(a la linear gradient fill tool) */
if (update_all)
{
update_rect->x = 0;
update_rect->y = 0;
update_rect->w = canvas->w;
update_rect->h = canvas->h;
}
else
{
for (yy = reflection_y1 - REFLECTION_XOR_SIZE; yy < reflection_y1 + REFLECTION_XOR_SIZE; yy++)
{
if (show_origin)
api->xorpixel(canvas, reflection_x1, yy);
else
api->putpixel(canvas, reflection_x1, yy, api->getpixel(last, reflection_x1, yy));
}
for (xx = reflection_x1 - REFLECTION_XOR_SIZE; xx < reflection_x1 + REFLECTION_XOR_SIZE; xx++)
{
if (show_origin)
api->xorpixel(canvas, xx, reflection_y1);
else
api->putpixel(canvas, xx, reflection_y1, api->getpixel(last, xx, reflection_y1));
}
update_rect->x -= REFLECTION_XOR_SIZE;
update_rect->w += (REFLECTION_XOR_SIZE * 2);
update_rect->y -= REFLECTION_XOR_SIZE;
update_rect->h += (REFLECTION_XOR_SIZE * 2);
}
api->playsound(reflection_snd, (x * 255) / canvas->w, (y * 255) / canvas->h);
}
void reflection_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect)
{
if (x <= 0)
x = 1;
else if (x >= canvas->w)
x = canvas->w - 1;
if (y <= 0)
y = 1;
else if (y >= canvas->h)
y = canvas->h - 1;
reflection_x1 = x;
reflection_y1 = y - 1;
reflection_side_old = REFLECTION_SIDE_BOTTOM;
reflection_drag(api, which, canvas, last, x, y, x, y, update_rect);
}
void reflection_release(magic_api * api, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect)
{
do_reflection(api, canvas, last, x, y, update_rect, 0);
}
void reflection_shutdown(magic_api * api ATTRIBUTE_UNUSED)
{
if (reflection_snd != NULL)
Mix_FreeChunk(reflection_snd);
}
void reflection_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED,
Uint8 b ATTRIBUTE_UNUSED)
{
}
int reflection_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return 0;
}
void reflection_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas)
{
reflection_x1 = canvas->w / 2;
reflection_y1 = canvas->h / 2;
}
void reflection_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
int reflection_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return MODE_PAINT;
}