[gimp] app: make GimpTool implement the GimpProgress interface properly



commit 41b905baa883b4b9b84019575a3fbce61e9b5d6d
Author: Michael Natterer <mitch gimp org>
Date:   Fri Mar 25 10:55:07 2011 +0100

    app: make GimpTool implement the GimpProgress interface properly
    
    and remove the previously added quick hack. Change the cage progress
    code to standard progress code, and use the tool progress also in
    blend.

 app/tools/Makefile.am         |    2 +
 app/tools/gimpblendtool.c     |    2 +-
 app/tools/gimpcagetool.c      |   12 ++-
 app/tools/gimptool-progress.c |  191 +++++++++++++++++++++++++++++++++++++++++
 app/tools/gimptool-progress.h |   28 ++++++
 app/tools/gimptool.c          |   70 +--------------
 app/tools/gimptool.h          |    7 --
 7 files changed, 234 insertions(+), 78 deletions(-)
---
diff --git a/app/tools/Makefile.am b/app/tools/Makefile.am
index a9a0571..d0f3624 100644
--- a/app/tools/Makefile.am
+++ b/app/tools/Makefile.am
@@ -180,6 +180,8 @@ libapptools_a_sources = \
 	gimpthresholdtool.h		\
 	gimptool.c			\
 	gimptool.h			\
+	gimptool-progress.c		\
+	gimptool-progress.h		\
 	gimptoolcontrol.c		\
 	gimptoolcontrol.h		\
 	gimptooloptions-gui.c		\
