Introduces zooming towards/away from mouse
This commit is contained in:
parent
73b165ef0c
commit
412067ad90
1 changed files with 24 additions and 0 deletions
|
@ -247,13 +247,37 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
ns.DrawingController.prototype.increaseZoom_ = function (zoomMultiplier) {
|
ns.DrawingController.prototype.increaseZoom_ = 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();
|
||||||
|
this.setOffset(
|
||||||
|
off.x + ((oldWidth - newWidth) * xRatio),
|
||||||
|
off.y + ((oldHeight - newHeight) * yRatio)
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
ns.DrawingController.prototype.decreaseZoom_ = function (zoomMultiplier) {
|
ns.DrawingController.prototype.decreaseZoom_ = 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();
|
||||||
|
this.setOffset(
|
||||||
|
off.x - ((newWidth - oldWidth) * xRatio),
|
||||||
|
off.y - ((newHeight - oldHeight) * yRatio)
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue