1
/* The GIMP -- an image manipulation program
2
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
5
* Copyright (C) 2003 Simon Budig <simon@gimp.org>
7
* This program is free software; you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License as published by
9
* the Free Software Foundation; either version 2 of the License, or
10
* (at your option) any later version.
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
17
* You should have received a copy of the GNU General Public License
18
* along with this program; if not, write to the Free Software
19
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
28
#include <gdk/gdkkeysyms.h>
30
#include "libgimpmath/gimpmath.h"
31
#include "libgimpbase/gimpbase.h"
32
#include "libgimpwidgets/gimpwidgets.h"
34
#include "tools-types.h"
36
#include "core/gimp.h"
37
#include "core/gimpcontext.h"
38
#include "core/gimpchannel-select.h"
39
#include "core/gimpimage.h"
40
#include "core/gimpimage-undo-push.h"
41
#include "core/gimplist.h"
42
#include "core/gimptoolinfo.h"
43
#include "core/gimpundo.h"
44
#include "core/gimpundostack.h"
46
#include "vectors/gimpanchor.h"
47
#include "vectors/gimpvectors.h"
48
#include "vectors/gimpbezierstroke.h"
50
#include "widgets/gimphelp-ids.h"
52
#include "display/gimpdisplay.h"
53
#include "display/gimpdisplayshell.h"
54
#include "display/gimpdisplayshell-scale.h"
56
#include "gimptoolcontrol.h"
57
#include "gimpvectoroptions.h"
58
#include "gimpvectortool.h"
60
#include "dialogs/stroke-dialog.h"
62
#include "gimp-intl.h"
67
#define TOGGLE_MASK GDK_SHIFT_MASK
68
#define MOVE_MASK GDK_MOD1_MASK
69
#define INSDEL_MASK GDK_CONTROL_MASK
72
/* local function prototypes */
74
static void gimp_vector_tool_class_init (GimpVectorToolClass *klass);
75
static void gimp_vector_tool_init (GimpVectorTool *tool);
77
static void gimp_vector_tool_control (GimpTool *tool,
78
GimpToolAction action,
80
static void gimp_vector_tool_button_press (GimpTool *tool,
83
GdkModifierType state,
85
static void gimp_vector_tool_button_release (GimpTool *tool,
88
GdkModifierType state,
90
static void gimp_vector_tool_motion (GimpTool *tool,
93
GdkModifierType state,
95
static gboolean gimp_vector_tool_key_press (GimpTool *tool,
98
static void gimp_vector_tool_modifier_key (GimpTool *tool,
101
GdkModifierType state,
103
static void gimp_vector_tool_oper_update (GimpTool *tool,
105
GdkModifierType state,
107
static void gimp_vector_tool_status_update (GimpTool *tool,
109
static void gimp_vector_tool_status_set (GimpTool *tool,
111
const gchar *message);
112
static void gimp_vector_tool_cursor_update (GimpTool *tool,
114
GdkModifierType state,
117
static void gimp_vector_tool_draw (GimpDrawTool *draw_tool);
119
static void gimp_vector_tool_vectors_changed (GimpImage *gimage,
120
GimpVectorTool *vector_tool);
121
static void gimp_vector_tool_vectors_removed (GimpVectors *vectors,
122
GimpVectorTool *vector_tool);
123
static void gimp_vector_tool_vectors_visible (GimpVectors *vectors,
124
GimpVectorTool *vector_tool);
125
static void gimp_vector_tool_vectors_freeze (GimpVectors *vectors,
126
GimpVectorTool *vector_tool);
127
static void gimp_vector_tool_vectors_thaw (GimpVectors *vectors,
128
GimpVectorTool *vector_tool);
130
static void gimp_vector_tool_move_selected_anchors
131
(GimpVectorTool *vector_tool,
134
static void gimp_vector_tool_delete_selected_anchors
135
(GimpVectorTool *vector_tool);
136
static void gimp_vector_tool_verify_state (GimpVectorTool *vector_tool);
137
static void gimp_vector_tool_undo_push (GimpVectorTool *vector_tool,
140
static void gimp_vector_tool_to_selection (GimpVectorTool *vector_tool);
141
static void gimp_vector_tool_to_selection_extended
142
(GimpVectorTool *vector_tool,
144
static void gimp_vector_tool_stroke_vectors (GimpVectorTool *vector_tool,
148
static GimpDrawToolClass *parent_class = NULL;
152
gimp_vector_tool_register (GimpToolRegisterCallback callback,
155
(* callback) (GIMP_TYPE_VECTOR_TOOL,
156
GIMP_TYPE_VECTOR_OPTIONS,
157
gimp_vector_options_gui,
161
_("Create and edit paths"),
163
NULL, GIMP_HELP_TOOL_PATH,
164
GIMP_STOCK_TOOL_PATH,
169
gimp_vector_tool_get_type (void)
171
static GType tool_type = 0;
175
static const GTypeInfo tool_info =
177
sizeof (GimpVectorToolClass),
178
(GBaseInitFunc) NULL,
179
(GBaseFinalizeFunc) NULL,
180
(GClassInitFunc) gimp_vector_tool_class_init,
181
NULL, /* class_finalize */
182
NULL, /* class_data */
183
sizeof (GimpVectorTool),
185
(GInstanceInitFunc) gimp_vector_tool_init,
188
tool_type = g_type_register_static (GIMP_TYPE_DRAW_TOOL,
197
gimp_vector_tool_class_init (GimpVectorToolClass *klass)
199
GObjectClass *object_class;
200
GimpToolClass *tool_class;
201
GimpDrawToolClass *draw_tool_class;
203
object_class = G_OBJECT_CLASS (klass);
204
tool_class = GIMP_TOOL_CLASS (klass);
205
draw_tool_class = GIMP_DRAW_TOOL_CLASS (klass);
207
parent_class = g_type_class_peek_parent (klass);
209
tool_class->control = gimp_vector_tool_control;
210
tool_class->button_press = gimp_vector_tool_button_press;
211
tool_class->button_release = gimp_vector_tool_button_release;
212
tool_class->motion = gimp_vector_tool_motion;
213
tool_class->key_press = gimp_vector_tool_key_press;
214
tool_class->modifier_key = gimp_vector_tool_modifier_key;
215
tool_class->oper_update = gimp_vector_tool_oper_update;
216
tool_class->cursor_update = gimp_vector_tool_cursor_update;
218
draw_tool_class->draw = gimp_vector_tool_draw;
222
gimp_vector_tool_init (GimpVectorTool *vector_tool)
224
GimpTool *tool = GIMP_TOOL (vector_tool);
226
gimp_tool_control_set_scroll_lock (tool->control, TRUE);
227
gimp_tool_control_set_motion_mode (tool->control, GIMP_MOTION_MODE_COMPRESS);
228
gimp_tool_control_set_tool_cursor (tool->control, GIMP_TOOL_CURSOR_PATHS);
230
vector_tool->status_msg = NULL;
232
vector_tool->function = VECTORS_CREATE_VECTOR;
233
vector_tool->restriction = GIMP_ANCHOR_FEATURE_NONE;
234
vector_tool->modifier_lock = FALSE;
235
vector_tool->last_x = 0.0;
236
vector_tool->last_y = 0.0;
237
vector_tool->undo_motion = FALSE;
238
vector_tool->have_undo = FALSE;
240
vector_tool->cur_anchor = NULL;
241
vector_tool->cur_anchor2 = NULL;
242
vector_tool->cur_stroke = NULL;
243
vector_tool->cur_position = 0.0;
244
vector_tool->cur_vectors = NULL;
245
vector_tool->vectors = NULL;
247
vector_tool->sel_count = 0;
248
vector_tool->sel_anchor = NULL;
249
vector_tool->sel_stroke = NULL;
251
vector_tool->saved_mode = GIMP_VECTOR_MODE_DESIGN;
256
gimp_vector_tool_control (GimpTool *tool,
257
GimpToolAction action,
260
GimpVectorTool *vector_tool = GIMP_VECTOR_TOOL (tool);
271
gimp_vector_tool_set_vectors (vector_tool, NULL);
272
gimp_vector_tool_status_set (tool, NULL, NULL);
279
GIMP_TOOL_CLASS (parent_class)->control (tool, action, gdisp);
283
gimp_vector_tool_button_press (GimpTool *tool,
286
GdkModifierType state,
289
GimpDrawTool *draw_tool;
290
GimpVectorTool *vector_tool;
291
GimpVectorOptions *options;
292
GimpVectors *vectors;
294
draw_tool = GIMP_DRAW_TOOL (tool);
295
vector_tool = GIMP_VECTOR_TOOL (tool);
296
options = GIMP_VECTOR_OPTIONS (tool->tool_info->tool_options);
298
/* do nothing if we are an FINISHED state */
299
if (vector_tool->function == VECTORS_FINISHED)
302
g_return_if_fail (vector_tool->vectors != NULL ||
303
vector_tool->function == VECTORS_SELECT_VECTOR ||
304
vector_tool->function == VECTORS_CREATE_VECTOR);
306
vector_tool->undo_motion = FALSE;
308
/* Save the current modifier state */
310
vector_tool->saved_state = state;
312
gimp_draw_tool_pause (draw_tool);
314
if (gimp_draw_tool_is_active (draw_tool) && draw_tool->gdisp != gdisp)
316
gimp_draw_tool_stop (draw_tool);
319
gimp_tool_control_activate (tool->control);
322
/* select a vectors object */
324
if (vector_tool->function == VECTORS_SELECT_VECTOR)
326
if (gimp_draw_tool_on_vectors (draw_tool, gdisp, coords, TARGET, TARGET,
327
NULL, NULL, NULL, NULL, NULL, &vectors))
329
gimp_vector_tool_set_vectors (vector_tool, vectors);
330
gimp_image_set_active_vectors (gdisp->gimage, vectors);
332
vector_tool->function = VECTORS_FINISHED;
335
/* create a new vector from scratch */
337
if (vector_tool->function == VECTORS_CREATE_VECTOR)
339
vectors = gimp_vectors_new (gdisp->gimage, _("Unnamed"));
341
/* Undo step gets added implicitely */
342
vector_tool->have_undo = TRUE;
344
vector_tool->undo_motion = TRUE;
346
gimp_image_add_vectors (gdisp->gimage, vectors, -1);
347
gimp_image_flush (gdisp->gimage);
349
gimp_vector_tool_set_vectors (vector_tool, vectors);
351
vector_tool->function = VECTORS_CREATE_STROKE;
355
gimp_vectors_freeze (vector_tool->vectors);
357
/* create a new stroke */
359
if (vector_tool->function == VECTORS_CREATE_STROKE)
361
g_return_if_fail (vector_tool->vectors != NULL);
363
gimp_vector_tool_undo_push (vector_tool, _("Add Stroke"));
365
vector_tool->cur_stroke = gimp_bezier_stroke_new ();
366
gimp_vectors_stroke_add (vector_tool->vectors, vector_tool->cur_stroke);
368
vector_tool->undo_motion = TRUE;
370
vector_tool->sel_stroke = vector_tool->cur_stroke;
371
vector_tool->cur_anchor = NULL;
372
vector_tool->sel_anchor = NULL;
373
vector_tool->function = VECTORS_ADD_ANCHOR;
377
/* add an anchor to an existing stroke */
379
if (vector_tool->function == VECTORS_ADD_ANCHOR)
381
gimp_vector_tool_undo_push (vector_tool, _("Add Anchor"));
383
vector_tool->undo_motion = TRUE;
385
vector_tool->cur_anchor =
386
gimp_bezier_stroke_extend (vector_tool->sel_stroke, coords,
387
vector_tool->sel_anchor,
390
vector_tool->restriction = GIMP_ANCHOR_FEATURE_SYMMETRIC;
392
if (!options->polygonal)
393
vector_tool->function = VECTORS_MOVE_HANDLE;
395
vector_tool->function = VECTORS_MOVE_ANCHOR;
396
vector_tool->cur_stroke = vector_tool->sel_stroke;
400
/* Insertion of an anchor in a curve segment */
402
if (vector_tool->function == VECTORS_INSERT_ANCHOR)
404
gimp_vector_tool_undo_push (vector_tool, _("Insert Anchor"));
406
vector_tool->undo_motion = TRUE;
408
vector_tool->cur_anchor =
409
gimp_stroke_anchor_insert (vector_tool->cur_stroke,
410
vector_tool->cur_anchor,
411
vector_tool->cur_position);
412
if (vector_tool->cur_anchor)
414
if (options->polygonal)
416
gimp_stroke_anchor_convert (vector_tool->cur_stroke,
417
vector_tool->cur_anchor,
418
GIMP_ANCHOR_FEATURE_EDGE);
420
vector_tool->function = VECTORS_MOVE_ANCHOR;
424
vector_tool->function = VECTORS_FINISHED;
431
if (vector_tool->function == VECTORS_MOVE_HANDLE)
433
gimp_vector_tool_undo_push (vector_tool, _("Drag Handle"));
435
if (vector_tool->cur_anchor->type == GIMP_ANCHOR_ANCHOR)
437
if (!vector_tool->cur_anchor->selected)
439
gimp_vectors_anchor_select (vector_tool->vectors,
440
vector_tool->cur_stroke,
441
vector_tool->cur_anchor,
443
vector_tool->undo_motion = TRUE;
446
gimp_draw_tool_on_vectors_handle (GIMP_DRAW_TOOL (tool), gdisp,
447
vector_tool->vectors, coords,
449
GIMP_ANCHOR_CONTROL, TRUE,
450
&vector_tool->cur_anchor,
451
&vector_tool->cur_stroke);
452
if (!vector_tool->cur_anchor)
453
vector_tool->function = VECTORS_FINISHED;
460
if (vector_tool->function == VECTORS_MOVE_ANCHOR)
462
gimp_vector_tool_undo_push (vector_tool, _("Drag Anchor"));
464
if (!vector_tool->cur_anchor->selected)
466
gimp_vectors_anchor_select (vector_tool->vectors,
467
vector_tool->cur_stroke,
468
vector_tool->cur_anchor,
470
vector_tool->undo_motion = TRUE;
475
/* move multiple anchors */
477
if (vector_tool->function == VECTORS_MOVE_ANCHORSET)
479
gimp_vector_tool_undo_push (vector_tool, _("Drag Anchors"));
481
if (state & TOGGLE_MASK)
483
gimp_vectors_anchor_select (vector_tool->vectors,
484
vector_tool->cur_stroke,
485
vector_tool->cur_anchor,
486
!vector_tool->cur_anchor->selected,
488
vector_tool->undo_motion = TRUE;
489
if (vector_tool->cur_anchor->selected == FALSE)
490
vector_tool->function = VECTORS_FINISHED;
495
/* move a curve segment directly */
497
if (vector_tool->function == VECTORS_MOVE_CURVE)
499
gimp_vector_tool_undo_push (vector_tool, _("Drag Curve"));
501
/* the magic numbers are taken from the "feel good" parameter
502
* from gimp_bezier_stroke_point_move_relative in gimpbezierstroke.c. */
503
if (vector_tool->cur_position < 5.0 / 6.0)
505
gimp_vectors_anchor_select (vector_tool->vectors,
506
vector_tool->cur_stroke,
507
vector_tool->cur_anchor, TRUE, TRUE);
508
vector_tool->undo_motion = TRUE;
511
if (vector_tool->cur_position > 1.0 / 6.0)
513
gimp_vectors_anchor_select (vector_tool->vectors,
514
vector_tool->cur_stroke,
515
vector_tool->cur_anchor2, TRUE,
516
(vector_tool->cur_position >= 5.0 / 6.0));
517
vector_tool->undo_motion = TRUE;
523
/* connect two strokes */
525
if (vector_tool->function == VECTORS_CONNECT_STROKES)
527
gimp_vector_tool_undo_push (vector_tool, _("Connect Strokes"));
529
gimp_stroke_connect_stroke (vector_tool->sel_stroke,
530
vector_tool->sel_anchor,
531
vector_tool->cur_stroke,
532
vector_tool->cur_anchor);
533
vector_tool->undo_motion = TRUE;
535
if (vector_tool->cur_stroke != vector_tool->sel_stroke &&
536
gimp_stroke_is_empty (vector_tool->cur_stroke))
538
gimp_vectors_stroke_remove (vector_tool->vectors,
539
vector_tool->cur_stroke);
541
vector_tool->sel_anchor = vector_tool->cur_anchor;
542
vector_tool->cur_stroke = vector_tool->sel_stroke;
544
gimp_vectors_anchor_select (vector_tool->vectors,
545
vector_tool->sel_stroke,
546
vector_tool->sel_anchor, TRUE, TRUE);
548
vector_tool->function = VECTORS_FINISHED;
552
/* move a stroke or all strokes of a vectors object */
554
if (vector_tool->function == VECTORS_MOVE_STROKE ||
555
vector_tool->function == VECTORS_MOVE_VECTORS)
557
gimp_vector_tool_undo_push (vector_tool, _("Drag Path"));
559
/* Work is being done in gimp_vector_tool_motion ()... */
563
/* convert an anchor to something that looks like an edge */
565
if (vector_tool->function == VECTORS_CONVERT_EDGE)
567
gimp_vector_tool_undo_push (vector_tool, _("Convert Edge"));
569
gimp_stroke_anchor_convert (vector_tool->cur_stroke,
570
vector_tool->cur_anchor,
571
GIMP_ANCHOR_FEATURE_EDGE);
572
vector_tool->undo_motion = TRUE;
574
if (vector_tool->cur_anchor->type == GIMP_ANCHOR_ANCHOR)
576
gimp_vectors_anchor_select (vector_tool->vectors,
577
vector_tool->cur_stroke,
578
vector_tool->cur_anchor, TRUE, TRUE);
580
vector_tool->function = VECTORS_MOVE_ANCHOR;
584
vector_tool->cur_stroke = NULL;
585
vector_tool->cur_anchor = NULL;
587
/* avoid doing anything stupid */
588
vector_tool->function = VECTORS_FINISHED;
593
/* removal of a node in a stroke */
595
if (vector_tool->function == VECTORS_DELETE_ANCHOR)
597
gimp_vector_tool_undo_push (vector_tool, _("Delete Anchor"));
599
gimp_stroke_anchor_delete (vector_tool->cur_stroke,
600
vector_tool->cur_anchor);
601
vector_tool->undo_motion = TRUE;
603
if (gimp_stroke_is_empty (vector_tool->cur_stroke))
604
gimp_vectors_stroke_remove (vector_tool->vectors,
605
vector_tool->cur_stroke);
607
vector_tool->cur_stroke = NULL;
608
vector_tool->cur_anchor = NULL;
609
vector_tool->function = VECTORS_FINISHED;
613
/* deleting a segment (opening up a stroke) */
615
if (vector_tool->function == VECTORS_DELETE_SEGMENT)
617
GimpStroke *new_stroke;
619
gimp_vector_tool_undo_push (vector_tool, _("Delete Segment"));
621
new_stroke = gimp_stroke_open (vector_tool->cur_stroke,
622
vector_tool->cur_anchor);
624
gimp_vectors_stroke_add (vector_tool->vectors, new_stroke);
626
vector_tool->undo_motion = TRUE;
627
vector_tool->cur_stroke = NULL;
628
vector_tool->cur_anchor = NULL;
629
vector_tool->function = VECTORS_FINISHED;
632
vector_tool->last_x = coords->x;
633
vector_tool->last_y = coords->y;
635
gimp_vectors_thaw (vector_tool->vectors);
637
if (! gimp_draw_tool_is_active (draw_tool))
639
gimp_draw_tool_start (draw_tool, gdisp);
642
gimp_draw_tool_resume (draw_tool);
646
gimp_vector_tool_button_release (GimpTool *tool,
649
GdkModifierType state,
652
GimpVectorTool *vector_tool = GIMP_VECTOR_TOOL (tool);
654
vector_tool->function = VECTORS_FINISHED;
656
if (vector_tool->have_undo &&
657
(! vector_tool->undo_motion || (state & GDK_BUTTON3_MASK)))
660
GimpUndoAccumulator accum = { 0, };
662
undo = gimp_undo_stack_pop_undo (gdisp->gimage->undo_stack,
663
GIMP_UNDO_MODE_UNDO, &accum);
665
gimp_image_undo_event (gdisp->gimage, GIMP_UNDO_EVENT_UNDO_EXPIRED, undo);
667
gimp_undo_free (undo, GIMP_UNDO_MODE_UNDO);
668
g_object_unref (undo);
671
vector_tool->have_undo = FALSE;
672
vector_tool->undo_motion = FALSE;
674
gimp_tool_control_halt (tool->control);
675
gimp_image_flush (gdisp->gimage);
679
gimp_vector_tool_motion (GimpTool *tool,
682
GdkModifierType state,
685
GimpVectorTool *vector_tool;
686
GimpVectorOptions *options;
689
vector_tool = GIMP_VECTOR_TOOL (tool);
690
options = GIMP_VECTOR_OPTIONS (tool->tool_info->tool_options);
692
if (vector_tool->function == VECTORS_FINISHED)
695
gimp_vectors_freeze (vector_tool->vectors);
697
if ((vector_tool->saved_state & TOGGLE_MASK) != (state & TOGGLE_MASK))
698
vector_tool->modifier_lock = FALSE;
700
if (!vector_tool->modifier_lock)
702
if (state & TOGGLE_MASK)
704
vector_tool->restriction = GIMP_ANCHOR_FEATURE_SYMMETRIC;
708
vector_tool->restriction = GIMP_ANCHOR_FEATURE_NONE;
712
switch (vector_tool->function)
714
case VECTORS_MOVE_ANCHOR:
715
case VECTORS_MOVE_HANDLE:
716
anchor = vector_tool->cur_anchor;
720
gimp_stroke_anchor_move_absolute (vector_tool->cur_stroke,
721
vector_tool->cur_anchor,
722
coords, vector_tool->restriction);
723
vector_tool->undo_motion = TRUE;
727
case VECTORS_MOVE_CURVE:
728
if (options->polygonal)
730
gimp_vector_tool_move_selected_anchors (vector_tool,
731
coords->x - vector_tool->last_x,
732
coords->y - vector_tool->last_y);
733
vector_tool->undo_motion = TRUE;
737
gimp_stroke_point_move_absolute (vector_tool->cur_stroke,
738
vector_tool->cur_anchor,
739
vector_tool->cur_position,
740
coords, vector_tool->restriction);
741
vector_tool->undo_motion = TRUE;
745
case VECTORS_MOVE_ANCHORSET:
746
gimp_vector_tool_move_selected_anchors (vector_tool,
747
coords->x - vector_tool->last_x,
748
coords->y - vector_tool->last_y);
749
vector_tool->undo_motion = TRUE;
752
case VECTORS_MOVE_STROKE:
753
if (vector_tool->cur_stroke)
755
gimp_stroke_translate (vector_tool->cur_stroke,
756
coords->x - vector_tool->last_x,
757
coords->y - vector_tool->last_y);
758
vector_tool->undo_motion = TRUE;
760
else if (vector_tool->sel_stroke)
762
gimp_stroke_translate (vector_tool->sel_stroke,
763
coords->x - vector_tool->last_x,
764
coords->y - vector_tool->last_y);
765
vector_tool->undo_motion = TRUE;
769
case VECTORS_MOVE_VECTORS:
770
gimp_item_translate (GIMP_ITEM (vector_tool->vectors),
771
coords->x - vector_tool->last_x,
772
coords->y - vector_tool->last_y, FALSE);
773
vector_tool->undo_motion = TRUE;
780
vector_tool->last_x = coords->x;
781
vector_tool->last_y = coords->y;
783
gimp_vectors_thaw (vector_tool->vectors);
787
gimp_vector_tool_key_press (GimpTool *tool,
791
GimpVectorTool *vector_tool = GIMP_VECTOR_TOOL (tool);
792
GimpDrawTool *draw_tool = GIMP_DRAW_TOOL (tool);
793
GimpVectorOptions *options;
795
GimpDisplayShell *shell;
796
gdouble xdist, ydist;
797
gdouble pixels = 1.0;
799
if (! vector_tool->vectors)
802
shell = GIMP_DISPLAY_SHELL (draw_tool->gdisp->shell);
804
if (kevent->state & GDK_SHIFT_MASK)
807
if (kevent->state & GDK_CONTROL_MASK)
810
if (gdisp == draw_tool->gdisp)
812
switch (kevent->keyval)
816
gimp_vector_tool_to_selection_extended (vector_tool, kevent->state);
821
gimp_vector_tool_delete_selected_anchors (vector_tool);
828
xdist = FUNSCALEX (shell, pixels);
829
ydist = FUNSCALEY (shell, pixels);
831
gimp_vector_tool_undo_push (vector_tool, _("Move Anchors"));
833
gimp_vectors_freeze (vector_tool->vectors);
835
switch (kevent->keyval)
838
gimp_vector_tool_move_selected_anchors (vector_tool, -xdist, 0);
842
gimp_vector_tool_move_selected_anchors (vector_tool, xdist, 0);
846
gimp_vector_tool_move_selected_anchors (vector_tool, 0, -ydist);
850
gimp_vector_tool_move_selected_anchors (vector_tool, 0, ydist);
857
gimp_vectors_thaw (vector_tool->vectors);
858
vector_tool->have_undo = FALSE;
862
options = GIMP_VECTOR_OPTIONS (tool->tool_info->tool_options);
864
if (options->edit_mode != GIMP_VECTOR_MODE_DESIGN)
865
g_object_set (options, "vectors-edit-mode",
866
GIMP_VECTOR_MODE_DESIGN, NULL);
873
gimp_image_flush (gdisp->gimage);
880
gimp_vector_tool_modifier_key (GimpTool *tool,
883
GdkModifierType state,
886
GimpVectorTool *vector_tool = GIMP_VECTOR_TOOL (tool);
887
GimpVectorOptions *options;
889
options = GIMP_VECTOR_OPTIONS (tool->tool_info->tool_options);
891
if (key == TOGGLE_MASK)
894
if (key == INSDEL_MASK || key == MOVE_MASK)
896
GimpVectorMode button_mode;
898
button_mode = options->edit_mode;
902
if (key == (state & (INSDEL_MASK | MOVE_MASK)))
904
/* first modifier pressed */
906
vector_tool->saved_mode = options->edit_mode;
911
if (! (state & (INSDEL_MASK | MOVE_MASK)))
913
/* last modifier released */
915
button_mode = vector_tool->saved_mode;
919
if (state & MOVE_MASK)
921
button_mode = GIMP_VECTOR_MODE_MOVE;
923
else if (state & INSDEL_MASK)
925
button_mode = GIMP_VECTOR_MODE_EDIT;
928
if (button_mode != options->edit_mode)
930
g_object_set (options, "vectors-edit-mode", button_mode, NULL);
936
gimp_vector_tool_oper_update (GimpTool *tool,
938
GdkModifierType state,
941
GimpVectorTool *vector_tool;
942
GimpDrawTool *draw_tool;
943
GimpVectorOptions *options;
944
GimpAnchor *anchor = NULL;
945
GimpAnchor *anchor2 = NULL;
946
GimpStroke *stroke = NULL;
947
gdouble position = -1;
948
gboolean on_handle = FALSE;
949
gboolean on_curve = FALSE;
950
gboolean on_vectors = FALSE;
952
vector_tool = GIMP_VECTOR_TOOL (tool);
953
options = GIMP_VECTOR_OPTIONS (tool->tool_info->tool_options);
955
draw_tool = GIMP_DRAW_TOOL (tool);
957
vector_tool->modifier_lock = FALSE;
959
/* are we hovering the current vectors on the current display? */
960
if (vector_tool->vectors && GIMP_DRAW_TOOL (tool)->gdisp == gdisp)
962
on_handle = gimp_draw_tool_on_vectors_handle (GIMP_DRAW_TOOL (tool),
964
vector_tool->vectors,
968
vector_tool->sel_count > 2,
972
on_curve = gimp_draw_tool_on_vectors_curve (GIMP_DRAW_TOOL (tool),
974
vector_tool->vectors,
982
if (on_handle || on_curve)
984
vector_tool->cur_vectors = NULL;
988
on_vectors = gimp_draw_tool_on_vectors (draw_tool, gdisp, coords,
990
NULL, NULL, NULL, NULL, NULL,
991
&(vector_tool->cur_vectors));
994
vector_tool->cur_position = position;
995
vector_tool->cur_anchor = anchor;
996
vector_tool->cur_anchor2 = anchor2;
997
vector_tool->cur_stroke = stroke;
999
switch (options->edit_mode)
1001
case GIMP_VECTOR_MODE_DESIGN:
1002
if (! vector_tool->vectors || GIMP_DRAW_TOOL (tool)->gdisp != gdisp)
1006
vector_tool->function = VECTORS_SELECT_VECTOR;
1010
vector_tool->function = VECTORS_CREATE_VECTOR;
1011
vector_tool->restriction = GIMP_ANCHOR_FEATURE_SYMMETRIC;
1012
vector_tool->modifier_lock = TRUE;
1017
if (anchor->type == GIMP_ANCHOR_ANCHOR)
1019
if (state & TOGGLE_MASK)
1021
vector_tool->function = VECTORS_MOVE_ANCHORSET;
1025
if (vector_tool->sel_count >= 2 && anchor->selected)
1026
vector_tool->function = VECTORS_MOVE_ANCHORSET;
1028
vector_tool->function = VECTORS_MOVE_ANCHOR;
1033
vector_tool->function = VECTORS_MOVE_HANDLE;
1034
if (state & TOGGLE_MASK)
1035
vector_tool->restriction = GIMP_ANCHOR_FEATURE_SYMMETRIC;
1037
vector_tool->restriction = GIMP_ANCHOR_FEATURE_NONE;
1042
if (gimp_stroke_point_is_movable (stroke, anchor, position))
1044
vector_tool->function = VECTORS_MOVE_CURVE;
1045
if (state & TOGGLE_MASK)
1046
vector_tool->restriction = GIMP_ANCHOR_FEATURE_SYMMETRIC;
1048
vector_tool->restriction = GIMP_ANCHOR_FEATURE_NONE;
1052
vector_tool->function = VECTORS_FINISHED;
1057
if (vector_tool->sel_stroke && vector_tool->sel_anchor &&
1058
gimp_stroke_is_extendable (vector_tool->sel_stroke,
1059
vector_tool->sel_anchor) &&
1060
!(state & TOGGLE_MASK))
1061
vector_tool->function = VECTORS_ADD_ANCHOR;
1063
vector_tool->function = VECTORS_CREATE_STROKE;
1065
vector_tool->restriction = GIMP_ANCHOR_FEATURE_SYMMETRIC;
1066
vector_tool->modifier_lock = TRUE;
1071
case GIMP_VECTOR_MODE_EDIT:
1072
if (! vector_tool->vectors || GIMP_DRAW_TOOL (tool)->gdisp != gdisp)
1076
vector_tool->function = VECTORS_SELECT_VECTOR;
1080
vector_tool->function = VECTORS_FINISHED;
1085
if (anchor->type == GIMP_ANCHOR_ANCHOR)
1087
if (!(state & TOGGLE_MASK) && vector_tool->sel_anchor &&
1088
vector_tool->sel_anchor != anchor &&
1089
gimp_stroke_is_extendable (vector_tool->sel_stroke,
1090
vector_tool->sel_anchor) &&
1091
gimp_stroke_is_extendable (stroke, anchor))
1093
vector_tool->function = VECTORS_CONNECT_STROKES;
1097
if (state & TOGGLE_MASK)
1099
vector_tool->function = VECTORS_DELETE_ANCHOR;
1103
if (options->polygonal)
1104
vector_tool->function = VECTORS_MOVE_ANCHOR;
1106
vector_tool->function = VECTORS_MOVE_HANDLE;
1112
if (state & TOGGLE_MASK)
1113
vector_tool->function = VECTORS_CONVERT_EDGE;
1115
vector_tool->function = VECTORS_MOVE_HANDLE;
1120
if (state & TOGGLE_MASK)
1122
vector_tool->function = VECTORS_DELETE_SEGMENT;
1124
else if (gimp_stroke_anchor_is_insertable (stroke, anchor, position))
1126
vector_tool->function = VECTORS_INSERT_ANCHOR;
1130
vector_tool->function = VECTORS_FINISHED;
1135
vector_tool->function = VECTORS_FINISHED;
1140
case GIMP_VECTOR_MODE_MOVE:
1141
if (! vector_tool->vectors || GIMP_DRAW_TOOL (tool)->gdisp != gdisp)
1145
vector_tool->function = VECTORS_SELECT_VECTOR;
1149
vector_tool->function = VECTORS_FINISHED;
1152
else if (on_handle || on_curve)
1154
if (state & TOGGLE_MASK)
1156
vector_tool->function = VECTORS_MOVE_VECTORS;
1160
vector_tool->function = VECTORS_MOVE_STROKE;
1167
vector_tool->function = VECTORS_SELECT_VECTOR;
1171
vector_tool->function = VECTORS_MOVE_VECTORS;
1177
gimp_vector_tool_status_update (tool, gdisp);
1182
gimp_vector_tool_status_update (GimpTool *tool,
1185
GimpVectorTool *vector_tool = GIMP_VECTOR_TOOL (tool);
1186
GimpDisplayShell *shell;
1187
const gchar *new_status = NULL;
1189
shell = tool->gdisp ? GIMP_DISPLAY_SHELL (tool->gdisp->shell) : NULL;
1191
if (shell && shell->proximity)
1193
switch (vector_tool->function)
1195
case VECTORS_SELECT_VECTOR:
1196
new_status = _("Click to pick path to edit.");
1198
case VECTORS_CREATE_VECTOR:
1199
new_status = _("Click to create a new path.");
1201
case VECTORS_CREATE_STROKE:
1202
new_status = _("Click to create a new component of the path.");
1204
case VECTORS_ADD_ANCHOR:
1205
new_status = _("Click to create a new anchor. (try SHIFT)");
1207
case VECTORS_MOVE_ANCHOR:
1208
new_status = _("Click-Drag to move the anchor around.");
1210
case VECTORS_MOVE_ANCHORSET:
1211
new_status = _("Click-Drag to move the anchors around.");
1213
case VECTORS_MOVE_HANDLE:
1214
new_status = _("Click-Drag to move the handle around. (try SHIFT)");
1216
case VECTORS_MOVE_CURVE:
1217
new_status = _("Click-Drag to change the shape of the curve. "
1218
"(SHIFT: symmetrical)");
1220
case VECTORS_MOVE_STROKE:
1221
new_status = _("Click-Drag to move the component around. "
1224
case VECTORS_MOVE_VECTORS:
1225
new_status = _("Click-Drag to move the path around.");
1227
case VECTORS_INSERT_ANCHOR:
1228
new_status = _("Click to insert an anchor on the path. (try SHIFT)");
1230
case VECTORS_DELETE_ANCHOR:
1231
new_status = _("Click to delete this anchor.");
1233
case VECTORS_CONNECT_STROKES:
1234
new_status = _("Click to connect this anchor "
1235
"with the selected endpoint.");
1237
case VECTORS_DELETE_SEGMENT:
1238
new_status = _("Click to open up the path.");
1240
case VECTORS_CONVERT_EDGE:
1241
new_status = _("Click to make this node angular.");
1243
case VECTORS_FINISHED:
1249
gimp_vector_tool_status_set (tool, gdisp, new_status);
1253
gimp_vector_tool_status_set (GimpTool *tool,
1255
const gchar *message)
1257
GimpVectorTool *vector_tool = GIMP_VECTOR_TOOL (tool);
1260
vector_tool->status_msg != message)
1262
if (vector_tool->status_msg)
1264
gimp_tool_pop_status (tool);
1265
vector_tool->status_msg = NULL;
1270
gimp_tool_push_status (tool, message);
1271
vector_tool->status_msg = message;
1277
gimp_vector_tool_cursor_update (GimpTool *tool,
1279
GdkModifierType state,
1282
GimpVectorTool *vector_tool;
1283
GimpCursorType cursor;
1284
GimpToolCursorType tool_cursor;
1285
GimpCursorModifier cmodifier;
1287
vector_tool = GIMP_VECTOR_TOOL (tool);
1289
cursor = GIMP_CURSOR_MOUSE;
1290
tool_cursor = GIMP_TOOL_CURSOR_PATHS;
1291
cmodifier = GIMP_CURSOR_MODIFIER_NONE;
1293
switch (vector_tool->function)
1295
case VECTORS_SELECT_VECTOR:
1297
tool_cursor = GIMP_TOOL_CURSOR_HAND;
1299
case VECTORS_CREATE_VECTOR:
1300
case VECTORS_CREATE_STROKE:
1301
cmodifier = GIMP_CURSOR_MODIFIER_CONTROL;
1303
case VECTORS_ADD_ANCHOR:
1304
case VECTORS_INSERT_ANCHOR:
1305
cmodifier = GIMP_CURSOR_MODIFIER_PLUS;
1307
case VECTORS_DELETE_ANCHOR:
1308
case VECTORS_DELETE_SEGMENT:
1309
cmodifier = GIMP_CURSOR_MODIFIER_MINUS;
1311
case VECTORS_MOVE_HANDLE:
1312
case VECTORS_CONVERT_EDGE:
1314
tool_cursor = GIMP_TOOL_CURSOR_HAND;
1315
cmodifier = GIMP_CURSOR_MODIFIER_CONTROL;
1317
case VECTORS_MOVE_ANCHOR:
1318
case VECTORS_MOVE_CURVE:
1319
case VECTORS_MOVE_STROKE:
1320
case VECTORS_MOVE_VECTORS:
1321
case VECTORS_MOVE_ANCHORSET:
1322
cmodifier = GIMP_CURSOR_MODIFIER_MOVE;
1324
case VECTORS_CONNECT_STROKES:
1325
cmodifier = GIMP_CURSOR_MODIFIER_INTERSECT;
1328
cursor = GIMP_CURSOR_BAD;
1332
gimp_tool_control_set_cursor (tool->control, cursor);
1333
gimp_tool_control_set_tool_cursor (tool->control, tool_cursor);
1334
gimp_tool_control_set_cursor_modifier (tool->control, cmodifier);
1336
GIMP_TOOL_CLASS (parent_class)->cursor_update (tool, coords, state, gdisp);
1340
gimp_vector_tool_draw (GimpDrawTool *draw_tool)
1342
GimpVectorTool *vector_tool = GIMP_VECTOR_TOOL (draw_tool);
1343
GimpAnchor *cur_anchor = NULL;
1344
GimpStroke *cur_stroke = NULL;
1345
GimpVectors *vectors;
1348
GList *draw_anchors;
1351
vectors = vector_tool->vectors;
1356
while ((cur_stroke = gimp_vectors_stroke_get_next (vectors, cur_stroke)))
1358
/* anchor handles */
1359
draw_anchors = gimp_stroke_get_draw_anchors (cur_stroke);
1361
for (list = draw_anchors; list; list = g_list_next (list))
1363
cur_anchor = GIMP_ANCHOR (list->data);
1365
if (cur_anchor->type == GIMP_ANCHOR_ANCHOR)
1367
gimp_draw_tool_draw_handle (draw_tool,
1368
cur_anchor->selected ?
1369
GIMP_HANDLE_CIRCLE :
1370
GIMP_HANDLE_FILLED_CIRCLE,
1371
cur_anchor->position.x,
1372
cur_anchor->position.y,
1380
g_list_free (draw_anchors);
1382
if (vector_tool->sel_count <= 2)
1384
/* control handles */
1385
draw_anchors = gimp_stroke_get_draw_controls (cur_stroke);
1387
for (list = draw_anchors; list; list = g_list_next (list))
1389
cur_anchor = GIMP_ANCHOR (list->data);
1391
gimp_draw_tool_draw_handle (draw_tool,
1393
cur_anchor->position.x,
1394
cur_anchor->position.y,
1401
g_list_free (draw_anchors);
1403
/* the lines to the control handles */
1404
coords = gimp_stroke_get_draw_lines (cur_stroke);
1408
if (coords->len % 2 == 0)
1412
for (i = 0; i < coords->len; i += 2)
1414
gimp_draw_tool_draw_dashed_line (draw_tool,
1415
g_array_index (coords, GimpCoords, i).x,
1416
g_array_index (coords, GimpCoords, i).y,
1417
g_array_index (coords, GimpCoords, i + 1).x,
1418
g_array_index (coords, GimpCoords, i + 1).y,
1423
g_array_free (coords, TRUE);
1427
/* the stroke itself */
1428
if (! gimp_item_get_visible (GIMP_ITEM (vectors)))
1430
coords = gimp_stroke_interpolate (cur_stroke, 1.0, &closed);
1435
gimp_draw_tool_draw_strokes (draw_tool,
1436
&g_array_index (coords,
1438
coords->len, FALSE, FALSE);
1440
g_array_free (coords, TRUE);
1447
gimp_vector_tool_vectors_changed (GimpImage *gimage,
1448
GimpVectorTool *vector_tool)
1450
gimp_vector_tool_set_vectors (vector_tool,
1451
gimp_image_get_active_vectors (gimage));
1455
gimp_vector_tool_vectors_removed (GimpVectors *vectors,
1456
GimpVectorTool *vector_tool)
1458
gimp_vector_tool_set_vectors (vector_tool, NULL);
1462
gimp_vector_tool_vectors_visible (GimpVectors *vectors,
1463
GimpVectorTool *vector_tool)
1465
GimpDrawTool *draw_tool = GIMP_DRAW_TOOL (vector_tool);
1467
if (gimp_draw_tool_is_active (draw_tool) && draw_tool->paused_count == 0)
1469
GimpStroke *stroke = NULL;
1471
while ((stroke = gimp_vectors_stroke_get_next (vectors, stroke)))
1476
coords = gimp_stroke_interpolate (stroke, 1.0, &closed);
1481
gimp_draw_tool_draw_strokes (draw_tool,
1482
&g_array_index (coords,
1484
coords->len, FALSE, FALSE);
1486
g_array_free (coords, TRUE);
1493
gimp_vector_tool_vectors_freeze (GimpVectors *vectors,
1494
GimpVectorTool *vector_tool)
1496
gimp_draw_tool_pause (GIMP_DRAW_TOOL (vector_tool));
1500
gimp_vector_tool_vectors_thaw (GimpVectors *vectors,
1501
GimpVectorTool *vector_tool)
1503
/* Ok, the vector might have changed externally (e.g. Undo)
1504
* we need to validate our internal state. */
1505
gimp_vector_tool_verify_state (vector_tool);
1507
gimp_draw_tool_resume (GIMP_DRAW_TOOL (vector_tool));
1511
gimp_vector_tool_set_vectors (GimpVectorTool *vector_tool,
1512
GimpVectors *vectors)
1514
GimpDrawTool *draw_tool;
1516
GimpItem *item = NULL;
1517
GtkWidget *stroke_button;
1518
GtkWidget *sel_button;
1519
GimpVectorOptions *options;
1521
g_return_if_fail (GIMP_IS_VECTOR_TOOL (vector_tool));
1522
g_return_if_fail (vectors == NULL || GIMP_IS_VECTORS (vectors));
1524
draw_tool = GIMP_DRAW_TOOL (vector_tool);
1525
tool = GIMP_TOOL (vector_tool);
1526
options = GIMP_VECTOR_OPTIONS (tool->tool_info->tool_options);
1529
item = GIMP_ITEM (vectors);
1531
if (vectors == vector_tool->vectors)
1534
gimp_draw_tool_pause (draw_tool);
1536
if (gimp_draw_tool_is_active (draw_tool) &&
1537
(! vectors || draw_tool->gdisp->gimage != item->gimage))
1539
gimp_draw_tool_stop (draw_tool);
1542
stroke_button = g_object_get_data (G_OBJECT (options),
1543
"gimp-stroke-vectors");
1544
sel_button = g_object_get_data (G_OBJECT (options),
1545
"gimp-vectors-to-selection");
1547
if (vector_tool->vectors)
1549
GimpImage *old_gimage;
1551
old_gimage = gimp_item_get_image (GIMP_ITEM (vector_tool->vectors));
1553
g_signal_handlers_disconnect_by_func (old_gimage,
1554
gimp_vector_tool_vectors_changed,
1556
g_signal_handlers_disconnect_by_func (vector_tool->vectors,
1557
gimp_vector_tool_vectors_removed,
1559
g_signal_handlers_disconnect_by_func (vector_tool->vectors,
1560
gimp_vector_tool_vectors_visible,
1562
g_signal_handlers_disconnect_by_func (vector_tool->vectors,
1563
gimp_vector_tool_vectors_freeze,
1565
g_signal_handlers_disconnect_by_func (vector_tool->vectors,
1566
gimp_vector_tool_vectors_thaw,
1568
g_object_unref (vector_tool->vectors);
1572
gtk_widget_set_sensitive (sel_button, FALSE);
1573
g_signal_handlers_disconnect_by_func (sel_button,
1574
gimp_vector_tool_to_selection,
1576
g_signal_handlers_disconnect_by_func (sel_button,
1577
gimp_vector_tool_to_selection_extended,
1583
gtk_widget_set_sensitive (stroke_button, FALSE);
1584
g_signal_handlers_disconnect_by_func (stroke_button,
1585
gimp_vector_tool_stroke_vectors,
1590
vector_tool->vectors = vectors;
1591
vector_tool->function = VECTORS_FINISHED;
1592
gimp_vector_tool_verify_state (vector_tool);
1594
if (! vector_tool->vectors)
1598
/* leave draw_tool->paused_count in a consistent state */
1599
gimp_draw_tool_resume (draw_tool);
1601
vector_tool->function = VECTORS_CREATE_VECTOR;
1606
g_object_ref (vectors);
1608
g_signal_connect_object (item->gimage, "active_vectors_changed",
1609
G_CALLBACK (gimp_vector_tool_vectors_changed),
1611
g_signal_connect_object (vectors, "removed",
1612
G_CALLBACK (gimp_vector_tool_vectors_removed),
1614
g_signal_connect_object (vectors, "visibility_changed",
1615
G_CALLBACK (gimp_vector_tool_vectors_visible),
1617
g_signal_connect_object (vectors, "freeze",
1618
G_CALLBACK (gimp_vector_tool_vectors_freeze),
1620
g_signal_connect_object (vectors, "thaw",
1621
G_CALLBACK (gimp_vector_tool_vectors_thaw),
1626
g_signal_connect_swapped (sel_button, "clicked",
1627
G_CALLBACK (gimp_vector_tool_to_selection),
1629
g_signal_connect_swapped (sel_button, "extended_clicked",
1630
G_CALLBACK (gimp_vector_tool_to_selection_extended),
1632
gtk_widget_set_sensitive (sel_button, TRUE);
1637
g_signal_connect_swapped (stroke_button, "clicked",
1638
G_CALLBACK (gimp_vector_tool_stroke_vectors),
1640
gtk_widget_set_sensitive (stroke_button, TRUE);
1643
if (! gimp_draw_tool_is_active (draw_tool))
1645
if (tool->gdisp && tool->gdisp->gimage == item->gimage)
1647
gimp_draw_tool_start (draw_tool, tool->gdisp);
1651
GimpContext *context;
1654
context = gimp_get_user_context (tool->tool_info->gimp);
1655
gdisp = gimp_context_get_display (context);
1657
if (! gdisp || gdisp->gimage != item->gimage)
1663
for (list = GIMP_LIST (item->gimage->gimp->displays)->list;
1665
list = g_list_next (list))
1667
if (((GimpDisplay *) list->data)->gimage == item->gimage)
1669
gimp_context_set_display (context,
1670
(GimpDisplay *) list->data);
1672
gdisp = gimp_context_get_display (context);
1678
tool->gdisp = gdisp;
1682
gimp_draw_tool_start (draw_tool, tool->gdisp);
1687
gimp_draw_tool_resume (draw_tool);
1691
gimp_vector_tool_move_selected_anchors (GimpVectorTool *vector_tool,
1695
GimpAnchor *cur_anchor;
1696
GimpStroke *cur_stroke = NULL;
1699
GimpCoords offset = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
1704
while ((cur_stroke = gimp_vectors_stroke_get_next (vector_tool->vectors,
1708
anchors = gimp_stroke_get_draw_anchors (cur_stroke);
1710
for (list = anchors; list; list = g_list_next (list))
1712
cur_anchor = GIMP_ANCHOR (list->data);
1714
if (cur_anchor->selected)
1715
gimp_stroke_anchor_move_relative (cur_stroke,
1718
GIMP_ANCHOR_FEATURE_NONE);
1721
g_list_free (anchors);
1726
gimp_vector_tool_delete_selected_anchors (GimpVectorTool *vector_tool)
1728
GimpAnchor *cur_anchor;
1729
GimpStroke *cur_stroke = NULL;
1732
gboolean have_undo = FALSE;
1734
gimp_draw_tool_pause (GIMP_DRAW_TOOL (vector_tool));
1735
gimp_vectors_freeze (vector_tool->vectors);
1737
while ((cur_stroke = gimp_vectors_stroke_get_next (vector_tool->vectors,
1741
anchors = gimp_stroke_get_draw_anchors (cur_stroke);
1743
for (list = anchors; list; list = g_list_next (list))
1745
cur_anchor = GIMP_ANCHOR (list->data);
1747
if (cur_anchor->selected)
1751
gimp_vector_tool_undo_push (vector_tool, _("Delete Anchors"));
1755
gimp_stroke_anchor_delete (cur_stroke, cur_anchor);
1757
if (gimp_stroke_is_empty (cur_stroke))
1758
gimp_vectors_stroke_remove (vector_tool->vectors, cur_stroke);
1762
g_list_free (anchors);
1765
gimp_vectors_thaw (vector_tool->vectors);
1766
gimp_draw_tool_resume (GIMP_DRAW_TOOL (vector_tool));
1770
gimp_vector_tool_verify_state (GimpVectorTool *vector_tool)
1772
GimpStroke *cur_stroke = NULL;
1773
GimpAnchor *cur_anchor;
1776
gboolean cur_anchor_valid;
1777
gboolean cur_stroke_valid;
1779
cur_anchor_valid = FALSE;
1780
cur_stroke_valid = FALSE;
1782
vector_tool->sel_count = 0;
1783
vector_tool->sel_anchor = NULL;
1784
vector_tool->sel_stroke = NULL;
1786
if (!vector_tool->vectors)
1788
vector_tool->cur_position = -1;
1789
vector_tool->cur_anchor = NULL;
1790
vector_tool->cur_stroke = NULL;
1794
while ((cur_stroke = gimp_vectors_stroke_get_next (vector_tool->vectors,
1797
/* anchor handles */
1798
anchors = gimp_stroke_get_draw_anchors (cur_stroke);
1800
if (cur_stroke == vector_tool->cur_stroke)
1801
cur_stroke_valid = TRUE;
1803
for (list = anchors; list; list = g_list_next (list))
1805
cur_anchor = GIMP_ANCHOR (list->data);
1807
if (cur_anchor == vector_tool->cur_anchor)
1808
cur_anchor_valid = TRUE;
1810
if (cur_anchor->type == GIMP_ANCHOR_ANCHOR &&
1811
cur_anchor->selected)
1813
vector_tool->sel_count++;
1814
if (vector_tool->sel_count == 1)
1816
vector_tool->sel_anchor = cur_anchor;
1817
vector_tool->sel_stroke = cur_stroke;
1821
vector_tool->sel_anchor = NULL;
1822
vector_tool->sel_stroke = NULL;
1827
anchors = gimp_stroke_get_draw_controls (cur_stroke);
1829
for (list = anchors; list; list = g_list_next (list))
1831
cur_anchor = GIMP_ANCHOR (list->data);
1833
if (cur_anchor == vector_tool->cur_anchor)
1834
cur_anchor_valid = TRUE;
1838
if (!cur_stroke_valid)
1839
vector_tool->cur_stroke = NULL;
1841
if (!cur_anchor_valid)
1842
vector_tool->cur_anchor = NULL;
1847
gimp_vector_tool_undo_push (GimpVectorTool *vector_tool, const gchar *desc)
1849
g_return_if_fail (vector_tool->vectors != NULL);
1851
/* don't push two undos */
1852
if (vector_tool->have_undo)
1855
gimp_image_undo_push_vectors_mod (GIMP_ITEM (vector_tool->vectors)->gimage,
1856
desc, vector_tool->vectors);
1857
vector_tool->have_undo = TRUE;
1862
gimp_vector_tool_to_selection (GimpVectorTool *vector_tool)
1864
gimp_vector_tool_to_selection_extended (vector_tool, 0);
1869
gimp_vector_tool_to_selection_extended (GimpVectorTool *vector_tool,
1873
GimpChannelOps operation = GIMP_CHANNEL_OP_REPLACE;
1875
if (! vector_tool->vectors)
1878
gimage = gimp_item_get_image (GIMP_ITEM (vector_tool->vectors));
1880
if (state & GDK_SHIFT_MASK)
1882
if (state & GDK_CONTROL_MASK)
1883
operation = GIMP_CHANNEL_OP_INTERSECT;
1885
operation = GIMP_CHANNEL_OP_ADD;
1887
else if (state & GDK_CONTROL_MASK)
1889
operation = GIMP_CHANNEL_OP_SUBTRACT;
1892
gimp_channel_select_vectors (gimp_image_get_mask (gimage),
1893
_("Path to selection"),
1894
vector_tool->vectors,
1897
gimp_image_flush (gimage);
1902
gimp_vector_tool_stroke_vectors (GimpVectorTool *vector_tool,
1906
GimpDrawable *active_drawable;
1909
if (! vector_tool->vectors)
1912
gimage = gimp_item_get_image (GIMP_ITEM (vector_tool->vectors));
1914
active_drawable = gimp_image_active_drawable (gimage);
1916
if (! active_drawable)
1918
g_message (_("There is no active layer or channel to stroke to"));
1922
dialog = stroke_dialog_new (GIMP_ITEM (vector_tool->vectors),
1924
GIMP_STOCK_PATH_STROKE,
1925
GIMP_HELP_PATH_STROKE,
1927
gtk_widget_show (dialog);