idraw/examples/board/features/lib/draw.js

37 lines
1.2 KiB
JavaScript
Raw Permalink Normal View History

2021-05-25 04:58:29 +00:00
import opts from './opts.js';
import { getData } from './data.js';
2021-05-25 02:39:56 +00:00
export function drawData(board, idx) {
2021-05-25 04:58:29 +00:00
const ctx = board.getContext();
const helperCtx = board.getHelperContext();
2021-05-25 04:58:29 +00:00
const data = getData();
board.clear();
2021-11-15 14:58:20 +00:00
ctx.clearRect(0, 0, opts.devicePixelRatio * opts.contextWidth, opts.devicePixelRatio * opts.contextHeight);
helperCtx.clearRect(0, 0, opts.devicePixelRatio * opts.contextWidth, opts.devicePixelRatio * opts.contextHeight);
// ctx.setFillStyle('#ffffff');
// ctx.fillRect(0, 0, opts.width, opts.height);
data.elements.forEach((ele, i) => {
2021-05-25 04:58:29 +00:00
ctx.setFillStyle(ele.desc.color);
ctx.fillRect(ele.x, ele.y, ele.w, ele.h);
// helperCtx.setFillStyle('#2196f3');
// helperCtx.fillRect(ele.x, ele.y, ele.w, ele.h);
if (i === idx) {
helperCtx.beginPath();
helperCtx.setLineDash([4, 4]);
helperCtx.setLineWidth(2);
helperCtx.setStrokeStyle('#2196f3');
helperCtx.moveTo(ele.x, ele.y);
helperCtx.lineTo(ele.x + ele.w, ele.y);
helperCtx.lineTo(ele.x + ele.w, ele.y + ele.h);
helperCtx.lineTo(ele.x, ele.y + ele.h);
helperCtx.lineTo(ele.x, ele.y);
helperCtx.stroke();
helperCtx.closePath();
}
2021-05-25 04:58:29 +00:00
});
2021-05-25 02:39:56 +00:00
board.draw();
}