gdk: Add gdk_event_set_coords() method

A helper function basically for gtk+, so coordinates can be translated
in place depending on the widget it's being delivered to.
This commit is contained in:
Carlos Garnacho 2017-03-31 16:51:42 +02:00
parent 53c297436d
commit 799428aaea
2 changed files with 57 additions and 0 deletions

View File

@ -1198,6 +1198,59 @@ gdk_event_get_root_coords (const GdkEvent *event,
return fetched;
}
void
gdk_event_set_coords (GdkEvent *event,
gdouble x,
gdouble y)
{
g_return_if_fail (event != NULL);
switch (event->type)
{
case GDK_CONFIGURE:
event->configure.x = x;
event->configure.y = y;
break;
case GDK_ENTER_NOTIFY:
case GDK_LEAVE_NOTIFY:
event->crossing.x = x;
event->crossing.y = y;
break;
case GDK_SCROLL:
event->scroll.x = x;
event->scroll.y = y;
break;
case GDK_BUTTON_PRESS:
case GDK_2BUTTON_PRESS:
case GDK_3BUTTON_PRESS:
case GDK_BUTTON_RELEASE:
event->button.x = x;
event->button.y = y;
break;
case GDK_TOUCH_BEGIN:
case GDK_TOUCH_UPDATE:
case GDK_TOUCH_END:
case GDK_TOUCH_CANCEL:
event->touch.x = x;
event->touch.y = y;
break;
case GDK_MOTION_NOTIFY:
event->motion.x = x;
event->motion.y = y;
break;
case GDK_TOUCHPAD_SWIPE:
event->touchpad_swipe.x = x;
event->touchpad_swipe.y = y;
break;
case GDK_TOUCHPAD_PINCH:
event->touchpad_pinch.x = x;
event->touchpad_pinch.y = y;
break;
default:
break;
}
}
/**
* gdk_event_get_button:
* @event: a #GdkEvent

View File

@ -1461,6 +1461,10 @@ GDK_AVAILABLE_IN_ALL
gboolean gdk_event_get_coords (const GdkEvent *event,
gdouble *x_win,
gdouble *y_win);
GDK_AVAILABLE_IN_3_90
void gdk_event_set_coords (GdkEvent *event,
gdouble x,
gdouble y);
GDK_AVAILABLE_IN_ALL
gboolean gdk_event_get_root_coords (const GdkEvent *event,
gdouble *x_root,