merged szimeks formatting with current branch

This commit is contained in:
Jono Brandel 2011-02-11 11:12:07 -08:00
commit 5d43707a21
9 changed files with 1077 additions and 1079 deletions

View File

@ -1,39 +1,39 @@
GUI.BooleanController = function() { GUI.BooleanController = function() {
this.type = "boolean"; this.type = "boolean";
GUI.Controller.apply(this, arguments); GUI.Controller.apply(this, arguments);
var _this = this; var _this = this;
var input = document.createElement('input'); var input = document.createElement('input');
input.setAttribute('type', 'checkbox'); input.setAttribute('type', 'checkbox');
this.domElement.addEventListener('click', function(e) { this.domElement.addEventListener('click', function(e) {
input.checked = !input.checked; input.checked = !input.checked;
e.preventDefault(); e.preventDefault();
_this.setValue(input.checked); _this.setValue(input.checked);
}, false); }, false);
input.addEventListener('mouseup', function(e) { input.addEventListener('mouseup', function(e) {
input.checked = !input.checked; // counteracts default. input.checked = !input.checked; // counteracts default.
}, false); }, false);
this.domElement.style.cursor = "pointer"; this.domElement.style.cursor = "pointer";
this.propertyNameElement.style.cursor = "pointer"; this.propertyNameElement.style.cursor = "pointer";
this.domElement.appendChild(input); this.domElement.appendChild(input);
this.updateDisplay = function() { this.updateDisplay = function() {
input.checked = _this.getValue(); input.checked = _this.getValue();
}; };
this.setValue = function(val) { this.setValue = function(val) {
if (typeof val != "boolean") { if (typeof val != "boolean") {
try { try {
val = eval(val); val = eval(val);
} catch (e) {} } catch (e) {}
} }
return GUI.Controller.prototype.setValue.call(this, val); return GUI.Controller.prototype.setValue.call(this, val);
} };
}; };
GUI.extendController(GUI.BooleanController); GUI.extendController(GUI.BooleanController);

View File

@ -1,30 +1,29 @@
GUI.FunctionController = function() { GUI.FunctionController = function() {
this.type = "function"; this.type = "function";
var _this = this; var _this = this;
GUI.Controller.apply(this, arguments); GUI.Controller.apply(this, arguments);
this.domElement.addEventListener('click', function() { this.domElement.addEventListener('click', function() {
_this.fire(); _this.fire();
}, false); }, false);
this.domElement.style.cursor = "pointer"; this.domElement.style.cursor = "pointer";
this.propertyNameElement.style.cursor = "pointer"; this.propertyNameElement.style.cursor = "pointer";
var fireFunction = null; var fireFunction = null;
this.onFire = function(fnc) { this.onFire = function(fnc) {
fireFunction = fnc; fireFunction = fnc;
return this; return this;
} }
this.fire = function() { this.fire = function() {
_this.object[_this.propertyName].call(_this.object); if (fireFunction != null) {
if (fireFunction != null) { fireFunction.call(this);
fireFunction.call(this); }
} _this.object[_this.propertyName].call(_this.object);
}; };
}; };
GUI.extendController(GUI.FunctionController); GUI.extendController(GUI.FunctionController);

View File

@ -1,96 +1,97 @@
GUI.Controller = function() { GUI.Controller = function() {
this.parent = arguments[0]; this.parent = arguments[0];
this.object = arguments[1]; this.object = arguments[1];
this.propertyName = arguments[2]; this.propertyName = arguments[2];
if (arguments.length > 0) this.initialValue = this.propertyName[this.object]; if (arguments.length > 0) this.initialValue = this.propertyName[this.object];
this.domElement = document.createElement('div'); this.domElement = document.createElement('div');
this.domElement.setAttribute('class', 'guidat-controller ' + this.type); this.domElement.setAttribute('class', 'guidat-controller ' + this.type);
this.propertyNameElement = document.createElement('span'); this.propertyNameElement = document.createElement('span');
this.propertyNameElement.setAttribute('class', 'guidat-propertyname'); this.propertyNameElement.setAttribute('class', 'guidat-propertyname');
this.name(this.propertyName); this.name(this.propertyName);
this.domElement.appendChild(this.propertyNameElement); this.domElement.appendChild(this.propertyNameElement);
GUI.makeUnselectable(this.domElement); GUI.makeUnselectable(this.domElement);
}; };
GUI.Controller.prototype.changeFunction = null; GUI.Controller.prototype.changeFunction = null;
GUI.Controller.prototype.finishChangeFunction = null; GUI.Controller.prototype.finishChangeFunction = null;
GUI.Controller.prototype.name = function(n) { GUI.Controller.prototype.name = function(n) {
this.propertyNameElement.innerHTML = n; this.propertyNameElement.innerHTML = n;
return this; return this;
}; };
GUI.Controller.prototype.reset = function() { GUI.Controller.prototype.reset = function() {
this.setValue(this.initialValue); this.setValue(this.initialValue);
return this; return this;
}; };
GUI.Controller.prototype.listen = function() { GUI.Controller.prototype.listen = function() {
this.parent.listenTo(this); this.parent.listenTo(this);
return this; return this;
} };
GUI.Controller.prototype.unlisten = function() { GUI.Controller.prototype.unlisten = function() {
this.parent.unlistenTo(this); // <--- hasn't been tested yet this.parent.unlistenTo(this); // <--- hasn't been tested yet
return this; return this;
} };
GUI.Controller.prototype.setValue = function(n) { GUI.Controller.prototype.setValue = function(n) {
this.object[this.propertyName] = n; this.object[this.propertyName] = n;
if (this.changeFunction != null) { if (this.changeFunction != null) {
this.changeFunction.call(this, n); this.changeFunction.call(this, n);
} }
this.updateDisplay(); this.updateDisplay();
return this; return this;
} };
GUI.Controller.prototype.getValue = function() { GUI.Controller.prototype.getValue = function() {
return this.object[this.propertyName]; return this.object[this.propertyName];
} };
GUI.Controller.prototype.updateDisplay = function() {};
GUI.Controller.prototype.updateDisplay = function() {}
GUI.Controller.prototype.onChange = function(fnc) { GUI.Controller.prototype.onChange = function(fnc) {
this.changeFunction = fnc; this.changeFunction = fnc;
return this; return this;
} };
GUI.Controller.prototype.onFinishChange = function(fnc) { GUI.Controller.prototype.onFinishChange = function(fnc) {
this.finishChangeFunction = fnc; this.finishChangeFunction = fnc;
return this; return this;
} };
GUI.Controller.prototype.options = function() { GUI.Controller.prototype.options = function() {
var _this = this; var _this = this;
var select = document.createElement('select'); var select = document.createElement('select');
if (arguments.length == 1) { if (arguments.length == 1) {
var arr = arguments[0]; var arr = arguments[0];
for (var i in arr) { for (var i in arr) {
var opt = document.createElement('option'); var opt = document.createElement('option');
opt.innerHTML = i; opt.innerHTML = i;
opt.setAttribute('value', arr[i]); opt.setAttribute('value', arr[i]);
select.appendChild(opt); select.appendChild(opt);
} }
} else { } else {
for (var i = 0; i < arguments.length; i++) { for (var i = 0; i < arguments.length; i++) {
var opt = document.createElement('option'); var opt = document.createElement('option');
opt.innerHTML = arguments[i]; opt.innerHTML = arguments[i];
opt.setAttribute('value', arguments[i]); opt.setAttribute('value', arguments[i]);
select.appendChild(opt); select.appendChild(opt);
} }
} }
select.addEventListener('change', function() { select.addEventListener('change', function() {
_this.setValue(this.value); _this.setValue(this.value);
if (_this.finishChangeFunction != null) { if (_this.finishChangeFunction != null) {
_this.finishChangeFunction.call(this, _this.getValue()); _this.finishChangeFunction.call(this, _this.getValue());
} }
}); }, false);
_this.domElement.appendChild(select); _this.domElement.appendChild(select);
return this; return this;
} };

