-
-
Save imbhupendra41/609b009dce8d25dd82bf5a80bb22796b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Reset Zoom | |
self.resetZoom = function() { | |
var objects = canvas.getObjects(); | |
for (var i in objects) { | |
var scaleX = objects[i].scaleX; | |
var scaleY = objects[i].scaleY; | |
var left = objects[i].left; | |
var top = objects[i].top; | |
var tempScaleX = scaleX * (1 / canvasScale); | |
var tempScaleY = scaleY * (1 / canvasScale); | |
var tempLeft = left * (1 / canvasScale); | |
var tempTop = top * (1 / canvasScale); | |
objects[i].scaleX = tempScaleX; | |
objects[i].scaleY = tempScaleY; | |
objects[i].left = tempLeft; | |
objects[i].top = tempTop; | |
objects[i].setCoords(); | |
} | |
var width = canvas.getWidth(); | |
var height = canvas.getHeight(); | |
var tempWidth = width * (1 / canvasScale); | |
var tempHeight = height * (1 / canvasScale); | |
canvas.setWidth(tempWidth); | |
canvas.setHeight(tempHeight); | |
canvas.renderAll(); | |
canvasScale = 1; | |
}; | |
// Zoom In | |
self.zoomIn = function() { | |
// TODO limit the max canvas zoom in | |
canvasScale = canvasScale * SCALE_FACTOR; | |
var objects = canvas.getObjects(); | |
for (var i in objects) { | |
var scaleX = objects[i].scaleX; | |
var scaleY = objects[i].scaleY; | |
var left = objects[i].left; | |
var top = objects[i].top; | |
var tempScaleX = scaleX * SCALE_FACTOR; | |
var tempScaleY = scaleY * SCALE_FACTOR; | |
var tempLeft = left * SCALE_FACTOR; | |
var tempTop = top * SCALE_FACTOR; | |
objects[i].scaleX = tempScaleX; | |
objects[i].scaleY = tempScaleY; | |
objects[i].left = tempLeft; | |
objects[i].top = tempTop; | |
objects[i].setCoords(); | |
} | |
var width = canvas.getWidth(); | |
var height = canvas.getHeight(); | |
var tempWidth = width * SCALE_FACTOR; | |
var tempHeight = height * SCALE_FACTOR; | |
canvas.setWidth(tempWidth); | |
canvas.setHeight(tempHeight); | |
canvas.renderAll(); | |
}; | |
// Zoom Out | |
self.zoomOut = function() { | |
// TODO limit max cavas zoom out | |
canvasScale = canvasScale / SCALE_FACTOR; | |
var objects = canvas.getObjects(); | |
for (var i in objects) { | |
var scaleX = objects[i].scaleX; | |
var scaleY = objects[i].scaleY; | |
var left = objects[i].left; | |
var top = objects[i].top; | |
var tempScaleX = scaleX * (1 / SCALE_FACTOR); | |
var tempScaleY = scaleY * (1 / SCALE_FACTOR); | |
var tempLeft = left * (1 / SCALE_FACTOR); | |
var tempTop = top * (1 / SCALE_FACTOR); | |
objects[i].scaleX = tempScaleX; | |
objects[i].scaleY = tempScaleY; | |
objects[i].left = tempLeft; | |
objects[i].top = tempTop; | |
objects[i].setCoords(); | |
} | |
var width = canvas.getWidth(); | |
var height = canvas.getHeight(); | |
var tempWidth = width * (1 / SCALE_FACTOR); | |
var tempHeight = height * (1 / SCALE_FACTOR); | |
canvas.setWidth(tempWidth); | |
canvas.setHeight(tempHeight); | |
canvas.renderAll(); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment