jcupitt / vipsdisp

Tiny libvips / gtk+4 image viewer
MIT License
143 stars 11 forks source link

Add Pinch zoom support #8

Closed earboxer closed 2 years ago

earboxer commented 2 years ago

Closes #6

Currently, this zooms from the center of the display (rather than from the center of the pinch/expand).

(It might be worth looking into how eog does this, since they seem to implement it correctly).

jcupitt commented 2 years ago

Hi @earboxer, this is a nice thing.

I don't have a touch display on my elderly laptop, so I can't really help, unfortunately :(

I suppose we'd need to get the two touch positions and calculate a scale and translate which mapped the two image points to those positions. Imagewindow does this for single points for drag, so it'd be a two point version of that.

The drag code uses these:

        /* Last known mouse postion, in gtk coordinates. We keep these in gtk
         * cods so we don't need to update them on pan / zoom.
         */
        double last_x_gtk;
        double last_y_gtk;

        /* For drag, the window position where we started, in gtk coordinates.
         */
        int drag_start_x;
        int drag_start_y;
jcupitt commented 2 years ago

Looking at GtkGestureZoom you'd think it should emit drag signals for this, strange.

... but perhaps we should merge this and improve pinch zoom in another PR.

earboxer commented 2 years ago

I figured it out. Since GtkGestureZoom extends GtkGesture, we can get a bunch of info about it, in this case, the center of the gesture when it started.

This is ready to be merged now!

jcupitt commented 2 years ago

Nice!

jcupitt commented 2 years ago

... I added a line to the CHANGELOG for this, and credited you. I hope that's OK.

earboxer commented 2 years ago

Merging it sounds fine, though maybe we should add a todo comment?

Either way, I'm fine.

jcupitt commented 2 years ago

Good idea, I added a note.