Skip to content

Multi-touch support #513

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

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

ThFnsc
Copy link

@ThFnsc ThFnsc commented Apr 16, 2025

This modification allows PanBehavior to handle multiple pointers at the same time.

When using a single pointer (mouse or single touch) it behaves in the same manner as before. When more than one pointer is used, it also gains the responsibility of zooming in/out the diagram if the pointers change distance (pinch to zoom)

Instead of adding the algorithms as private methods, I've added them as public methods in various locations. I have had copies of them as extension methods in my application anyway, so I thought other might find them useful as well. Do let me know if you think otherwise, or if there are better locations to put them!

Modifications:

  • The Point class gained a CalculateCentroid static method to calculate the centroid of a set of points
  • MouseEventArgs gained a Client property that combines ClientX and ClientY into a Point. A shortcut, basically
  • The Diagram class gained an overload for the SetZoom method that accepts a Point to be used as the zoom origin. The logic was moved from ZoomBehavior
  • PanBehavior got an overhaul to support multiple pointers

Things I'm unsure of:
Should the new SetZoom overload clamp by the Minimum and Maximum zoom? I see that the original SetZoom only clamps the Minimum, but I'm not sure why. Perhaps something to do with the fit to screen action?

Is it bothersome that PanBehavior now also has logic for zooming, while there's a separate ZoomBehavior?

My thought in doing it that way is that ZoomBehavior is better off handling just zoom by wheel events. Leaving PanBehavior to handle all pointer events. This way makes things simpler, because if I were to split the Pan and Zoom multi-touch logic, there would be a lot of duplicated code, as they're really closely related.

I see the following options:

  1. Renaming each to something like WheelZoomBehavior and PointersPanZoomBehavior. So instead of naming the behavior as the actions they do, it would be a combination of the events they listen to and the actions they can perform based on them.
  2. Adding comments to each to clarify the overlapping actions
  3. Split by actions. Duplicate some of the new PanBehavior code into ZoomBehavior and make it listen to pointer events too
  4. The way I did it is fine as is

Personally, I like option 1. But there's the impact of breaking code for people who reference these behavior directly in their codebase. Not sure how common that is, or if it's that significant. If it is significant, perhaps option 2? Would love some input about this

Closes #512

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Multi-touch support for panning and zooming
1 participant