mirror of
https://github.com/lospec/pixel-editor.git
synced 2023-08-10 21:12:51 +03:00
Started commenting code
This commit is contained in:
@ -1,4 +1,9 @@
|
||||
function changeZoom (layer, direction, cursorLocation) {
|
||||
/** Changes the zoom level of the canvas
|
||||
* @param {*} direction 'in' or 'out'
|
||||
* @param {*} cursorLocation The position of the cursor when the user zoomed
|
||||
*/
|
||||
function changeZoom (direction, cursorLocation) {
|
||||
// Computing current width and height
|
||||
var oldWidth = canvasSize[0] * zoom;
|
||||
var oldHeight = canvasSize[1] * zoom;
|
||||
var newWidth, newHeight;
|
||||
@ -11,7 +16,9 @@ function changeZoom (layer, direction, cursorLocation) {
|
||||
newHeight = canvasSize[1] * zoom;
|
||||
|
||||
//adjust canvas position
|
||||
layer.setCanvasOffset(layer.canvas.offsetLeft + (oldWidth - newWidth) *cursorLocation[0]/oldWidth, layer.canvas.offsetTop + (oldHeight - newHeight) *cursorLocation[1]/oldWidth);
|
||||
layers[0].setCanvasOffset(
|
||||
layers[0].canvas.offsetLeft + (oldWidth - newWidth) * cursorLocation[0]/oldWidth,
|
||||
layers[0].canvas.offsetTop + (oldHeight - newHeight) * cursorLocation[1]/oldWidth);
|
||||
}
|
||||
//if you want to zoom in
|
||||
else if (direction == 'in' && zoom + Math.ceil(zoom/10) < window.innerHeight/4){
|
||||
@ -20,11 +27,13 @@ function changeZoom (layer, direction, cursorLocation) {
|
||||
newHeight = canvasSize[1] * zoom;
|
||||
|
||||
//adjust canvas position
|
||||
layer.setCanvasOffset(layer.canvas.offsetLeft - Math.round((newWidth - oldWidth)*cursorLocation[0]/oldWidth), layer.canvas.offsetTop - Math.round((newHeight - oldHeight)*cursorLocation[1]/oldHeight));
|
||||
layers[0].setCanvasOffset(
|
||||
layers[0].canvas.offsetLeft - Math.round((newWidth - oldWidth)*cursorLocation[0]/oldWidth),
|
||||
layers[0].canvas.offsetTop - Math.round((newHeight - oldHeight)*cursorLocation[1]/oldHeight));
|
||||
}
|
||||
|
||||
//resize canvas
|
||||
layer.resize();
|
||||
layers[0].resize();
|
||||
|
||||
// adjust brush size
|
||||
currentTool.updateCursor();
|
||||
|
Reference in New Issue
Block a user