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
|
|
|
*/
|
2000-07-30 00:12:40 +08:00
|
|
|
|
2000-12-17 05:37:03 +08:00
|
|
|
#include "config.h"
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2000-03-29 07:39:32 +08:00
|
|
|
|
2000-12-29 23:22:01 +08:00
|
|
|
#include <gtk/gtk.h>
|
2000-12-17 05:37:03 +08:00
|
|
|
|
2001-01-24 07:56:18 +08:00
|
|
|
#include "libgimpmath/gimpmath.h"
|
|
|
|
|
2001-05-10 06:34:59 +08:00
|
|
|
#include "tools-types.h"
|
2000-12-17 05:37:03 +08:00
|
|
|
|
2001-05-09 10:32:03 +08:00
|
|
|
#include "core/gimpchannel.h"
|
|
|
|
#include "core/gimpimage.h"
|
|
|
|
#include "core/gimpimage-mask.h"
|
2001-05-26 02:10:38 +08:00
|
|
|
#include "core/gimpscanconvert.h"
|
2001-01-25 06:36:18 +08:00
|
|
|
|
2001-03-10 01:39:18 +08:00
|
|
|
#include "gimpeditselectiontool.h"
|
|
|
|
#include "gimpfreeselecttool.h"
|
1999-04-13 01:55:06 +08:00
|
|
|
#include "selection_options.h"
|
2000-12-29 23:22:01 +08:00
|
|
|
#include "tool_options.h"
|
2001-03-10 01:39:18 +08:00
|
|
|
#include "tool_manager.h"
|
|
|
|
|
2001-05-26 02:10:38 +08:00
|
|
|
#include "errors.h"
|
|
|
|
#include "floating_sel.h"
|
|
|
|
#include "gdisplay.h"
|
|
|
|
|
2001-03-10 01:39:18 +08:00
|
|
|
#include "libgimp/gimpintl.h"
|
|
|
|
|
2001-05-14 08:04:29 +08:00
|
|
|
#define WANT_FREE_SELECT_BITS
|
|
|
|
#include "icons.h"
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-07-30 00:12:40 +08:00
|
|
|
|
1999-04-09 06:25:54 +08:00
|
|
|
#define DEFAULT_MAX_INC 1024
|
|
|
|
#define SUPERSAMPLE 3
|
|
|
|
#define SUPERSAMPLE2 9
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-03-10 01:39:18 +08:00
|
|
|
static void gimp_free_select_tool_class_init (GimpFreeSelectToolClass *klass);
|
|
|
|
static void gimp_free_select_tool_init (GimpFreeSelectTool *free_select);
|
|
|
|
static void gimp_free_select_tool_destroy (GtkObject *object);
|
1999-05-05 17:10:35 +08:00
|
|
|
|
2001-03-10 01:39:18 +08:00
|
|
|
static void gimp_free_select_tool_button_press (GimpTool *tool,
|
|
|
|
GdkEventButton *bevent,
|
|
|
|
GDisplay *gdisp);
|
|
|
|
static void gimp_free_select_tool_button_release (GimpTool *tool,
|
|
|
|
GdkEventButton *bevent,
|
|
|
|
GDisplay *gdisp);
|
|
|
|
static void gimp_free_select_tool_motion (GimpTool *tool,
|
|
|
|
GdkEventMotion *mevent,
|
|
|
|
GDisplay *gdisp);
|
2000-03-02 07:22:43 +08:00
|
|
|
|
2001-03-10 01:39:18 +08:00
|
|
|
static void gimp_free_select_tool_draw (GimpDrawTool *draw_tool);
|
2000-03-02 07:22:43 +08:00
|
|
|
|
2001-03-10 01:39:18 +08:00
|
|
|
static void gimp_free_select_tool_add_point (GimpFreeSelectTool *free_sel,
|
|
|
|
gint x,
|
|
|
|
gint y);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-05-26 02:10:38 +08:00
|
|
|
static GimpChannel * scan_convert (GimpImage *gimage,
|
|
|
|
gint n_points,
|
|
|
|
GimpVector2 *points,
|
|
|
|
gint width,
|
|
|
|
gint height,
|
|
|
|
gboolean antialias);
|
2000-12-31 12:07:42 +08:00
|
|
|
|
|
|
|
|
2001-03-10 01:39:18 +08:00
|
|
|
static GimpSelectionToolClass *parent_class = NULL;
|
1999-04-13 01:55:06 +08:00
|
|
|
|
1999-04-09 06:25:54 +08:00
|
|
|
static SelectionOptions * free_options = NULL;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
|
2001-03-10 01:39:18 +08:00
|
|
|
/* public functions */
|
1999-04-09 06:25:54 +08:00
|
|
|
|
2001-03-10 01:39:18 +08:00
|
|
|
void
|
2001-07-07 20:17:23 +08:00
|
|
|
gimp_free_select_tool_register (Gimp *gimp)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-07-07 20:17:23 +08:00
|
|
|
tool_manager_register_tool (gimp,
|
|
|
|
GIMP_TYPE_FREE_SELECT_TOOL,
|
|
|
|
FALSE,
|
2001-03-10 01:39:18 +08:00
|
|
|
"gimp:free_select_tool",
|
|
|
|
_("Free Select"),
|
|
|
|
_("Select hand-drawn regions"),
|
|
|
|
_("/Tools/Selection Tools/Free Select"), "F",
|
|
|
|
NULL, "tools/free_select.html",
|
2001-05-14 08:04:29 +08:00
|
|
|
(const gchar **) free_select_bits);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2001-03-10 01:39:18 +08:00
|
|
|
GtkType
|
|
|
|
gimp_free_select_tool_get_type (void)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-03-10 01:39:18 +08:00
|
|
|
static GtkType free_select_type = 0;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-03-10 01:39:18 +08:00
|
|
|
if (! free_select_type)
|
|
|
|
{
|
|
|
|
GtkTypeInfo free_select_info =
|
|
|
|
{
|
|
|
|
"GimpFreeSelectTool",
|
|
|
|
sizeof (GimpFreeSelectTool),
|
|
|
|
sizeof (GimpFreeSelectToolClass),
|
|
|
|
(GtkClassInitFunc) gimp_free_select_tool_class_init,
|
|
|
|
(GtkObjectInitFunc) gimp_free_select_tool_init,
|
|
|
|
/* reserved_1 */ NULL,
|
|
|
|
/* reserved_2 */ NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
free_select_type = gtk_type_unique (GIMP_TYPE_SELECTION_TOOL,
|
|
|
|
&free_select_info);
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-03-10 01:39:18 +08:00
|
|
|
return free_select_type;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
1999-04-19 05:22:41 +08:00
|
|
|
void
|
2001-05-26 02:10:38 +08:00
|
|
|
free_select (GimpImage *gimage,
|
|
|
|
gint n_points,
|
|
|
|
GimpVector2 *points,
|
|
|
|
SelectOps op,
|
|
|
|
gboolean antialias,
|
|
|
|
gboolean feather,
|
|
|
|
gdouble feather_radius)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-01-29 10:45:02 +08:00
|
|
|
GimpChannel *mask;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* if applicable, replace the current selection */
|
|
|
|
/* or insure that a floating selection is anchored down... */
|
2000-03-29 07:39:32 +08:00
|
|
|
if (op == SELECTION_REPLACE)
|
1997-11-25 06:05:25 +08:00
|
|
|
gimage_mask_clear (gimage);
|
|
|
|
else
|
|
|
|
gimage_mask_undo (gimage);
|
|
|
|
|
2001-05-26 02:10:38 +08:00
|
|
|
mask = scan_convert (gimage, n_points, points,
|
2000-03-29 07:39:32 +08:00
|
|
|
gimage->width, gimage->height, antialias);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
if (mask)
|
|
|
|
{
|
|
|
|
if (feather)
|
2001-01-29 10:45:02 +08:00
|
|
|
gimp_channel_feather (mask, gimp_image_get_mask (gimage),
|
|
|
|
feather_radius,
|
|
|
|
feather_radius,
|
|
|
|
op, 0, 0);
|
1997-11-25 06:05:25 +08:00
|
|
|
else
|
2001-01-29 10:45:02 +08:00
|
|
|
gimp_channel_combine_mask (gimp_image_get_mask (gimage),
|
|
|
|
mask, op, 0, 0);
|
2001-01-29 08:46:04 +08:00
|
|
|
|
|
|
|
gtk_object_unref (GTK_OBJECT (mask));
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-03-10 01:39:18 +08:00
|
|
|
|
|
|
|
/* private functions */
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_free_select_tool_class_init (GimpFreeSelectToolClass *klass)
|
|
|
|
{
|
|
|
|
GtkObjectClass *object_class;
|
|
|
|
GimpToolClass *tool_class;
|
|
|
|
GimpDrawToolClass *draw_tool_class;
|
|
|
|
|
|
|
|
object_class = (GtkObjectClass *) klass;
|
|
|
|
tool_class = (GimpToolClass *) klass;
|
|
|
|
draw_tool_class = (GimpDrawToolClass *) klass;
|
|
|
|
|
|
|
|
parent_class = gtk_type_class (GIMP_TYPE_SELECTION_TOOL);
|
|
|
|
|
|
|
|
object_class->destroy = gimp_free_select_tool_destroy;
|
|
|
|
|
|
|
|
tool_class->button_press = gimp_free_select_tool_button_press;
|
|
|
|
tool_class->button_release = gimp_free_select_tool_button_release;
|
|
|
|
tool_class->motion = gimp_free_select_tool_motion;
|
|
|
|
|
|
|
|
draw_tool_class->draw = gimp_free_select_tool_draw;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_free_select_tool_init (GimpFreeSelectTool *free_select)
|
|
|
|
{
|
|
|
|
GimpTool *tool;
|
|
|
|
GimpSelectionTool *select_tool;
|
|
|
|
|
|
|
|
tool = GIMP_TOOL (free_select);
|
|
|
|
select_tool = GIMP_SELECTION_TOOL (free_select);
|
|
|
|
|
|
|
|
if (! free_options)
|
|
|
|
{
|
|
|
|
free_options = selection_options_new (GIMP_TYPE_FREE_SELECT_TOOL,
|
2001-04-01 04:41:39 +08:00
|
|
|
selection_options_reset);
|
2001-03-10 01:39:18 +08:00
|
|
|
|
|
|
|
tool_manager_register_tool_options (GIMP_TYPE_FREE_SELECT_TOOL,
|
2001-07-18 04:50:01 +08:00
|
|
|
(GimpToolOptions *) free_options);
|
2001-03-10 01:39:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
tool->tool_cursor = GIMP_FREE_SELECT_TOOL_CURSOR;
|
|
|
|
tool->scroll_lock = TRUE; /* Do not allow scrolling */
|
|
|
|
|
|
|
|
free_select->points = NULL;
|
|
|
|
free_select->num_points = 0;
|
|
|
|
free_select->max_segs = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_free_select_tool_destroy (GtkObject *object)
|
|
|
|
{
|
|
|
|
GimpFreeSelectTool *free_sel;
|
|
|
|
|
|
|
|
free_sel = GIMP_FREE_SELECT_TOOL (object);
|
|
|
|
|
|
|
|
g_free (free_sel->points);
|
|
|
|
|
|
|
|
if (GTK_OBJECT_CLASS (parent_class)->destroy)
|
|
|
|
GTK_OBJECT_CLASS (parent_class)->destroy (object);
|
|
|
|
}
|
|
|
|
|
2000-12-31 12:07:42 +08:00
|
|
|
static void
|
2001-03-10 01:39:18 +08:00
|
|
|
gimp_free_select_tool_button_press (GimpTool *tool,
|
|
|
|
GdkEventButton *bevent,
|
|
|
|
GDisplay *gdisp)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-03-10 01:39:18 +08:00
|
|
|
GimpFreeSelectTool *free_sel;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-03-10 01:39:18 +08:00
|
|
|
free_sel = GIMP_FREE_SELECT_TOOL (tool);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
gdk_pointer_grab (gdisp->canvas->window, FALSE,
|
new ui for the "Layer Offset" dialog.
1999-07-22 Michael Natterer <mitschel@cs.tu-berlin.de>
* app/channel_ops.[ch]: new ui for the "Layer Offset" dialog.
* app/channels_dialog.c
* app/layers_dialog.c: major code cleanup: Folded some callbacks
into common ones, "widget" instead of "w", indentation, ...
* app/commands.c
* app/interface.[ch]
* app/global_edit.c: the query boxes must be shown by the caller
now. There's no need to split up the string for the message box
manually as the Gtk 1.2 label widget handles newlines corectly.
Added the "edge_lock" toggle to the "Shrink Selection" dialog.
Nicer spacings for the query and message boxes.
* app/ink.c: tried to grab the pointer in the blob preview but
failed. Left the code there as a reminder (commented out).
* app/menus.c: reordered <Image>/Select.
I was bored and grep-ed the sources for ancient or deprecated stuff:
* app/about_dialog.[ch]
* app/actionarea.[ch]
* app/app_procs.c
* app/brush_edit.c
* app/brush_select.c
* app/color_select.c
* app/convert.c
* app/devices.c
* app/gdisplay.c
* app/gdisplay_ops.c
* app/histogram_tool.[ch]
* app/info_window.c
* app/install.c
* app/ops_buttons.c
* app/palette.c
* app/palette_select.c
* app/paths_dialog.c
* app/pattern_select.c
* app/resize.c
* app/scale_toolc.c
* app/text_tool.c:
s/container_border_width/container_set_border_width/g,
s/sprintf/g_snprintf/g, replaced some constant string lengths with
strlen(x).
* app/bezier_select.c
* app/blend.c
* app/boundary.c
* app/errors.[ch]
* app/free_select.c
* app/gimpbrushlist.c
* app/gimprc.c
* app/iscissors.c
* app/main.c
* app/patterns.[ch]
* app/text_tool.c: namespace fanaticism: prefixed all gimp error
functions with "gimp_" and formated the messages more uniformly.
* app/gradient.c
* app/gradient_select.c: same stuff as above for the ui
code. There are still some sub-dialogs which need cleanup.
Did some cleanup in most of these files: prototypes, removed tons
of #include's, i18n fixes, s/w/widget/ as above, indentation, ...
1999-07-23 00:21:10 +08:00
|
|
|
GDK_POINTER_MOTION_HINT_MASK |
|
|
|
|
GDK_BUTTON1_MOTION_MASK |
|
|
|
|
GDK_BUTTON_RELEASE_MASK,
|
1997-11-25 06:05:25 +08:00
|
|
|
NULL, NULL, bevent->time);
|
|
|
|
|
|
|
|
tool->state = ACTIVE;
|
2000-12-31 12:07:42 +08:00
|
|
|
tool->gdisp = gdisp;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-03-10 01:39:18 +08:00
|
|
|
switch (GIMP_SELECTION_TOOL (tool)->op)
|
2000-03-29 07:39:32 +08:00
|
|
|
{
|
|
|
|
case SELECTION_MOVE_MASK:
|
2000-12-31 12:07:42 +08:00
|
|
|
init_edit_selection (tool, gdisp, bevent, EDIT_MASK_TRANSLATE);
|
2000-03-29 07:39:32 +08:00
|
|
|
return;
|
|
|
|
case SELECTION_MOVE:
|
2000-12-31 12:07:42 +08:00
|
|
|
init_edit_selection (tool, gdisp, bevent, EDIT_MASK_TO_LAYER_TRANSLATE);
|
2000-03-29 07:39:32 +08:00
|
|
|
return;
|
2000-04-07 02:59:48 +08:00
|
|
|
default:
|
2000-04-26 08:17:54 +08:00
|
|
|
break;
|
2000-03-29 07:39:32 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-03-10 01:39:18 +08:00
|
|
|
free_sel->num_points = 0;
|
|
|
|
|
|
|
|
gimp_free_select_tool_add_point (free_sel, bevent->x, bevent->y);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-03-10 01:39:18 +08:00
|
|
|
gimp_draw_tool_start (GIMP_DRAW_TOOL (tool),
|
|
|
|
gdisp->canvas->window);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2000-12-31 12:07:42 +08:00
|
|
|
static void
|
2001-03-10 01:39:18 +08:00
|
|
|
gimp_free_select_tool_button_release (GimpTool *tool,
|
|
|
|
GdkEventButton *bevent,
|
|
|
|
GDisplay *gdisp)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-03-10 01:39:18 +08:00
|
|
|
GimpFreeSelectTool *free_sel;
|
2001-05-26 02:10:38 +08:00
|
|
|
GimpVector2 *points;
|
2001-03-10 01:39:18 +08:00
|
|
|
gint i;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-03-10 01:39:18 +08:00
|
|
|
free_sel = GIMP_FREE_SELECT_TOOL (tool);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
gdk_pointer_ungrab (bevent->time);
|
|
|
|
gdk_flush ();
|
|
|
|
|
2001-03-10 01:39:18 +08:00
|
|
|
gimp_draw_tool_stop (GIMP_DRAW_TOOL (tool));
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
tool->state = INACTIVE;
|
|
|
|
|
|
|
|
/* First take care of the case where the user "cancels" the action */
|
|
|
|
if (! (bevent->state & GDK_BUTTON3_MASK))
|
|
|
|
{
|
2001-03-10 01:39:18 +08:00
|
|
|
if (free_sel->num_points == 1)
|
2000-07-30 00:12:40 +08:00
|
|
|
{
|
|
|
|
/* If there is a floating selection, anchor it */
|
2000-12-29 23:22:01 +08:00
|
|
|
if (gimp_image_floating_sel (gdisp->gimage))
|
|
|
|
floating_sel_anchor (gimp_image_floating_sel (gdisp->gimage));
|
2000-07-30 00:12:40 +08:00
|
|
|
/* Otherwise, clear the selection mask */
|
|
|
|
else
|
|
|
|
gimage_mask_clear (gdisp->gimage);
|
2001-03-10 01:39:18 +08:00
|
|
|
|
2000-07-30 00:12:40 +08:00
|
|
|
gdisplays_flush ();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-05-26 02:10:38 +08:00
|
|
|
points = g_new (GimpVector2, free_sel->num_points);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-03-10 01:39:18 +08:00
|
|
|
for (i = 0; i < free_sel->num_points; i++)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-03-10 01:39:18 +08:00
|
|
|
gdisplay_untransform_coords_f (gdisp,
|
|
|
|
free_sel->points[i].x,
|
|
|
|
free_sel->points[i].y,
|
2001-05-26 02:10:38 +08:00
|
|
|
&points[i].x,
|
|
|
|
&points[i].y,
|
2001-03-10 01:39:18 +08:00
|
|
|
FALSE);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2001-03-10 01:39:18 +08:00
|
|
|
free_select (gdisp->gimage,
|
2001-05-26 02:10:38 +08:00
|
|
|
free_sel->num_points, points,
|
2001-03-10 01:39:18 +08:00
|
|
|
GIMP_SELECTION_TOOL (tool)->op,
|
|
|
|
free_options->antialias,
|
|
|
|
free_options->feather,
|
1997-11-25 06:05:25 +08:00
|
|
|
free_options->feather_radius);
|
|
|
|
|
2001-05-26 02:10:38 +08:00
|
|
|
g_free (points);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
gdisplays_flush ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-12-31 12:07:42 +08:00
|
|
|
static void
|
2001-03-10 01:39:18 +08:00
|
|
|
gimp_free_select_tool_motion (GimpTool *tool,
|
|
|
|
GdkEventMotion *mevent,
|
|
|
|
GDisplay *gdisp)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-03-10 01:39:18 +08:00
|
|
|
GimpFreeSelectTool *free_sel;
|
|
|
|
GimpSelectionTool *sel_tool;
|
|
|
|
GimpDrawTool *draw_tool;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-03-10 01:39:18 +08:00
|
|
|
free_sel = GIMP_FREE_SELECT_TOOL (tool);
|
|
|
|
sel_tool = GIMP_SELECTION_TOOL (tool);
|
|
|
|
draw_tool = GIMP_DRAW_TOOL (tool);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-03-02 07:22:43 +08:00
|
|
|
/* needed for immediate cursor update on modifier event */
|
2001-03-10 01:39:18 +08:00
|
|
|
sel_tool->current_x = mevent->x;
|
|
|
|
sel_tool->current_y = mevent->y;
|
2000-03-02 07:22:43 +08:00
|
|
|
|
|
|
|
if (tool->state != ACTIVE)
|
|
|
|
return;
|
|
|
|
|
2001-03-10 01:39:18 +08:00
|
|
|
if (sel_tool->op == SELECTION_ANCHOR)
|
2000-07-30 00:12:40 +08:00
|
|
|
{
|
2001-03-10 01:39:18 +08:00
|
|
|
sel_tool->op = SELECTION_REPLACE;
|
2000-07-30 00:12:40 +08:00
|
|
|
|
2001-03-10 01:39:18 +08:00
|
|
|
gimp_tool_cursor_update (tool, mevent, gdisp);
|
2000-07-30 00:12:40 +08:00
|
|
|
}
|
|
|
|
|
2001-03-10 01:39:18 +08:00
|
|
|
gimp_free_select_tool_add_point (free_sel, mevent->x, mevent->y);
|
1999-05-02 05:37:34 +08:00
|
|
|
|
2001-03-10 01:39:18 +08:00
|
|
|
gdk_draw_line (draw_tool->win,
|
|
|
|
draw_tool->gc,
|
|
|
|
free_sel->points[free_sel->num_points - 2].x,
|
|
|
|
free_sel->points[free_sel->num_points - 2].y,
|
|
|
|
free_sel->points[free_sel->num_points - 1].x,
|
|
|
|
free_sel->points[free_sel->num_points - 1].y);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2001-03-10 01:39:18 +08:00
|
|
|
gimp_free_select_tool_draw (GimpDrawTool *draw_tool)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-03-10 01:39:18 +08:00
|
|
|
GimpFreeSelectTool *free_sel;
|
|
|
|
gint i;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-03-10 01:39:18 +08:00
|
|
|
free_sel = GIMP_FREE_SELECT_TOOL (draw_tool);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-03-10 01:39:18 +08:00
|
|
|
for (i = 1; i < free_sel->num_points; i++)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-03-10 01:39:18 +08:00
|
|
|
gdk_draw_line (draw_tool->win,
|
|
|
|
draw_tool->gc,
|
|
|
|
free_sel->points[i - 1].x,
|
|
|
|
free_sel->points[i - 1].y,
|
|
|
|
free_sel->points[i].x,
|
|
|
|
free_sel->points[i].y);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-03-10 01:39:18 +08:00
|
|
|
static void
|
|
|
|
gimp_free_select_tool_add_point (GimpFreeSelectTool *free_sel,
|
|
|
|
gint x,
|
|
|
|
gint y)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-03-10 01:39:18 +08:00
|
|
|
if (free_sel->num_points >= free_sel->max_segs)
|
1999-04-13 01:55:06 +08:00
|
|
|
{
|
2001-03-10 01:39:18 +08:00
|
|
|
free_sel->max_segs += DEFAULT_MAX_INC;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-03-10 01:39:18 +08:00
|
|
|
free_sel->points = (GdkPoint *)
|
|
|
|
g_realloc ((void *) free_sel->points,
|
|
|
|
sizeof (GdkPoint) * free_sel->max_segs);
|
1999-07-03 01:40:10 +08:00
|
|
|
|
2001-03-10 01:39:18 +08:00
|
|
|
if (! free_sel->points)
|
|
|
|
gimp_fatal_error ("%s(): Unable to reallocate points array",
|
|
|
|
G_GNUC_FUNCTION);
|
|
|
|
}
|
2001-02-25 03:29:47 +08:00
|
|
|
|
2001-03-10 01:39:18 +08:00
|
|
|
free_sel->points[free_sel->num_points].x = x;
|
|
|
|
free_sel->points[free_sel->num_points].y = y;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-03-10 01:39:18 +08:00
|
|
|
free_sel->num_points++;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2001-03-10 01:39:18 +08:00
|
|
|
static GimpChannel *
|
2001-05-26 02:10:38 +08:00
|
|
|
scan_convert (GimpImage *gimage,
|
|
|
|
gint n_points,
|
|
|
|
GimpVector2 *points,
|
|
|
|
gint width,
|
|
|
|
gint height,
|
|
|
|
gboolean antialias)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-05-26 02:10:38 +08:00
|
|
|
GimpChannel *mask;
|
|
|
|
GimpScanConvert *sc;
|
|
|
|
|
|
|
|
sc = gimp_scan_convert_new (width, height, antialias ? SUPERSAMPLE : 1);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-05-26 02:10:38 +08:00
|
|
|
gimp_scan_convert_add_points (sc, n_points, points);
|
|
|
|
mask = gimp_scan_convert_to_channel (sc, gimage);
|
2001-03-10 01:39:18 +08:00
|
|
|
|
2001-05-26 02:10:38 +08:00
|
|
|
gimp_scan_convert_free (sc);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-03-10 01:39:18 +08:00
|
|
|
return mask;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|