diff --git a/app/tools/gimpblendtool.c b/app/tools/gimpblendtool.c
index 74f580d..80b62b8 100644
--- a/app/tools/gimpblendtool.c
+++ b/app/tools/gimpblendtool.c
@@ -236,7 +236,7 @@ gimp_blend_tool_button_release (GimpTool              *tool,
       gint          off_x;
       gint          off_y;
 
-      progress = gimp_progress_start (GIMP_PROGRESS (display),
+      progress = gimp_progress_start (GIMP_PROGRESS (tool),
                                       _("Blending"), FALSE);
 
       gimp_item_get_offset (GIMP_ITEM (drawable), &off_x, &off_y);
diff --git a/app/tools/gimpcagetool.c b/app/tools/gimpcagetool.c
index e6d60c8..abafcef 100644
--- a/app/tools/gimpcagetool.c
+++ b/app/tools/gimpcagetool.c
@@ -40,6 +40,7 @@
 #include "core/gimpimage.h"
 #include "core/gimpimagemap.h"
 #include "core/gimplayer.h"
+#include "core/gimpprogress.h"
 #include "core/gimpprojection.h"
 
 #include "gegl/gimpcageconfig.h"
@@ -950,6 +951,7 @@ gimp_cage_tool_compute_coef (GimpCageTool *ct,
                              GimpDisplay  *display)
 {
   GimpCageConfig *config = ct->config;
+  GimpProgress   *progress;
   Babl           *format;
   GeglNode       *gegl;
   GeglNode       *input;
@@ -958,8 +960,8 @@ gimp_cage_tool_compute_coef (GimpCageTool *ct,
   GeglBuffer     *buffer;
   gdouble         value;
 
-  gimp_tool_progress_start (GIMP_TOOL (ct), display,
-                            _("Coefficient computation..."));
+  progress = gimp_progress_start (GIMP_PROGRESS (ct),
+                                  _("Coefficient computation"), FALSE);
 
   if (ct->coef)
     {
@@ -991,10 +993,12 @@ gimp_cage_tool_compute_coef (GimpCageTool *ct,
 
   while (gegl_processor_work (processor, &value))
     {
-      gimp_tool_progress_set_value (GIMP_TOOL (ct), value);
+      if (progress)
+        gimp_progress_set_value (progress, value);
     }
 
-  gimp_tool_progress_end (GIMP_TOOL (ct));
+  if (progress)
+    gimp_progress_end (progress);
 
   gegl_processor_destroy (processor);
 
diff --git a/app/tools/gimptool-progress.c b/app/tools/gimptool-progress.c
new file mode 100644
index 0000000..d2ab917
--- /dev/null
+++ b/app/tools/gimptool-progress.c
@@ -0,0 +1,191 @@
+/* GIMP - The GNU Image Manipulation Program
+ * Copyright (C) 1995 Spencer Kimball and Peter Mattis
+ *
+ * gimptool-progress.c
+ * Copyright (C) 2011 Michael Natterer <mitch gimp org>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+
+#include <gtk/gtk.h>
+
+#include "tools-types.h"
+
+#include "core/gimpprogress.h"
+
+#include "widgets/gimpwidgets-utils.h"
+
+#include "display/gimpcanvasprogress.h"
+
+#include "display/gimpdisplay.h"
+#include "display/gimpdisplayshell.h"
+#include "display/gimpdisplayshell-items.h"
+#include "display/gimpdisplayshell-transform.h"
+#include "display/gimpdisplayshell-style.h"
+
+#include "gimptool.h"
+#include "gimptool-progress.h"
+
+
+/*  local function prototypes  */
+
+static GimpProgress * gimp_tool_progress_start     (GimpProgress        *progress,
+                                                    const gchar         *message,
+                                                    gboolean             cancelable);
+static void           gimp_tool_progress_end       (GimpProgress        *progress);
+static gboolean       gimp_tool_progress_is_active (GimpProgress        *progress);
+static void           gimp_tool_progress_set_text  (GimpProgress        *progress,
+                                                    const gchar         *message);
+static void           gimp_tool_progress_set_value (GimpProgress        *progress,
+                                                    gdouble              percentage);
+static gdouble        gimp_tool_progress_get_value (GimpProgress        *progress);
+static void           gimp_tool_progress_pulse     (GimpProgress        *progress);
+static gboolean       gimp_tool_progress_message   (GimpProgress        *progress,
+                                                    Gimp                *gimp,
+                                                    GimpMessageSeverity  severity,
+                                                    const gchar         *domain,
+                                                    const gchar         *message);
+
+
+/*  public functions  */
+
+void
+gimp_tool_progress_iface_init (GimpProgressInterface *iface)
+{
+  iface->start     = gimp_tool_progress_start;
+  iface->end       = gimp_tool_progress_end;
+  iface->is_active = gimp_tool_progress_is_active;
+  iface->set_text  = gimp_tool_progress_set_text;
+  iface->set_value = gimp_tool_progress_set_value;
+  iface->get_value = gimp_tool_progress_get_value;
+  iface->pulse     = gimp_tool_progress_pulse;
+  iface->message   = gimp_tool_progress_message;
+}
+
+
+/*  private functions  */
+
+static GimpProgress *
+gimp_tool_progress_start (GimpProgress *progress,
+                          const gchar  *message,
+                          gboolean      cancelable)
+{
+  GimpTool         *tool = GIMP_TOOL (progress);
+  GimpDisplayShell *shell;
+  gint              x, y, w, h;
+
+  g_return_val_if_fail (GIMP_IS_DISPLAY (tool->display), NULL);
+  g_return_val_if_fail (tool->progress == NULL, NULL);
+
+  shell = gimp_display_get_shell (tool->display);
+
+  gimp_display_shell_untransform_viewport (shell, &x, &y, &w, &h);
+
+  tool->progress = gimp_canvas_progress_new (shell,
+                                             GIMP_HANDLE_ANCHOR_CENTER,
+                                             x + w / 2, y + h / 2);
+  gimp_display_shell_add_item (shell, tool->progress);
+  g_object_unref (tool->progress);
+
+  gimp_progress_start (GIMP_PROGRESS (tool->progress),
+                       message, FALSE);
+  gimp_widget_flush_expose (shell->canvas);
+
+  tool->progress_display = tool->display;
+
+  return progress;
+}
+
+static void
+gimp_tool_progress_end (GimpProgress *progress)
+{
+  GimpTool *tool = GIMP_TOOL (progress);
+
+  if (tool->progress)
+    {
+      GimpDisplayShell *shell = gimp_display_get_shell (tool->progress_display);
+
+      gimp_progress_end (GIMP_PROGRESS (tool->progress));
+      gimp_display_shell_remove_item (shell, tool->progress);
+
+      tool->progress         = NULL;
+      tool->progress_display = NULL;
+    }
+}
+
+static gboolean
+gimp_tool_progress_is_active (GimpProgress *progress)
+{
+  GimpTool *tool = GIMP_TOOL (progress);
+
+  return tool->progress != NULL;
+}
+
+static void
+gimp_tool_progress_set_text (GimpProgress *progress,
+                             const gchar  *message)
+{
+  GimpTool *tool = GIMP_TOOL (progress);
+
+  if (tool->progress)
+    {
+      GimpDisplayShell *shell = gimp_display_get_shell (tool->progress_display);
+
+      gimp_progress_set_text (GIMP_PROGRESS (tool->progress), message);
+      gimp_widget_flush_expose (shell->canvas);
+    }
+}
+
+static void
+gimp_tool_progress_set_value (GimpProgress *progress,
+                              gdouble       percentage)
+{
+  GimpTool *tool = GIMP_TOOL (progress);
+
+  if (tool->progress)
+    {
+      GimpDisplayShell *shell = gimp_display_get_shell (tool->progress_display);
+
+      gimp_progress_set_value (GIMP_PROGRESS (tool->progress), percentage);
+      gimp_widget_flush_expose (shell->canvas);
+    }
+}
+
+static gdouble
+gimp_tool_progress_get_value (GimpProgress *progress)
+{
+  GimpTool *tool = GIMP_TOOL (progress);
+
+  if (tool->progress)
+    return gimp_progress_get_value (GIMP_PROGRESS (tool->progress));
+
+  return 0.0;
+}
+
+static void
+gimp_tool_progress_pulse (GimpProgress *progress)
+{
+}
+
+static gboolean
+gimp_tool_progress_message (GimpProgress        *progress,
+                            Gimp                *gimp,
+                            GimpMessageSeverity  severity,
+                            const gchar         *domain,
+                            const gchar         *message)
+{
+  return FALSE;
+}
diff --git a/app/tools/gimptool-progress.h b/app/tools/gimptool-progress.h
new file mode 100644
index 0000000..2899253
--- /dev/null
+++ b/app/tools/gimptool-progress.h
@@ -0,0 +1,28 @@
+/* GIMP - The GNU Image Manipulation Program
+ * Copyright (C) 1995 Spencer Kimball and Peter Mattis
+ *
+ * gimptool-progress.h
+ * Copyright (C) 2011 Michael Natterer <mitch gimp org>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __GIMP_TOOL_PROGRESS_H__
+#define __GIMP_TOOL_PROGRESS_H__
+
+
+void   gimp_tool_progress_iface_init (GimpProgressInterface *iface);
+
+
+#endif /* __GIMP_TOOL_PROGRESS */
diff --git a/app/tools/gimptool.c b/app/tools/gimptool.c
index 8b2237b..2e86070 100644
--- a/app/tools/gimptool.c
+++ b/app/tools/gimptool.c
@@ -30,17 +30,13 @@
 #include "core/gimpprogress.h"
 #include "core/gimptoolinfo.h"
 
-#include "widgets/gimpwidgets-utils.h"
-
-#include "display/gimpcanvasprogress.h"
 #include "display/gimpdisplay.h"
 #include "display/gimpdisplayshell.h"
 #include "display/gimpdisplayshell-cursor.h"
-#include "display/gimpdisplayshell-items.h"
-#include "display/gimpdisplayshell-transform.h"
 #include "display/gimpstatusbar.h"
 
 #include "gimptool.h"
+#include "gimptool-progress.h"
 #include "gimptoolcontrol.h"
 
 #include "gimp-log.h"
@@ -132,7 +128,9 @@ static void       gimp_tool_options_notify      (GimpToolOptions       *options,
 static void       gimp_tool_clear_status        (GimpTool              *tool);
 
 
-G_DEFINE_TYPE (GimpTool, gimp_tool, GIMP_TYPE_OBJECT)
+G_DEFINE_TYPE_WITH_CODE (GimpTool, gimp_tool, GIMP_TYPE_OBJECT,
+                         G_IMPLEMENT_INTERFACE (GIMP_TYPE_PROGRESS,
+                                                gimp_tool_progress_iface_init))
 
 #define parent_class gimp_tool_parent_class
 
@@ -1133,66 +1131,6 @@ gimp_tool_set_cursor (GimpTool           *tool,
                                  cursor, tool_cursor, modifier);
 }
 
-void
-gimp_tool_progress_start (GimpTool    *tool,
-                          GimpDisplay *display,
-                          const gchar *text)
-{
-  GimpDisplayShell *shell;
-  gint              x, y, w, h;
-
-  g_return_if_fail (GIMP_IS_TOOL (tool));
-  g_return_if_fail (GIMP_IS_DISPLAY (display));
-  g_return_if_fail (tool->progress == NULL);
-
-  shell = gimp_display_get_shell (display);
-
-  gimp_display_shell_untransform_viewport (shell, &x, &y, &w, &h);
-
-  tool->progress = gimp_canvas_progress_new (shell, GIMP_HANDLE_ANCHOR_CENTER,
-                                             x + w / 2, y + h / 2);
-  gimp_display_shell_add_item (shell, tool->progress);
-  g_object_unref (tool->progress);
-
-  gimp_progress_start (GIMP_PROGRESS (tool->progress),
-                       text, FALSE);
-  gimp_widget_flush_expose (shell->canvas);
-
-  tool->progress_display = display;
-}
-
-void
-gimp_tool_progress_set_value (GimpTool *tool,
-                              gdouble  value)
-{
-  GimpDisplayShell *shell;
-
-  g_return_if_fail (GIMP_IS_TOOL (tool));
-  g_return_if_fail (GIMP_IS_PROGRESS (tool->progress));
-
-  shell = gimp_display_get_shell (tool->progress_display);
-
-  gimp_progress_set_value (GIMP_PROGRESS (tool->progress), value);
-  gimp_widget_flush_expose (shell->canvas);
-}
-
-void
-gimp_tool_progress_end (GimpTool *tool)
-{
-  GimpDisplayShell *shell;
-
-  g_return_if_fail (GIMP_IS_TOOL (tool));
-  g_return_if_fail (GIMP_IS_PROGRESS (tool->progress));
-
-  shell = gimp_display_get_shell (tool->progress_display);
-
-  gimp_progress_end (GIMP_PROGRESS (tool->progress));
-  gimp_display_shell_remove_item (shell, tool->progress);
-
-  tool->progress         = NULL;
-  tool->progress_display = NULL;
-}
-
 
 /*  private functions  */
 
diff --git a/app/tools/gimptool.h b/app/tools/gimptool.h
index af10ce2..805140b 100644
--- a/app/tools/gimptool.h
+++ b/app/tools/gimptool.h
@@ -251,12 +251,5 @@ void          gimp_tool_set_cursor          (GimpTool            *tool,
                                              GimpToolCursorType   tool_cursor,
                                              GimpCursorModifier   modifier);
 
-void          gimp_tool_progress_start      (GimpTool            *tool,
-                                             GimpDisplay         *display,
-                                             const gchar         *text);
-void          gimp_tool_progress_set_value  (GimpTool            *tool,
-                                             gdouble              value);
-void          gimp_tool_progress_end        (GimpTool            *tool);
-
 
 #endif  /*  __GIMP_TOOL_H__  */



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