gimp r27277 - trunk/app/core



Author: mitch
Date: Tue Oct 14 18:32:07 2008
New Revision: 27277
URL: http://svn.gnome.org/viewvc/gimp?rev=27277&view=rev

Log:
2008-10-14  Michael Natterer  <mitch gimp org>

	* app/core/gimpdrawable.[ch]: add a default implementation of
	GimpDrawable::get_node() which contains a layer mode node.
	Implement GimpItem::visibility_changed() and turn the node into a
	nop when the drawable is invisible. Added public function
	gimp_drawable_get_mode_node() so subclasses can plug stuff
	into its "aux" pad.

	* app/core/gimplayer.[ch]
	* app/core/gimpchannel.[ch]: changed accordingly (remove
	duplicated member and code that is now in GimpDrawable).



Modified:
   trunk/app/core/gimpchannel.c
   trunk/app/core/gimpchannel.h
   trunk/app/core/gimpdrawable.c
   trunk/app/core/gimpdrawable.h
   trunk/app/core/gimplayer.c
   trunk/app/core/gimplayer.h

Modified: trunk/app/core/gimpchannel.c
==============================================================================
--- trunk/app/core/gimpchannel.c	(original)
+++ trunk/app/core/gimpchannel.c	Tue Oct 14 18:32:07 2008
@@ -82,7 +82,6 @@
 static gchar  * gimp_channel_get_description (GimpViewable     *viewable,
                                               gchar           **tooltip);
 
-static void       gimp_channel_visibility_changed (GimpItem    *item);
 static gboolean   gimp_channel_is_attached   (GimpItem         *item);
 static GimpItem * gimp_channel_duplicate     (GimpItem         *item,
                                               GType             new_type);
@@ -253,7 +252,6 @@
   viewable_class->get_description  = gimp_channel_get_description;
   viewable_class->default_stock_id = "gimp-channel";
 
-  item_class->visibility_changed   = gimp_channel_visibility_changed;
   item_class->is_attached          = gimp_channel_is_attached;
   item_class->duplicate            = gimp_channel_duplicate;
   item_class->convert              = gimp_channel_convert;
@@ -336,12 +334,6 @@
 {
   GimpChannel *channel = GIMP_CHANNEL (object);
 
-  if (channel->node)
-    {
-      g_object_unref (channel->node);
-      channel->node = NULL;
-    }
-
   if (channel->segs_in)
     {
       g_free (channel->segs_in);
@@ -383,39 +375,6 @@
                                                               tooltip);
 }
 
