[gimp] app: add start_stroke() and finish_stroke() API to GimpMotionBuffer



commit 6f865eda2bea63ec3551eb68342e7f04e42bd5ba
Author: Michael Natterer <mitch gimp org>
Date:   Mon Apr 18 00:29:32 2011 +0200

    app: add start_stroke() and finish_stroke() API to GimpMotionBuffer
    
    where finish_stroke() is the former flush_event_queue() and
    start_stroke() is used in BUTTON_PRESS instead of poking into the
    motion buffer's internals. Also, call finish_stroke() also when the
    tool is not active, so the event buffer is flushed (the "motion"
    callback will ignore the events if the tool is not active).

 app/display/gimpdisplayshell-tool-events.c |   26 +++++++++---------
 app/display/gimpmotionbuffer.c             |   38 +++++++++++++++++++--------
 app/display/gimpmotionbuffer.h             |    6 +++-
 3 files changed, 45 insertions(+), 25 deletions(-)
---
diff --git a/app/display/gimpdisplayshell-tool-events.c b/app/display/gimpdisplayshell-tool-events.c
index b46eec7..7223404 100644
--- a/app/display/gimpdisplayshell-tool-events.c
+++ b/app/display/gimpdisplayshell-tool-events.c
@@ -502,30 +502,30 @@ gimp_display_shell_canvas_tool_events (GtkWidget        *canvas,
             if (gimp_display_shell_initialize_tool (shell,
                                                     &image_coords, state))
               {
+                GimpCoords last_motion;
+
                 /* Use the last evaluated dynamic axes instead of the
                  * button_press event's ones because the click is
                  * usually at the same spot as the last motion event
                  * which would give us bogus dynamics.
                  */
-                GimpCoords tmp_coords;
-
-                tmp_coords = shell->motion_buffer->last_coords;
+                gimp_motion_buffer_start_stroke (shell->motion_buffer, time,
+                                                 &last_motion);
 
-                tmp_coords.x        = image_coords.x;
-                tmp_coords.y        = image_coords.y;
-                tmp_coords.pressure = image_coords.pressure;
-                tmp_coords.xtilt    = image_coords.xtilt;
-                tmp_coords.ytilt    = image_coords.ytilt;
+                last_motion.x        = image_coords.x;
+                last_motion.y        = image_coords.y;
+                last_motion.pressure = image_coords.pressure;
+                last_motion.xtilt    = image_coords.xtilt;
+                last_motion.ytilt    = image_coords.ytilt;
+                last_motion.wheel    = image_coords.wheel;
 
-                image_coords = tmp_coords;
+                image_coords = last_motion;
 
                 tool_manager_button_press_active (gimp,
                                                   &image_coords,
                                                   time, state,
                                                   GIMP_BUTTON_PRESS_NORMAL,
                                                   display);
-
-                shell->motion_buffer->last_read_motion_time = bevent->time;
               }
             break;
 
@@ -656,10 +656,10 @@ gimp_display_shell_canvas_tool_events (GtkWidget        *canvas,
                 (! gimp_image_is_empty (image) ||
                  gimp_tool_control_get_handle_empty_image (active_tool->control)))
               {
+                gimp_motion_buffer_finish_stroke (shell->motion_buffer);
+
                 if (gimp_tool_control_is_active (active_tool->control))
                   {
-                    gimp_motion_buffer_flush_event_queue (shell->motion_buffer);
-
                     tool_manager_button_release_active (gimp,
                                                         &image_coords,
                                                         time, state,
diff --git a/app/display/gimpmotionbuffer.c b/app/display/gimpmotionbuffer.c
index 30a6464..f10dc31 100644
--- a/app/display/gimpmotionbuffer.c
+++ b/app/display/gimpmotionbuffer.c
@@ -188,6 +188,33 @@ gimp_motion_buffer_new (void)
                        NULL);
 }
 
+void
+gimp_motion_buffer_start_stroke (GimpMotionBuffer *buffer,
+                                 guint32           time,
+                                 GimpCoords       *last_motion)
+{
+  g_return_if_fail (GIMP_IS_MOTION_BUFFER (buffer));
+  g_return_if_fail (last_motion != NULL);
+
+  buffer->last_read_motion_time = time;
+
+  *last_motion = buffer->last_coords;
+}
+
+void
+gimp_motion_buffer_finish_stroke (GimpMotionBuffer *buffer)
+{
+  g_return_if_fail (GIMP_IS_MOTION_BUFFER (buffer));
+
+  if (buffer->event_delay_timeout)
+    {
+      g_source_remove (buffer->event_delay_timeout);
+      buffer->event_delay_timeout = 0;
+    }
+
+  gimp_motion_buffer_event_queue_timeout (buffer);
+}
+
 /**
  * gimp_motion_buffer_eval_event:
  * @buffer:
@@ -475,17 +502,6 @@ gimp_motion_buffer_process_event_queue (GimpMotionBuffer *buffer,
     }
 }
 
-void
-gimp_motion_buffer_flush_event_queue (GimpMotionBuffer *buffer)
-{
-  g_return_if_fail (GIMP_IS_MOTION_BUFFER (buffer));
-
-  if (buffer->event_delay_timeout)
-    g_source_remove (buffer->event_delay_timeout);
-
-  gimp_motion_buffer_event_queue_timeout (buffer);
-}
-
 
 /*  private functions  */
 
diff --git a/app/display/gimpmotionbuffer.h b/app/display/gimpmotionbuffer.h
index e89a5f2..119d610 100644
--- a/app/display/gimpmotionbuffer.h
+++ b/app/display/gimpmotionbuffer.h
@@ -73,6 +73,11 @@ GType              gimp_motion_buffer_get_type    (void) G_GNUC_CONST;
 
 GimpMotionBuffer * gimp_motion_buffer_new         (void);
 
+void       gimp_motion_buffer_start_stroke        (GimpMotionBuffer *buffer,
+                                                   guint32           time,
+                                                   GimpCoords       *last_motion);
+void       gimp_motion_buffer_finish_stroke       (GimpMotionBuffer *buffer);
+
 gboolean   gimp_motion_buffer_eval_event          (GimpMotionBuffer *buffer,
                                                    gdouble           scale_x,
                                                    gdouble           scale_y,
@@ -88,7 +93,6 @@ void       gimp_motion_buffer_pop_event_queue     (GimpMotionBuffer *buffer,
 void       gimp_motion_buffer_process_event_queue (GimpMotionBuffer *buffer,
                                                    GdkModifierType   state,
                                                    guint32           time);
-void       gimp_motion_buffer_flush_event_queue   (GimpMotionBuffer *buffer);
 
 
 #endif /* __GIMP_MOTION_BUFFER_H__ */



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