Skip to content

Commit

Permalink
Tweak how backgrounds work to avoid black lines in saved images
Browse files Browse the repository at this point in the history
  • Loading branch information
neilh-cogapp committed Mar 21, 2024
1 parent 499808a commit 65f7789
Show file tree
Hide file tree
Showing 10 changed files with 10 additions and 16 deletions.
Binary file added public/rooms/room-1.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed public/rooms/room-1.png
Binary file not shown.
Binary file added public/rooms/room-2.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed public/rooms/room-2.png
Binary file not shown.
Binary file added public/rooms/room-3.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed public/rooms/room-3.png
Binary file not shown.
Binary file added public/rooms/room-4.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed public/rooms/room-4.png
Binary file not shown.
18 changes: 6 additions & 12 deletions src/app/components/Canvas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ const Canvas = (
useEffect(() => {
if (divRef.current?.offsetHeight && divRef.current?.offsetWidth) {
setSize({
width: divRef.current.offsetWidth,
height: divRef.current.offsetHeight,
width: Math.min(divRef.current.offsetWidth, CANVAS_VIRTUAL_WIDTH),
height: Math.min(divRef.current.offsetHeight, CANVAS_VIRTUAL_HEIGHT),
});
}
}, []);
Expand All @@ -45,8 +45,8 @@ const Canvas = (
const checkSize = () => {
if (divRef.current?.offsetHeight && divRef.current?.offsetWidth) {
setSize({
width: divRef.current.offsetWidth,
height: divRef.current.offsetHeight,
width: Math.min(divRef.current.offsetWidth, CANVAS_VIRTUAL_WIDTH),
height: Math.min(divRef.current.offsetHeight, CANVAS_VIRTUAL_HEIGHT),
});
}
};
Expand Down Expand Up @@ -82,15 +82,10 @@ const Canvas = (
};
}, [selectedId, images, setImages]);

const scale = Math.min(
divRef.current?.offsetWidth ? divRef.current?.offsetWidth / CANVAS_VIRTUAL_WIDTH : CANVAS_VIRTUAL_WIDTH,
divRef.current?.offsetHeight ? divRef.current?.offsetWidth / CANVAS_VIRTUAL_HEIGHT : CANVAS_VIRTUAL_HEIGHT,
);

return (
<div
ref={divRef}
className="h-full w-full bg-contain bg-center bg-no-repeat"
className="h-full w-full"
onDragOver={(e) => e.preventDefault()}
onDrop={(e) => {
e.preventDefault();
Expand All @@ -100,11 +95,10 @@ const Canvas = (
}}
>
<Stage
className="flex justify-center"
ref={forwardedRef}
width={size.width}
height={size.height}
scaleX={scale}
scaleY={scale}
onMouseDown={checkDeselect}
onTouchStart={checkDeselect}
>
Expand Down
8 changes: 4 additions & 4 deletions src/app/components/backgrounds.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const backgroundImages = [
'/rooms/room-1.png',
'/rooms/room-2.png',
'/rooms/room-3.png',
'/rooms/room-4.png',
'/rooms/room-1.jpeg',
'/rooms/room-2.jpeg',
'/rooms/room-3.jpeg',
'/rooms/room-4.jpeg',
];

export {
Expand Down

0 comments on commit 65f7789

Please sign in to comment.