use of javafx.scene.input.ZoomEvent in project NMEAParser by tvesalainen.
the class ZoomEmulator method handle.
@Override
public void handle(MouseEvent me) {
node = (Node) me.getTarget();
double sx = me.getScreenX();
double sy = me.getScreenY();
Point2D local = node.screenToLocal(sx, sy);
if (local == null) {
initialHypot = hypot = 0;
zoomFactor = 1;
totalZoomFactor = 1;
return;
}
Bounds bounds = node.getBoundsInLocal();
double cx = local.getX() - bounds.getWidth() / 2;
double cy = local.getY() - bounds.getHeight() / 2;
EventType<? extends MouseEvent> eventType = me.getEventType();
if (eventType == MOUSE_PRESSED) {
initialHypot = hypot = Math.hypot(cy, cx);
zoomFactor = 1;
totalZoomFactor = 1;
ZoomEvent ze = createZoomEvent(me, ZOOM_STARTED);
Event.fireEvent(node, ze);
} else {
double dHypot = Math.hypot(cy, cx);
;
zoomFactor = dHypot / hypot;
totalZoomFactor = dHypot / initialHypot;
hypot = dHypot;
if (eventType == MOUSE_DRAGGED) {
ZoomEvent ze = createZoomEvent(me, ZOOM);
Event.fireEvent(node, ze);
} else {
ZoomEvent ze = createZoomEvent(me, ZOOM_FINISHED);
Event.fireEvent(node, ze);
}
}
}