added _is_empty () that checks if a stroke is empty.

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

	* app/vectors/gimpstroke.[ch]: added _is_empty () that checks
	if a stroke is empty.

	* app/vectors/gimpbezierstroke.c: Implemented _anchor_delete ()

	* app/vectors/gimpvectors.[ch]: added _stroke_remove ()

	* app/tools/gimpvectortool.[ch]: implemented the deletion of
	anchors. CTRL-Click on the anchor in Insert/Delete mode does
	the trick. Also did some renaming to the Vector tool
	(now Path tool) and set the Tooltip to something sane.

	Folks, I think the new path tool is no longer a regression
	against the 1.2 bezier select tool!
This commit is contained in:
Simon Budig 2003-08-21 17:47:12 +00:00 committed by Simon Budig
parent 818cbe8279
commit 044ea72c69
8 changed files with 143 additions and 22 deletions

View File

@ -1,3 +1,20 @@
2003-08-21 Simon Budig <simon@gimp.org>
* app/vectors/gimpstroke.[ch]: added _is_empty () that checks
if a stroke is empty.
* app/vectors/gimpbezierstroke.c: Implemented _anchor_delete ()
* app/vectors/gimpvectors.[ch]: added _stroke_remove ()
* app/tools/gimpvectortool.[ch]: implemented the deletion of
anchors. CTRL-Click on the anchor in Insert/Delete mode does
the trick. Also did some renaming to the Vector tool
(now Path tool) and set the Tooltip to something sane.
Folks, I think the new path tool is no longer a regression
against the 1.2 bezier select tool!
2003-08-21 Henrik Brix Andersen <brix@gimp.org>
* app/tools/gimpmovetool.c (gimp_move_tool_control): test

View File

