Last active
August 29, 2015 14:02
-
-
Save clouddueling/f50fa9af43c8dad1b81a 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
var SCALE_FACTOR = 1.2; | |
self.center = function() { | |
var activeObject = self.canvas.getActiveObject(); | |
if (activeObject) { | |
activeObject.center(); | |
activeObject.setCoords(); | |
setUnsaved(); | |
} | |
}; | |
self.centerH = function() { | |
var activeObject = canvas.getActiveObject(); | |
if (activeObject) { | |
activeObject.centerH(); | |
activeObject.setCoords(); | |
setUnsaved(); | |
} | |
}; | |
self.centerV = function() { | |
var activeObject = canvas.getActiveObject(); | |
if (activeObject) { | |
activeObject.centerV(); | |
activeObject.setCoords(); | |
setUnsaved(); | |
} | |
}; | |
// Reset Zoom | |
self.resetZoom = function(cb) { | |
var width = canvas.getWidth(); | |
var height = canvas.getHeight(); | |
var tempWidth = width * (1 / canvas.scale); | |
var tempHeight = height * (1 / canvas.scale); | |
canvas.setWidth(tempWidth); | |
canvas.setHeight(tempHeight); | |
canvas.scale = 1; | |
canvas.setZoom(1); | |
if (cb) { | |
cb(); | |
} | |
}; | |
// Zoom In | |
self.zoomIn = function() { | |
canvas.scale = canvas.scale * SCALE_FACTOR; | |
canvas.setZoom(canvas.scale); | |
var width = canvas.getWidth(); | |
var height = canvas.getHeight(); | |
var tempWidth = width * SCALE_FACTOR; | |
var tempHeight = height * SCALE_FACTOR; | |
canvas.setWidth(tempWidth); | |
canvas.setHeight(tempHeight); | |
}; | |
// Zoom Out | |
self.zoomOut = function() { | |
canvas.scale = self.canvas.scale / SCALE_FACTOR; | |
canvas.setZoom(canvas.scale); | |
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); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment