mirror of
https://github.com/lospec/pixel-editor.git
synced 2023-08-10 21:12:51 +03:00
34 lines
1.2 KiB
JavaScript
34 lines
1.2 KiB
JavaScript
function Canvas(height, width, canvas) {
|
|
this.canvasSize = [width, height],
|
|
this.canvas = canvas,
|
|
this.initialize = function() {
|
|
var maxHorizontalZoom = Math.floor(window.innerWidth/canvasSize[0]*0.75);
|
|
var maxVerticalZoom = Math.floor(window.innerHeight/canvasSize[1]*0.75);
|
|
|
|
zoom = Math.min(maxHorizontalZoom,maxVerticalZoom);
|
|
if (zoom < 1) zoom = 1;
|
|
|
|
//resize canvas
|
|
this.canvas.width = canvasSize[0];
|
|
this.canvas.height = canvasSize[1];
|
|
this.canvas.style.width = (this.canvas.width*zoom)+'px';
|
|
this.canvas.style.height = (this.canvas.height*zoom)+'px';
|
|
|
|
//unhide canvas
|
|
this.canvas.style.display = 'block';
|
|
|
|
//center canvas in window
|
|
this.canvas.style.left = 64+canvasView.clientWidth/2-(canvasSize[0]*zoom/2)+'px';
|
|
this.canvas.style.top = 48+canvasView.clientHeight/2-(canvasSize[1]*zoom/2)+'px';
|
|
},
|
|
this.resize = function() {
|
|
let newWidth = (this.canvas.width*zoom)+'px';
|
|
let newHeight = (this.canvas.height*zoom)+'px';
|
|
|
|
this.canvas.style.width = newWidth;
|
|
this.canvas.style.height = newHeight;
|
|
|
|
this.width = newWidth;
|
|
this.height = newHeight;
|
|
}
|
|
} |