Skip to content

Commit 75c902e

Browse files
committed
Canvas size in custom parameters
1 parent fd4116e commit 75c902e

File tree

4 files changed

+45
-7
lines changed

4 files changed

+45
-7
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
## ShaderToy extension changelog (major changes only):
2+
- 0.14.272 (11-01-2025)
3+
4+
- Canvas size can be set with custom parameters object in common tab. [See documentation](./docs/custom-params.md)
5+
26
- 0.14.266 (02-10-2024)
37

48
- Resoulution can be multiplied (alt + shift + 1...9)

README.md

+2-6
Original file line numberDiff line numberDiff line change
@@ -173,13 +173,9 @@ Please add issue with description before PR.
173173

174174
Render timing based on [shadertoy_gpu_timing.user.js](https://github.com/andrei-drexler/shadertoy-userscripts/blob/master/shadertoy_gpu_timing.user.js) by [Andrei Drexler](https://github.com/andrei-drexler)
175175

176-
## Beer? Sure.
176+
## Beer? Sure!
177177

178-
If you find this extension useful, I'd love to hug a beer [PayPal](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=VDFNBT9N3ANHW&source=url). :beer:
179-
180-
```
181-
int totalBeers = 3;
182-
```
178+
If you find this extension useful, I'd love to hug :beer: via [PayPal](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=VDFNBT9N3ANHW&source=url)
183179

184180
## Changelog:
185181

app/add-ons/shadertoy-plugin-parameters.js

+38
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,44 @@
5353
});
5454
});
5555
}
56+
57+
if (params.canvas) {
58+
const canvas = document.getElementById("demogl");
59+
canvas.style.margin = "auto";
60+
61+
const xres = params.canvas.width;
62+
const yres = params.canvas.height;
63+
64+
if (!Number.isInteger(xres) || !Number.isInteger(yres)) {
65+
return;
66+
}
67+
68+
const mE = gShaderToy.mEffect;
69+
70+
mE.mCanvas.setAttribute('width', xres);
71+
mE.mCanvas.setAttribute('height', yres);
72+
73+
mE.mCanvas.width = xres;
74+
mE.mCanvas.height = yres;
75+
76+
mE.mXres = xres;
77+
mE.mYres = yres;
78+
79+
mE.ResizeBuffers(xres, yres);
80+
81+
gShaderToy.iSetResolution(xres, yres);
82+
83+
canvas.style.aspectRatio = `${xres}/${yres}`;
84+
85+
if (xres <= canvas.clientWidth) {
86+
canvas.style.width = `${xres}px`;
87+
} else {
88+
canvas.style.width = "100%";
89+
}
90+
91+
console.log(canvas.clientWidth, canvas.clientHeight);
92+
window.dispatchEvent(new Event("resize"));
93+
}
5694
}
5795

5896
// Evaluate parameters on load

app/manifest.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"manifest_version": 3,
33
"name": "Shadertoy unofficial plugin.",
4-
"version": "0.14.270",
4+
"version": "0.14.271",
55
"description": "Shadertoy.com unofficial plugin.",
66
"homepage_url": "https://github.com/patuwwy/ShaderToy-Chrome-Plugin",
77
"background": {

0 commit comments

Comments
 (0)