diff --git a/script/Appilcation.js b/script/Appilcation.js index 90031b0..9dc6b2c 100644 --- a/script/Appilcation.js +++ b/script/Appilcation.js @@ -515,15 +515,24 @@ Application.prototype.CanvasOnMouseUp = function(e) this.updateMessage(); } -Application.prototype.multCanvasScale = function(factor) -{ - var oldRealWidth = this.GetRealWidth(); - var oldRealHeight = this.GetRealHeight(); - - this.canvasScale *= factor; - - this.canvasPosition = this.canvasPosition.add(new Point((this.GetRealWidth() - oldRealWidth) / 2.0, - (this.GetRealHeight() - oldRealHeight) / 2.0)); +Application.prototype.multCanvasScale = function(factor, zoom_to=null) +{ + if (zoom_to) // zoom on cursor + { + var pos1 = this.getMousePos(this.canvas, zoom_to); // mouse position before zooming + this.canvasScale *= factor; + var pos2 = this.getMousePos(this.canvas, zoom_to); // mouse position after zooming + + this.canvasPosition = this.canvasPosition.add(new Point(pos2.x-pos1.x, pos2.y-pos1.y)); + } + else // zoom on center + { + var oldRealWidth = this.GetRealWidth(); + var oldRealHeight = this.GetRealHeight(); + this.canvasScale *= factor; + + this.canvasPosition = this.canvasPosition.add(new Point((this.GetRealWidth() - oldRealWidth) / 2.0, (this.GetRealHeight() - oldRealHeight) / 2.0)); + } this.redrawGraph(); } diff --git a/script/main.js b/script/main.js index ad1fc60..c1ea89a 100644 --- a/script/main.js +++ b/script/main.js @@ -191,11 +191,11 @@ function postLoadPage() var delta = Math.max(-1, Math.min(1, (e.wheelDelta || -e.detail))); if (delta > 0) { - application.multCanvasScale(1.3); + application.multCanvasScale(1.3, e); } else { - application.multCanvasScale(1.0 / 1.3); + application.multCanvasScale(1.0 / 1.3, e); } }