mirror of https://github.com/GNOME/gimp.git
app: remove the GIMP_IS_CHANNEL() case from gimpimage-arrange.c
The object offset is calculated correctly for channels in the GIMP_IS_ITEM() case using gimp_item_bounds(). Also did some general formatting cleanup in the entire file.
This commit is contained in:
parent
658a7834fe
commit
1aa382e594
|
@ -29,8 +29,6 @@
|
|||
#include "gimpimage-guides.h"
|
||||
#include "gimpimage-undo.h"
|
||||
#include "gimpitem.h"
|
||||
#include "gimpchannel.h"
|
||||
#include "gimpdrawable.h"
|
||||
#include "gimpguide.h"
|
||||
|
||||
#include "gimp-intl.h"
|
||||
|
@ -54,21 +52,22 @@ static gint offset_compare (gconstpointer a,
|
|||
* @reference_alignment: The point on the reference object to align the target item with..
|
||||
* @offset: How much to shift the target from perfect alignment..
|
||||
*
|
||||
* This function shifts the positions of a set of target objects, which can be
|
||||
* "items" or guides, to bring them into a specified type of alignment with a
|
||||
* reference object, which can be an item, guide, or image. If the requested
|
||||
* alignment does not make sense (i.e., trying to align a vertical guide vertically),
|
||||
* nothing happens and no error message is generated.
|
||||
* This function shifts the positions of a set of target objects,
|
||||
* which can be "items" or guides, to bring them into a specified type
|
||||
* of alignment with a reference object, which can be an item, guide,
|
||||
* or image. If the requested alignment does not make sense (i.e.,
|
||||
* trying to align a vertical guide vertically), nothing happens and
|
||||
* no error message is generated.
|
||||
*
|
||||
* The objects in the list are sorted into increasing order before
|
||||
* being arranged, where the order is defined by the type of alignment
|
||||
* being requested. If the @reference argument is #NULL, then the first
|
||||
* object in the sorted list is used as reference.
|
||||
* being requested. If the @reference argument is #NULL, then the
|
||||
* first object in the sorted list is used as reference.
|
||||
*
|
||||
* When there are multiple target objects, they are arranged so that the spacing
|
||||
* between consecutive ones is given by the argument @offset but for HFILL and VFILL -
|
||||
* in this case, @offset works as an internal margin for the distribution
|
||||
* (and it can be negative).
|
||||
* When there are multiple target objects, they are arranged so that
|
||||
* the spacing between consecutive ones is given by the argument
|
||||
* @offset but for HFILL and VFILL - in this case, @offset works as an
|
||||
* internal margin for the distribution (and it can be negative).
|
||||
*/
|
||||
void
|
||||
gimp_image_arrange_objects (GimpImage *image,
|
||||
|
@ -78,9 +77,9 @@ gimp_image_arrange_objects (GimpImage *image,
|
|||
GimpAlignmentType reference_alignment,
|
||||
gint offset)
|
||||
{
|
||||
gboolean do_x = FALSE;
|
||||
gboolean do_y = FALSE;
|
||||
gint z0 = 0;
|
||||
gboolean do_x = FALSE;
|
||||
gboolean do_y = FALSE;
|
||||
gint z0 = 0;
|
||||
GList *object_list;
|
||||
|
||||
g_return_if_fail (GIMP_IS_IMAGE (image));
|
||||
|
@ -96,6 +95,7 @@ gimp_image_arrange_objects (GimpImage *image,
|
|||
do_x = TRUE;
|
||||
compute_offsets (list, GIMP_ALIGN_TOP);
|
||||
break;
|
||||
|
||||
/* order horizontally for horizontal arrangement */
|
||||
case GIMP_ARRANGE_LEFT:
|
||||
case GIMP_ARRANGE_HCENTER:
|
||||
|
@ -104,6 +104,7 @@ gimp_image_arrange_objects (GimpImage *image,
|
|||
do_x = TRUE;
|
||||
compute_offsets (list, alignment);
|
||||
break;
|
||||
|
||||
/* order horizontally for vertical alignment */
|
||||
case GIMP_ALIGN_TOP:
|
||||
case GIMP_ALIGN_VCENTER:
|
||||
|
@ -111,6 +112,7 @@ gimp_image_arrange_objects (GimpImage *image,
|
|||
do_y = TRUE;
|
||||
compute_offsets (list, GIMP_ALIGN_LEFT);
|
||||
break;
|
||||
|
||||
/* order vertically for vertical arrangement */
|
||||
case GIMP_ARRANGE_TOP:
|
||||
case GIMP_ARRANGE_VCENTER:
|
||||
|
@ -141,7 +143,7 @@ gimp_image_arrange_objects (GimpImage *image,
|
|||
|
||||
if (object_list)
|
||||
{
|
||||
GList *lst;
|
||||
GList *list;
|
||||
gint n;
|
||||
gint distr_width = 0;
|
||||
gint distr_height = 0;
|
||||
|
@ -162,36 +164,35 @@ gimp_image_arrange_objects (GimpImage *image,
|
|||
fill_offset = (distr_height - 2 * offset) /
|
||||
g_list_length (object_list);
|
||||
}
|
||||
|
||||
/* FIXME: undo group type is wrong */
|
||||
gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_ITEM_DISPLACE,
|
||||
C_("undo-type", "Arrange Objects"));
|
||||
|
||||
for (lst = object_list, n = 1; lst; lst = g_list_next (lst), n++)
|
||||
for (list = object_list, n = 1;
|
||||
list;
|
||||
list = g_list_next (list), n++)
|
||||
{
|
||||
GObject *target = G_OBJECT (lst->data);
|
||||
gint xtranslate = 0;
|
||||
gint ytranslate = 0;
|
||||
gint width;
|
||||
gint height;
|
||||
GObject *target = list->data;
|
||||
gint xtranslate = 0;
|
||||
gint ytranslate = 0;
|
||||
gint z1;
|
||||
|
||||
z1 = GPOINTER_TO_INT (g_object_get_data (target,
|
||||
"align-offset"));
|
||||
z1 = GPOINTER_TO_INT (g_object_get_data (target, "align-offset"));
|
||||
|
||||
if (reference_alignment == GIMP_ARRANGE_HFILL)
|
||||
{
|
||||
|
||||
width = GPOINTER_TO_INT (g_object_get_data (target,
|
||||
"align-width"));
|
||||
gint width = GPOINTER_TO_INT (g_object_get_data (target,
|
||||
"align-width"));
|
||||
xtranslate = ROUND (z0 - z1 + (n - 0.5) * fill_offset -
|
||||
width/2.0 + offset);
|
||||
width / 2.0 + offset);
|
||||
}
|
||||
else if (reference_alignment == GIMP_ARRANGE_VFILL)
|
||||
{
|
||||
height = GPOINTER_TO_INT (g_object_get_data (target,
|
||||
"align-height"));
|
||||
gint height = GPOINTER_TO_INT (g_object_get_data (target,
|
||||
"align-height"));
|
||||
ytranslate = ROUND (z0 - z1 + (n - 0.5) * fill_offset -
|
||||
height/2.0 + offset);
|
||||
height / 2.0 + offset);
|
||||
}
|
||||
else /* the normal computing, when we don't depend on the
|
||||
* width or height of the reference object
|
||||
|
@ -236,7 +237,6 @@ gimp_image_arrange_objects (GimpImage *image,
|
|||
g_list_free (object_list);
|
||||
}
|
||||
|
||||
|
||||
static GList *
|
||||
sort_by_offset (GList *list)
|
||||
{
|
||||
|
@ -257,8 +257,7 @@ offset_compare (gconstpointer a,
|
|||
return offset1 - offset2;
|
||||
}
|
||||
|
||||
/*
|
||||
* this function computes the position of the alignment point
|
||||
/* this function computes the position of the alignment point
|
||||
* for each object in the list, and attaches it to the
|
||||
* object as object data.
|
||||
*/
|
||||
|
@ -266,14 +265,14 @@ static void
|
|||
compute_offsets (GList *list,
|
||||
GimpAlignmentType alignment)
|
||||
{
|
||||
GList *lst;
|
||||
GList *l;
|
||||
|
||||
for (lst = list; lst; lst = g_list_next (lst))
|
||||
compute_offset (G_OBJECT (lst->data), alignment);
|
||||
for (l = list; l; l = g_list_next (l))
|
||||
compute_offset (l->data, alignment);
|
||||
}
|
||||
|
||||
static void
|
||||
compute_offset (GObject *object,
|
||||
compute_offset (GObject *object,
|
||||
GimpAlignmentType alignment)
|
||||
{
|
||||
gint object_offset_x = 0;
|
||||
|
@ -291,33 +290,6 @@ compute_offset (GObject *object,
|
|||
object_height = gimp_image_get_height (image);
|
||||
object_width = gimp_image_get_width (image);
|
||||
}
|
||||
else if (GIMP_IS_CHANNEL (object))
|
||||
{
|
||||
/* for channels, we use the bounds of the visible area, not
|
||||
the layer bounds. This includes the selection channel */
|
||||
|
||||
GimpChannel *channel = GIMP_CHANNEL (object);
|
||||
|
||||
if (gimp_channel_is_empty (channel))
|
||||
{
|
||||
/* fall back on using the offsets instead */
|
||||
GimpItem *item = GIMP_ITEM (object);
|
||||
|
||||
gimp_item_get_offset (item, &object_offset_x, &object_offset_y);
|
||||
object_width = gimp_item_get_width (item);
|
||||
object_height = gimp_item_get_height (item);
|
||||
}
|
||||
else
|
||||
{
|
||||
gint x1, x2, y1, y2;
|
||||
|
||||
gimp_channel_bounds (channel, &x1, &y1, &x2, &y2);
|
||||
object_offset_x = x1;
|
||||
object_offset_y = y1;
|
||||
object_width = x2 - x1;
|
||||
object_height = y2 - y1;
|
||||
}
|
||||
}
|
||||
else if (GIMP_IS_ITEM (object))
|
||||
{
|
||||
GimpItem *item = GIMP_ITEM (object);
|
||||
|
@ -365,27 +337,33 @@ compute_offset (GObject *object,
|
|||
case GIMP_ARRANGE_HFILL:
|
||||
offset = object_offset_x;
|
||||
break;
|
||||
|
||||
case GIMP_ALIGN_HCENTER:
|
||||
case GIMP_ARRANGE_HCENTER:
|
||||
offset = object_offset_x + object_width/2;
|
||||
offset = object_offset_x + object_width / 2;
|
||||
break;
|
||||
|
||||
case GIMP_ALIGN_RIGHT:
|
||||
case GIMP_ARRANGE_RIGHT:
|
||||
offset = object_offset_x + object_width;
|
||||
break;
|
||||
|
||||
case GIMP_ALIGN_TOP:
|
||||
case GIMP_ARRANGE_TOP:
|
||||
case GIMP_ARRANGE_VFILL:
|
||||
offset = object_offset_y;
|
||||
break;
|
||||
|
||||
case GIMP_ALIGN_VCENTER:
|
||||
case GIMP_ARRANGE_VCENTER:
|
||||
offset = object_offset_y + object_height/2;
|
||||
offset = object_offset_y + object_height / 2;
|
||||
break;
|
||||
|
||||
case GIMP_ALIGN_BOTTOM:
|
||||
case GIMP_ARRANGE_BOTTOM:
|
||||
offset = object_offset_y + object_height;
|
||||
break;
|
||||
|
||||
default:
|
||||
g_assert_not_reached ();
|
||||
}
|
||||
|
@ -393,17 +371,15 @@ compute_offset (GObject *object,
|
|||
g_object_set_data (object, "align-offset",
|
||||
GINT_TO_POINTER (offset));
|
||||
|
||||
/* These are only used for HFILL and VFILL, but
|
||||
* since the call to gimp_image_arrange_objects
|
||||
* allows for two different alignments (object and reference_alignment)
|
||||
* we better be on the safe side in case they differ.
|
||||
* (the current implementation of the align tool always
|
||||
* pass the same value to both parameters)
|
||||
/* These are only used for HFILL and VFILL, but since the call to
|
||||
* gimp_image_arrange_objects allows for two different alignments
|
||||
* (object and reference_alignment) we better be on the safe side in
|
||||
* case they differ. (the current implementation of the align tool
|
||||
* always pass the same value to both parameters)
|
||||
*/
|
||||
g_object_set_data (object, "align-width",
|
||||
GINT_TO_POINTER (object_width));
|
||||
|
||||
g_object_set_data (object, "align-height",
|
||||
GINT_TO_POINTER (object_height));
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue