Bill Skaggs <weskaggs@primate.ucdavis.edu>

* app/core/gimpimage-arrange.[ch]: added, utility function for
	aligning and arranging things in an image.

	* app/core/gimpitem-align.[ch}: removed, no longer needed.

	* app/core/gimpimage-item-list.[ch] (gimp_image_item_list_align):
	removed this function, no longer used.

	* app/core/Makefile.am: changes described above.

	* app/core/gimpguide.c: remove bit of cruft left accidentally.

	* app/tools/gimpalignoptions.[ch]: remove "alignment type"
	option, not needed at this point.

	* app/tools/gimpaligntool.[ch]: numerous changes, most
	importantly ability to align guides, and use them for
	alignment.  More work coming on this tool.
This commit is contained in:
William Skaggs 2006-06-07 21:29:54 +00:00
parent 4a60cf418b
commit 40db64f48c
12 changed files with 511 additions and 356 deletions

View File

@ -1,3 +1,24 @@
2006-06-07 Bill Skaggs <weskaggs@primate.ucdavis.edu>
* app/core/gimpimage-arrange.[ch]: added, utility function for
aligning and arranging things in an image.
* app/core/gimpitem-align.[ch}: removed, no longer needed.
* app/core/gimpimage-item-list.[ch] (gimp_image_item_list_align):
removed this function, no longer used.
* app/core/Makefile.am: changes described above.
* app/core/gimpguide.c: remove bit of cruft left accidentally.
* app/tools/gimpalignoptions.[ch]: remove "alignment type"
option, not needed at this point.
* app/tools/gimpaligntool.[ch]: numerous changes, most
importantly ability to align guides, and use them for
alignment. More work coming on this tool.
2006-06-07 Bill Skaggs <weskaggs@primate.ucdavis.edu>
* app/core/gimpguide.[ch]: add "removed" signal and associated

View File

@ -124,6 +124,8 @@ libappcore_a_sources = \
gimpguide.h \
gimpimage.c \
gimpimage.h \
gimpimage-arrange.c \
gimpimage-arrange.h \
gimpimage-colorhash.c \
gimpimage-colorhash.h \
gimpimage-colormap.c \
@ -176,8 +178,6 @@ libappcore_a_sources = \
gimpimagemap.h \
gimpitem.c \
gimpitem.h \
gimpitem-align.c \
gimpitem-align.h \
gimpitem-linked.c \
gimpitem-linked.h \
gimpitem-preview.c \

View File

@ -34,7 +34,6 @@
enum
{
REMOVED,
MOVED,
LAST_SIGNAL
};

View File

