Skip to content

Commit 4c6febe

Browse files
Allow tiling the IconsBackground for A3 and bigger formats
1 parent 3fd36d1 commit 4c6febe

2 files changed

Lines changed: 53 additions & 10 deletions

File tree

resources/js/service/canvas/elements/background/BackgroundIcons.js

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,53 @@
11
import BackgroundImage from "./BackgroundImage";
22

33
export default class BackgroundIcons extends BackgroundImage {
4-
54
constructor() {
65
super();
7-
this._image = this.iconsImage
6+
this._image = this.iconsImage;
87
}
98

109
_drawBackground() {
11-
super._drawBackground();
10+
if (!this._image) {
11+
return;
12+
}
13+
14+
// Calculate the scaled dimensions for a single tile
15+
const minImageWidth = this._minImageWidth();
16+
const maxImageWidth = this._maxImageWidth();
17+
const scaledWidth = minImageWidth + (maxImageWidth - minImageWidth) * this._zoom;
18+
const aspectRatio = this._image.width / this._image.height;
19+
const scaledHeight = scaledWidth / aspectRatio;
20+
21+
// Calculate how many tiles we need in each direction
22+
const numTilesX = Math.ceil(this._containerWidth / scaledWidth);
23+
const numTilesY = Math.ceil(this._containerHeight / scaledHeight);
24+
25+
// Set canvas size to fit all tiles exactly
26+
this._canvas.width = numTilesX * scaledWidth;
27+
this._canvas.height = numTilesY * scaledHeight;
28+
29+
// Draw the image in a tiled pattern
30+
for (let y = 0; y < numTilesY; y++) {
31+
for (let x = 0; x < numTilesX; x++) {
32+
const destX = x * scaledWidth;
33+
const destY = y * scaledHeight;
34+
35+
this._context.drawImage(
36+
this._image,
37+
0,
38+
0,
39+
this._image.width,
40+
this._image.height,
41+
destX,
42+
destY,
43+
scaledWidth,
44+
scaledHeight
45+
);
46+
}
47+
}
48+
49+
// Repaint to validate the image
50+
this._context.drawImage(this._canvas, 0, 0);
1251
}
1352
}
1453

resources/js/service/canvas/elements/background/BackgroundImage.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,15 @@ export default class BackgroundImage extends Background {
6060
}
6161

6262
_setCanvasSize() {
63-
const aspectRatioImage = this._image.width / this._image.height;
63+
if (!this._image) {
64+
this._canvas.width = this._containerWidth;
65+
this._canvas.height = this._containerHeight;
66+
return;
67+
}
6468

69+
const aspectRatioImage = this._image.width / this._image.height;
6570
const minImageWidth = this._minImageWidth();
6671
const maxImageWidth = this._maxImageWidth();
67-
6872
const width = minImageWidth + (maxImageWidth - minImageWidth) * this._zoom;
6973
const height = width / aspectRatioImage;
7074

@@ -99,11 +103,11 @@ export default class BackgroundImage extends Background {
99103
// landscape
100104
const maxZoomedWidth = this._image.width * MaxImageZoomFactor;
101105
return Math.min(maxZoomedWidth, CanvasMaxSideLen);
106+
} else {
107+
// portrait
108+
const maxZoomedHeight = this._image.height * MaxImageZoomFactor;
109+
const maxHeight = Math.min(maxZoomedHeight, CanvasMaxSideLen);
110+
return maxHeight * aspectRatio;
102111
}
103-
104-
// portrait
105-
const maxZoomedHeight = this._image.height * MaxImageZoomFactor;
106-
const maxHeight = Math.min(maxZoomedHeight, CanvasMaxSideLen);
107-
return maxHeight * aspectRatio;
108112
}
109113
}

0 commit comments

Comments
 (0)