Skip to content

Instantly share code, notes, and snippets.

@jimoneil
Created May 16, 2013 14:04
Show Gist options
  • Save jimoneil/5591962 to your computer and use it in GitHub Desktop.
Save jimoneil/5591962 to your computer and use it in GitHub Desktop.
Windows 8 settings flyout script demonstrating how to interact with Construct 2 global variables
var customizer = (function () {
"use strict";
var t = {};
//flip the RGB components
function flipRGB(colorIn)
{
var part1 = colorIn & 0xFF0000;
var part2 = colorIn & 0xFF00;
var part3 = colorIn & 0xFF;
return (part3 << 16) | part2 | (part1 >> 16);
}
// get reference to global by name
function getConstruct2Global(varName) {
var allGlobals = cr_getC2Runtime().all_global_vars;
for (var i in allGlobals)
if (allGlobals[i].name === varName) {
return allGlobals[i];
}
}
// get background color
t.getBackgroundColor = function () {
var backgroundColor = getConstruct2Global("BackgroundColor");
return flipRGB(backgroundColor.getValue());
};
// set background color
t.setBackgroundColor = function (newColor) {
var backgroundColor = getConstruct2Global("BackgroundColor");
return flipRGB(backgroundColor.setValue(flipRGB(newColor)));
}
// initialize flyout
t.init = function () {
jscolor.init();
var colorPicker = new jscolor.color(
document.getElementById("colorText"), {});
colorPicker.fromString(t.getBackgroundColor().toString(16));
colorPicker.onImmediateChange = function () {
t.setBackgroundColor(parseInt(colorPicker.valueElement.value, 16));
}
}
// required to allow function to be invoked in setting flyout event
t.init.supportedForProcessing = true;
return t;
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment