Commit 7256f184 authored by Michael Natterer's avatar Michael Natterer 😴

app: change offsets parameters of GimpItem::translate() from int to double

so we can use it to precisely position paths; use SIGNED_ROUND() in
channel, layer etc. to snap to pixels.
parent b1a36b04
......@@ -23,6 +23,7 @@
#include <gegl.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include "libgimpbase/gimpbase.h"
#include "libgimpmath/gimpmath.h"
#include "libgimpcolor/gimpcolor.h"
......@@ -89,8 +90,8 @@ static void gimp_channel_convert (GimpItem *item,
GimpImage *dest_image,
GType old_type);
static void gimp_channel_translate (GimpItem *item,
gint off_x,
gint off_y,
gdouble off_x,
gdouble off_y,
gboolean push_undo);
static void gimp_channel_scale (GimpItem *item,
gint new_width,
......@@ -634,82 +635,73 @@ gimp_channel_convert (GimpItem *item,
static void
gimp_channel_translate (GimpItem *item,
gint off_x,
gint off_y,
gdouble off_x,
gdouble off_y,
gboolean push_undo)
{
GimpChannel *channel = GIMP_CHANNEL (item);
GeglBuffer *tmp_buffer = NULL;
gint width, height;
gint x1, y1, x2, y2;
GimpChannel *channel = GIMP_CHANNEL (item);
gint x, y, width, height;
gimp_item_bounds (GIMP_ITEM (channel), &x1, &y1, &x2, &y2);
x2 += x1;
y2 += y1;
gimp_item_bounds (GIMP_ITEM (channel), &x, &y, &width, &height);
/* update the old area */
gimp_drawable_update (GIMP_DRAWABLE (item), x1, y1, x2 - x1, y2 - y1);
gimp_drawable_update (GIMP_DRAWABLE (item), x, y, width, height);
if (push_undo)
gimp_channel_push_undo (channel, NULL);
x1 = CLAMP ((x1 + off_x), 0, gimp_item_get_width (GIMP_ITEM (channel)));
y1 = CLAMP ((y1 + off_y), 0, gimp_item_get_height (GIMP_ITEM (channel)));
x2 = CLAMP ((x2 + off_x), 0, gimp_item_get_width (GIMP_ITEM (channel)));
y2 = CLAMP ((y2 + off_y), 0, gimp_item_get_height (GIMP_ITEM (channel)));
width = x2 - x1;
height = y2 - y1;
/* make sure width and height are non-zero */
if (width != 0 && height != 0)
if (gimp_rectangle_intersect (x + SIGNED_ROUND (off_x),
y + SIGNED_ROUND (off_y),
width, height,
0, 0,
gimp_item_get_width (GIMP_ITEM (channel)),
gimp_item_get_height (GIMP_ITEM (channel)),
&x, &y, &width, &height))
{
/* copy the portion of the mask we will keep to a temporary
* buffer
*/
tmp_buffer =
GeglBuffer *tmp_buffer =
gegl_buffer_new (GEGL_RECTANGLE (0, 0, width, height),
gimp_drawable_get_format (GIMP_DRAWABLE (channel)));
gegl_buffer_copy (gimp_drawable_get_buffer (GIMP_DRAWABLE (channel)),
GEGL_RECTANGLE (x1 - off_x, y1 - off_y, width, height),
GEGL_RECTANGLE (x - SIGNED_ROUND (off_x),
y - SIGNED_ROUND (off_y),
width, height),
GEGL_ABYSS_NONE,
tmp_buffer,
GEGL_RECTANGLE (0, 0, 0, 0));
}
/* clear the mask */
gegl_buffer_clear (gimp_drawable_get_buffer (GIMP_DRAWABLE (channel)),
NULL);
/* clear the mask */
gegl_buffer_clear (gimp_drawable_get_buffer (GIMP_DRAWABLE (channel)),
NULL);
if (width != 0 && height != 0)
{
/* copy the temp mask back to the mask */
gegl_buffer_copy (tmp_buffer, NULL, GEGL_ABYSS_NONE,
gimp_drawable_get_buffer (GIMP_DRAWABLE (channel)),
GEGL_RECTANGLE (x1, y1, 0, 0));
GEGL_RECTANGLE (x, y, 0, 0));
/* free the temporary mask */
g_object_unref (tmp_buffer);
}
/* calculate new bounds */
if (width == 0 || height == 0)
channel->x1 = x;
channel->y1 = y;
channel->x2 = x + width;
channel->y2 = y + height;
}
else
{
/* clear the mask */
gegl_buffer_clear (gimp_drawable_get_buffer (GIMP_DRAWABLE (channel)),
NULL);
channel->empty = TRUE;
channel->x1 = 0;
channel->y1 = 0;
channel->x2 = gimp_item_get_width (GIMP_ITEM (channel));
channel->y2 = gimp_item_get_height (GIMP_ITEM (channel));
}
else
{
channel->x1 = x1;
channel->y1 = y1;
channel->x2 = x2;
channel->y2 = y2;
}
/* update the new area */
gimp_drawable_update (GIMP_DRAWABLE (item),
......
......@@ -148,8 +148,8 @@ static void gimp_item_real_start_transform (GimpItem *item,
static void gimp_item_real_end_transform (GimpItem *item,
gboolean push_undo);
static void gimp_item_real_translate (GimpItem *item,
gint offset_x,
gint offset_y,
gdouble offset_x,
gdouble offset_y,
gboolean push_undo);
static void gimp_item_real_scale (GimpItem *item,
gint new_width,
......@@ -612,15 +612,15 @@ gimp_item_real_rename (GimpItem *item,
static void
gimp_item_real_translate (GimpItem *item,
gint offset_x,
gint offset_y,
gdouble offset_x,
gdouble offset_y,
gboolean push_undo)
{
GimpItemPrivate *private = GET_PRIVATE (item);
gimp_item_set_offset (item,
private->offset_x + offset_x,
private->offset_y + offset_y);
private->offset_x + SIGNED_ROUND (offset_x),
private->offset_y + SIGNED_ROUND (offset_y));
}
static void
......@@ -1256,8 +1256,8 @@ gimp_item_end_transform (GimpItem *item,
*/
void
gimp_item_translate (GimpItem *item,
gint offset_x,
gint offset_y,
gdouble offset_x,
gdouble offset_y,
gboolean push_undo)
{
GimpItemClass *item_class;
......
......@@ -78,8 +78,8 @@ struct _GimpItemClass
void (* end_transform) (GimpItem *item,
gboolean push_undo);
void (* translate) (GimpItem *item,
gint offset_x,
gint offset_y,
gdouble offset_x,
gdouble offset_y,
gboolean push_undo);
void (* scale) (GimpItem *item,
gint new_width,
......@@ -226,8 +226,8 @@ void gimp_item_end_transform (GimpItem *item,
gboolean push_undo);
void gimp_item_translate (GimpItem *item,
gint offset_x,
gint offset_y,
gdouble offset_x,
gdouble offset_y,
gboolean push_undo);
gboolean gimp_item_check_scaling (GimpItem *item,
......
......@@ -136,8 +136,8 @@ static void gimp_layer_start_move (GimpItem *item,
static void gimp_layer_end_move (GimpItem *item,
gboolean push_undo);
static void gimp_layer_translate (GimpItem *item,
gint offset_x,
gint offset_y,
gdouble offset_x,
gdouble offset_y,
gboolean push_undo);
static void gimp_layer_scale (GimpItem *item,
gint new_width,
......@@ -1119,8 +1119,8 @@ gimp_layer_end_move (GimpItem *item,
static void
gimp_layer_translate (GimpItem *item,
gint offset_x,
gint offset_y,
gdouble offset_x,
gdouble offset_y,
gboolean push_undo)
{
GimpLayer *layer = GIMP_LAYER (item);
......@@ -1128,7 +1128,9 @@ gimp_layer_translate (GimpItem *item,
if (push_undo)
gimp_image_undo_push_item_displace (gimp_item_get_image (item), NULL, item);
GIMP_LAYER_GET_CLASS (layer)->translate (layer, offset_x, offset_y);
GIMP_LAYER_GET_CLASS (layer)->translate (layer,
SIGNED_ROUND (offset_x),
SIGNED_ROUND (offset_y));
if (layer->mask)
{
......
......@@ -49,8 +49,8 @@
static gboolean gimp_selection_is_attached (GimpItem *item);
static GimpItemTree * gimp_selection_get_tree (GimpItem *item);
static void gimp_selection_translate (GimpItem *item,
gint offset_x,
gint offset_y,
gdouble offset_x,
gdouble offset_y,
gboolean push_undo);
static void gimp_selection_scale (GimpItem *item,
gint new_width,
......@@ -217,8 +217,8 @@ gimp_selection_get_tree (GimpItem *item)
static void
gimp_selection_translate (GimpItem *item,
gint offset_x,
gint offset_y,
gdouble offset_x,
gdouble offset_y,
gboolean push_undo)
{
GIMP_ITEM_CLASS (parent_class)->translate (item, offset_x, offset_y,
......
......@@ -81,8 +81,8 @@ static void gimp_vectors_convert (GimpItem *item,
GimpImage *dest_image,
GType old_type);
static void gimp_vectors_translate (GimpItem *item,
gint offset_x,
gint offset_y,
gdouble offset_x,
gdouble offset_y,
gboolean push_undo);
static void gimp_vectors_scale (GimpItem *item,
gint new_width,
......@@ -441,8 +441,8 @@ gimp_vectors_convert (GimpItem *item,
static void
gimp_vectors_translate (GimpItem *item,
gint offset_x,
gint offset_y,
gdouble offset_x,
gdouble offset_y,
gboolean push_undo)
{
GimpVectors *vectors = GIMP_VECTORS (item);
......
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