allow browser zoom and improve performance

This commit is contained in:
raphael 2020-03-19 20:42:46 +01:00
parent 62c77dac83
commit bc9f97b8da

View File

@ -27,8 +27,6 @@ var whiteboard = {
whiteboardId: "0",
username: "unknown",
sendFunction: null,
canvasWidth: 3000,
canvasHeight: 2000,
backgroundGridUrl: './images/KtEBa2.png'
},
loadWhiteboard: function (whiteboardContainer, newSettings) {
@ -51,7 +49,7 @@ var whiteboard = {
// whiteboard canvas
_this.canvasElement = $('<canvas id="whiteboardCanvas" style="position: absolute; left:0px; top:0; cursor:crosshair;"></canvas>');
// SVG container holding drawing or moving previews
_this.svgContainer = $('<svg style="position: absolute; top:0px; left:0px;" width="' + _this.settings.canvasWidth + '" height="' + _this.settings.canvasHeight + '"></svg>');
_this.svgContainer = $('<svg style="position: absolute; top:0px; left:0px;" width="100%" height="100%"></svg>');
// drag and drop indicator, hidden by default
_this.dropIndicator = $('<div style="position:absolute; height: 100%; width: 100%; border: 7px dashed gray; text-align: center; top: 0px; left: 0px; color: gray; font-size: 23em; display: none;"><i class="far fa-plus-square" aria-hidden="true"></i></div>')
// container for other users cursors
@ -70,11 +68,19 @@ var whiteboard = {
.append(_this.textContainer)
.append(_this.mouseOverlay);
this.canvas = $("#whiteboardCanvas")[0];
this.canvas.height = _this.settings.canvasHeight;
this.canvas.width = _this.settings.canvasWidth;
this.canvas.height = $(window).height();
this.canvas.width = $(window).width();
this.ctx = this.canvas.getContext("2d");
this.oldGCO = this.ctx.globalCompositeOperation;
$(window).resize(function () { //Handel resize
var dbCp = JSON.parse(JSON.stringify(_this.drawBuffer)); //Copy the buffer
_this.canvas.width = $(window).width();
_this.canvas.height = $(window).height(); //Set new canvas height
_this.drawBuffer = [];
_this.loadData(dbCp); //draw old content in
});
$(_this.mouseOverlay).on("mousedown touchstart", function (e) {
if (_this.imgDragActive || _this.drawFlag) {
return;