gesture-action: Add clutter_gesture_action_get_last_event()
Export the last event received for each touch point in its entirety, instead of duplicating ClutterEvent accessors one at a time. examples/pan-action.c has been updated to show the type of the event that's causing the panning. https://bugzilla.gnome.org/show_bug.cgi?id=685737
This commit is contained in:
parent
61f2d751d0
commit
ccdbd36234
@ -103,6 +103,7 @@ typedef struct
|
|||||||
{
|
{
|
||||||
ClutterInputDevice *device;
|
ClutterInputDevice *device;
|
||||||
ClutterEventSequence *sequence;
|
ClutterEventSequence *sequence;
|
||||||
|
ClutterEvent *last_event;
|
||||||
|
|
||||||
gfloat press_x, press_y;
|
gfloat press_x, press_y;
|
||||||
gint64 last_motion_time;
|
gint64 last_motion_time;
|
||||||
@ -153,6 +154,7 @@ gesture_register_point (ClutterGestureAction *action, ClutterEvent *event)
|
|||||||
g_array_set_size (priv->points, priv->points->len + 1);
|
g_array_set_size (priv->points, priv->points->len + 1);
|
||||||
point = &g_array_index (priv->points, GesturePoint, priv->points->len - 1);
|
point = &g_array_index (priv->points, GesturePoint, priv->points->len - 1);
|
||||||
|
|
||||||
|
point->last_event = clutter_event_copy (event);
|
||||||
point->device = clutter_event_get_device (event);
|
point->device = clutter_event_get_device (event);
|
||||||
|
|
||||||
clutter_event_get_coords (event, &point->press_x, &point->press_y);
|
clutter_event_get_coords (event, &point->press_x, &point->press_y);
|
||||||
@ -220,6 +222,12 @@ gesture_get_threshold (ClutterGestureAction *action)
|
|||||||
return threshold;
|
return threshold;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
gesture_point_unset (GesturePoint *point)
|
||||||
|
{
|
||||||
|
clutter_event_free (point->last_event);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
cancel_gesture (ClutterGestureAction *action)
|
cancel_gesture (ClutterGestureAction *action)
|
||||||
{
|
{
|
||||||
@ -331,6 +339,9 @@ stage_captured_event_cb (ClutterActor *stage,
|
|||||||
return CLUTTER_EVENT_PROPAGATE;
|
return CLUTTER_EVENT_PROPAGATE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
clutter_event_free (point->last_event);
|
||||||
|
point->last_event = clutter_event_copy (event);
|
||||||
|
|
||||||
point->last_delta_x = motion_x - point->last_motion_x;
|
point->last_delta_x = motion_x - point->last_motion_x;
|
||||||
point->last_delta_y = motion_y - point->last_motion_y;
|
point->last_delta_y = motion_y - point->last_motion_y;
|
||||||
point->last_motion_x = motion_x;
|
point->last_motion_x = motion_x;
|
||||||
@ -364,6 +375,9 @@ stage_captured_event_cb (ClutterActor *stage,
|
|||||||
{
|
{
|
||||||
clutter_event_get_coords (event, &point->release_x, &point->release_y);
|
clutter_event_get_coords (event, &point->release_x, &point->release_y);
|
||||||
|
|
||||||
|
clutter_event_free (point->last_event);
|
||||||
|
point->last_event = clutter_event_copy (event);
|
||||||
|
|
||||||
if (priv->in_gesture &&
|
if (priv->in_gesture &&
|
||||||
((priv->points->len - 1) < priv->requested_nb_points))
|
((priv->points->len - 1) < priv->requested_nb_points))
|
||||||
{
|
{
|
||||||
@ -618,6 +632,8 @@ clutter_gesture_action_init (ClutterGestureAction *self)
|
|||||||
ClutterGestureActionPrivate);
|
ClutterGestureActionPrivate);
|
||||||
|
|
||||||
self->priv->points = g_array_sized_new (FALSE, TRUE, sizeof (GesturePoint), 3);
|
self->priv->points = g_array_sized_new (FALSE, TRUE, sizeof (GesturePoint), 3);
|
||||||
|
g_array_set_clear_func (self->priv->points, (GDestroyNotify) gesture_point_unset);
|
||||||
|
|
||||||
self->priv->requested_nb_points = 1;
|
self->priv->requested_nb_points = 1;
|
||||||
self->priv->edge = CLUTTER_GESTURE_TRIGGER_EDGE_AFTER;
|
self->priv->edge = CLUTTER_GESTURE_TRIGGER_EDGE_AFTER;
|
||||||
}
|
}
|
||||||
@ -955,6 +971,32 @@ clutter_gesture_action_get_device (ClutterGestureAction *action,
|
|||||||
return g_array_index (action->priv->points, GesturePoint, point).device;
|
return g_array_index (action->priv->points, GesturePoint, point).device;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* clutter_gesture_action_get_last_event:
|
||||||
|
* @action: a #ClutterGestureAction
|
||||||
|
* @point: index of a point currently active
|
||||||
|
*
|
||||||
|
* Retrieves a reference to the last #ClutterEvent for a touch point. Call
|
||||||
|
* clutter_event_copy() if you need to store the reference somewhere.
|
||||||
|
*
|
||||||
|
* Return value: (transfer none): the last #ClutterEvent for a touch point.
|
||||||
|
*
|
||||||
|
* Since: 1.14
|
||||||
|
*/
|
||||||
|
const ClutterEvent *
|
||||||
|
clutter_gesture_action_get_last_event (ClutterGestureAction *action,
|
||||||
|
guint point)
|
||||||
|
{
|
||||||
|
GesturePoint *gesture_point;
|
||||||
|
|
||||||
|
g_return_val_if_fail (CLUTTER_IS_GESTURE_ACTION (action), NULL);
|
||||||
|
g_return_val_if_fail (action->priv->points->len > point, NULL);
|
||||||
|
|
||||||
|
gesture_point = &g_array_index (action->priv->points, GesturePoint, point);
|
||||||
|
|
||||||
|
return gesture_point->last_event;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* clutter_gesture_action_cancel:
|
* clutter_gesture_action_cancel:
|
||||||
* @action: a #ClutterGestureAction
|
* @action: a #ClutterGestureAction
|
||||||
|
@ -142,6 +142,10 @@ CLUTTER_AVAILABLE_IN_1_12
|
|||||||
ClutterInputDevice * clutter_gesture_action_get_device (ClutterGestureAction *action,
|
ClutterInputDevice * clutter_gesture_action_get_device (ClutterGestureAction *action,
|
||||||
guint point);
|
guint point);
|
||||||
|
|
||||||
|
CLUTTER_AVAILABLE_IN_1_14
|
||||||
|
const ClutterEvent * clutter_gesture_action_get_last_event (ClutterGestureAction *action,
|
||||||
|
guint point);
|
||||||
|
|
||||||
CLUTTER_AVAILABLE_IN_1_12
|
CLUTTER_AVAILABLE_IN_1_12
|
||||||
void clutter_gesture_action_cancel (ClutterGestureAction *action);
|
void clutter_gesture_action_cancel (ClutterGestureAction *action);
|
||||||
|
|
||||||
|
@ -735,6 +735,7 @@ clutter_geometry_intersects
|
|||||||
clutter_geometry_union
|
clutter_geometry_union
|
||||||
clutter_gesture_action_cancel
|
clutter_gesture_action_cancel
|
||||||
clutter_gesture_action_get_device
|
clutter_gesture_action_get_device
|
||||||
|
clutter_gesture_action_get_last_event
|
||||||
clutter_gesture_action_get_motion_coords
|
clutter_gesture_action_get_motion_coords
|
||||||
clutter_gesture_action_get_motion_delta
|
clutter_gesture_action_get_motion_delta
|
||||||
clutter_gesture_action_get_n_current_points
|
clutter_gesture_action_get_n_current_points
|
||||||
|
@ -2940,6 +2940,7 @@ clutter_snap_constraint_get_type
|
|||||||
ClutterGestureAction
|
ClutterGestureAction
|
||||||
ClutterGestureActionClass
|
ClutterGestureActionClass
|
||||||
clutter_gesture_action_new
|
clutter_gesture_action_new
|
||||||
|
clutter_gesture_action_get_last_event
|
||||||
clutter_gesture_action_get_press_coords
|
clutter_gesture_action_get_press_coords
|
||||||
clutter_gesture_action_get_motion_coords
|
clutter_gesture_action_get_motion_coords
|
||||||
clutter_gesture_action_get_motion_delta
|
clutter_gesture_action_get_motion_delta
|
||||||
|
@ -42,13 +42,22 @@ on_pan (ClutterPanAction *action,
|
|||||||
gpointer *user_data)
|
gpointer *user_data)
|
||||||
{
|
{
|
||||||
gfloat delta_x, delta_y;
|
gfloat delta_x, delta_y;
|
||||||
|
const ClutterEvent *event = NULL;
|
||||||
|
|
||||||
if (is_interpolated)
|
if (is_interpolated)
|
||||||
clutter_pan_action_get_interpolated_delta (action, &delta_x, &delta_y);
|
clutter_pan_action_get_interpolated_delta (action, &delta_x, &delta_y);
|
||||||
else
|
else
|
||||||
|
{
|
||||||
clutter_gesture_action_get_motion_delta (CLUTTER_GESTURE_ACTION (action), 0, &delta_x, &delta_y);
|
clutter_gesture_action_get_motion_delta (CLUTTER_GESTURE_ACTION (action), 0, &delta_x, &delta_y);
|
||||||
|
event = clutter_gesture_action_get_last_event (CLUTTER_GESTURE_ACTION (action), 0);
|
||||||
|
}
|
||||||
|
|
||||||
g_print ("panning dx:%.2f dy:%.2f\n", delta_x, delta_y);
|
g_print ("[%s] panning dx:%.2f dy:%.2f\n",
|
||||||
|
event == NULL ? "INTERPOLATED" :
|
||||||
|
event->type == CLUTTER_MOTION ? "MOTION" :
|
||||||
|
event->type == CLUTTER_TOUCH_UPDATE ? "TOUCH UPDATE" :
|
||||||
|
"?",
|
||||||
|
delta_x, delta_y);
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user