aboutsummaryrefslogtreecommitdiff
path: root/emcclib.js
diff options
context:
space:
mode:
authorBen Harris <bjh21@bjh21.me.uk>2022-12-10 17:49:49 +0000
committerBen Harris <bjh21@bjh21.me.uk>2022-12-10 17:58:41 +0000
commit14eb35da4aa8a66a05012af9860a7088dbf21c6d (patch)
treea93b255cf2e0b3294a24c58cb373391fe85c108d /emcclib.js
parent02f1d55a023eeab52b20cb5db6428f8ff40b9459 (diff)
downloadpuzzles-14eb35da4aa8a66a05012af9860a7088dbf21c6d.zip
puzzles-14eb35da4aa8a66a05012af9860a7088dbf21c6d.tar.gz
puzzles-14eb35da4aa8a66a05012af9860a7088dbf21c6d.tar.bz2
puzzles-14eb35da4aa8a66a05012af9860a7088dbf21c6d.tar.xz
js: Set the default colour from the CSS background of the canvas
This allows the HTML/CSS to decide that it would like a different background colour without the need to recompile. The default if the CSS specifies no colour (and hence the canvas is transparent) is the same grey as before.
Diffstat (limited to 'emcclib.js')
-rw-r--r--emcclib.js18
1 files changed, 18 insertions, 0 deletions
diff --git a/emcclib.js b/emcclib.js
index 02085bd..b63c6b2 100644
--- a/emcclib.js
+++ b/emcclib.js
@@ -144,6 +144,24 @@ mergeInto(LibraryManager.library, {
},
/*
+ * void js_default_colour(float *output);
+ *
+ * Try to extract a default colour from the CSS computed
+ * background colour of the canvas element.
+ */
+ js_default_colour: function(output) {
+ var col = window.getComputedStyle(onscreen_canvas).backgroundColor;
+ /* We only support opaque sRGB colours. */
+ var m = col.match(
+ /^rgb\((\d+(?:\.\d+)?), (\d+(?:\.\d+)?), (\d+(?:\.\d+)?)\)$/);
+ if (m) {
+ setValue(output, +m[1] / 255, "float");
+ setValue(output + 4, +m[2] / 255, "float");
+ setValue(output + 8, +m[3] / 255, "float");
+ }
+ },
+
+ /*
* void js_set_background_colour(const char *bg);
*
* Record the puzzle background colour in a CSS variable so