mirror of
https://github.com/piskelapp/piskel.git
synced 2023-08-10 21:12:52 +03:00
only update zoom for a valid modifier, fix zoom centering bug when using keyboard shortcuts
This commit is contained in:
parent
3e7999cfc5
commit
fdd4fb5b4e
@ -253,24 +253,41 @@
|
|||||||
evt.preventDefault();
|
evt.preventDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.updateZoom_(modifier);
|
var coords = this.getSpriteCoordinates(evt.clientX, evt.clientY);
|
||||||
|
this.updateZoom_(modifier, coords);
|
||||||
};
|
};
|
||||||
|
|
||||||
ns.DrawingController.prototype.updateZoom_ = function (zoomMultiplier) {
|
/**
|
||||||
var coords = this.getSpriteCoordinates(this._clientX,this._clientY);
|
* Update the current zoom level by a given multiplier.
|
||||||
|
*
|
||||||
|
* @param {Number} zoomMultiplier: factor by which the zoom should be modified. Negative
|
||||||
|
* values will decrease the zoom, positive values will increase it.
|
||||||
|
* @param {Object} centerCoords, optional:
|
||||||
|
* - {Number} x: x coordinate of the desired center the zoomed canvas
|
||||||
|
* - {Number} y: y coordinate of the desired center the zoomed canvas
|
||||||
|
*/
|
||||||
|
ns.DrawingController.prototype.updateZoom_ = function (zoomMultiplier, centerCoords) {
|
||||||
|
if (zoomMultiplier === 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var off = this.getOffset();
|
var off = this.getOffset();
|
||||||
var oldWidth = this.getContainerWidth_() / this.renderer.getZoom();
|
var oldWidth = this.getContainerWidth_() / this.renderer.getZoom();
|
||||||
var oldHeight = this.getContainerHeight_() / 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 * this.getZoomStep_();
|
||||||
var step = (zoomMultiplier || 1) * this.getZoomStep_();
|
|
||||||
this.setZoom_(this.renderer.getZoom() + step);
|
this.setZoom_(this.renderer.getZoom() + step);
|
||||||
|
|
||||||
|
if (centerCoords) {
|
||||||
|
var xRatio = (centerCoords.x - off.x) / oldWidth;
|
||||||
|
var yRatio = (centerCoords.y - off.y) / oldHeight;
|
||||||
var newWidth = this.getContainerWidth_() / this.renderer.getZoom();
|
var newWidth = this.getContainerWidth_() / this.renderer.getZoom();
|
||||||
var newHeight = this.getContainerHeight_() / this.renderer.getZoom();
|
var newHeight = this.getContainerHeight_() / this.renderer.getZoom();
|
||||||
this.setOffset(
|
this.setOffset(
|
||||||
off.x - ((newWidth - oldWidth) * xRatio),
|
off.x - ((newWidth - oldWidth) * xRatio),
|
||||||
off.y - ((newHeight - oldHeight) * yRatio)
|
off.y - ((newHeight - oldHeight) * yRatio)
|
||||||
);
|
);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user