[gimp] gimpwarptool: use a second timer to refresh the preview



commit 1769750542aab6fdbbcbe29be31f670a60b1df42
Author: Michael Muré <batolettre gmail com>
Date:   Sat Jun 18 18:13:30 2011 +0200

    gimpwarptool: use a second timer to refresh the preview

 app/tools/gimpwarptool.c |   85 +++++++++++++++++++++++++---------------------
 app/tools/gimpwarptool.h |    3 +-
 2 files changed, 48 insertions(+), 40 deletions(-)
---
diff --git a/app/tools/gimpwarptool.c b/app/tools/gimpwarptool.c
index 107af9b..31e1c79 100644
--- a/app/tools/gimpwarptool.c
+++ b/app/tools/gimpwarptool.c
@@ -93,7 +93,8 @@ static void       gimp_warp_tool_oper_update        (GimpTool              *tool
                                                      gboolean               proximity,
                                                      GimpDisplay           *display);
 
-static gboolean   gimp_warp_tool_timer              (gpointer               data);
+static gboolean   gimp_warp_tool_stroke_timer       (gpointer               data);
+static gboolean   gimp_warp_tool_preview_timer      (gpointer               data);
 static void       gimp_warp_tool_draw               (GimpDrawTool          *draw_tool);
 
 static void       gimp_warp_tool_create_graph       (GimpWarpTool          *wt);
@@ -101,13 +102,14 @@ static void       gimp_warp_tool_create_image_map   (GimpWarpTool          *wt,
                                                      GimpDrawable          *drawable);
 static void       gimp_warp_tool_image_map_flush    (GimpImageMap          *image_map,
                                                      GimpTool              *tool);
-static void       gimp_warp_tool_image_map_update   (GimpWarpTool          *wt);
 static void       gimp_warp_tool_add_op             (GimpWarpTool          *wt);
 
 G_DEFINE_TYPE (GimpWarpTool, gimp_warp_tool, GIMP_TYPE_DRAW_TOOL)
 
 #define parent_class gimp_warp_tool_parent_class
 
+#define STROKE_PERIOD 100
+#define PREVIEW_PERIOD 1000
 
 void
 gimp_warp_tool_register (GimpToolRegisterCallback  callback,
@@ -378,10 +380,10 @@ gimp_warp_tool_button_press (GimpTool            *tool,
   gegl_path_append (wt->current_stroke,
                     'M', coords->x, coords->y);
 
-  wt->timer = g_timeout_add (100, gimp_warp_tool_timer, wt);
+  wt->stroke_timer = g_timeout_add (STROKE_PERIOD, gimp_warp_tool_stroke_timer, wt);
+  wt->preview_timer = g_timeout_add (PREVIEW_PERIOD, gimp_warp_tool_preview_timer, wt);
 
   gimp_warp_tool_add_op (wt);
-  gimp_warp_tool_image_map_update (wt);
 
   gimp_tool_control_activate (tool->control);
 }
@@ -400,10 +402,11 @@ gimp_warp_tool_button_release (GimpTool              *tool,
 
   gimp_tool_control_halt (tool->control);
 
-  g_source_remove (wt->timer);
+  g_source_remove (wt->stroke_timer);
+  g_source_remove (wt->preview_timer);
 
   printf ("%s\n", gegl_path_to_string (wt->current_stroke));
-  gimp_warp_tool_image_map_update (wt);
+  gimp_warp_tool_preview_timer (wt);
 
   if (release_type == GIMP_BUTTON_RELEASE_CANCEL)
     {
@@ -433,13 +436,48 @@ gimp_warp_tool_cursor_update (GimpTool         *tool,
   GIMP_TOOL_CLASS (parent_class)->cursor_update (tool, coords, state, display);
 }
 
-gboolean
-gimp_warp_tool_timer (gpointer data)
+static gboolean
+gimp_warp_tool_stroke_timer (gpointer data)
 {
   GimpWarpTool    *wt        = GIMP_WARP_TOOL (data);
 
   gegl_path_append (wt->current_stroke,
                     'M', wt->cursor_x, wt->cursor_y);
+  return TRUE;
+}
+
+static gboolean
+gimp_warp_tool_preview_timer (gpointer data)
+{
+  GimpWarpTool     *wt    = GIMP_WARP_TOOL (data);
+  GimpTool         *tool  = GIMP_TOOL (wt);
+  GimpDisplayShell *shell = gimp_display_get_shell (tool->display);
+  GimpItem         *item  = GIMP_ITEM (tool->drawable);
+  gint              x, y;
+  gint              w, h;
+  gint              off_x, off_y;
+  GeglRectangle     visible;
+
+  gimp_display_shell_untransform_viewport (shell, &x, &y, &w, &h);
+
+  gimp_item_get_offset (item, &off_x, &off_y);
+
+  gimp_rectangle_intersect (x, y, w, h,
+                            off_x,
+                            off_y,
+                            gimp_item_get_width  (item),
+                            gimp_item_get_height (item),
+                            &visible.x,
+                            &visible.y,
+                            &visible.width,
+                            &visible.height);
+
+  visible.x -= off_x;
+  visible.y -= off_y;
+
+  gimp_image_map_apply (wt->image_map, &visible);
+
+  return TRUE;
 }
 
 static void
@@ -524,37 +562,6 @@ gimp_warp_tool_image_map_flush (GimpImageMap *image_map,
 }
 
 static void
-gimp_warp_tool_image_map_update (GimpWarpTool *wt)
-{
-  GimpTool         *tool  = GIMP_TOOL (wt);
-  GimpDisplayShell *shell = gimp_display_get_shell (tool->display);
-  GimpItem         *item  = GIMP_ITEM (tool->drawable);
-  gint              x, y;
-  gint              w, h;
-  gint              off_x, off_y;
-  GeglRectangle     visible;
-
-  gimp_display_shell_untransform_viewport (shell, &x, &y, &w, &h);
-
-  gimp_item_get_offset (item, &off_x, &off_y);
-
-  gimp_rectangle_intersect (x, y, w, h,
-                            off_x,
-                            off_y,
-                            gimp_item_get_width  (item),
-                            gimp_item_get_height (item),
-                            &visible.x,
-                            &visible.y,
-                            &visible.width,
-                            &visible.height);
-
-  visible.x -= off_x;
-  visible.y -= off_y;
-
-  gimp_image_map_apply (wt->image_map, &visible);
-}
-
-static void
 gimp_warp_tool_add_op (GimpWarpTool *wt)
 {
   GimpWarpOptions *options = GIMP_WARP_TOOL_GET_OPTIONS (wt);
diff --git a/app/tools/gimpwarptool.h b/app/tools/gimpwarptool.h
index 169d7fd..a8ba939 100644
--- a/app/tools/gimpwarptool.h
+++ b/app/tools/gimpwarptool.h
@@ -52,7 +52,8 @@ struct _GimpWarpTool
 
   GeglPath       *current_stroke;
 
-  guint           timer;
+  guint           stroke_timer;
+  guint           preview_timer;
 
   GimpImageMap   *image_map; /* For preview */
 };


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