Skip to content

Commit

Permalink
fix fullscreen canvas scaling
Browse files Browse the repository at this point in the history
  • Loading branch information
floe committed Oct 8, 2023
1 parent e01fdc6 commit 02ddc36
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions webclient/canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,17 @@ function paint(ctx, centerX, centerY, clearcolor, clearmode) {
}


function onCanvasDown(evt) { x = evt.offsetX/scale; y = evt.offsetY/scale; mousedown = (evt.buttons == undefined) ? 1 : evt.buttons; }
function onCanvasUp (evt) { onCanvasMove(evt); mousedown = 0; }
function onCanvasDown(evt) {
scale = canvas.offsetWidth / canvas.width;
x = evt.offsetX/scale;
y = evt.offsetY/scale;
mousedown = (evt.buttons == undefined) ? 1 : evt.buttons;
}

function onCanvasUp(evt) {
onCanvasMove(evt);
mousedown = 0;
}

function onCanvasMove(evt) {

Expand Down Expand Up @@ -53,7 +62,6 @@ function canvas_init() {
canvas.ontouchmove = onCanvasMove;

canvas.addEventListener("contextmenu", function(e) { e.preventDefault(); } );
scale = canvas.offsetWidth / canvas.width; // FIXME needs recalc at screen size change

var colors = ["red", "cyan", "yellow", "blue", "magenta" ];
mycolor = colors[Math.floor(Math.random() * colors.length)];
Expand Down

0 comments on commit 02ddc36

Please sign in to comment.