在大多数应用中,向下旋转的滚轮会减小缩放对象的大小,而向上旋转的滚轮会增大缩放对象的大小。
piccol2d的默认行为是相反的:
private static void showWorldNode() {
new PFrame() {
@Override
public void initialize() {
getCanvas().getLayer().addChild(worldNode);
PMouseWheelZoomEventHandler mouseWheelZoomEventHandler = new PMouseWheelZoomEventHandler();
mouseWheelZoomEventHandler.zoomAboutMouse();
getCanvas().addInputEventListener(mouseWheelZoomEventHandler);
}
};
}
如何恢复默认设置?
您可以提供一个负比例因子来反转该行为,例如:
mouseWheelZoomEventHandler.setScaleFactor(-0.1d);
PMouseWheelZoomEventHandler
根据比例因子和MouseWheelEvent.getWheelRotation()的值计算缩放值,返回:
为负值,如果鼠标滚轮向上/远离用户,和正值,如果鼠标滚轮向下/向用户
以下是PMouseWheelZoomEventHandler
double scale = 1.0d + event.getWheelRotation() * scaleFactor;