[gimp] app: Implement canvas support for touchpad gesture zoom by pinch
- From: Jehan <jehanp src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] app: Implement canvas support for touchpad gesture zoom by pinch
- Date: Thu, 22 Apr 2021 18:21:55 +0000 (UTC)
commit a8b258cd84693b505e45fcfe8d4ab232072d923f
Author: Povilas Kanapickas <povilas radix lt>
Date: Tue Jan 26 22:14:45 2021 +0200
app: Implement canvas support for touchpad gesture zoom by pinch
app/display/gimpcanvas.h | 1 +
app/display/gimpdisplayshell-scale.c | 3 +++
app/display/gimpdisplayshell-tool-events.c | 23 +++++++++++++++++++++++
app/display/gimpdisplayshell-tool-events.h | 7 +++++++
app/display/gimpdisplayshell.c | 12 ++++++++++++
app/display/gimpdisplayshell.h | 4 ++++
app/widgets/gimppaletteeditor.c | 3 ++-
7 files changed, 52 insertions(+), 1 deletion(-)
---
diff --git a/app/display/gimpcanvas.h b/app/display/gimpcanvas.h
index cb81f71897..0844b0a344 100644
--- a/app/display/gimpcanvas.h
+++ b/app/display/gimpcanvas.h
@@ -28,6 +28,7 @@
GDK_BUTTON_RELEASE_MASK | \
GDK_SCROLL_MASK | \
GDK_SMOOTH_SCROLL_MASK | \
+ GDK_TOUCHPAD_GESTURE_MASK | \
GDK_STRUCTURE_MASK | \
GDK_ENTER_NOTIFY_MASK | \
GDK_LEAVE_NOTIFY_MASK | \
diff --git a/app/display/gimpdisplayshell-scale.c b/app/display/gimpdisplayshell-scale.c
index 8e61eb47ae..26afbbbf22 100644
--- a/app/display/gimpdisplayshell-scale.c
+++ b/app/display/gimpdisplayshell-scale.c
@@ -516,6 +516,9 @@ gimp_display_shell_scale (GimpDisplayShell *shell,
if (zoom_type == GIMP_ZOOM_SMOOTH)
delta = -new_scale;
+ if (zoom_type == GIMP_ZOOM_PINCH)
+ delta = new_scale;
+
if (zoom_type != GIMP_ZOOM_TO)
new_scale = gimp_zoom_model_zoom_step (zoom_type, current_scale, delta);
diff --git a/app/display/gimpdisplayshell-tool-events.c b/app/display/gimpdisplayshell-tool-events.c
index 917b16845a..487a95a158 100644
--- a/app/display/gimpdisplayshell-tool-events.c
+++ b/app/display/gimpdisplayshell-tool-events.c
@@ -1247,6 +1247,29 @@ gimp_display_shell_canvas_grab_notify (GtkWidget *canvas,
}
}
+void
+gimp_display_shell_zoom_gesture_begin (GtkGestureZoom *gesture,
+ GdkEventSequence *sequence,
+ GimpDisplayShell *shell)
+{
+ shell->last_zoom_scale = gtk_gesture_zoom_get_scale_delta (gesture);
+}
+
+void
+gimp_display_shell_zoom_gesture_update (GtkGestureZoom *gesture,
+ GdkEventSequence *sequence,
+ GimpDisplayShell *shell)
+{
+ gdouble current_scale = gtk_gesture_zoom_get_scale_delta (gesture);
+ gdouble delta = (current_scale - shell->last_zoom_scale) / shell->last_zoom_scale;
+ shell->last_zoom_scale = current_scale;
+
+ gimp_display_shell_scale (shell,
+ GIMP_ZOOM_PINCH,
+ delta,
+ GIMP_ZOOM_FOCUS_POINTER);
+}
+
void
gimp_display_shell_buffer_stroke (GimpMotionBuffer *buffer,
const GimpCoords *coords,
diff --git a/app/display/gimpdisplayshell-tool-events.h b/app/display/gimpdisplayshell-tool-events.h
index 4458a926ac..6539640c11 100644
--- a/app/display/gimpdisplayshell-tool-events.h
+++ b/app/display/gimpdisplayshell-tool-events.h
@@ -30,6 +30,13 @@ void gimp_display_shell_canvas_grab_notify (GtkWidget *widget,
gboolean was_grabbed,
GimpDisplayShell *shell);
+void gimp_display_shell_zoom_gesture_begin (GtkGestureZoom *gesture,
+ GdkEventSequence *sequence,
+ GimpDisplayShell *shell);
+void gimp_display_shell_zoom_gesture_update (GtkGestureZoom *gesture,
+ GdkEventSequence *sequence,
+ GimpDisplayShell *shell);
+
void gimp_display_shell_buffer_stroke (GimpMotionBuffer *buffer,
const GimpCoords *coords,
guint32 time,
diff --git a/app/display/gimpdisplayshell.c b/app/display/gimpdisplayshell.c
index 2ca4039a40..957dea8f51 100644
--- a/app/display/gimpdisplayshell.c
+++ b/app/display/gimpdisplayshell.c
@@ -521,6 +521,10 @@ gimp_display_shell_constructed (GObject *object)
gimp_display_shell_dnd_init (shell);
gimp_display_shell_selection_init (shell);
+ shell->zoom_gesture = gtk_gesture_zoom_new (GTK_WIDGET (shell->canvas));
+ gtk_event_controller_set_propagation_phase (GTK_EVENT_CONTROLLER (shell->zoom_gesture),
+ GTK_PHASE_CAPTURE);
+
/* the horizontal ruler */
shell->hrule = gimp_ruler_new (GTK_ORIENTATION_HORIZONTAL);
gtk_widget_set_events (GTK_WIDGET (shell->hrule),
@@ -607,6 +611,12 @@ gimp_display_shell_constructed (GObject *object)
g_signal_connect (shell->canvas, "key-release-event",
G_CALLBACK (gimp_display_shell_canvas_tool_events),
shell);
+ g_signal_connect (shell->zoom_gesture, "begin",
+ G_CALLBACK (gimp_display_shell_zoom_gesture_begin),
+ shell);
+ g_signal_connect (shell->zoom_gesture, "update",
+ G_CALLBACK (gimp_display_shell_zoom_gesture_update),
+ shell);
/* the zoom button */
shell->zoom_button = g_object_new (GTK_TYPE_CHECK_BUTTON,
@@ -757,6 +767,8 @@ gimp_display_shell_dispose (GObject *object)
shell->filter_idle_id = 0;
}
+ g_clear_object (&shell->zoom_gesture);
+
g_clear_pointer (&shell->render_cache, cairo_surface_destroy);
g_clear_pointer (&shell->render_cache_valid, cairo_region_destroy);
diff --git a/app/display/gimpdisplayshell.h b/app/display/gimpdisplayshell.h
index 389370b464..8815b7e7b4 100644
--- a/app/display/gimpdisplayshell.h
+++ b/app/display/gimpdisplayshell.h
@@ -99,6 +99,7 @@ struct _GimpDisplayShell
GList *children;
GtkWidget *canvas; /* GimpCanvas widget */
+ GtkGesture *zoom_gesture; /* Zoom gesture handler for the canvas*/
GtkAdjustment *hsbdata; /* adjustments */
GtkAdjustment *vsbdata;
@@ -203,6 +204,9 @@ struct _GimpDisplayShell
GdkDevice *grab_keyboard_source;
guint32 grab_keyboard_time;
+ /* the state of gimp_display_shell_zoom_gesture_*() */
+ gdouble last_zoom_scale;
+
/* Two states are possible when the shell is grabbed: it can be
* grabbed with space (or space+button1 which is the same state),
* then if space is released but button1 was still pressed, we wait
diff --git a/app/widgets/gimppaletteeditor.c b/app/widgets/gimppaletteeditor.c
index a5b039566e..6abee86f45 100644
--- a/app/widgets/gimppaletteeditor.c
+++ b/app/widgets/gimppaletteeditor.c
@@ -610,7 +610,8 @@ gimp_palette_editor_zoom (GimpPaletteEditor *editor,
}
break;
- case GIMP_ZOOM_SMOOTH: /* can't happen */
+ case GIMP_ZOOM_SMOOTH:
+ case GIMP_ZOOM_PINCH: /* can't happen */
g_return_if_reached ();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]