View File

@ -1,153 +1,152 @@
GUI.NumberController = function() { GUI.NumberController = function() {
this.type = "number"; this.type = "number";
GUI.Controller.apply(this, arguments); GUI.Controller.apply(this, arguments);
var _this = this; var _this = this;
// If we simply click and release a number field, we want to highlight it. // If we simply click and release a number field, we want to highlight it.
// This variable keeps track of whether or not we've dragged // This variable keeps track of whether or not we've dragged
var draggedNumberField = false; var draggedNumberField = false;
var clickedNumberField = false; var clickedNumberField = false;
var y = py = 0; var y = 0, py = 0;
var min = arguments[3]; var min = arguments[3];
var max = arguments[4]; var max = arguments[4];
var step = arguments[5]; var step = arguments[5];
if (!step) { if (!step) {
if (min != undefined && max != undefined) { if (min != undefined && max != undefined) {
step = (max-min)*0.01; step = (max-min)*0.01;
} else { } else {
step = 1; step = 1;
} }
} }
var numberField = document.createElement('input'); var numberField = document.createElement('input');
numberField.setAttribute('id', this.propertyName); numberField.setAttribute('id', this.propertyName);
numberField.setAttribute('type', 'text'); numberField.setAttribute('type', 'text');
numberField.setAttribute('value', this.getValue()); numberField.setAttribute('value', this.getValue());
if (step) numberField.setAttribute('step', step); if (step) numberField.setAttribute('step', step);
this.domElement.appendChild(numberField); this.domElement.appendChild(numberField);
var slider; var slider;
if (min != undefined && max != undefined) { if (min != undefined && max != undefined) {
slider = new GUI.Slider(this, min, max, step, this.getValue()); slider = new GUI.Slider(this, min, max, step, this.getValue());
this.domElement.appendChild(slider.domElement); this.domElement.appendChild(slider.domElement);
} }
numberField.addEventListener('blur', function(e) { numberField.addEventListener('blur', function(e) {
var val = parseFloat(this.value); var val = parseFloat(this.value);
console.log(val);
if (!isNaN(val)) { if (!isNaN(val)) {
_this.setValue(val); _this.setValue(val);
} }
}, false); }, false);
numberField.addEventListener('mousewheel', function(e) { numberField.addEventListener('mousewheel', function(e) {
e.preventDefault(); e.preventDefault();
_this.setValue(_this.getValue() + Math.abs(e.wheelDeltaY)/e.wheelDeltaY*step); _this.setValue(_this.getValue() + Math.abs(e.wheelDeltaY)/e.wheelDeltaY*step);
return false; return false;
}, false); }, false);
numberField.addEventListener('mousedown', function(e) { numberField.addEventListener('mousedown', function(e) {
py = y = e.pageY; py = y = e.pageY;
clickedNumberField = true; clickedNumberField = true;
document.addEventListener('mousemove', dragNumberField, false); document.addEventListener('mousemove', dragNumberField, false);
document.addEventListener('mouseup', mouseup, false); document.addEventListener('mouseup', mouseup, false);
}, false);
// Handle up arrow and down arrow
numberField.addEventListener('keydown', function(e) {
var newVal;
switch(e.keyCode) {
case 38: // up
newVal = _this.getValue() + step;
_this.setValue(newVal);
break;
case 40: // down
newVal = _this.getValue() - step;
_this.setValue(newVal);
break;
}
}, false); }, false);
// Handle up arrow and down arrow
numberField.addEventListener('keydown', function(e) {
switch(e.keyCode) {
case 38: // up
var newVal = _this.getValue() + step;
_this.setValue(newVal);
break;
case 40: // down
var newVal = _this.getValue() - step;
_this.setValue(newVal);
break;
}
}, false);
var mouseup = function(e) { var mouseup = function(e) {
document.removeEventListener('mousemove', dragNumberField, false); document.removeEventListener('mousemove', dragNumberField, false);
GUI.makeSelectable(_this.parent.domElement); GUI.makeSelectable(_this.parent.domElement);
GUI.makeSelectable(numberField); GUI.makeSelectable(numberField);
if (clickedNumberField && !draggedNumberField) { if (clickedNumberField && !draggedNumberField) {
numberField.focus(); numberField.focus();
numberField.select(); numberField.select();
} }
if(slider) slider.domElement.className = slider.domElement.className.replace(' active', ''); if(slider) slider.domElement.className = slider.domElement.className.replace(' active', '');
draggedNumberField = false; draggedNumberField = false;
clickedNumberField = false; clickedNumberField = false;
if (_this.finishChangeFunction != null) { if (_this.finishChangeFunction != null) {
_this.finishChangeFunction.call(this, _this.getValue()); _this.finishChangeFunction.call(this, _this.getValue());
} }
document.removeEventListener('mouseup', mouseup, false); document.removeEventListener('mouseup', mouseup, false);
} };
var dragNumberField = function(e) { var dragNumberField = function(e) {
draggedNumberField = true;
e.preventDefault();
// We don't want to be highlighting this field as we scroll. draggedNumberField = true;
// Or any other fields in this gui for that matter ... e.preventDefault();
// TODO: Make makeUselectable go through each element and child element.
// We don't want to be highlighting this field as we scroll.
// Or any other fields in this gui for that matter ...
// TODO: Make makeUselectable go through each element and child element.
GUI.makeUnselectable(_this.parent.domElement);
GUI.makeUnselectable(numberField);
if(slider) slider.domElement.className += ' active';
py = y;
y = e.pageY;
var dy = py - y;
var newVal = _this.getValue() + dy*step;
_this.setValue(newVal);
return false;
};
GUI.makeUnselectable(_this.parent.domElement);
GUI.makeUnselectable(numberField);
if(slider) slider.domElement.className += ' active';
py = y;
y = e.pageY;
var dy = py - y;
var newVal = _this.getValue() + dy*step;
_this.setValue(newVal);
return false;
}
this.options = function() { this.options = function() {
_this.noSlider(); _this.noSlider();
_this.domElement.removeChild(numberField); _this.domElement.removeChild(numberField);
return GUI.Controller.prototype.options.apply(this, arguments); return GUI.Controller.prototype.options.apply(this, arguments);
}; };
this.noSlider = function() { this.noSlider = function() {
if (slider) { if (slider) {
_this.domElement.removeChild(slider.domElement); _this.domElement.removeChild(slider.domElement);
} }
return this; return this;
}; };
this.setValue = function(val) { this.setValue = function(val) {
val = parseFloat(val); val = parseFloat(val);
if (min != undefined && val <= min) { if (min != undefined && val <= min) {
val = min; val = min;
} else if (max != undefined && val >= max) { } else if (max != undefined && val >= max) {
val = max; val = max;
} }
return GUI.Controller.prototype.setValue.call(this, val); return GUI.Controller.prototype.setValue.call(this, val);
} };
this.updateDisplay = function() { this.updateDisplay = function() {
numberField.value = GUI.roundToDecimal(_this.getValue(), 4); numberField.value = GUI.roundToDecimal(_this.getValue(), 4);
if (slider) slider.value = _this.getValue(); if (slider) slider.value = _this.getValue();
} };
}; };
GUI.extendController(GUI.NumberController); GUI.extendController(GUI.NumberController);

