Added enum for vector tool operation mode

2003-08-21  Simon Budig  <simon@gimp.org>

        * app/tools/tools-enums.h: Added enum for vector tool operation
        mode

        * app/tools/tools-enums.c: regenerated

        * app/tools/gimpvectoroptions.[ch]: Use new enum.
        Add "Polygonal" Option

        * app/tools/gimpvectortool.c: New Option "Polygonal" that
        places all newly generated handles at the position of their
        anchor, effectively ensuring that only polygons can be created.

        Cleaned up the editing states. It is now possible to move anchors
        in the Insert/Delete mode. Cleaned up the associated cursors.

        Fixed warning when Shift+Ctrl-Clicking on an inactive Anchor.
This commit is contained in:
Simon Budig 2003-08-20 22:19:37 +00:00 committed by Simon Budig
parent 52a16ff5a4
commit 2a47fda7f0
6 changed files with 141 additions and 38 deletions

View File

@ -1,3 +1,22 @@
2003-08-21 Simon Budig <simon@gimp.org>
* app/tools/tools-enums.h: Added enum for vector tool operation
mode
* app/tools/tools-enums.c: regenerated
* app/tools/gimpvectoroptions.[ch]: Use new enum.
Add "Polygonal" Option
* app/tools/gimpvectortool.c: New Option "Polygonal" that
places all newly generated handles at the position of their
anchor, effectively ensuring that only polygons can be created.
Cleaned up the editing states. It is now possible to move anchors
in the Insert/Delete mode. Cleaned up the associated cursors.
Fixed warning when Shift+Ctrl-Clicking on an inactive Anchor.
2003-08-20 Simon Budig <simon@gimp.org> 2003-08-20 Simon Budig <simon@gimp.org>
* app/vectors/gimpstroke.[ch]: Add hooks for insertion of points * app/vectors/gimpstroke.[ch]: Add hooks for insertion of points

View File

