[gimp] app: finally get rid of gimp_item_configure() and drawable_configure()



commit eacd80446d68b40e40f2e36d052ab74abf7aacb8
Author: Michael Natterer <mitch gimp org>
Date:   Tue Feb 1 12:47:24 2011 +0100

    app: finally get rid of gimp_item_configure() and drawable_configure()
    
    and turn them into gimp_item_new() and gimp_drawable_new()

 app/core/gimpchannel.c    |   11 ++---
 app/core/gimpdrawable.c   |   62 +++++++++++-------------
 app/core/gimpdrawable.h   |   15 +++---
 app/core/gimpgrouplayer.c |   13 ++---
 app/core/gimpitem.c       |  114 ++++++++++++++++++++++-----------------------
 app/core/gimpitem.h       |   14 +++--
 app/core/gimplayer.c      |   12 ++---
 app/core/gimplayermask.c  |   18 ++++---
 app/core/gimpselection.c  |   13 ++---
 app/text/gimptextlayer.c  |   13 ++---
 app/vectors/gimpvectors.c |   14 ++----
 11 files changed, 140 insertions(+), 159 deletions(-)
---
diff --git a/app/core/gimpchannel.c b/app/core/gimpchannel.c
index 4d4a0a1..a1a9ab8 100644
--- a/app/core/gimpchannel.c
+++ b/app/core/gimpchannel.c
@@ -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;
diff --git a/app/core/gimpdrawable.c b/app/core/gimpdrawable.c
index 354370e..e27448d 100644
--- a/app/core/gimpdrawable.c
+++ b/app/core/gimpdrawable.c
@@ -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,
@@ -1189,39 +1218,6 @@ gimp_drawable_estimate_memsize (const GimpDrawable *drawable,
 }
 
 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,
                       gint          y,
diff --git a/app/core/gimpdrawable.h b/app/core/gimpdrawable.h
index a42203f..15531f2 100644
--- a/app/core/gimpdrawable.h
+++ b/app/core/gimpdrawable.h
@@ -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,
diff --git a/app/core/gimpgrouplayer.c b/app/core/gimpgrouplayer.c
index da78bf0..6c6e5a2 100644
--- a/app/core/gimpgrouplayer.c
+++ b/app/core/gimpgrouplayer.c
@@ -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;
diff --git a/app/core/gimpitem.c b/app/core/gimpitem.c
index 68b1469..c86f1b0 100644
--- a/app/core/gimpitem.c
+++ b/app/core/gimpitem.c
@@ -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.
@@ -699,56 +745,6 @@ gimp_item_unset_removed (GimpItem *item)
 }
 
 /**
- * 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.
  *
diff --git a/app/core/gimpitem.h b/app/core/gimpitem.h
index ba0d7ae..402758f 100644
--- a/app/core/gimpitem.h
+++ b/app/core/gimpitem.h
@@ -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,
diff --git a/app/core/gimplayer.c b/app/core/gimplayer.c
index b7509cb..b27381d 100644
--- a/app/core/gimplayer.c
+++ b/app/core/gimplayer.c
@@ -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);
 
diff --git a/app/core/gimplayermask.c b/app/core/gimplayermask.c
index 7f7e420..59bd341 100644
--- a/app/core/gimplayermask.c
+++ b/app/core/gimplayermask.c
@@ -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;
 }
diff --git a/app/core/gimpselection.c b/app/core/gimpselection.c
index 6792610..d883497 100644
--- a/app/core/gimpselection.c
+++ b/app/core/gimpselection.c
@@ -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);
diff --git a/app/text/gimptextlayer.c b/app/text/gimptextlayer.c
index a54b54a..2c97ed1 100644
--- a/app/text/gimptextlayer.c
+++ b/app/text/gimptextlayer.c
@@ -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);
 
diff --git a/app/vectors/gimpvectors.c b/app/vectors/gimpvectors.c
index 0b08688..205f365 100644
--- a/app/vectors/gimpvectors.c
+++ b/app/vectors/gimpvectors.c
@@ -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;
 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]