View File

@ -1,47 +1,47 @@
GUI.StringController = function() { GUI.StringController = function() {
this.type = "string"; this.type = "string";
var _this = this; var _this = this;
GUI.Controller.apply(this, arguments); GUI.Controller.apply(this, arguments);
var input = document.createElement('input'); var input = document.createElement('input');
var initialValue = this.getValue(); var initialValue = this.getValue();
input.setAttribute('value', initialValue); input.setAttribute('value', initialValue);
input.setAttribute('spellcheck', 'false'); input.setAttribute('spellcheck', 'false');
this.domElement.addEventListener('mouseup', function() { this.domElement.addEventListener('mouseup', function() {
input.focus(); input.focus();
input.select(); input.select();
}, false); }, false);
// TODO: getting messed up on ctrl a // TODO: getting messed up on ctrl a
input.addEventListener('keyup', function(e) { input.addEventListener('keyup', function(e) {
if (e.keyCode == 13 && _this.finishChangeFunction != null) { if (e.keyCode == 13 && _this.finishChangeFunction != null) {
_this.finishChangeFunction.call(this, _this.getValue()); _this.finishChangeFunction.call(this, _this.getValue());
} }
_this.setValue(input.value); _this.setValue(input.value);
}, false); }, false);
input.addEventListener('blur', function() { input.addEventListener('blur', function() {
if (_this.finishChangeFunction != null) { if (_this.finishChangeFunction != null) {
_this.finishChangeFunction.call(this, _this.getValue()); _this.finishChangeFunction.call(this, _this.getValue());
} }
}, false); }, false);
this.updateDisplay = function() { this.updateDisplay = function() {
input.value = _this.getValue(); input.value = _this.getValue();
}
this.options = function() {
_this.domElement.removeChild(input);
return GUI.Controller.prototype.options.apply(this, arguments);
}; };
this.options = function() {
_this.domElement.removeChild(input);
return GUI.Controller.prototype.options.apply(this, arguments);
};
this.domElement.appendChild(input); this.domElement.appendChild(input);
}; };
GUI.extendController(GUI.StringController); GUI.extendController(GUI.StringController);

