mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
Remove last get/setTransform (#964)
My original hack to put the scale when we create the canvas element doesn't make much sense. It should be done when we are rendering the scene. I moved it there in this PR. The rest was all about forwarding the scale to where it's needed.
This commit is contained in:
parent
79ea76b48b
commit
2937efacde
6 changed files with 31 additions and 13 deletions
|
@ -64,6 +64,10 @@ function generateElementCanvas(
|
|||
const rc = rough.canvas(canvas);
|
||||
drawElementOnCanvas(element, rc, context);
|
||||
context.translate(-CANVAS_PADDING, -CANVAS_PADDING);
|
||||
context.scale(
|
||||
1 / (window.devicePixelRatio * zoom),
|
||||
1 / (window.devicePixelRatio * zoom),
|
||||
);
|
||||
return { element, canvas, canvasZoom: zoom, canvasOffsetX, canvasOffsetY };
|
||||
}
|
||||
|
||||
|
|
|
@ -55,6 +55,7 @@ export function renderScene(
|
|||
const elements = allElements.filter(element => !element.isDeleted);
|
||||
|
||||
const context = canvas.getContext("2d")!;
|
||||
context.scale(scale, scale);
|
||||
|
||||
// When doing calculations based on canvas width we should used normalized one
|
||||
const normalizedCanvasWidth = canvas.width / scale;
|
||||
|
@ -205,8 +206,9 @@ export function renderScene(
|
|||
}
|
||||
|
||||
// Paint scrollbars
|
||||
let scrollBars;
|
||||
if (renderScrollbars) {
|
||||
const scrollBars = getScrollBars(
|
||||
scrollBars = getScrollBars(
|
||||
elements,
|
||||
normalizedCanvasWidth,
|
||||
normalizedCanvasHeight,
|
||||
|
@ -231,10 +233,11 @@ export function renderScene(
|
|||
});
|
||||
context.fillStyle = fillStyle;
|
||||
context.strokeStyle = strokeStyle;
|
||||
return { atLeastOneVisibleElement: visibleElements.length > 0, scrollBars };
|
||||
}
|
||||
|
||||
return { atLeastOneVisibleElement: visibleElements.length > 0 };
|
||||
context.scale(1 / scale, 1 / scale);
|
||||
|
||||
return { atLeastOneVisibleElement: visibleElements.length > 0, scrollBars };
|
||||
}
|
||||
|
||||
function isVisibleElement(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue