2006-12-09 21:33:38 +00:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
1997-11-24 22:05:25 +00:00
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
2009-01-17 22:28:01 +00:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
1997-11-24 22:05:25 +00:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-17 22:28:01 +00:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
1997-11-24 22:05:25 +00:00
|
|
|
* (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
|
2018-07-11 23:27:07 +02:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
1997-11-24 22:05:25 +00:00
|
|
|
*/
|
2000-12-16 21:37:03 +00:00
|
|
|
|
2000-02-16 20:44:39 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
1997-11-24 22:05:25 +00:00
|
|
|
#include <string.h>
|
2000-01-14 12:41:00 +00:00
|
|
|
|
2011-04-28 15:50:39 +02:00
|
|
|
#include <cairo.h>
|
2008-10-09 20:24:04 +00:00
|
|
|
#include <gegl.h>
|
2012-05-03 03:36:22 +02:00
|
|
|
#include <gdk-pixbuf/gdk-pixbuf.h>
|
2000-12-16 21:37:03 +00:00
|
|
|
|
2001-05-09 22:34:59 +00:00
|
|
|
#include "core-types.h"
|
2000-12-16 21:37:03 +00:00
|
|
|
|
2001-07-07 12:17:23 +00:00
|
|
|
#include "gimp.h"
|
2001-02-01 18:44:22 +00:00
|
|
|
#include "gimpcontext.h"
|
2001-05-09 02:32:03 +00:00
|
|
|
#include "gimpdrawable.h"
|
2001-04-18 19:14:20 +00:00
|
|
|
#include "gimpdrawable-offset.h"
|
2019-06-05 18:01:18 -04:00
|
|
|
#include "gimpdrawable-operation.h"
|
1997-11-24 22:05:25 +00:00
|
|
|
|
2003-03-25 16:38:19 +00:00
|
|
|
#include "gimp-intl.h"
|
2003-02-14 14:14:29 +00:00
|
|
|
|
1997-11-24 22:05:25 +00:00
|
|
|
|
|
|
|
void
|
2001-04-18 20:41:15 +00:00
|
|
|
gimp_drawable_offset (GimpDrawable *drawable,
|
2004-04-14 23:37:34 +00:00
|
|
|
GimpContext *context,
|
2006-04-12 12:49:29 +00:00
|
|
|
gboolean wrap_around,
|
|
|
|
GimpOffsetType fill_type,
|
2024-11-08 05:37:19 +00:00
|
|
|
GeglColor *color,
|
2006-04-12 12:49:29 +00:00
|
|
|
gint offset_x,
|
|
|
|
gint offset_y)
|
1997-11-24 22:05:25 +00:00
|
|
|
{
|
2019-06-05 18:01:18 -04:00
|
|
|
GeglNode *node;
|
2019-06-06 02:20:27 -04:00
|
|
|
gint width;
|
|
|
|
gint height;
|
1997-11-24 22:05:25 +00:00
|
|
|
|
2003-05-08 13:12:46 +00:00
|
|
|
g_return_if_fail (GIMP_IS_DRAWABLE (drawable));
|
2004-04-14 23:37:34 +00:00
|
|
|
g_return_if_fail (GIMP_IS_CONTEXT (context));
|
2003-05-08 13:12:46 +00:00
|
|
|
|
2019-06-06 02:20:27 -04:00
|
|
|
if (! gimp_item_mask_intersect (GIMP_ITEM (drawable),
|
|
|
|
NULL, NULL, &width, &height))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-03-15 00:03:07 +01:00
|
|
|
if (wrap_around)
|
2019-06-05 18:01:18 -04:00
|
|
|
fill_type = GIMP_OFFSET_WRAP_AROUND;
|
2012-03-15 00:03:07 +01:00
|
|
|
|
2019-06-06 02:20:27 -04:00
|
|
|
if (fill_type == GIMP_OFFSET_WRAP_AROUND)
|
|
|
|
{
|
|
|
|
offset_x %= width;
|
|
|
|
offset_y %= height;
|
|
|
|
}
|
|
|
|
|
2019-07-11 11:52:17 +02:00
|
|
|
if (offset_x == 0 && offset_y == 0)
|
2019-06-06 02:20:27 -04:00
|
|
|
return;
|
|
|
|
|
2019-06-05 18:01:18 -04:00
|
|
|
node = gegl_node_new_child (NULL,
|
|
|
|
"operation", "gimp:offset",
|
2024-11-08 05:37:19 +00:00
|
|
|
"type", fill_type,
|
|
|
|
"x", offset_x,
|
|
|
|
"y", offset_y,
|
2019-06-05 18:01:18 -04:00
|
|
|
NULL);
|
2006-04-12 12:49:29 +00:00
|
|
|
|
2024-11-08 05:37:19 +00:00
|
|
|
if (color == NULL)
|
|
|
|
{
|
|
|
|
color = gegl_color_duplicate (gimp_context_get_background (context));
|
|
|
|
gegl_node_set (node, "color", color, NULL);
|
|
|
|
g_object_unref (color);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gegl_node_set (node, "color", color, NULL);
|
|
|
|
}
|
|
|
|
|
2019-06-05 18:01:18 -04:00
|
|
|
gimp_drawable_apply_operation (drawable, NULL,
|
|
|
|
C_("undo-type", "Offset Drawable"),
|
|
|
|
node);
|
1997-11-24 22:05:25 +00:00
|
|
|
|
2019-06-05 18:01:18 -04:00
|
|
|
g_object_unref (node);
|
1997-11-24 22:05:25 +00:00
|
|
|
}
|