-static void
-gimp_channel_visibility_changed (GimpItem *item)
-{
-  GimpChannel *channel = GIMP_CHANNEL (item);
-
-  if (channel->node)
-    {
-      GeglNode *input;
-      GeglNode *output;
-
-      input  = gegl_node_get_input_proxy (channel->node, "input");
-      output = gegl_node_get_output_proxy (channel->node, "output");
-
-      if (gimp_item_get_visible (item))
-        {
-          gegl_node_connect_to (input,              "output",
-                                channel->mode_node, "input");
-          gegl_node_connect_to (channel->mode_node, "output",
-                                output,             "input");
-        }
-      else
-        {
-          gegl_node_disconnect (channel->mode_node, "input");
-
-          gegl_node_connect_to (input,  "output",
-                                output, "input");
-        }
-    }
-
-  if (GIMP_ITEM_CLASS (parent_class)->visibility_changed)
-    GIMP_ITEM_CLASS (parent_class)->visibility_changed (item);
-}
-
 static gboolean
 gimp_channel_is_attached (GimpItem *item)
 {
@@ -876,22 +835,15 @@
 gimp_channel_get_node (GimpDrawable *drawable)
 {
   GimpChannel *channel = GIMP_CHANNEL (drawable);
+  GeglNode    *node;
   GeglNode    *source;
-  GeglNode    *input;
-  GeglNode    *output;
+  GeglNode    *mode_node;
   GeglColor   *color;
 
-  g_printerr ("%s 1\n", G_STRFUNC);
-
-  if (channel->node)
-    return channel->node;
-
-  g_printerr ("%s 2\n", G_STRFUNC);
-
-  channel->node = gegl_node_new ();
+  node = GIMP_DRAWABLE_CLASS (parent_class)->get_node (drawable);
 
   source = gimp_drawable_get_source_node (drawable);
-  gegl_node_add_child (channel->node, source);
+  gegl_node_add_child (node, source);
 
   color = gegl_color_new (NULL);
   gegl_color_set_rgba (color,
@@ -900,20 +852,20 @@
                        channel->color.b,
                        channel->color.a);
 
-  channel->color_node = gegl_node_new_child (channel->node,
+  channel->color_node = gegl_node_new_child (node,
                                              "operation", "color",
                                              "value",     color,
                                              NULL);
 
   g_object_unref (color);
 
-  channel->mask_node = gegl_node_new_child (channel->node,
+  channel->mask_node = gegl_node_new_child (node,
                                             "operation", "opacity",
                                             NULL);
   gegl_node_connect_to (channel->color_node, "output",
                         channel->mask_node,  "input");
 
-  channel->invert_node = gegl_node_new_child (channel->node,
+  channel->invert_node = gegl_node_new_child (node,
                                               "operation", "invert",
                                               NULL);
 
@@ -930,29 +882,12 @@
                             channel->mask_node, "aux");
     }
 
-  channel->mode_node = gegl_node_new_child (channel->node,
-                                            "operation", "normal",
-                                            NULL);
-  gegl_node_connect_to (channel->mask_node, "output",
-                        channel->mode_node, "aux");
-
-  input  = gegl_node_get_input_proxy (channel->node, "input");
-  output = gegl_node_get_output_proxy (channel->node, "output");
+  mode_node = gimp_drawable_get_mode_node (drawable);
 
-  if (gimp_item_get_visible (GIMP_ITEM (channel)))
-    {
-      gegl_node_connect_to (input,              "output",
-                            channel->mode_node, "input");
-      gegl_node_connect_to (channel->mode_node, "output",
-                            output,             "input");
-    }
-  else
-    {
-      gegl_node_connect_to (input,  "output",
-                            output, "input");
-    }
+  gegl_node_connect_to (channel->mask_node, "output",
+                        mode_node,          "aux");
 
-  return channel->node;
+  return node;
 }
 
 static void

Modified: trunk/app/core/gimpchannel.h
==============================================================================
--- trunk/app/core/gimpchannel.h	(original)
+++ trunk/app/core/gimpchannel.h	Tue Oct 14 18:32:07 2008
@@ -40,11 +40,9 @@
   gboolean      show_masked;       /*  Show masked areas--as          */
                                    /*  opposed to selected areas      */
 
-  GeglNode     *node;
   GeglNode     *color_node;
   GeglNode     *invert_node;
   GeglNode     *mask_node;
-  GeglNode     *mode_node;
 
   /*  Selection mask variables  */
   gboolean      boundary_known;    /*  is the current boundary valid  */

Modified: trunk/app/core/gimpdrawable.c
==============================================================================
--- trunk/app/core/gimpdrawable.c	(original)
+++ trunk/app/core/gimpdrawable.c	Tue Oct 14 18:32:07 2008
@@ -76,6 +76,7 @@
 static void       gimp_drawable_invalidate_preview (GimpViewable      *viewable);
 
 static void       gimp_drawable_removed            (GimpItem          *item);
+static void       gimp_drawable_visibility_changed (GimpItem          *item);
 static GimpItem * gimp_drawable_duplicate          (GimpItem          *item,
                                                     GType              new_type);
 static void       gimp_drawable_translate          (GimpItem          *item,
@@ -137,6 +138,7 @@
                                                     GimpImageType      type,
                                                     gint               offset_x,
                                                     gint               offset_y);
+static GeglNode * gimp_drawable_real_get_node      (GimpDrawable      *drawable);
 
 static void       gimp_drawable_real_push_undo     (GimpDrawable      *drawable,
                                                     const gchar       *undo_desc,
@@ -203,6 +205,7 @@
   viewable_class->get_preview        = gimp_drawable_get_preview;
 
   item_class->removed                = gimp_drawable_removed;
+  item_class->visibility_changed     = gimp_drawable_visibility_changed;
   item_class->duplicate              = gimp_drawable_duplicate;
   item_class->translate              = gimp_drawable_translate;
   item_class->scale                  = gimp_drawable_scale;
@@ -220,7 +223,7 @@
   klass->replace_region              = gimp_drawable_real_replace_region;
   klass->get_tiles                   = gimp_drawable_real_get_tiles;
   klass->set_tiles                   = gimp_drawable_real_set_tiles;
-  klass->get_node                    = NULL;
+  klass->get_node                    = gimp_drawable_real_get_node;
   klass->push_undo                   = gimp_drawable_real_push_undo;
   klass->swap_pixels                 = gimp_drawable_real_swap_pixels;
 }
@@ -268,6 +271,12 @@
       drawable->source_node = NULL;
     }
 
+  if (drawable->node)
+    {
+      g_object_unref (drawable->node);
+      drawable->node = NULL;
+    }
+
   if (drawable->preview_cache)
     gimp_preview_cache_invalidate (&drawable->preview_cache);
 
@@ -329,6 +338,39 @@
     GIMP_ITEM_CLASS (parent_class)->removed (item);
 }
 