@ -0,0 +1,294 @@
/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "config.h"
#include <glib-object.h>
#include "core-types.h"
#include "gimpimage.h"
#include "gimpimage-arrange.h"
#include "gimpimage-guides.h"
#include "gimpimage-undo.h"
#include "gimpitem.h"
#include "gimpguide.h"
#include "gimp-intl.h"
/**
* gimp_image_arrange_objects:
* @image: The #GimpImage to which the objects belong.
* @list: A #GList of objects to be aligned.
* @alignment: The point on each target object to bring into alignment.
* @reference: The #GObject to align the targets with.
* @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.
*
* When there are multiple target objects, they are arranged so that the spacing
* between consecutive ones is given by the argument @offset.
*/
void
gimp_image_arrange_objects (GimpImage *image,
GList *list,
GimpAlignmentType alignment,
GObject *reference,
GimpAlignmentType reference_alignment,
gint offset)
{
gboolean do_x = FALSE;
gboolean do_y = FALSE;
gint reference_offset_x = 0;
gint reference_offset_y = 0;
gint reference_height = 0;
gint reference_width = 0;
gint x0 = 0;
gint y0 = 0;
g_return_if_fail (GIMP_IS_IMAGE (image));
g_return_if_fail (G_IS_OBJECT (reference));
/* figure out whether we are aligning horizontally or vertically */
switch (reference_alignment)
{
case GIMP_ALIGN_LEFT:
case GIMP_ALIGN_CENTER:
case GIMP_ALIGN_RIGHT:
do_x = TRUE;
break;
case GIMP_ALIGN_TOP:
case GIMP_ALIGN_MIDDLE:
case GIMP_ALIGN_BOTTOM:
do_y = TRUE;
break;
default:
g_assert_not_reached ();
}
/* get dimensions of the reference object */
if (GIMP_IS_IMAGE (reference))
{
reference_offset_x = 0;
reference_offset_y = 0;
reference_width = gimp_image_get_width (image);
reference_height = gimp_image_get_height (image);
}
else if (GIMP_IS_ITEM (reference))
{
GimpItem *item = GIMP_ITEM (reference);
reference_offset_x = item->offset_x;
reference_offset_y = item->offset_y;
reference_height = item->height;
reference_width = item->width;
}
else if (GIMP_IS_GUIDE (reference))
{
GimpGuide *guide = GIMP_GUIDE (reference);
switch (gimp_guide_get_orientation (guide))
{
case GIMP_ORIENTATION_VERTICAL:
if (do_y)
return;
reference_offset_x = gimp_guide_get_position (guide);
reference_width = 0;
break;
case GIMP_ORIENTATION_HORIZONTAL:
if (do_x)
return;
reference_offset_y = gimp_guide_get_position (guide);
reference_height = 0;
break;
default:
break;
}
}
else
{
g_printerr ("Reference object is not an image, item, or guide.\n");
return;
}
/* compute alignment pos for reference object */
switch (reference_alignment)
{
case GIMP_ALIGN_LEFT:
x0 = reference_offset_x;
break;
case GIMP_ALIGN_CENTER:
x0 = reference_offset_x + reference_width/2;
break;
case GIMP_ALIGN_RIGHT:
x0 = reference_offset_x + reference_width;
break;
case GIMP_ALIGN_TOP:
y0 = reference_offset_y;
break;
case GIMP_ALIGN_MIDDLE:
y0 = reference_offset_y + reference_height/2;
break;
case GIMP_ALIGN_BOTTOM:
y0 = reference_offset_y + reference_height;
break;
default:
g_assert_not_reached ();
}
if (list)
{
GList *l;
gint n;
/* FIXME: undo group type is wrong */
gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_ITEM_DISPLACE,
_("Arrange Objects"));
for (l = list, n = 1; l; l = g_list_next (l), n++)
{
GObject *target = G_OBJECT (l->data);
gint xtranslate = 0;
gint ytranslate = 0;
gint target_offset_x = 0;
gint target_offset_y = 0;
gint target_height = 0;
gint target_width = 0;
gint x1 = 0;
gint y1 = 0;
/* compute dimensions of target object */
if (GIMP_IS_ITEM (target))
{
GimpItem *item = GIMP_ITEM (target);
target_offset_x = item->offset_x;
target_offset_y = item->offset_y;
target_height = item->height;
target_width = item->width;
}
else if (GIMP_IS_GUIDE (target))
{
GimpGuide *guide = GIMP_GUIDE (target);
switch (gimp_guide_get_orientation (guide))
{
case GIMP_ORIENTATION_VERTICAL:
if (do_y)
return;
target_offset_x = gimp_guide_get_position (guide);
target_width = 0;
break;
case GIMP_ORIENTATION_HORIZONTAL:
if (do_x)
return;
target_offset_y = gimp_guide_get_position (guide);
target_height = 0;
break;
default:
break;
}
}
else
{
g_printerr ("Alignment target is not an item or guide.\n");
}
if (do_x)
{
switch (alignment)
{
case GIMP_ALIGN_LEFT:
x1 = target_offset_x;
break;
case GIMP_ALIGN_CENTER:
x1 = target_offset_x + target_width/2;
break;
case GIMP_ALIGN_RIGHT:
x1 = target_offset_x + target_width;
break;
default:
g_assert_not_reached ();
}
xtranslate = x0 - x1 + n * offset;
}
if (do_y)
{
switch (alignment)
{
case GIMP_ALIGN_TOP:
y1 = target_offset_y;
break;
case GIMP_ALIGN_MIDDLE:
y1 = target_offset_y + target_height/2;
break;
case GIMP_ALIGN_BOTTOM:
y1 = target_offset_y + target_height;
break;
default:
g_assert_not_reached ();
}
ytranslate = y0 - y1 + n * offset;
}
/* now actually align the target object */
if (GIMP_IS_ITEM (target))
{
gimp_item_translate (GIMP_ITEM (target),
xtranslate, ytranslate, TRUE);
}
else if (GIMP_IS_GUIDE (target))
{
GimpGuide *guide = GIMP_GUIDE (target);
switch (gimp_guide_get_orientation (guide))
{
case GIMP_ORIENTATION_VERTICAL:
gimp_image_move_guide (image, guide, x1 + xtranslate, TRUE);
gimp_image_update_guide (image, guide);
break;
case GIMP_ORIENTATION_HORIZONTAL:
gimp_image_move_guide (image, guide, y1 + ytranslate, TRUE);
gimp_image_update_guide (image, guide);
break;
default:
break;
}
}
}
gimp_image_undo_group_end (image);
gimp_image_flush (image);
}
}

