event: Add accessor for the axes field

CLUTTER_BUTTON_* and CLUTTER_MOTION event types have axes data attached
to them, so we want to expose a common ClutterEvent method for
extracting that data.
This commit is contained in:
Emmanuele Bassi 2011-01-18 16:54:12 +00:00
parent 431200f40d
commit d805237c31
2 changed files with 59 additions and 0 deletions

View File

@ -989,3 +989,60 @@ _clutter_event_set_source_device (ClutterEvent *event,
real_event = (ClutterEventPrivate *) event;
real_event->source_device = device;
}
/**
* clutter_event_get_axes:
* @event: a #ClutterEvent
* @n_axes: (out): return location for the number of axes returned
*
* Retrieves the array of axes values attached to the event.
*
* Return value: (transfer none): an array of axis values
*
* Since: 1.6
*/
gdouble *
clutter_event_get_axes (const ClutterEvent *event,
guint *n_axes)
{
gdouble *retval = NULL;
guint len = 0;
switch (event->type)
{
case CLUTTER_NOTHING:
case CLUTTER_STAGE_STATE:
case CLUTTER_DESTROY_NOTIFY:
case CLUTTER_CLIENT_MESSAGE:
case CLUTTER_DELETE:
case CLUTTER_ENTER:
case CLUTTER_LEAVE:
case CLUTTER_SCROLL:
case CLUTTER_KEY_PRESS:
case CLUTTER_KEY_RELEASE:
break;
case CLUTTER_BUTTON_PRESS:
case CLUTTER_BUTTON_RELEASE:
retval = event->button.axes;
break;
case CLUTTER_MOTION:
retval = event->motion.axes;
break;
}
if (retval != NULL)
{
ClutterInputDevice *device;
device = clutter_event_get_device (event);
if (device != NULL)
len = clutter_input_device_get_n_axes (device);
}
if (n_axes)
*n_axes = len;
return retval;
}

View File

@ -410,6 +410,8 @@ ClutterStage * clutter_event_get_stage (const ClutterEvent
void clutter_event_get_coords (const ClutterEvent *event,
gfloat *x,
gfloat *y);
gdouble * clutter_event_get_axes (const ClutterEvent *event,
guint *n_axes);
guint clutter_event_get_key_symbol (const ClutterEvent *event);
guint16 clutter_event_get_key_code (const ClutterEvent *event);