gboolean gimp_pdb_item_is_in_same_tree (GimpItem *item, GimpItem *item2, GimpImage *image, GError **error) { g_return_val_if_fail (GIMP_IS_ITEM (item), FALSE); g_return_val_if_fail (GIMP_IS_ITEM (item2), FALSE); g_return_val_if_fail (image == NULL || GIMP_IS_IMAGE (image), FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); if (! gimp_pdb_item_is_in_tree (item, image, FALSE, error) || ! gimp_pdb_item_is_in_tree (item2, image, FALSE, error)) return FALSE; if (gimp_item_get_tree (item) != gimp_item_get_tree (item2)) { g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_INVALID_ARGUMENT, _("Items '%s' (%d) and '%s' (%d) cannot be used " "because they are not part of the same item tree"), gimp_object_get_name (item), gimp_item_get_ID (item), gimp_object_get_name (item2), gimp_item_get_ID (item2)); return FALSE; } return TRUE; }
gint gimp_item_get_ID (GimpItem *item) { g_return_val_if_fail (GIMP_IS_ITEM (item), -1); return item->ID; }
GimpTattoo gimp_item_get_tattoo (const GimpItem *item) { g_return_val_if_fail (GIMP_IS_ITEM (item), 0); return item->tattoo; }
/** * gimp_item_is_removed: * @item: the #GimpItem to check. * * Returns: %TRUE if the 'removed' flag is set for @item, %FALSE otherwise. */ gboolean gimp_item_is_removed (const GimpItem *item) { g_return_val_if_fail (GIMP_IS_ITEM (item), FALSE); return item->removed; }
gboolean gimp_pdb_item_is_modifyable (GimpItem *item, GimpPDBItemModify modify, GError **error) { g_return_val_if_fail (GIMP_IS_ITEM (item), FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); if ((modify & GIMP_PDB_ITEM_CONTENT) && gimp_item_is_content_locked (item)) { g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_INVALID_ARGUMENT, _("Item '%s' (%d) cannot be modified because its " "contents are locked"), gimp_object_get_name (item), gimp_item_get_ID (item)); return FALSE; } if ((modify & GIMP_PDB_ITEM_POSITION) && gimp_item_is_position_locked (item)) { g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_INVALID_ARGUMENT, _("Item '%s' (%d) cannot be modified because its " "position and size are locked"), gimp_object_get_name (item), gimp_item_get_ID (item)); return FALSE; } return TRUE; }
/** * gimp_item_width: * @item: The #GimpItem to check. * * Returns: The width of the item. */ gint gimp_item_width (const GimpItem *item) { g_return_val_if_fail (GIMP_IS_ITEM (item), -1); return item->width; }
void gimp_item_linked_transform (GimpItem *item, GimpContext *context, const GimpMatrix3 *matrix, GimpTransformDirection direction, GimpInterpolationType interpolation_type, GimpTransformResize clip_result, GimpProgress *progress) { GList *list; g_return_if_fail (GIMP_IS_ITEM (item)); g_return_if_fail (GIMP_IS_CONTEXT (context)); g_return_if_fail (gimp_item_get_linked (item) == TRUE); g_return_if_fail (gimp_item_is_attached (item)); g_return_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress)); list = gimp_image_item_list_get_list (gimp_item_get_image (item), item, GIMP_ITEM_TYPE_ALL, GIMP_ITEM_SET_LINKED); list = gimp_image_item_list_filter (item, list, TRUE, FALSE); gimp_image_item_list_transform (gimp_item_get_image (item), list, context, matrix, direction, interpolation_type, clip_result, progress); g_list_free (list); }
/** * gimp_item_is_attached: * @item: The #GimpItem to check. * * Returns: %TRUE if the item is attached to an image, %FALSE otherwise. */ gboolean gimp_item_is_attached (GimpItem *item) { g_return_val_if_fail (GIMP_IS_ITEM (item), FALSE); return GIMP_ITEM_GET_CLASS (item)->is_attached (item); }
void gimp_item_transform (GimpItem *item, GimpContext *context, const GimpMatrix3 *matrix, GimpTransformDirection direction, GimpInterpolationType interpolation, gint recursion_level, GimpTransformResize clip_result, GimpProgress *progress) { GimpItemClass *item_class; GimpImage *image; g_return_if_fail (GIMP_IS_ITEM (item)); g_return_if_fail (gimp_item_is_attached (item)); g_return_if_fail (GIMP_IS_CONTEXT (context)); g_return_if_fail (matrix != NULL); g_return_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress)); item_class = GIMP_ITEM_GET_CLASS (item); image = gimp_item_get_image (item); gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_TRANSFORM, item_class->transform_desc); item_class->transform (item, context, matrix, direction, interpolation, recursion_level, clip_result, progress); gimp_image_undo_group_end (image); }
/** * gimp_item_height: * @item: The #GimpItem to check. * * Returns: The height of the item. */ gint gimp_item_height (const GimpItem *item) { g_return_val_if_fail (GIMP_IS_ITEM (item), -1); return item->height; }
void gimp_item_resize (GimpItem *item, GimpContext *context, gint new_width, gint new_height, gint offset_x, gint offset_y) { GimpItemClass *item_class; GimpImage *image; g_return_if_fail (GIMP_IS_ITEM (item)); g_return_if_fail (GIMP_IS_CONTEXT (context)); if (new_width < 1 || new_height < 1) return; item_class = GIMP_ITEM_GET_CLASS (item); image = gimp_item_get_image (item); if (gimp_item_is_attached (item)) gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_ITEM_RESIZE, item_class->resize_desc); item_class->resize (item, context, new_width, new_height, offset_x, offset_y); if (gimp_item_is_attached (item)) gimp_image_undo_group_end (image); }
void gimp_item_rotate (GimpItem *item, GimpContext *context, GimpRotationType rotate_type, gdouble center_x, gdouble center_y, gboolean clip_result) { GimpItemClass *item_class; GimpImage *image; g_return_if_fail (GIMP_IS_ITEM (item)); g_return_if_fail (gimp_item_is_attached (item)); g_return_if_fail (GIMP_IS_CONTEXT (context)); item_class = GIMP_ITEM_GET_CLASS (item); image = gimp_item_get_image (item); gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_TRANSFORM, item_class->rotate_desc); item_class->rotate (item, context, rotate_type, center_x, center_y, clip_result); gimp_image_undo_group_end (image); }
void gimp_item_scale (GimpItem *item, gint new_width, gint new_height, gint new_offset_x, gint new_offset_y, GimpInterpolationType interpolation, GimpProgress *progress) { GimpItemClass *item_class; GimpImage *image; g_return_if_fail (GIMP_IS_ITEM (item)); g_return_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress)); if (new_width < 1 || new_height < 1) return; item_class = GIMP_ITEM_GET_CLASS (item); image = gimp_item_get_image (item); if (gimp_item_is_attached (item)) gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_ITEM_SCALE, item_class->scale_desc); item_class->scale (item, new_width, new_height, new_offset_x, new_offset_y, interpolation, progress); if (gimp_item_is_attached (item)) gimp_image_undo_group_end (image); }
/** * gimp_item_scale_by_factors: * @item: Item to be transformed by explicit width and height factors. * @w_factor: scale factor to apply to width and horizontal offset * @h_factor: scale factor to apply to height and vertical offset * @interpolation: * @progress: * * Scales item dimensions and offsets by uniform width and * height factors. * * Use gimp_item_scale_by_factors() in circumstances when the same * width and height scaling factors are to be uniformly applied to a * set of items. In this context, the item's dimensions and offsets * from the sides of the containing image all change by these * predetermined factors. By fiat, the fixed point of the transform is * the upper left hand corner of the image. Returns #FALSE if a * requested scale factor is zero or if a scaling zero's out a item * dimension; returns #TRUE otherwise. * * Use gimp_item_scale() in circumstances where new item width * and height dimensions are predetermined instead. * * Side effects: Undo set created for item. Old item imagery * scaled & painted to new item tiles. * * Returns: #TRUE, if the scaled item has positive dimensions * #FALSE if the scaled item has at least one zero dimension **/ gboolean gimp_item_scale_by_factors (GimpItem *item, gdouble w_factor, gdouble h_factor, GimpInterpolationType interpolation, GimpProgress *progress) { gint new_width, new_height; gint new_offset_x, new_offset_y; g_return_val_if_fail (GIMP_IS_ITEM (item), FALSE); g_return_val_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress), FALSE); if (w_factor == 0.0 || h_factor == 0.0) { g_warning ("%s: requested width or height scale equals zero", G_STRFUNC); return FALSE; } new_offset_x = ROUND (w_factor * (gdouble) item->offset_x); new_offset_y = ROUND (h_factor * (gdouble) item->offset_y); new_width = ROUND (w_factor * (gdouble) gimp_item_width (item)); new_height = ROUND (h_factor * (gdouble) gimp_item_height (item)); if (new_width != 0 && new_height != 0) { gimp_item_scale (item, new_width, new_height, new_offset_x, new_offset_y, interpolation, progress); return TRUE; } return FALSE; }
void gimp_item_parasite_detach (GimpItem *item, const gchar *name) { const GimpParasite *parasite; g_return_if_fail (GIMP_IS_ITEM (item)); g_return_if_fail (name != NULL); parasite = gimp_parasite_list_find (item->parasites, name); if (! parasite) return; if (gimp_parasite_is_undoable (parasite)) { gimp_image_undo_push_item_parasite_remove (item->image, _("Remove Parasite from Item"), item, gimp_parasite_name (parasite)); } else if (gimp_parasite_is_persistent (parasite)) { gimp_image_undo_push_cantundo (item->image, _("Remove Parasite from Item")); } gimp_parasite_list_remove (item->parasites, name); }
/** * gimp_item_translate: * @item: The #GimpItem to move. * @offset_x: Increment to the X offset of the item. * @offset_y: Increment to the Y offset of the item. * @push_undo: If #TRUE, create an entry in the image's undo stack * for this action. * * Adds the specified increments to the X and Y offsets for the item. */ void gimp_item_translate (GimpItem *item, gint offset_x, gint offset_y, gboolean push_undo) { GimpItemClass *item_class; GimpImage *image; g_return_if_fail (GIMP_IS_ITEM (item)); item_class = GIMP_ITEM_GET_CLASS (item); image = gimp_item_get_image (item); if (! gimp_item_is_attached (item)) push_undo = FALSE; if (push_undo) gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_ITEM_DISPLACE, item_class->translate_desc); item_class->translate (item, offset_x, offset_y, push_undo); if (push_undo) gimp_image_undo_group_end (image); }
gboolean gimp_pdb_item_is_attached (GimpItem *item, GimpImage *image, GimpPDBItemModify modify, GError **error) { g_return_val_if_fail (GIMP_IS_ITEM (item), FALSE); g_return_val_if_fail (image == NULL || GIMP_IS_IMAGE (image), FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); if (! gimp_item_is_attached (item)) { g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_INVALID_ARGUMENT, _("Item '%s' (%d) cannot be used because it has not " "been added to an image"), gimp_object_get_name (item), gimp_item_get_ID (item)); return FALSE; } if (image && image != gimp_item_get_image (item)) { g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_INVALID_ARGUMENT, _("Item '%s' (%d) cannot be used because it is " "attached to another image"), gimp_object_get_name (item), gimp_item_get_ID (item)); return FALSE; } return gimp_pdb_item_is_modifyable (item, modify, error); }
GimpImage * gimp_item_get_image (const GimpItem *item) { g_return_val_if_fail (GIMP_IS_ITEM (item), NULL); return item->image; }
gboolean gimp_pdb_item_is_in_tree (GimpItem *item, GimpImage *image, GimpPDBItemModify modify, GError **error) { g_return_val_if_fail (GIMP_IS_ITEM (item), FALSE); g_return_val_if_fail (image == NULL || GIMP_IS_IMAGE (image), FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); if (! gimp_pdb_item_is_attached (item, image, modify, error)) return FALSE; if (! gimp_item_get_tree (item)) { g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_INVALID_ARGUMENT, _("Item '%s' (%d) cannot be used because it is not " "a direct child of an item tree"), gimp_object_get_name (item), gimp_item_get_ID (item)); return FALSE; } return TRUE; }
void gimp_item_linked_flip (GimpItem *item, GimpContext *context, GimpOrientationType flip_type, gdouble axis, gboolean clip_result) { GList *list; g_return_if_fail (GIMP_IS_ITEM (item)); g_return_if_fail (GIMP_IS_CONTEXT (context)); g_return_if_fail (gimp_item_get_linked (item) == TRUE); g_return_if_fail (gimp_item_is_attached (item)); list = gimp_image_item_list_get_list (gimp_item_get_image (item), item, GIMP_ITEM_TYPE_ALL, GIMP_ITEM_SET_LINKED); list = gimp_image_item_list_filter (item, list, TRUE, FALSE); gimp_image_item_list_flip (gimp_item_get_image (item), list, context, flip_type, axis, clip_result); g_list_free (list); }
gboolean gimp_pdb_item_is_floating (GimpItem *item, GimpImage *dest_image, GError **error) { g_return_val_if_fail (GIMP_IS_ITEM (item), FALSE); g_return_val_if_fail (GIMP_IS_IMAGE (dest_image), FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); if (! g_object_is_floating (item)) { g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_INVALID_ARGUMENT, _("Item '%s' (%d) has already been added to an image"), gimp_object_get_name (item), gimp_item_get_ID (item)); return FALSE; } else if (gimp_item_get_image (item) != dest_image) { g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_INVALID_ARGUMENT, _("Trying to add item '%s' (%d) to wrong image"), gimp_object_get_name (item), gimp_item_get_ID (item)); return FALSE; } return TRUE; }
gboolean gimp_item_is_in_set (GimpItem *item, GimpItemSet set) { g_return_val_if_fail (GIMP_IS_ITEM (item), FALSE); switch (set) { case GIMP_ITEM_SET_NONE: return FALSE; case GIMP_ITEM_SET_ALL: return TRUE; case GIMP_ITEM_SET_IMAGE_SIZED: return (gimp_item_width (item) == gimp_image_get_width (item->image) && gimp_item_height (item) == gimp_image_get_height (item->image)); case GIMP_ITEM_SET_VISIBLE: return gimp_item_get_visible (item); case GIMP_ITEM_SET_LINKED: return gimp_item_get_linked (item); } return FALSE; }
gboolean gimp_item_get_linked (const GimpItem *item) { g_return_val_if_fail (GIMP_IS_ITEM (item), FALSE); return item->linked; }
gboolean gimp_item_get_visible (const GimpItem *item) { g_return_val_if_fail (GIMP_IS_ITEM (item), FALSE); return item->visible; }
const GimpParasite * gimp_item_parasite_find (const GimpItem *item, const gchar *name) { g_return_val_if_fail (GIMP_IS_ITEM (item), NULL); return gimp_parasite_list_find (item->parasites, name); }
void gimp_item_set_tattoo (GimpItem *item, GimpTattoo tattoo) { g_return_if_fail (GIMP_IS_ITEM (item)); item->tattoo = tattoo; }
void gimp_item_parasite_attach (GimpItem *item, const GimpParasite *parasite) { GimpParasite copy; g_return_if_fail (GIMP_IS_ITEM (item)); g_return_if_fail (parasite != NULL); /* make a temporary copy of the GimpParasite struct because * gimp_parasite_shift_parent() changes it */ copy = *parasite; if (gimp_item_is_attached (item)) { /* only set the dirty bit manually if we can be saved and the new * parasite differs from the current one and we aren't undoable */ if (gimp_parasite_is_undoable (©)) { /* do a group in case we have attach_parent set */ gimp_image_undo_group_start (item->image, GIMP_UNDO_GROUP_PARASITE_ATTACH, _("Attach Parasite")); gimp_image_undo_push_item_parasite (item->image, NULL, item, ©); } else if (gimp_parasite_is_persistent (©) && ! gimp_parasite_compare (©, gimp_item_parasite_find (item, gimp_parasite_name (©)))) { gimp_image_undo_push_cantundo (item->image, _("Attach Parasite to Item")); } } gimp_parasite_list_add (item->parasites, ©); if (gimp_parasite_has_flag (©, GIMP_PARASITE_ATTACH_PARENT)) { gimp_parasite_shift_parent (©); gimp_image_parasite_attach (item->image, ©); } else if (gimp_parasite_has_flag (©, GIMP_PARASITE_ATTACH_GRANDPARENT)) { gimp_parasite_shift_parent (©); gimp_parasite_shift_parent (©); gimp_parasite_attach (item->image->gimp, ©); } if (gimp_item_is_attached (item) && gimp_parasite_is_undoable (©)) { gimp_image_undo_group_end (item->image); } }
static void gimp_item_undo_constructed (GObject *object) { GimpItemUndo *item_undo = GIMP_ITEM_UNDO (object); G_OBJECT_CLASS (parent_class)->constructed (object); g_assert (GIMP_IS_ITEM (item_undo->item)); }
static GimpItem * gimp_item_real_duplicate (GimpItem *item, GType new_type) { GimpItem *new_item; gchar *new_name; g_return_val_if_fail (GIMP_IS_ITEM (item), NULL); g_return_val_if_fail (GIMP_IS_IMAGE (item->image), NULL); g_return_val_if_fail (g_type_is_a (new_type, GIMP_TYPE_ITEM), NULL); /* formulate the new name */ { const gchar *name; gchar *ext; gint number; gint len; name = gimp_object_get_name (GIMP_OBJECT (item)); g_return_val_if_fail (name != NULL, NULL); ext = strrchr (name, '#'); len = strlen (_("copy")); if ((strlen (name) >= len && strcmp (&name[strlen (name) - len], _("copy")) == 0) || (ext && (number = atoi (ext + 1)) > 0 && ((int)(log10 (number) + 1)) == strlen (ext + 1))) { /* don't have redundant "copy"s */ new_name = g_strdup (name); } else { new_name = g_strdup_printf (_("%s copy"), name); } } new_item = g_object_new (new_type, NULL); gimp_item_configure (new_item, gimp_item_get_image (item), item->offset_x, item->offset_y, gimp_item_width (item), gimp_item_height (item), new_name); g_free (new_name); g_object_unref (new_item->parasites); new_item->parasites = gimp_parasite_list_copy (item->parasites); new_item->visible = gimp_item_get_visible (item); new_item->linked = gimp_item_get_linked (item); return new_item; }
/** * gimp_item_remove: * @item: the #GimpItem to remove. * * This function sets the 'removed' flag on @item to #TRUE, and emits * a 'removed' signal on the item. */ void gimp_item_removed (GimpItem *item) { g_return_if_fail (GIMP_IS_ITEM (item)); item->removed = TRUE; g_signal_emit (item, gimp_item_signals[REMOVED], 0); }