New Fill tool mode: Brush
Similar to solid fill (classic mode), but allows freehand filling of an area. Closes https://sourceforge.net/p/tuxpaint/feature-requests/207/
This commit is contained in:
parent
910cd298e5
commit
dcdebe9882
16 changed files with 152 additions and 6 deletions
98
src/fill.c
98
src/fill.c
|
|
@ -27,7 +27,7 @@
|
|||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
(See COPYING.txt)
|
||||
|
||||
Last updated: May 5, 2021
|
||||
Last updated: October 18, 2021
|
||||
$Id$
|
||||
*/
|
||||
|
||||
|
|
@ -380,6 +380,102 @@ void draw_linear_gradient(SDL_Surface * canvas, SDL_Surface * last,
|
|||
}
|
||||
}
|
||||
|
||||
void draw_brush_fill_single(SDL_Surface * canvas, int x, int y, Uint32 draw_color, Uint8 * touched) {
|
||||
int xx, yy;
|
||||
|
||||
for (yy = -16; yy < 16; yy++)
|
||||
{
|
||||
for (xx = -16; xx < 16; xx++)
|
||||
{
|
||||
if ((xx * xx) + (yy * yy) < (16 * 16) &&
|
||||
touched[((y + yy) * canvas->w) + (x + xx)])
|
||||
{
|
||||
putpixels[canvas->format->BytesPerPixel] (canvas, x + xx, y + yy, draw_color);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void draw_brush_fill(SDL_Surface * canvas,
|
||||
int x_left, int y_top, int x_right, int y_bottom,
|
||||
int x1, int y1, int x2, int y2, Uint32 draw_color, Uint8 * touched,
|
||||
int * up_x1, int * up_y1, int * up_x2, int * up_y2
|
||||
) {
|
||||
int xx, yy, x, y, dx, dy;
|
||||
int orig_x1, orig_y1, orig_x2, orig_y2, tmp;
|
||||
float m, b;
|
||||
|
||||
orig_x1 = x1;
|
||||
orig_y1 = y1;
|
||||
|
||||
orig_x2 = x2;
|
||||
orig_y2 = y2;
|
||||
|
||||
dx = x2 - x1;
|
||||
dy = y2 - y1;
|
||||
|
||||
if (dx != 0)
|
||||
{
|
||||
m = ((float)dy) / ((float)dx);
|
||||
b = y1 - m * x1;
|
||||
|
||||
if (x2 >= x1)
|
||||
dx = 1;
|
||||
else
|
||||
dx = -1;
|
||||
|
||||
while (x1 != x2)
|
||||
{
|
||||
y1 = m * x1 + b;
|
||||
y2 = m * (x1 + dx) + b;
|
||||
|
||||
if (y1 > y2)
|
||||
{
|
||||
for (y = y1; y >= y2; y--)
|
||||
draw_brush_fill_single(canvas, x1, y, draw_color, touched);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (y = y1; y <= y2; y++)
|
||||
draw_brush_fill_single(canvas, x1, y, draw_color, touched);
|
||||
}
|
||||
|
||||
x1 = x1 + dx;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (y1 > y2)
|
||||
{
|
||||
y = y1;
|
||||
y1 = y2;
|
||||
y2 = y;
|
||||
}
|
||||
|
||||
for (y = y1; y <= y2; y++)
|
||||
draw_brush_fill_single(canvas, x1, y, draw_color, touched);
|
||||
}
|
||||
|
||||
if (orig_x1 > orig_x2)
|
||||
{
|
||||
tmp = orig_x1;
|
||||
orig_x1 = orig_x2;
|
||||
orig_x2 = tmp;
|
||||
}
|
||||
|
||||
if (orig_y1 > orig_y2)
|
||||
{
|
||||
tmp = orig_y1;
|
||||
orig_y1 = orig_y2;
|
||||
orig_y2 = tmp;
|
||||
}
|
||||
|
||||
*up_x1 = orig_x1 - 16;
|
||||
*up_y1 = orig_y1 - 16;
|
||||
*up_x2 = orig_x2 + 16;
|
||||
*up_y2 = orig_y2 + 16;
|
||||
}
|
||||
|
||||
void draw_radial_gradient(SDL_Surface * canvas, int x_left, int y_top, int x_right, int y_bottom,
|
||||
int x, int y, Uint32 draw_color, Uint8 * touched
|
||||
) {
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@
|
|||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
(See COPYING.txt)
|
||||
|
||||
Last updated: March 8, 2021
|
||||
Last updated: October 18, 2021
|
||||
$Id$
|
||||
*/
|
||||
|
||||
|
|
@ -44,6 +44,10 @@ void draw_linear_gradient(SDL_Surface * canvas, SDL_Surface * last,
|
|||
int x1, int y1, int x2, int y2, Uint32 draw_color, Uint8 * touched);
|
||||
void draw_radial_gradient(SDL_Surface * canvas, int x_left, int y_top, int x_right, int y_bottom,
|
||||
int x, int y, Uint32 draw_color, Uint8 * touched);
|
||||
void draw_brush_fill(SDL_Surface * canvas,
|
||||
int x_left, int y_top, int x_right, int y_bottom,
|
||||
int x1, int y1, int x2, int y2, Uint32 draw_color, Uint8 * touched,
|
||||
int * up_x1, int * up_y1, int * up_x2, int * up_y2);
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@
|
|||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
(See COPYING.txt)
|
||||
|
||||
Last updated: September 6, 2021
|
||||
Last updated: October 18, 2021
|
||||
$Id$
|
||||
*/
|
||||
|
||||
|
|
@ -40,6 +40,7 @@
|
|||
|
||||
enum {
|
||||
FILL_FLOOD,
|
||||
FILL_BRUSH,
|
||||
FILL_GRADIENT_LINEAR,
|
||||
FILL_GRADIENT_RADIAL,
|
||||
NUM_FILLS
|
||||
|
|
@ -47,18 +48,21 @@ enum {
|
|||
|
||||
const char *const fill_names[NUM_FILLS] = {
|
||||
gettext_noop("Solid"),
|
||||
gettext_noop("Brush"),
|
||||
gettext_noop("Linear"),
|
||||
gettext_noop("Radial")
|
||||
};
|
||||
|
||||
const char *const fill_tips[NUM_FILLS] = {
|
||||
gettext_noop("Click to fill an area with a solid color."),
|
||||
gettext_noop("Click to fill an by hand, using a brush."),
|
||||
gettext_noop("Click and drag to fill an area with a linear gradient (from the chosen color to transparent)."),
|
||||
gettext_noop("Click to fill an area with a radial gradient (from the chosen color to transparent).")
|
||||
};
|
||||
|
||||
const char *const fill_img_fnames[NUM_FILLS] = {
|
||||
DATA_PREFIX "images/fills/solid.png",
|
||||
DATA_PREFIX "images/fills/brush.png",
|
||||
DATA_PREFIX "images/fills/gradient_linear.png",
|
||||
DATA_PREFIX "images/fills/gradient_radial.png"
|
||||
};
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@
|
|||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
(See COPYING.txt)
|
||||
|
||||
June 14, 2002 - September 25, 2021
|
||||
June 14, 2002 - October 18, 2021
|
||||
*/
|
||||
|
||||
#include "platform.h"
|
||||
|
|
@ -4719,6 +4719,12 @@ static void mainloop(void)
|
|||
fill_x, fill_y, old_x, old_y + 1, draw_color, sim_flood_touched);
|
||||
fill_drag_started = 1;
|
||||
}
|
||||
else if (cur_fill == FILL_BRUSH)
|
||||
{
|
||||
/* Start painting within the fill area */
|
||||
draw_brush_fill(canvas, sim_flood_x1, sim_flood_y1, sim_flood_x2, sim_flood_y2,
|
||||
fill_x, fill_y, old_x, old_y, draw_color, sim_flood_touched, &x1, &x2, &y1, &y2);
|
||||
}
|
||||
|
||||
update_canvas(x1, y1, x2, y2);
|
||||
}
|
||||
|
|
@ -5676,7 +5682,7 @@ static void mainloop(void)
|
|||
}
|
||||
else if (cur_tool == TOOL_FILL && cur_fill == FILL_GRADIENT_LINEAR && fill_drag_started)
|
||||
{
|
||||
Uint32 draw_color, canv_color;
|
||||
Uint32 draw_color;
|
||||
int undo_ctr;
|
||||
SDL_Surface * last;
|
||||
|
||||
|
|
@ -5698,6 +5704,23 @@ static void mainloop(void)
|
|||
|
||||
update_canvas(sim_flood_x1, sim_flood_y1, sim_flood_x2, sim_flood_y2);
|
||||
}
|
||||
else if (cur_tool == TOOL_FILL && cur_fill == FILL_BRUSH)
|
||||
{
|
||||
Uint32 draw_color;
|
||||
int x1, y1, x2, y2;
|
||||
|
||||
/* Pushing button and moving: Paint more within the fill area: */
|
||||
|
||||
draw_color = SDL_MapRGB(canvas->format,
|
||||
color_hexes[cur_color][0],
|
||||
color_hexes[cur_color][1],
|
||||
color_hexes[cur_color][2]);
|
||||
|
||||
draw_brush_fill(canvas, sim_flood_x1, sim_flood_y1, sim_flood_x2, sim_flood_y2,
|
||||
old_x, old_y, new_x, new_y, draw_color, sim_flood_touched, &x1, &y1, &x2, &y2);
|
||||
|
||||
update_canvas(x1, y1, x2, y2);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue