Blazor.Diagrams
Blazor.Diagrams copied to clipboard
Multi-touch support
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
Pointclass gained aCalculateCentroidstatic method to calculate the centroid of a set of points MouseEventArgsgained aClientproperty that combinesClientXandClientYinto aPoint. A shortcut, basically- The
Diagramclass gained an overload for theSetZoommethod that accepts aPointto be used as the zoom origin. The logic was moved fromZoomBehavior PanBehaviorgot 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:
- Renaming each to something like
WheelZoomBehaviorandPointersPanZoomBehavior. 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. - Adding comments to each to clarify the overlapping actions
- Split by actions. Duplicate some of the new
PanBehaviorcode intoZoomBehaviorand make it listen to pointer events too - 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 Blazor-Diagrams/Blazor.Diagrams#512