@ -42,7 +42,8 @@
enum enum
{ {
PROP_0, PROP_0,
PROP_VECTORS_EDIT_MODE PROP_VECTORS_EDIT_MODE,
PROP_VECTORS_POLYGONAL
}; };
static void gimp_vector_options_init (GimpVectorOptions *options); static void gimp_vector_options_init (GimpVectorOptions *options);
@ -100,8 +101,15 @@ gimp_vector_options_class_init (GimpVectorOptionsClass *klass)
object_class->set_property = gimp_vector_options_set_property; object_class->set_property = gimp_vector_options_set_property;
object_class->get_property = gimp_vector_options_get_property; object_class->get_property = gimp_vector_options_get_property;
GIMP_CONFIG_INSTALL_PROP_BOOLEAN (object_class, PROP_VECTORS_EDIT_MODE, GIMP_CONFIG_INSTALL_PROP_ENUM (object_class, PROP_VECTORS_EDIT_MODE,
"vectors-edit-mode", NULL, "vectors-edit-mode", NULL,
GIMP_TYPE_VECTOR_MODE,
GIMP_VECTOR_MODE_CREATE,
0);
GIMP_CONFIG_INSTALL_PROP_BOOLEAN (object_class, PROP_VECTORS_POLYGONAL,
"vectors-polygonal",
N_("restrict editing to polygonals"),
FALSE, FALSE,
0); 0);
} }
@ -124,7 +132,10 @@ gimp_vector_options_set_property (GObject *object,
switch (property_id) switch (property_id)
{ {
case PROP_VECTORS_EDIT_MODE: case PROP_VECTORS_EDIT_MODE:
options->edit_mode = g_value_get_boolean (value); options->edit_mode = g_value_get_enum (value);
break;
case PROP_VECTORS_POLYGONAL:
options->polygonal = g_value_get_boolean (value);
break; break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@ -146,7 +157,10 @@ gimp_vector_options_get_property (GObject *object,
switch (property_id) switch (property_id)
{ {
case PROP_VECTORS_EDIT_MODE: case PROP_VECTORS_EDIT_MODE:
g_value_set_boolean (value, options->edit_mode); g_value_set_enum (value, options->edit_mode);
break;
case PROP_VECTORS_POLYGONAL:
g_value_set_boolean (value, options->polygonal);
break; break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@ -161,18 +175,22 @@ gimp_vector_options_gui (GimpToolOptions *tool_options)
GObject *config; GObject *config;
GtkWidget *vbox; GtkWidget *vbox;
GtkWidget *frame; GtkWidget *frame;
GtkWidget *button;
config = G_OBJECT (tool_options); config = G_OBJECT (tool_options);
vbox = gimp_tool_options_gui (tool_options); vbox = gimp_tool_options_gui (tool_options);
/* tool toggle */ /* tool toggle */
frame = gimp_prop_boolean_radio_frame_new (config, "vectors-edit-mode", frame = gimp_prop_enum_radio_frame_new (config, "vectors-edit-mode",
_("Edit Mode"), _("Edit Mode"), 0, 0);
_("Insert/Delete Nodes"),
_("Extend Stroke/Move Nodes"));
gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
gtk_widget_show (frame); gtk_widget_show (frame);
button = gimp_prop_check_button_new (config, "vectors-polygonal",
_("Polygonal"));
gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
gtk_widget_show (button);
return vbox; return vbox;
} }

View File

@ -38,7 +38,8 @@ struct _GimpVectorOptions
{ {
GimpSelectionOptions parent_instance; GimpSelectionOptions parent_instance;
gboolean edit_mode; GimpVectorMode edit_mode;
gboolean polygonal;
}; };

View File

@ -291,7 +291,7 @@ gimp_vector_tool_button_press (GimpTool *tool,
gimp_tool_control_activate (tool->control); gimp_tool_control_activate (tool->control);
tool->gdisp = gdisp; tool->gdisp = gdisp;
if (options->edit_mode) if (options->edit_mode == GIMP_VECTOR_MODE_ADJUST)
{ {
switch (vector_tool->function) switch (vector_tool->function)
{ {
@ -303,6 +303,11 @@ gimp_vector_tool_button_press (GimpTool *tool,
anchor = gimp_stroke_anchor_insert (stroke, segment_start, pos); anchor = gimp_stroke_anchor_insert (stroke, segment_start, pos);
if (anchor) if (anchor)
{ {
if (options->polygonal)
{
gimp_stroke_anchor_convert (stroke, anchor,
GIMP_ANCHOR_FEATURE_EDGE);
}
vector_tool->function = VECTORS_MOVE_ANCHOR; vector_tool->function = VECTORS_MOVE_ANCHOR;
} }
else else
@ -318,7 +323,6 @@ gimp_vector_tool_button_press (GimpTool *tool,
break; break;
default: default:
vector_tool->function = VECTORS_FINISHED;
break; break;
} }
} }
@ -363,13 +367,17 @@ gimp_vector_tool_button_press (GimpTool *tool,
state |= GDK_CONTROL_MASK; state |= GDK_CONTROL_MASK;
vector_tool->restriction = GIMP_ANCHOR_FEATURE_SYMMETRIC; vector_tool->restriction = GIMP_ANCHOR_FEATURE_SYMMETRIC;
vector_tool->function = VECTORS_MOVE_HANDLE; if (!options->polygonal)
vector_tool->function = VECTORS_MOVE_HANDLE;
else
vector_tool->function = VECTORS_MOVE_ANCHOR;
vector_tool->cur_anchor = anchor; vector_tool->cur_anchor = anchor;
/* no break! */ /* no break! */
case VECTORS_MOVE_HANDLE: case VECTORS_MOVE_HANDLE:
preferred = GIMP_ANCHOR_CONTROL; if (!options->polygonal)
preferred = GIMP_ANCHOR_CONTROL;
/* no break! */ /* no break! */
@ -377,16 +385,13 @@ gimp_vector_tool_button_press (GimpTool *tool,
gimp_vector_tool_on_handle (tool, coords, gimp_vector_tool_on_handle (tool, coords,
preferred, gdisp, &anchor, &stroke); preferred, gdisp, &anchor, &stroke);
/* g_return_if_fail (anchor != NULL && stroke != NULL); */
if (anchor && stroke && anchor->type == GIMP_ANCHOR_ANCHOR) if (anchor && stroke && anchor->type == GIMP_ANCHOR_ANCHOR)
{ {
gimp_vectors_anchor_select (vector_tool->vectors, stroke, gimp_vectors_anchor_select (vector_tool->vectors, stroke,
anchor, TRUE); anchor, TRUE);
/* if the selected anchor changed, the visible control /* if the selected anchor changed, the visible control
* points might have changed too * points might have changed too */
*/
if (vector_tool->function == VECTORS_MOVE_HANDLE) if (vector_tool->function == VECTORS_MOVE_HANDLE)
gimp_vector_tool_on_handle (tool, coords, GIMP_ANCHOR_CONTROL, gimp_vector_tool_on_handle (tool, coords, GIMP_ANCHOR_CONTROL,
gdisp, &anchor, &stroke); gdisp, &anchor, &stroke);
@ -401,14 +406,32 @@ gimp_vector_tool_button_press (GimpTool *tool,
break; /* here it is... :-) */ break; /* here it is... :-) */
case VECTORS_CONVERT_EDGE: case VECTORS_CONVERT_EDGE:
gimp_stroke_anchor_convert (vector_tool->cur_stroke, if (gimp_vector_tool_on_handle (tool, coords,
vector_tool->cur_anchor, GIMP_ANCHOR_ANCHOR, gdisp,
GIMP_ANCHOR_FEATURE_EDGE); &anchor, &stroke))
vector_tool->cur_stroke = NULL; {
vector_tool->cur_anchor = NULL; gimp_vectors_anchor_select (vector_tool->vectors, stroke,
anchor, TRUE);
gimp_stroke_anchor_convert (stroke, anchor,
GIMP_ANCHOR_FEATURE_EDGE);
/* avoid doing anything stupid */ if (anchor->type == GIMP_ANCHOR_ANCHOR)
vector_tool->function = VECTORS_FINISHED; {
vector_tool->cur_stroke = stroke;
vector_tool->cur_anchor = anchor;
/* avoid doing anything stupid */
vector_tool->function = VECTORS_MOVE_ANCHOR;
}
else
{
vector_tool->cur_stroke = NULL;
vector_tool->cur_anchor = NULL;
/* avoid doing anything stupid */
vector_tool->function = VECTORS_FINISHED;
}
}
break; break;
@ -706,10 +729,13 @@ gimp_vector_tool_oper_update (GimpTool *tool,
GimpVectorTool *vector_tool; GimpVectorTool *vector_tool;
GimpVectorOptions *options; GimpVectorOptions *options;
GimpAnchor *anchor; GimpAnchor *anchor;
GimpVectorMode edit_mode;
vector_tool = GIMP_VECTOR_TOOL (tool); vector_tool = GIMP_VECTOR_TOOL (tool);
options = GIMP_VECTOR_OPTIONS (tool->tool_info->tool_options); options = GIMP_VECTOR_OPTIONS (tool->tool_info->tool_options);
edit_mode = options->edit_mode;
if (! vector_tool->vectors || GIMP_DRAW_TOOL (tool)->gdisp != gdisp) if (! vector_tool->vectors || GIMP_DRAW_TOOL (tool)->gdisp != gdisp)
{ {
vector_tool->function = VECTORS_CREATE_VECTOR; vector_tool->function = VECTORS_CREATE_VECTOR;
@ -737,7 +763,10 @@ gimp_vector_tool_oper_update (GimpTool *tool,
} }
else else
{ {
vector_tool->function = VECTORS_MOVE_HANDLE; if (!options->polygonal)
vector_tool->function = VECTORS_MOVE_HANDLE;
else
vector_tool->function = VECTORS_MOVE_ANCHOR;
} }
} }
else else
@ -751,14 +780,10 @@ gimp_vector_tool_oper_update (GimpTool *tool,
coords, gdisp, coords, gdisp,
NULL, NULL, NULL, NULL)) NULL, NULL, NULL, NULL))
{ {
if (options->edit_mode) vector_tool->function =
{ edit_mode == GIMP_VECTOR_MODE_ADJUST ?
vector_tool->function = VECTORS_INSERT_ANCHOR; VECTORS_INSERT_ANCHOR :
} VECTORS_MOVE_CURVE;
else
{
vector_tool->function = VECTORS_MOVE_CURVE;
}
} }
else else
{ {
@ -766,11 +791,17 @@ gimp_vector_tool_oper_update (GimpTool *tool,
gimp_stroke_is_extendable (vector_tool->cur_stroke, gimp_stroke_is_extendable (vector_tool->cur_stroke,
vector_tool->cur_anchor)) vector_tool->cur_anchor))
{ {
vector_tool->function = VECTORS_ADD_ANCHOR; vector_tool->function =
edit_mode == GIMP_VECTOR_MODE_ADJUST ?
VECTORS_FINISHED :
VECTORS_ADD_ANCHOR;
} }
else else
{ {
vector_tool->function = VECTORS_CREATE_STROKE; vector_tool->function =
edit_mode == GIMP_VECTOR_MODE_ADJUST ?
VECTORS_FINISHED :
VECTORS_CREATE_STROKE;
} }
} }
} }
@ -785,11 +816,13 @@ gimp_vector_tool_cursor_update (GimpTool *tool,
{ {
GimpVectorTool *vector_tool; GimpVectorTool *vector_tool;
GimpToolCursorType tool_cursor; GimpToolCursorType tool_cursor;
GimpCursorType cursor;
GimpCursorModifier cmodifier; GimpCursorModifier cmodifier;
vector_tool = GIMP_VECTOR_TOOL (tool); vector_tool = GIMP_VECTOR_TOOL (tool);
tool_cursor = gimp_tool_control_get_tool_cursor (tool->control); tool_cursor = gimp_tool_control_get_tool_cursor (tool->control);
cursor = GIMP_MOUSE_CURSOR;
cmodifier = GIMP_CURSOR_MODIFIER_NONE; cmodifier = GIMP_CURSOR_MODIFIER_NONE;
switch (vector_tool->function) switch (vector_tool->function)
@ -810,9 +843,11 @@ gimp_vector_tool_cursor_update (GimpTool *tool,
cmodifier = GIMP_CURSOR_MODIFIER_MOVE; cmodifier = GIMP_CURSOR_MODIFIER_MOVE;
break; break;
case VECTORS_MOVE_CURVE: case VECTORS_MOVE_CURVE:
cmodifier = GIMP_CURSOR_MODIFIER_MINUS; cmodifier = GIMP_CURSOR_MODIFIER_NONE;
break; break;
default: default:
cursor = GIMP_BAD_CURSOR;
cmodifier = GIMP_CURSOR_MODIFIER_NONE;
/* GIMP_CURSOR_MODIFIER_MINUS */ /* GIMP_CURSOR_MODIFIER_MINUS */
break; break;
} }
@ -824,7 +859,7 @@ gimp_vector_tool_cursor_update (GimpTool *tool,
* gimp_tool_control_set_cursor_modifier (tool->control, cmodifier); * gimp_tool_control_set_cursor_modifier (tool->control, cmodifier);
*/ */
gimp_tool_set_cursor (tool, gdisp, GIMP_MOUSE_CURSOR, tool_cursor, cmodifier); gimp_tool_set_cursor (tool, gdisp, cursor, tool_cursor, cmodifier);
} }
static void static void

View File

@ -68,6 +68,25 @@ gimp_transform_type_get_type (void)
} }
static const GEnumValue gimp_vector_mode_enum_values[] =
{
{ GIMP_VECTOR_MODE_CREATE, N_("Extend Stroke/Move Nodes"), "create" },
{ GIMP_VECTOR_MODE_ADJUST, N_("Insert/Delete Nodes"), "adjust" },
{ 0, NULL, NULL }
};
GType
gimp_vector_mode_get_type (void)
{
static GType enum_type = 0;
if (!enum_type)
enum_type = g_enum_register_static ("GimpVectorMode", gimp_vector_mode_enum_values);
return enum_type;
}
static const GEnumValue gimp_transform_grid_type_enum_values[] = static const GEnumValue gimp_transform_grid_type_enum_values[] =
{ {
{ GIMP_TRANSFORM_GRID_TYPE_NONE, N_("Don't Show Grid"), "none" }, { GIMP_TRANSFORM_GRID_TYPE_NONE, N_("Don't Show Grid"), "none" },

View File

@ -104,6 +104,17 @@ typedef enum /*< pdb-skip >*/
} GimpTransformType; } GimpTransformType;
#define GIMP_TYPE_VECTOR_MODE (gimp_vector_mode_get_type ())
GType gimp_vector_mode_get_type (void) G_GNUC_CONST;
typedef enum /*< pdb-skip >*/
{
GIMP_VECTOR_MODE_CREATE, /*< desc="Extend Stroke/Move Nodes" >*/
GIMP_VECTOR_MODE_ADJUST, /*< desc="Insert/Delete Nodes" >*/
} GimpVectorMode;
#define GIMP_TYPE_TRANSFORM_GRID_TYPE (gimp_transform_grid_type_get_type ()) #define GIMP_TYPE_TRANSFORM_GRID_TYPE (gimp_transform_grid_type_get_type ())
GType gimp_transform_grid_type_get_type (void) G_GNUC_CONST; GType gimp_transform_grid_type_get_type (void) G_GNUC_CONST;