+static void
+gimp_drawable_visibility_changed (GimpItem *item)
+{
+  GimpDrawable *drawable = GIMP_DRAWABLE (item);
+
+  if (drawable->node)
+    {
+      GeglNode *input;
+      GeglNode *output;
+
+      input  = gegl_node_get_input_proxy  (drawable->node, "input");
+      output = gegl_node_get_output_proxy (drawable->node, "output");
+
+      if (gimp_item_get_visible (item))
+        {
+          gegl_node_connect_to (input,               "output",
+                                drawable->mode_node, "input");
+          gegl_node_connect_to (drawable->mode_node, "output",
+                                output,              "input");
+        }
+      else
+        {
+          gegl_node_disconnect (drawable->mode_node, "input");
+
+          gegl_node_connect_to (input,  "output",
+                                output, "input");
+        }
+    }
+
+  if (GIMP_ITEM_CLASS (parent_class)->visibility_changed)
+    GIMP_ITEM_CLASS (parent_class)->visibility_changed (item);
+}
+
 static GimpItem *
 gimp_drawable_duplicate (GimpItem *item,
                          GType     new_type)
@@ -735,6 +777,37 @@
                    NULL);
 }
 
+static GeglNode *
+gimp_drawable_real_get_node (GimpDrawable *drawable)
+{
+  GeglNode  *input;
+  GeglNode  *output;
+
+  drawable->node = gegl_node_new ();
+
+  drawable->mode_node = gegl_node_new_child (drawable->node,
+                                             "operation", "normal",
+                                             NULL);
+
+  input  = gegl_node_get_input_proxy  (drawable->node, "input");
+  output = gegl_node_get_output_proxy (drawable->node, "output");
+
+  if (gimp_item_get_visible (GIMP_ITEM (drawable)))
+    {
+      gegl_node_connect_to (input,               "output",
+                            drawable->mode_node, "input");
+      gegl_node_connect_to (drawable->mode_node, "output",
+                            output,              "input");
+    }
+  else
+    {
+      gegl_node_connect_to (input,  "output",
+                            output, "input");
+    }
+
+  return drawable->node;
+}
+
 static void
 gimp_drawable_real_push_undo (GimpDrawable *drawable,
                               const gchar  *undo_desc,
@@ -1072,10 +1145,21 @@
 {
   g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), NULL);
 
-  if (GIMP_DRAWABLE_GET_CLASS (drawable)->get_node)
-    return GIMP_DRAWABLE_GET_CLASS (drawable)->get_node (drawable);
+  if (drawable->node)
+    return drawable->node;
+
+  return GIMP_DRAWABLE_GET_CLASS (drawable)->get_node (drawable);
+}
+
+GeglNode *
+gimp_drawable_get_mode_node (GimpDrawable *drawable)
+{
+  g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), NULL);
+
+  if (! drawable->mode_node)
+    gimp_drawable_get_node (drawable);
 
-  return NULL;
+  return drawable->mode_node;
 }
 
 void

Modified: trunk/app/core/gimpdrawable.h
==============================================================================
--- trunk/app/core/gimpdrawable.h	(original)
+++ trunk/app/core/gimpdrawable.h	Tue Oct 14 18:32:07 2008
@@ -42,6 +42,9 @@
 
   GeglNode      *source_node;
 
+  GeglNode      *node;
+  GeglNode      *mode_node;
+
   gint           bytes;              /* bytes per pixel                */
   GimpImageType  type;               /* type of drawable               */
   gboolean       has_alpha;          /* drawable has alpha             */
