Commit 19a168cb authored by Michael Natterer's avatar Michael Natterer 😴

Mostly revert to the state before group layers

Now that group layers properly implement GimpItem::resize(), ::flip(),
::rotate() and ::scale(), we can go back to just transforming the
toplevel container of layers in the image. Left in and/or added some
special cases anyway, like when resizing sets of layers along with the
image is requested.
parent cfaf6501
......@@ -120,15 +120,7 @@ gimp_image_crop (GimpImage *image,
}
else
{
GList *all_layers;
GList *all_channels;
GList *all_vectors;
GimpItem *item;
GList *list;
all_layers = gimp_image_get_layer_list (image);
all_channels = gimp_image_get_channel_list (image);
all_vectors = gimp_image_get_vectors_list (image);
GList *list;
g_object_freeze_notify (G_OBJECT (image));
......@@ -154,17 +146,21 @@ gimp_image_crop (GimpImage *image,
NULL);
/* Resize all channels */
for (list = all_channels; list; list = g_list_next (list))
for (list = gimp_image_get_channel_iter (image);
list;
list = g_list_next (list))
{
item = (GimpItem *) list->data;
GimpItem *item = list->data;
gimp_item_resize (item, context, width, height, -x1, -y1);
}
/* Resize all vectors */
for (list = all_vectors; list; list = g_list_next (list))
for (list = gimp_image_get_vectors_iter (image);
list;
list = g_list_next (list))
{
item = (GimpItem *) list->data;
GimpItem *item = list->data;
gimp_item_resize (item, context, width, height, -x1, -y1);
}
......@@ -174,13 +170,13 @@ gimp_image_crop (GimpImage *image,
width, height, -x1, -y1);
/* crop all layers */
for (list = all_layers; list; list = g_list_next (list))
list = gimp_image_get_layer_iter (image);
while (list)
{
item = (GimpItem *) list->data;
GimpItem *item = list->data;
/* group layers are updated automatically */
if (gimp_viewable_get_children (GIMP_VIEWABLE (item)))
continue;
list = g_list_next (list);
gimp_item_translate (item, -x1, -y1, TRUE);
......@@ -202,16 +198,22 @@ gimp_image_crop (GimpImage *image,
height = ly2 - ly1;
if (width > 0 && height > 0)
gimp_item_resize (item, context, width, height,
-(lx1 - off_x),
-(ly1 - off_y));
{
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_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;
......@@ -248,6 +250,7 @@ gimp_image_crop (GimpImage *image,
/* Reposition or remove sample points */
list = gimp_image_get_sample_points (image);
while (list)
{
GimpSamplePoint *sample_point = list->data;
......@@ -286,10 +289,6 @@ gimp_image_crop (GimpImage *image,
previous_height);
g_object_thaw_notify (G_OBJECT (image));
g_list_free (all_layers);
g_list_free (all_channels);
g_list_free (all_vectors);
}
gimp_unset_busy (image->gimp);
......
......@@ -42,9 +42,6 @@ gimp_image_flip (GimpImage *image,
GimpOrientationType flip_type,
GimpProgress *progress)
{
GList *all_layers;
GList *all_channels;
GList *all_vectors;
GList *list;
gdouble axis;
gdouble progress_max;
......@@ -71,19 +68,17 @@ gimp_image_flip (GimpImage *image,
return;
}
all_layers = gimp_image_get_layer_list (image);
all_channels = gimp_image_get_channel_list (image);
all_vectors = gimp_image_get_vectors_list (image);
progress_max = (g_list_length (all_layers) +
g_list_length (all_channels) +
g_list_length (all_vectors) +
progress_max = (gimp_container_get_n_children (image->channels) +
gimp_container_get_n_children (image->layers) +
gimp_container_get_n_children (image->vectors) +
1 /* selection */);
gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_IMAGE_FLIP, NULL);
/* Flip all channels */
for (list = all_channels; list; list = g_list_next (list))
for (list = gimp_image_get_channel_iter (image);
list;
list = g_list_next (list))
{
GimpItem *item = list->data;
......@@ -94,7 +89,9 @@ gimp_image_flip (GimpImage *image,
}
/* Flip all vectors */
for (list = all_vectors; list; list = g_list_next (list))
for (list = gimp_image_get_vectors_iter (image);
list;
list = g_list_next (list))
{
GimpItem *item = list->data;
......@@ -112,14 +109,12 @@ gimp_image_flip (GimpImage *image,
gimp_progress_set_value (progress, progress_current++ / progress_max);
/* Flip all layers */
for (list = all_layers; list; list = g_list_next (list))
for (list = gimp_image_get_layer_iter (image);
list;
list = g_list_next (list))
{
GimpItem *item = list->data;
/* group layers are updated automatically */
if (gimp_viewable_get_children (GIMP_VIEWABLE (item)))
continue;
gimp_item_flip (item, context, flip_type, axis, FALSE);
if (progress)
......@@ -179,9 +174,5 @@ gimp_image_flip (GimpImage *image,
gimp_image_undo_group_end (image);
g_list_free (all_layers);
g_list_free (all_channels);
g_list_free (all_vectors);
gimp_unset_busy (image->gimp);
}
......@@ -19,6 +19,8 @@
#include <gegl.h>
#include "libgimpbase/gimpbase.h"
#include "core-types.h"
#include "gimp.h"
......@@ -65,9 +67,6 @@ gimp_image_resize_with_layers (GimpImage *image,
GimpItemSet layer_set,
GimpProgress *progress)
{
GList *all_layers;
GList *all_channels;
GList *all_vectors;
GList *list;
GList *resize_layers;
gdouble progress_max;
......@@ -81,15 +80,6 @@ gimp_image_resize_with_layers (GimpImage *image,
gimp_set_busy (image->gimp);
all_layers = gimp_image_get_layer_list (image);
all_channels = gimp_image_get_channel_list (image);
all_vectors = gimp_image_get_vectors_list (image);
progress_max = (g_list_length (all_layers) +
g_list_length (all_channels) +
g_list_length (all_vectors) +
1 /* selection */);
g_object_freeze_notify (G_OBJECT (image));
gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_IMAGE_RESIZE,
......@@ -99,6 +89,12 @@ gimp_image_resize_with_layers (GimpImage *image,
GIMP_ITEM_TYPE_LAYERS,
layer_set);
progress_max = (gimp_container_get_n_children (image->layers) +
gimp_container_get_n_children (image->channels) +
gimp_container_get_n_children (image->vectors) +
g_list_length (resize_layers) +
1 /* selection */);
old_width = gimp_image_get_width (image);
old_height = gimp_image_get_height (image);
......@@ -117,7 +113,9 @@ gimp_image_resize_with_layers (GimpImage *image,
NULL);
/* Resize all channels */
for (list = all_channels; list; list = g_list_next (list))
for (list = gimp_image_get_channel_iter (image);
list;
list = g_list_next (list))
{
GimpItem *item = list->data;
......@@ -129,7 +127,9 @@ gimp_image_resize_with_layers (GimpImage *image,
}
/* Resize all vectors */
for (list = all_vectors; list; list = g_list_next (list))
for (list = gimp_image_get_vectors_iter (image);
list;
list = g_list_next (list))
{
GimpItem *item = list->data;
......@@ -148,24 +148,34 @@ gimp_image_resize_with_layers (GimpImage *image,
gimp_progress_set_value (progress, progress_current++ / progress_max);
/* Reposition all layers */
for (list = all_layers; list; list = g_list_next (list))
for (list = gimp_image_get_layer_iter (image);
list;
list = g_list_next (list))
{
GimpItem *item = list->data;
gimp_item_translate (item, offset_x, offset_y, TRUE);
if (progress)
gimp_progress_set_value (progress, progress_current++ / progress_max);
}
/* Resize all resize_layers to image size */
for (list = resize_layers; list; list = g_list_next (list))
{
GimpItem *item = list->data;
gint old_offset_x;
gint old_offset_y;
/* group layers are updated automatically */
/* group layers can't be resized here */
if (gimp_viewable_get_children (GIMP_VIEWABLE (item)))
continue;
gimp_item_get_offset (item, &old_offset_x, &old_offset_y);
gimp_item_translate (item, offset_x, offset_y, TRUE);
if (g_list_find (resize_layers, item))
gimp_item_resize (item, context,
new_width, new_height,
offset_x + old_offset_x, offset_y + old_offset_y);
gimp_item_resize (item, context,
new_width, new_height,
old_offset_x, old_offset_y);
if (progress)
gimp_progress_set_value (progress, progress_current++ / progress_max);
......@@ -241,10 +251,6 @@ gimp_image_resize_with_layers (GimpImage *image,
g_object_thaw_notify (G_OBJECT (image));
g_list_free (all_layers);
g_list_free (all_channels);
g_list_free (all_vectors);
gimp_unset_busy (image->gimp);
}
......@@ -253,45 +259,45 @@ gimp_image_resize_to_layers (GimpImage *image,
GimpContext *context,
GimpProgress *progress)
{
GList *all_layers;
GList *list;
GimpItem *item;
gint min_x, max_x;
gint min_y, max_y;
gint x, y;
gint width, height;
g_return_if_fail (GIMP_IS_IMAGE (image));
g_return_if_fail (GIMP_IS_CONTEXT (context));
g_return_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress));
all_layers = gimp_image_get_layer_list (image);
list = gimp_image_get_layer_iter (image);
if (! all_layers)
if (! list)
return;
list = all_layers;
/* figure out starting values */
item = list->data;
min_x = gimp_item_get_offset_x (item);
min_y = gimp_item_get_offset_y (item);
max_x = gimp_item_get_offset_x (item) + gimp_item_get_width (item);
max_y = gimp_item_get_offset_y (item) + gimp_item_get_height (item);
x = gimp_item_get_offset_x (item);
y = gimp_item_get_offset_y (item);
width = gimp_item_get_width (item);
height = gimp_item_get_height (item);
/* Respect all layers */
for (list = g_list_next (list); list; list = g_list_next (list))
{
item = list->data;
min_x = MIN (min_x, gimp_item_get_offset_x (item));
min_y = MIN (min_y, gimp_item_get_offset_y (item));
max_x = MAX (max_x, gimp_item_get_offset_x (item) + gimp_item_get_width (item));
max_y = MAX (max_y, gimp_item_get_offset_y (item) + gimp_item_get_height (item));
gimp_rectangle_union (x, y,
width, height,
gimp_item_get_offset_x (item),
gimp_item_get_offset_y (item),
gimp_item_get_width (item),
gimp_item_get_height (item),
&x, &y,
&width, &height);
}
gimp_image_resize (image, context,
max_x - min_x, max_y - min_y,
- min_x, - min_y,
width, height, -x, -y,
progress);
}
......
......@@ -53,9 +53,6 @@ gimp_image_rotate (GimpImage *image,
GimpRotationType rotate_type,
GimpProgress *progress)
{
GList *all_layers;
GList *all_channels;
GList *all_vectors;
GList *list;
gdouble center_x;
gdouble center_y;
......@@ -81,13 +78,9 @@ gimp_image_rotate (GimpImage *image,
center_x = previous_image_width / 2.0;
center_y = previous_image_height / 2.0;
all_layers = gimp_image_get_layer_list (image);
all_channels = gimp_image_get_channel_list (image);
all_vectors = gimp_image_get_vectors_list (image);
progress_max = (g_list_length (all_layers) +
g_list_length (all_channels) +
g_list_length (all_vectors) +
progress_max = (gimp_container_get_n_children (image->channels) +
gimp_container_get_n_children (image->layers) +
gimp_container_get_n_children (image->vectors) +
1 /* selection */);
g_object_freeze_notify (G_OBJECT (image));
......@@ -120,7 +113,9 @@ gimp_image_rotate (GimpImage *image,
}
/* Rotate all channels */
for (list = all_channels; list; list = g_list_next (list))
for (list = gimp_image_get_channel_iter (image);
list;
list = g_list_next (list))
{
GimpItem *item = list->data;
......@@ -133,7 +128,9 @@ gimp_image_rotate (GimpImage *image,
}
/* Rotate all vectors */
for (list = all_vectors; list; list = g_list_next (list))
for (list = gimp_image_get_vectors_iter (image);
list;
list = g_list_next (list))
{
GimpItem *item = list->data;
......@@ -165,16 +162,14 @@ gimp_image_rotate (GimpImage *image,
}
/* Rotate all layers */
for (list = all_layers; list; list = g_list_next (list))
for (list = gimp_image_get_layer_iter (image);
list;
list = g_list_next (list))
{
GimpItem *item = list->data;
gint off_x;
gint off_y;
/* group layers are updated automatically */
if (gimp_viewable_get_children (GIMP_VIEWABLE (item)))
continue;
gimp_item_get_offset (item, &off_x, &off_y);
gimp_item_rotate (item, context, rotate_type, center_x, center_y, FALSE);
......@@ -226,10 +221,6 @@ gimp_image_rotate (GimpImage *image,
g_object_thaw_notify (G_OBJECT (image));
g_list_free (all_layers);
g_list_free (all_channels);
g_list_free (all_vectors);
gimp_unset_busy (image->gimp);
}
......@@ -276,7 +267,9 @@ gimp_image_rotate_guides (GimpImage *image,
GList *list;
/* Rotate all Guides */
for (list = gimp_image_get_guides (image); list; list = g_list_next (list))
for (list = gimp_image_get_guides (image);
list;
list = g_list_next (list))
{
GimpGuide *guide = list->data;
GimpOrientationType orientation = gimp_guide_get_orientation (guide);
......@@ -355,7 +348,9 @@ gimp_image_rotate_sample_points (GimpImage *image,
GList *list;
/* Rotate all sample points */
for (list = gimp_image_get_sample_points (image); list; list = g_list_next (list))
for (list = gimp_image_get_sample_points (image);
list;
list = g_list_next (list))
{
GimpSamplePoint *sample_point = list->data;
gint old_x;
......
......@@ -168,7 +168,9 @@ gimp_image_scale (GimpImage *image,
}
/* Scale all Guides */
for (list = gimp_image_get_guides (image); list; list = g_list_next (list))
for (list = gimp_image_get_guides (image);
list;
list = g_list_next (list))
{
GimpGuide *guide = list->data;
gint position = gimp_guide_get_position (guide);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment