wieslawsoltes / PanAndZoom

Pan and zoom control for Avalonia.
http://wieslawsoltes.github.io/PanAndZoom/
MIT License
348 stars 45 forks source link

Rectangular zoom #61

Closed PhilippPaetzold closed 1 year ago

PhilippPaetzold commented 2 years ago

I like to use this library for implementing an image viewer. So far it works great for panning and zooming with the mouse wheel. What I am missing is a rectangular zoom. Could you give me any clues how to best implement this? Thank you for your great work. This is really the best library for panning and scrolling with avalonia.

Best regards Philipp

HoneyTauOverTwo commented 2 years ago

Take a look at my fork for it: https://github.com/HoneyTauOverTwo/PanAndZoom/tree/ZoomIntoArea

I also needed this functionality. Peer-reviewing is greatly appreciated.

[edit] Note that I did not implement box selection in the GUI, what I implemented is only a method that receives a rectangle to zoom into.

If you can implement the box selection logic to save the top left corner when the mouse is clicked and bottom right corner when the mouse is released, you should be able to create a Rect from those and then use the ZoomIntoArea method.

PhilippPaetzold commented 2 years ago

Thanks @HoneyTauOverTwo, I will review your implementation and try to include it in my app for further testing.

PhilippPaetzold commented 1 year ago

@HoneyTauOverTwo Sorry it took me ages, but I created a small VS2022 .NET demo project 2023-03-29_13-03-19_ImageViewer.zip to evaluate your fork of ZoomBorder, especially the ZoomIntoArea method. In the demo, you can open an image and perform a rectangle zoom by holding the left mouse button. When you release the button again, I invoke the ZoomIntoArea method, so it should zoom and pan automatically and according to the zoom rectangle. Unfortunatly its not really working as expected. It would be great, if you could check it out.