1997-11-25 06:05:25 +08:00
|
|
|
/* The GIMP -- an image manipulation program
|
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
|
|
|
* 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
|
1998-04-13 13:44:11 +08:00
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
1997-11-25 06:05:25 +08:00
|
|
|
*/
|
|
|
|
#include <stdlib.h>
|
1999-08-14 04:50:30 +08:00
|
|
|
#include "gdk/gdkkeysyms.h"
|
1997-11-25 06:05:25 +08:00
|
|
|
#include "appenv.h"
|
1999-08-14 04:50:30 +08:00
|
|
|
#include "cursorutil.h"
|
1997-11-25 06:05:25 +08:00
|
|
|
#include "drawable.h"
|
|
|
|
#include "errors.h"
|
|
|
|
#include "gdisplay.h"
|
1999-08-14 04:50:30 +08:00
|
|
|
#include "gimage_mask.h"
|
1997-11-25 06:05:25 +08:00
|
|
|
#include "paint_funcs.h"
|
|
|
|
#include "paint_core.h"
|
1999-04-22 22:34:00 +08:00
|
|
|
#include "paint_options.h"
|
1997-11-25 06:05:25 +08:00
|
|
|
#include "palette.h"
|
|
|
|
#include "eraser.h"
|
|
|
|
#include "selection.h"
|
1999-04-13 01:55:06 +08:00
|
|
|
#include "tool_options_ui.h"
|
1997-11-25 06:05:25 +08:00
|
|
|
#include "tools.h"
|
|
|
|
|
Lots of ii8n stuff here and some additions to the de.po. Applied
Wed Oct 14 17:46:15 EDT 1998 Adrian Likins <adrian@gimp.org>
* app/*, po/de.po, de/POTFILES.in, libgimp/gimpintl.h:
Lots of ii8n stuff here and some additions to the de.po.
Applied gimp-egger-981005-1 ,gimp-egger-981006-1,
gimp-egger-981007-1, gimp-egger-981008-1,
gimp-egger-981009-1.patch, gimp-egger-981010-1.patch
* plug-in/guillotine/guillotine.c: added the coordinates
of the split images from the original image to the title.
ie foo.jpg (0,0) for the image in the topleft.
* plug-in/script-fu/scripts/neon-logo.scm,
perspective-shadow.scm, predator.scm,rendermap.scm,
ripply-anim.scm, select_to_image.scm,swirltile.scm,
xach-effect.scm: updated scripts to use new script-fu stuff
wooo boy! a big un!
in testing this, it looks like some of the po files are busted.
but the code stuff seems okay.
-adrian
1998-10-15 07:23:52 +08:00
|
|
|
#include "libgimp/gimpintl.h"
|
|
|
|
|
1999-07-20 06:42:49 +08:00
|
|
|
/* Defaults */
|
|
|
|
#define ERASER_DEFAULT_HARD FALSE
|
|
|
|
#define ERASER_DEFAULT_INCREMENTAL FALSE
|
1999-08-14 04:50:30 +08:00
|
|
|
#define ERASER_DEFAULT_ANTI_ERASE FALSE
|
1999-07-20 06:42:49 +08:00
|
|
|
|
1999-04-09 06:25:54 +08:00
|
|
|
/* the eraser structures */
|
1998-03-01 09:18:45 +08:00
|
|
|
|
|
|
|
typedef struct _EraserOptions EraserOptions;
|
|
|
|
struct _EraserOptions
|
|
|
|
{
|
1999-04-22 22:34:00 +08:00
|
|
|
PaintOptions paint_options;
|
1999-04-09 06:25:54 +08:00
|
|
|
|
1999-04-22 22:34:00 +08:00
|
|
|
gboolean hard;
|
|
|
|
gboolean hard_d;
|
|
|
|
GtkWidget *hard_w;
|
1999-04-13 01:55:06 +08:00
|
|
|
|
1999-04-22 22:34:00 +08:00
|
|
|
gboolean incremental;
|
|
|
|
gboolean incremental_d;
|
|
|
|
GtkWidget *incremental_w;
|
1999-08-14 04:50:30 +08:00
|
|
|
|
|
|
|
gboolean anti_erase;
|
|
|
|
gboolean anti_erase_d;
|
|
|
|
GtkWidget *anti_erase_w;
|
1998-03-01 09:18:45 +08:00
|
|
|
};
|
|
|
|
|
1999-04-13 01:55:06 +08:00
|
|
|
|
|
|
|
/* the eraser tool options */
|
1998-03-01 09:18:45 +08:00
|
|
|
static EraserOptions *eraser_options = NULL;
|
|
|
|
|
1999-04-09 06:25:54 +08:00
|
|
|
/* local variables */
|
|
|
|
static gboolean non_gui_hard;
|
|
|
|
static gboolean non_gui_incremental;
|
1999-08-14 04:50:30 +08:00
|
|
|
static gboolean non_gui_anti_erase;
|
1999-04-09 06:25:54 +08:00
|
|
|
|
|
|
|
/* forward function declarations */
|
1999-04-13 01:55:06 +08:00
|
|
|
static void eraser_motion (PaintCore *, GimpDrawable *,
|
1999-08-14 04:50:30 +08:00
|
|
|
gboolean, gboolean, gboolean);
|
1999-04-09 06:25:54 +08:00
|
|
|
|
|
|
|
|
|
|
|
/* functions */
|
|
|
|
|
1998-03-01 09:18:45 +08:00
|
|
|
static void
|
1999-04-13 01:55:06 +08:00
|
|
|
eraser_options_reset (void)
|
1999-04-09 06:25:54 +08:00
|
|
|
{
|
|
|
|
EraserOptions *options = eraser_options;
|
|
|
|
|
1999-04-22 22:34:00 +08:00
|
|
|
paint_options_reset ((PaintOptions *) options);
|
|
|
|
|
1999-04-09 06:25:54 +08:00
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (options->hard_w),
|
|
|
|
options->hard_d);
|
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (options->incremental_w),
|
|
|
|
options->incremental_d);
|
|
|
|
}
|
|
|
|
|
1998-03-01 09:18:45 +08:00
|
|
|
static EraserOptions *
|
1999-04-13 01:55:06 +08:00
|
|
|
eraser_options_new (void)
|
1998-03-01 09:18:45 +08:00
|
|
|
{
|
|
|
|
EraserOptions *options;
|
|
|
|
|
1999-04-13 01:55:06 +08:00
|
|
|
GtkWidget *vbox;
|
|
|
|
|
|
|
|
/* the new eraser tool options structure */
|
1998-03-01 09:18:45 +08:00
|
|
|
options = (EraserOptions *) g_malloc (sizeof (EraserOptions));
|
1999-04-22 22:34:00 +08:00
|
|
|
paint_options_init ((PaintOptions *) options,
|
|
|
|
ERASER,
|
|
|
|
eraser_options_reset);
|
1999-07-20 06:42:49 +08:00
|
|
|
options->hard = options->hard_d = ERASER_DEFAULT_HARD;
|
|
|
|
options->incremental = options->incremental_d = ERASER_DEFAULT_INCREMENTAL;
|
1999-08-14 04:50:30 +08:00
|
|
|
options->anti_erase = options->anti_erase_d = ERASER_DEFAULT_ANTI_ERASE;
|
1998-03-01 09:18:45 +08:00
|
|
|
|
|
|
|
/* the main vbox */
|
1999-04-22 22:34:00 +08:00
|
|
|
vbox = ((ToolOptions *) options)->main_vbox;
|
1998-03-01 09:18:45 +08:00
|
|
|
|
|
|
|
/* the hard toggle */
|
1999-04-09 06:25:54 +08:00
|
|
|
options->hard_w = gtk_check_button_new_with_label (_("Hard edge"));
|
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), options->hard_w, FALSE, FALSE, 0);
|
|
|
|
gtk_signal_connect (GTK_OBJECT (options->hard_w), "toggled",
|
1999-04-13 01:55:06 +08:00
|
|
|
(GtkSignalFunc) tool_options_toggle_update,
|
1998-03-01 09:18:45 +08:00
|
|
|
&options->hard);
|
1999-04-09 06:25:54 +08:00
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (options->hard_w),
|
|
|
|
options->hard_d);
|
|
|
|
gtk_widget_show (options->hard_w);
|
1998-03-01 09:18:45 +08:00
|
|
|
|
|
|
|
/* the incremental toggle */
|
1999-04-09 06:25:54 +08:00
|
|
|
options->incremental_w = gtk_check_button_new_with_label (_("Incremental"));
|
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), options->incremental_w, FALSE, FALSE, 0);
|
|
|
|
gtk_signal_connect (GTK_OBJECT (options->incremental_w), "toggled",
|
1999-04-13 01:55:06 +08:00
|
|
|
(GtkSignalFunc) tool_options_toggle_update,
|
1998-03-01 09:18:45 +08:00
|
|
|
&options->incremental);
|
1999-04-09 06:25:54 +08:00
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (options->incremental_w),
|
|
|
|
options->incremental_d);
|
|
|
|
gtk_widget_show (options->incremental_w);
|
1998-03-01 09:18:45 +08:00
|
|
|
|
1999-08-14 04:50:30 +08:00
|
|
|
/* the anti_erase toggle */
|
|
|
|
options->anti_erase_w = gtk_check_button_new_with_label (_("Anti erase"));
|
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), options->anti_erase_w, FALSE, FALSE, 0);
|
|
|
|
gtk_signal_connect (GTK_OBJECT (options->anti_erase_w), "toggled",
|
|
|
|
(GtkSignalFunc) tool_options_toggle_update,
|
|
|
|
&options->anti_erase);
|
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (options->anti_erase_w),
|
|
|
|
options->anti_erase_d);
|
|
|
|
gtk_widget_show (options->anti_erase_w);
|
|
|
|
|
1998-03-01 09:18:45 +08:00
|
|
|
return options;
|
|
|
|
}
|
1999-08-14 04:50:30 +08:00
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
eraser_modifier_key_func (Tool *tool,
|
|
|
|
GdkEventKey *kevent,
|
|
|
|
gpointer gdisp_ptr)
|
|
|
|
{
|
|
|
|
switch (kevent->keyval)
|
|
|
|
{
|
|
|
|
case GDK_Alt_L: case GDK_Alt_R:
|
|
|
|
break;
|
|
|
|
case GDK_Shift_L: case GDK_Shift_R:
|
|
|
|
break;
|
|
|
|
case GDK_Control_L: case GDK_Control_R:
|
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (eraser_options->anti_erase_w), ! eraser_options->anti_erase);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
void *
|
1999-04-09 06:25:54 +08:00
|
|
|
eraser_paint_func (PaintCore *paint_core,
|
|
|
|
GimpDrawable *drawable,
|
|
|
|
int state)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
switch (state)
|
|
|
|
{
|
|
|
|
case INIT_PAINT :
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MOTION_PAINT :
|
1999-08-14 04:50:30 +08:00
|
|
|
eraser_motion (paint_core, drawable, eraser_options->hard, eraser_options->incremental, eraser_options->anti_erase);
|
1997-11-25 06:05:25 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FINISH_PAINT :
|
|
|
|
break;
|
|
|
|
|
|
|
|
default :
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-08-14 04:50:30 +08:00
|
|
|
static void
|
|
|
|
eraser_cursor_update (Tool *tool,
|
|
|
|
GdkEventMotion *mevent,
|
|
|
|
gpointer gdisp_ptr)
|
|
|
|
{
|
|
|
|
GDisplay *gdisp;
|
|
|
|
Layer *layer;
|
|
|
|
GdkCursorType ctype = GDK_TOP_LEFT_ARROW;
|
|
|
|
int x, y;
|
|
|
|
|
|
|
|
gdisp = (GDisplay *) gdisp_ptr;
|
|
|
|
|
|
|
|
gdisplay_untransform_coords (gdisp, mevent->x, mevent->y, &x, &y,
|
|
|
|
FALSE, FALSE);
|
|
|
|
|
|
|
|
if ((layer = gimage_get_active_layer (gdisp->gimage)))
|
|
|
|
{
|
|
|
|
int off_x, off_y;
|
|
|
|
drawable_offsets (GIMP_DRAWABLE(layer), &off_x, &off_y);
|
|
|
|
if (x >= off_x && y >= off_y &&
|
|
|
|
x < (off_x + drawable_width (GIMP_DRAWABLE(layer))) &&
|
|
|
|
y < (off_y + drawable_height (GIMP_DRAWABLE(layer))))
|
|
|
|
{
|
|
|
|
if (gimage_mask_is_empty (gdisp->gimage) || gimage_mask_value (gdisp->gimage, x, y))
|
|
|
|
{
|
|
|
|
if (eraser_options->anti_erase)
|
|
|
|
ctype = GDK_PENCIL; /* ANTI_ERASER CURSOR */
|
|
|
|
else
|
|
|
|
ctype = GDK_PENCIL; /* ERASER CURSOR */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
gdisplay_install_tool_cursor (gdisp, ctype);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
Tool *
|
|
|
|
tools_new_eraser ()
|
|
|
|
{
|
|
|
|
Tool * tool;
|
|
|
|
PaintCore * private;
|
|
|
|
|
1999-04-13 01:55:06 +08:00
|
|
|
/* The tool options */
|
1997-11-25 06:05:25 +08:00
|
|
|
if (! eraser_options)
|
1999-04-13 01:55:06 +08:00
|
|
|
{
|
|
|
|
eraser_options = eraser_options_new ();
|
|
|
|
tools_register (ERASER, (ToolOptions *) eraser_options);
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
tool = paint_core_new (ERASER);
|
|
|
|
|
|
|
|
private = (PaintCore *) tool->private;
|
|
|
|
private->paint_func = eraser_paint_func;
|
1999-08-14 04:50:30 +08:00
|
|
|
tool->modifier_key_func = eraser_modifier_key_func;
|
|
|
|
tool->cursor_update_func = eraser_cursor_update;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
return tool;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
tools_free_eraser (tool)
|
|
|
|
Tool * tool;
|
|
|
|
{
|
|
|
|
paint_core_free (tool);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-03-19 06:35:31 +08:00
|
|
|
static void
|
1999-04-09 06:25:54 +08:00
|
|
|
eraser_motion (PaintCore *paint_core,
|
|
|
|
GimpDrawable *drawable,
|
|
|
|
gboolean hard,
|
1999-08-14 04:50:30 +08:00
|
|
|
gboolean incremental,
|
|
|
|
gboolean anti_erase)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
GImage *gimage;
|
1998-06-21 23:37:48 +08:00
|
|
|
gint opacity;
|
1997-11-25 06:05:25 +08:00
|
|
|
TempBuf * area;
|
|
|
|
unsigned char col[MAX_CHANNELS];
|
|
|
|
|
1998-01-22 15:02:57 +08:00
|
|
|
if (! (gimage = drawable_gimage (drawable)))
|
1997-11-25 06:05:25 +08:00
|
|
|
return;
|
|
|
|
|
1998-01-22 15:02:57 +08:00
|
|
|
gimage_get_background (gimage, drawable, col);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* Get a region which can be used to paint to */
|
1998-01-22 15:02:57 +08:00
|
|
|
if (! (area = paint_core_get_paint_area (paint_core, drawable)))
|
1997-11-25 06:05:25 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
/* set the alpha channel */
|
1998-01-25 09:24:46 +08:00
|
|
|
col[area->bytes - 1] = OPAQUE_OPACITY;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* color the pixels */
|
|
|
|
color_pixels (temp_buf_data (area), col,
|
|
|
|
area->width * area->height, area->bytes);
|
1999-07-06 23:18:25 +08:00
|
|
|
opacity = 255 * gimp_context_get_opacity (NULL) * (paint_core->curpressure / 0.5);
|
1998-06-23 11:41:59 +08:00
|
|
|
if(opacity > OPAQUE_OPACITY) opacity=OPAQUE_OPACITY;
|
1997-11-25 06:05:25 +08:00
|
|
|
/* paste the newly painted canvas to the gimage which is being worked on */
|
1998-06-21 23:37:48 +08:00
|
|
|
paint_core_paste_canvas (paint_core, drawable, opacity,
|
1999-07-06 23:18:25 +08:00
|
|
|
(int) (gimp_context_get_opacity (NULL) * 255),
|
1999-08-14 04:50:30 +08:00
|
|
|
anti_erase ? ANTI_ERASE_MODE : ERASE_MODE,
|
1999-07-06 23:18:25 +08:00
|
|
|
hard ? HARD : SOFT,
|
|
|
|
incremental ? INCREMENTAL : CONSTANT);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void *
|
1999-04-09 06:25:54 +08:00
|
|
|
eraser_non_gui_paint_func (PaintCore *paint_core,
|
|
|
|
GimpDrawable *drawable,
|
|
|
|
int state)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
1999-08-14 04:50:30 +08:00
|
|
|
eraser_motion (paint_core, drawable, non_gui_hard, non_gui_incremental, non_gui_anti_erase);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
1999-07-20 06:42:49 +08:00
|
|
|
gboolean
|
|
|
|
eraser_non_gui_default (GimpDrawable *drawable,
|
|
|
|
int num_strokes,
|
|
|
|
double *stroke_array)
|
|
|
|
{
|
|
|
|
gint hardness = ERASER_DEFAULT_HARD;
|
|
|
|
gint method = ERASER_DEFAULT_INCREMENTAL;
|
1999-08-14 04:50:30 +08:00
|
|
|
gint anti_erase = ERASER_DEFAULT_ANTI_ERASE;
|
|
|
|
|
1999-07-20 06:42:49 +08:00
|
|
|
EraserOptions *options = eraser_options;
|
|
|
|
|
|
|
|
if(options)
|
|
|
|
{
|
|
|
|
hardness = options->hard;
|
|
|
|
method = options->incremental;
|
1999-08-14 04:50:30 +08:00
|
|
|
anti_erase = options->anti_erase;
|
1999-07-20 06:42:49 +08:00
|
|
|
}
|
|
|
|
|
1999-08-14 04:50:30 +08:00
|
|
|
return eraser_non_gui(drawable,num_strokes,stroke_array,hardness,method,anti_erase);
|
1999-07-20 06:42:49 +08:00
|
|
|
}
|
|
|
|
|
1999-04-19 05:22:41 +08:00
|
|
|
gboolean
|
|
|
|
eraser_non_gui (GimpDrawable *drawable,
|
|
|
|
int num_strokes,
|
|
|
|
double *stroke_array,
|
|
|
|
int hardness,
|
1999-08-14 04:50:30 +08:00
|
|
|
int method,
|
|
|
|
int anti_erase)
|
1998-03-01 09:18:45 +08:00
|
|
|
{
|
1997-11-25 06:05:25 +08:00
|
|
|
int i;
|
1999-04-19 05:22:41 +08:00
|
|
|
|
|
|
|
if (paint_core_init (&non_gui_paint_core, drawable,
|
|
|
|
stroke_array[0], stroke_array[1]))
|
1998-03-01 09:18:45 +08:00
|
|
|
{
|
1999-04-19 05:22:41 +08:00
|
|
|
non_gui_hard = hardness;
|
|
|
|
non_gui_incremental = method;
|
1999-08-14 04:50:30 +08:00
|
|
|
non_gui_anti_erase = anti_erase;
|
1998-03-01 09:18:45 +08:00
|
|
|
|
1999-04-19 05:22:41 +08:00
|
|
|
/* Set the paint core's paint func */
|
1997-11-25 06:05:25 +08:00
|
|
|
non_gui_paint_core.paint_func = eraser_non_gui_paint_func;
|
|
|
|
|
|
|
|
non_gui_paint_core.startx = non_gui_paint_core.lastx = stroke_array[0];
|
|
|
|
non_gui_paint_core.starty = non_gui_paint_core.lasty = stroke_array[1];
|
|
|
|
|
1999-07-23 07:11:46 +08:00
|
|
|
eraser_non_gui_paint_func (&non_gui_paint_core, drawable, 0);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
for (i = 1; i < num_strokes; i++)
|
|
|
|
{
|
|
|
|
non_gui_paint_core.curx = stroke_array[i * 2 + 0];
|
|
|
|
non_gui_paint_core.cury = stroke_array[i * 2 + 1];
|
|
|
|
|
1998-01-22 15:02:57 +08:00
|
|
|
paint_core_interpolate (&non_gui_paint_core, drawable);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
non_gui_paint_core.lastx = non_gui_paint_core.curx;
|
|
|
|
non_gui_paint_core.lasty = non_gui_paint_core.cury;
|
|
|
|
}
|
|
|
|
|
1999-04-19 05:22:41 +08:00
|
|
|
/* Finish the painting */
|
1998-01-22 15:02:57 +08:00
|
|
|
paint_core_finish (&non_gui_paint_core, drawable, -1);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-04-19 05:22:41 +08:00
|
|
|
/* Cleanup */
|
1997-11-25 06:05:25 +08:00
|
|
|
paint_core_cleanup ();
|
1999-04-19 05:22:41 +08:00
|
|
|
return TRUE;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
1999-04-19 05:22:41 +08:00
|
|
|
else
|
|
|
|
return FALSE;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|