use of javafx.scene.input.RotateEvent in project NMEAParser by tvesalainen.
the class RotateEmulator 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) {
a = 0;
angle = 0;
totalAngle = 0;
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) {
a = Math.toDegrees(Math.atan2(cy, cx));
angle = 0;
totalAngle = 0;
RotateEvent re = createRotateEvent(me, ROTATION_STARTED);
Event.fireEvent(node, re);
} else {
if (node == null) {
return;
}
double da = Math.toDegrees(Math.atan2(cy, cx));
angle = da - a;
a = da;
totalAngle += angle;
if (eventType == MOUSE_DRAGGED) {
RotateEvent re = createRotateEvent(me, ROTATE);
Event.fireEvent(node, re);
} else {
RotateEvent re = createRotateEvent(me, ROTATION_FINISHED);
Event.fireEvent(node, re);
}
}
}
Aggregations