2002-02-22 08:11:37 +08:00
|
|
|
/* The GIMP -- an image manipulation program
|
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
|
|
|
* Vector tool
|
2003-08-17 10:49:24 +08:00
|
|
|
* Copyright (C) 2003 Simon Budig <simon@gimp.org>
|
2002-02-22 08:11:37 +08:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
|
|
|
#include "libgimpmath/gimpmath.h"
|
|
|
|
#include "libgimpbase/gimpbase.h"
|
|
|
|
#include "libgimpwidgets/gimpwidgets.h"
|
|
|
|
|
2002-05-03 20:45:22 +08:00
|
|
|
#include "tools-types.h"
|
2002-02-22 08:11:37 +08:00
|
|
|
|
2002-02-26 11:19:47 +08:00
|
|
|
#include "core/gimp.h"
|
|
|
|
#include "core/gimpcontext.h"
|
2002-02-22 08:11:37 +08:00
|
|
|
#include "core/gimpimage.h"
|
2003-09-02 01:10:55 +08:00
|
|
|
#include "core/gimpimage-undo-push.h"
|
2002-05-09 01:48:24 +08:00
|
|
|
#include "core/gimplist.h"
|
2002-02-22 08:11:37 +08:00
|
|
|
#include "core/gimptoolinfo.h"
|
|
|
|
|
|
|
|
#include "vectors/gimpanchor.h"
|
|
|
|
#include "vectors/gimpvectors.h"
|
2002-02-25 11:16:41 +08:00
|
|
|
#include "vectors/gimpbezierstroke.h"
|
2002-02-22 08:11:37 +08:00
|
|
|
|
2003-08-22 09:42:57 +08:00
|
|
|
#include "widgets/gimphelp-ids.h"
|
|
|
|
|
2002-02-22 08:11:37 +08:00
|
|
|
#include "display/gimpdisplay.h"
|
|
|
|
#include "display/gimpdisplay-foreach.h"
|
|
|
|
|
2003-04-16 00:05:52 +08:00
|
|
|
#include "gimptoolcontrol.h"
|
2003-02-05 22:39:40 +08:00
|
|
|
#include "gimpvectoroptions.h"
|
2002-02-22 08:11:37 +08:00
|
|
|
#include "gimpvectortool.h"
|
|
|
|
|
2003-03-26 00:38:19 +08:00
|
|
|
#include "gimp-intl.h"
|
2002-02-22 08:11:37 +08:00
|
|
|
|
|
|
|
|
2003-04-14 22:52:00 +08:00
|
|
|
#define TARGET 9
|
2002-02-22 08:11:37 +08:00
|
|
|
|
2003-08-30 03:55:32 +08:00
|
|
|
#define TOGGLE_MASK GDK_SHIFT_MASK
|
|
|
|
#define MOVE_MASK GDK_MOD1_MASK
|
|
|
|
#define INSDEL_MASK GDK_CONTROL_MASK
|
|
|
|
|
2002-02-22 08:11:37 +08:00
|
|
|
|
|
|
|
/* local function prototypes */
|
2003-02-05 22:39:40 +08:00
|
|
|
|
2002-02-22 08:11:37 +08:00
|
|
|
static void gimp_vector_tool_class_init (GimpVectorToolClass *klass);
|
|
|
|
static void gimp_vector_tool_init (GimpVectorTool *tool);
|
|
|
|
|
|
|
|
static void gimp_vector_tool_control (GimpTool *tool,
|
|
|
|
GimpToolAction action,
|
|
|
|
GimpDisplay *gdisp);
|
|
|
|
static void gimp_vector_tool_button_press (GimpTool *tool,
|
|
|
|
GimpCoords *coords,
|
|
|
|
guint32 time,
|
|
|
|
GdkModifierType state,
|
|
|
|
GimpDisplay *gdisp);
|
|
|
|
static void gimp_vector_tool_button_release (GimpTool *tool,
|
|
|
|
GimpCoords *coords,
|
|
|
|
guint32 time,
|
|
|
|
GdkModifierType state,
|
|
|
|
GimpDisplay *gdisp);
|
|
|
|
static void gimp_vector_tool_motion (GimpTool *tool,
|
|
|
|
GimpCoords *coords,
|
|
|
|
guint32 time,
|
|
|
|
GdkModifierType state,
|
|
|
|
GimpDisplay *gdisp);
|
2003-08-30 03:55:32 +08:00
|
|
|
static void gimp_vector_tool_modifier_key (GimpTool *tool,
|
|
|
|
GdkModifierType key,
|
|
|
|
gboolean press,
|
|
|
|
GdkModifierType state,
|
|
|
|
GimpDisplay *gdisp);
|
2003-08-17 10:49:24 +08:00
|
|
|
static void gimp_vector_tool_oper_update (GimpTool *tool,
|
|
|
|
GimpCoords *coords,
|
|
|
|
GdkModifierType state,
|
|
|
|
GimpDisplay *gdisp);
|
2002-02-22 08:11:37 +08:00
|
|
|
static void gimp_vector_tool_cursor_update (GimpTool *tool,
|
|
|
|
GimpCoords *coords,
|
|
|
|
GdkModifierType state,
|
|
|
|
GimpDisplay *gdisp);
|
|
|
|
|
2003-06-25 07:11:13 +08:00
|
|
|
static gboolean gimp_vector_tool_on_handle (GimpTool *tool,
|
2003-04-14 08:37:04 +08:00
|
|
|
GimpCoords *coords,
|
|
|
|
GimpAnchorType preferred,
|
2003-06-25 07:11:13 +08:00
|
|
|
GimpDisplay *gdisp,
|
|
|
|
GimpAnchor **ret_anchor,
|
|
|
|
GimpStroke **ret_stroke);
|
2003-08-21 01:29:13 +08:00
|
|
|
static gboolean gimp_vector_tool_on_curve (GimpTool *tool,
|
|
|
|
GimpCoords *coord,
|
|
|
|
GimpDisplay *gdisp,
|
|
|
|
GimpCoords *ret_coords,
|
|
|
|
gdouble *ret_pos,
|
|
|
|
GimpAnchor **ret_segment_start,
|
|
|
|
GimpStroke **ret_stroke);
|
2003-04-14 08:37:04 +08:00
|
|
|
|
2002-02-22 08:11:37 +08:00
|
|
|
static void gimp_vector_tool_draw (GimpDrawTool *draw_tool);
|
|
|
|
|
2003-04-14 22:52:00 +08:00
|
|
|
static void gimp_vector_tool_clear_vectors (GimpVectorTool *vector_tool);
|
2003-05-09 08:38:51 +08:00
|
|
|
|
|
|
|
static void gimp_vector_tool_vectors_freeze (GimpVectors *vectors,
|
|
|
|
GimpVectorTool *vector_tool);
|
|
|
|
static void gimp_vector_tool_vectors_thaw (GimpVectors *vectors,
|
2003-04-14 22:52:00 +08:00
|
|
|
GimpVectorTool *vector_tool);
|
|
|
|
|
2002-02-22 08:11:37 +08:00
|
|
|
|
2002-03-03 18:38:37 +08:00
|
|
|
static GimpSelectionToolClass *parent_class = NULL;
|
2002-02-22 08:11:37 +08:00
|
|
|
|
|
|
|
|
|
|
|
void
|
2002-03-29 11:50:29 +08:00
|
|
|
gimp_vector_tool_register (GimpToolRegisterCallback callback,
|
2002-05-03 19:31:08 +08:00
|
|
|
gpointer data)
|
2002-02-22 08:11:37 +08:00
|
|
|
{
|
2002-03-29 11:50:29 +08:00
|
|
|
(* callback) (GIMP_TYPE_VECTOR_TOOL,
|
2003-02-05 22:39:40 +08:00
|
|
|
GIMP_TYPE_VECTOR_OPTIONS,
|
|
|
|
gimp_vector_options_gui,
|
2003-06-28 19:20:37 +08:00
|
|
|
0,
|
2003-08-22 01:47:12 +08:00
|
|
|
"gimp-path-tool",
|
|
|
|
_("Paths"),
|
|
|
|
_("Create and edit paths"),
|
|
|
|
N_("/Tools/_Paths"), NULL,
|
2003-08-22 09:42:57 +08:00
|
|
|
NULL, GIMP_HELP_TOOL_PATH,
|
2002-03-29 11:50:29 +08:00
|
|
|
GIMP_STOCK_TOOL_PATH,
|
2002-05-03 19:31:08 +08:00
|
|
|
data);
|
2002-02-22 08:11:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
GType
|
|
|
|
gimp_vector_tool_get_type (void)
|
|
|
|
{
|
|
|
|
static GType tool_type = 0;
|
|
|
|
|
|
|
|
if (! tool_type)
|
|
|
|
{
|
|
|
|
static const GTypeInfo tool_info =
|
|
|
|
{
|
|
|
|
sizeof (GimpVectorToolClass),
|
|
|
|
(GBaseInitFunc) NULL,
|
|
|
|
(GBaseFinalizeFunc) NULL,
|
|
|
|
(GClassInitFunc) gimp_vector_tool_class_init,
|
|
|
|
NULL, /* class_finalize */
|
|
|
|
NULL, /* class_data */
|
|
|
|
sizeof (GimpVectorTool),
|
|
|
|
0, /* n_preallocs */
|
|
|
|
(GInstanceInitFunc) gimp_vector_tool_init,
|
|
|
|
};
|
|
|
|
|
2002-03-03 18:38:37 +08:00
|
|
|
tool_type = g_type_register_static (GIMP_TYPE_SELECTION_TOOL,
|
2003-08-22 09:42:57 +08:00
|
|
|
"GimpVectorTool",
|
2002-02-22 08:11:37 +08:00
|
|
|
&tool_info, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
return tool_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_vector_tool_class_init (GimpVectorToolClass *klass)
|
|
|
|
{
|
2002-02-26 08:58:04 +08:00
|
|
|
GObjectClass *object_class;
|
2002-02-22 08:11:37 +08:00
|
|
|
GimpToolClass *tool_class;
|
|
|
|
GimpDrawToolClass *draw_tool_class;
|
|
|
|
|
2002-02-26 08:58:04 +08:00
|
|
|
object_class = G_OBJECT_CLASS (klass);
|
2002-02-22 08:11:37 +08:00
|
|
|
tool_class = GIMP_TOOL_CLASS (klass);
|
|
|
|
draw_tool_class = GIMP_DRAW_TOOL_CLASS (klass);
|
|
|
|
|
|
|
|
parent_class = g_type_class_peek_parent (klass);
|
|
|
|
|
|
|
|
tool_class->control = gimp_vector_tool_control;
|
|
|
|
tool_class->button_press = gimp_vector_tool_button_press;
|
|
|
|
tool_class->button_release = gimp_vector_tool_button_release;
|
|
|
|
tool_class->motion = gimp_vector_tool_motion;
|
2003-08-30 03:55:32 +08:00
|
|
|
tool_class->modifier_key = gimp_vector_tool_modifier_key;
|
2003-08-17 10:49:24 +08:00
|
|
|
tool_class->oper_update = gimp_vector_tool_oper_update;
|
2002-02-22 08:11:37 +08:00
|
|
|
tool_class->cursor_update = gimp_vector_tool_cursor_update;
|
|
|
|
|
|
|
|
draw_tool_class->draw = gimp_vector_tool_draw;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_vector_tool_init (GimpVectorTool *vector_tool)
|
|
|
|
{
|
|
|
|
GimpTool *tool;
|
|
|
|
|
|
|
|
tool = GIMP_TOOL (vector_tool);
|
|
|
|
|
2002-05-03 05:03:27 +08:00
|
|
|
gimp_tool_control_set_scroll_lock (tool->control, TRUE);
|
2003-09-04 03:52:46 +08:00
|
|
|
gimp_tool_control_set_motion_mode (tool->control, GIMP_MOTION_MODE_COMPRESS);
|
2003-08-22 09:42:57 +08:00
|
|
|
|
2003-08-17 10:49:24 +08:00
|
|
|
vector_tool->function = VECTORS_CREATE_VECTOR;
|
2003-08-30 03:55:32 +08:00
|
|
|
vector_tool->restriction = GIMP_ANCHOR_FEATURE_NONE;
|
|
|
|
vector_tool->modifier_lock = 0;
|
2003-01-10 21:26:47 +08:00
|
|
|
vector_tool->last_x = 0;
|
|
|
|
vector_tool->last_y = 0;
|
|
|
|
|
|
|
|
vector_tool->cur_anchor = NULL;
|
|
|
|
vector_tool->cur_stroke = NULL;
|
2003-09-04 03:52:46 +08:00
|
|
|
vector_tool->cur_position = 0;
|
2003-01-10 21:26:47 +08:00
|
|
|
vector_tool->vectors = NULL;
|
2003-09-04 03:52:46 +08:00
|
|
|
|
|
|
|
vector_tool->sel_count = 0;
|
|
|
|
vector_tool->sel_anchor = NULL;
|
|
|
|
vector_tool->sel_stroke = NULL;
|
2002-02-22 08:11:37 +08:00
|
|
|
}
|
|
|
|
|
2002-02-26 08:58:04 +08:00
|
|
|
|
2002-02-22 08:11:37 +08:00
|
|
|
static void
|
|
|
|
gimp_vector_tool_control (GimpTool *tool,
|
2003-01-10 21:26:47 +08:00
|
|
|
GimpToolAction action,
|
|
|
|
GimpDisplay *gdisp)
|
2002-02-22 08:11:37 +08:00
|
|
|
{
|
|
|
|
GimpVectorTool *vector_tool;
|
|
|
|
|
|
|
|
vector_tool = GIMP_VECTOR_TOOL (tool);
|
|
|
|
|
|
|
|
switch (action)
|
|
|
|
{
|
|
|
|
case PAUSE:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RESUME:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case HALT:
|
2003-03-29 12:47:44 +08:00
|
|
|
/* gimp_tool_pop_status (tool); */
|
2003-04-14 08:37:04 +08:00
|
|
|
gimp_vector_tool_clear_vectors (vector_tool);
|
2002-02-22 08:11:37 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
GIMP_TOOL_CLASS (parent_class)->control (tool, action, gdisp);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_vector_tool_button_press (GimpTool *tool,
|
2002-12-29 07:52:29 +08:00
|
|
|
GimpCoords *coords,
|
|
|
|
guint32 time,
|
|
|
|
GdkModifierType state,
|
|
|
|
GimpDisplay *gdisp)
|
2002-02-22 08:11:37 +08:00
|
|
|
{
|
2003-08-19 02:05:57 +08:00
|
|
|
GimpDrawTool *draw_tool;
|
2003-02-05 22:39:40 +08:00
|
|
|
GimpVectorTool *vector_tool;
|
|
|
|
GimpVectorOptions *options;
|
2003-08-17 10:49:24 +08:00
|
|
|
GimpVectors *vectors;
|
2003-08-19 02:05:57 +08:00
|
|
|
GimpStroke *stroke = NULL;
|
|
|
|
GimpAnchor *anchor = NULL;
|
2003-06-25 07:11:13 +08:00
|
|
|
GimpAnchorType preferred = GIMP_ANCHOR_ANCHOR;
|
2002-02-22 08:11:37 +08:00
|
|
|
|
2003-08-19 02:05:57 +08:00
|
|
|
draw_tool = GIMP_DRAW_TOOL (tool);
|
2002-02-22 08:11:37 +08:00
|
|
|
vector_tool = GIMP_VECTOR_TOOL (tool);
|
2003-02-05 22:39:40 +08:00
|
|
|
options = GIMP_VECTOR_OPTIONS (tool->tool_info->tool_options);
|
2002-02-22 08:11:37 +08:00
|
|
|
|
2003-08-30 03:55:32 +08:00
|
|
|
/* Save the current modifier state */
|
|
|
|
|
|
|
|
vector_tool->saved_state = state;
|
2003-06-25 07:11:13 +08:00
|
|
|
|
2003-08-22 09:42:57 +08:00
|
|
|
/* if we are changing displays, pop the statusbar of the old one */
|
2003-08-19 02:05:57 +08:00
|
|
|
if (gdisp != tool->gdisp)
|
2002-02-22 08:11:37 +08:00
|
|
|
{
|
2003-03-29 12:47:44 +08:00
|
|
|
/* gimp_tool_pop_status (tool); */
|
2002-02-22 08:11:37 +08:00
|
|
|
}
|
2003-04-14 22:52:00 +08:00
|
|
|
|
2003-08-19 02:05:57 +08:00
|
|
|
gimp_draw_tool_pause (draw_tool);
|
|
|
|
|
2003-03-20 07:51:43 +08:00
|
|
|
if (vector_tool->vectors &&
|
|
|
|
gdisp->gimage != GIMP_ITEM (vector_tool->vectors)->gimage)
|
2003-08-19 02:05:57 +08:00
|
|
|
{
|
|
|
|
g_print ("calling clear_vectors\n");
|
|
|
|
gimp_vector_tool_clear_vectors (vector_tool);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gimp_draw_tool_is_active (draw_tool) && draw_tool->gdisp != gdisp)
|
|
|
|
{
|
|
|
|
g_print ("calling draw_tool_stop\n");
|
|
|
|
gimp_draw_tool_stop (draw_tool);
|
|
|
|
}
|
2003-03-20 07:51:43 +08:00
|
|
|
|
2003-09-02 01:10:55 +08:00
|
|
|
gimp_tool_control_set_preserve (tool->control, TRUE);
|
|
|
|
if (vector_tool->vectors)
|
|
|
|
gimp_image_undo_push_vectors_mod (GIMP_ITEM (vector_tool->vectors)->gimage,
|
|
|
|
"Vectors operation",
|
|
|
|
vector_tool->vectors);
|
|
|
|
gimp_tool_control_set_preserve (tool->control, FALSE);
|
|
|
|
|
2003-08-18 07:19:09 +08:00
|
|
|
gimp_tool_control_activate (tool->control);
|
2003-06-26 17:54:56 +08:00
|
|
|
tool->gdisp = gdisp;
|
|
|
|
|
2003-09-04 03:52:46 +08:00
|
|
|
/* Insertion of an anchor in a curve segment */
|
|
|
|
|
|
|
|
if (vector_tool->function == VECTORS_INSERT_ANCHOR)
|
2003-08-21 01:29:13 +08:00
|
|
|
{
|
2003-09-04 03:52:46 +08:00
|
|
|
anchor = gimp_stroke_anchor_insert (vector_tool->cur_stroke,
|
|
|
|
vector_tool->cur_anchor,
|
|
|
|
vector_tool->cur_position);
|
|
|
|
if (anchor)
|
2003-08-21 01:29:13 +08:00
|
|
|
{
|
2003-09-04 03:52:46 +08:00
|
|
|
vector_tool->cur_anchor = anchor;
|
|
|
|
if (options->polygonal)
|
2003-08-21 01:29:13 +08:00
|
|
|
{
|
2003-09-04 03:52:46 +08:00
|
|
|
gimp_stroke_anchor_convert (vector_tool->cur_stroke,
|
|
|
|
vector_tool->cur_anchor,
|
|
|
|
GIMP_ANCHOR_FEATURE_EDGE);
|
2003-08-21 01:29:13 +08:00
|
|
|
}
|
2003-09-04 03:52:46 +08:00
|
|
|
vector_tool->function = VECTORS_MOVE_ANCHOR;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
vector_tool->function = VECTORS_FINISHED;
|
|
|
|
}
|
|
|
|
}
|
2003-08-21 01:29:13 +08:00
|
|
|
|
|
|
|
|
2003-09-04 03:52:46 +08:00
|
|
|
/* removal of a node in a stroke */
|
2003-08-22 01:47:12 +08:00
|
|
|
|
2003-09-04 03:52:46 +08:00
|
|
|
if (vector_tool->function == VECTORS_DELETE_ANCHOR)
|
|
|
|
{
|
|
|
|
gimp_stroke_anchor_delete (vector_tool->cur_stroke,
|
|
|
|
vector_tool->cur_anchor);
|
2003-08-22 01:47:12 +08:00
|
|
|
|
2003-09-04 03:52:46 +08:00
|
|
|
if (gimp_stroke_is_empty (vector_tool->cur_stroke))
|
|
|
|
gimp_vectors_stroke_remove (vector_tool->vectors,
|
|
|
|
vector_tool->cur_stroke);
|
2003-08-22 09:42:57 +08:00
|
|
|
|
2003-09-04 03:52:46 +08:00
|
|
|
vector_tool->cur_stroke = NULL;
|
|
|
|
vector_tool->cur_anchor = NULL;
|
|
|
|
vector_tool->function = VECTORS_FINISHED;
|
|
|
|
}
|
2003-08-22 01:47:12 +08:00
|
|
|
|
2003-08-22 09:12:26 +08:00
|
|
|
|
2003-09-04 03:52:46 +08:00
|
|
|
/* deleting a segment (opening up a stroke) */
|
2003-08-22 09:12:26 +08:00
|
|
|
|
2003-09-04 03:52:46 +08:00
|
|
|
if (vector_tool->function == VECTORS_DELETE_SEGMENT)
|
|
|
|
{
|
|
|
|
GimpStroke *new_stroke;
|
|
|
|
new_stroke = gimp_stroke_open (vector_tool->cur_stroke,
|
|
|
|
vector_tool->cur_anchor);
|
|
|
|
if (new_stroke)
|
|
|
|
gimp_vectors_stroke_add (vector_tool->vectors, new_stroke);
|
|
|
|
|
|
|
|
vector_tool->cur_stroke = NULL;
|
|
|
|
vector_tool->cur_anchor = NULL;
|
|
|
|
vector_tool->function = VECTORS_FINISHED;
|
2003-08-21 01:29:13 +08:00
|
|
|
}
|
|
|
|
|
2003-08-17 10:49:24 +08:00
|
|
|
|
2003-09-04 03:52:46 +08:00
|
|
|
/* create a new vector from scratch */
|
|
|
|
|
|
|
|
if (vector_tool->function == VECTORS_CREATE_VECTOR)
|
|
|
|
{
|
2003-08-17 10:49:24 +08:00
|
|
|
vectors = gimp_vectors_new (gdisp->gimage, _("Unnamed"));
|
|
|
|
|
2003-08-19 02:05:57 +08:00
|
|
|
gimp_tool_control_set_preserve (tool->control, TRUE);
|
|
|
|
|
2003-08-17 10:49:24 +08:00
|
|
|
gimp_image_add_vectors (gdisp->gimage, vectors, -1);
|
|
|
|
gimp_image_flush (gdisp->gimage);
|
|
|
|
|
2003-08-19 02:05:57 +08:00
|
|
|
gimp_tool_control_set_preserve (tool->control, FALSE);
|
|
|
|
|
2003-08-17 10:49:24 +08:00
|
|
|
gimp_vector_tool_set_vectors (vector_tool, vectors);
|
|
|
|
|
|
|
|
vector_tool->function = VECTORS_CREATE_STROKE;
|
2003-09-04 03:52:46 +08:00
|
|
|
}
|
2003-08-17 10:49:24 +08:00
|
|
|
|
2003-09-04 03:52:46 +08:00
|
|
|
/* create a new stroke */
|
2003-08-17 10:49:24 +08:00
|
|
|
|
2003-09-04 03:52:46 +08:00
|
|
|
if (vector_tool->function == VECTORS_CREATE_STROKE)
|
|
|
|
{
|
2003-08-17 10:49:24 +08:00
|
|
|
g_return_if_fail (vector_tool->vectors != NULL);
|
2003-01-10 21:26:47 +08:00
|
|
|
|
2003-05-19 07:08:01 +08:00
|
|
|
stroke = gimp_bezier_stroke_new ();
|
2002-02-25 11:16:41 +08:00
|
|
|
gimp_vectors_stroke_add (vector_tool->vectors, stroke);
|
|
|
|
|
2003-08-17 10:49:24 +08:00
|
|
|
vector_tool->cur_stroke = stroke;
|
|
|
|
vector_tool->cur_anchor = NULL;
|
2003-09-04 03:52:46 +08:00
|
|
|
vector_tool->sel_stroke = stroke;
|
|
|
|
vector_tool->sel_anchor = NULL;
|
2003-08-17 10:49:24 +08:00
|
|
|
vector_tool->function = VECTORS_ADD_ANCHOR;
|
2003-09-04 03:52:46 +08:00
|
|
|
}
|
2002-02-26 08:58:04 +08:00
|
|
|
|
2003-09-04 03:52:46 +08:00
|
|
|
/* add an anchor to an existing stroke */
|
2002-02-26 08:58:04 +08:00
|
|
|
|
2003-09-04 03:52:46 +08:00
|
|
|
if (vector_tool->function == VECTORS_ADD_ANCHOR)
|
|
|
|
{
|
|
|
|
anchor = gimp_bezier_stroke_extend (vector_tool->sel_stroke, coords,
|
|
|
|
vector_tool->sel_anchor,
|
2003-06-25 07:11:13 +08:00
|
|
|
EXTEND_EDITABLE);
|
2002-02-22 08:11:37 +08:00
|
|
|
|
2003-06-26 17:54:56 +08:00
|
|
|
vector_tool->restriction = GIMP_ANCHOR_FEATURE_SYMMETRIC;
|
|
|
|
|
2003-08-21 06:19:37 +08:00
|
|
|
if (!options->polygonal)
|
|
|
|
vector_tool->function = VECTORS_MOVE_HANDLE;
|
|
|
|
else
|
|
|
|
vector_tool->function = VECTORS_MOVE_ANCHOR;
|
2003-08-17 10:49:24 +08:00
|
|
|
vector_tool->cur_anchor = anchor;
|
2003-09-04 03:52:46 +08:00
|
|
|
vector_tool->cur_stroke = vector_tool->sel_stroke;
|
|
|
|
}
|
2003-06-26 17:54:56 +08:00
|
|
|
|
2003-09-04 03:52:46 +08:00
|
|
|
/* move a handle */
|
2003-06-26 17:54:56 +08:00
|
|
|
|
2003-09-04 03:52:46 +08:00
|
|
|
if (vector_tool->function == VECTORS_MOVE_HANDLE)
|
|
|
|
{
|
2003-08-21 06:19:37 +08:00
|
|
|
if (!options->polygonal)
|
|
|
|
preferred = GIMP_ANCHOR_CONTROL;
|
2003-09-04 03:52:46 +08:00
|
|
|
}
|
2003-06-26 17:54:56 +08:00
|
|
|
|
2003-09-04 03:52:46 +08:00
|
|
|
/* move a handle or an anchor */
|
2003-08-17 10:49:24 +08:00
|
|
|
|
2003-09-04 03:52:46 +08:00
|
|
|
if (vector_tool->function == VECTORS_MOVE_ANCHOR ||
|
|
|
|
vector_tool->function == VECTORS_MOVE_HANDLE)
|
|
|
|
{
|
2003-08-17 10:49:24 +08:00
|
|
|
gimp_vector_tool_on_handle (tool, coords,
|
2003-09-04 03:52:46 +08:00
|
|
|
preferred, gdisp,
|
|
|
|
&(vector_tool->cur_anchor),
|
|
|
|
&(vector_tool->cur_stroke));
|
2003-08-17 10:49:24 +08:00
|
|
|
|
2003-09-04 03:52:46 +08:00
|
|
|
if (vector_tool->cur_anchor &&
|
|
|
|
vector_tool->cur_anchor->type == GIMP_ANCHOR_ANCHOR &&
|
|
|
|
vector_tool->cur_stroke)
|
2003-06-26 17:54:56 +08:00
|
|
|
{
|
2003-09-04 03:52:46 +08:00
|
|
|
gimp_vectors_anchor_select (vector_tool->vectors,
|
|
|
|
vector_tool->cur_stroke,
|
|
|
|
vector_tool->cur_anchor, TRUE);
|
2003-08-22 09:42:57 +08:00
|
|
|
|
2003-06-26 17:54:56 +08:00
|
|
|
/* if the selected anchor changed, the visible control
|
2003-08-21 06:19:37 +08:00
|
|
|
* points might have changed too */
|
2003-08-17 10:49:24 +08:00
|
|
|
if (vector_tool->function == VECTORS_MOVE_HANDLE)
|
2003-09-04 03:52:46 +08:00
|
|
|
{
|
|
|
|
gimp_vector_tool_on_handle (tool, coords, GIMP_ANCHOR_CONTROL,
|
|
|
|
gdisp, &anchor, &stroke);
|
|
|
|
vector_tool->cur_stroke = stroke;
|
|
|
|
vector_tool->cur_anchor = anchor;
|
|
|
|
}
|
2003-06-26 17:54:56 +08:00
|
|
|
}
|
2003-09-04 03:52:46 +08:00
|
|
|
}
|
2003-08-22 09:42:57 +08:00
|
|
|
|
2003-09-04 03:52:46 +08:00
|
|
|
/* connect two strokes */
|
2003-08-22 09:42:57 +08:00
|
|
|
|
2003-09-04 03:52:46 +08:00
|
|
|
if (vector_tool->function == VECTORS_CONNECT_STROKES)
|
|
|
|
{
|
|
|
|
gimp_stroke_connect_stroke (vector_tool->sel_stroke,
|
|
|
|
vector_tool->sel_anchor,
|
|
|
|
vector_tool->cur_stroke,
|
|
|
|
vector_tool->cur_anchor);
|
|
|
|
if (vector_tool->cur_stroke != vector_tool->sel_stroke &&
|
|
|
|
gimp_stroke_is_empty (vector_tool->cur_stroke))
|
2003-08-29 23:17:06 +08:00
|
|
|
{
|
2003-09-04 03:52:46 +08:00
|
|
|
gimp_vectors_stroke_remove (vector_tool->vectors,
|
|
|
|
vector_tool->cur_stroke);
|
2003-08-27 08:31:20 +08:00
|
|
|
}
|
2003-09-04 03:52:46 +08:00
|
|
|
|
|
|
|
vector_tool->function = VECTORS_FINISHED;
|
|
|
|
}
|
2003-08-29 23:17:06 +08:00
|
|
|
|
2003-09-04 03:52:46 +08:00
|
|
|
/* move a curve segment directly */
|
2003-08-29 23:17:06 +08:00
|
|
|
|
2003-09-04 03:52:46 +08:00
|
|
|
if (vector_tool->function == VECTORS_MOVE_CURVE)
|
|
|
|
{
|
|
|
|
gimp_vectors_anchor_select (vector_tool->vectors,
|
|
|
|
vector_tool->cur_stroke,
|
|
|
|
vector_tool->cur_anchor, TRUE);
|
|
|
|
}
|
2003-08-26 08:27:03 +08:00
|
|
|
|
2003-09-04 03:52:46 +08:00
|
|
|
/* convert an anchor to something that looks like an edge */
|
2003-08-21 06:19:37 +08:00
|
|
|
|
2003-09-04 03:52:46 +08:00
|
|
|
if (vector_tool->function == VECTORS_CONVERT_EDGE)
|
|
|
|
{
|
|
|
|
gimp_stroke_anchor_convert (vector_tool->cur_stroke,
|
|
|
|
vector_tool->cur_anchor,
|
|
|
|
GIMP_ANCHOR_FEATURE_EDGE);
|
2003-08-21 06:19:37 +08:00
|
|
|
|
2003-09-04 03:52:46 +08:00
|
|
|
if (vector_tool->cur_anchor->type == GIMP_ANCHOR_ANCHOR)
|
|
|
|
{
|
|
|
|
gimp_vectors_anchor_select (vector_tool->vectors,
|
|
|
|
vector_tool->cur_stroke,
|
|
|
|
vector_tool->cur_anchor, TRUE);
|
2003-08-17 10:49:24 +08:00
|
|
|
|
2003-09-04 03:52:46 +08:00
|
|
|
vector_tool->function = VECTORS_MOVE_ANCHOR;
|
2003-08-21 06:19:37 +08:00
|
|
|
}
|
2003-09-04 03:52:46 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
vector_tool->cur_stroke = NULL;
|
|
|
|
vector_tool->cur_anchor = NULL;
|
2003-08-22 09:42:57 +08:00
|
|
|
|
2003-09-04 03:52:46 +08:00
|
|
|
/* avoid doing anything stupid */
|
|
|
|
vector_tool->function = VECTORS_FINISHED;
|
|
|
|
}
|
|
|
|
}
|
2003-08-18 07:19:09 +08:00
|
|
|
|
2003-09-04 03:52:46 +08:00
|
|
|
/* move a stroke or all strokes of a vectors object */
|
2003-08-29 23:17:06 +08:00
|
|
|
|
2003-09-04 03:52:46 +08:00
|
|
|
if (vector_tool->function == VECTORS_MOVE_STROKE ||
|
|
|
|
vector_tool->function == VECTORS_MOVE_VECTORS)
|
|
|
|
{
|
|
|
|
/* Work is being done in gimp_vector_tool_motion ()... */
|
2003-08-29 23:17:06 +08:00
|
|
|
vector_tool->last_x = coords->x;
|
|
|
|
vector_tool->last_y = coords->y;
|
2002-02-22 08:11:37 +08:00
|
|
|
}
|
|
|
|
|
2003-08-19 02:05:57 +08:00
|
|
|
if (! gimp_draw_tool_is_active (draw_tool))
|
|
|
|
gimp_draw_tool_start (draw_tool, gdisp);
|
|
|
|
|
|
|
|
gimp_draw_tool_resume (draw_tool);
|
2003-09-04 03:52:46 +08:00
|
|
|
|
2002-02-22 08:11:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_vector_tool_button_release (GimpTool *tool,
|
|
|
|
GimpCoords *coords,
|
|
|
|
guint32 time,
|
|
|
|
GdkModifierType state,
|
|
|
|
GimpDisplay *gdisp)
|
|
|
|
{
|
|
|
|
GimpVectorTool *vector_tool;
|
2002-12-29 07:52:29 +08:00
|
|
|
GimpViewable *viewable;
|
2002-02-22 08:11:37 +08:00
|
|
|
|
|
|
|
vector_tool = GIMP_VECTOR_TOOL (tool);
|
|
|
|
|
2003-08-30 06:40:13 +08:00
|
|
|
gimp_vectors_freeze (vector_tool->vectors);
|
|
|
|
|
2003-08-17 10:49:24 +08:00
|
|
|
vector_tool->function = VECTORS_FINISHED;
|
2002-12-29 07:52:29 +08:00
|
|
|
|
2003-08-30 06:40:13 +08:00
|
|
|
gimp_vectors_thaw (vector_tool->vectors);
|
|
|
|
|
2002-12-29 07:52:29 +08:00
|
|
|
/* THIS DOES NOT BELONG HERE! */
|
2003-03-20 07:51:43 +08:00
|
|
|
if (vector_tool->vectors)
|
|
|
|
{
|
|
|
|
viewable = GIMP_VIEWABLE (vector_tool->vectors);
|
|
|
|
gimp_viewable_invalidate_preview (viewable);
|
|
|
|
}
|
2003-06-26 17:54:56 +08:00
|
|
|
|
|
|
|
gimp_tool_control_halt (tool->control);
|
2002-02-22 08:11:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_vector_tool_motion (GimpTool *tool,
|
|
|
|
GimpCoords *coords,
|
|
|
|
guint32 time,
|
|
|
|
GdkModifierType state,
|
|
|
|
GimpDisplay *gdisp)
|
|
|
|
{
|
2003-02-05 22:39:40 +08:00
|
|
|
GimpVectorTool *vector_tool;
|
|
|
|
GimpVectorOptions *options;
|
|
|
|
GimpAnchor *anchor;
|
2002-02-22 08:11:37 +08:00
|
|
|
|
|
|
|
vector_tool = GIMP_VECTOR_TOOL (tool);
|
2003-02-05 22:39:40 +08:00
|
|
|
options = GIMP_VECTOR_OPTIONS (tool->tool_info->tool_options);
|
2002-02-22 08:11:37 +08:00
|
|
|
|
2003-08-21 08:18:44 +08:00
|
|
|
if (vector_tool->function == VECTORS_FINISHED)
|
|
|
|
return;
|
|
|
|
|
2003-05-09 08:38:51 +08:00
|
|
|
gimp_vectors_freeze (vector_tool->vectors);
|
2002-02-22 08:11:37 +08:00
|
|
|
|
2003-08-30 03:55:32 +08:00
|
|
|
if ((vector_tool->saved_state & TOGGLE_MASK) != (state & TOGGLE_MASK))
|
|
|
|
vector_tool->modifier_lock = FALSE;
|
|
|
|
|
|
|
|
if (!vector_tool->modifier_lock)
|
2003-06-25 07:11:13 +08:00
|
|
|
{
|
2003-08-30 03:55:32 +08:00
|
|
|
if (state & TOGGLE_MASK)
|
|
|
|
{
|
|
|
|
vector_tool->restriction = GIMP_ANCHOR_FEATURE_SYMMETRIC;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
vector_tool->restriction = GIMP_ANCHOR_FEATURE_NONE;
|
|
|
|
}
|
2003-06-25 07:11:13 +08:00
|
|
|
}
|
|
|
|
|
2002-02-22 08:11:37 +08:00
|
|
|
switch (vector_tool->function)
|
|
|
|
{
|
2003-08-17 10:49:24 +08:00
|
|
|
case VECTORS_MOVE_ANCHOR:
|
|
|
|
case VECTORS_MOVE_HANDLE:
|
2002-02-22 08:11:37 +08:00
|
|
|
anchor = vector_tool->cur_anchor;
|
|
|
|
|
|
|
|
if (anchor)
|
2002-02-26 00:57:19 +08:00
|
|
|
gimp_stroke_anchor_move_absolute (vector_tool->cur_stroke,
|
|
|
|
vector_tool->cur_anchor,
|
2003-03-29 12:47:44 +08:00
|
|
|
coords, vector_tool->restriction);
|
2003-08-26 08:27:03 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case VECTORS_MOVE_CURVE:
|
|
|
|
gimp_stroke_point_move_absolute (vector_tool->cur_stroke,
|
|
|
|
vector_tool->cur_anchor,
|
|
|
|
vector_tool->cur_position,
|
|
|
|
coords, vector_tool->restriction);
|
|
|
|
break;
|
2002-02-22 08:11:37 +08:00
|
|
|
|
2003-08-29 23:17:06 +08:00
|
|
|
case VECTORS_MOVE_STROKE:
|
2003-09-04 03:52:46 +08:00
|
|
|
if (vector_tool->cur_stroke)
|
|
|
|
{
|
|
|
|
gimp_stroke_translate (vector_tool->cur_stroke,
|
|
|
|
coords->x - vector_tool->last_x,
|
|
|
|
coords->y - vector_tool->last_y);
|
|
|
|
}
|
|
|
|
else if (vector_tool->sel_stroke)
|
|
|
|
{
|
|
|
|
gimp_stroke_translate (vector_tool->sel_stroke,
|
|
|
|
coords->x - vector_tool->last_x,
|
|
|
|
coords->y - vector_tool->last_y);
|
|
|
|
}
|
2003-08-29 23:17:06 +08:00
|
|
|
vector_tool->last_x = coords->x;
|
|
|
|
vector_tool->last_y = coords->y;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VECTORS_MOVE_VECTORS:
|
|
|
|
gimp_item_translate (GIMP_ITEM (vector_tool->vectors),
|
|
|
|
coords->x - vector_tool->last_x,
|
|
|
|
coords->y - vector_tool->last_y, FALSE);
|
|
|
|
vector_tool->last_x = coords->x;
|
|
|
|
vector_tool->last_y = coords->y;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
2002-02-22 08:11:37 +08:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2003-05-09 08:38:51 +08:00
|
|
|
gimp_vectors_thaw (vector_tool->vectors);
|
2002-02-22 08:11:37 +08:00
|
|
|
}
|
|
|
|
|
2003-08-30 03:55:32 +08:00
|
|
|
static void
|
|
|
|
gimp_vector_tool_modifier_key (GimpTool *tool,
|
|
|
|
GdkModifierType key,
|
|
|
|
gboolean press,
|
|
|
|
GdkModifierType state,
|
|
|
|
GimpDisplay *gdisp)
|
|
|
|
{
|
|
|
|
GimpVectorOptions *options;
|
|
|
|
|
|
|
|
options = GIMP_VECTOR_OPTIONS (tool->tool_info->tool_options);
|
|
|
|
|
|
|
|
if (key == TOGGLE_MASK)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (state & MOVE_MASK)
|
|
|
|
{
|
|
|
|
g_object_set (options,
|
|
|
|
"vectors-edit-mode", GIMP_VECTOR_MODE_MOVE,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
else if (state & INSDEL_MASK)
|
|
|
|
{
|
|
|
|
g_object_set (options,
|
|
|
|
"vectors-edit-mode", GIMP_VECTOR_MODE_ADJUST,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_object_set (options,
|
|
|
|
"vectors-edit-mode", GIMP_VECTOR_MODE_CREATE,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2003-04-14 22:52:00 +08:00
|
|
|
static gboolean
|
|
|
|
gimp_vector_tool_on_handle (GimpTool *tool,
|
|
|
|
GimpCoords *coords,
|
|
|
|
GimpAnchorType preferred,
|
2003-06-25 07:11:13 +08:00
|
|
|
GimpDisplay *gdisp,
|
|
|
|
GimpAnchor **ret_anchor,
|
|
|
|
GimpStroke **ret_stroke)
|
2003-04-14 08:37:04 +08:00
|
|
|
{
|
|
|
|
GimpVectorTool *vector_tool;
|
2003-08-19 02:05:57 +08:00
|
|
|
GimpStroke *stroke = NULL;
|
|
|
|
GimpStroke *pref_stroke = NULL;
|
|
|
|
GimpAnchor *anchor = NULL;
|
|
|
|
GimpAnchor *pref_anchor = NULL;
|
|
|
|
GList *list;
|
|
|
|
GList *anchor_list = NULL;
|
|
|
|
gdouble dx, dy;
|
|
|
|
gdouble pref_mindist = -1;
|
|
|
|
gdouble mindist = -1;
|
2003-04-14 08:37:04 +08:00
|
|
|
|
|
|
|
vector_tool = GIMP_VECTOR_TOOL (tool);
|
|
|
|
|
2003-08-22 23:20:13 +08:00
|
|
|
if (vector_tool->vectors == NULL
|
|
|
|
|| vector_tool->vectors->strokes == NULL)
|
2003-04-14 08:37:04 +08:00
|
|
|
{
|
|
|
|
if (ret_anchor)
|
|
|
|
*ret_anchor = NULL;
|
2003-06-25 07:11:13 +08:00
|
|
|
|
|
|
|
if (ret_stroke)
|
|
|
|
*ret_stroke = NULL;
|
|
|
|
|
2003-04-14 08:37:04 +08:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
while ((stroke = gimp_vectors_stroke_get_next (vector_tool->vectors, stroke))
|
|
|
|
!= NULL)
|
|
|
|
{
|
2003-06-25 07:11:13 +08:00
|
|
|
anchor_list = gimp_stroke_get_draw_anchors (stroke);
|
2003-04-14 08:37:04 +08:00
|
|
|
|
|
|
|
list = gimp_stroke_get_draw_controls (stroke);
|
|
|
|
anchor_list = g_list_concat (anchor_list, list);
|
2003-04-14 22:52:00 +08:00
|
|
|
|
2003-06-25 07:11:13 +08:00
|
|
|
while (anchor_list)
|
2003-04-14 08:37:04 +08:00
|
|
|
{
|
2003-08-26 22:29:10 +08:00
|
|
|
dx = coords->x - GIMP_ANCHOR (anchor_list->data)->position.x;
|
|
|
|
dy = coords->y - GIMP_ANCHOR (anchor_list->data)->position.y;
|
2003-04-14 22:52:00 +08:00
|
|
|
|
2003-06-26 17:54:56 +08:00
|
|
|
if (mindist < 0 || mindist > dx * dx + dy * dy)
|
2003-06-25 07:11:13 +08:00
|
|
|
{
|
|
|
|
mindist = dx * dx + dy * dy;
|
2003-08-26 22:29:10 +08:00
|
|
|
anchor = GIMP_ANCHOR (anchor_list->data);
|
2003-06-25 07:11:13 +08:00
|
|
|
if (ret_stroke)
|
|
|
|
*ret_stroke = stroke;
|
|
|
|
}
|
2003-04-14 22:52:00 +08:00
|
|
|
|
2003-06-26 17:54:56 +08:00
|
|
|
if ((pref_mindist < 0 || pref_mindist > dx * dx + dy * dy) &&
|
2003-08-26 22:29:10 +08:00
|
|
|
GIMP_ANCHOR (anchor_list->data)->type == preferred)
|
2003-06-25 07:11:13 +08:00
|
|
|
{
|
|
|
|
pref_mindist = dx * dx + dy * dy;
|
2003-08-26 22:29:10 +08:00
|
|
|
pref_anchor = GIMP_ANCHOR (anchor_list->data);
|
2003-06-25 07:11:13 +08:00
|
|
|
pref_stroke = stroke;
|
|
|
|
}
|
2003-04-14 08:37:04 +08:00
|
|
|
|
2003-06-25 07:11:13 +08:00
|
|
|
anchor_list = anchor_list->next;
|
|
|
|
}
|
2003-04-14 08:37:04 +08:00
|
|
|
|
2003-06-25 07:11:13 +08:00
|
|
|
g_list_free (anchor_list);
|
|
|
|
}
|
2003-04-14 08:37:04 +08:00
|
|
|
|
2003-06-26 17:54:56 +08:00
|
|
|
/* If the data passed into ret_anchor is a preferred anchor, return
|
|
|
|
* it.
|
|
|
|
*/
|
|
|
|
if (ret_anchor && *ret_anchor
|
|
|
|
&& gimp_draw_tool_on_handle (GIMP_DRAW_TOOL (tool), gdisp,
|
|
|
|
coords->x,
|
|
|
|
coords->y,
|
|
|
|
GIMP_HANDLE_CIRCLE,
|
|
|
|
(*ret_anchor)->position.x,
|
|
|
|
(*ret_anchor)->position.y,
|
|
|
|
TARGET,
|
|
|
|
TARGET,
|
|
|
|
GTK_ANCHOR_CENTER,
|
|
|
|
FALSE)
|
|
|
|
&& (*ret_anchor)->type == preferred)
|
|
|
|
{
|
|
|
|
if (ret_stroke)
|
|
|
|
*ret_stroke = pref_stroke;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2003-06-25 07:11:13 +08:00
|
|
|
if (pref_anchor && gimp_draw_tool_on_handle (GIMP_DRAW_TOOL (tool), gdisp,
|
|
|
|
coords->x,
|
|
|
|
coords->y,
|
|
|
|
GIMP_HANDLE_CIRCLE,
|
|
|
|
pref_anchor->position.x,
|
|
|
|
pref_anchor->position.y,
|
|
|
|
TARGET,
|
|
|
|
TARGET,
|
|
|
|
GTK_ANCHOR_CENTER,
|
|
|
|
FALSE))
|
|
|
|
{
|
|
|
|
if (ret_anchor)
|
|
|
|
*ret_anchor = pref_anchor;
|
|
|
|
if (ret_stroke)
|
|
|
|
*ret_stroke = pref_stroke;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
else if (anchor && gimp_draw_tool_on_handle (GIMP_DRAW_TOOL (tool), gdisp,
|
|
|
|
coords->x,
|
|
|
|
coords->y,
|
|
|
|
GIMP_HANDLE_CIRCLE,
|
|
|
|
anchor->position.x,
|
|
|
|
anchor->position.y,
|
|
|
|
TARGET,
|
|
|
|
TARGET,
|
|
|
|
GTK_ANCHOR_CENTER,
|
|
|
|
FALSE))
|
|
|
|
{
|
|
|
|
if (ret_anchor)
|
|
|
|
*ret_anchor = anchor;
|
2003-08-22 09:42:57 +08:00
|
|
|
|
2003-06-25 07:11:13 +08:00
|
|
|
/* *ret_stroke already set correctly. */
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (ret_anchor)
|
|
|
|
*ret_anchor = NULL;
|
|
|
|
if (ret_stroke)
|
|
|
|
*ret_stroke = NULL;
|
|
|
|
return FALSE;
|
|
|
|
}
|
2003-04-14 08:37:04 +08:00
|
|
|
}
|
|
|
|
|
2003-08-21 01:29:13 +08:00
|
|
|
static gboolean
|
|
|
|
gimp_vector_tool_on_curve (GimpTool *tool,
|
|
|
|
GimpCoords *coord,
|
|
|
|
GimpDisplay *gdisp,
|
|
|
|
GimpCoords *ret_coords,
|
|
|
|
gdouble *ret_pos,
|
|
|
|
GimpAnchor **ret_segment_start,
|
|
|
|
GimpStroke **ret_stroke)
|
|
|
|
{
|
|
|
|
GimpVectorTool *vector_tool;
|
|
|
|
GimpStroke *stroke;
|
|
|
|
GimpAnchor *segment_start;
|
|
|
|
GimpCoords min_coords, cur_coords;
|
|
|
|
gdouble min_dist, cur_dist, cur_pos;
|
|
|
|
|
|
|
|
vector_tool = GIMP_VECTOR_TOOL (tool);
|
|
|
|
min_dist = -1.0;
|
|
|
|
stroke = NULL;
|
|
|
|
|
|
|
|
while ((stroke = gimp_vectors_stroke_get_next (vector_tool->vectors, stroke))
|
|
|
|
!= NULL)
|
|
|
|
{
|
|
|
|
cur_dist = gimp_stroke_nearest_point_get (stroke, coord, 1.0,
|
|
|
|
&cur_coords,
|
|
|
|
&segment_start,
|
|
|
|
&cur_pos);
|
|
|
|
|
|
|
|
if (cur_dist < min_dist || min_dist < 0)
|
|
|
|
{
|
|
|
|
min_dist = cur_dist;
|
|
|
|
min_coords = cur_coords;
|
|
|
|
|
|
|
|
if (ret_coords)
|
|
|
|
*ret_coords = cur_coords;
|
|
|
|
if (ret_pos)
|
|
|
|
*ret_pos = cur_pos;
|
|
|
|
if (ret_segment_start)
|
|
|
|
*ret_segment_start = segment_start;
|
|
|
|
if (ret_stroke)
|
|
|
|
*ret_stroke = stroke;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-08-22 23:20:13 +08:00
|
|
|
if (min_dist >= 0 &&
|
|
|
|
gimp_draw_tool_on_handle (GIMP_DRAW_TOOL (tool), gdisp,
|
2003-08-21 01:29:13 +08:00
|
|
|
coord->x,
|
|
|
|
coord->y,
|
|
|
|
GIMP_HANDLE_CIRCLE,
|
|
|
|
min_coords.x,
|
|
|
|
min_coords.y,
|
|
|
|
TARGET,
|
|
|
|
TARGET,
|
|
|
|
GTK_ANCHOR_CENTER,
|
|
|
|
FALSE))
|
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (ret_coords)
|
|
|
|
*ret_coords = *coord;
|
|
|
|
if (ret_pos)
|
|
|
|
*ret_pos = 0.0;
|
|
|
|
if (ret_segment_start)
|
|
|
|
*ret_segment_start = NULL;
|
|
|
|
if (ret_stroke)
|
|
|
|
*ret_stroke = NULL;
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-08-17 10:49:24 +08:00
|
|
|
static void
|
|
|
|
gimp_vector_tool_oper_update (GimpTool *tool,
|
|
|
|
GimpCoords *coords,
|
|
|
|
GdkModifierType state,
|
|
|
|
GimpDisplay *gdisp)
|
|
|
|
{
|
2003-08-21 01:29:13 +08:00
|
|
|
GimpVectorTool *vector_tool;
|
|
|
|
GimpVectorOptions *options;
|
2003-08-22 23:20:13 +08:00
|
|
|
GimpAnchor *anchor = NULL;
|
2003-09-04 03:52:46 +08:00
|
|
|
GimpStroke *stroke = NULL;
|
|
|
|
gdouble position = -1;
|
|
|
|
gboolean on_handle = FALSE;
|
|
|
|
gboolean on_curve = FALSE;
|
2003-08-17 10:49:24 +08:00
|
|
|
|
2003-08-19 02:05:57 +08:00
|
|
|
vector_tool = GIMP_VECTOR_TOOL (tool);
|
2003-08-21 01:29:13 +08:00
|
|
|
options = GIMP_VECTOR_OPTIONS (tool->tool_info->tool_options);
|
2003-08-17 10:49:24 +08:00
|
|
|
|
2003-08-30 03:55:32 +08:00
|
|
|
vector_tool->modifier_lock = FALSE;
|
|
|
|
|
2003-09-04 03:52:46 +08:00
|
|
|
if (vector_tool->vectors)
|
|
|
|
{
|
|
|
|
on_handle = gimp_vector_tool_on_handle (tool, coords, GIMP_ANCHOR_ANCHOR,
|
|
|
|
gdisp, &anchor, &stroke);
|
|
|
|
|
|
|
|
if (! on_handle)
|
|
|
|
on_curve = gimp_vector_tool_on_curve (tool, coords, gdisp, NULL,
|
|
|
|
&position, &anchor, &stroke);
|
|
|
|
}
|
|
|
|
|
|
|
|
vector_tool->cur_position = position;
|
|
|
|
vector_tool->cur_anchor = anchor;
|
|
|
|
vector_tool->cur_stroke = stroke;
|
|
|
|
|
2003-08-29 23:17:06 +08:00
|
|
|
switch (options->edit_mode)
|
2003-08-17 10:49:24 +08:00
|
|
|
{
|
2003-08-29 23:17:06 +08:00
|
|
|
case GIMP_VECTOR_MODE_CREATE:
|
|
|
|
if (! vector_tool->vectors || GIMP_DRAW_TOOL (tool)->gdisp != gdisp)
|
2003-08-17 10:49:24 +08:00
|
|
|
{
|
2003-08-29 23:17:06 +08:00
|
|
|
vector_tool->function = VECTORS_CREATE_VECTOR;
|
2003-08-30 03:55:32 +08:00
|
|
|
vector_tool->restriction = GIMP_ANCHOR_FEATURE_SYMMETRIC;
|
|
|
|
vector_tool->modifier_lock = TRUE;
|
2003-08-29 23:17:06 +08:00
|
|
|
}
|
2003-09-04 03:52:46 +08:00
|
|
|
else if (on_handle)
|
2003-08-29 23:17:06 +08:00
|
|
|
{
|
2003-08-30 03:55:32 +08:00
|
|
|
if (anchor->type == GIMP_ANCHOR_ANCHOR)
|
2003-08-17 10:49:24 +08:00
|
|
|
{
|
2003-08-29 23:17:06 +08:00
|
|
|
vector_tool->function = VECTORS_MOVE_ANCHOR;
|
2003-08-17 10:49:24 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2003-08-30 03:55:32 +08:00
|
|
|
vector_tool->function = VECTORS_MOVE_HANDLE;
|
|
|
|
if (state & TOGGLE_MASK)
|
|
|
|
vector_tool->restriction = GIMP_ANCHOR_FEATURE_SYMMETRIC;
|
2003-08-21 06:19:37 +08:00
|
|
|
else
|
2003-08-30 03:55:32 +08:00
|
|
|
vector_tool->restriction = GIMP_ANCHOR_FEATURE_NONE;
|
2003-08-17 10:49:24 +08:00
|
|
|
}
|
|
|
|
}
|
2003-09-04 03:52:46 +08:00
|
|
|
else if (on_curve)
|
2003-08-29 23:17:06 +08:00
|
|
|
{
|
2003-09-04 03:52:46 +08:00
|
|
|
if (gimp_stroke_point_is_movable (stroke, anchor, position))
|
|
|
|
{
|
|
|
|
vector_tool->function = VECTORS_MOVE_CURVE;
|
|
|
|
if (state & TOGGLE_MASK)
|
|
|
|
vector_tool->restriction = GIMP_ANCHOR_FEATURE_SYMMETRIC;
|
|
|
|
else
|
|
|
|
vector_tool->restriction = GIMP_ANCHOR_FEATURE_NONE;
|
|
|
|
}
|
2003-08-30 03:55:32 +08:00
|
|
|
else
|
2003-09-04 03:52:46 +08:00
|
|
|
{
|
|
|
|
vector_tool->function = VECTORS_FINISHED;
|
|
|
|
}
|
2003-08-29 23:17:06 +08:00
|
|
|
}
|
2003-08-22 09:42:57 +08:00
|
|
|
else
|
2003-08-17 10:49:24 +08:00
|
|
|
{
|
2003-09-04 03:52:46 +08:00
|
|
|
if (vector_tool->sel_stroke && vector_tool->sel_anchor &&
|
|
|
|
gimp_stroke_is_extendable (vector_tool->sel_stroke,
|
|
|
|
vector_tool->sel_anchor) &&
|
|
|
|
!(state & TOGGLE_MASK))
|
2003-08-29 23:17:06 +08:00
|
|
|
vector_tool->function = VECTORS_ADD_ANCHOR;
|
|
|
|
else
|
|
|
|
vector_tool->function = VECTORS_CREATE_STROKE;
|
2003-08-30 03:55:32 +08:00
|
|
|
|
|
|
|
vector_tool->restriction = GIMP_ANCHOR_FEATURE_SYMMETRIC;
|
|
|
|
vector_tool->modifier_lock = TRUE;
|
2003-08-17 10:49:24 +08:00
|
|
|
}
|
2003-08-29 23:17:06 +08:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_VECTOR_MODE_ADJUST:
|
|
|
|
if (! vector_tool->vectors || GIMP_DRAW_TOOL (tool)->gdisp != gdisp)
|
2003-08-17 10:49:24 +08:00
|
|
|
{
|
2003-08-29 23:17:06 +08:00
|
|
|
vector_tool->function = VECTORS_FINISHED;
|
|
|
|
}
|
2003-09-04 03:52:46 +08:00
|
|
|
else if (on_handle)
|
2003-08-29 23:17:06 +08:00
|
|
|
{
|
2003-08-30 03:55:32 +08:00
|
|
|
if (anchor->type == GIMP_ANCHOR_ANCHOR)
|
2003-08-22 09:12:26 +08:00
|
|
|
{
|
2003-09-04 03:52:46 +08:00
|
|
|
if (!(state & TOGGLE_MASK) && vector_tool->sel_anchor &&
|
|
|
|
vector_tool->sel_anchor != anchor &&
|
|
|
|
gimp_stroke_is_extendable (vector_tool->sel_stroke,
|
|
|
|
vector_tool->sel_anchor) &&
|
|
|
|
gimp_stroke_is_extendable (stroke, anchor))
|
2003-08-30 03:55:32 +08:00
|
|
|
{
|
2003-09-04 03:52:46 +08:00
|
|
|
vector_tool->function = VECTORS_CONNECT_STROKES;
|
2003-08-30 03:55:32 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2003-09-04 03:52:46 +08:00
|
|
|
vector_tool->function = VECTORS_DELETE_ANCHOR;
|
2003-08-30 03:55:32 +08:00
|
|
|
}
|
2003-08-22 09:12:26 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2003-08-30 03:55:32 +08:00
|
|
|
vector_tool->function = VECTORS_CONVERT_EDGE;
|
|
|
|
if (state & TOGGLE_MASK)
|
|
|
|
vector_tool->restriction = GIMP_ANCHOR_FEATURE_SYMMETRIC;
|
|
|
|
else
|
|
|
|
vector_tool->restriction = GIMP_ANCHOR_FEATURE_NONE;
|
2003-08-22 09:12:26 +08:00
|
|
|
}
|
2003-08-17 10:49:24 +08:00
|
|
|
}
|
2003-09-04 03:52:46 +08:00
|
|
|
else if (on_curve)
|
2003-08-17 10:49:24 +08:00
|
|
|
{
|
2003-08-30 03:55:32 +08:00
|
|
|
if (state & TOGGLE_MASK)
|
2003-08-21 01:29:13 +08:00
|
|
|
{
|
2003-08-29 23:17:06 +08:00
|
|
|
vector_tool->function = VECTORS_DELETE_SEGMENT;
|
2003-08-21 01:29:13 +08:00
|
|
|
}
|
2003-09-04 03:52:46 +08:00
|
|
|
else if (gimp_stroke_anchor_is_insertable (stroke, anchor, position))
|
2003-08-21 01:29:13 +08:00
|
|
|
{
|
2003-08-29 23:17:06 +08:00
|
|
|
vector_tool->function = VECTORS_INSERT_ANCHOR;
|
2003-08-21 01:29:13 +08:00
|
|
|
}
|
2003-09-04 03:52:46 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
vector_tool->function = VECTORS_FINISHED;
|
|
|
|
}
|
2003-08-17 10:49:24 +08:00
|
|
|
}
|
2003-08-29 23:17:06 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
vector_tool->function = VECTORS_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_VECTOR_MODE_MOVE:
|
2003-09-04 03:52:46 +08:00
|
|
|
if (! vector_tool->vectors ||
|
|
|
|
! vector_tool->vectors->strokes ||
|
|
|
|
GIMP_DRAW_TOOL (tool)->gdisp != gdisp)
|
2003-08-30 03:55:32 +08:00
|
|
|
{
|
|
|
|
vector_tool->function = VECTORS_FINISHED;
|
|
|
|
}
|
|
|
|
else if (state & TOGGLE_MASK)
|
|
|
|
{
|
|
|
|
vector_tool->function = VECTORS_MOVE_VECTORS;
|
|
|
|
}
|
2003-08-29 23:17:06 +08:00
|
|
|
else
|
2003-08-30 03:55:32 +08:00
|
|
|
{
|
|
|
|
vector_tool->function = VECTORS_MOVE_STROKE;
|
|
|
|
}
|
2003-08-29 23:17:06 +08:00
|
|
|
|
|
|
|
break;
|
2003-08-17 10:49:24 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-02-22 08:11:37 +08:00
|
|
|
static void
|
|
|
|
gimp_vector_tool_cursor_update (GimpTool *tool,
|
|
|
|
GimpCoords *coords,
|
|
|
|
GdkModifierType state,
|
|
|
|
GimpDisplay *gdisp)
|
|
|
|
{
|
2003-08-19 02:05:57 +08:00
|
|
|
GimpVectorTool *vector_tool;
|
|
|
|
GimpToolCursorType tool_cursor;
|
2003-08-21 06:19:37 +08:00
|
|
|
GimpCursorType cursor;
|
2003-08-19 02:05:57 +08:00
|
|
|
GimpCursorModifier cmodifier;
|
2002-02-22 08:11:37 +08:00
|
|
|
|
|
|
|
vector_tool = GIMP_VECTOR_TOOL (tool);
|
|
|
|
|
2003-08-17 10:49:24 +08:00
|
|
|
tool_cursor = gimp_tool_control_get_tool_cursor (tool->control);
|
2003-08-21 06:19:37 +08:00
|
|
|
cursor = GIMP_MOUSE_CURSOR;
|
2003-08-17 10:49:24 +08:00
|
|
|
cmodifier = GIMP_CURSOR_MODIFIER_NONE;
|
|
|
|
|
|
|
|
switch (vector_tool->function)
|
2002-02-22 08:11:37 +08:00
|
|
|
{
|
2003-08-17 10:49:24 +08:00
|
|
|
case VECTORS_CREATE_VECTOR:
|
|
|
|
case VECTORS_CREATE_STROKE:
|
|
|
|
cmodifier = GIMP_CURSOR_MODIFIER_CONTROL;
|
|
|
|
break;
|
|
|
|
case VECTORS_ADD_ANCHOR:
|
2003-08-21 01:29:13 +08:00
|
|
|
case VECTORS_INSERT_ANCHOR:
|
2003-08-17 10:49:24 +08:00
|
|
|
cmodifier = GIMP_CURSOR_MODIFIER_PLUS;
|
|
|
|
break;
|
2003-08-22 01:47:12 +08:00
|
|
|
case VECTORS_DELETE_ANCHOR:
|
2003-08-22 09:12:26 +08:00
|
|
|
case VECTORS_DELETE_SEGMENT:
|
2003-08-22 01:47:12 +08:00
|
|
|
cmodifier = GIMP_CURSOR_MODIFIER_MINUS;
|
|
|
|
break;
|
2003-08-17 10:49:24 +08:00
|
|
|
case VECTORS_MOVE_HANDLE:
|
|
|
|
case VECTORS_CONVERT_EDGE:
|
|
|
|
cmodifier = GIMP_CURSOR_MODIFIER_HAND;
|
|
|
|
break;
|
|
|
|
case VECTORS_MOVE_ANCHOR:
|
2003-08-21 01:29:13 +08:00
|
|
|
case VECTORS_MOVE_CURVE:
|
2003-08-29 23:17:06 +08:00
|
|
|
case VECTORS_MOVE_STROKE:
|
|
|
|
case VECTORS_MOVE_VECTORS:
|
2003-08-26 08:27:03 +08:00
|
|
|
cmodifier = GIMP_CURSOR_MODIFIER_MOVE;
|
2003-08-21 01:29:13 +08:00
|
|
|
break;
|
2003-08-27 08:31:20 +08:00
|
|
|
case VECTORS_CONNECT_STROKES:
|
|
|
|
cmodifier = GIMP_CURSOR_MODIFIER_INTERSECT;
|
|
|
|
break;
|
2003-08-17 10:49:24 +08:00
|
|
|
default:
|
2003-08-21 06:19:37 +08:00
|
|
|
cursor = GIMP_BAD_CURSOR;
|
|
|
|
cmodifier = GIMP_CURSOR_MODIFIER_NONE;
|
2003-08-17 10:49:24 +08:00
|
|
|
break;
|
2002-02-22 08:11:37 +08:00
|
|
|
}
|
|
|
|
|
2003-08-18 07:19:09 +08:00
|
|
|
/*
|
|
|
|
* gimp_tool_control_set_cursor (tool->control, ctype);
|
|
|
|
* gimp_tool_control_set_tool_cursor (tool->control,
|
|
|
|
* GIMP_BEZIER_SELECT_TOOL_CURSOR);
|
|
|
|
* gimp_tool_control_set_cursor_modifier (tool->control, cmodifier);
|
|
|
|
*/
|
|
|
|
|
2003-08-21 06:19:37 +08:00
|
|
|
gimp_tool_set_cursor (tool, gdisp, cursor, tool_cursor, cmodifier);
|
2002-02-22 08:11:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_vector_tool_draw (GimpDrawTool *draw_tool)
|
|
|
|
{
|
2002-02-26 08:58:04 +08:00
|
|
|
GimpVectorTool *vector_tool;
|
2002-02-22 08:11:37 +08:00
|
|
|
GimpTool *tool;
|
|
|
|
GimpAnchor *cur_anchor = NULL;
|
|
|
|
GimpStroke *cur_stroke = NULL;
|
|
|
|
GimpVectors *vectors;
|
2002-12-29 07:52:29 +08:00
|
|
|
GArray *coords;
|
2002-02-26 08:58:04 +08:00
|
|
|
gboolean closed;
|
2003-04-14 22:52:00 +08:00
|
|
|
GList *draw_anchors;
|
|
|
|
GList *list;
|
2002-02-22 08:11:37 +08:00
|
|
|
|
|
|
|
vector_tool = GIMP_VECTOR_TOOL (draw_tool);
|
2002-02-26 08:58:04 +08:00
|
|
|
tool = GIMP_TOOL (draw_tool);
|
2002-02-22 08:11:37 +08:00
|
|
|
|
|
|
|
vectors = vector_tool->vectors;
|
|
|
|
|
2003-03-20 07:51:43 +08:00
|
|
|
if (!vectors)
|
|
|
|
return;
|
|
|
|
|
2002-02-26 08:58:04 +08:00
|
|
|
while ((cur_stroke = gimp_vectors_stroke_get_next (vectors, cur_stroke)))
|
2002-02-22 08:11:37 +08:00
|
|
|
{
|
2002-12-31 00:36:01 +08:00
|
|
|
/* anchor handles */
|
|
|
|
draw_anchors = gimp_stroke_get_draw_anchors (cur_stroke);
|
|
|
|
|
2003-04-14 22:52:00 +08:00
|
|
|
for (list = draw_anchors; list; list = g_list_next (list))
|
2002-12-31 00:36:01 +08:00
|
|
|
{
|
2003-08-26 22:29:10 +08:00
|
|
|
cur_anchor = GIMP_ANCHOR (list->data);
|
2002-12-31 00:36:01 +08:00
|
|
|
|
2003-03-29 12:47:44 +08:00
|
|
|
if (cur_anchor->type == GIMP_ANCHOR_ANCHOR)
|
2002-12-31 00:36:01 +08:00
|
|
|
{
|
|
|
|
gimp_draw_tool_draw_handle (draw_tool,
|
|
|
|
cur_anchor->selected ?
|
2003-04-14 22:52:00 +08:00
|
|
|
GIMP_HANDLE_CIRCLE :
|
|
|
|
GIMP_HANDLE_FILLED_CIRCLE,
|
2002-12-31 00:36:01 +08:00
|
|
|
cur_anchor->position.x,
|
|
|
|
cur_anchor->position.y,
|
|
|
|
TARGET,
|
|
|
|
TARGET,
|
|
|
|
GTK_ANCHOR_CENTER,
|
|
|
|
FALSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_list_free (draw_anchors);
|
|
|
|
|
|
|
|
/* control handles */
|
2002-12-31 11:18:49 +08:00
|
|
|
draw_anchors = gimp_stroke_get_draw_controls (cur_stroke);
|
2002-12-31 00:36:01 +08:00
|
|
|
|
2003-04-14 22:52:00 +08:00
|
|
|
for (list = draw_anchors; list; list = g_list_next (list))
|
2002-02-26 08:58:04 +08:00
|
|
|
{
|
2003-08-26 22:29:10 +08:00
|
|
|
cur_anchor = GIMP_ANCHOR (list->data);
|
2002-12-31 00:36:01 +08:00
|
|
|
|
2002-02-22 08:11:37 +08:00
|
|
|
gimp_draw_tool_draw_handle (draw_tool,
|
2002-12-31 00:36:01 +08:00
|
|
|
GIMP_HANDLE_SQUARE,
|
2002-02-26 08:58:04 +08:00
|
|
|
cur_anchor->position.x,
|
|
|
|
cur_anchor->position.y,
|
2003-06-26 17:54:56 +08:00
|
|
|
TARGET - 3,
|
|
|
|
TARGET - 3,
|
2002-02-22 08:11:37 +08:00
|
|
|
GTK_ANCHOR_CENTER,
|
|
|
|
FALSE);
|
2002-02-26 08:58:04 +08:00
|
|
|
}
|
2002-12-29 07:52:29 +08:00
|
|
|
|
2002-12-31 00:36:01 +08:00
|
|
|
g_list_free (draw_anchors);
|
|
|
|
|
|
|
|
/* the lines to the control handles */
|
2002-12-31 11:18:49 +08:00
|
|
|
coords = gimp_stroke_get_draw_lines (cur_stroke);
|
2003-08-22 09:42:57 +08:00
|
|
|
|
2003-08-22 21:00:25 +08:00
|
|
|
if (coords)
|
2002-12-31 00:36:01 +08:00
|
|
|
{
|
2003-08-22 21:00:25 +08:00
|
|
|
if (coords->len % 2 == 0)
|
|
|
|
{
|
|
|
|
gint i;
|
2003-04-14 22:52:00 +08:00
|
|
|
|
2003-08-22 21:00:25 +08:00
|
|
|
for (i = 0; i < coords->len; i += 2)
|
|
|
|
gimp_draw_tool_draw_strokes (draw_tool,
|
|
|
|
&g_array_index (coords,
|
|
|
|
GimpCoords, i),
|
|
|
|
2, FALSE, FALSE);
|
|
|
|
}
|
2003-04-14 22:52:00 +08:00
|
|
|
|
2003-08-22 21:00:25 +08:00
|
|
|
g_array_free (coords, TRUE);
|
|
|
|
}
|
2002-12-31 00:36:01 +08:00
|
|
|
|
|
|
|
/* the stroke itself */
|
|
|
|
coords = gimp_stroke_interpolate (cur_stroke, 1.0, &closed);
|
2002-12-29 07:52:29 +08:00
|
|
|
|
2003-08-17 10:49:24 +08:00
|
|
|
if (coords && coords->len)
|
|
|
|
{
|
|
|
|
gimp_draw_tool_draw_strokes (draw_tool,
|
|
|
|
&g_array_index (coords, GimpCoords, 0),
|
|
|
|
coords->len, FALSE, FALSE);
|
2002-02-22 08:11:37 +08:00
|
|
|
|
2003-08-17 10:49:24 +08:00
|
|
|
g_array_free (coords, TRUE);
|
|
|
|
}
|
2002-02-22 08:11:37 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-04-14 22:52:00 +08:00
|
|
|
static void
|
2003-03-20 07:51:43 +08:00
|
|
|
gimp_vector_tool_clear_vectors (GimpVectorTool *vector_tool)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_VECTOR_TOOL (vector_tool));
|
2003-04-14 22:52:00 +08:00
|
|
|
|
2003-03-20 07:51:43 +08:00
|
|
|
gimp_vector_tool_set_vectors (vector_tool, NULL);
|
|
|
|
}
|
|
|
|
|
2003-04-14 22:52:00 +08:00
|
|
|
static void
|
2003-05-09 08:38:51 +08:00
|
|
|
gimp_vector_tool_vectors_freeze (GimpVectors *vectors,
|
|
|
|
GimpVectorTool *vector_tool)
|
2003-04-14 22:52:00 +08:00
|
|
|
{
|
2003-08-19 02:05:57 +08:00
|
|
|
gimp_draw_tool_pause (GIMP_DRAW_TOOL (vector_tool));
|
2003-04-14 22:52:00 +08:00
|
|
|
}
|
|
|
|
|
2003-05-09 08:38:51 +08:00
|
|
|
static void
|
|
|
|
gimp_vector_tool_vectors_thaw (GimpVectors *vectors,
|
|
|
|
GimpVectorTool *vector_tool)
|
|
|
|
{
|
2003-09-04 03:52:46 +08:00
|
|
|
GimpStroke *cur_stroke=NULL;
|
|
|
|
GimpAnchor *cur_anchor;
|
|
|
|
GList *draw_anchors, *list;
|
|
|
|
gboolean cur_anchor_valid, cur_stroke_valid;
|
|
|
|
|
|
|
|
/* Ok, the vector might have changed externally (e.g. Undo)
|
|
|
|
* we need to validate our internal state. */
|
|
|
|
|
|
|
|
cur_anchor_valid = FALSE;
|
|
|
|
cur_stroke_valid = FALSE;
|
|
|
|
|
|
|
|
vector_tool->sel_count = 0;
|
|
|
|
vector_tool->sel_anchor = NULL;
|
|
|
|
vector_tool->sel_stroke = NULL;
|
|
|
|
|
|
|
|
while ((cur_stroke = gimp_vectors_stroke_get_next (vectors, cur_stroke)))
|
|
|
|
{
|
|
|
|
/* anchor handles */
|
|
|
|
draw_anchors = gimp_stroke_get_draw_anchors (cur_stroke);
|
|
|
|
|
|
|
|
if (cur_stroke == vector_tool->cur_stroke)
|
|
|
|
cur_stroke_valid = TRUE;
|
|
|
|
|
|
|
|
for (list = draw_anchors; list; list = g_list_next (list))
|
|
|
|
{
|
|
|
|
cur_anchor = GIMP_ANCHOR (list->data);
|
|
|
|
|
|
|
|
if (cur_anchor == vector_tool->cur_anchor)
|
|
|
|
cur_anchor_valid = TRUE;
|
|
|
|
|
|
|
|
if (cur_anchor->type == GIMP_ANCHOR_ANCHOR &&
|
|
|
|
cur_anchor->selected)
|
|
|
|
{
|
|
|
|
vector_tool->sel_count++;
|
|
|
|
if (vector_tool->sel_count == 1)
|
|
|
|
{
|
|
|
|
vector_tool->sel_anchor = cur_anchor;
|
|
|
|
vector_tool->sel_stroke = cur_stroke;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
vector_tool->sel_anchor = NULL;
|
|
|
|
vector_tool->sel_stroke = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
draw_anchors = gimp_stroke_get_draw_controls (cur_stroke);
|
|
|
|
|
|
|
|
for (list = draw_anchors; list; list = g_list_next (list))
|
|
|
|
{
|
|
|
|
cur_anchor = GIMP_ANCHOR (list->data);
|
|
|
|
|
|
|
|
if (cur_anchor == vector_tool->cur_anchor)
|
|
|
|
cur_anchor_valid = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!cur_stroke_valid)
|
|
|
|
vector_tool->cur_stroke = NULL;
|
|
|
|
|
|
|
|
if (!cur_anchor_valid)
|
|
|
|
vector_tool->cur_anchor = NULL;
|
|
|
|
|
|
|
|
|
2003-08-19 02:05:57 +08:00
|
|
|
gimp_draw_tool_resume (GIMP_DRAW_TOOL (vector_tool));
|
2003-05-09 08:38:51 +08:00
|
|
|
}
|
2003-04-14 22:52:00 +08:00
|
|
|
|
2002-02-26 08:58:04 +08:00
|
|
|
void
|
2002-02-26 10:14:11 +08:00
|
|
|
gimp_vector_tool_set_vectors (GimpVectorTool *vector_tool,
|
|
|
|
GimpVectors *vectors)
|
2002-02-26 08:58:04 +08:00
|
|
|
{
|
2002-02-26 11:19:47 +08:00
|
|
|
GimpDrawTool *draw_tool;
|
|
|
|
GimpTool *tool;
|
2003-05-19 07:08:01 +08:00
|
|
|
GimpItem *item = NULL;
|
2002-02-26 11:19:47 +08:00
|
|
|
|
2002-02-26 08:58:04 +08:00
|
|
|
g_return_if_fail (GIMP_IS_VECTOR_TOOL (vector_tool));
|
2003-03-20 07:51:43 +08:00
|
|
|
g_return_if_fail (vectors == NULL || GIMP_IS_VECTORS (vectors));
|
2002-02-26 08:58:04 +08:00
|
|
|
|
2002-02-26 11:19:47 +08:00
|
|
|
draw_tool = GIMP_DRAW_TOOL (vector_tool);
|
|
|
|
tool = GIMP_TOOL (vector_tool);
|
2003-04-14 22:52:00 +08:00
|
|
|
|
|
|
|
if (vectors)
|
|
|
|
item = GIMP_ITEM (vectors);
|
2002-02-26 11:19:47 +08:00
|
|
|
|
2003-03-20 07:51:43 +08:00
|
|
|
if (vectors == vector_tool->vectors)
|
|
|
|
return;
|
|
|
|
|
2003-08-19 02:05:57 +08:00
|
|
|
gimp_draw_tool_pause (draw_tool);
|
|
|
|
|
|
|
|
if (gimp_draw_tool_is_active (draw_tool) &&
|
|
|
|
(! vectors || draw_tool->gdisp->gimage != item->gimage))
|
|
|
|
gimp_draw_tool_stop (draw_tool);
|
2002-02-26 08:58:04 +08:00
|
|
|
|
|
|
|
if (vector_tool->vectors)
|
2003-03-20 07:51:43 +08:00
|
|
|
{
|
|
|
|
g_signal_handlers_disconnect_by_func (vector_tool->vectors,
|
|
|
|
gimp_vector_tool_clear_vectors,
|
|
|
|
vector_tool);
|
2003-04-14 22:52:00 +08:00
|
|
|
g_signal_handlers_disconnect_by_func (vector_tool->vectors,
|
2003-05-09 08:38:51 +08:00
|
|
|
gimp_vector_tool_vectors_freeze,
|
|
|
|
vector_tool);
|
|
|
|
g_signal_handlers_disconnect_by_func (vector_tool->vectors,
|
|
|
|
gimp_vector_tool_vectors_thaw,
|
2003-04-14 22:52:00 +08:00
|
|
|
vector_tool);
|
|
|
|
g_object_unref (vector_tool->vectors);
|
2003-03-20 07:51:43 +08:00
|
|
|
}
|
2002-02-26 08:58:04 +08:00
|
|
|
|
2002-02-26 11:19:47 +08:00
|
|
|
vector_tool->vectors = vectors;
|
|
|
|
vector_tool->cur_stroke = NULL;
|
|
|
|
vector_tool->cur_anchor = NULL;
|
2003-08-17 10:49:24 +08:00
|
|
|
vector_tool->function = VECTORS_MOVE_ANCHOR;
|
2002-02-26 08:58:04 +08:00
|
|
|
|
2003-04-14 22:52:00 +08:00
|
|
|
if (! vector_tool->vectors)
|
2003-03-20 07:51:43 +08:00
|
|
|
{
|
2003-04-14 22:52:00 +08:00
|
|
|
tool->gdisp = NULL;
|
|
|
|
|
2003-08-19 02:05:57 +08:00
|
|
|
/* leave draw_tool->paused_count in a consistent state */
|
|
|
|
gimp_draw_tool_resume (draw_tool);
|
|
|
|
|
|
|
|
vector_tool->function = VECTORS_CREATE_VECTOR;
|
|
|
|
|
2003-04-14 22:52:00 +08:00
|
|
|
return;
|
2003-03-20 07:51:43 +08:00
|
|
|
}
|
2002-02-26 08:58:04 +08:00
|
|
|
|
2003-04-14 22:52:00 +08:00
|
|
|
g_object_ref (vectors);
|
|
|
|
|
2003-08-22 09:42:57 +08:00
|
|
|
g_signal_connect_object (vectors, "removed",
|
2003-04-14 22:52:00 +08:00
|
|
|
G_CALLBACK (gimp_vector_tool_clear_vectors),
|
|
|
|
vector_tool,
|
|
|
|
G_CONNECT_SWAPPED);
|
2003-05-09 08:38:51 +08:00
|
|
|
g_signal_connect_object (vectors, "freeze",
|
|
|
|
G_CALLBACK (gimp_vector_tool_vectors_freeze),
|
|
|
|
vector_tool,
|
|
|
|
0);
|
|
|
|
g_signal_connect_object (vectors, "thaw",
|
|
|
|
G_CALLBACK (gimp_vector_tool_vectors_thaw),
|
2003-04-14 22:52:00 +08:00
|
|
|
vector_tool,
|
|
|
|
0);
|
|
|
|
|
2003-08-19 02:05:57 +08:00
|
|
|
if (! gimp_draw_tool_is_active (draw_tool))
|
2002-02-26 11:19:47 +08:00
|
|
|
{
|
2003-08-19 02:05:57 +08:00
|
|
|
if (tool->gdisp && tool->gdisp->gimage == item->gimage)
|
2002-02-26 11:19:47 +08:00
|
|
|
{
|
2003-08-19 02:05:57 +08:00
|
|
|
gimp_draw_tool_start (draw_tool, tool->gdisp);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GimpContext *context;
|
|
|
|
GimpDisplay *gdisp;
|
2002-02-26 11:19:47 +08:00
|
|
|
|
2003-08-19 02:05:57 +08:00
|
|
|
context = gimp_get_user_context (tool->tool_info->gimp);
|
|
|
|
gdisp = gimp_context_get_display (context);
|
2002-02-26 08:58:04 +08:00
|
|
|
|
2003-08-19 02:05:57 +08:00
|
|
|
if (! gdisp || gdisp->gimage != item->gimage)
|
2002-02-26 11:19:47 +08:00
|
|
|
{
|
2003-08-19 02:05:57 +08:00
|
|
|
GList *list;
|
2002-02-26 08:58:04 +08:00
|
|
|
|
2003-08-19 02:05:57 +08:00
|
|
|
gdisp = NULL;
|
|
|
|
|
|
|
|
for (list = GIMP_LIST (item->gimage->gimp->displays)->list;
|
|
|
|
list;
|
|
|
|
list = g_list_next (list))
|
|
|
|
{
|
|
|
|
if (((GimpDisplay *) list->data)->gimage == item->gimage)
|
|
|
|
{
|
|
|
|
gimp_context_set_display (context,
|
|
|
|
(GimpDisplay *) list->data);
|
|
|
|
|
|
|
|
gdisp = gimp_context_get_display (context);
|
|
|
|
break;
|
|
|
|
}
|
2002-02-26 11:19:47 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-04-14 22:52:00 +08:00
|
|
|
tool->gdisp = gdisp;
|
2002-02-26 11:19:47 +08:00
|
|
|
|
2003-08-19 02:05:57 +08:00
|
|
|
if (tool->gdisp)
|
|
|
|
gimp_draw_tool_start (draw_tool, tool->gdisp);
|
2003-04-14 22:52:00 +08:00
|
|
|
}
|
2002-02-26 11:19:47 +08:00
|
|
|
}
|
2003-08-19 02:05:57 +08:00
|
|
|
|
|
|
|
gimp_draw_tool_resume (draw_tool);
|
2002-02-26 11:19:47 +08:00
|
|
|
}
|