View File

@ -1,71 +1,92 @@
GUI.Slider = function(numberController, min, max, step, initValue) { GUI.Slider = function(numberController, min, max, step, initValue) {
var min = min; var clicked = false;
var max = max; var _this = this;
var step = step;
var clicked = false;
var _this = this;
var x, px;
this.domElement = document.createElement('div');
this.domElement.setAttribute('class', 'guidat-slider-bg');
this.fg = document.createElement('div');
this.fg.setAttribute('class', 'guidat-slider-fg');
this.domElement.appendChild(this.fg);
var findPos = function(obj) {
var curleft = curtop = 0;
if (obj.offsetParent) {
do {
curleft += obj.offsetLeft;
curtop += obj.offsetTop;
} while (obj = obj.offsetParent);
return [curleft,curtop];
}
}
this.__defineSetter__('value', function(e) {
var pct = GUI.map(e, min, max, 0, 100);
this.fg.style.width = pct+"%";
});
var onDrag = function(e) { var onDrag = function(e) {
if (!clicked) return; if (!clicked) return;
var pos = findPos(_this.domElement); var pos = findPos(_this.domElement);
var val = GUI.map(e.pageX, pos[0], pos[0] + _this.domElement.offsetWidth, min, max); var val = GUI.map(e.pageX, pos[0], pos[0] + _this.domElement.offsetWidth, min, max);
val = Math.round(val/step)*step; val = Math.round(val/step)*step;
numberController.setValue(val); numberController.setValue(val);
} };
this.domElement.addEventListener('mousedown', function(e) { this.domElement.addEventListener('mousedown', function(e) {
clicked = true; clicked = true;
x = px = e.pageX; x = px = e.pageX;
_this.domElement.setAttribute('class', 'guidat-slider-bg active'); _this.domElement.className += ' active';
_this.fg.setAttribute('class', 'guidat-slider-fg active'); _this.fg.className += ' active';
numberController.domElement.className += ' active'; numberController.domElement.className += ' active';
onDrag(e); onDrag(e);
document.addEventListener('mouseup', mouseup, false); document.addEventListener('mouseup', mouseup, false);
}, false); }, false);
var mouseup = function(e) {
var mouseup = function(e) { _this.domElement.className = _this.domElement.className.replace(' active', '');
_this.domElement.setAttribute('class', 'guidat-slider-bg'); _this.fg.className = _this.fg.className.replace(' active', '');
_this.fg.setAttribute('class', 'guidat-slider-fg'); numberController.domElement.className = numberController.domElement.className.replace(' active', '');
numberController.domElement.className = numberController.domElement.className.replace(' active', ''); clicked = false;
clicked = false; if (numberController.finishChangeFunction != null) {
if (numberController.finishChangeFunction != null) { numberController.finishChangeFunction.call(this, numberController.getValue());
numberController.finishChangeFunction.call(this, numberController.getValue()); }
} document.removeEventListener('mouseup', mouseup, false);
document.removeEventListener('mouseup', mouseup, false); };
};
var x, px;
document.addEventListener('mousemove', onDrag, false);
this.domElement = document.createElement('div');
this.value = initValue; this.domElement.setAttribute('class', 'guidat-slider-bg');
} this.fg = document.createElement('div');
this.fg.setAttribute('class', 'guidat-slider-fg');
this.domElement.appendChild(this.fg);
var findPos = function(obj) {
var curleft = 0, curtop = 0;
if (obj.offsetParent) {
do {
curleft += obj.offsetLeft;
curtop += obj.offsetTop;
} while ((obj = obj.offsetParent));
return [curleft,curtop];
}
};
this.__defineSetter__('value', function(e) {
var pct = GUI.map(e, min, max, 0, 100);
this.fg.style.width = pct+"%";
});
var onDrag = function(e) {
if (!clicked) return;
var pos = findPos(_this.domElement);
var val = GUI.map(e.pageX, pos[0], pos[0] + _this.domElement.offsetWidth, min, max);
val = Math.round(val/step)*step;
numberController.setValue(val);
};
this.domElement.addEventListener('mousedown', function(e) {
clicked = true;
x = px = e.pageX;
_this.domElement.setAttribute('class', 'guidat-slider-bg active');
_this.fg.setAttribute('class', 'guidat-slider-fg active');
onDrag(e);
document.addEventListener('mouseup', mouseup, false);
}, false);
var mouseup = function(e) {
_this.domElement.setAttribute('class', 'guidat-slider-bg');
_this.fg.setAttribute('class', 'guidat-slider-fg');
clicked = false;
if (numberController.finishChangeFunction != null) {
numberController.finishChangeFunction.call(this, numberController.getValue());
}
document.removeEventListener('mouseup', mouseup, false);
};
document.addEventListener('mousemove', onDrag, false);
this.value = initValue;
};

161
gui.css
View File

