[gimp] app: GimpMotionBuffer API cleanup and refactoring
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] app: GimpMotionBuffer API cleanup and refactoring
- Date: Mon, 18 Apr 2011 09:13:19 +0000 (UTC)
commit 3fbbb9b333acddac6ebbb370fd7b24a4616c152f
Author: Michael Natterer <mitch gimp org>
Date: Mon Apr 18 11:08:24 2011 +0200
app: GimpMotionBuffer API cleanup and refactoring
- start_stroke()/finih_stroke() -> begin_stroke()/end_stroke()
- process_event_queue() -> process_stroke()
- GimpMotionBuffer::motion() -> GimpMotionBuffer::stroke()
- add GimpMotionBuffer::hover() and process_hover()
- remove push_event_history() and pop_event_queue() from API
The thing works like this:
- Motion events are continuously fed into the buffer using motion_event()
- begin_stroke()/end_stroke() correspond to BUTTON_PRESS/BUTTON_RELEASE,
the period between them is a "stroke"
- If motion_event() returns TRUE, we request "stroke" signals by calling
process_stroke() and "hover" signals by calling process_hover()
app/core/gimpmarshal.list | 1 +
app/display/gimpdisplayshell-tool-events.c | 55 ++++++++++++-------
app/display/gimpdisplayshell-tool-events.h | 7 ++-
app/display/gimpdisplayshell.c | 7 ++-
app/display/gimpmotionbuffer.c | 79 +++++++++++++++++++--------
app/display/gimpmotionbuffer.h | 20 ++++---
6 files changed, 112 insertions(+), 57 deletions(-)
---
diff --git a/app/core/gimpmarshal.list b/app/core/gimpmarshal.list
index d4f457d..e2453d2 100644
--- a/app/core/gimpmarshal.list
+++ b/app/core/gimpmarshal.list
@@ -54,6 +54,7 @@ VOID: OBJECT, POINTER
VOID: POINTER
VOID: POINTER, BOXED
VOID: POINTER, ENUM
+VOID: POINTER, FLAGS, BOOLEAN
VOID: POINTER, UINT, FLAGS
VOID: STRING
VOID: STRING, BOOLEAN, UINT, FLAGS
diff --git a/app/display/gimpdisplayshell-tool-events.c b/app/display/gimpdisplayshell-tool-events.c
index d5ee29a..05516d8 100644
--- a/app/display/gimpdisplayshell-tool-events.c
+++ b/app/display/gimpdisplayshell-tool-events.c
@@ -509,7 +509,7 @@ gimp_display_shell_canvas_tool_events (GtkWidget *canvas,
* usually at the same spot as the last motion event
* which would give us bogus dynamics.
*/
- gimp_motion_buffer_start_stroke (shell->motion_buffer, time,
+ gimp_motion_buffer_begin_stroke (shell->motion_buffer, time,
&last_motion);
last_motion.x = image_coords.x;
@@ -656,7 +656,7 @@ 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);
+ gimp_motion_buffer_end_stroke (shell->motion_buffer);
if (gimp_tool_control_is_active (active_tool->control))
{
@@ -924,9 +924,9 @@ gimp_display_shell_canvas_tool_events (GtkWidget *canvas,
shell->scale_y,
TRUE))
{
- gimp_motion_buffer_process_event_queue (shell->motion_buffer,
- state,
- history_events[i]->time);
+ gimp_motion_buffer_process_stroke (shell->motion_buffer,
+ state,
+ history_events[i]->time);
}
}
@@ -945,9 +945,9 @@ gimp_display_shell_canvas_tool_events (GtkWidget *canvas,
shell->scale_y,
event_fill))
{
- gimp_motion_buffer_process_event_queue (shell->motion_buffer,
- state,
- time);
+ gimp_motion_buffer_process_stroke (shell->motion_buffer,
+ state,
+ time);
}
}
}
@@ -966,19 +966,10 @@ gimp_display_shell_canvas_tool_events (GtkWidget *canvas,
shell->scale_y,
FALSE))
{
- GimpCoords buf_coords;
-
- gimp_motion_buffer_pop_event_queue (shell->motion_buffer,
- &buf_coords);
-
- tool_manager_oper_update_active (gimp,
- &buf_coords, state,
- shell->proximity,
- display);
+ gimp_motion_buffer_process_hover (shell->motion_buffer,
+ state,
+ shell->proximity);
}
-
- gimp_motion_buffer_push_event_history (shell->motion_buffer,
- &image_coords);
}
return_val = TRUE;
@@ -1212,7 +1203,7 @@ gimp_display_shell_canvas_tool_events (GtkWidget *canvas,
}
void
-gimp_display_shell_buffer_motion (GimpMotionBuffer *buffer,
+gimp_display_shell_buffer_stroke (GimpMotionBuffer *buffer,
const GimpCoords *coords,
guint32 time,
GdkModifierType state,
@@ -1233,6 +1224,28 @@ gimp_display_shell_buffer_motion (GimpMotionBuffer *buffer,
}
}
+void
+gimp_display_shell_buffer_hover (GimpMotionBuffer *buffer,
+ const GimpCoords *coords,
+ GdkModifierType state,
+ gboolean proximity,
+ GimpDisplayShell *shell)
+{
+ GimpDisplay *display = shell->display;
+ Gimp *gimp = gimp_display_get_gimp (display);
+ GimpTool *active_tool;
+
+ active_tool = tool_manager_get_active (gimp);
+
+ if (active_tool &&
+ ! gimp_tool_control_is_active (active_tool->control))
+ {
+ tool_manager_oper_update_active (gimp,
+ coords, state, proximity,
+ display);
+ }
+}
+
static gboolean
gimp_display_shell_ruler_button_press (GtkWidget *widget,
GdkEventButton *event,
diff --git a/app/display/gimpdisplayshell-tool-events.h b/app/display/gimpdisplayshell-tool-events.h
index 0c6fddf..0ceeb6f 100644
--- a/app/display/gimpdisplayshell-tool-events.h
+++ b/app/display/gimpdisplayshell-tool-events.h
@@ -26,11 +26,16 @@ gboolean gimp_display_shell_events (GtkWidget *widget,
gboolean gimp_display_shell_canvas_tool_events (GtkWidget *widget,
GdkEvent *event,
GimpDisplayShell *shell);
-void gimp_display_shell_buffer_motion (GimpMotionBuffer *buffer,
+void gimp_display_shell_buffer_stroke (GimpMotionBuffer *buffer,
const GimpCoords *coords,
guint32 time,
GdkModifierType state,
GimpDisplayShell *shell);
+void gimp_display_shell_buffer_hover (GimpMotionBuffer *buffer,
+ const GimpCoords *coords,
+ GdkModifierType state,
+ gboolean proximity,
+ GimpDisplayShell *shell);
gboolean gimp_display_shell_hruler_button_press (GtkWidget *widget,
GdkEventButton *bevent,
diff --git a/app/display/gimpdisplayshell.c b/app/display/gimpdisplayshell.c
index a38fef3..b628478 100644
--- a/app/display/gimpdisplayshell.c
+++ b/app/display/gimpdisplayshell.c
@@ -307,8 +307,11 @@ gimp_display_shell_init (GimpDisplayShell *shell)
shell->motion_buffer = gimp_motion_buffer_new ();
- g_signal_connect (shell->motion_buffer, "motion",
- G_CALLBACK (gimp_display_shell_buffer_motion),
+ g_signal_connect (shell->motion_buffer, "stroke",
+ G_CALLBACK (gimp_display_shell_buffer_stroke),
+ shell);
+ g_signal_connect (shell->motion_buffer, "hover",
+ G_CALLBACK (gimp_display_shell_buffer_hover),
shell);
shell->zoom_focus_pointer_queue = g_queue_new ();
diff --git a/app/display/gimpmotionbuffer.c b/app/display/gimpmotionbuffer.c
index fa56966..5ec57a3 100644
--- a/app/display/gimpmotionbuffer.c
+++ b/app/display/gimpmotionbuffer.c
@@ -47,7 +47,8 @@ enum
enum
{
- MOTION,
+ STROKE,
+ HOVER,
LAST_SIGNAL
};
@@ -66,6 +67,11 @@ static void gimp_motion_buffer_get_property (GObject *object
GValue *value,
GParamSpec *pspec);
+static void gimp_motion_buffer_push_event_history (GimpMotionBuffer *buffer,
+ const GimpCoords *coords);
+static void gimp_motion_buffer_pop_event_queue (GimpMotionBuffer *buffer,
+ GimpCoords *coords);
+
static void gimp_motion_buffer_interpolate_stroke (GimpMotionBuffer *buffer,
GimpCoords *coords);
static gboolean gimp_motion_buffer_event_queue_timeout (GimpMotionBuffer *buffer);
@@ -85,11 +91,11 @@ gimp_motion_buffer_class_init (GimpMotionBufferClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
- motion_buffer_signals[MOTION] =
- g_signal_new ("motion",
+ motion_buffer_signals[STROKE] =
+ g_signal_new ("stroke",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_FIRST,
- G_STRUCT_OFFSET (GimpMotionBufferClass, motion),
+ G_STRUCT_OFFSET (GimpMotionBufferClass, stroke),
NULL, NULL,
gimp_marshal_VOID__POINTER_UINT_FLAGS,
G_TYPE_NONE, 3,
@@ -97,6 +103,18 @@ gimp_motion_buffer_class_init (GimpMotionBufferClass *klass)
G_TYPE_UINT,
GDK_TYPE_MODIFIER_TYPE);
+ motion_buffer_signals[HOVER] =
+ g_signal_new ("hover",
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_FIRST,
+ G_STRUCT_OFFSET (GimpMotionBufferClass, hover),
+ NULL, NULL,
+ gimp_marshal_VOID__POINTER_FLAGS_BOOLEAN,
+ G_TYPE_NONE, 3,
+ G_TYPE_POINTER,
+ GDK_TYPE_MODIFIER_TYPE,
+ G_TYPE_BOOLEAN);
+
object_class->constructed = gimp_motion_buffer_constructed;
object_class->dispose = gimp_motion_buffer_dispose;
object_class->finalize = gimp_motion_buffer_finalize;
@@ -189,7 +207,7 @@ gimp_motion_buffer_new (void)
}
void
-gimp_motion_buffer_start_stroke (GimpMotionBuffer *buffer,
+gimp_motion_buffer_begin_stroke (GimpMotionBuffer *buffer,
guint32 time,
GimpCoords *last_motion)
{
@@ -202,7 +220,7 @@ gimp_motion_buffer_start_stroke (GimpMotionBuffer *buffer,
}
void
-gimp_motion_buffer_finish_stroke (GimpMotionBuffer *buffer)
+gimp_motion_buffer_end_stroke (GimpMotionBuffer *buffer)
{
g_return_if_fail (GIMP_IS_MOTION_BUFFER (buffer));
@@ -427,9 +445,9 @@ gimp_motion_buffer_motion_event (GimpMotionBuffer *buffer,
}
void
-gimp_motion_buffer_process_event_queue (GimpMotionBuffer *buffer,
- GdkModifierType state,
- guint32 time)
+gimp_motion_buffer_process_stroke (GimpMotionBuffer *buffer,
+ GdkModifierType state,
+ guint32 time)
{
GdkModifierType event_state;
gint keep = 0;
@@ -463,7 +481,7 @@ gimp_motion_buffer_process_event_queue (GimpMotionBuffer *buffer,
gimp_motion_buffer_pop_event_queue (buffer, &buf_coords);
- g_signal_emit (buffer, motion_buffer_signals[MOTION], 0,
+ g_signal_emit (buffer, motion_buffer_signals[STROKE], 0,
&buf_coords, time, event_state);
}
@@ -477,34 +495,47 @@ gimp_motion_buffer_process_event_queue (GimpMotionBuffer *buffer,
}
void
-gimp_motion_buffer_push_event_history (GimpMotionBuffer *buffer,
- const GimpCoords *coords)
+gimp_motion_buffer_process_hover (GimpMotionBuffer *buffer,
+ GdkModifierType state,
+ gboolean proximity)
{
g_return_if_fail (GIMP_IS_MOTION_BUFFER (buffer));
- g_return_if_fail (coords != NULL);
+ if (buffer->event_queue->len > 0)
+ {
+ GimpCoords buf_coords = g_array_index (buffer->event_queue,
+ GimpCoords,
+ buffer->event_queue->len - 1);
+
+ g_signal_emit (buffer, motion_buffer_signals[HOVER], 0,
+ &buf_coords, state, proximity);
+
+ g_array_set_size (buffer->event_queue, 0);
+ }
+}
+
+
+/* private functions */
+
+static void
+gimp_motion_buffer_push_event_history (GimpMotionBuffer *buffer,
+ const GimpCoords *coords)
+{
if (buffer->event_history->len == 4)
g_array_remove_index (buffer->event_history, 0);
g_array_append_val (buffer->event_history, *coords);
}
-void
+static void
gimp_motion_buffer_pop_event_queue (GimpMotionBuffer *buffer,
GimpCoords *coords)
{
- g_return_if_fail (GIMP_IS_MOTION_BUFFER (buffer));
- g_return_if_fail (coords != NULL);
- g_return_if_fail (buffer->event_queue->len > 0);
-
*coords = g_array_index (buffer->event_queue, GimpCoords, 0);
g_array_remove_index (buffer->event_queue, 0);
}
-
-/* private functions */
-
static void
gimp_motion_buffer_interpolate_stroke (GimpMotionBuffer *buffer,
GimpCoords *coords)
@@ -556,9 +587,9 @@ gimp_motion_buffer_event_queue_timeout (GimpMotionBuffer *buffer)
gimp_motion_buffer_push_event_history (buffer, &last_coords);
- gimp_motion_buffer_process_event_queue (buffer,
- buffer->last_active_state,
- buffer->last_read_motion_time);
+ gimp_motion_buffer_process_stroke (buffer,
+ buffer->last_active_state,
+ buffer->last_read_motion_time);
}
return FALSE;
diff --git a/app/display/gimpmotionbuffer.h b/app/display/gimpmotionbuffer.h
index e040e20..84da69f 100644
--- a/app/display/gimpmotionbuffer.h
+++ b/app/display/gimpmotionbuffer.h
@@ -62,10 +62,14 @@ struct _GimpMotionBufferClass
{
GtkBoxClass parent_class;
- void (* motion) (GimpMotionBuffer *buffer,
+ void (* stroke) (GimpMotionBuffer *buffer,
const GimpCoords *coords,
guint32 time,
GdkModifierType state);
+ void (* hover) (GimpMotionBuffer *buffer,
+ const GimpCoords *coords,
+ GdkModifierType state,
+ gboolean proximity);
};
@@ -73,10 +77,10 @@ GType gimp_motion_buffer_get_type (void) G_GNUC_CONST;
GimpMotionBuffer * gimp_motion_buffer_new (void);
-void gimp_motion_buffer_start_stroke (GimpMotionBuffer *buffer,
+void gimp_motion_buffer_begin_stroke (GimpMotionBuffer *buffer,
guint32 time,
GimpCoords *last_motion);
-void gimp_motion_buffer_finish_stroke (GimpMotionBuffer *buffer);
+void gimp_motion_buffer_end_stroke (GimpMotionBuffer *buffer);
gboolean gimp_motion_buffer_motion_event (GimpMotionBuffer *buffer,
GimpCoords *coords,
@@ -85,14 +89,12 @@ gboolean gimp_motion_buffer_motion_event (GimpMotionBuffer *buffer,
gdouble scale_y,
gboolean event_fill);
-void gimp_motion_buffer_push_event_history (GimpMotionBuffer *buffer,
- const GimpCoords *coords);
-void gimp_motion_buffer_pop_event_queue (GimpMotionBuffer *buffer,
- GimpCoords *coords);
-
-void gimp_motion_buffer_process_event_queue (GimpMotionBuffer *buffer,
+void gimp_motion_buffer_process_stroke (GimpMotionBuffer *buffer,
GdkModifierType state,
guint32 time);
+void gimp_motion_buffer_process_hover (GimpMotionBuffer *buffer,
+ GdkModifierType state,
+ gboolean proximity);
#endif /* __GIMP_MOTION_BUFFER_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]