@@ -174,6 +177,7 @@
 
 GeglNode      * gimp_drawable_get_source_node    (GimpDrawable       *drawable);
 GeglNode      * gimp_drawable_get_node           (GimpDrawable       *drawable);
+GeglNode      * gimp_drawable_get_mode_node      (GimpDrawable       *drawable);
 
 void            gimp_drawable_swap_pixels        (GimpDrawable       *drawable,
                                                   TileManager        *tiles,

Modified: trunk/app/core/gimplayer.c
==============================================================================
--- trunk/app/core/gimplayer.c	(original)
+++ trunk/app/core/gimplayer.c	Tue Oct 14 18:32:07 2008
@@ -106,7 +106,6 @@
                                                  gchar             **tooltip);
 
 static void       gimp_layer_removed            (GimpItem           *item);
-static void       gimp_layer_visibility_changed (GimpItem           *item);
 static gboolean   gimp_layer_is_attached        (GimpItem           *item);
 static GimpItem * gimp_layer_duplicate          (GimpItem           *item,
                                                  GType               new_type);
@@ -253,7 +252,6 @@
   viewable_class->get_description     = gimp_layer_get_description;
 
   item_class->removed                 = gimp_layer_removed;
-  item_class->visibility_changed      = gimp_layer_visibility_changed;
   item_class->is_attached             = gimp_layer_is_attached;
   item_class->duplicate               = gimp_layer_duplicate;
   item_class->convert                 = gimp_layer_convert;
@@ -396,12 +394,6 @@
       layer->mask = NULL;
     }
 