@ -1,171 +1,166 @@
#guidat { #guidat {
position: fixed; position: fixed;
top: 0; top: 0;
right: 0; right: 0;
width: auto; width: auto;
z-index: 1001; z-index: 1001;
text-align: right; text-align: right;
} }
.guidat { .guidat {
color: #fff; color: #fff;
opacity: 0.97; opacity: 0.97;
text-align: left; text-align: left;
float: right; float: right;
margin-right: 20px; margin-right: 20px;
margin-bottom: 20px; margin-bottom: 20px;
background-color: #fff; background-color: #fff;
} }
.guidat, .guidat,
.guidat input { .guidat input {
font: 9.5px Lucida Grande, sans-serif; font: 9.5px Lucida Grande, sans-serif;
} }
.guidat-controllers { .guidat-controllers {
height: 300px; height: 300px;
overflow-y: auto; overflow-y: auto;
overflow-x: hidden; overflow-x: hidden;
background-color: rgba(0,0,0,0.1); background-color: rgba(0,0,0,0.1);
/*
-moz-transition: height .2s ease-out;
-webkit-transition: height .2s ease-out;
transition: height .2s ease-out;
*/
} }
a.guidat-toggle { a.guidat-toggle {
text-decoration: none; text-decoration: none;
cursor: pointer; cursor: pointer;
color: #fff; color: #fff;
background-color: #222; background-color: #222;
text-align: center; text-align: center;
display: block; display: block;
padding: 5px; padding: 5px;
} }
a.guidat-toggle:hover { a.guidat-toggle:hover {
background-color: #000; background-color: #000;
} }
.guidat-controller { .guidat-controller {
padding: 3px; padding: 3px;
height: 25px; height: 25px;
clear: left; clear: left;
border-bottom: 1px solid #222; border-bottom: 1px solid #222;
background-color: #111; background-color: #111;
} }
.guidat-controller, .guidat-controller,
.guidat-controller input, .guidat-controller input,
.guidat-slider-bg, .guidat-slider-bg,
.guidat-slider-fg { .guidat-slider-fg {
-moz-transition: background-color 0.15s linear; -moz-transition: background-color 0.15s linear;
-webkit-transition: background-color 0.15s linear; -webkit-transition: background-color 0.15s linear;
transition: background-color 0.15s linear; transition: background-color 0.15s linear;
} }
.guidat-controller.boolean:hover, .guidat-controller.boolean:hover,
.guidat-controller.function:hover { .guidat-controller.function:hover {
background-color: #000; background-color: #000;
} }
.guidat-controller input { .guidat-controller input {
float: right; float: right;
outline: none; outline: none;
border: 0; border: 0;
padding: 4px; padding: 4px;
margin-top: 2px; margin-top: 2px;
background-color: #222; background-color: #222;
} }
.guidat-controller select { .guidat-controller select {
margin-top: 4px; margin-top: 4px;
float: right; float: right;
} }
.guidat-controller input:hover. .guidat-controller input:hover.
.guidat-controller.number.active { .guidat-controller.number.active {
background-color: #444; background-color: #444;
} }
.guidat-controller input:focus { .guidat-controller input:focus {
background-color: #555; background-color: #555;
} }
.guidat-controller.number { .guidat-controller.number {
border-left: 5px solid #00aeff ; border-left: 5px solid #00aeff ;
} }
.guidat-controller.string { .guidat-controller.string {
border-left: 5px solid #1ed36f; border-left: 5px solid #1ed36f;
} }
.guidat-controller.string input { .guidat-controller.string input {
border: 0; border: 0;
color: #1ed36f; color: #1ed36f;
margin-right: 2px; margin-right: 2px;
width: 148px; width: 148px;
} }
.guidat-controller.boolean { .guidat-controller.boolean {
border-left: 5px solid #54396e; border-left: 5px solid #54396e;
} }
.guidat-controller.function { .guidat-controller.function {
border-left: 5px solid #e61d5f; border-left: 5px solid #e61d5f;
} }
.guidat-controller.number input[type=text] { .guidat-controller.number input[type=text] {
width: 35px; width: 35px;
margin-left: 5px; margin-left: 5px;
margin-right: 2px; margin-right: 2px;
color: #00aeff; color: #00aeff;
} }
.guidat .guidat-controller.boolean input { .guidat .guidat-controller.boolean input {
margin-top: 6px; margin-top: 6px;
margin-right: 2px; margin-right: 2px;
font-size: 20px; font-size: 20px;
} }
.guidat-controller:last-child { .guidat-controller:last-child {
border-bottom: none; border-bottom: none;
-webkit-box-shadow: 0px 1px 3px rgba(0, 0, 0, 0.5); -webkit-box-shadow: 0px 1px 3px rgba(0, 0, 0, 0.5);
-moz-box-shadow: 0px 1px 3px rgba(0, 0, 0, 0.5); -moz-box-shadow: 0px 1px 3px rgba(0, 0, 0, 0.5);
box-shadow: 0px 1px 3px rgba(0, 0, 0, 0.5); box-shadow: 0px 1px 3px rgba(0, 0, 0, 0.5);
} }
.guidat-propertyname { .guidat-propertyname {
padding: 5px; padding: 5px;
padding-top: 7px; padding-top: 7px;
cursor: default; cursor: default;
display: inline-block; display: inline-block;
} }
.guidat-slider-bg:hover, .guidat-slider-bg:hover,
.guidat-slider-bg.active { .guidat-slider-bg.active {
background-color: #444; background-color: #444;
} }
.guidat-slider-bg:hover .guidat-slider-fg, .guidat-slider-bg:hover .guidat-slider-fg,
.guidat-slider-bg.active .guidat-slider-fg { .guidat-slider-bg.active .guidat-slider-fg {
background-color: #52c8ff; background-color: #52c8ff;
} }
.guidat-slider-bg { .guidat-slider-bg {
background-color: #222; background-color: #222;
cursor: ew-resize; cursor: ew-resize;
width: 40%; width: 40%;
margin-top: 2px; margin-top: 2px;
float: right; float: right;
height: 21px; height: 21px;
} }
.guidat-slider-fg { .guidat-slider-fg {
background-color: #00aeff; background-color: #00aeff;
height: 20px; height: 20px;
} }

1048
gui.js

File diff suppressed because it is too large Load Diff

View File

