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
if (GIMP_VECTOR_OPTIONS (tool->tool_info->tool_options)->polygonal)
1218
new_status = _("Click-Drag to move the anchors around.");
1220
new_status = _("Click-Drag to change the shape of the curve. "
1221
"(SHIFT: symmetrical)");
1223
case VECTORS_MOVE_STROKE:
1224
new_status = _("Click-Drag to move the component around. "
1227
case VECTORS_MOVE_VECTORS:
1228
new_status = _("Click-Drag to move the path around.");
1230
case VECTORS_INSERT_ANCHOR:
1231
new_status = _("Click to insert an anchor on the path. (try SHIFT)");
1233
case VECTORS_DELETE_ANCHOR:
1234
new_status = _("Click to delete this anchor.");
1236
case VECTORS_CONNECT_STROKES:
1237
new_status = _("Click to connect this anchor "
1238
"with the selected endpoint.");
1240
case VECTORS_DELETE_SEGMENT:
1241
new_status = _("Click to open up the path.");
1243
case VECTORS_CONVERT_EDGE:
1244
new_status = _("Click to make this node angular.");
1246
case VECTORS_FINISHED:
1252
gimp_vector_tool_status_set (tool, gdisp, new_status);
1256
gimp_vector_tool_status_set (GimpTool *tool,
1258
const gchar *message)
1260
GimpVectorTool *vector_tool = GIMP_VECTOR_TOOL (tool);
1263
vector_tool->status_msg != message)
1265
if (vector_tool->status_msg)
1267
gimp_tool_pop_status (tool);
1268
vector_tool->status_msg = NULL;
1273
gimp_tool_push_status (tool, message);
1274
vector_tool->status_msg = message;
1280
gimp_vector_tool_cursor_update (GimpTool *tool,
1282
GdkModifierType state,
1285
GimpVectorTool *vector_tool;
1286
GimpCursorType cursor;
1287
GimpToolCursorType tool_cursor;
1288
GimpCursorModifier cmodifier;
1290
vector_tool = GIMP_VECTOR_TOOL (tool);
1292
cursor = GIMP_CURSOR_MOUSE;
1293
tool_cursor = GIMP_TOOL_CURSOR_PATHS;
1294
cmodifier = GIMP_CURSOR_MODIFIER_NONE;
1296
switch (vector_tool->function)
1298
case VECTORS_SELECT_VECTOR:
1300
tool_cursor = GIMP_TOOL_CURSOR_HAND;
1303
case VECTORS_CREATE_VECTOR:
1304
case VECTORS_CREATE_STROKE:
1305
cmodifier = GIMP_CURSOR_MODIFIER_CONTROL;
1308
case VECTORS_ADD_ANCHOR:
1309
case VECTORS_INSERT_ANCHOR:
1310
cmodifier = GIMP_CURSOR_MODIFIER_PLUS;
1313
case VECTORS_DELETE_ANCHOR:
1314
case VECTORS_DELETE_SEGMENT:
1315
cmodifier = GIMP_CURSOR_MODIFIER_MINUS;
1318
case VECTORS_MOVE_HANDLE:
1319
case VECTORS_CONVERT_EDGE:
1321
tool_cursor = GIMP_TOOL_CURSOR_HAND;
1322
cmodifier = GIMP_CURSOR_MODIFIER_CONTROL;
1325
case VECTORS_MOVE_ANCHOR:
1326
case VECTORS_MOVE_CURVE:
1327
case VECTORS_MOVE_STROKE:
1328
case VECTORS_MOVE_VECTORS:
1329
case VECTORS_MOVE_ANCHORSET:
1330
cmodifier = GIMP_CURSOR_MODIFIER_MOVE;
1333
case VECTORS_CONNECT_STROKES:
1334
cmodifier = GIMP_CURSOR_MODIFIER_INTERSECT;
1338
cursor = GIMP_CURSOR_BAD;
1342
gimp_tool_control_set_cursor (tool->control, cursor);
1343
gimp_tool_control_set_tool_cursor (tool->control, tool_cursor);
1344
gimp_tool_control_set_cursor_modifier (tool->control, cmodifier);
1346
GIMP_TOOL_CLASS (parent_class)->cursor_update (tool, coords, state, gdisp);
1350
gimp_vector_tool_draw (GimpDrawTool *draw_tool)
1352
GimpVectorTool *vector_tool = GIMP_VECTOR_TOOL (draw_tool);
1353
GimpAnchor *cur_anchor = NULL;
1354
GimpStroke *cur_stroke = NULL;
1355
GimpVectors *vectors;
1358
GList *draw_anchors;
1361
vectors = vector_tool->vectors;
1366
while ((cur_stroke = gimp_vectors_stroke_get_next (vectors, cur_stroke)))
1368
/* anchor handles */
1369
draw_anchors = gimp_stroke_get_draw_anchors (cur_stroke);
1371
for (list = draw_anchors; list; list = g_list_next (list))
1373
cur_anchor = GIMP_ANCHOR (list->data);
1375
if (cur_anchor->type == GIMP_ANCHOR_ANCHOR)
1377
gimp_draw_tool_draw_handle (draw_tool,
1378
cur_anchor->selected ?
1379
GIMP_HANDLE_CIRCLE :
1380
GIMP_HANDLE_FILLED_CIRCLE,
1381
cur_anchor->position.x,
1382
cur_anchor->position.y,
1390
g_list_free (draw_anchors);
1392
if (vector_tool->sel_count <= 2)
1394
/* control handles */
1395
draw_anchors = gimp_stroke_get_draw_controls (cur_stroke);
1397
for (list = draw_anchors; list; list = g_list_next (list))
1399
cur_anchor = GIMP_ANCHOR (list->data);
1401
gimp_draw_tool_draw_handle (draw_tool,
1403
cur_anchor->position.x,
1404
cur_anchor->position.y,
1411
g_list_free (draw_anchors);
1413
/* the lines to the control handles */
1414
coords = gimp_stroke_get_draw_lines (cur_stroke);
1418
if (coords->len % 2 == 0)
1422
for (i = 0; i < coords->len; i += 2)
1424
gimp_draw_tool_draw_dashed_line (draw_tool,
1425
g_array_index (coords, GimpCoords, i).x,
1426
g_array_index (coords, GimpCoords, i).y,
1427
g_array_index (coords, GimpCoords, i + 1).x,
1428
g_array_index (coords, GimpCoords, i + 1).y,
1433
g_array_free (coords, TRUE);
1437
/* the stroke itself */
1438
if (! gimp_item_get_visible (GIMP_ITEM (vectors)))
1440
coords = gimp_stroke_interpolate (cur_stroke, 1.0, &closed);
1445
gimp_draw_tool_draw_strokes (draw_tool,
1446
&g_array_index (coords,
1448
coords->len, FALSE, FALSE);
1450
g_array_free (coords, TRUE);
1457
gimp_vector_tool_vectors_changed (GimpImage *gimage,
1458
GimpVectorTool *vector_tool)
1460
gimp_vector_tool_set_vectors (vector_tool,
1461
gimp_image_get_active_vectors (gimage));
1465
gimp_vector_tool_vectors_removed (GimpVectors *vectors,
1466
GimpVectorTool *vector_tool)
1468
gimp_vector_tool_set_vectors (vector_tool, NULL);
1472
gimp_vector_tool_vectors_visible (GimpVectors *vectors,
1473
GimpVectorTool *vector_tool)
1475
GimpDrawTool *draw_tool = GIMP_DRAW_TOOL (vector_tool);
1477
if (gimp_draw_tool_is_active (draw_tool) && draw_tool->paused_count == 0)
1479
GimpStroke *stroke = NULL;
1481
while ((stroke = gimp_vectors_stroke_get_next (vectors, stroke)))
1486
coords = gimp_stroke_interpolate (stroke, 1.0, &closed);
1491
gimp_draw_tool_draw_strokes (draw_tool,
1492
&g_array_index (coords,
1494
coords->len, FALSE, FALSE);
1496
g_array_free (coords, TRUE);
1503
gimp_vector_tool_vectors_freeze (GimpVectors *vectors,
1504
GimpVectorTool *vector_tool)
1506
gimp_draw_tool_pause (GIMP_DRAW_TOOL (vector_tool));
1510
gimp_vector_tool_vectors_thaw (GimpVectors *vectors,
1511
GimpVectorTool *vector_tool)
1513
/* Ok, the vector might have changed externally (e.g. Undo)
1514
* we need to validate our internal state. */
1515
gimp_vector_tool_verify_state (vector_tool);
1517
gimp_draw_tool_resume (GIMP_DRAW_TOOL (vector_tool));
1521
gimp_vector_tool_set_vectors (GimpVectorTool *vector_tool,
1522
GimpVectors *vectors)
1524
GimpDrawTool *draw_tool;
1526
GimpItem *item = NULL;
1527
GtkWidget *stroke_button;
1528
GtkWidget *sel_button;
1529
GimpVectorOptions *options;
1531
g_return_if_fail (GIMP_IS_VECTOR_TOOL (vector_tool));
1532
g_return_if_fail (vectors == NULL || GIMP_IS_VECTORS (vectors));
1534
draw_tool = GIMP_DRAW_TOOL (vector_tool);
1535
tool = GIMP_TOOL (vector_tool);
1536
options = GIMP_VECTOR_OPTIONS (tool->tool_info->tool_options);
1539
item = GIMP_ITEM (vectors);
1541
if (vectors == vector_tool->vectors)
1544
gimp_draw_tool_pause (draw_tool);
1546
if (gimp_draw_tool_is_active (draw_tool) &&
1547
(! vectors || draw_tool->gdisp->gimage != item->gimage))
1549
gimp_draw_tool_stop (draw_tool);
1552
stroke_button = g_object_get_data (G_OBJECT (options),
1553
"gimp-stroke-vectors");
1554
sel_button = g_object_get_data (G_OBJECT (options),
1555
"gimp-vectors-to-selection");
1557
if (vector_tool->vectors)
1559
GimpImage *old_gimage;
1561
old_gimage = gimp_item_get_image (GIMP_ITEM (vector_tool->vectors));
1563
g_signal_handlers_disconnect_by_func (old_gimage,
1564
gimp_vector_tool_vectors_changed,
1566
g_signal_handlers_disconnect_by_func (vector_tool->vectors,
1567
gimp_vector_tool_vectors_removed,
1569
g_signal_handlers_disconnect_by_func (vector_tool->vectors,
1570
gimp_vector_tool_vectors_visible,
1572
g_signal_handlers_disconnect_by_func (vector_tool->vectors,
1573
gimp_vector_tool_vectors_freeze,
1575
g_signal_handlers_disconnect_by_func (vector_tool->vectors,
1576
gimp_vector_tool_vectors_thaw,
1578
g_object_unref (vector_tool->vectors);
1582
gtk_widget_set_sensitive (sel_button, FALSE);
1583
g_signal_handlers_disconnect_by_func (sel_button,
1584
gimp_vector_tool_to_selection,
1586
g_signal_handlers_disconnect_by_func (sel_button,
1587
gimp_vector_tool_to_selection_extended,
1593
gtk_widget_set_sensitive (stroke_button, FALSE);
1594
g_signal_handlers_disconnect_by_func (stroke_button,
1595
gimp_vector_tool_stroke_vectors,
1600
vector_tool->vectors = vectors;
1601
vector_tool->function = VECTORS_FINISHED;
1602
gimp_vector_tool_verify_state (vector_tool);
1604
if (! vector_tool->vectors)
1608
/* leave draw_tool->paused_count in a consistent state */
1609
gimp_draw_tool_resume (draw_tool);
1611
vector_tool->function = VECTORS_CREATE_VECTOR;
1616
g_object_ref (vectors);
1618
g_signal_connect_object (item->gimage, "active_vectors_changed",
1619
G_CALLBACK (gimp_vector_tool_vectors_changed),
1621
g_signal_connect_object (vectors, "removed",
1622
G_CALLBACK (gimp_vector_tool_vectors_removed),
1624
g_signal_connect_object (vectors, "visibility_changed",
1625
G_CALLBACK (gimp_vector_tool_vectors_visible),
1627
g_signal_connect_object (vectors, "freeze",
1628
G_CALLBACK (gimp_vector_tool_vectors_freeze),
1630
g_signal_connect_object (vectors, "thaw",
1631
G_CALLBACK (gimp_vector_tool_vectors_thaw),
1636
g_signal_connect_swapped (sel_button, "clicked",
1637
G_CALLBACK (gimp_vector_tool_to_selection),
1639
g_signal_connect_swapped (sel_button, "extended_clicked",
1640
G_CALLBACK (gimp_vector_tool_to_selection_extended),
1642
gtk_widget_set_sensitive (sel_button, TRUE);
1647
g_signal_connect_swapped (stroke_button, "clicked",
1648
G_CALLBACK (gimp_vector_tool_stroke_vectors),
1650
gtk_widget_set_sensitive (stroke_button, TRUE);
1653
if (! gimp_draw_tool_is_active (draw_tool))
1655
if (tool->gdisp && tool->gdisp->gimage == item->gimage)
1657
gimp_draw_tool_start (draw_tool, tool->gdisp);
1661
GimpContext *context;
1664
context = gimp_get_user_context (tool->tool_info->gimp);
1665
gdisp = gimp_context_get_display (context);
1667
if (! gdisp || gdisp->gimage != item->gimage)
1673
for (list = GIMP_LIST (item->gimage->gimp->displays)->list;
1675
list = g_list_next (list))
1677
if (((GimpDisplay *) list->data)->gimage == item->gimage)
1679
gimp_context_set_display (context,
1680
(GimpDisplay *) list->data);
1682
gdisp = gimp_context_get_display (context);
1688
tool->gdisp = gdisp;
1692
gimp_draw_tool_start (draw_tool, tool->gdisp);
1697
gimp_draw_tool_resume (draw_tool);
1701
gimp_vector_tool_move_selected_anchors (GimpVectorTool *vector_tool,
1705
GimpAnchor *cur_anchor;
1706
GimpStroke *cur_stroke = NULL;
1709
GimpCoords offset = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
1714
while ((cur_stroke = gimp_vectors_stroke_get_next (vector_tool->vectors,
1718
anchors = gimp_stroke_get_draw_anchors (cur_stroke);
1720
for (list = anchors; list; list = g_list_next (list))
1722
cur_anchor = GIMP_ANCHOR (list->data);
1724
if (cur_anchor->selected)
1725
gimp_stroke_anchor_move_relative (cur_stroke,
1728
GIMP_ANCHOR_FEATURE_NONE);
1731
g_list_free (anchors);
1736
gimp_vector_tool_delete_selected_anchors (GimpVectorTool *vector_tool)
1738
GimpAnchor *cur_anchor;
1739
GimpStroke *cur_stroke = NULL;
1742
gboolean have_undo = FALSE;
1744
gimp_draw_tool_pause (GIMP_DRAW_TOOL (vector_tool));
1745
gimp_vectors_freeze (vector_tool->vectors);
1747
while ((cur_stroke = gimp_vectors_stroke_get_next (vector_tool->vectors,
1751
anchors = gimp_stroke_get_draw_anchors (cur_stroke);
1753
for (list = anchors; list; list = g_list_next (list))
1755
cur_anchor = GIMP_ANCHOR (list->data);
1757
if (cur_anchor->selected)
1761
gimp_vector_tool_undo_push (vector_tool, _("Delete Anchors"));
1765
gimp_stroke_anchor_delete (cur_stroke, cur_anchor);
1767
if (gimp_stroke_is_empty (cur_stroke))
1768
gimp_vectors_stroke_remove (vector_tool->vectors, cur_stroke);
1772
g_list_free (anchors);
1775
gimp_vectors_thaw (vector_tool->vectors);
1776
gimp_draw_tool_resume (GIMP_DRAW_TOOL (vector_tool));
1780
gimp_vector_tool_verify_state (GimpVectorTool *vector_tool)
1782
GimpStroke *cur_stroke = NULL;
1783
GimpAnchor *cur_anchor;
1786
gboolean cur_anchor_valid;
1787
gboolean cur_stroke_valid;
1789
cur_anchor_valid = FALSE;
1790
cur_stroke_valid = FALSE;
1792
vector_tool->sel_count = 0;
1793
vector_tool->sel_anchor = NULL;
1794
vector_tool->sel_stroke = NULL;
1796
if (!vector_tool->vectors)
1798
vector_tool->cur_position = -1;
1799
vector_tool->cur_anchor = NULL;
1800
vector_tool->cur_stroke = NULL;
1804
while ((cur_stroke = gimp_vectors_stroke_get_next (vector_tool->vectors,
1807
/* anchor handles */
1808
anchors = gimp_stroke_get_draw_anchors (cur_stroke);
1810
if (cur_stroke == vector_tool->cur_stroke)
1811
cur_stroke_valid = TRUE;
1813
for (list = anchors; list; list = g_list_next (list))
1815
cur_anchor = GIMP_ANCHOR (list->data);
1817
if (cur_anchor == vector_tool->cur_anchor)
1818
cur_anchor_valid = TRUE;
1820
if (cur_anchor->type == GIMP_ANCHOR_ANCHOR &&
1821
cur_anchor->selected)
1823
vector_tool->sel_count++;
1824
if (vector_tool->sel_count == 1)
1826
vector_tool->sel_anchor = cur_anchor;
1827
vector_tool->sel_stroke = cur_stroke;
1831
vector_tool->sel_anchor = NULL;
1832
vector_tool->sel_stroke = NULL;
1837
anchors = gimp_stroke_get_draw_controls (cur_stroke);
1839
for (list = anchors; list; list = g_list_next (list))
1841
cur_anchor = GIMP_ANCHOR (list->data);
1843
if (cur_anchor == vector_tool->cur_anchor)
1844
cur_anchor_valid = TRUE;
1848
if (!cur_stroke_valid)
1849
vector_tool->cur_stroke = NULL;
1851
if (!cur_anchor_valid)
1852
vector_tool->cur_anchor = NULL;
1857
gimp_vector_tool_undo_push (GimpVectorTool *vector_tool, const gchar *desc)
1859
g_return_if_fail (vector_tool->vectors != NULL);
1861
/* don't push two undos */
1862
if (vector_tool->have_undo)
1865
gimp_image_undo_push_vectors_mod (GIMP_ITEM (vector_tool->vectors)->gimage,
1866
desc, vector_tool->vectors);
1867
vector_tool->have_undo = TRUE;
1872
gimp_vector_tool_to_selection (GimpVectorTool *vector_tool)
1874
gimp_vector_tool_to_selection_extended (vector_tool, 0);
1879
gimp_vector_tool_to_selection_extended (GimpVectorTool *vector_tool,
1883
GimpChannelOps operation = GIMP_CHANNEL_OP_REPLACE;
1885
if (! vector_tool->vectors)
1888
gimage = gimp_item_get_image (GIMP_ITEM (vector_tool->vectors));
1890
if (state & GDK_SHIFT_MASK)
1892
if (state & GDK_CONTROL_MASK)
1893
operation = GIMP_CHANNEL_OP_INTERSECT;
1895
operation = GIMP_CHANNEL_OP_ADD;
1897
else if (state & GDK_CONTROL_MASK)
1899
operation = GIMP_CHANNEL_OP_SUBTRACT;
1902
gimp_channel_select_vectors (gimp_image_get_mask (gimage),
1903
_("Path to selection"),
1904
vector_tool->vectors,
1907
gimp_image_flush (gimage);
1912
gimp_vector_tool_stroke_vectors (GimpVectorTool *vector_tool,
1916
GimpDrawable *active_drawable;
1919
if (! vector_tool->vectors)
1922
gimage = gimp_item_get_image (GIMP_ITEM (vector_tool->vectors));
1924
active_drawable = gimp_image_active_drawable (gimage);
1926
if (! active_drawable)
1928
g_message (_("There is no active layer or channel to stroke to"));
1932
dialog = stroke_dialog_new (GIMP_ITEM (vector_tool->vectors),
1934
GIMP_STOCK_PATH_STROKE,
1935
GIMP_HELP_PATH_STROKE,
1937
gtk_widget_show (dialog);