[gtk/global-coords: 13/37] surface: Add coordinate translation
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/global-coords: 13/37] surface: Add coordinate translation
- Date: Wed, 29 May 2019 18:04:51 +0000 (UTC)
commit 902a49af9deccdd5d500e9e2a5b27c49c3960b82
Author: Matthias Clasen <mclasen redhat com>
Date: Tue May 28 23:41:56 2019 -0400
surface: Add coordinate translation
We maintain offsets for popups, so we can translate
coordinates between surfaces that are attached directly
or indirectly to the same toplevel. Add an api for that.
gdk/gdksurface.c | 38 ++++++++++++++++++++++++++++++++++++++
gdk/gdksurface.h | 6 ++++++
2 files changed, 44 insertions(+)
---
diff --git a/gdk/gdksurface.c b/gdk/gdksurface.c
index b3f0c64223..fc30d532d9 100644
--- a/gdk/gdksurface.c
+++ b/gdk/gdksurface.c
@@ -4076,3 +4076,41 @@ gdk_surface_handle_event (GdkEvent *event)
return handled;
}
+
+gboolean
+gdk_surface_translate_coordinates (GdkSurface *from,
+ GdkSurface *to,
+ double *x,
+ double *y)
+{
+ int x1, y1, x2, y2;
+ GdkSurface *f, *t;
+
+ x1 = 0;
+ y1 = 0;
+ f = from;
+ while (f->parent)
+ {
+ x1 += f->x;
+ y1 += f->y;
+ f = f->parent;
+ }
+
+ x2 = 0;
+ y2 = 0;
+ t = to;
+ while (t->parent)
+ {
+ x2 += t->x;
+ y2 += t->y;
+ t = t->parent;
+ }
+
+ if (f != t)
+ return FALSE;
+
+ *x += x1 - x2;
+ *y += y1 - y2;
+
+ return TRUE;
+}
diff --git a/gdk/gdksurface.h b/gdk/gdksurface.h
index b02d40192a..acca090683 100644
--- a/gdk/gdksurface.h
+++ b/gdk/gdksurface.h
@@ -557,6 +557,12 @@ gint gdk_surface_get_origin (GdkSurface *surface,
gint *x,
gint *y);
GDK_AVAILABLE_IN_ALL
+gboolean gdk_surface_translate_coordinates (GdkSurface *from,
+ GdkSurface *to,
+ double *x,
+ double *y);
+
+GDK_AVAILABLE_IN_ALL
void gdk_surface_get_frame_extents (GdkSurface *surface,
GdkRectangle *rect);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]