mirror of
git://git.tartarus.org/simon/puzzles.git
synced 2025-04-20 15:41:30 -07:00
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.
This commit is contained in:
18
emcclib.js
18
emcclib.js
@ -143,6 +143,24 @@ mergeInto(LibraryManager.library, {
|
||||
menuform.elements["preset"].value = n;
|
||||
},
|
||||
|
||||
/*
|
||||
* 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);
|
||||
*
|
||||
|
Reference in New Issue
Block a user