app: add virtual function GimpItem::bounds()
Which returns a boolean indicating if there is content at all, and the bounds as double x, y, width, height because for most use cases that's better than x1, y1, x2, y2. Wrap the method with two functions gimp_item_bounds() which returns integer bounds and gimp_item_bounds_f() which returns the original double bounds.
This commit is contained in:
@ -77,6 +77,11 @@ static GeglNode * gimp_channel_get_node (GimpFilter *filter);
|
||||
|
||||
static gboolean gimp_channel_is_attached (const GimpItem *item);
|
||||
static GimpItemTree * gimp_channel_get_tree (GimpItem *item);
|
||||
static gboolean gimp_channel_item_bounds (GimpItem *item,
|
||||
gdouble *x,
|
||||
gdouble *y,
|
||||
gdouble *width,
|
||||
gdouble *height);
|
||||
static GimpItem * gimp_channel_duplicate (GimpItem *item,
|
||||
GType new_type);
|
||||
static void gimp_channel_convert (GimpItem *item,
|
||||
@ -262,6 +267,7 @@ gimp_channel_class_init (GimpChannelClass *klass)
|
||||
|
||||
item_class->is_attached = gimp_channel_is_attached;
|
||||
item_class->get_tree = gimp_channel_get_tree;
|
||||
item_class->bounds = gimp_channel_item_bounds;
|
||||
item_class->duplicate = gimp_channel_duplicate;
|
||||
item_class->convert = gimp_channel_convert;
|
||||
item_class->translate = gimp_channel_translate;
|
||||
@ -481,6 +487,26 @@ gimp_channel_get_tree (GimpItem *item)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gimp_channel_item_bounds (GimpItem *item,
|
||||
gdouble *x,
|
||||
gdouble *y,
|
||||
gdouble *width,
|
||||
gdouble *height)
|
||||
{
|
||||
gint x1, y1, x2, y2;
|
||||
gdouble retval;
|
||||
|
||||
retval = gimp_channel_bounds (GIMP_CHANNEL (item), &x1, &y1, &x2, &y2);
|
||||
|
||||
*x = x1;
|
||||
*y = y1;
|
||||
*width = x2 - x1;
|
||||
*height = y2 - y1;
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
static GimpItem *
|
||||
gimp_channel_duplicate (GimpItem *item,
|
||||
GType new_type)
|
||||
|
||||
@ -125,6 +125,11 @@ static void gimp_item_real_visibility_changed (GimpItem *item);
|
||||
|
||||
static gboolean gimp_item_real_is_content_locked (const GimpItem *item);
|
||||
static gboolean gimp_item_real_is_position_locked (const GimpItem *item);
|
||||
static gboolean gimp_item_real_bounds (GimpItem *item,
|
||||
gdouble *x,
|
||||
gdouble *y,
|
||||
gdouble *width,
|
||||
gdouble *height);
|
||||
static GimpItem * gimp_item_real_duplicate (GimpItem *item,
|
||||
GType new_type);
|
||||
static void gimp_item_real_convert (GimpItem *item,
|
||||
@ -232,6 +237,7 @@ gimp_item_class_init (GimpItemClass *klass)
|
||||
klass->is_content_locked = gimp_item_real_is_content_locked;
|
||||
klass->is_position_locked = gimp_item_real_is_position_locked;
|
||||
klass->get_tree = NULL;
|
||||
klass->bounds = gimp_item_real_bounds;
|
||||
klass->duplicate = gimp_item_real_duplicate;
|
||||
klass->convert = gimp_item_real_convert;
|
||||
klass->rename = gimp_item_real_rename;
|
||||
@ -494,6 +500,23 @@ gimp_item_real_is_position_locked (const GimpItem *item)
|
||||
return GET_PRIVATE (item)->lock_position;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gimp_item_real_bounds (GimpItem *item,
|
||||
gdouble *x,
|
||||
gdouble *y,
|
||||
gdouble *width,
|
||||
gdouble *height)
|
||||
{
|
||||
GimpItemPrivate *private = GET_PRIVATE (item);
|
||||
|
||||
*x = 0;
|
||||
*y = 0;
|
||||
*width = private->width;
|
||||
*height = private->height;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static GimpItem *
|
||||
gimp_item_real_duplicate (GimpItem *item,
|
||||
GType new_type)
|
||||
@ -882,6 +905,54 @@ gimp_item_get_path (GimpItem *item)
|
||||
return path;
|
||||
}
|
||||
|
||||
gboolean
|
||||
gimp_item_bounds (GimpItem *item,
|
||||
gint *x,
|
||||
gint *y,
|
||||
gint *width,
|
||||
gint *height)
|
||||
{
|
||||
gdouble tmp_x, tmp_y, tmp_width, tmp_height;
|
||||
gboolean retval;
|
||||
|
||||
g_return_val_if_fail (GIMP_IS_ITEM (item), FALSE);
|
||||
|
||||
retval = GIMP_ITEM_GET_CLASS (item)->bounds (item,
|
||||
&tmp_x, &tmp_y,
|
||||
&tmp_width, &tmp_height);
|
||||
|
||||
if (x) *x = floor (tmp_x);
|
||||
if (y) *y = floor (tmp_y);
|
||||
if (width) *width = ceil (tmp_x + tmp_width) - floor (tmp_x);
|
||||
if (height) *height = ceil (tmp_y + tmp_height) - floor (tmp_y);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
gboolean
|
||||
gimp_item_bounds_f (GimpItem *item,
|
||||
gdouble *x,
|
||||
gdouble *y,
|
||||
gdouble *width,
|
||||
gdouble *height)
|
||||
{
|
||||
gdouble tmp_x, tmp_y, tmp_width, tmp_height;
|
||||
gboolean retval;
|
||||
|
||||
g_return_val_if_fail (GIMP_IS_ITEM (item), FALSE);
|
||||
|
||||
retval = GIMP_ITEM_GET_CLASS (item)->bounds (item,
|
||||
&tmp_x, &tmp_y,
|
||||
&tmp_width, &tmp_height);
|
||||
|
||||
if (x) *x = tmp_x;
|
||||
if (y) *y = tmp_y;
|
||||
if (width) *width = tmp_width;
|
||||
if (height) *height = tmp_height;
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
/**
|
||||
* gimp_item_duplicate:
|
||||
* @item: The #GimpItem to duplicate.
|
||||
|
||||
@ -54,6 +54,11 @@ struct _GimpItemClass
|
||||
gboolean (* is_content_locked) (const GimpItem *item);
|
||||
gboolean (* is_position_locked) (const GimpItem *item);
|
||||
GimpItemTree * (* get_tree) (GimpItem *item);
|
||||
gboolean (* bounds) (GimpItem *item,
|
||||
gdouble *x,
|
||||
gdouble *y,
|
||||
gdouble *width,
|
||||
gdouble *height);
|
||||
GimpItem * (* duplicate) (GimpItem *item,
|
||||
GType new_type);
|
||||
void (* convert) (GimpItem *item,
|
||||
@ -156,6 +161,17 @@ GList * gimp_item_get_container_iter (GimpItem *item);
|
||||
gint gimp_item_get_index (GimpItem *item);
|
||||
GList * gimp_item_get_path (GimpItem *item);
|
||||
|
||||
gboolean gimp_item_bounds (GimpItem *item,
|
||||
gint *x,
|
||||
gint *y,
|
||||
gint *width,
|
||||
gint *height);
|
||||
gboolean gimp_item_bounds_f (GimpItem *item,
|
||||
gdouble *x,
|
||||
gdouble *y,
|
||||
gdouble *width,
|
||||
gdouble *height);
|
||||
|
||||
GimpItem * gimp_item_duplicate (GimpItem *item,
|
||||
GType new_type);
|
||||
GimpItem * gimp_item_convert (GimpItem *item,
|
||||
|
||||
@ -69,6 +69,11 @@ static gint64 gimp_vectors_get_memsize (GimpObject *object,
|
||||
|
||||
static gboolean gimp_vectors_is_attached (const GimpItem *item);
|
||||
static GimpItemTree * gimp_vectors_get_tree (GimpItem *item);
|
||||
static gboolean gimp_vectors_item_bounds (GimpItem *item,
|
||||
gdouble *x,
|
||||
gdouble *y,
|
||||
gdouble *width,
|
||||
gdouble *height);
|
||||
static GimpItem * gimp_vectors_duplicate (GimpItem *item,
|
||||
GType new_type);
|
||||
static void gimp_vectors_convert (GimpItem *item,
|
||||
@ -194,6 +199,7 @@ gimp_vectors_class_init (GimpVectorsClass *klass)
|
||||
|
||||
item_class->is_attached = gimp_vectors_is_attached;
|
||||
item_class->get_tree = gimp_vectors_get_tree;
|
||||
item_class->bounds = gimp_vectors_item_bounds;
|
||||
item_class->duplicate = gimp_vectors_duplicate;
|
||||
item_class->convert = gimp_vectors_convert;
|
||||
item_class->translate = gimp_vectors_translate;
|
||||
@ -316,6 +322,26 @@ gimp_vectors_get_tree (GimpItem *item)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gimp_vectors_item_bounds (GimpItem *item,
|
||||
gdouble *x,
|
||||
gdouble *y,
|
||||
gdouble *width,
|
||||
gdouble *height)
|
||||
{
|
||||
gdouble x1, y1, x2, y2;
|
||||
gdouble retval;
|
||||
|
||||
retval = gimp_vectors_bounds (GIMP_VECTORS (item), &x1, &y1, &x2, &y2);
|
||||
|
||||
*x = x1;
|
||||
*y = y1;
|
||||
*width = x2 - x1;
|
||||
*height = y2 - y1;
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
static GimpItem *
|
||||
gimp_vectors_duplicate (GimpItem *item,
|
||||
GType new_type)
|
||||
|
||||
Reference in New Issue
Block a user