mirror of https://github.com/GNOME/gimp.git
app: Implement canvas support for touchpad gesture zoom by pinch
This commit is contained in:
parent
51d1ab9bce
commit
a8b258cd84
|
@ -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 | \
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 ();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue