static GimpStroke * gimp_vectors_real_stroke_get_next (const GimpVectors *vectors, const GimpStroke *prev) { if (! prev) { return vectors->strokes ? vectors->strokes->data : NULL; } else { GList *stroke; stroke = g_list_find (vectors->strokes, prev); g_return_val_if_fail (stroke != NULL, NULL); return stroke->next ? GIMP_STROKE (stroke->next->data) : NULL; } }
void gimp_channel_select_vectors (GimpChannel *channel, const gchar *undo_desc, GimpVectors *vectors, GimpChannelOps op, gboolean antialias, gboolean feather, gdouble feather_radius_x, gdouble feather_radius_y, gboolean push_undo) { GimpScanConvert *scan_convert; GList *stroke; gboolean coords_added = FALSE; g_return_if_fail (GIMP_IS_CHANNEL (channel)); g_return_if_fail (gimp_item_is_attached (GIMP_ITEM (channel))); g_return_if_fail (undo_desc != NULL); g_return_if_fail (GIMP_IS_VECTORS (vectors)); scan_convert = gimp_scan_convert_new (); for (stroke = vectors->strokes; stroke; stroke = stroke->next) { GArray *coords; gboolean closed; coords = gimp_stroke_interpolate (GIMP_STROKE (stroke->data), 1.0, &closed); if (coords && coords->len) { GimpVector2 *points; gint i; points = g_new0 (GimpVector2, coords->len); for (i = 0; i < coords->len; i++) { points[i].x = g_array_index (coords, GimpCoords, i).x; points[i].y = g_array_index (coords, GimpCoords, i).y; } gimp_scan_convert_add_polyline (scan_convert, coords->len, points, TRUE); coords_added = TRUE; g_free (points); } if (coords) g_array_free (coords, TRUE); } if (coords_added) gimp_channel_select_scan_convert (channel, undo_desc, scan_convert, 0, 0, op, antialias, feather, feather_radius_x, feather_radius_y, push_undo); gimp_scan_convert_free (scan_convert); }
gboolean gimp_paint_core_stroke_vectors (GimpPaintCore *core, GimpDrawable *drawable, GimpPaintOptions *paint_options, gboolean emulate_dynamics, GimpVectors *vectors, gboolean push_undo, GError **error) { GList *stroke; gboolean initialized = FALSE; gboolean due_to_lack_of_points = FALSE; gint off_x, off_y; gint vectors_off_x, vectors_off_y; g_return_val_if_fail (GIMP_IS_PAINT_CORE (core), FALSE); g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), FALSE); g_return_val_if_fail (gimp_item_is_attached (GIMP_ITEM (drawable)), FALSE); g_return_val_if_fail (GIMP_IS_PAINT_OPTIONS (paint_options), FALSE); g_return_val_if_fail (GIMP_IS_VECTORS (vectors), FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); gimp_item_get_offset (GIMP_ITEM (vectors), &vectors_off_x, &vectors_off_y); gimp_item_get_offset (GIMP_ITEM (drawable), &off_x, &off_y); off_x -= vectors_off_x; off_y -= vectors_off_y; for (stroke = vectors->strokes; stroke; stroke = stroke->next) { GArray *coords; gboolean closed; coords = gimp_stroke_interpolate (GIMP_STROKE (stroke->data), 1.0, &closed); if (coords && coords->len) { gint i; for (i = 0; i < coords->len; i++) { g_array_index (coords, GimpCoords, i).x -= off_x; g_array_index (coords, GimpCoords, i).y -= off_y; } if (emulate_dynamics) gimp_paint_core_stroke_emulate_dynamics ((GimpCoords *) coords->data, coords->len); if (initialized || gimp_paint_core_start (core, drawable, paint_options, &g_array_index (coords, GimpCoords, 0), error)) { initialized = TRUE; core->cur_coords = g_array_index (coords, GimpCoords, 0); core->last_coords = g_array_index (coords, GimpCoords, 0); gimp_paint_core_paint (core, drawable, paint_options, GIMP_PAINT_STATE_INIT, 0); gimp_paint_core_paint (core, drawable, paint_options, GIMP_PAINT_STATE_MOTION, 0); for (i = 1; i < coords->len; i++) { gimp_paint_core_interpolate (core, drawable, paint_options, &g_array_index (coords, GimpCoords, i), 0); } gimp_paint_core_paint (core, drawable, paint_options, GIMP_PAINT_STATE_FINISH, 0); } else { if (coords) g_array_free (coords, TRUE); break; } } else { due_to_lack_of_points = TRUE; } if (coords) g_array_free (coords, TRUE); } if (initialized) { gimp_paint_core_finish (core, drawable, push_undo); gimp_paint_core_cleanup (core); } if (! initialized && due_to_lack_of_points && *error == NULL) { g_set_error_literal (error, GIMP_ERROR, GIMP_FAILED, _("Not enough points to stroke")); } return initialized; }