[gtk+/wip/baedert/drawing: 242/306] widget: Adapt translate_coordinates to coordinate changes
- From: Timm Bäder <baedert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/baedert/drawing: 242/306] widget: Adapt translate_coordinates to coordinate changes
- Date: Fri, 23 Jun 2017 20:17:16 +0000 (UTC)
commit e06524f9a7b4ea6656a2324a71c5b8a18cf75eb6
Author: Timm Bäder <mail baedert org>
Date: Tue May 30 16:20:01 2017 +0200
widget: Adapt translate_coordinates to coordinate changes
gtk/gtkwidget.c | 25 ++++++++++++++-----------
1 files changed, 14 insertions(+), 11 deletions(-)
---
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index 2e81588..619a6b4 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -6951,21 +6951,24 @@ static void
translate_coordinates (GdkEvent *event,
GtkWidget *widget)
{
- GtkWidget *event_widget;
- gdouble xd, yd;
- gint x, y;
+ double x, y;
- if (!gdk_event_get_coords (event, &xd, &yd))
+ if (!gdk_event_get_coords (event, &x, &y))
return;
- event_widget = gtk_get_event_widget (event);
- /* FIXME: loses precision */
- x = xd;
- y = yd;
- gtk_widget_translate_coordinates (event_widget, widget,
- x, y, &x, &y);
+ /* @event's coordinates are in toplevel coordinates, so we can simply
+ * walk up the hierarchy starting at @widget to translate the coordinates. */
+ while (widget)
+ {
+ GtkAllocation alloc;
+
+ _gtk_widget_get_allocation (widget, &alloc);
+ x -= alloc.x;
+ y -= alloc.y;
+
+ widget = _gtk_widget_get_parent (widget);
+ }
- /*g_message ("New coords for %p: %d/%d (widget %s)", event, x, y, G_OBJECT_TYPE_NAME (widget));*/
gdk_event_set_coords (event, x, y);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]