Add zoom event handler that responds to mouse wheel events
Closed this issue · 8 comments
mro commented
Originally reported on Google Code with ID 236
Feature request, add a zoom event handler that responds to mouse wheel events.
Reported by heuermh
on 2012-01-25 22:35:37
mro commented
Patch to svn trunk attached.
Reported by heuermh
on 2012-01-25 22:37:05
- Status changed:
Started
- Labels added: Type-Enhancement, Priority-Medium, Effort-Low, OpSys-All, Toolkit-Piccolo2D.Java, Component-Core, Milestone-2.0
- _Attachment: [patch.txt](https://storage.googleapis.com/google-code-attachments/piccolo2d/issue-236/comment-1/patch.txt)_
mro commented
Looks good.
PZoomEventHandler uses a viewZoomPoint (where the user clicked) to anchor the zoom.
Consider anchoring zoom where the mouse is pointing when the wheel is rotated. (This
is how Google Maps works, for example.)
Something like:
...
final Point2D anchor = e.getCanvasPosition();
camera.localToView(anchor);
camera.scaleViewAboutPoint(scale, anchor.getX(), anchor.getY());
...
Reported by atdixon
on 2012-02-12 00:06:26
mro commented
Thank you for the comments.
I was thinking of adding the viewZoomPoint feature, but I don't actually like that
behavior. Would you be ok with making that configurable with a boolean bound property?
The same might be added to PZoomEventHandler while I'm at it.
And one minor fix to the patch above,
- PMouseWheelZoomEventHandler() {
+ public PMouseWheelZoomEventHandler() {
Reported by heuermh
on 2012-02-12 02:18:22
mro commented
Yep, I like making it configurable with a boolean option.
Reported by atdixon
on 2012-02-12 19:25:24
mro commented
Input event handlers don't have property change support, so I just went with a ZoomMode
enum instead. Let me know what you think; updated patch attached.
Reported by heuermh
on 2012-02-15 23:05:12
- _Attachment: [zoom-mode-patch.txt](https://storage.googleapis.com/google-code-attachments/piccolo2d/issue-236/comment-5/zoom-mode-patch.txt)_
mro commented
I like it.
Reported by atdixon
on 2012-02-18 03:31:03
mro commented
Turns out another zoom mode was what I was actually after, zoom about canvas center.
I added that and made it the default.
There is also a new MouseWheelZoomExample that demonstrates the different modes.
$ svn commit -m "Issue 236 ; adding zoom event handler that responds to mouse wheel
events" core/ examples/
Adding core/src/main/java/org/piccolo2d/event/PMouseWheelZoomEventHandler.java
Adding core/src/test/java/org/piccolo2d/event/PMouseWheelZoomEventHandlerTest.java
Sending examples/src/main/java/org/piccolo2d/examples/ExampleRunner.java
Adding examples/src/main/java/org/piccolo2d/examples/MouseWheelZoomExample.java
Transmitting file data ....
Committed revision 1163.
Reported by heuermh
on 2012-02-23 22:05:40
- Status changed:
Fixed
mro commented
Reported by atdixon
on 2012-02-25 01:29:12
- Status changed:
Verified