-
Notifications
You must be signed in to change notification settings - Fork 537
mac: Support for pan, zoom and rotate trackpad gestures #1093
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
@tomsci I'm very glad to see you are familiar with Mac GUI programming. I'm sure this is a huge improvement but I can't believe it was unusable before. For rotating there is We "recently" had a nice long "chat" about mice, trackpads (of differents sophistication) and touch screens here #825. It was in the context of smooth scrolling (zooming), which now works on Mac and Windows. One extra result is that now there is Also be aware (if you are not already) of "turntable navigation" and |
They don't work for me on my mac :) I should have added "depending on your trackpad and dexterity" - it is possible to rotate with shift-two-finger-click-drag (which is simulating shift-right-click-drag) but that is a very awkward gesture compared to shift-two-finger-drag (ie without the "click") which is what I've added. And to be honest I've only just discovered that shift-two-finger-click-drag works - it's not a standard finger contortion that I'm accustomed to performing. Mac trackpads are easiest to use with 2-finger gestures that don't require clicks, and those unfortunately require a chunk more code to support compared to the basic mouse case. I'm just relieved it wasn't necessary to drop down to the level of counting individual touches on the trackpad! So yes it's true it's not "unusable", but I spent some few minutes clicking around and didn't figure it out when I first started using SolveSpace, and again when I started coding this PR, so it's not obvious :) |
Oh you are rigtht - sorry - it is |
|
Looks well contained and not very big changes for what's covered by this PR. |
|
Cool! I just tested this and found the following things (might not all be caused by this PR though 😉)
A bit off-topic, but dumping it here anyways as it might be interesting: I once tried to expand the "turntable nav" to also allow locking on the X or Y axis (see my half-failed attempt here: vespakoen@97630bd) |
I've never seen that before.
Sliding fingers to the right should move the sketch to the right. Some people have complained that it feels backward and they seem to want the camera to move right, but moving the sketch is how solvespace works.
I think being able to select a point and rotate around it would be a huge benefit when looking at things up close / zoomed in. But that's not part of this. |
|
I tried rerunning this one and it failed again, I assume it's because the fix was not present when the PR was created. Since macOS tests can pass now, is there a way to rebase a PR and rerun tests? |
|
git fetch origin |
Yep I will rebase and force push. Stand by, just writing another comment :) |
Well yeah, but I meant through github since I'm not on my dev machine ;-) They have a "rebase and merge" button, but not just a plain rebase. They also allow you to rerun the tests. |
Darn, I really thought I'd got away with that! That's the downside of shoehorning this in via simulated I debated refactoring I also tried using As an aside, why does middle-click rotate always rotate around the centre of the scene/window rather than around the location that was clicked on? This has always felt weird to me especially when zoomed far in, where a small rotate around the centre will quickly make the thing you were interested in vanish unless you made sure to centre it in the window on the thing of interest first. It seems to be how fusion does it too, but I don't really understand why - rotating around where you clicked definitely feels more natural to me. Anyway, I digress... I'm not sure how best to fix the hover text thing without significant additional refactoring. Which I don't mind attempting, but the likelihood of messing something up for another platform/usecase will be higher. Suggestions welcome on what would be best to do here :)
The pan behaviour should follow the standard mac behaviour - when "natural scrolling" is off, dragging down moves the content up, and dragging left moves the content to the right. When "Natural scrolling is on", dragging down moves the content down (but dragging left still moves content to the right, go figure...). That's what how standard apps like Preview.app behave and behaving the same as that seemed like the best option. |
Currently SolveSpace is nearly unusable on a mac if you only have a buttonless trackpad and not a mouse, because there's no way to pan (ie right-click-drag) or rotate (ie middle-click-drag). You can zoom, but only by using two-finger-drag up and down, which ends up getting interpreted as a scrollwheel event. This change makes the app behave much more like any other mac app, by adding 2-finger-drag pan gesture support and pinch-gesture zooming, and 3D rotate using shift-2-finger-drag. I've also added support for the rotate two-finger trackpad gesture, which rotates directly around the screen Z axis (rather than in all 3 dimensions) which is actually something I've found myself wanting to do with the mouse but afaik there's no equivalent way of achieving that. While I was there, I fixed a bugette in convertMouseEvent which was incorrectly translating the NSEvent coordinates, and then fixing up the fact that the sign of the y-coordinate was wrong as a result. Using the convertPoint API correctly means that fixup is not required because convertPoint handles it for you.
7b5015a to
cabe114
Compare
@tomsci Agreed. That's what I meant in one of my comments. It would be nice to select a point and have the rotation happen around that point. That could be done by rotating the way it is now and then panning so that point remains in the same place on the screen. Just a thought, not sure if that'd be the best way to do it. Further off topic, I'd really like to see some of the VR input methods too ;-) |
|
Yeah I realised after I wrote it that you could only rotate about the point you clicked on (assuming you clicked in empty space, not on an actual bit of geometry) if you have an active workplane, otherwise you don't know what the z-coord of the rotate origin should be. Or maybe you could do some sort of approximation based on the closest bit of geometry in the 3d space.
I don't think any of my models are impressive enough to be worth looking at in VR but I admit I'm tempted :-) Maybe this will be enough impetus for me to look in to OpenXR... |
I don't think we need the Z value, just pan the rotated model so the point is in the same screen position?
The old emscripten port works in the web browser inside my Quest2. Not sure if the browser supports VR inputs? If so, I wonder if some gestures could be used in there with the model in the browser. Then a VR specific version could be made that pops the model out of the browser into the same VR space as the user? Someone would probably jump on developing that if we knew the pieces would all work together. |
Not sure, in my head it seems like you might need it but I'm pretty bad at visualising geometry so maybe not.
Wow, C++ to javascript (to webgl?) to browser-projected-in-VR? Sounds like a terrifying technology stack but pretty cool that it worked I guess. I was thinking more like directly implementing an OpenXR renderer and hooking that up through WMR, but that's probably a huge amount of work and would never work on my mac anyway :-) |
Now is the time to mention that this has been on line 6 of Jonathan's wishlist for eleven years ;-) Of course that file is a historical artefact so no one touches it. It is also closely related to rotation with 6DOF controllers (3Dconnexion SpaceMouse etc.). |
|
By the way the 3Dconnexion developers have thought about this a lot. Take a look at the "Center of Rotation" section here https://github.com/natevm/Foton/blob/master/external/spacemouse/Doc/DevInfo.htm The rest of the Doc directory is pretty interesting as well. |
|
Putting back to draft status as there are some broken interactions with the text window that I didn't notice. There's also some (preexisting) weirdnesses with the scrollbars on the text window that may be relevant. Also still open to suggestions on how best to fix the phantom hovertext issues. Maybe for that, we just need to fix when GraphicsWindow shows hovers since that also happens if you right-click-drag the mouse over the toolbar - it's just less unexpected of course since the cursor is right there. The case could be made though that it'd be better not showing hover text in the middle of a right-click-drag, and that'd solve it for the trackpad issue too. |
Which has not worked quite right since the last major refactor.
|
Have pushed fixes for trackpad gestures in the text window, and the text window scrollbar issues that were annoying me (but are technically unrelated to the trackpad changes). The only remaining issue is the phantom hovertext, which I think would require some minor changes to the generic mouse.cpp to fix properly (to prevent toolbar hovers appearing when doing right-click-drag) |
@tomsci you can do a conversion, just use something like PI * dist_in_pixels / screen_width_in_pixels to produce a 180 degree rotation by dragging all the way across the screen. Ok, maybe 2*PI then to make it more sensitive. |
This improves the behaviour of trackpad pan/rotate on mac which uses simulated right-button events.
|
I've pushed commits to address the 3 specific issues that I put the PR back into draft for.
I'm going to step back from the question of what the centre of rotation should be or whether some of these events could be input using SixDofEvent - it's an interesting discussion but it's getting a bit too deep into weeds for me :-) I think the trackpad is generally more mouselike than it is a 6-DOF controller so using the mouse API is probably ok. It's a shame there isn't a more nuanced API to say "I want a mouse-like rotate gesture with this much X and Y" rather than having to say "here's a shift-right-button x y motion" and having to know that that will result in a rotate, but that's more a philosophical objection than a real issue. And I can sympathise with the complexities of cross-platform input handling, been there before! |
|
I just checked this again and noticed that cmd+scrolling behaves strange. |
|
You're right, I didn't realise that ctrl and cmd are swapped and didn't test that combination. In fact I didn't realise you could do an in-plane rotate with ctrl-right-click-drag full stop :-) I've made sure to clear |
|
LGTM! |
|
@tomsci Hi. I just tried to run latest master with your changes on my Mac using Magic Mouse, that has some sort of single finger touchpad that's emulating scroll wheel. And the problem is that now zoom with scroll is now gone and replaced with panning, which is kind of a bummer because there's no way to zoom anymore with Magic Mouse, and panning is duplicated as you could do panning with holding right mouse button before. |
|
@nanoant That wasn't intentional :-( I'm not sure the best way to distinguish a Magic Mouse from a trackpad, the documentation is frustratingly vague as to how the APIs line up with the actual hardware Apple produces. I don't have a Magic Mouse to test with but I can try some speculative changes if you'd be able to test them? |
|
@tomsci I have Magic Mouse here. I've already managed to compile and run Solve Space here. Let me try if I can anything specific in NSEvent to disable the trackpad condition. I'll keep you informed. |
|
I tried it on my Air, and I do miss the 2 finger zoom. Pinch zoom is great, as are the other changes so overall it seems better. But 2 finger zoom emulating a scroll wheel was nice. |
|
Hopefully it's just a matter of becoming accustomed, I found myself hating that it zoomed when I expected it to pan because I was so accustomed to how other mac apps behave, and the fact that I kept zooming accidentally when I meant to pan was the primary motivation for making this PR :-) |
@verylowfreq has added some gestures in the Web version here: |
) * mac: Support for pan, zoom and rotate trackpad gestures Currently SolveSpace is nearly unusable on a mac if you only have a buttonless trackpad and not a mouse, because there's no way to pan (ie right-click-drag) or rotate (ie middle-click-drag). You can zoom, but only by using two-finger-drag up and down, which ends up getting interpreted as a scrollwheel event. This change makes the app behave much more like any other mac app, by adding 2-finger-drag pan gesture support and pinch-gesture zooming, and 3D rotate using shift-2-finger-drag. I've also added support for the rotate two-finger trackpad gesture, which rotates directly around the screen Z axis (rather than in all 3 dimensions) which is actually something I've found myself wanting to do with the mouse but afaik there's no equivalent way of achieving that. While I was there, I fixed a bugette in convertMouseEvent which was incorrectly translating the NSEvent coordinates, and then fixing up the fact that the sign of the y-coordinate was wrong as a result. Using the convertPoint API correctly means that fixup is not required because convertPoint handles it for you. * Don't do trackpad gestures on anything except the toplevel window * mac: Fix non-functional scrollbar on text window Which has not worked quite right since the last major refactor. * Don't pass right-button drags to the toolbar This improves the behaviour of trackpad pan/rotate on mac which uses simulated right-button events. * Don't pass cmd/ctrl modifier through on trackpad pan/rotate MouseEvents
) * mac: Support for pan, zoom and rotate trackpad gestures Currently SolveSpace is nearly unusable on a mac if you only have a buttonless trackpad and not a mouse, because there's no way to pan (ie right-click-drag) or rotate (ie middle-click-drag). You can zoom, but only by using two-finger-drag up and down, which ends up getting interpreted as a scrollwheel event. This change makes the app behave much more like any other mac app, by adding 2-finger-drag pan gesture support and pinch-gesture zooming, and 3D rotate using shift-2-finger-drag. I've also added support for the rotate two-finger trackpad gesture, which rotates directly around the screen Z axis (rather than in all 3 dimensions) which is actually something I've found myself wanting to do with the mouse but afaik there's no equivalent way of achieving that. While I was there, I fixed a bugette in convertMouseEvent which was incorrectly translating the NSEvent coordinates, and then fixing up the fact that the sign of the y-coordinate was wrong as a result. Using the convertPoint API correctly means that fixup is not required because convertPoint handles it for you. * Don't do trackpad gestures on anything except the toplevel window * mac: Fix non-functional scrollbar on text window Which has not worked quite right since the last major refactor. * Don't pass right-button drags to the toolbar This improves the behaviour of trackpad pan/rotate on mac which uses simulated right-button events. * Don't pass cmd/ctrl modifier through on trackpad pan/rotate MouseEvents


Fixes #1047
Currently SolveSpace is nearly unusable on a mac if you only have a
buttonless trackpad and not a mouse, because there's no way to pan
(ie right-click-drag) or rotate (ie middle-click-drag). You can zoom,
but only by using two-finger-drag up and down, which ends up getting
interpreted as a scrollwheel event.
This change makes the app behave much more like any other mac app, by
adding 2-finger-drag pan gesture support and pinch-gesture zooming, and
3D rotate using shift-2-finger-drag.
I've also added support for the rotate two-finger trackpad gesture,
which rotates directly around the screen Z axis (rather than in all 3
dimensions) which is actually something I've found myself wanting to do
with the mouse but afaik there's no equivalent way of achieving that.
While I was there, I fixed a bugette in convertMouseEvent which was
incorrectly translating the NSEvent coordinates, and then fixing up the
fact that the sign of the y-coordinate was wrong as a result. Using the
convertPoint API correctly means that fixup is not required because
convertPoint handles it for you.