feat: render bold lines in grid (#6779)
Co-authored-by: dwelle <luzar.david@gmail.com>
This commit is contained in:
parent
48924688c7
commit
a7c590d459
@ -162,23 +162,52 @@ const fillCircle = (
|
|||||||
const strokeGrid = (
|
const strokeGrid = (
|
||||||
context: CanvasRenderingContext2D,
|
context: CanvasRenderingContext2D,
|
||||||
gridSize: number,
|
gridSize: number,
|
||||||
offsetX: number,
|
scrollX: number,
|
||||||
offsetY: number,
|
scrollY: number,
|
||||||
|
zoom: Zoom,
|
||||||
width: number,
|
width: number,
|
||||||
height: number,
|
height: number,
|
||||||
) => {
|
) => {
|
||||||
|
const BOLD_LINE_FREQUENCY = 5;
|
||||||
|
|
||||||
|
enum GridLineColor {
|
||||||
|
Bold = "#cccccc",
|
||||||
|
Regular = "#e5e5e5",
|
||||||
|
}
|
||||||
|
|
||||||
|
const offsetX =
|
||||||
|
-Math.round(zoom.value / gridSize) * gridSize + (scrollX % gridSize);
|
||||||
|
const offsetY =
|
||||||
|
-Math.round(zoom.value / gridSize) * gridSize + (scrollY % gridSize);
|
||||||
|
|
||||||
|
const lineWidth = Math.min(1 / zoom.value, 1);
|
||||||
|
|
||||||
|
const spaceWidth = 1 / zoom.value;
|
||||||
|
const lineDash = [lineWidth * 3, spaceWidth + (lineWidth + spaceWidth)];
|
||||||
|
|
||||||
context.save();
|
context.save();
|
||||||
context.strokeStyle = "rgba(0,0,0,0.1)";
|
context.lineWidth = lineWidth;
|
||||||
context.beginPath();
|
|
||||||
for (let x = offsetX; x < offsetX + width + gridSize * 2; x += gridSize) {
|
for (let x = offsetX; x < offsetX + width + gridSize * 2; x += gridSize) {
|
||||||
|
const isBold =
|
||||||
|
Math.round(x - scrollX) % (BOLD_LINE_FREQUENCY * gridSize) === 0;
|
||||||
|
context.beginPath();
|
||||||
|
context.setLineDash(isBold ? [] : lineDash);
|
||||||
|
context.strokeStyle = isBold ? GridLineColor.Bold : GridLineColor.Regular;
|
||||||
context.moveTo(x, offsetY - gridSize);
|
context.moveTo(x, offsetY - gridSize);
|
||||||
context.lineTo(x, offsetY + height + gridSize * 2);
|
context.lineTo(x, offsetY + height + gridSize * 2);
|
||||||
|
context.stroke();
|
||||||
}
|
}
|
||||||
for (let y = offsetY; y < offsetY + height + gridSize * 2; y += gridSize) {
|
for (let y = offsetY; y < offsetY + height + gridSize * 2; y += gridSize) {
|
||||||
|
const isBold =
|
||||||
|
Math.round(y - scrollY) % (BOLD_LINE_FREQUENCY * gridSize) === 0;
|
||||||
|
context.beginPath();
|
||||||
|
context.setLineDash(isBold ? [] : lineDash);
|
||||||
|
context.strokeStyle = isBold ? GridLineColor.Bold : GridLineColor.Regular;
|
||||||
context.moveTo(offsetX - gridSize, y);
|
context.moveTo(offsetX - gridSize, y);
|
||||||
context.lineTo(offsetX + width + gridSize * 2, y);
|
context.lineTo(offsetX + width + gridSize * 2, y);
|
||||||
|
context.stroke();
|
||||||
}
|
}
|
||||||
context.stroke();
|
|
||||||
context.restore();
|
context.restore();
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -425,12 +454,9 @@ export const _renderScene = ({
|
|||||||
strokeGrid(
|
strokeGrid(
|
||||||
context,
|
context,
|
||||||
appState.gridSize,
|
appState.gridSize,
|
||||||
-Math.ceil(renderConfig.zoom.value / appState.gridSize) *
|
renderConfig.scrollX,
|
||||||
appState.gridSize +
|
renderConfig.scrollY,
|
||||||
(renderConfig.scrollX % appState.gridSize),
|
renderConfig.zoom,
|
||||||
-Math.ceil(renderConfig.zoom.value / appState.gridSize) *
|
|
||||||
appState.gridSize +
|
|
||||||
(renderConfig.scrollY % appState.gridSize),
|
|
||||||
normalizedCanvasWidth / renderConfig.zoom.value,
|
normalizedCanvasWidth / renderConfig.zoom.value,
|
||||||
normalizedCanvasHeight / renderConfig.zoom.value,
|
normalizedCanvasHeight / renderConfig.zoom.value,
|
||||||
);
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user