Spaces:
Paused
Paused
Client: size canvas to viewport, 100% zoom, patch blit no longer clears the screen
Browse files- index.html +29 -9
index.html
CHANGED
|
@@ -38,18 +38,34 @@
|
|
| 38 |
canvas.width = Math.round(vw*dpr);
|
| 39 |
canvas.height = Math.round(vh*dpr);
|
| 40 |
canvas.style.width = vw+"px"; canvas.style.height = vh+"px";
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
}
|
| 47 |
|
| 48 |
-
|
|
|
|
| 49 |
ctx.imageSmoothingEnabled = false;
|
| 50 |
ctx.fillStyle = "#000"; ctx.fillRect(0,0,canvas.width,canvas.height);
|
| 51 |
-
ctx.drawImage(off,
|
| 52 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
}
|
| 54 |
|
| 55 |
function toFB(clientX, clientY){
|
|
@@ -88,7 +104,7 @@
|
|
| 88 |
octx.imageSmoothingEnabled = false;
|
| 89 |
octx.drawImage(bmp, 0, 0);
|
| 90 |
bmp.close && bmp.close();
|
| 91 |
-
|
| 92 |
hud();
|
| 93 |
});
|
| 94 |
}
|
|
@@ -201,6 +217,10 @@
|
|
| 201 |
hud();
|
| 202 |
}, 1000);
|
| 203 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 204 |
connect();
|
| 205 |
})();
|
| 206 |
</script>
|
|
|
|
| 38 |
canvas.width = Math.round(vw*dpr);
|
| 39 |
canvas.height = Math.round(vh*dpr);
|
| 40 |
canvas.style.width = vw+"px"; canvas.style.height = vh+"px";
|
| 41 |
+
// 100% zoom = one framebuffer pixel per CSS pixel (x dpr for device px).
|
| 42 |
+
// Never magnify past 100%; only shrink to fit a viewport smaller than the
|
| 43 |
+
// framebuffer. (Previously it always scaled up to fill the window, which
|
| 44 |
+
// is why the OS looked "zoomed in" / too big.)
|
| 45 |
+
var fit = Math.min(vw/FB, vh/FB);
|
| 46 |
+
view.scale = Math.min(fit, 1) * dpr;
|
| 47 |
+
view.ox = Math.floor((canvas.width - FB*view.scale)/2);
|
| 48 |
+
view.oy = Math.floor((canvas.height - FB*view.scale)/2);
|
| 49 |
+
paintAll();
|
| 50 |
}
|
| 51 |
|
| 52 |
+
// Full repaint of the VISIBLE canvas from the offscreen framebuffer.
|
| 53 |
+
function paintAll(){
|
| 54 |
ctx.imageSmoothingEnabled = false;
|
| 55 |
ctx.fillStyle = "#000"; ctx.fillRect(0,0,canvas.width,canvas.height);
|
| 56 |
+
ctx.drawImage(off, 0,0,FB,FB, view.ox, view.oy, FB*view.scale, FB*view.scale);
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
// Partial repaint: redraw ONLY the changed region. This must not clear the
|
| 60 |
+
// whole visible canvas -- doing so blacked out everything outside the patch
|
| 61 |
+
// until the next frame happened to touch it ("black tiles until mouseover").
|
| 62 |
+
function blit(x,y,w,h){
|
| 63 |
+
ctx.imageSmoothingEnabled = false;
|
| 64 |
+
var dx = Math.floor(view.ox + x*view.scale);
|
| 65 |
+
var dy = Math.floor(view.oy + y*view.scale);
|
| 66 |
+
var dx2 = Math.ceil(view.ox + (x+w)*view.scale);
|
| 67 |
+
var dy2 = Math.ceil(view.oy + (y+h)*view.scale);
|
| 68 |
+
ctx.drawImage(off, x,y,w,h, dx,dy, dx2-dx, dy2-dy);
|
| 69 |
}
|
| 70 |
|
| 71 |
function toFB(clientX, clientY){
|
|
|
|
| 104 |
octx.imageSmoothingEnabled = false;
|
| 105 |
octx.drawImage(bmp, 0, 0);
|
| 106 |
bmp.close && bmp.close();
|
| 107 |
+
paintAll();
|
| 108 |
hud();
|
| 109 |
});
|
| 110 |
}
|
|
|
|
| 217 |
hud();
|
| 218 |
}, 1000);
|
| 219 |
|
| 220 |
+
// Size the backing store to the viewport BEFORE anything else. Without this
|
| 221 |
+
// the canvas keeps its 300x150 default and the browser stretches it to the
|
| 222 |
+
// window -- a massively zoomed-in, blocky desktop.
|
| 223 |
+
layout();
|
| 224 |
connect();
|
| 225 |
})();
|
| 226 |
</script>
|