OndrejKunc / SkiaScene

Simple API to transform SkiaSharp objects using functions like zoom and rotate or using gestures like pan and pinch.
MIT License
67 stars 18 forks source link

Pan with 2 fingers #15

Closed AlisiaNew closed 4 years ago

AlisiaNew commented 4 years ago

Thank you for the lightweight and easy to use library! Is there any chance you add a "pan-while-pinching" feature (or, in other words, pan with 2 fingers)? This would help a lot, because now I have to use a customized TouchGestureRecognizer to handle these two gestures when they happen simultaneously. I think it would be great if it was an optional feature, something like this: if (infos.Length == 1 || PanWhilePinching) { // ... } if (infos.Length >= 2) // without 'else' { // ... }

OndrejKunc commented 4 years ago

Hi @AlisiaNew , Sorry for the late response. I didn't have Xamarin tools installed at the moment so I wasn't able to dive into this issue earlier.

I played with the example code and I think what you are suggesting is already possible. The SceneGestureRenderingResponder has property TouchManipulationMode which is either IsotropicScale or ScaleRotate. Default is IsotropicScale and it indeed doesn't let you pan with 2 fingers but it also disables rotation of your scene. The second one is ScaleRotate. It allows you to do pan with 2 fingers but it also enables rotation which may not be what you want.

I already checked your PR #16 but I am not sure if this should be solved in TouchGestureRecognizer class. I haven't tested it yet but I think if we want to just add this pan with 2 fingers into IsotropicScale touch mode it should be solved in SceneGestureResponder (parent of SceneGestureRenderingResponder) in TouchGestureRecognizerOnPinch method because current TouchGestureRecognizer already sends all the info from pinch and pan gestures (even with 2 fingers) via OnPinch event.

Please let me know if I understand it correctly and TouchManipulationMode = TouchManipulationMode.ScaleRotate solved your issue, otherwise, I will test your PR and see if we can enable pan with 2 fingers in the IsotropicScale mode.

AlisiaNew commented 4 years ago

Hi Ondrej, thank you for the response! I noticed that ScaleRotate is more flexible regarding pan gestures, but unfortunately, IsotropicScale is preferable for my project as my scene shouldn't have rotation enabled. And regarding my implementation, I think you're right and it should be better solved in SceneGestureResponder. I would appreciate if you could move the solution there. Thank you!

OndrejKunc commented 4 years ago

Ok, so I gave it a try via #17 and it seems like it is working. Can you please test it? I wasn't able to run the Forms sample because of some strange Xamarin errors so I would really appreciate if you can try it out in my branch - or just copy the code to your working project.

Basically you need to set SceneGestureRenderingResponder properties to:

TouchManipulationMode = TouchManipulationMode.IsotropicScale,
EnableTwoFingersPanInIsotropicScaleMode = true,
AlisiaNew commented 4 years ago

Thank you, Ondrej! I've tested it (Forms application, run on Android device) and it works almost fine except for one thing: it seems that the 2 fingers pan "speed" is much faster than it is with 1 finger for smaller zoom values (and much slower for the larger zoom values). With a smaller zoom the scene objects disappear from the visible view area quite quickly. I would expect it to work with same pace as one finger gesture.

OndrejKunc commented 4 years ago

Thanks for your feedback! I am testing it in a native sample project but I was able to reproduce it as well. Sorry for that, I didn't play with the zoom before so it seemed fine. I will try to come up with some fix soon.

OndrejKunc commented 4 years ago

@AlisiaNew I updated the PR - now it seems it may be the desired behavior. Can you please check it again? Thanks!

AlisiaNew commented 4 years ago

Hi Ondrej! It seems it's working good. Thanks!

OndrejKunc commented 4 years ago

Great! I just merged it and published a new version to NuGet. Thanks again for your help.