@ -121,11 +121,11 @@ gimp_vector_tool_register (GimpToolRegisterCallback callback,
GIMP_TYPE_VECTOR_OPTIONS,
gimp_vector_options_gui,
0,
"gimp-vector-tool",
_("Vectors"),
_("the most promising path tool prototype... :-)"),
N_("/Tools/_Vectors"), NULL,
NULL, "tools/vector.html",
"gimp-path-tool",
_("Paths"),
_("Create and edit paths"),
N_("/Tools/_Paths"), NULL,
NULL, "tools/paths.html",
GIMP_STOCK_TOOL_PATH,
data);
}
@ -322,6 +322,23 @@ gimp_vector_tool_button_press (GimpTool *tool,
break;
case VECTORS_DELETE_ANCHOR:
if (gimp_vector_tool_on_handle (tool, coords, GIMP_ANCHOR_ANCHOR,
gdisp, &anchor, &stroke)
&& anchor->type == GIMP_ANCHOR_ANCHOR)
{
gimp_stroke_anchor_delete (stroke, anchor);
if (gimp_stroke_is_empty (stroke))
gimp_vectors_stroke_remove (vector_tool->vectors, stroke);
vector_tool->cur_stroke = NULL;
vector_tool->cur_anchor = NULL;
vector_tool->function = VECTORS_FINISHED;
}
break;
default:
break;
}
@ -748,18 +765,8 @@ gimp_vector_tool_oper_update (GimpTool *tool,
return;
}
anchor = gimp_vectors_anchor_get (vector_tool->vectors, coords, NULL);
if (anchor && gimp_draw_tool_on_handle (GIMP_DRAW_TOOL (tool), gdisp,
coords->x,
coords->y,
GIMP_HANDLE_CIRCLE,
anchor->position.x,
anchor->position.y,
TARGET,
TARGET,
GTK_ANCHOR_CENTER,
FALSE))
if (gimp_vector_tool_on_handle (tool, coords, GIMP_ANCHOR_ANCHOR,
gdisp, &anchor, NULL))
{
if (state & GDK_CONTROL_MASK)
{
@ -769,10 +776,18 @@ gimp_vector_tool_oper_update (GimpTool *tool,
}
else
{
if (!options->polygonal)
vector_tool->function = VECTORS_MOVE_HANDLE;
if (edit_mode == GIMP_VECTOR_MODE_ADJUST
&& anchor->type == GIMP_ANCHOR_ANCHOR)
{
vector_tool->function = VECTORS_DELETE_ANCHOR;
}
else
vector_tool->function = VECTORS_MOVE_ANCHOR;
{
if (!options->polygonal)
vector_tool->function = VECTORS_MOVE_HANDLE;
else
vector_tool->function = VECTORS_MOVE_ANCHOR;
}
}
}
else
@ -841,6 +856,9 @@ gimp_vector_tool_cursor_update (GimpTool *tool,
case VECTORS_INSERT_ANCHOR:
cmodifier = GIMP_CURSOR_MODIFIER_PLUS;
break;
case VECTORS_DELETE_ANCHOR:
cmodifier = GIMP_CURSOR_MODIFIER_MINUS;
break;
case VECTORS_MOVE_HANDLE:
case VECTORS_CONVERT_EDGE:
cmodifier = GIMP_CURSOR_MODIFIER_HAND;
@ -854,7 +872,6 @@ gimp_vector_tool_cursor_update (GimpTool *tool,
default:
cursor = GIMP_BAD_CURSOR;
cmodifier = GIMP_CURSOR_MODIFIER_NONE;
/* GIMP_CURSOR_MODIFIER_MINUS */
break;
}

View File

@ -36,6 +36,7 @@ typedef enum
VECTORS_MOVE_HANDLE,
VECTORS_MOVE_CURVE,
VECTORS_INSERT_ANCHOR,
VECTORS_DELETE_ANCHOR,
VECTORS_CONVERT_EDGE,
VECTORS_FINISHED
} VectorFunction;

View File

@ -60,6 +60,8 @@ static void gimp_bezier_stroke_anchor_move_absolute (GimpStroke *stroke,
static void gimp_bezier_stroke_anchor_convert (GimpStroke *stroke,
GimpAnchor *anchor,
GimpAnchorFeatureType feature);
static void gimp_bezier_stroke_anchor_delete (GimpStroke *stroke,
GimpAnchor *anchor);
static gboolean gimp_bezier_stroke_anchor_is_insertable
(GimpStroke *stroke,
GimpAnchor *predec,
@ -158,6 +160,7 @@ gimp_bezier_stroke_class_init (GimpBezierStrokeClass *klass)
stroke_class->anchor_move_relative = gimp_bezier_stroke_anchor_move_relative;
stroke_class->anchor_move_absolute = gimp_bezier_stroke_anchor_move_absolute;
stroke_class->anchor_convert = gimp_bezier_stroke_anchor_convert;
stroke_class->anchor_delete = gimp_bezier_stroke_anchor_delete;
stroke_class->anchor_is_insertable = gimp_bezier_stroke_anchor_is_insertable;
stroke_class->anchor_insert = gimp_bezier_stroke_anchor_insert;
stroke_class->is_extendable = gimp_bezier_stroke_is_extendable;
@ -230,6 +233,32 @@ gimp_bezier_stroke_new_from_coords (const GimpCoords *coords,
return stroke;
}
static void
gimp_bezier_stroke_anchor_delete (GimpStroke *stroke,
GimpAnchor *anchor)
{
GList *list, *list2;
gint i;
/* Anchors always are surrounded by two handles that have to
* be deleted too */
g_return_if_fail (GIMP_IS_BEZIER_STROKE (stroke));
g_return_if_fail (anchor && anchor->type == GIMP_ANCHOR_ANCHOR);
list2 = g_list_find (stroke->anchors, anchor);
list = g_list_previous(list2);
for (i=0; i < 3; i++)
{
g_return_if_fail (list != NULL);
list2 = g_list_next (list);
gimp_anchor_free ((GimpAnchor *) list->data);
stroke->anchors = g_list_delete_link (stroke->anchors, list);
list = list2;
}
}
static gboolean
gimp_bezier_stroke_anchor_is_insertable (GimpStroke *stroke,
GimpAnchor *predec,

View File

@ -71,12 +71,13 @@ static GimpAnchor * gimp_stroke_real_anchor_insert (GimpStroke *stroke,
static gboolean gimp_stroke_real_is_extendable (GimpStroke *stroke,
GimpAnchor *neighbor);
static GimpAnchor * gimp_stroke_real_extend (GimpStroke *stroke,
const GimpCoords *coords,
GimpAnchor *neighbor,
GimpVectorExtendMode extend_mode);
static gboolean gimp_stroke_real_is_empty (const GimpStroke *stroke);
static gdouble gimp_stroke_real_get_length (const GimpStroke *stroke);
static gdouble gimp_stroke_real_get_distance (const GimpStroke *stroke,
const GimpCoords *coord);
@ -177,6 +178,7 @@ gimp_stroke_class_init (GimpStrokeClass *klass)
klass->is_extendable = gimp_stroke_real_is_extendable;
klass->extend = gimp_stroke_real_extend;
klass->is_empty = gimp_stroke_real_is_empty;
klass->get_length = gimp_stroke_real_get_length;
klass->get_distance = gimp_stroke_real_get_distance;
klass->interpolate = gimp_stroke_real_interpolate;
@ -552,6 +554,21 @@ gimp_stroke_real_extend (GimpStroke *stroke,
return NULL;
}
gboolean
gimp_stroke_is_empty (const GimpStroke *stroke)
{
g_return_val_if_fail (GIMP_IS_STROKE (stroke), FALSE);
return GIMP_STROKE_GET_CLASS (stroke)->is_empty (stroke);
}
static gboolean
gimp_stroke_real_is_empty (const GimpStroke *stroke)
{
return stroke->anchors == NULL;
}
gdouble
gimp_stroke_get_length (const GimpStroke *stroke)
{

View File

@ -91,6 +91,8 @@ struct _GimpStrokeClass
GimpAnchor *neighbor,
GimpVectorExtendMode extend_mode);
gboolean (* is_empty) (const GimpStroke *stroke);
gdouble (* get_length) (const GimpStroke *stroke);
gdouble (* get_distance) (const GimpStroke *stroke,
@ -206,6 +208,8 @@ GimpAnchor * gimp_stroke_extend (GimpStroke *stroke,
GimpAnchor *neighbor,
GimpVectorExtendMode extend_mode);
gboolean gimp_stroke_is_empty (const GimpStroke *stroke);
/* accessing the shape of the curve */
gdouble gimp_stroke_get_length (const GimpStroke *stroke);

View File

@ -91,6 +91,8 @@ static void gimp_vectors_transform (GimpItem *item,
static void gimp_vectors_real_thaw (GimpVectors *vectors);
static void gimp_vectors_real_stroke_add (GimpVectors *vectors,
GimpStroke *stroke);
static void gimp_vectors_real_stroke_remove (GimpVectors *vectors,
GimpStroke *stroke);
static GimpStroke * gimp_vectors_real_stroke_get (const GimpVectors *vectors,
const GimpCoords *coord);
static GimpStroke *gimp_vectors_real_stroke_get_next(const GimpVectors *vectors,
@ -202,6 +204,7 @@ gimp_vectors_class_init (GimpVectorsClass *klass)
klass->thaw = gimp_vectors_real_thaw;
klass->stroke_add = gimp_vectors_real_stroke_add;
klass->stroke_remove = gimp_vectors_real_stroke_remove;
klass->stroke_get = gimp_vectors_real_stroke_get;
klass->stroke_get_next = gimp_vectors_real_stroke_get_next;
klass->stroke_get_length = gimp_vectors_real_stroke_get_length;
@ -614,6 +617,35 @@ gimp_vectors_real_stroke_add (GimpVectors *vectors,
g_object_ref (stroke);
}
void
gimp_vectors_stroke_remove (GimpVectors *vectors,
GimpStroke *stroke)
{
g_return_if_fail (GIMP_IS_VECTORS (vectors));
g_return_if_fail (GIMP_IS_STROKE (stroke));
gimp_vectors_freeze (vectors);
GIMP_VECTORS_GET_CLASS (vectors)->stroke_remove (vectors, stroke);
gimp_vectors_thaw (vectors);
}
static void
gimp_vectors_real_stroke_remove (GimpVectors *vectors,
GimpStroke *stroke)
{
GList *list;
list = g_list_find (vectors->strokes, stroke);
if (list)
{
vectors->strokes = g_list_delete_link (vectors->strokes, list);
g_object_unref (stroke);
}
}
GimpStroke *
gimp_vectors_stroke_get (const GimpVectors *vectors,

View File

@ -55,6 +55,8 @@ struct _GimpVectorsClass
/* virtual functions */
void (* stroke_add) (GimpVectors *vectors,
GimpStroke *stroke);
void (* stroke_remove) (GimpVectors *vectors,
GimpStroke *stroke);
GimpStroke * (* stroke_get) (const GimpVectors *vectors,
const GimpCoords *coord);
GimpStroke * (* stroke_get_next) (const GimpVectors *vectors,
@ -131,6 +133,8 @@ void gimp_vectors_anchor_select (GimpVectors *vectors,
void gimp_vectors_stroke_add (GimpVectors *vectors,
GimpStroke *stroke);
void gimp_vectors_stroke_remove (GimpVectors *vectors,
GimpStroke *stroke);
GimpStroke * gimp_vectors_stroke_get (const GimpVectors *vectors,
const GimpCoords *coord);