View File

@ -16,13 +16,15 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __GIMP_ITEM_ALIGN_H__
#define __GIMP_ITEM_ALIGN_H__
#ifndef __GIMP_IMAGE_ARRANGE_H__
#define __GIMP_IMAGE_ARRANGE_H__
void gimp_item_align (GimpItem *target,
GimpAlignmentType target_alignment,
GimpItem *refeence,
void gimp_image_arrange_objects (GimpImage *image,
GList *list,
GimpAlignmentType alignment,
GObject *reference,
GimpAlignmentType reference_alignment,
gint offset);
#endif /* __GIMP_ITEM_ALIGN_H__ */
#endif /* __GIMP_IMAGE_ARRANGE_H__ */

View File

@ -27,7 +27,6 @@
#include "gimpimage-item-list.h"
#include "gimpimage-undo.h"
#include "gimpitem.h"
#include "gimpitem-align.h"
#include "gimplist.h"
#include "gimpprogress.h"
@ -149,32 +148,6 @@ gimp_image_item_list_transform (GimpImage *image,
}
}
void
gimp_image_item_list_align (GimpImage *image,
GList *list,
GimpAlignmentType alignment,
GimpItem *reference,
GimpAlignmentType reference_alignment,
gint offset)
{
g_return_if_fail (GIMP_IS_IMAGE (image));
g_return_if_fail (GIMP_IS_ITEM (reference));
if (list)
{
GList *l;
gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_ITEM_DISPLACE,
_("Align Items"));
for (l = list; l; l = g_list_next (l))
gimp_item_align (GIMP_ITEM (l->data), alignment,
reference, reference_alignment, offset);
gimp_image_undo_group_end (image);
}
}
/**
* gimp_image_item_list_get_list:
* @item: A linked @item.

View File

@ -48,12 +48,6 @@ void gimp_image_item_list_transform (GimpImage *image,
gint recursion_level,
gboolean clip_result,
GimpProgress *progress);
void gimp_image_item_list_align (GimpImage *image,
GList *list,
GimpAlignmentType alignment,
GimpItem *reference,
GimpAlignmentType reference_alignment,
gint offset);
GList * gimp_image_item_list_get_list (GimpImage *image,
GimpItem *exclude,

View File

@ -1,158 +0,0 @@
/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "config.h"
#include <glib-object.h>
#include "libgimpbase/gimpbase.h"
#include "core-types.h"
#include "gimp.h"
#include "gimpimage.h"
#include "gimpitem.h"
#include "gimpitem-align.h"
#include "gimp-intl.h"
/**
* gimp_item_align:
* @target: The #GimpItem to move.
* @target_alignment: The part of the target to align..
* @reference: The #GimpItem to align the target with.
* @reference_alignment: The part of the reference item to align the target item with..
* @offset: How much to shift the target from perfect alignment..
*
* Aligns the target item with the reference item in the specified way. If
* the reference item is #NULL, then the target item is aligned with the
* image it belongs to.
*/
void
gimp_item_align (GimpItem *target,
GimpAlignmentType target_alignment,
GimpItem *reference,
GimpAlignmentType reference_alignment,
gint offset)
{
gboolean do_x = FALSE;
gboolean do_y = FALSE;
gint xtranslate = 0;
gint ytranslate = 0;
gint reference_offset_x;
gint reference_offset_y;
gint reference_height;
gint reference_width;
gint x0 = 0;
gint y0 = 0;
gint x1 = 0;
gint y1 = 0;
if (!target)
return;
if (! (reference || target->image))
return;
if (reference)
{
reference_offset_x = reference->offset_x;
reference_offset_y = reference->offset_y;
reference_height = reference->height;
reference_width = reference->width;
}
else
{
reference_offset_x = 0;
reference_offset_y = 0;
reference_height = gimp_image_get_height (target->image);
reference_width = gimp_image_get_width (target->image);
}
switch (reference_alignment)
{
case GIMP_ALIGN_LEFT:
do_x = TRUE;
x0 = reference_offset_x;
break;
case GIMP_ALIGN_CENTER:
do_x = TRUE;
x0 = reference_offset_x + reference_width/2;
break;
case GIMP_ALIGN_RIGHT:
do_x = TRUE;
x0 = reference_offset_x + reference_width;
break;
case GIMP_ALIGN_TOP:
do_y = TRUE;
y0 = reference_offset_y;
break;
case GIMP_ALIGN_MIDDLE:
do_y = TRUE;
y0 = reference_offset_y + reference_height/2;
break;
case GIMP_ALIGN_BOTTOM:
do_y = TRUE;
y0 = reference_offset_y + reference_height;
break;
default:
g_assert_not_reached ();
}
if (do_x)
{
switch (target_alignment)
{
case GIMP_ALIGN_LEFT:
x1 = target->offset_x;
break;
case GIMP_ALIGN_CENTER:
x1 = target->offset_x + target->width/2;
break;
case GIMP_ALIGN_RIGHT:
x1 = target->offset_x + target->width;
break;
default:
g_assert_not_reached ();
}
xtranslate = x0 - x1 + offset;
}
if (do_y)
{
switch (target_alignment)
{
case GIMP_ALIGN_TOP:
y1 = target->offset_y;
break;
case GIMP_ALIGN_MIDDLE:
y1 = target->offset_y + target->height/2;
break;
case GIMP_ALIGN_BOTTOM:
y1 = target->offset_y + target->height;
break;
default:
g_assert_not_reached ();
}
ytranslate = y0 - y1 + offset;
}
gimp_item_translate (target, xtranslate, ytranslate, TRUE);
}

