piccolo2d / piccolo2d.java

Structured 2D Graphics Framework
http://piccolo2d.org
Other
51 stars 14 forks source link

Add zoom event handler that responds to mouse wheel events #236

Closed mro closed 9 years ago

mro commented 9 years ago

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 9 years ago
Patch to svn trunk attached.

Reported by heuermh on 2012-01-25 22:37:05


mro commented 9 years ago
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 9 years ago
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 9 years ago
Yep, I like making it configurable with a boolean option.

Reported by atdixon on 2012-02-12 19:25:24

mro commented 9 years ago
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


mro commented 9 years ago
I like it.

Reported by atdixon on 2012-02-18 03:31:03

mro commented 9 years ago
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

mro commented 9 years ago

Reported by atdixon on 2012-02-25 01:29:12