-  if (layer->node)
-    {
-      g_object_unref (layer->node);
-      layer->node = NULL;
-    }
-
   if (layer->fs.backing_store)
     {
       tile_manager_unref (layer->fs.backing_store);
@@ -520,18 +512,15 @@
 gimp_layer_get_node (GimpDrawable *drawable)
 {
   GimpLayer *layer = GIMP_LAYER (drawable);
+  GeglNode  *node;
   GeglNode  *source;
+  GeglNode  *mode_node;
   gint       off_x, off_y;
-  GeglNode  *input;
-  GeglNode  *output;
 
-  if (layer->node)
-    return layer->node;
-
-  layer->node = gegl_node_new ();
+  node = GIMP_DRAWABLE_CLASS (parent_class)->get_node (drawable);
 
   source = gimp_drawable_get_source_node (drawable);
-  gegl_node_add_child (layer->node, source);
+  gegl_node_add_child (node, source);
 
   if (layer->mask)
     {
@@ -539,7 +528,7 @@
 
       mask = gimp_drawable_get_source_node (GIMP_DRAWABLE (layer->mask));
 
-      layer->mask_node = gegl_node_new_child (layer->node,
+      layer->mask_node = gegl_node_new_child (node,
                                               "operation", "opacity",
                                               NULL);
       gegl_node_connect_to (mask,             "output",
@@ -549,7 +538,7 @@
     }
 
   gimp_item_offsets (GIMP_ITEM (layer), &off_x, &off_y);
-  layer->shift_node = gegl_node_new_child (layer->node,
+  layer->shift_node = gegl_node_new_child (node,
                                            "operation", "shift",
                                            "x",         (gdouble) off_x,
                                            "y",         (gdouble) off_y,
@@ -562,36 +551,23 @@
     gegl_node_connect_to (source,            "output",
                           layer->shift_node, "input");
 
-  layer->opacity_node = gegl_node_new_child (layer->node,
+  layer->opacity_node = gegl_node_new_child (node,
                                              "operation", "opacity",
                                              "value",     layer->opacity,
                                              NULL);
   gegl_node_connect_to (layer->shift_node,   "output",
                         layer->opacity_node, "input");
 
-  layer->mode_node = gegl_node_new_child (layer->node,
-                                          "operation", gimp_layer_mode_to_gegl_operation (layer->mode),
-                                          NULL);
-  gegl_node_connect_to (layer->opacity_node, "output",
-                        layer->mode_node,    "aux");
+  mode_node = gimp_drawable_get_mode_node (drawable);
 
-  input  = gegl_node_get_input_proxy (layer->node, "input");
-  output = gegl_node_get_output_proxy (layer->node, "output");
+  gegl_node_set (mode_node,
+                 "operation", gimp_layer_mode_to_gegl_operation (layer->mode),
+                 NULL);
 
-  if (gimp_item_get_visible (GIMP_ITEM (layer)))
-    {
-      gegl_node_connect_to (input,            "output",
-                            layer->mode_node, "input");
-      gegl_node_connect_to (layer->mode_node, "output",
-                            output,           "input");
-    }
-  else
-    {
-      gegl_node_connect_to (input,  "output",
-                            output, "input");
-    }
+  gegl_node_connect_to (layer->opacity_node, "output",
+                        mode_node,           "aux");
 
-  return layer->node;
+  return node;
 }
 
 static void
@@ -606,39 +582,6 @@
     GIMP_ITEM_CLASS (parent_class)->removed (item);
 }
 
-static void
-gimp_layer_visibility_changed (GimpItem *item)
-{
-  GimpLayer *layer = GIMP_LAYER (item);
-
-  if (layer->node)
-    {
-      GeglNode *input;
-      GeglNode *output;
-
-      input  = gegl_node_get_input_proxy (layer->node, "input");
-      output = gegl_node_get_output_proxy (layer->node, "output");
-
-      if (gimp_item_get_visible (item))
-        {
-          gegl_node_connect_to (input,            "output",
-                                layer->mode_node, "input");
-          gegl_node_connect_to (layer->mode_node, "output",
-                                output,           "input");
-        }
-      else
-        {
-          gegl_node_disconnect (layer->mode_node, "input");
-
-          gegl_node_connect_to (input,  "output",
-                                output, "input");
-        }
-    }
-
-  if (GIMP_ITEM_CLASS (parent_class)->visibility_changed)
-    GIMP_ITEM_CLASS (parent_class)->visibility_changed (item);
-}
-
 static gboolean
 gimp_layer_is_attached (GimpItem *item)
 {
@@ -1429,12 +1372,15 @@
 
   gimp_layer_mask_set_layer (mask, layer);
 
-  if (layer->node)
+  if (layer->shift_node)
     {
+      GeglNode *node;
       GeglNode *source;
       GeglNode *mask;
 
-      layer->mask_node = gegl_node_new_child (layer->node,
+      node = gimp_drawable_get_node (GIMP_DRAWABLE (layer));
+
+      layer->mask_node = gegl_node_new_child (node,
                                               "operation", "opacity",
                                               NULL);
 
@@ -1774,14 +1720,17 @@
   if (push_undo)
     gimp_image_undo_group_end (image);
 
-  if (layer->node)
+  if (layer->mask_node)
     {
+      GeglNode *node;
       GeglNode *source;
 
+      node = gimp_drawable_get_node (GIMP_DRAWABLE (layer));
+
       gegl_node_disconnect (layer->mask_node, "input");
       gegl_node_disconnect (layer->mask_node, "aux");
 
-      gegl_node_remove_child (layer->node, layer->mask_node);
+      gegl_node_remove_child (node, layer->mask_node);
       layer->mask_node = NULL;
 
       source = gimp_drawable_get_source_node (GIMP_DRAWABLE (layer));
@@ -2079,10 +2028,16 @@
       g_signal_emit (layer, layer_signals[MODE_CHANGED], 0);
       g_object_notify (G_OBJECT (layer), "mode");
 
-      if (layer->mode_node)
-        gegl_node_set (layer->mode_node,
-                       "operation", gimp_layer_mode_to_gegl_operation (layer->mode),
-                       NULL);
+      if (layer->shift_node)
+        {
+          GeglNode *mode_node;
+
+          mode_node = gimp_drawable_get_mode_node (GIMP_DRAWABLE (layer));
+
+          gegl_node_set (mode_node,
+                         "operation", gimp_layer_mode_to_gegl_operation (layer->mode),
+                         NULL);
+        }
 
       gimp_drawable_update (GIMP_DRAWABLE (layer),
                             0, 0,

Modified: trunk/app/core/gimplayer.h
==============================================================================
--- trunk/app/core/gimplayer.h	(original)
+++ trunk/app/core/gimplayer.h	Tue Oct 14 18:32:07 2008
@@ -43,11 +43,9 @@
 
   GimpLayerMask        *mask;             /*  possible layer mask        */
 
-  GeglNode             *node;
   GeglNode             *mask_node;
   GeglNode             *shift_node;
   GeglNode             *opacity_node;
-  GeglNode             *mode_node;
 
   /*  Floating selections  */
   struct



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