[gimp] app: add a progress indicator for cage transform



commit 6fdcc5f46518240f4e339768911ed49792cdf2aa
Author: Michael Natterer <mitch gimp org>
Date:   Fri Mar 25 15:41:53 2011 +0100

    app: add a progress indicator for cage transform
    
    - add a double "progress" property to GimpOperationCageTransform
      and update it every 20 rows
    - connect to the notify::progress in the tool and display a tool
      progress

 app/gegl/gimpoperationcagetransform.c |   32 +++++++++++++++++++++++++++++++-
 app/gegl/gimpoperationcagetransform.h |    2 ++
 app/tools/gimpcagetool.c              |   33 ++++++++++++++++++++++++++++++++-
 3 files changed, 65 insertions(+), 2 deletions(-)
---
diff --git a/app/gegl/gimpoperationcagetransform.c b/app/gegl/gimpoperationcagetransform.c
index 6764089..0d48aa3 100644
--- a/app/gegl/gimpoperationcagetransform.c
+++ b/app/gegl/gimpoperationcagetransform.c
@@ -35,7 +35,8 @@ enum
 {
   PROP_0,
   PROP_CONFIG,
-  PROP_FILL
+  PROP_FILL,
+  PROP_PROGRESS
 };
 
 
@@ -121,6 +122,13 @@ gimp_operation_cage_transform_class_init (GimpOperationCageTransformClass *klass
                                                          "Fill the original position of the cage with a plain color",
                                                          FALSE,
                                                          G_PARAM_READWRITE));
+
+  g_object_class_install_property (object_class, PROP_PROGRESS,
+                                   g_param_spec_double ("progress",
+                                                        "Progress",
+                                                        "Progress indicator, and a bad hack",
+                                                        0.0, 1.0, 0.0,
+                                                        G_PARAM_READABLE));
 }
 
 static void
@@ -159,6 +167,9 @@ gimp_operation_cage_transform_get_property (GObject    *object,
     case PROP_FILL:
       g_value_set_boolean (value, self->fill_plain_color);
       break;
+    case PROP_PROGRESS:
+      g_value_set_double (value, self->progress);
+      break;
 
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -274,6 +285,9 @@ gimp_operation_cage_transform_process (GeglOperation       *operation,
         }
     }
 
+  oct->progress = 0.0;
+  g_object_notify (G_OBJECT (oct), "progress");
+
   /* pre-allocate memory outside of the loop */
   coords      = g_slice_alloc (2 * sizeof (gfloat));
   coef        = g_malloc (config->n_cage_vertices * 2 * sizeof (gfloat));
@@ -328,11 +342,27 @@ gimp_operation_cage_transform_process (GeglOperation       *operation,
                                                                               coords);
             }
         }
+
+      if ((y - cage_bb.y) % 20 == 0)
+        {
+          gdouble fraction = ((gdouble) (y - cage_bb.y) /
+                              (gdouble) (cage_bb.height));
+
+          /*  0.0 and 1.0 indicate progress start/end, so avoid them  */
+          if (fraction > 0.0 && fraction < 1.0)
+            {
+              oct->progress = fraction;
+              g_object_notify (G_OBJECT (oct), "progress");
+            }
+        }
     }
 
   g_free (coef);
   g_slice_free1 (2 * sizeof (gfloat), coords);
 
+  oct->progress = 1.0;
+  g_object_notify (G_OBJECT (oct), "progress");
+
   return TRUE;
 }
 
diff --git a/app/gegl/gimpoperationcagetransform.h b/app/gegl/gimpoperationcagetransform.h
index 2e06234..fead68e 100644
--- a/app/gegl/gimpoperationcagetransform.h
+++ b/app/gegl/gimpoperationcagetransform.h
@@ -43,6 +43,8 @@ struct _GimpOperationCageTransform
   gboolean               fill_plain_color;
 
   Babl                  *format_coords;
+
+  gdouble                progress; /* bad hack */
 };
 
 struct _GimpOperationCageTransformClass
diff --git a/app/tools/gimpcagetool.c b/app/tools/gimpcagetool.c
index abafcef..31213b7 100644
--- a/app/tools/gimpcagetool.c
+++ b/app/tools/gimpcagetool.c
@@ -961,7 +961,7 @@ gimp_cage_tool_compute_coef (GimpCageTool *ct,
   gdouble         value;
 
   progress = gimp_progress_start (GIMP_PROGRESS (ct),
-                                  _("Coefficient computation"), FALSE);
+                                  _("Computing Cage Coefficients"), FALSE);
 
   if (ct->coef)
     {
@@ -1009,12 +1009,37 @@ gimp_cage_tool_compute_coef (GimpCageTool *ct,
 }
 
 static void
+gimp_cage_tool_transform_progress (GObject          *object,
+                                   const GParamSpec *pspec,
+                                   GimpCageTool     *ct)
+{
+  GimpProgress *progress = GIMP_PROGRESS (ct);
+  gdouble       value;
+
+  g_object_get (object, "progress", &value, NULL);
+
+  if (value == 0.0)
+    {
+      gimp_progress_start (progress, _("Cage Transform"), FALSE);
+    }
+  else if (value == 1.0)
+    {
+      gimp_progress_end (progress);
+    }
+  else
+    {
+      gimp_progress_set_value (progress, value);
+    }
+}
+
+static void
 gimp_cage_tool_create_render_node (GimpCageTool *ct)
 {
   GimpCageOptions *options  = GIMP_CAGE_TOOL_GET_OPTIONS (ct);
   GeglNode        *coef, *cage, *render; /* Render nodes */
   GeglNode        *input, *output; /* Proxy nodes*/
   GeglNode        *node; /* wraper to be returned */
+  GObject         *transform;
 
   g_return_if_fail (ct->render_node == NULL);
   /* render_node is not supposed to be recreated */
@@ -1057,6 +1082,12 @@ gimp_cage_tool_create_render_node (GimpCageTool *ct)
   ct->render_node = node;
   ct->cage_node = cage;
   ct->coef_node = coef;
+
+  g_object_get (cage, "gegl-operation", &transform, NULL);
+  g_signal_connect (transform, "notify::progress",
+                    G_CALLBACK (gimp_cage_tool_transform_progress),
+                    ct);
+  g_object_unref (transform);
 }
 
 static void



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