浏览代码

Allow toggling of screen-fitting

master
Fen Dweller 5 年前
父节点
当前提交
7bca7b2f8a
共有 2 个文件被更改,包括 15 次插入5 次删除
  1. +4
    -0
      xray.html
  2. +11
    -5
      xray.js

+ 4
- 0
xray.html 查看文件

@@ -39,6 +39,10 @@
Paint mode: Paint mode:
<input type="checkbox" id="paint-mode"> <input type="checkbox" id="paint-mode">
</label> </label>
<label class="nostart large">
Fit to screen:
<input type="checkbox" id="fit-screen" checked>
</label>
</div> </div>
<div id="fill-div"> <div id="fill-div">


+ 11
- 5
xray.js 查看文件

@@ -11,6 +11,7 @@ let softness = 25;
let width; let width;
let height; let height;


let fitScreen = true;
let paintMode = false; let paintMode = false;


let scale; let scale;
@@ -255,6 +256,11 @@ document.addEventListener("DOMContentLoaded", e => {
document.querySelector("#paint-mode").addEventListener("change", e => { document.querySelector("#paint-mode").addEventListener("change", e => {
paintMode = e.target.checked; paintMode = e.target.checked;
}); });
document.querySelector("#fit-screen").addEventListener("change", e => {
fitScreen = e.target.checked;
setup();
});
}); });


function load() { function load() {
@@ -327,16 +333,16 @@ function setup() {


const scaleW = availableWidth / baseImg.width; const scaleW = availableWidth / baseImg.width;
const scaleH = availableHeight / baseImg.height; const scaleH = availableHeight / baseImg.height;
scale = Math.min(scaleW, scaleH);
scale = fitScreen ? Math.min(scaleW, scaleH) : 1;


width = Math.floor(availableWidth * scale / scaleW);
height = Math.floor(availableHeight * scale / scaleH);
width = fitScreen ? Math.floor(availableWidth * scale / scaleW) : baseImg.width;
height = fitScreen ? Math.floor(availableHeight * scale / scaleH) : baseImg.height;


[baseCtx, baseCtxResized, overlayCtx, overlayCtxResized].forEach(ctx => { [baseCtx, baseCtxResized, overlayCtx, overlayCtxResized].forEach(ctx => {
ctx.canvas.width = width; ctx.canvas.width = width;
ctx.canvas.height = height; ctx.canvas.height = height;
ctx.canvas.style.left = (availableWidth - width) / 2 + "px";
ctx.canvas.style.top = (availableHeight - height) / 2 + "px";
ctx.canvas.style.left = fitScreen ? (availableWidth - width) / 2 + "px" : 0;
ctx.canvas.style.top = fitScreen ? (availableHeight - height) / 2 + "px" : 0;
}); });
baseCtxResized.drawImage(baseImg, 0, 0, width, height); baseCtxResized.drawImage(baseImg, 0, 0, width, height);


正在加载...
取消
保存