Zoom in to the cursor position - more intuitive

This commit is contained in:
Ivan 2022-07-10 01:21:04 +05:00
parent 59b01bec36
commit 964f1e5723
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)
{
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();
}

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