app: finally get rid of gimp_item_configure() and drawable_configure()

and turn them into gimp_item_new() and gimp_drawable_new()
This commit is contained in:
Michael Natterer 2011-02-01 12:47:24 +01:00
parent ccd3beb8ff
commit eacd80446d
11 changed files with 140 additions and 159 deletions

View File

@ -1630,13 +1630,10 @@ gimp_channel_new (GimpImage *image,
g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
channel = g_object_new (GIMP_TYPE_CHANNEL,
"image", image,
NULL);
gimp_drawable_configure (GIMP_DRAWABLE (channel),
0, 0, width, height,
GIMP_GRAY_IMAGE, name);
channel = GIMP_CHANNEL (gimp_drawable_new (GIMP_TYPE_CHANNEL,
image, name,
0, 0, width, height,
GIMP_GRAY_IMAGE));
if (color)
channel->color = *color;

View File

@ -1177,6 +1177,35 @@ gimp_drawable_fs_update (GimpLayer *fs,
/* public functions */
GimpDrawable *
gimp_drawable_new (GType type,
GimpImage *image,
const gchar *name,
gint offset_x,
gint offset_y,
gint width,
gint height,
GimpImageType image_type)
{
GimpDrawable *drawable;
g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
g_return_val_if_fail (g_type_is_a (type, GIMP_TYPE_DRAWABLE), NULL);
g_return_val_if_fail (width > 0 && height > 0, NULL);
drawable = GIMP_DRAWABLE (gimp_item_new (type,
image, name,
offset_x, offset_y,
width, height));
drawable->type = image_type;
drawable->bytes = GIMP_IMAGE_TYPE_BYTES (image_type);
drawable->private->tiles = tile_manager_new (width, height, drawable->bytes);
return drawable;
}
gint64
gimp_drawable_estimate_memsize (const GimpDrawable *drawable,
gint width,
@ -1188,39 +1217,6 @@ gimp_drawable_estimate_memsize (const GimpDrawable *drawable,
width, height);
}
void
gimp_drawable_configure (GimpDrawable *drawable,
gint offset_x,
gint offset_y,
gint width,
gint height,
GimpImageType type,
const gchar *name)
{
g_return_if_fail (GIMP_IS_DRAWABLE (drawable));
g_return_if_fail (width > 0 && height > 0);
gimp_item_configure (GIMP_ITEM (drawable),
offset_x, offset_y, width, height, name);
drawable->type = type;
drawable->bytes = GIMP_IMAGE_TYPE_BYTES (type);
if (drawable->private->tiles)
tile_manager_unref (drawable->private->tiles);
drawable->private->tiles = tile_manager_new (width, height, drawable->bytes);
/* preview variables */
drawable->private->preview_cache = NULL;
drawable->private->preview_valid = FALSE;
if (drawable->private->tile_source_node)
gegl_node_set (drawable->private->tile_source_node,
"tile-manager", gimp_drawable_get_tiles (drawable),
NULL);
}
void
gimp_drawable_update (GimpDrawable *drawable,
gint x,

View File

@ -119,17 +119,18 @@ struct _GimpDrawableClass
GType gimp_drawable_get_type (void) G_GNUC_CONST;
gint64 gimp_drawable_estimate_memsize (const GimpDrawable *drawable,
gint width,
gint height);
void gimp_drawable_configure (GimpDrawable *drawable,
GimpDrawable * gimp_drawable_new (GType type,
GimpImage *image,
const gchar *name,
gint offset_x,
gint offset_y,
gint width,
gint height,
GimpImageType type,
const gchar *name);
GimpImageType image_type);
gint64 gimp_drawable_estimate_memsize (const GimpDrawable *drawable,
gint width,
gint height);
void gimp_drawable_update (GimpDrawable *drawable,
gint x,

View File

@ -825,17 +825,16 @@ GimpLayer *
gimp_group_layer_new (GimpImage *image)
{
GimpGroupLayer *group;
GimpImageType type;
g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
group = g_object_new (GIMP_TYPE_GROUP_LAYER,
"image", image,
NULL);
type = gimp_image_base_type_with_alpha (image);
gimp_drawable_configure (GIMP_DRAWABLE (group),
0, 0, 1, 1,
gimp_image_base_type_with_alpha (image),
NULL);
group = GIMP_GROUP_LAYER (gimp_drawable_new (GIMP_TYPE_GROUP_LAYER,
image, NULL,
0, 0, 1, 1,
type));
if (gimp_image_get_projection (image)->use_gegl)
group->projection->use_gegl = TRUE;

View File

@ -509,15 +509,11 @@ gimp_item_real_duplicate (GimpItem *item,
}
}
new_item = g_object_new (new_type,
"image", gimp_item_get_image (item),
NULL);
gimp_item_configure (new_item,
private->offset_x, private->offset_y,
gimp_item_get_width (item),
gimp_item_get_height (item),
new_name);
new_item = gimp_item_new (new_type,
gimp_item_get_image (item), new_name,
private->offset_x, private->offset_y,
gimp_item_get_width (item),
gimp_item_get_height (item));
g_free (new_name);
@ -642,6 +638,56 @@ gimp_item_sync_offset_node (GimpItem *item)
NULL);
}
/* public functions */
/**
* gimp_item_new:
* @type: The new item's type.
* @image: The new item's #GimpImage.
* @name: The name to assign the item.
* @offset_x: The X offset to assign the item.
* @offset_y: The Y offset to assign the item.
* @width: The width to assign the item.
* @height: The height to assign the item.
*
* Return value: The newly created item.
*/
GimpItem *
gimp_item_new (GType type,
GimpImage *image,
const gchar *name,
gint offset_x,
gint offset_y,
gint width,
gint height)
{
GimpItem *item;
GimpItemPrivate *private;
g_return_val_if_fail (g_type_is_a (type, GIMP_TYPE_ITEM), NULL);
g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
g_return_val_if_fail (width > 0 && height > 0, NULL);
item = g_object_new (type,
"image", image,
NULL);
private = GET_PRIVATE (item);
item->width = width;
item->height = height;
gimp_item_set_offset (item, offset_x, offset_y);
if (name && strlen (name))
gimp_object_set_name (GIMP_OBJECT (item), name);
else
gimp_object_set_static_name (GIMP_OBJECT (item),
GIMP_ITEM_GET_CLASS (item)->default_name);
return item;
}
/**
* gimp_item_remove:
* @item: the #GimpItem to remove.
@ -698,56 +744,6 @@ gimp_item_unset_removed (GimpItem *item)
GET_PRIVATE (item)->removed = FALSE;
}
/**
* gimp_item_configure:
* @item: The #GimpItem to configure.
* @offset_x: The X offset to assign the item.
* @offset_y: The Y offset to assign the item.
* @width: The width to assign the item.
* @height: The height to assign the item.
* @name: The name to assign the item.
*
* This function is used to configure a new item.
*/
void
gimp_item_configure (GimpItem *item,
gint offset_x,
gint offset_y,
gint width,
gint height,
const gchar *name)
{
GimpItemPrivate *private;
g_return_if_fail (GIMP_IS_ITEM (item));
private = GET_PRIVATE (item);
g_object_freeze_notify (G_OBJECT (item));
if (item->width != width)
{
item->width = width;
g_object_notify (G_OBJECT (item), "width");
}
if (item->height != height)
{
item->height = height;
g_object_notify (G_OBJECT (item), "height");
}
gimp_item_set_offset (item, offset_x, offset_y);
if (name && strlen (name))
gimp_object_set_name (GIMP_OBJECT (item), name);
else
gimp_object_set_static_name (GIMP_OBJECT (item),
GIMP_ITEM_GET_CLASS (item)->default_name);
g_object_thaw_notify (G_OBJECT (item));
}
/**
* gimp_item_is_attached:
* @item: The #GimpItem to check.

View File

@ -136,6 +136,14 @@ struct _GimpItemClass
GType gimp_item_get_type (void) G_GNUC_CONST;
GimpItem * gimp_item_new (GType type,
GimpImage *image,
const gchar *name,
gint offset_x,
gint offset_y,
gint width,
gint height);
void gimp_item_removed (GimpItem *item);
gboolean gimp_item_is_removed (const GimpItem *item);
void gimp_item_unset_removed (GimpItem *item);
@ -150,12 +158,6 @@ GList * gimp_item_get_container_iter (GimpItem *item);
gint gimp_item_get_index (GimpItem *item);
GList * gimp_item_get_path (GimpItem *item);
void gimp_item_configure (GimpItem *item,
gint offset_x,
gint offset_y,
gint width,
gint height,
const gchar *name);
GimpItem * gimp_item_duplicate (GimpItem *item,
GType new_type);
GimpItem * gimp_item_convert (GimpItem *item,

View File

@ -1116,14 +1116,10 @@ gimp_layer_new (GimpImage *image,
g_return_val_if_fail (width > 0, NULL);
g_return_val_if_fail (height > 0, NULL);
layer = g_object_new (GIMP_TYPE_LAYER,
"image", image,
NULL);
gimp_drawable_configure (GIMP_DRAWABLE (layer),
0, 0, width, height,
type,
name);
layer = GIMP_LAYER (gimp_drawable_new (GIMP_TYPE_LAYER,
image, name,
0, 0, width, height,
type));
opacity = CLAMP (opacity, GIMP_OPACITY_TRANSPARENT, GIMP_OPACITY_OPAQUE);

View File

@ -194,21 +194,23 @@ gimp_layer_mask_new (GimpImage *image,
{
GimpLayerMask *layer_mask;
layer_mask = g_object_new (GIMP_TYPE_LAYER_MASK,
"image", image,
NULL);
g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
g_return_val_if_fail (width > 0, NULL);
g_return_val_if_fail (height > 0, NULL);
g_return_val_if_fail (color != NULL, NULL);
gimp_drawable_configure (GIMP_DRAWABLE (layer_mask),
0, 0, width, height,
GIMP_GRAY_IMAGE, name);
layer_mask = GIMP_LAYER_MASK (gimp_drawable_new (GIMP_TYPE_LAYER_MASK,
image, name,
0, 0, width, height,
GIMP_GRAY_IMAGE));
/* set the layer_mask color and opacity */
gimp_channel_set_color (GIMP_CHANNEL (layer_mask), color, FALSE);
gimp_channel_set_show_masked (GIMP_CHANNEL (layer_mask), TRUE);
/* selection mask variables */
GIMP_CHANNEL (layer_mask)->x2 = width;
GIMP_CHANNEL (layer_mask)->y2 = height;
GIMP_CHANNEL (layer_mask)->x2 = width;
GIMP_CHANNEL (layer_mask)->y2 = height;
return layer_mask;
}

View File

@ -523,15 +523,12 @@ gimp_selection_new (GimpImage *image,
GimpChannel *channel;
g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
g_return_val_if_fail (width > 0 && height > 0, NULL);
channel = g_object_new (GIMP_TYPE_SELECTION,
"image", image,
NULL);
gimp_drawable_configure (GIMP_DRAWABLE (channel),
0, 0, width, height,
GIMP_GRAY_IMAGE,
NULL);
channel = GIMP_CHANNEL (gimp_drawable_new (GIMP_TYPE_SELECTION,
image, NULL,
0, 0, width, height,
GIMP_GRAY_IMAGE));
gimp_channel_set_color (channel, &black, FALSE);
gimp_channel_set_show_masked (channel, TRUE);

View File

@ -382,6 +382,7 @@ gimp_text_layer_new (GimpImage *image,
GimpText *text)
{
GimpTextLayer *layer;
GimpImageType type;
g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
g_return_val_if_fail (GIMP_IS_TEXT (text), NULL);
@ -389,14 +390,12 @@ gimp_text_layer_new (GimpImage *image,
if (! text->text && ! text->markup)
return NULL;
layer = g_object_new (GIMP_TYPE_TEXT_LAYER,
"image", image,
NULL);
type = gimp_image_base_type_with_alpha (image);
gimp_drawable_configure (GIMP_DRAWABLE (layer),
0, 0, 1, 1,
gimp_image_base_type_with_alpha (image),
NULL);
layer = GIMP_TEXT_LAYER (gimp_drawable_new (GIMP_TYPE_TEXT_LAYER,
image, NULL,
0, 0, 1, 1,
type));
gimp_text_layer_set_text (layer, text);

View File

@ -641,15 +641,11 @@ gimp_vectors_new (GimpImage *image,
g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
vectors = g_object_new (GIMP_TYPE_VECTORS,
"image", image,
NULL);
gimp_item_configure (GIMP_ITEM (vectors),
0, 0,
gimp_image_get_width (image),
gimp_image_get_height (image),
name);
vectors = GIMP_VECTORS (gimp_item_new (GIMP_TYPE_VECTORS,
image, name,
0, 0,
gimp_image_get_width (image),
gimp_image_get_height (image)));
return vectors;
}