[gimp] app: remove "gboolean active_layer_only" from gimp_image_crop()
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] app: remove "gboolean active_layer_only" from gimp_image_crop()
- Date: Sat, 22 Sep 2012 13:09:08 +0000 (UTC)
commit 303e554ab1ccf8b4e22e5f954b9df0ab2baa44c4
Author: Michael Natterer <mitch gimp org>
Date: Sat Sep 22 15:06:35 2012 +0200
app: remove "gboolean active_layer_only" from gimp_image_crop()
Also a very historic API, it doesn't belong there. Instead, simply
call gimp_item_resize() in GimpCropTool.
app/actions/image-commands.c | 2 +-
app/core/gimpimage-crop.c | 299 +++++++++++++++++++-----------------------
app/core/gimpimage-crop.h | 1 -
app/pdb/image-cmds.c | 2 +-
app/tools/gimpcroptool.c | 20 ++-
tools/pdbgen/pdb/image.pdb | 2 +-
6 files changed, 155 insertions(+), 171 deletions(-)
---
diff --git a/app/actions/image-commands.c b/app/actions/image-commands.c
index 83df4fc..9eedc8c 100644
--- a/app/actions/image-commands.c
+++ b/app/actions/image-commands.c
@@ -458,7 +458,7 @@ image_crop_cmd_callback (GtkAction *action,
}
gimp_image_crop (image, action_data_get_context (data),
- x1, y1, x2, y2, FALSE, TRUE);
+ x1, y1, x2, y2, TRUE);
gimp_image_flush (image);
}
diff --git a/app/core/gimpimage-crop.c b/app/core/gimpimage-crop.c
index c43ba51..de7cd6a 100644
--- a/app/core/gimpimage-crop.c
+++ b/app/core/gimpimage-crop.c
@@ -45,16 +45,14 @@ gimp_image_crop (GimpImage *image,
gint y1,
gint x2,
gint y2,
- gboolean active_layer_only,
gboolean crop_layers)
{
- gint width, height;
- gint previous_width, previous_height;
+ GList *list;
+ gint width, height;
+ gint previous_width, previous_height;
g_return_if_fail (GIMP_IS_IMAGE (image));
g_return_if_fail (GIMP_IS_CONTEXT (context));
- g_return_if_fail (active_layer_only == FALSE ||
- gimp_image_get_active_layer (image));
previous_width = gimp_image_get_width (image);
previous_height = gimp_image_get_height (image);
@@ -68,192 +66,169 @@ gimp_image_crop (GimpImage *image,
gimp_set_busy (image->gimp);
- if (active_layer_only)
- {
- GimpLayer *layer;
- gint off_x, off_y;
-
- layer = gimp_image_get_active_layer (image);
-
- gimp_item_get_offset (GIMP_ITEM (layer), &off_x, &off_y);
+ g_object_freeze_notify (G_OBJECT (image));
- off_x -= x1;
- off_y -= y1;
-
- gimp_item_resize (GIMP_ITEM (layer), context, width, height, off_x, off_y);
- }
+ if (crop_layers)
+ gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_IMAGE_CROP,
+ C_("undo-type", "Crop Image"));
else
+ gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_IMAGE_RESIZE,
+ C_("undo-type", "Resize Image"));
+
+ /* Push the image size to the stack */
+ gimp_image_undo_push_image_size (image, NULL,
+ x1, y1, width, height);
+
+ /* Set the new width and height */
+ g_object_set (image,
+ "width", width,
+ "height", height,
+ NULL);
+
+ /* Resize all channels */
+ for (list = gimp_image_get_channel_iter (image);
+ list;
+ list = g_list_next (list))
{
- GList *list;
+ GimpItem *item = list->data;
- g_object_freeze_notify (G_OBJECT (image));
+ gimp_item_resize (item, context, width, height, -x1, -y1);
+ }
- if (crop_layers)
- gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_IMAGE_CROP,
- C_("undo-type", "Crop Image"));
- else
- gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_IMAGE_RESIZE,
- C_("undo-type", "Resize Image"));
-
- /* Push the image size to the stack */
- gimp_image_undo_push_image_size (image,
- NULL,
- x1,
- y1,
- width,
- height);
-
- /* Set the new width and height */
- g_object_set (image,
- "width", width,
- "height", height,
- NULL);
-
- /* Resize all channels */
- for (list = gimp_image_get_channel_iter (image);
- list;
- list = g_list_next (list))
- {
- GimpItem *item = list->data;
+ /* Resize all vectors */
+ for (list = gimp_image_get_vectors_iter (image);
+ list;
+ list = g_list_next (list))
+ {
+ GimpItem *item = list->data;
- gimp_item_resize (item, context, width, height, -x1, -y1);
- }
+ gimp_item_resize (item, context, width, height, -x1, -y1);
+ }
- /* Resize all vectors */
- for (list = gimp_image_get_vectors_iter (image);
- list;
- list = g_list_next (list))
- {
- GimpItem *item = list->data;
+ /* Don't forget the selection mask! */
+ gimp_item_resize (GIMP_ITEM (gimp_image_get_mask (image)), context,
+ width, height, -x1, -y1);
- gimp_item_resize (item, context, width, height, -x1, -y1);
- }
+ /* crop all layers */
+ list = gimp_image_get_layer_iter (image);
- /* Don't forget the selection mask! */
- gimp_item_resize (GIMP_ITEM (gimp_image_get_mask (image)), context,
- width, height, -x1, -y1);
+ while (list)
+ {
+ GimpItem *item = list->data;
+
+ list = g_list_next (list);
- /* crop all layers */
- list = gimp_image_get_layer_iter (image);
+ gimp_item_translate (item, -x1, -y1, TRUE);
- while (list)
+ if (crop_layers)
{
- GimpItem *item = list->data;
+ gint off_x, off_y;
+ gint lx1, ly1, lx2, ly2;
+
+ gimp_item_get_offset (item, &off_x, &off_y);
- list = g_list_next (list);
+ lx1 = CLAMP (off_x, 0, gimp_image_get_width (image));
+ ly1 = CLAMP (off_y, 0, gimp_image_get_height (image));
+ lx2 = CLAMP (gimp_item_get_width (item) + off_x,
+ 0, gimp_image_get_width (image));
+ ly2 = CLAMP (gimp_item_get_height (item) + off_y,
+ 0, gimp_image_get_height (image));
- gimp_item_translate (item, -x1, -y1, TRUE);
+ width = lx2 - lx1;
+ height = ly2 - ly1;
- if (crop_layers)
+ if (width > 0 && height > 0)
{
- gint off_x, off_y;
- gint lx1, ly1, lx2, ly2;
-
- gimp_item_get_offset (item, &off_x, &off_y);
-
- lx1 = CLAMP (off_x, 0, gimp_image_get_width (image));
- ly1 = CLAMP (off_y, 0, gimp_image_get_height (image));
- lx2 = CLAMP (gimp_item_get_width (item) + off_x,
- 0, gimp_image_get_width (image));
- ly2 = CLAMP (gimp_item_get_height (item) + off_y,
- 0, gimp_image_get_height (image));
-
- width = lx2 - lx1;
- height = ly2 - ly1;
-
- if (width > 0 && height > 0)
- {
- gimp_item_resize (item, context, width, height,
- -(lx1 - off_x),
- -(ly1 - off_y));
- }
- else
- {
- gimp_image_remove_layer (image, GIMP_LAYER (item),
- TRUE, NULL);
- }
+ gimp_item_resize (item, context, width, height,
+ -(lx1 - off_x),
+ -(ly1 - off_y));
+ }
+ else
+ {
+ gimp_image_remove_layer (image, GIMP_LAYER (item),
+ TRUE, NULL);
}
}
+ }
- /* Reposition or remove all guides */
- list = gimp_image_get_guides (image);
-
- while (list)
- {
- GimpGuide *guide = list->data;
- gboolean remove_guide = FALSE;
- gint position = gimp_guide_get_position (guide);
+ /* Reposition or remove all guides */
+ list = gimp_image_get_guides (image);
- list = g_list_next (list);
+ while (list)
+ {
+ GimpGuide *guide = list->data;
+ gboolean remove_guide = FALSE;
+ gint position = gimp_guide_get_position (guide);
- switch (gimp_guide_get_orientation (guide))
- {
- case GIMP_ORIENTATION_HORIZONTAL:
- if ((position < y1) || (position > y2))
- remove_guide = TRUE;
- else
- position -= y1;
- break;
-
- case GIMP_ORIENTATION_VERTICAL:
- if ((position < x1) || (position > x2))
- remove_guide = TRUE;
- else
- position -= x1;
- break;
-
- default:
- break;
- }
+ list = g_list_next (list);
- if (remove_guide)
- gimp_image_remove_guide (image, guide, TRUE);
- else if (position != gimp_guide_get_position (guide))
- gimp_image_move_guide (image, guide, position, TRUE);
+ switch (gimp_guide_get_orientation (guide))
+ {
+ case GIMP_ORIENTATION_HORIZONTAL:
+ if ((position < y1) || (position > y2))
+ remove_guide = TRUE;
+ else
+ position -= y1;
+ break;
+
+ case GIMP_ORIENTATION_VERTICAL:
+ if ((position < x1) || (position > x2))
+ remove_guide = TRUE;
+ else
+ position -= x1;
+ break;
+
+ default:
+ break;
}
- /* Reposition or remove sample points */
- list = gimp_image_get_sample_points (image);
+ if (remove_guide)
+ gimp_image_remove_guide (image, guide, TRUE);
+ else if (position != gimp_guide_get_position (guide))
+ gimp_image_move_guide (image, guide, position, TRUE);
+ }
- while (list)
- {
- GimpSamplePoint *sample_point = list->data;
- gboolean remove_sample_point = FALSE;
- gint new_x = sample_point->x;
- gint new_y = sample_point->y;
-
- list = g_list_next (list);
-
- new_y -= y1;
- if ((sample_point->y < y1) || (sample_point->y > y2))
- remove_sample_point = TRUE;
-
- new_x -= x1;
- if ((sample_point->x < x1) || (sample_point->x > x2))
- remove_sample_point = TRUE;
-
- if (remove_sample_point)
- gimp_image_remove_sample_point (image, sample_point, TRUE);
- else if (new_x != sample_point->x || new_y != sample_point->y)
- gimp_image_move_sample_point (image, sample_point,
- new_x, new_y, TRUE);
- }
+ /* Reposition or remove sample points */
+ list = gimp_image_get_sample_points (image);
- gimp_image_undo_group_end (image);
+ while (list)
+ {
+ GimpSamplePoint *sample_point = list->data;
+ gboolean remove_sample_point = FALSE;
+ gint new_x = sample_point->x;
+ gint new_y = sample_point->y;
+
+ list = g_list_next (list);
+
+ new_y -= y1;
+ if ((sample_point->y < y1) || (sample_point->y > y2))
+ remove_sample_point = TRUE;
+
+ new_x -= x1;
+ if ((sample_point->x < x1) || (sample_point->x > x2))
+ remove_sample_point = TRUE;
+
+ if (remove_sample_point)
+ gimp_image_remove_sample_point (image, sample_point, TRUE);
+ else if (new_x != sample_point->x || new_y != sample_point->y)
+ gimp_image_move_sample_point (image, sample_point,
+ new_x, new_y, TRUE);
+ }
- gimp_image_invalidate (image,
- 0, 0,
- gimp_image_get_width (image),
- gimp_image_get_height (image));
+ gimp_image_undo_group_end (image);
- gimp_image_size_changed_detailed (image,
- -x1,
- -y1,
- previous_width,
- previous_height);
+ gimp_image_invalidate (image,
+ 0, 0,
+ gimp_image_get_width (image),
+ gimp_image_get_height (image));
- g_object_thaw_notify (G_OBJECT (image));
- }
+ gimp_image_size_changed_detailed (image,
+ -x1,
+ -y1,
+ previous_width,
+ previous_height);
+
+ g_object_thaw_notify (G_OBJECT (image));
gimp_unset_busy (image->gimp);
}
diff --git a/app/core/gimpimage-crop.h b/app/core/gimpimage-crop.h
index 90d6398..d437cf2 100644
--- a/app/core/gimpimage-crop.h
+++ b/app/core/gimpimage-crop.h
@@ -25,7 +25,6 @@ void gimp_image_crop (GimpImage *image,
gint y1,
gint x2,
gint y2,
- gboolean active_layer_only,
gboolean crop_layers);
diff --git a/app/pdb/image-cmds.c b/app/pdb/image-cmds.c
index d02f24c..f81a82c 100644
--- a/app/pdb/image-cmds.c
+++ b/app/pdb/image-cmds.c
@@ -567,7 +567,7 @@ image_crop_invoker (GimpProcedure *procedure,
else
gimp_image_crop (image, context,
offx, offy, offx + new_width, offy + new_height,
- FALSE, TRUE);
+ TRUE);
}
return gimp_procedure_get_return_values (procedure, success,
diff --git a/app/tools/gimpcroptool.c b/app/tools/gimpcroptool.c
index 218f50d..95fe73f 100644
--- a/app/tools/gimpcroptool.c
+++ b/app/tools/gimpcroptool.c
@@ -311,6 +311,7 @@ gimp_crop_tool_execute (GimpRectangleTool *rectangle,
if (options->layer_only)
{
GimpLayer *layer = gimp_image_get_active_layer (image);
+ gint off_x, off_y;
if (! layer)
{
@@ -325,12 +326,21 @@ gimp_crop_tool_execute (GimpRectangleTool *rectangle,
_("The active layer's pixels are locked."));
return FALSE;
}
- }
- gimp_image_crop (image, GIMP_CONTEXT (options),
- x, y, w + x, h + y,
- options->layer_only,
- TRUE);
+ gimp_item_get_offset (GIMP_ITEM (layer), &off_x, &off_y);
+
+ off_x -= x;
+ off_y -= y;
+
+ gimp_item_resize (GIMP_ITEM (layer), GIMP_CONTEXT (options),
+ w, h, off_x, off_y);
+ }
+ else
+ {
+ gimp_image_crop (image, GIMP_CONTEXT (options),
+ x, y, w + x, h + y,
+ TRUE);
+ }
gimp_image_flush (image);
diff --git a/tools/pdbgen/pdb/image.pdb b/tools/pdbgen/pdb/image.pdb
index b634d9c..70ca996 100644
--- a/tools/pdbgen/pdb/image.pdb
+++ b/tools/pdbgen/pdb/image.pdb
@@ -414,7 +414,7 @@ HELP
else
gimp_image_crop (image, context,
offx, offy, offx + new_width, offy + new_height,
- FALSE, TRUE);
+ TRUE);
}
CODE
);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]