Commit 643e2257 authored by William Skaggs's avatar William Skaggs
Browse files

Bill Skaggs <weskaggs@primate.ucdavis.edu>

	* app/core/gimpitem-align.[ch]: newly created to
	hold code for gimp_item_align().

	* app/core/Makefile.am: add new files

	* app/core/gimpitem.[ch]: remove code from here.

	* app/tools/gimpaligntool.c: fix includes and remove
	unneeded includes.
parent 635795cc
2005-06-03 Bill Skaggs <weskaggs@primate.ucdavis.edu>
* app/core/gimpitem-align.[ch]: newly created to
hold code for gimp_item_align().
* app/core/Makefile.am: add new files
* app/core/gimpitem.[ch]: remove code from here.
* app/tools/gimpaligntool.c: fix includes and remove
unneeded includes.
2005-06-03 Michael Natterer <mitch@gimp.org>
* app/widgets/gimpcolorframe.c (gimp_color_frame_init): pack the
......
......@@ -170,6 +170,8 @@ libappcore_a_sources = \
gimpinterpreterdb.h \
gimpitem.c \
gimpitem.h \
gimpitem-align.c \
gimpitem-align.h \
gimpitem-linked.c \
gimpitem-linked.h \
gimpitem-preview.c \
......
/* 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..
* @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);
}
/* 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_ITEM_ALIGN_H__
#define __GIMP_ITEM_ALIGN_H__
void gimp_item_align (GimpItem *target,
GimpAlignmentType target_alignment,
GimpItem *refeence,
GimpAlignmentType reference_alignment,
gint offset,
gboolean push_undo);
#endif /* __GIMP_ITEM_ALIGN_H__ */
......@@ -1250,131 +1250,3 @@ 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,12 +253,5 @@ 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__ */
......@@ -24,21 +24,13 @@
#include "tools-types.h"
#include "config/gimpdisplayconfig.h"
#include "config/gimpguiconfig.h"
#include "core/gimp.h"
#include "core/gimpimage.h"
#include "core/gimplayer.h"
#include "core/gimplayermask.h"
#include "core/gimplayer-floating-sel.h"
#include "core/gimptoolinfo.h"
#include "core/gimpitem-align.h"
#include "display/gimpdisplay.h"
#include "display/gimpdisplayshell.h"
#include "display/gimpdisplayshell-appearance.h"
#include "display/gimpdisplayshell-draw.h"
#include "display/gimpdisplayshell-transform.h"
#include "widgets/gimphelp-ids.h"
......
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