Commit 8c4ab03b authored by Jonathan Wilkes's avatar Jonathan Wilkes
Browse files

refactor dialog_iemgui.html to use javascript objects instead of attr_array

parent 79391c3e
......@@ -480,23 +480,19 @@ function cancel() {
// This gets called from the nw_create_window function in index.html
// It provides us with our window id from the C side. Once we have it
// we can create the menu and register event callbacks
function register_canvas_id(gfxstub, attr_array) {
function register_canvas_id(gfxstub, attr_object) {
pd_object_callback = gfxstub;
console.log('attr array is ' + attr_array.toString());
for (var i = 0; i < attr_array.length; i+=2) {
console.log(attr_array[i] + ": " + attr_array[i+1]);
}
console.log('attr object is ' + attr_object.toString());
add_events(gfxstub);
// not sure that we need this for properties windows
//pdgui.canvas_map(gfxstub);
translate_form();
populate_form(attr_array);
populate_form(attr_object);
// We don't turn on rendering of the "container" div until
// We've finished displaying all the spans and populating the
// labels and form elements. That makes it more efficient and
// snappier, at least on older machines.
document.getElementsByClassName('container')[0].style.setProperty('display', 'inline');
document.getElementsByClassName('container')[0]
.style.setProperty('display', 'inline');
pdgui.resize_window(pd_object_callback);
}
......@@ -519,25 +515,26 @@ function translate_form() {
}
}
function populate_form(attr_array) {
for(var i = 0; i < attr_array.length; i+=2) {
function populate_form(attr_object) {
var attr;
for(attr in attr_object) {
// Unhide the span with the class with the same name as the id
var prop_group = document.getElementsByClassName(attr_array[i])[0];
var prop_group = document.getElementsByClassName(attr)[0];
if (prop_group !== undefined) {
console.log("the thing here is " + attr_array[i]);
console.log("the thing here is " + attr);
prop_group.classList.remove('hidden');
} else {
pdgui.gui_post("Error: couldn't find iemgui prop group for " +
attr_array[i]);
attr);
}
// iemguis use the string 'empty' for null because of
// the limitations of Pd's state-saving API. So we have
// to filter that one out
if(attr_array[i+1] !== 'empty') {
var elem = document.getElementsByName(attr_array[i]);
if(attr_object[attr] !== 'empty') {
var elem = document.getElementsByName(attr);
if (elem.length > 0) {
if(attr_array[i].slice(-5) === 'color') {
var hex_string = Number(attr_array[i+1]).toString(16);
if(attr.slice(-5) === 'color') {
var hex_string = Number(attr_object[attr]).toString(16);
var color_string = "#" +
(hex_string === '0' ? '000000' : hex_string);
pdgui.gui_post("color is " + color_string);
......@@ -545,11 +542,11 @@ function populate_form(attr_array) {
} else if (elem[0].type === 'checkbox') {
// The attr here is a string, so we need to
// force it to number, hence the "+" below
elem[0].checked = +attr_array[i+1];
elem[0].checked = +attr_object[attr];
} else if (elem[0].type === 'select-one') {
elem[0].selectedIndex = +attr_array[i+1];
elem[0].selectedIndex = +attr_object[attr];
} else {
elem[0].value = attr_array[i+1];
elem[0].value = attr_object[attr];
}
}
}
......
......@@ -3533,6 +3533,8 @@ exports.file_dialog_callback = function(file_string) {
pdsend(file_dialog_target + " callback " + enquote(file_string));
}
// Used to convert the ["key", "value"...] arrays coming from
// Pd to a javascript object
function attr_array_to_object(attr_array) {
var i,
len = attr_array.length,
......@@ -3556,7 +3558,8 @@ function gui_iemgui_dialog(did, attr_array) {
// attr_array[i] = '"' + attr_array[i] + '"';
//}
dialogwin[did] = nw_create_window(did, 'iemgui', 265, 450, 20, 20, 0,
0, 1, 'white', 'Properties', '', 0, null, attr_array);
0, 1, 'white', 'Properties', '', 0, null,
attr_array_to_object(attr_array));
}
function gui_create_array(did, count) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment