Commit 72502972 authored by William Skaggs's avatar William Skaggs
Browse files

Bill Skaggs <weskaggs@primate.ucdavis.edu>

	* gimp/app/tools/Makefile.am
	* gimp/app/tools/gimp-tools.c
	* gimp/app/tools/gimpalignoptions.c
	* gimp/app/tools/gimpalignoptions.h
	* gimp/app/tools/gimpaligntool.c
	* gimp/app/tools/gimpaligntool.h: Add new tool for
	aligning layers etc, as described in bug #147437.

	* gimp/app/core/gimpitem.c
	* gimp/app/core/gimpitem.h (gimp_item_align): add
	function required by new tool.

	* gimp/app/core/core-enums.c
	* gimp/app/core/core-enums.h: add enum for alignment
	types.

	* gimp/themes/Default/images/stock-hcenter-24.png
	* gimp/themes/Default/images/stock-vcenter-24.png
	* gimp/libgimpwidgets/gimpstock.c
	* gimp/libgimpwidgets/gimpstock.h
	* gimp/themes/Default/images/Makefile.am
	* gimp/themes/Default/images/makefile.msc: add two
	stock symbols, modeled on the gravity symbols.
parent b91651fe
2005-06-03 Bill Skaggs <weskaggs@primate.ucdavis.edu>
* gimp/app/tools/Makefile.am
* gimp/app/tools/gimp-tools.c
* gimp/app/tools/gimpalignoptions.c
* gimp/app/tools/gimpalignoptions.h
* gimp/app/tools/gimpaligntool.c
* gimp/app/tools/gimpaligntool.h: Add new tool for
aligning layers etc, as described in bug #147437.
* gimp/app/core/gimpitem.c
* gimp/app/core/gimpitem.h (gimp_item_align): add
function required by new tool.
* gimp/app/core/core-enums.c
* gimp/app/core/core-enums.h: add enum for alignment
types.
* gimp/themes/Default/images/stock-hcenter-24.png
* gimp/themes/Default/images/stock-vcenter-24.png
* gimp/libgimpwidgets/gimpstock.c
* gimp/libgimpwidgets/gimpstock.h
* gimp/themes/Default/images/Makefile.am
* gimp/themes/Default/images/makefile.msc: add two
stock symbols, modeled on the gravity symbols.
2005-06-02 Bill Skaggs <weskaggs@primate.ucdavis.edu>
* app/tools/gimprectangletool.c (gimp_rectangle_tool_motion):
......
......@@ -144,6 +144,42 @@ gimp_gravity_type_get_type (void)
return type;
}
GType
gimp_alignment_type_get_type (void)
{
static const GEnumValue values[] =
{
{ GIMP_ALIGN_LEFT, "GIMP_ALIGN_LEFT", "left" },
{ GIMP_ALIGN_CENTER, "GIMP_ALIGN_CENTER", "center" },
{ GIMP_ALIGN_RIGHT, "GIMP_ALIGN_RIGHT", "right" },
{ GIMP_ALIGN_TOP, "GIMP_ALIGN_TOP", "top" },
{ GIMP_ALIGN_MIDDLE, "GIMP_ALIGN_MIDDLE", "middle" },
{ GIMP_ALIGN_BOTTOM, "GIMP_ALIGN_BOTTOM", "bottom" },
{ 0, NULL, NULL }
};
static const GimpEnumDesc descs[] =
{
{ GIMP_ALIGN_LEFT, "GIMP_ALIGN_LEFT", NULL },
{ GIMP_ALIGN_CENTER, "GIMP_ALIGN_CENTER", NULL },
{ GIMP_ALIGN_RIGHT, "GIMP_ALIGN_RIGHT", NULL },
{ GIMP_ALIGN_TOP, "GIMP_ALIGN_TOP", NULL },
{ GIMP_ALIGN_MIDDLE, "GIMP_ALIGN_MIDDLE", NULL },
{ GIMP_ALIGN_BOTTOM, "GIMP_ALIGN_BOTTOM", NULL },
{ 0, NULL, NULL }
};
static GType type = 0;
if (! type)
{
type = g_enum_register_static ("GimpAlignmentType", values);
gimp_enum_set_value_descriptions (type, descs);
}
return type;
}
GType
gimp_fill_type_get_type (void)
{
......
......@@ -95,6 +95,21 @@ typedef enum /*< pdb-skip >*/
} GimpGravityType;
#define GIMP_TYPE_ALIGNMENT (gimp_alignment_type_get_type ())
GType gimp_alignment_type_get_type (void) G_GNUC_CONST;
typedef enum /*< pdb-skip >*/
{
GIMP_ALIGN_LEFT,
GIMP_ALIGN_CENTER,
GIMP_ALIGN_RIGHT,
GIMP_ALIGN_TOP,
GIMP_ALIGN_MIDDLE,
GIMP_ALIGN_BOTTOM
} GimpAlignmentType;
#define GIMP_TYPE_FILL_TYPE (gimp_fill_type_get_type ())
GType gimp_fill_type_get_type (void) G_GNUC_CONST;
......
......@@ -1249,3 +1249,132 @@ gimp_item_get_linked (const GimpItem *item)
return item->linked;
}
/**
* 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..
* @push_undo: If #TRUE, create an entry in the image's undo stack
* for this action.
*
* 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 push_undo)
{
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->gimage))
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->gimage);
reference_width = gimp_image_get_width (target->gimage);
}
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, push_undo);
}
......@@ -253,5 +253,12 @@ void gimp_item_set_linked (GimpItem *item,
gboolean push_undo);
gboolean gimp_item_get_linked (const GimpItem *item);
void gimp_item_align (GimpItem *target,
GimpAlignmentType target_alignment,
GimpItem *refeence,
GimpAlignmentType reference_alignment,
gint offset,
gboolean push_undo);
#endif /* __GIMP_ITEM_H__ */
......@@ -14,6 +14,10 @@ libapptools_a_sources = \
\
gimpairbrushtool.c \
gimpairbrushtool.h \
gimpalignoptions.c \
gimpalignoptions.h \
gimpaligntool.c \
gimpaligntool.h \
gimpblendoptions.c \
gimpblendoptions.h \
gimpblendtool.c \
......
......@@ -42,6 +42,7 @@
#include "tool_manager.h"
#include "gimpairbrushtool.h"
#include "gimpaligntool.h"
#include "gimpblendtool.h"
#include "gimpbrightnesscontrasttool.h"
#include "gimpbucketfilltool.h"
......@@ -148,6 +149,7 @@ gimp_tools_init (Gimp *gimp)
gimp_rotate_tool_register,
gimp_crop_tool_register,
gimp_move_tool_register,
gimp_align_tool_register,
/* non-modifying tools */
......
/* 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 <gtk/gtk.h>
#include "libgimpconfig/gimpconfig.h"
#include "libgimpwidgets/gimpwidgets.h"
#include "tools-types.h"
#include "core/gimptoolinfo.h"
#include "widgets/gimpwidgets-utils.h"
#include "gimpalignoptions.h"
#include "gimptooloptions-gui.h"
#include "gimp-intl.h"
enum
{
PROP_0,
PROP_ALIGN_TYPE
};
static void gimp_align_options_class_init (GimpAlignOptionsClass *options_class);
static void gimp_align_options_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec);
static void gimp_align_options_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec);
static GimpToolOptionsClass *parent_class = NULL;
GType
gimp_align_options_get_type (void)
{
static GType type = 0;
if (! type)
{
static const GTypeInfo info =
{
sizeof (GimpAlignOptionsClass),
(GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL,
(GClassInitFunc) gimp_align_options_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (GimpAlignOptions),
0, /* n_preallocs */
(GInstanceInitFunc) NULL
};
type = g_type_register_static (GIMP_TYPE_TOOL_OPTIONS,
"GimpAlignOptions",
&info, 0);
}
return type;
}
static void
gimp_align_options_class_init (GimpAlignOptionsClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
parent_class = g_type_class_peek_parent (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,
0);
}
static void
gimp_align_options_set_property (GObject *object,
guint property_id,
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;
}
}
static void
gimp_align_options_get_property (GObject *object,
guint property_id,
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;
}
}
GtkWidget *
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);
g_object_set_data (G_OBJECT (tool_options),
"controls-container", controls_container);
return vbox;
}
/* 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.
*/
#ifndef __GIMP_ALIGN_OPTIONS_H__
#define __GIMP_ALIGN_OPTIONS_H__
#include "core/gimptooloptions.h"
#define GIMP_TYPE_ALIGN_OPTIONS (gimp_align_options_get_type ())
#define GIMP_ALIGN_OPTIONS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_ALIGN_OPTIONS, GimpAlignOptions))
#define GIMP_ALIGN_OPTIONS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_ALIGN_OPTIONS, GimpAlignOptionsClass))
#define GIMP_IS_ALIGN_OPTIONS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_ALIGN_OPTIONS))
#define GIMP_IS_ALIGN_OPTIONS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_ALIGN_OPTIONS))
#define GIMP_ALIGN_OPTIONS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_ALIGN_OPTIONS, GimpAlignOptionsClass))
typedef struct _GimpAlignOptions GimpAlignOptions;
typedef struct _GimpToolOptionsClass GimpAlignOptionsClass;
struct _GimpAlignOptions
{
GimpToolOptions parent_instence;
GimpTransformType align_type;
};
GType gimp_align_options_get_type (void) G_GNUC_CONST;
GtkWidget * gimp_align_options_gui (GimpToolOptions *tool_options);
#endif /* __GIMP_ALIGN_OPTIONS_H__ */
This diff is collapsed.
/* 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.
*/
#ifndef __GIMP_ALIGN_TOOL_H__
#define __GIMP_ALIGN_TOOL_H__
#include "gimpdrawtool.h"
#define GIMP_TYPE_ALIGN_TOOL (gimp_align_tool_get_type ())
#define GIMP_ALIGN_TOOL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_ALIGN_TOOL, GimpAlignTool))
#define GIMP_ALIGN_TOOL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_ALIGN_TOOL, GimpAlignToolClass))
#define GIMP_IS_ALIGN_TOOL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_ALIGN_TOOL))
#define GIMP_IS_ALIGN_TOOL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_ALIGN_TOOL))
#define GIMP_ALIGN_TOOL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_ALIGN_TOOL, GimpAlignToolClass))
typedef struct _GimpAlignTool GimpAlignTool;
typedef struct _GimpAlignToolClass GimpAlignToolClass;
struct _GimpAlignTool
{
GimpDrawTool parent_instance;
GtkWidget *controls;
GimpItem *target_item;
GimpItem *reference_item;
GimpAlignmentType target_horz_align_type;
GimpAlignmentType target_vert_align_type;
GimpAlignmentType ref_horz_align_type;
GimpAlignmentType ref_vert_align_type;
gdouble horz_offset;
gdouble vert_offset;
GtkObject *horz_offset_adjustment;
GtkObject *vert_offset_adjustment;
};
struct _GimpAlignToolClass
{
GimpDrawToolClass parent_class;
};
void gimp_align_tool_register (GimpToolRegisterCallback callback,
gpointer data);
GType gimp_align_tool_get_type (void) G_GNUC_CONST;
#endif /* __GIMP_ALIGN_TOOL_H__ */
......@@ -141,6 +141,9 @@ static GtkStockItem gimp_stock_items[] =
{ GIMP_STOCK_GRAVITY_SOUTH_WEST, NULL, 0, 0, LIBGIMP_DOMAIN },
{ GIMP_STOCK_GRAVITY_WEST, NULL, 0, 0, LIBGIMP_DOMAIN },
{ GIMP_STOCK_HCENTER, NULL, 0, 0, LIBGIMP_DOMAIN },
{ GIMP_STOCK_VCENTER, NULL, 0, 0, LIBGIMP_DOMAIN },
{ GIMP_STOCK_HCHAIN, NULL, 0, 0, LIBGIMP_DOMAIN },
{ GIMP_STOCK_HCHAIN_BROKEN, NULL, 0, 0, LIBGIMP_DOMAIN },
{ GIMP_STOCK_VCHAIN, NULL, 0, 0, LIBGIMP_DOMAIN },
......@@ -323,6 +326,9 @@ gimp_stock_button_pixbufs[] =
{ GIMP_STOCK_GRAVITY_SOUTH_WEST, stock_gravity_south_west_24 },
{ GIMP_STOCK_GRAVITY_WEST, stock_gravity_west_24 },
{ GIMP_STOCK_HCENTER, stock_hcenter_24 },
{ GIMP_STOCK_VCENTER, stock_vcenter_24 },
{ GIMP_STOCK_HCHAIN, stock_hchain_24 },
{ GIMP_STOCK_HCHAIN_BROKEN, stock_hchain_broken_24 },
{ GIMP_STOCK_VCHAIN, stock_vchain_24 },
......
......@@ -62,6 +62,9 @@ G_BEGIN_DECLS
#define GIMP_STOCK_GRAVITY_SOUTH_WEST "gimp-gravity-south-west"
#define GIMP_STOCK_GRAVITY_WEST "gimp-gravity-west"
#define GIMP_STOCK_HCENTER "gimp-hcenter"
#define GIMP_STOCK_VCENTER "gimp-vcenter"
#define GIMP_STOCK_HCHAIN "gimp-hchain"
#define GIMP_STOCK_HCHAIN_BROKEN "gimp-hchain-broken"
#define GIMP_STOCK_VCHAIN "gimp-vchain"
......
......@@ -161,6 +161,7 @@ STOCK_BUTTON_IMAGES = \
stock-gravity-south-east-24.png \
stock-gravity-south-west-24.png \
stock-gravity-west-24.png \
stock-hcenter-24.png \
stock-hchain-24.png \
stock-hchain-broken-24.png \
stock-histogram-22.png \
......@@ -199,6 +200,7 @@ STOCK_BUTTON_IMAGES = \
stock-tool-options-24.png \
stock-tools-24.png \
stock-transparency-24.png \
stock-vcenter-24.png \
stock-vchain-24.png \
stock-vchain-broken-24.png \
stock-video-24.png \
......
......@@ -89,6 +89,7 @@ STOCK_VARIABLES = \
stock_gravity_south_west_24 stock-gravity-south-west-24.png \
stock_gravity_west_24 stock-gravity-west-24.png \
stock_grid_16 stock-grid-16.png \
stock_hcenter_24 stock-hcenter-24.png \
stock_histogram_16 stock-histogram-16.png \