mirror of
https://github.com/UnickSoft/graphonline.git
synced 2025-07-01 23:36:00 +00:00
Merge pull request #39 from PonomarevIK/master
Zoom in to the cursor position
This commit is contained in:
commit
871035b271
@ -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();
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user