[gimp/soc-2011-seamless-clone: 4/4] Free resources and abort the ImageMap preview when the tool finishes



commit b67dbc4ed50d09cfbcda5434a7c64b350c60b538
Author: Barak Itkin <lightningismyname gmail com>
Date:   Sat Jul 9 00:07:54 2011 +0300

    Free resources and abort the ImageMap preview when the tool finishes

 app/tools/gimpseamlessclonetool.c |   56 +++++++++++++++++++++++++++++++++++++
 1 files changed, 56 insertions(+), 0 deletions(-)
---
diff --git a/app/tools/gimpseamlessclonetool.c b/app/tools/gimpseamlessclonetool.c
index 9178572..7c231d0 100644
--- a/app/tools/gimpseamlessclonetool.c
+++ b/app/tools/gimpseamlessclonetool.c
@@ -90,6 +90,11 @@ gimp_seamless_clone_tool_initialize (GimpTool              *tool,
                                      GError               **error);
 
 static void
+gimp_seamless_clone_tool_control (GimpTool       *tool,
+                                  GimpToolAction  action,
+                                  GimpDisplay    *display);
+
+static void
 gimp_seamless_clone_tool_update_image_map_easy (GimpSeamlessCloneTool *sct);
 
 static void
@@ -172,6 +177,7 @@ gimp_seamless_clone_tool_class_init (GimpSeamlessCloneToolClass *klass)
 
   tool_class->initialize = gimp_seamless_clone_tool_initialize;
 
+  tool_class->control         = gimp_seamless_clone_tool_control;
   tool_class->options_notify  = gimp_seamless_clone_tool_options_notify;
   tool_class->button_press    = gimp_seamless_clone_tool_button_press;
   tool_class->button_release  = gimp_seamless_clone_tool_button_release;
@@ -209,6 +215,56 @@ gimp_seamless_clone_tool_init (GimpSeamlessCloneTool *self)
   self->translate_op    = NULL;
 }
 
+static void
+gimp_seamless_clone_tool_control (GimpTool       *tool,
+                                  GimpToolAction  action,
+                                  GimpDisplay    *display)
+{
+  GimpSeamlessCloneTool *sct = GIMP_SEAMLESS_CLONE_TOOL (tool);
+
+  DBG_CALL_NAME();
+
+  switch (action)
+    {
+    case GIMP_TOOL_ACTION_PAUSE:
+    case GIMP_TOOL_ACTION_RESUME:
+      break;
+
+    case GIMP_TOOL_ACTION_HALT:
+      if (sct->paste_buf)
+        {
+          gegl_buffer_destroy (sct->paste_buf);
+          sct->paste_buf = NULL;
+        }
+
+      if (sct->render_node)
+        {
+          g_object_unref (sct->render_node);
+          sct->render_node  = NULL;
+          sct->translate_op = NULL;
+        }
+
+      if (sct->image_map)
+        {
+          gimp_tool_control_set_preserve (tool->control, TRUE);
+
+          gimp_image_map_abort (sct->image_map);
+          g_object_unref (sct->image_map);
+          sct->image_map = NULL;
+
+          gimp_tool_control_set_preserve (tool->control, FALSE);
+
+          gimp_image_flush (gimp_display_get_image (tool->display));
+        }
+
+      tool->display = NULL;
+
+      break;
+    }
+
+  GIMP_TOOL_CLASS (parent_class)->control (tool, action, display);
+}
+
 /**
  * gimp_seamless_clone_tool_update_image_map:
  * @sct - an instance of the #GimpSeamlessCloneTool



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