use a GQueue to store the points.

2007-05-23  Sven Neumann  <sven@gimp.org>

	* app/tools/gimpiscissorstool.[ch]: use a GQueue to store the points.

svn path=/trunk/; revision=22597
This commit is contained in:
Sven Neumann
2007-05-23 14:56:21 +00:00
committed by Sven Neumann
parent 8216ba62ed
commit ac2f30c485
3 changed files with 45 additions and 56 deletions

View File

@ -1,3 +1,7 @@
2007-05-23 Sven Neumann <sven@gimp.org>
* app/tools/gimpiscissorstool.[ch]: use a GQueue to store the points.
2007-05-23 Sven Neumann <sven@gimp.org> 2007-05-23 Sven Neumann <sven@gimp.org>
* plug-ins/help/gimphelpitem.c * plug-ins/help/gimphelpitem.c

View File

@ -175,7 +175,7 @@ static void calculate_curve (GimpTool *tool,
ICurve *curve); ICurve *curve);
static void iscissors_draw_curve (GimpDrawTool *draw_tool, static void iscissors_draw_curve (GimpDrawTool *draw_tool,
ICurve *curve); ICurve *curve);
static void iscissors_free_icurves (GSList *list); static void iscissors_free_icurves (GQueue *curves);
static gint mouse_over_vertex (GimpIscissorsTool *iscissors, static gint mouse_over_vertex (GimpIscissorsTool *iscissors,
gdouble x, gdouble x,
@ -183,7 +183,7 @@ static gint mouse_over_vertex (GimpIscissorsTool *iscissors,
static gboolean clicked_on_vertex (GimpIscissorsTool *iscissors, static gboolean clicked_on_vertex (GimpIscissorsTool *iscissors,
gdouble x, gdouble x,
gdouble y); gdouble y);
static GSList * mouse_over_curve (GimpIscissorsTool *iscissors, static GList * mouse_over_curve (GimpIscissorsTool *iscissors,
gdouble x, gdouble x,
gdouble y); gdouble y);
static gboolean clicked_on_curve (GimpIscissorsTool *iscissors, static gboolean clicked_on_curve (GimpIscissorsTool *iscissors,
@ -330,7 +330,7 @@ gimp_iscissors_tool_init (GimpIscissorsTool *iscissors)
iscissors->op = ISCISSORS_OP_NONE; iscissors->op = ISCISSORS_OP_NONE;
iscissors->dp_buf = NULL; iscissors->dp_buf = NULL;
iscissors->curves = NULL; iscissors->curves = g_queue_new ();
iscissors->draw = DRAW_NOTHING; iscissors->draw = DRAW_NOTHING;
iscissors->state = NO_ACTION; iscissors->state = NO_ACTION;
iscissors->mask = NULL; iscissors->mask = NULL;
@ -353,6 +353,8 @@ gimp_iscissors_tool_finalize (GObject *object)
gimp_iscissors_tool_reset (iscissors); gimp_iscissors_tool_reset (iscissors);
g_queue_free (iscissors->curves);
G_OBJECT_CLASS (parent_class)->finalize (object); G_OBJECT_CLASS (parent_class)->finalize (object);
} }
@ -494,23 +496,19 @@ iscissors_convert (GimpIscissorsTool *iscissors,
{ {
GimpSelectionOptions *options = GIMP_SELECTION_TOOL_GET_OPTIONS (iscissors); GimpSelectionOptions *options = GIMP_SELECTION_TOOL_GET_OPTIONS (iscissors);
GimpScanConvert *sc; GimpScanConvert *sc;
GimpVector2 *points; GList *list;
guint n_points;
GSList *list;
gint i;
gint index;
sc = gimp_scan_convert_new (); sc = gimp_scan_convert_new ();
/* go over the curves in reverse order, adding the points we have */ /* go over the curves in reverse order, adding the points we have */
list = iscissors->curves; for (list = g_queue_peek_tail_link (iscissors->curves);
index = g_slist_length (list); list;
while (index) list = g_list_previous (list))
{ {
ICurve *icurve; ICurve *icurve = list->data;
GimpVector2 *points;
index--; guint n_points;
icurve = g_slist_nth_data (list, index); gint i;
n_points = icurve->points->len; n_points = icurve->points->len;
points = g_new (GimpVector2, n_points); points = g_new (GimpVector2, n_points);
@ -583,9 +581,9 @@ gimp_iscissors_tool_button_release (GimpTool *tool,
if (!iscissors->first_point) if (!iscissors->first_point)
{ {
/* Determine if we're connecting to the first point */ /* Determine if we're connecting to the first point */
if (iscissors->curves) if (! g_queue_is_empty (iscissors->curves))
{ {
ICurve *curve = iscissors->curves->data; ICurve *curve = g_queue_peek_head (iscissors->curves);
if (gimp_draw_tool_on_handle (GIMP_DRAW_TOOL (tool), display, if (gimp_draw_tool_on_handle (GIMP_DRAW_TOOL (tool), display,
iscissors->x, iscissors->y, iscissors->x, iscissors->y,
@ -612,7 +610,9 @@ gimp_iscissors_tool_button_release (GimpTool *tool,
iscissors->ix = curve->x2 = iscissors->x; iscissors->ix = curve->x2 = iscissors->x;
iscissors->iy = curve->y2 = iscissors->y; iscissors->iy = curve->y2 = iscissors->y;
curve->points = NULL; curve->points = NULL;
iscissors->curves = g_slist_append (iscissors->curves, curve);
g_queue_push_tail (iscissors->curves, curve);
calculate_curve (tool, curve); calculate_curve (tool, curve);
} }
} }
@ -727,10 +727,6 @@ gimp_iscissors_tool_draw (GimpDrawTool *draw_tool)
{ {
GimpTool *tool = GIMP_TOOL (draw_tool); GimpTool *tool = GIMP_TOOL (draw_tool);
GimpIscissorsTool *iscissors = GIMP_ISCISSORS_TOOL (draw_tool); GimpIscissorsTool *iscissors = GIMP_ISCISSORS_TOOL (draw_tool);
GimpDisplay *display;
GSList *list;
display = tool->display;
/* Draw the crosshairs target if we're placing a seed */ /* Draw the crosshairs target if we're placing a seed */
if (iscissors->draw & DRAW_CURRENT_SEED) if (iscissors->draw & DRAW_CURRENT_SEED)
@ -791,6 +787,8 @@ gimp_iscissors_tool_draw (GimpDrawTool *draw_tool)
if ((iscissors->draw & DRAW_CURVE) && ! iscissors->first_point) if ((iscissors->draw & DRAW_CURVE) && ! iscissors->first_point)
{ {
GList *list;
/* Draw a point at the init point coordinates */ /* Draw a point at the init point coordinates */
if (! iscissors->connected) if (! iscissors->connected)
{ {
@ -805,7 +803,9 @@ gimp_iscissors_tool_draw (GimpDrawTool *draw_tool)
} }
/* Go through the list of icurves, and render each one... */ /* Go through the list of icurves, and render each one... */
for (list = iscissors->curves; list; list = g_slist_next (list)) for (list = g_queue_peek_head_link (iscissors->curves);
list;
list = g_list_next (list))
{ {
ICurve *curve = list->data; ICurve *curve = list->data;
@ -924,9 +924,7 @@ gimp_iscissors_tool_oper_update (GimpTool *tool,
} }
else if (mouse_over_curve (iscissors, coords->x, coords->y)) else if (mouse_over_curve (iscissors, coords->x, coords->y))
{ {
ICurve *curve; ICurve *curve = g_queue_peek_head (iscissors->curves);
curve = (ICurve *) iscissors->curves->data;
if (gimp_draw_tool_on_handle (GIMP_DRAW_TOOL (tool), display, if (gimp_draw_tool_on_handle (GIMP_DRAW_TOOL (tool), display,
RINT (coords->x), RINT (coords->y), RINT (coords->x), RINT (coords->y),
@ -1103,12 +1101,7 @@ static void
gimp_iscissors_tool_reset (GimpIscissorsTool *iscissors) gimp_iscissors_tool_reset (GimpIscissorsTool *iscissors)
{ {
/* Free and reset the curve list */ /* Free and reset the curve list */
if (iscissors->curves) iscissors_free_icurves (iscissors->curves);
{
iscissors_free_icurves (iscissors->curves);
g_slist_free (iscissors->curves);
iscissors->curves = NULL;
}
/* free mask */ /* free mask */
if (iscissors->mask) if (iscissors->mask)
@ -1148,17 +1141,16 @@ gimp_iscissors_tool_reset (GimpIscissorsTool *iscissors)
static void static void
iscissors_free_icurves (GSList *list) iscissors_free_icurves (GQueue *curves)
{ {
while (list) while (! g_queue_is_empty (curves))
{ {
ICurve *curve = list->data; ICurve *curve = g_queue_pop_head (curves);
if (curve->points) if (curve->points)
g_ptr_array_free (curve->points, TRUE); g_ptr_array_free (curve->points, TRUE);
g_slice_free (ICurve, curve); g_slice_free (ICurve, curve);
list = g_slist_next (list);
} }
} }
@ -1170,8 +1162,8 @@ mouse_over_vertex (GimpIscissorsTool *iscissors,
gdouble x, gdouble x,
gdouble y) gdouble y)
{ {
GSList *list; GList *list;
gint curves_found = 0; gint curves_found = 0;
/* traverse through the list, returning non-zero if the current cursor /* traverse through the list, returning non-zero if the current cursor
* position is on an existing curve vertex. Set the curve1 and curve2 * position is on an existing curve vertex. Set the curve1 and curve2
@ -1180,9 +1172,9 @@ mouse_over_vertex (GimpIscissorsTool *iscissors,
iscissors->curve1 = iscissors->curve2 = NULL; iscissors->curve1 = iscissors->curve2 = NULL;
list = iscissors->curves; for (list = g_queue_peek_head_link (iscissors->curves);
list;
while (list && curves_found < 2) list = g_list_next (list))
{ {
ICurve *curve = list->data; ICurve *curve = list->data;
@ -1214,8 +1206,6 @@ mouse_over_vertex (GimpIscissorsTool *iscissors,
if (curves_found++) if (curves_found++)
return curves_found; return curves_found;
} }
list = g_slist_next (list);
} }
return curves_found; return curves_found;
@ -1250,17 +1240,19 @@ clicked_on_vertex (GimpIscissorsTool *iscissors,
} }
static GSList * static GList *
mouse_over_curve (GimpIscissorsTool *iscissors, mouse_over_curve (GimpIscissorsTool *iscissors,
gdouble x, gdouble x,
gdouble y) gdouble y)
{ {
GSList *list; GList *list;
/* traverse through the list, returning the curve segment's list element /* traverse through the list, returning the curve segment's list element
* if the current cursor position is on a curve... * if the current cursor position is on a curve...
*/ */
for (list = iscissors->curves; list; list = g_slist_next (list)) for (list = g_queue_peek_head_link (iscissors->curves);
list;
list = g_list_next (list))
{ {
ICurve *curve = list->data; ICurve *curve = list->data;
gpointer *pt; gpointer *pt;
@ -1298,20 +1290,18 @@ clicked_on_curve (GimpIscissorsTool *iscissors,
gdouble x, gdouble x,
gdouble y) gdouble y)
{ {
GSList *list; GList *list = mouse_over_curve (iscissors, x, y);
/* traverse through the list, getting back the curve segment's list /* traverse through the list, getting back the curve segment's list
* element if the current cursor position is on a curve... * element if the current cursor position is on a curve...
* If this occurs, replace the curve with two new curves, * If this occurs, replace the curve with two new curves,
* separated by a new vertex. * separated by a new vertex.
*/ */
list = mouse_over_curve (iscissors, x, y);
if (list) if (list)
{ {
ICurve *curve = list->data; ICurve *curve = list->data;
ICurve *new_curve; ICurve *new_curve;
GSList *new_link;
/* undraw the curve */ /* undraw the curve */
iscissors->draw = DRAW_CURVE; iscissors->draw = DRAW_CURVE;
@ -1327,12 +1317,7 @@ clicked_on_curve (GimpIscissorsTool *iscissors,
new_curve->points = NULL; new_curve->points = NULL;
/* Create the new link and supply the new curve as data */ /* Create the new link and supply the new curve as data */
new_link = g_slist_alloc (); g_queue_insert_after (iscissors->curves, list, new_curve);
new_link->data = new_curve;
/* Insert the new link in the list */
new_link->next = list->next;
list->next = new_link;
iscissors->curve1 = new_curve; iscissors->curve1 = new_curve;
iscissors->curve2 = curve; iscissors->curve2 = curve;

View File

@ -84,7 +84,7 @@ struct _GimpIscissorsTool
ICurve *curve1; /* 1st curve connected to current point */ ICurve *curve1; /* 1st curve connected to current point */
ICurve *curve2; /* 2nd curve connected to current point */ ICurve *curve2; /* 2nd curve connected to current point */
GSList *curves; /* the list of curves */ GQueue *curves; /* the list of curves */
gboolean first_point; /* is this the first point? */ gboolean first_point; /* is this the first point? */
gboolean connected; /* is the region closed? */ gboolean connected; /* is the region closed? */