mirror of
https://github.com/piskelapp/piskel.git
synced 2023-08-10 21:12:52 +03:00
Merge pull request #385 from smiegrin/master
Introduces zooming towards/away from mouse
This commit is contained in:
commit
3e7999cfc5
@ -64,8 +64,8 @@
|
|||||||
|
|
||||||
var shortcuts = pskl.service.keyboard.Shortcuts;
|
var shortcuts = pskl.service.keyboard.Shortcuts;
|
||||||
pskl.app.shortcutService.registerShortcut(shortcuts.MISC.RESET_ZOOM, this.resetZoom_.bind(this));
|
pskl.app.shortcutService.registerShortcut(shortcuts.MISC.RESET_ZOOM, this.resetZoom_.bind(this));
|
||||||
pskl.app.shortcutService.registerShortcut(shortcuts.MISC.INCREASE_ZOOM, this.increaseZoom_.bind(this, 1));
|
pskl.app.shortcutService.registerShortcut(shortcuts.MISC.INCREASE_ZOOM, this.updateZoom_.bind(this, 1));
|
||||||
pskl.app.shortcutService.registerShortcut(shortcuts.MISC.DECREASE_ZOOM, this.decreaseZoom_.bind(this, 1));
|
pskl.app.shortcutService.registerShortcut(shortcuts.MISC.DECREASE_ZOOM, this.updateZoom_.bind(this, -1));
|
||||||
|
|
||||||
window.setTimeout(function () {
|
window.setTimeout(function () {
|
||||||
this.afterWindowResize_();
|
this.afterWindowResize_();
|
||||||
@ -245,7 +245,7 @@
|
|||||||
} else if (pskl.utils.UserAgent.isFirefox) {
|
} else if (pskl.utils.UserAgent.isFirefox) {
|
||||||
delta = -40 * evt.deltaY;
|
delta = -40 * evt.deltaY;
|
||||||
}
|
}
|
||||||
var modifier = Math.abs(delta / 120);
|
var modifier = (delta / 120);
|
||||||
|
|
||||||
if (pskl.utils.UserAgent.isMac ? evt.metaKey : evt.ctrlKey) {
|
if (pskl.utils.UserAgent.isMac ? evt.metaKey : evt.ctrlKey) {
|
||||||
modifier = modifier * 5;
|
modifier = modifier * 5;
|
||||||
@ -253,21 +253,24 @@
|
|||||||
evt.preventDefault();
|
evt.preventDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (delta > 0) {
|
this.updateZoom_(modifier);
|
||||||
this.increaseZoom_(modifier);
|
|
||||||
} else if (delta < 0) {
|
|
||||||
this.decreaseZoom_(modifier);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
ns.DrawingController.prototype.increaseZoom_ = function (zoomMultiplier) {
|
ns.DrawingController.prototype.updateZoom_ = function (zoomMultiplier) {
|
||||||
|
var coords = this.getSpriteCoordinates(this._clientX,this._clientY);
|
||||||
|
var off = this.getOffset();
|
||||||
|
var oldWidth = this.getContainerWidth_() / this.renderer.getZoom();
|
||||||
|
var oldHeight = this.getContainerHeight_() / this.renderer.getZoom();
|
||||||
|
var xRatio = (coords.x - off.x) / oldWidth;
|
||||||
|
var yRatio = (coords.y - off.y) / oldHeight;
|
||||||
var step = (zoomMultiplier || 1) * this.getZoomStep_();
|
var step = (zoomMultiplier || 1) * this.getZoomStep_();
|
||||||
this.setZoom_(this.renderer.getZoom() + step);
|
this.setZoom_(this.renderer.getZoom() + step);
|
||||||
};
|
var newWidth = this.getContainerWidth_() / this.renderer.getZoom();
|
||||||
|
var newHeight = this.getContainerHeight_() / this.renderer.getZoom();
|
||||||
ns.DrawingController.prototype.decreaseZoom_ = function (zoomMultiplier) {
|
this.setOffset(
|
||||||
var step = (zoomMultiplier || 1) * this.getZoomStep_();
|
off.x - ((newWidth - oldWidth) * xRatio),
|
||||||
this.setZoom_(this.renderer.getZoom() - step);
|
off.y - ((newHeight - oldHeight) * yRatio)
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user