Commit 40db64f4 authored by William Skaggs's avatar William Skaggs

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.
parent 4a60cf41
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
......
......@@ -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 \
......
......@@ -34,7 +34,6 @@
enum
{
REMOVED,
MOVED,
LAST_SIGNAL
};
......
/* 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);
}
}
......@@ -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,
GimpAlignmentType reference_alignment,
gint offset);
#endif /* __GIMP_ITEM_ALIGN_H__ */
void gimp_image_arrange_objects (GimpImage *image,
GList *list,
GimpAlignmentType alignment,
GObject *reference,
GimpAlignmentType reference_alignment,
gint offset);
#endif /* __GIMP_IMAGE_ARRANGE_H__ */
......@@ -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.
......
......@@ -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,
......
/* 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);
}
......@@ -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);
......
......@@ -37,8 +37,6 @@ typedef struct _GimpToolOptionsClass GimpAlignOptionsClass;
struct _GimpAlignOptions
{
GimpToolOptions parent_instence;
GimpTransformType align_type;
};
......
......@@ -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))
......@@ -279,53 +292,68 @@ gimp_align_tool_button_release (GimpTool *tool,
GdkModifierType state,
GimpDisplay *display)
{
GimpAlignTool *align_tool = GIMP_ALIGN_TOOL (tool);
GimpAlignOptions *options = GIMP_ALIGN_OPTIONS (tool->tool_info->tool_options);
GimpItem *item = NULL;
GimpImage *image = display->image;
GimpAlignTool *align_tool = GIMP_ALIGN_TOOL (tool);
GimpDisplayShell *shell = GIMP_DISPLAY_SHELL (display->shell);
GObject *object = NULL;
GimpImage *image = display->image;
gint i;
gimp_draw_tool_pau