xaos-project / XaoS

Real-time interactive fractal zoomer
https://xaos-project.github.io/
GNU General Public License v2.0
513 stars 59 forks source link

Add track pad gestures #134

Open jblang opened 4 years ago

jblang commented 4 years ago

In the original Cocoa driver, I had implemented the panning gesture (two fingered drag) for trackpads, but this was lost when we switched to Qt. I would like to bring this feature back in Qt, which also supports gestures but will require additional code. It might also be desirable to add pinch gestures to zoom, unzoom, and rotate, but I think these would be considerably more work.

arpithindukuri commented 4 years ago

Hello, I am running XaoS 4.0 Pre-Release 4 on a Windows 10 laptop, and pinching to zoom and unzoom seems to work. What trackpad gesture do you propose for rotation?

jblang commented 4 years ago

Do you mean that you have added a patch to do this, or the code works as is?

For rotation I would use a two fingered rotating gesture similar to the one used on iPhone etc for photo rotation.

arpithindukuri commented 4 years ago

The code works as is for pinch to zoom and unzoom. Scrolling up and down, and scrolling left and right with 2 fingers also zooms and unzooms.

When I was using linux, I found that pinch to zoom did not work at all out of the box. Could it be that zoom works becuase of a driver I have installed on my windows machine?

jblang commented 4 years ago

I think your mouse driver is emulating the scroll wheel using these gestures. There is no code in XaoS yet to explicitly support gestures.

arpithindukuri commented 4 years ago

That makes sense.

I will try and make some time to implement the rotation gesture, and once I figure out how to work around my touchpad driver emulating the scroll wheel, I can try to implement pinch-to-zoom and panning as well.

Do you have any suggestions for C++ touchpad libraries I can use to do this? Gainput seems promising.

Apologies if this is the wrong place to ask this, but would you know in which file I can find the code that currently implements zooming?

jblang commented 4 years ago

Qt has builtin support for gestures... see https://doc.qt.io/qt-5/gestures-overview.html

On Mon, Mar 23, 2020 at 7:14 PM arpithindukuri notifications@github.com wrote:

That makes sense.

I will try and make some time to implement the rotation gesture, and once I figure out how to work around my touchpad driver emulating the scroll wheel, I can try to implement pinch-to-zoom and panning as well.

Do you have any suggestions for C++ touchpad libraries I can use to do this? Gainput https://github.com/jkuhlmann/gainput seems promising.

Apologies if this is the wrong place to ask this, but would you know in which file I can find the code that currently implements zooming?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/xaos-project/XaoS/issues/134#issuecomment-602928090, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAHHNZS52YSKVAMMUMNZHILRI73ORANCNFSM4KOUD7BA .

jblang commented 4 years ago

Gesture event handlers should be implemented on FractalWidget and pass the mouse buttons and coordinates to MainWindow

XaoS code itself has no concept of gestures; you must generate the correct combination of mouse buttons and coordinates to trigger the correct effect for the gestures. The mouse buttons and X,Y coordinates are stored in class variables on MainWindow and passed to the uih_update function during the execution processEvents. You shouldn't need to modify that code, just add code to set the class variables for X,Y coordinates and button combination as appropriate for the gesture event. The constants used by XaoS are BUTTON1 to zoom in, BUTTON2 to pan, and BUTTON3 to zoom out.

When you detect a two-fingered swipe, you will want to set mouseButtons |= BUTTON2 to make it pan and add the X, Y delta for the pan gesture to the previous X,Y coordinates. You can look at how I implemented two-finger scrolling for the Mac as an example but obviously you will have to rewrite the logic to work with Qt: https://github.com/xaos-project/XaoS/blob/release-3.7/src/ui/ui-drv/cocoa/FractalView.m#L138

I would just focus on getting panning to work with two-fingered swipe first, and leave the rest of the gestures for later as they will be more complicated to implement.

For zoom in and out, you would probably have to calculate the center point between two fingers and use that as X,Y and then apply BUTTON1 or BUTTON3 to zoom in or out depending on the direction of the pinch. For rotation, a special rotation mode has to be engaged by calling uih_fastrotate, then BUTTON1 is used to rotate it. You will have to figure out how to translate the gesture coordinates to the correct X,Y to trigger a proper rotation; I am not sure myself.

arpithindukuri commented 4 years ago

Thank you, this is very helpful. I will begin work on implementing touchpad panning.