2019-03-31 18:15:03 +03:00
|
|
|
function changeZoom (layer, direction, cursorLocation) {
|
2019-03-27 02:20:54 +03:00
|
|
|
var oldWidth = canvasSize[0] * zoom;
|
|
|
|
var oldHeight = canvasSize[1] * zoom;
|
|
|
|
var newWidth, newHeight;
|
2020-04-15 03:01:31 +03:00
|
|
|
|
2019-03-27 02:20:54 +03:00
|
|
|
//change zoom level
|
|
|
|
//if you want to zoom out, and the zoom isnt already at the smallest level
|
|
|
|
if (direction == 'out' && zoom > 1) {
|
|
|
|
zoom -= Math.ceil(zoom / 10);
|
|
|
|
newWidth = canvasSize[0] * zoom;
|
|
|
|
newHeight = canvasSize[1] * zoom;
|
2020-04-15 03:01:31 +03:00
|
|
|
|
2019-03-27 02:20:54 +03:00
|
|
|
//adjust canvas position
|
2020-07-21 23:30:46 +03:00
|
|
|
layer.setCanvasOffset(layer.canvas.offsetLeft + (oldWidth - newWidth) *cursorLocation[0]/oldWidth, layer.canvas.offsetTop + (oldHeight - newHeight) *cursorLocation[1]/oldWidth);
|
2019-03-27 02:20:54 +03:00
|
|
|
}
|
|
|
|
//if you want to zoom in
|
|
|
|
else if (direction == 'in' && zoom + Math.ceil(zoom/10) < window.innerHeight/4){
|
|
|
|
zoom += Math.ceil(zoom/10);
|
|
|
|
newWidth = canvasSize[0] * zoom;
|
|
|
|
newHeight = canvasSize[1] * zoom;
|
2020-04-15 03:01:31 +03:00
|
|
|
|
2019-03-27 02:20:54 +03:00
|
|
|
//adjust canvas position
|
2020-07-21 23:30:46 +03:00
|
|
|
layer.setCanvasOffset(layer.canvas.offsetLeft - Math.round((newWidth - oldWidth)*cursorLocation[0]/oldWidth), layer.canvas.offsetTop - Math.round((newHeight - oldHeight)*cursorLocation[1]/oldHeight));
|
2019-03-27 02:20:54 +03:00
|
|
|
}
|
2020-04-15 03:01:31 +03:00
|
|
|
|
2019-03-27 02:20:54 +03:00
|
|
|
//resize canvas
|
2019-03-31 19:41:08 +03:00
|
|
|
layer.resize();
|
2019-03-27 02:20:54 +03:00
|
|
|
|
|
|
|
// adjust brush size
|
2020-04-15 03:01:31 +03:00
|
|
|
currentTool.updateCursor();
|
2020-04-04 10:41:56 +03:00
|
|
|
}
|