View File

@ -38,7 +38,6 @@
enum
{
PROP_0,
PROP_ALIGN_TYPE
};
@ -62,12 +61,6 @@ gimp_align_options_class_init (GimpAlignOptionsClass *klass)
object_class->set_property = gimp_align_options_set_property;
object_class->get_property = gimp_align_options_get_property;
GIMP_CONFIG_INSTALL_PROP_ENUM (object_class, PROP_ALIGN_TYPE,
"align-type", NULL,
GIMP_TYPE_TRANSFORM_TYPE,
GIMP_TRANSFORM_TYPE_LAYER,
GIMP_PARAM_STATIC_STRINGS);
}
static void
@ -81,13 +74,8 @@ gimp_align_options_set_property (GObject *object,
const GValue *value,
GParamSpec *pspec)
{
GimpAlignOptions *options = GIMP_ALIGN_OPTIONS (object);
switch (property_id)
{
case PROP_ALIGN_TYPE:
options->align_type = g_value_get_enum (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
@ -100,13 +88,8 @@ gimp_align_options_get_property (GObject *object,
GValue *value,
GParamSpec *pspec)
{
GimpAlignOptions *options = GIMP_ALIGN_OPTIONS (object);
switch (property_id)
{
case PROP_ALIGN_TYPE:
g_value_set_enum (value, options->align_type);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
@ -119,25 +102,8 @@ gimp_align_options_gui (GimpToolOptions *tool_options)
GtkWidget *vbox;
GtkWidget *controls_container;
#if 0
GObject *config = G_OBJECT (tool_options);
GtkWidget *hbox;
GtkWidget *label;
#endif
vbox = gimp_tool_options_gui (tool_options);
#if 0
hbox = gimp_prop_enum_stock_box_new (config, "align-type", "gimp", 0, 0);
gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
gtk_widget_show (hbox);
label = gtk_label_new (_("Affect:"));
gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
gtk_box_reorder_child (GTK_BOX (hbox), label, 0);
gtk_widget_show (label);
#endif
controls_container = gtk_vbox_new (FALSE, 0);
gtk_box_pack_start (GTK_BOX (vbox), controls_container, FALSE, FALSE, 0);
gtk_widget_show (controls_container);

View File

@ -37,8 +37,6 @@ typedef struct _GimpToolOptionsClass GimpAlignOptionsClass;
struct _GimpAlignOptions
{
GimpToolOptions parent_instence;
GimpTransformType align_type;
};

View File

@ -24,9 +24,14 @@
#include "tools-types.h"
#include "config/gimpdisplayconfig.h"
#include "core/gimp.h"
#include "core/gimpguide.h"
#include "core/gimpimage.h"
#include "core/gimpimage-item-list.h"
#include "core/gimpimage-arrange.h"
#include "core/gimpimage-guides.h"
#include "core/gimpimage-undo.h"
#include "core/gimplayer.h"
#include "core/gimptoolinfo.h"
#include "core/gimplist.h"
@ -34,6 +39,8 @@
#include "widgets/gimphelp-ids.h"
#include "display/gimpdisplay.h"
#include "display/gimpdisplayshell.h"
#include "display/gimpdisplayshell-appearance.h"
#include "gimpalignoptions.h"
#include "gimpaligntool.h"
@ -85,12 +92,18 @@ static void do_horizontal_alignment (GtkWidget *widget,
gpointer data);
static void do_vertical_alignment (GtkWidget *widget,
gpointer data);
static void clear_selected (GimpItem *item,
static void clear_selected_object (GObject *object,
GimpAlignTool *align_tool);
static void clear_selected_items (GimpAlignTool *align_tool);
static void clear_all_selected_objects (GimpAlignTool *align_tool);
static GimpLayer *select_layer_by_coords (GimpImage *image,
gint x,
gint y);
void gimp_image_arrange_objects (GimpImage *image,
GList *list,
GimpAlignmentType alignment,
GObject *reference,
GimpAlignmentType reference_alignment,
gint offset);
G_DEFINE_TYPE (GimpAlignTool, gimp_align_tool, GIMP_TYPE_DRAW_TOOL)
@ -141,7 +154,7 @@ gimp_align_tool_init (GimpAlignTool *align_tool)
align_tool->controls = NULL;
align_tool->selected_items = NULL;
align_tool->selected_objects = NULL;
align_tool->horz_align_type = GIMP_ALIGN_LEFT;
align_tool->vert_align_type = GIMP_ALIGN_TOP;
@ -229,7 +242,7 @@ gimp_align_tool_control (GimpTool *tool,
break;
case GIMP_TOOL_ACTION_HALT:
clear_selected_items (align_tool);
clear_all_selected_objects (align_tool);
gimp_tool_pop_status (tool, display);
break;
}
@ -255,7 +268,7 @@ gimp_align_tool_button_press (GimpTool *tool,
if (gimp_draw_tool_is_active (GIMP_DRAW_TOOL (tool)))
gimp_draw_tool_stop (GIMP_DRAW_TOOL (tool));
clear_selected_items (align_tool);
clear_all_selected_objects (align_tool);
}
if (! gimp_tool_control_is_active (tool->control))
@ -280,52 +293,67 @@ gimp_align_tool_button_release (GimpTool *tool,
GimpDisplay *display)
{
GimpAlignTool *align_tool = GIMP_ALIGN_TOOL (tool);
GimpAlignOptions *options = GIMP_ALIGN_OPTIONS (tool->tool_info->tool_options);
GimpItem *item = NULL;
GimpDisplayShell *shell = GIMP_DISPLAY_SHELL (display->shell);
GObject *object = NULL;
GimpImage *image = display->image;
gint i;
gimp_draw_tool_pause (GIMP_DRAW_TOOL (tool));
if (! (state & GDK_SHIFT_MASK))
clear_selected_items (align_tool);
clear_all_selected_objects (align_tool);
if (coords->x == align_tool->x0 && coords->y == align_tool->y0)
{
if (options->align_type == GIMP_TRANSFORM_TYPE_PATH)
#define EPSILON 3
/* if mouse has moved less than EPSILON pixels since button press, select
the nearest thing, otherwise make a rubber-band rectangle */
if (hypot (coords->x - align_tool->x0, coords->y - align_tool->y0) < EPSILON)
{
GimpVectors *vectors;
GimpGuide *guide;
GimpLayer *layer;
gint snap_distance;
snap_distance =
GIMP_DISPLAY_CONFIG (display->image->gimp->config)->snap_distance;
if (gimp_draw_tool_on_vectors (GIMP_DRAW_TOOL (tool), display,
coords, 7, 7,
coords, snap_distance, snap_distance,
NULL, NULL, NULL, NULL, NULL,
&vectors))
{
item = GIMP_ITEM (vectors);
object = G_OBJECT (vectors);
}
}
else if (options->align_type == GIMP_TRANSFORM_TYPE_LAYER)
else if (gimp_display_shell_get_show_guides (shell) &&
(guide = gimp_image_find_guide (display->image,
coords->x, coords->y,
FUNSCALEX (shell, snap_distance),
FUNSCALEY (shell, snap_distance))))
{
object = G_OBJECT (guide);
}
else
{
GimpLayer *layer;
if ((layer = select_layer_by_coords (display->image,
coords->x, coords->y)))
{
item = GIMP_ITEM (layer);
object = G_OBJECT (layer);
}
}
if (item)
if (object)
{
if (! g_list_find (align_tool->selected_items, item))
if (! g_list_find (align_tool->selected_objects, object))
{
align_tool->selected_items = g_list_append (align_tool->selected_items, item);
g_signal_connect (item, "removed", G_CALLBACK (clear_selected),
align_tool->selected_objects
= g_list_append (align_tool->selected_objects, object);
g_signal_connect (object, "removed",
G_CALLBACK (clear_selected_object),
(gpointer) align_tool);
}
}
}
else
else /* FIXME: look for vectors too */
{
gint X0 = MIN (coords->x, align_tool->x0);
gint X1 = MAX (coords->x, align_tool->x0);
@ -350,18 +378,19 @@ gimp_align_tool_button_release (GimpTool *tool,
if (x0 < X0 || y0 < Y0 || x1 > X1 || y1 > Y1)
continue;
if (g_list_find (align_tool->selected_items, layer))
if (g_list_find (align_tool->selected_objects, layer))
continue;
align_tool->selected_items = g_list_append (align_tool->selected_items, layer);
g_signal_connect (layer, "removed", G_CALLBACK (clear_selected),
align_tool->selected_objects
= g_list_append (align_tool->selected_objects, layer);
g_signal_connect (layer, "removed", G_CALLBACK (clear_selected_object),
(gpointer) align_tool);
}
}
for (i = 0; i < ALIGN_TOOL_NUM_BUTTONS; i++)
gtk_widget_set_sensitive (align_tool->button[i],
(align_tool->selected_items != NULL));
(align_tool->selected_objects != NULL));
align_tool->x1 = align_tool->x0;
align_tool->y1 = align_tool->y0;
@ -392,51 +421,37 @@ gimp_align_tool_cursor_update (GimpTool *tool,
GdkModifierType state,
GimpDisplay *display)
{
GimpAlignOptions *options;
GimpDisplayShell *shell = GIMP_DISPLAY_SHELL (display->shell);
GimpCursorType cursor = GIMP_CURSOR_MOUSE;
GimpToolCursorType tool_cursor = GIMP_TOOL_CURSOR_MOVE;
GimpCursorModifier modifier = GIMP_CURSOR_MODIFIER_NONE;
gint snap_distance;
options = GIMP_ALIGN_OPTIONS (tool->tool_info->tool_options);
if (options->align_type == GIMP_TRANSFORM_TYPE_PATH)
{
tool_cursor = GIMP_TOOL_CURSOR_PATHS;
snap_distance =
GIMP_DISPLAY_CONFIG (display->image->gimp->config)->snap_distance;
if (gimp_draw_tool_on_vectors (GIMP_DRAW_TOOL (tool), display,
coords, 7, 7,
coords, snap_distance, snap_distance,
NULL, NULL, NULL, NULL, NULL, NULL))
{
tool_cursor = GIMP_TOOL_CURSOR_HAND;
modifier = GIMP_CURSOR_MODIFIER_MOVE;
tool_cursor = GIMP_TOOL_CURSOR_PATHS;
}
else if (gimp_display_shell_get_show_guides (shell) &&
(NULL != gimp_image_find_guide (display->image,
coords->x, coords->y,
FUNSCALEX (shell, snap_distance),
FUNSCALEY (shell, snap_distance))))
{
tool_cursor = GIMP_TOOL_CURSOR_MOVE;
}
else
{
modifier = GIMP_CURSOR_MODIFIER_BAD;
}
}
else
{
GimpLayer *layer = gimp_image_pick_correlate_layer (display->image,
GimpLayer *layer = select_layer_by_coords (display->image,
coords->x, coords->y);
if (layer)
{
/* if there is a floating selection, and this aint it... */
if (gimp_image_floating_sel (display->image) &&
! gimp_layer_is_floating_sel (layer))
{
modifier = GIMP_CURSOR_MODIFIER_ANCHOR;
}
else if (layer != gimp_image_get_active_layer (display->image))
{
tool_cursor = GIMP_TOOL_CURSOR_HAND;
modifier = GIMP_CURSOR_MODIFIER_MOVE;
}
}
else
{
modifier = GIMP_CURSOR_MODIFIER_BAD;
}
}
@ -465,10 +480,12 @@ gimp_align_tool_draw (GimpDrawTool *draw_tool)
x, y,w, h,
FALSE);
for (list = g_list_first (align_tool->selected_items); list;
for (list = g_list_first (align_tool->selected_objects); list;
list = g_list_next (list))
{
GimpItem *item = list->data;
if (GIMP_IS_ITEM (list->data))
{
GimpItem *item = GIMP_ITEM (list->data);
gimp_item_offsets (item, &x, &y);
w = gimp_item_width (item);
@ -487,6 +504,42 @@ gimp_align_tool_draw (GimpDrawTool *draw_tool)
x + w, y + h, 4, 4,
GTK_ANCHOR_SOUTH_EAST, FALSE);
}
else if (GIMP_IS_GUIDE (list->data))
{
GimpGuide *guide = GIMP_GUIDE (list->data);
GimpImage *image = GIMP_TOOL (draw_tool)->display->image;
gint x, y;
gint w, h;
switch (gimp_guide_get_orientation (guide))
{
case GIMP_ORIENTATION_VERTICAL:
x = gimp_guide_get_position (guide);
h = gimp_image_get_height (image);
gimp_draw_tool_draw_handle (draw_tool, GIMP_HANDLE_FILLED_SQUARE,
x, h, 4, 4,
GTK_ANCHOR_SOUTH, FALSE);
gimp_draw_tool_draw_handle (draw_tool, GIMP_HANDLE_FILLED_SQUARE,
x, 0, 4, 4,
GTK_ANCHOR_NORTH, FALSE);
break;
case GIMP_ORIENTATION_HORIZONTAL:
y = gimp_guide_get_position (guide);
w = gimp_image_get_width (image);
gimp_draw_tool_draw_handle (draw_tool, GIMP_HANDLE_FILLED_SQUARE,
w, y, 4, 4,
GTK_ANCHOR_EAST, FALSE);
gimp_draw_tool_draw_handle (draw_tool, GIMP_HANDLE_FILLED_SQUARE,
0, y, 4, 4,
GTK_ANCHOR_WEST, FALSE);
break;
default:
break;
}
}
}
}
@ -636,21 +689,26 @@ do_horizontal_alignment (GtkWidget *widget,
{
GimpAlignTool *align_tool = GIMP_ALIGN_TOOL (data);
GimpImage *image;
GimpItem *reference;
/* make sure there is something to align */
if (! g_list_nth (align_tool->selected_items, 1))
return;
GObject *reference_object;
image = GIMP_TOOL (align_tool)->display->image;
reference = align_tool->selected_items->data;
/* if nothing is selected, just return
* if only one object is selected, use the image as reference
* if multiple objects are selected, use the first one as reference
*/
if (g_list_length (align_tool->selected_objects) == 0)
return;
else if (g_list_length (align_tool->selected_objects) == 1)
reference_object = G_OBJECT (image);
else
reference_object = G_OBJECT (align_tool->selected_objects->data);
gimp_draw_tool_pause (GIMP_DRAW_TOOL (align_tool));
gimp_image_item_list_align (image, g_list_next (align_tool->selected_items),
gimp_image_arrange_objects (image, align_tool->selected_objects,
align_tool->horz_align_type,
reference,
reference_object,
align_tool->horz_align_type,
align_tool->horz_offset);
@ -666,21 +724,26 @@ do_vertical_alignment (GtkWidget *widget,
{
GimpAlignTool *align_tool = GIMP_ALIGN_TOOL (data);
GimpImage *image;
GimpItem *reference;
/* make sure there is something to align */
if (g_list_nth (align_tool->selected_items, 1))
return;
GObject *reference_object;
image = GIMP_TOOL (align_tool)->display->image;
reference = align_tool->selected_items->data;
/* if nothing is selected, just return
* if only one object is selected, use the image as reference
* if multiple objects are selected, use the first one as reference
*/
if (g_list_length (align_tool->selected_objects) == 0)
return;
else if (g_list_length (align_tool->selected_objects) == 1)
reference_object = G_OBJECT (image);
else
reference_object = G_OBJECT (align_tool->selected_objects->data);
gimp_draw_tool_pause (GIMP_DRAW_TOOL (align_tool));
gimp_image_item_list_align (image, g_list_next (align_tool->selected_items),
gimp_image_arrange_objects (image, align_tool->selected_objects,
align_tool->vert_align_type,
reference,
reference_object,
align_tool->vert_align_type,
align_tool->vert_offset);
@ -766,40 +829,40 @@ set_action (GtkWidget *widget,
}
static void
clear_selected (GimpItem *item,
clear_selected_object (GObject *object,
GimpAlignTool *align_tool)
{
gimp_draw_tool_pause (GIMP_DRAW_TOOL (align_tool));
if (align_tool->selected_items)
g_signal_handlers_disconnect_by_func (item,
G_CALLBACK (clear_selected),
if (align_tool->selected_objects)
g_signal_handlers_disconnect_by_func (object,
G_CALLBACK (clear_selected_object),
(gpointer) align_tool);
align_tool->selected_items = g_list_remove (align_tool->selected_items,
item);
align_tool->selected_objects = g_list_remove (align_tool->selected_objects,
object);
gimp_draw_tool_resume (GIMP_DRAW_TOOL (align_tool));
}
static void
clear_selected_items (GimpAlignTool *align_tool)
clear_all_selected_objects (GimpAlignTool *align_tool)
{
GimpDrawTool *draw_tool = GIMP_DRAW_TOOL (align_tool);
if (gimp_draw_tool_is_active (draw_tool))
gimp_draw_tool_pause (draw_tool);
while (align_tool->selected_items)
while (align_tool->selected_objects)
{
GimpItem *item = g_list_first (align_tool->selected_items)->data;
GObject *object = G_OBJECT (g_list_first (align_tool->selected_objects)->data);
g_signal_handlers_disconnect_by_func (item,
G_CALLBACK (clear_selected),
g_signal_handlers_disconnect_by_func (object,
G_CALLBACK (clear_selected_object),
(gpointer) align_tool);
align_tool->selected_items = g_list_remove (align_tool->selected_items,
item);
align_tool->selected_objects = g_list_remove (align_tool->selected_objects,
object);
}
if (gimp_draw_tool_is_active (draw_tool))
@ -841,3 +904,6 @@ select_layer_by_coords (GimpImage *image,
return NULL;
}

View File

@ -42,7 +42,7 @@ struct _GimpAlignTool
GtkWidget *controls;
GtkWidget *button[ALIGN_TOOL_NUM_BUTTONS];
GList *selected_items;
GList *selected_objects;
GimpAlignmentType horz_align_type;
GimpAlignmentType vert_align_type;