Merge pull request #39 from PonomarevIK/master

Zoom in to the cursor position
This commit is contained in:
Unick Soft 2022-07-10 10:52:51 +02:00 committed by GitHub
commit 871035b271
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 11 deletions

View File

@ -515,15 +515,24 @@ Application.prototype.CanvasOnMouseUp = function(e)
this.updateMessage();
}
Application.prototype.multCanvasScale = function(factor)
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.canvasPosition = this.canvasPosition.add(new Point((this.GetRealWidth() - oldRealWidth) / 2.0, (this.GetRealHeight() - oldRealHeight) / 2.0));
}
this.redrawGraph();
}

View File

@ -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);
}
}