@ -1,31 +1,24 @@
<!doctype html> <!doctype html>
<head> <head>
<title>gui-dat</title> <title>gui-dat</title>
<link rel="icon" type="image/png" href="demo/assets/favicon.png" /> <link rel="icon" type="image/png" href="demo/assets/favicon.png" />
<link href="demo/demo.css" media="screen" rel="stylesheet" type="text/css" /> <link href="demo/demo.css" media="screen" rel="stylesheet" type="text/css" />
<link href="gui.css" media="screen" rel="stylesheet" type="text/css" /> <link href="gui.css" media="screen" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="gui.js">
</script> <script type="text/javascript" src="gui.js"></script>
<script type="text/javascript" src="controllers/slider.js"> <script type="text/javascript" src="controllers/slider.js"></script>
</script> <script type="text/javascript" src="controllers/controller.js"></script>
<script type="text/javascript" src="controllers/controller.js"> <script type="text/javascript" src="controllers/controller.boolean.js"></script>
</script> <script type="text/javascript" src="controllers/controller.function.js"></script>
<script type="text/javascript" src="controllers/controller.boolean.js"> <script type="text/javascript" src="controllers/controller.number.js"></script>
</script> <script type="text/javascript" src="controllers/controller.string.js"></script>
<script type="text/javascript" src="controllers/controller.function.js"> <script type="text/javascript" src="demo/improvedNoise.js"></script>
</script> <script type="text/javascript" src="demo/prettify.js"></script>
<script type="text/javascript" src="controllers/controller.number.js"> <script type="text/javascript" src="demo/demo.js"></script>
</script>
<script type="text/javascript" src="controllers/controller.string.js">
</script>
<script type="text/javascript" src="demo/improvedNoise.js">
</script>
<script type="text/javascript" src="demo/prettify.js">
</script>
<script type="text/javascript" src="demo/demo.js">
</script>
<script type="text/javascript"> <script type="text/javascript">
//<![CDATA[ //<![CDATA[
window.onload = function() { window.onload = function() {
@ -52,59 +45,59 @@
// Fires a function called "explode" // Fires a function called "explode"
gui.add(fizzyText, "explode").name("Explode!"); // Specify a custom name. gui.add(fizzyText, "explode").name("Explode!"); // Specify a custom name.
// Javascript for documentation // Javascript for documentation
getCollapsables(); getCollapsables();
handleListening(); handleListening();
}; };
function toggle(e) { function toggle(e) {
var collapsable = this.childNodes[3], var collapsable = this.childNodes[3],
wrapper = collapsable.childNodes[1]; wrapper = collapsable.childNodes[1];
if (this.className === 'collapsed') { if (this.className === 'collapsed') {
this.className = 'expanded'; this.className = 'expanded';
collapsable.style.height = wrapper.clientHeight + 'px'; collapsable.style.height = wrapper.clientHeight + 'px';
} else { } else {
this.className = 'collapsed'; this.className = 'collapsed';
collapsable.style.height = '0px'; collapsable.style.height = '0px';
} }
} }
function getCollapsables() { function getCollapsables() {
if (document.getElementsByClassName == undefined) { if (document.getElementsByClassName == undefined) {
document.getElementsByClassName = function(className) document.getElementsByClassName = function(className)
{ {
var hasClassName = new RegExp("(?:^|\\s)" + className + "(?:$|\\s)"); var hasClassName = new RegExp("(?:^|\\s)" + className + "(?:$|\\s)");
var allElements = document.getElementsByTagName("*"); var allElements = document.getElementsByTagName("*");
var results = []; var results = [];
var element; var element;
for (var i = 0; (element = allElements[i]) != null; i++) { for (var i = 0; (element = allElements[i]) != null; i++) {
var elementClass = element.className; var elementClass = element.className;
if (elementClass && elementClass.indexOf(className) != -1 && hasClassName.test(elementClass)) if (elementClass && elementClass.indexOf(className) != -1 && hasClassName.test(elementClass))
results.push(element); results.push(element);
} }
return results; return results;
}; };
} }
collapsed = document.getElementsByClassName('collapsed'); collapsed = document.getElementsByClassName('collapsed');
expanded = document.getElementsByClassName('expanded'); expanded = document.getElementsByClassName('expanded');
} }
function handleListening() { function handleListening() {
for(var i = 0; i < collapsed.length; i++) { for(var i = 0; i < collapsed.length; i++) {
collapsed[i].addEventListener('click', toggle, false); collapsed[i].addEventListener('click', toggle, false);
} }
for(var j = 0; j < expanded.length; j++) { for(var j = 0; j < expanded.length; j++) {
expanded[i].addEventListener('click', toggle, false); expanded[i].addEventListener('click', toggle, false);
} }
} }
//]]> //]]>
</script> </script>
@ -113,10 +106,10 @@
<body> <body>
<div id="container"> <div id="container">
<!-- GUIDAT logo --> <!-- GUIDAT logo -->
<div id="helvetica-demo"></div> <div id="helvetica-demo"></div>
<!-- It gives you this! --> <!-- It gives you this! -->
<div id="notifier"></div> <div id="notifier"></div>
<h1><a href="http://twitter.com/guidat"><img src="demo/assets/profile.png" border="0" alt="GUI-DAT flag" /></a></h1> <h1><a href="http://twitter.com/guidat"><img src="demo/assets/profile.png" border="0" alt="GUI-DAT flag" /></a></h1>
@ -174,26 +167,26 @@ window.onload = function() {
<pre class="prettyprint">gui.add(obj, "propName").onChange(function(n) { <pre class="prettyprint">gui.add(obj, "propName").onChange(function(n) {
alert("You changed me to " + n); alert("You changed me to " + n);
});</pre>--> });</pre>-->
<div class="collapsed"> <div class="collapsed">
<h2 class="section">Saving your parameters</h2> <h2 class="section">Saving your parameters</h2>
<div class="collapsable"> <div class="collapsable">
<div> <div>
<p>The simplest way to save your parameters is via <code>GUI.saveURL()</code>. This method directs your browser to a URL containing the current GUI settings.</p> <p>The simplest way to save your parameters is via <code>GUI.saveURL()</code>. This method directs your browser to a URL containing the current GUI settings.</p>
<pre class="prettyprint last"> <pre class="prettyprint last">
// Make a button for the url function // Make a button for the url function
gui.add(GUI, "saveURL");</pre> gui.add(GUI, "saveURL");</pre>
</div> </div>
</div> </div>
</div> </div>
<div class="collapsed"> <div class="collapsed">
<h2 class="section">Advanced saving</h2> <h2 class="section">Advanced saving</h2>
<div class="collapsable"> <div class="collapsable">
<div> <div>
<p>Let's say you'd like to share your settings with someone. Instead of sending a long link with lots of parameters stored in it, you can make your saved settings the defaults.</p> <p>Let's say you'd like to share your settings with someone. Instead of sending a long link with lots of parameters stored in it, you can make your saved settings the defaults.</p>
<p>First, add the method <code>GUI.showSaveString()</code> to a gui object:</p> <p>First, add the method <code>GUI.showSaveString()</code> to a gui object:</p>
<pre class="prettyprint">var gui = new GUI(); <pre class="prettyprint">var gui = new GUI();
// Add some stuff (and pretend I change their values); // Add some stuff (and pretend I change their values);
gui.add(someObject, "someProperty"); gui.add(someObject, "someProperty");
@ -202,8 +195,8 @@ gui.add(someObject, "someOtherProperty");
// Make a save button. // Make a save button.
gui.add(GUI, "showSaveString");</pre> gui.add(GUI, "showSaveString");</pre>
<p>Clicking the "showSaveString" button bring up an alert with a string. Copy and paste that string into the method <code>GUI.load()</code> before you instantiate any gui objects.</p> <p>Clicking the "showSaveString" button bring up an alert with a string. Copy and paste that string into the method <code>GUI.load()</code> before you instantiate any gui objects.</p>
<pre class="prettyprint"> <pre class="prettyprint">
// Replace COPIED STRING with the value you got from showSaveString() // Replace COPIED STRING with the value you got from showSaveString()
GUI.load("COPIED STRING"); GUI.load("COPIED STRING");
@ -213,69 +206,69 @@ var gui = new GUI();
gui.add(someObject, "someProperty"); gui.add(someObject, "someProperty");
gui.add(someObject, "someOtherProperty");</pre> gui.add(someObject, "someOtherProperty");</pre>
<p class = "last"><strong>Save strings won't work if you change the order in which you've added properties to your gui objects, or the order of the gui objects themselves.</strong>. If you want to add more parameters to your gui and use an old save string, make sure they're added after the properties whose values you've saved.</p> <p class = "last"><strong>Save strings won't work if you change the order in which you've added properties to your gui objects, or the order of the gui objects themselves.</strong>. If you want to add more parameters to your gui and use an old save string, make sure they're added after the properties whose values you've saved.</p>
</div> </div>
</div> </div>
</div> </div>
<div class="collapsed"> <div class="collapsed">
<h2 class="section">Choosing from a list of values</h2> <h2 class="section">Choosing from a list of values</h2>
<div class="collapsable"> <div class="collapsable">
<div> <div>
<pre class="prettyprint first last">gui.add(obj, "propertyName").options(1, 2, 3, 5, 8); <pre class="prettyprint first last">gui.add(obj, "propertyName").options(1, 2, 3, 5, 8);
// Alternatively, you can specify custom labels using object syntax // Alternatively, you can specify custom labels using object syntax
gui.add(obj, "propertyName").options({'Small': 1, 'Medium': 2, 'Large': 3}); gui.add(obj, "propertyName").options({'Small': 1, 'Medium': 2, 'Large': 3});
</pre> </pre>
</div> </div>
</div> </div>
</div> </div>
<div class="collapsed"> <div class="collapsed">
<h2 class="section">Listen for variable changes inside the GUI</h2> <h2 class="section">Listen for variable changes inside the GUI</h2>
<div class="collapsable"> <div class="collapsable">
<div> <div>
<p>To fire a function whenever a user changes a variable via the GUI, use the following syntax:</p> <p>To fire a function whenever a user changes a variable via the GUI, use the following syntax:</p>
<pre class="prettyprint">gui.add(obj, "propertyName").onChange(function(newValue) { <pre class="prettyprint">gui.add(obj, "propertyName").onChange(function(newValue) {
alert("You changed me to " + newValue); alert("You changed me to " + newValue);
});</pre> <p>This can be slightly annoying for types like number or string. You may not want to fire a function while the user is sliding, or while they're typing. To fire a function when the user has <em>finished</em> making changes, use the following:</p> });</pre> <p>This can be slightly annoying for types like number or string. You may not want to fire a function while the user is sliding, or while they're typing. To fire a function when the user has <em>finished</em> making changes, use the following:</p>
<pre class="prettyprint">gui.add(obj, "propertyName").onFinishChange(function(newValue) { <pre class="prettyprint">gui.add(obj, "propertyName").onFinishChange(function(newValue) {
alert("You just finished changing me to " + newValue); alert("You just finished changing me to " + newValue);
});</pre> });</pre>
<p>Finally, if you'd like to do a little something extra when a function is called, use the following:</p> <p>Finally, if you'd like to do a little something extra when a function is called, use the following:</p>
<pre class="prettyprint last">gui.add(obj, "functionName").onFire(function() { <pre class="prettyprint last">gui.add(obj, "functionName").onFire(function() {
alert("You called a function with gui-dat"); alert("You called a function with gui-dat");
});</pre> });</pre>
</div> </div>
</div> </div>
</div> </div>
<div class="collapsed"> <div class="collapsed">
<h2 class="section">Listen for variable changes outside of the GUI</h2> <h2 class="section">Listen for variable changes outside of the GUI</h2>
<div class="collapsable"> <div class="collapsable">
<div> <div>
<p>Let's say you have a variable that changes by itself from time to time. If you'd like the GUI to reflect those changes, use the <code>listen()</code> method.</p> <p>Let's say you have a variable that changes by itself from time to time. If you'd like the GUI to reflect those changes, use the <code>listen()</code> method.</p>
<pre class="prettyprint last">gui.add(obj, "changingProperty").listen();</pre> <pre class="prettyprint last">gui.add(obj, "changingProperty").listen();</pre>
</div> </div>
</div> </div>
</div> </div>
<div class="collapsed"> <div class="collapsed">
<h2 class="section">Advanced listening</h2> <h2 class="section">Advanced listening</h2>
<div class="collapsable"> <div class="collapsable">
<div> <div>
<p>By default, <strong>gui-dat</strong> will create an internal interval that checks for changes in the values you've marked with <code>listen()</code>. If you'd like to check for these changes in an interval of your own definition, use the following:</p> <p>By default, <strong>gui-dat</strong> will create an internal interval that checks for changes in the values you've marked with <code>listen()</code>. If you'd like to check for these changes in an interval of your own definition, use the following:</p>
<pre class="prettyprint"> <pre class="prettyprint">
gui.autoListen = false; // disables internal interval gui.autoListen = false; // disables internal interval
gui.add(obj, "changingProperty").listen(); gui.add(obj, "changingProperty").listen();
// Make your own loop // Make your own loop
setInterval(function() { setInterval(function() {
gui.listen(); // updates values you've marked with listen() gui.listen(); // updates values you've marked with listen()
}, 1000 / 60);</pre> }, 1000 / 60);</pre>
<p>Alternatively, you can forego calling <code>listen()</code> on individual controllers, and instead choose to monitor changes in <em>all</em> values controlled by your gui.</p> <p>Alternatively, you can forego calling <code>listen()</code> on individual controllers, and instead choose to monitor changes in <em>all</em> values controlled by your gui.</p>
<pre class="prettyprint last"> <pre class="prettyprint last">
gui.autoListen = false; // disables internal interval gui.autoListen = false; // disables internal interval
gui.add(obj, "add"); gui.add(obj, "add");
gui.add(obj, "lotsa"); gui.add(obj, "lotsa");
@ -283,26 +276,26 @@ gui.add(obj, "properties");
// Make your own loop // Make your own loop
setInterval(function() { setInterval(function() {
gui.listenAll(); // updates ALL values managed by this gui gui.listenAll(); // updates ALL values managed by this gui
}, 1000 / 60);</pre> }, 1000 / 60);</pre>
</div> </div>
</div> </div>
</div> </div>
<div class="collapsed"> <div class="collapsed">
<h2 class="section">Multiple panels and custom placement</h2> <h2 class="section">Multiple panels and custom placement</h2>
<div class="collapsable"> <div class="collapsable">
<div> <div>
<p>You can instantiate multiple <code>GUI</code> objects and name them however you'd like.</p> <p>You can instantiate multiple <code>GUI</code> objects and name them however you'd like.</p>
<pre class="prettyprint">var gui1 = new GUI(); <pre class="prettyprint">var gui1 = new GUI();
var gui2 = new GUI(); var gui2 = new GUI();
// The name function overwrites the "Show Controls" text. // The name function overwrites the "Show Controls" text.
gui1.name("Utilities"); gui1.name("Utilities");
gui2.name("Camera Placement");</pre> gui2.name("Camera Placement");</pre>
<p>By default, <strong>gui-dat</strong> panels will be automatically added to the HTML document and fixed to the top of the screen. You can disable this behavior / styling and append the gui DOM element to a container of your choosing.</p> <p>By default, <strong>gui-dat</strong> panels will be automatically added to the HTML document and fixed to the top of the screen. You can disable this behavior / styling and append the gui DOM element to a container of your choosing.</p>
<pre class="prettyprint last"> <pre class="prettyprint last">
// Notice this belongs to the GUI class (uppercase) // Notice this belongs to the GUI class (uppercase)
// and not an instance thereof. // and not an instance thereof.
GUI.autoPlace = false; GUI.autoPlace = false;
@ -315,26 +308,26 @@ gui.domElement.style.top = "20px";
gui.domElement.style.left = "20px"; gui.domElement.style.left = "20px";
document.getElementById("my-gui-container").appendChild( gui.domElement );</pre> document.getElementById("my-gui-container").appendChild( gui.domElement );</pre>
</div> </div>
</div> </div>
</div> </div>
<div class="collapsed"> <div class="collapsed">
<h2 class="section">Pro tips.</h2> <h2 class="section">Pro tips.</h2>
<div class="collapsable"> <div class="collapsable">
<div> <div>
<ol id="secrets"> <ol id="secrets">
<li><strong>gui-dat</strong> panels are resizeable. Drag the show/hide button.</li> <li><strong>gui-dat</strong> panels are resizeable. Drag the show/hide button.</li>
<li>Pro tip #2 forthcoming.</li> <li>Pro tip #2 forthcoming.</li>
</ol> </ol>
</div> </div>
</div> </div>
</div> </div>
<div class = "trans">&nbsp;</div> <div class = "trans">&nbsp;</div>
<footer class = "trans">Initiated by <a href="http://georgemichaelbrower.com/">George Michael Brower</a> and <a href="http://jonobr1.com/">Jono Brandel</a> of the Data Arts Team, Google Creative Lab. <footer class = "trans">Initiated by <a href="http://georgemichaelbrower.com/">George Michael Brower</a> and <a href="http://jonobr1.com/">Jono Brandel</a> of the Data Arts Team, Google Creative Lab.
</footer> </footer>
</body> </body>
</html> </html>