demo: Use pinch translation in the gestures demo
authorYariv Barkan <nushoin@users.noreply.github.com>
Sat, 14 Dec 2019 09:27:44 +0000 (11:27 +0200)
committerYariv Barkan <21448-yarivb@users.noreply.gitlab.gnome.org>
Fri, 17 Jan 2020 20:34:48 +0000 (22:34 +0200)
Add the pinch translation offset to the pinch gesture demo. That allows
moving the square around in addition to the already-supported rotate and
zoom.

demos/gtk-demo/gestures.c

index 8d53ae34344fe959cd2cf86afb3e9398e0a0cae3..4079ed950fd8d3fd5ba13303172adb4f2405b73f 100644 (file)
@@ -94,9 +94,12 @@ drawing_area_draw (GtkDrawingArea *area,
       cairo_pattern_t *pat;
       cairo_matrix_t matrix;
       gdouble angle, scale;
+      gdouble x_center, y_center;
+
+      gtk_gesture_get_bounding_box_center (GTK_GESTURE (zoom), &x_center, &y_center);
 
       cairo_get_matrix (cr, &matrix);
-      cairo_matrix_translate (&matrix, width / 2, height / 2);
+      cairo_matrix_translate (&matrix, x_center, y_center);
 
       cairo_save (cr);