Skip to content

Virtual whiteboard for sketching hand-drawn like diagrams

feat: render bold lines in grid (#6779)

Arnost Pleskota7c590d45938
diff --git a/src/renderer/renderScene.ts b/src/renderer/renderScene.ts
index 7d1d51027c..f8fa79ed7a 100644
--- a/src/renderer/renderScene.ts
+++ b/src/renderer/renderScene.ts
@@ -162,23 +162,52 @@ const fillCircle = (
const strokeGrid = (
context: CanvasRenderingContext2D,
gridSize: number,
- offsetX: number,
- offsetY: number,
+ scrollX: number,
+ scrollY: number,
+ zoom: Zoom,
width: 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.strokeStyle = "rgba(0,0,0,0.1)";
- context.beginPath();
+ context.lineWidth = lineWidth;
+
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.lineTo(x, offsetY + height + gridSize * 2);
+ context.stroke();
}
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.lineTo(offsetX + width + gridSize * 2, y);
+ context.stroke();
}
- context.stroke();
context.restore();
};
@@ -425,12 +454,9 @@ export const _renderScene = ({
strokeGrid(
context,
appState.gridSize,
- -Math.ceil(renderConfig.zoom.value / appState.gridSize) *
- appState.gridSize +
- (renderConfig.scrollX % appState.gridSize),
- -Math.ceil(renderConfig.zoom.value / appState.gridSize) *
- appState.gridSize +
- (renderConfig.scrollY % appState.gridSize),
+ renderConfig.scrollX,
+ renderConfig.scrollY,
+ renderConfig.zoom,
normalizedCanvasWidth / renderConfig.zoom.value,
normalizedCanvasHeight / renderConfig.zoom.value,
);