merged szimeks formatting with current branch

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

View File

@ -1,39 +1,39 @@
GUI.BooleanController = function() {
this.type = "boolean";
GUI.Controller.apply(this, arguments);
this.type = "boolean";
GUI.Controller.apply(this, arguments);
var _this = this;
var _this = this;
var input = document.createElement('input');
input.setAttribute('type', 'checkbox');
this.domElement.addEventListener('click', function(e) {
input.checked = !input.checked;
e.preventDefault();
_this.setValue(input.checked);
input.checked = !input.checked;
e.preventDefault();
_this.setValue(input.checked);
}, false);
input.addEventListener('mouseup', function(e) {
input.checked = !input.checked; // counteracts default.
input.checked = !input.checked; // counteracts default.
}, false);
this.domElement.style.cursor = "pointer";
this.propertyNameElement.style.cursor = "pointer";
this.domElement.appendChild(input);
this.updateDisplay = function() {
input.checked = _this.getValue();
input.checked = _this.getValue();
};
this.setValue = function(val) {
if (typeof val != "boolean") {
try {
val = eval(val);
} catch (e) {}
}
return GUI.Controller.prototype.setValue.call(this, val);
}
if (typeof val != "boolean") {
try {
val = eval(val);
} catch (e) {}
}
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() {
this.type = "function";
var _this = this;
GUI.Controller.apply(this, arguments);
this.domElement.addEventListener('click', function() {
_this.fire();
}, false);
this.domElement.style.cursor = "pointer";
this.propertyNameElement.style.cursor = "pointer";
var fireFunction = null;
this.onFire = function(fnc) {
fireFunction = fnc;
return this;
}
this.fire = function() {
_this.object[_this.propertyName].call(_this.object);
if (fireFunction != null) {
fireFunction.call(this);
}
};
this.type = "function";
var _this = this;
GUI.Controller.apply(this, arguments);
this.domElement.addEventListener('click', function() {
_this.fire();
}, false);
this.domElement.style.cursor = "pointer";
this.propertyNameElement.style.cursor = "pointer";
var fireFunction = null;
this.onFire = function(fnc) {
fireFunction = fnc;
return this;
}
this.fire = function() {
if (fireFunction != null) {
fireFunction.call(this);
}
_this.object[_this.propertyName].call(_this.object);
};
};
GUI.extendController(GUI.FunctionController);

View File

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

View File

@ -1,153 +1,152 @@
GUI.NumberController = function() {
this.type = "number";
this.type = "number";
GUI.Controller.apply(this, arguments);
var _this = this;
// 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
var draggedNumberField = false;
var clickedNumberField = false;
var y = py = 0;
var y = 0, py = 0;
var min = arguments[3];
var max = arguments[4];
var step = arguments[5];
if (!step) {
if (min != undefined && max != undefined) {
step = (max-min)*0.01;
} else {
step = 1;
}
if (min != undefined && max != undefined) {
step = (max-min)*0.01;
} else {
step = 1;
}
}
var numberField = document.createElement('input');
numberField.setAttribute('id', this.propertyName);
numberField.setAttribute('type', 'text');
numberField.setAttribute('value', this.getValue());
if (step) numberField.setAttribute('step', step);
this.domElement.appendChild(numberField);
var slider;
if (min != undefined && max != undefined) {
slider = new GUI.Slider(this, min, max, step, this.getValue());
this.domElement.appendChild(slider.domElement);
slider = new GUI.Slider(this, min, max, step, this.getValue());
this.domElement.appendChild(slider.domElement);
}
numberField.addEventListener('blur', function(e) {
var val = parseFloat(this.value);
console.log(val);
if (!isNaN(val)) {
_this.setValue(val);
_this.setValue(val);
}
}, false);
numberField.addEventListener('mousewheel', function(e) {
e.preventDefault();
_this.setValue(_this.getValue() + Math.abs(e.wheelDeltaY)/e.wheelDeltaY*step);
return false;
e.preventDefault();
_this.setValue(_this.getValue() + Math.abs(e.wheelDeltaY)/e.wheelDeltaY*step);
return false;
}, false);
numberField.addEventListener('mousedown', function(e) {
py = y = e.pageY;
clickedNumberField = true;
clickedNumberField = true;
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);
// 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) {
document.removeEventListener('mousemove', dragNumberField, false);
GUI.makeSelectable(_this.parent.domElement);
GUI.makeSelectable(_this.parent.domElement);
GUI.makeSelectable(numberField);
if (clickedNumberField && !draggedNumberField) {
numberField.focus();
numberField.select();
if (clickedNumberField && !draggedNumberField) {
numberField.focus();
numberField.select();
}
if(slider) slider.domElement.className = slider.domElement.className.replace(' active', '');
if(slider) slider.domElement.className = slider.domElement.className.replace(' active', '');
draggedNumberField = false;
clickedNumberField = false;
if (_this.finishChangeFunction != null) {
_this.finishChangeFunction.call(this, _this.getValue());
}
document.removeEventListener('mouseup', mouseup, false);
}
if (_this.finishChangeFunction != null) {
_this.finishChangeFunction.call(this, _this.getValue());
}
document.removeEventListener('mouseup', mouseup, false);
};
var dragNumberField = function(e) {
draggedNumberField = true;
e.preventDefault();
// 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.
draggedNumberField = true;
e.preventDefault();
// 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.noSlider();
_this.domElement.removeChild(numberField);
return GUI.Controller.prototype.options.apply(this, arguments);
_this.noSlider();
_this.domElement.removeChild(numberField);
return GUI.Controller.prototype.options.apply(this, arguments);
};
this.noSlider = function() {
if (slider) {
_this.domElement.removeChild(slider.domElement);
}
return this;
if (slider) {
_this.domElement.removeChild(slider.domElement);
}
return this;
};
this.setValue = function(val) {
val = parseFloat(val);
if (min != undefined && val <= min) {
val = min;
} else if (max != undefined && val >= max) {
val = max;
}
return GUI.Controller.prototype.setValue.call(this, val);
}
val = parseFloat(val);
if (min != undefined && val <= min) {
val = min;
} else if (max != undefined && val >= max) {
val = max;
}
return GUI.Controller.prototype.setValue.call(this, val);
};
this.updateDisplay = function() {
numberField.value = GUI.roundToDecimal(_this.getValue(), 4);
if (slider) slider.value = _this.getValue();
}
};
};
GUI.extendController(GUI.NumberController);

View File

@ -1,47 +1,47 @@
GUI.StringController = function() {
this.type = "string";
var _this = this;
this.type = "string";
var _this = this;
GUI.Controller.apply(this, arguments);
var input = document.createElement('input');
var initialValue = this.getValue();
input.setAttribute('value', initialValue);
input.setAttribute('spellcheck', 'false');
this.domElement.addEventListener('mouseup', function() {
input.focus();
input.select();
input.focus();
input.select();
}, false);
// TODO: getting messed up on ctrl a
input.addEventListener('keyup', function(e) {
if (e.keyCode == 13 && _this.finishChangeFunction != null) {
_this.finishChangeFunction.call(this, _this.getValue());
}
if (e.keyCode == 13 && _this.finishChangeFunction != null) {
_this.finishChangeFunction.call(this, _this.getValue());
}
_this.setValue(input.value);
}, false);
input.addEventListener('blur', function() {
if (_this.finishChangeFunction != null) {
_this.finishChangeFunction.call(this, _this.getValue());
}
if (_this.finishChangeFunction != null) {
_this.finishChangeFunction.call(this, _this.getValue());
}
}, false);
this.updateDisplay = function() {
input.value = _this.getValue();
}
this.options = function() {
_this.domElement.removeChild(input);
return GUI.Controller.prototype.options.apply(this, arguments);
input.value = _this.getValue();
};
this.options = function() {
_this.domElement.removeChild(input);
return GUI.Controller.prototype.options.apply(this, arguments);
};
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) {
var min = min;
var max = max;
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 clicked = false;
var _this = this;
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');
numberController.domElement.className += ' 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');
numberController.domElement.className = numberController.domElement.className.replace(' active', '');
clicked = false;
if (numberController.finishChangeFunction != null) {
numberController.finishChangeFunction.call(this, numberController.getValue());
}
document.removeEventListener('mouseup', mouseup, false);
};
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.className += ' active';
_this.fg.className += ' active';
numberController.domElement.className += ' active';
onDrag(e);
document.addEventListener('mouseup', mouseup, false);
}, false);
var mouseup = function(e) {
_this.domElement.className = _this.domElement.className.replace(' active', '');
_this.fg.className = _this.fg.className.replace(' active', '');
numberController.domElement.className = numberController.domElement.className.replace(' active', '');
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;
}
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 = 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 {
position: fixed;
top: 0;
right: 0;
width: auto;
z-index: 1001;
text-align: right;
position: fixed;
top: 0;
right: 0;
width: auto;
z-index: 1001;
text-align: right;
}
.guidat {
color: #fff;
opacity: 0.97;
text-align: left;
float: right;
margin-right: 20px;
margin-bottom: 20px;
background-color: #fff;
color: #fff;
opacity: 0.97;
text-align: left;
float: right;
margin-right: 20px;
margin-bottom: 20px;
background-color: #fff;
}
.guidat,
.guidat input {
font: 9.5px Lucida Grande, sans-serif;
font: 9.5px Lucida Grande, sans-serif;
}
.guidat-controllers {
height: 300px;
overflow-y: auto;
overflow-x: hidden;
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;
*/
height: 300px;
overflow-y: auto;
overflow-x: hidden;
background-color: rgba(0,0,0,0.1);
}
a.guidat-toggle {
text-decoration: none;
cursor: pointer;
color: #fff;
background-color: #222;
text-align: center;
display: block;
padding: 5px;
text-decoration: none;
cursor: pointer;
color: #fff;
background-color: #222;
text-align: center;
display: block;
padding: 5px;
}
a.guidat-toggle:hover {
background-color: #000;
background-color: #000;
}
.guidat-controller {
padding: 3px;
height: 25px;
clear: left;
border-bottom: 1px solid #222;
background-color: #111;
padding: 3px;
height: 25px;
clear: left;
border-bottom: 1px solid #222;
background-color: #111;
}
.guidat-controller,
.guidat-controller input,
.guidat-slider-bg,
.guidat-slider-fg {
-moz-transition: background-color 0.15s linear;
-webkit-transition: background-color 0.15s linear;
transition: background-color 0.15s linear;
-moz-transition: background-color 0.15s linear;
-webkit-transition: background-color 0.15s linear;
transition: background-color 0.15s linear;
}
.guidat-controller.boolean:hover,
.guidat-controller.function:hover {
background-color: #000;
background-color: #000;
}
.guidat-controller input {
float: right;
outline: none;
border: 0;
padding: 4px;
margin-top: 2px;
background-color: #222;
float: right;
outline: none;
border: 0;
padding: 4px;
margin-top: 2px;
background-color: #222;
}
.guidat-controller select {
margin-top: 4px;
float: right;
margin-top: 4px;
float: right;
}
.guidat-controller input:hover.
.guidat-controller.number.active {
background-color: #444;
background-color: #444;
}
.guidat-controller input:focus {
background-color: #555;
background-color: #555;
}
.guidat-controller.number {
border-left: 5px solid #00aeff ;
border-left: 5px solid #00aeff ;
}
.guidat-controller.string {
border-left: 5px solid #1ed36f;
border-left: 5px solid #1ed36f;
}
.guidat-controller.string input {
border: 0;
color: #1ed36f;
margin-right: 2px;
width: 148px;
border: 0;
color: #1ed36f;
margin-right: 2px;
width: 148px;
}
.guidat-controller.boolean {
border-left: 5px solid #54396e;
border-left: 5px solid #54396e;
}
.guidat-controller.function {
border-left: 5px solid #e61d5f;
border-left: 5px solid #e61d5f;
}
.guidat-controller.number input[type=text] {
width: 35px;
margin-left: 5px;
margin-right: 2px;
color: #00aeff;
width: 35px;
margin-left: 5px;
margin-right: 2px;
color: #00aeff;
}
.guidat .guidat-controller.boolean input {
margin-top: 6px;
margin-right: 2px;
font-size: 20px;
margin-top: 6px;
margin-right: 2px;
font-size: 20px;
}
.guidat-controller:last-child {
border-bottom: none;
-webkit-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);
border-bottom: none;
-webkit-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);
}
.guidat-propertyname {
padding: 5px;
padding-top: 7px;
cursor: default;
display: inline-block;
padding: 5px;
padding-top: 7px;
cursor: default;
display: inline-block;
}
.guidat-slider-bg:hover,
.guidat-slider-bg.active {
background-color: #444;
background-color: #444;
}
.guidat-slider-bg:hover .guidat-slider-fg,
.guidat-slider-bg.active .guidat-slider-fg {
background-color: #52c8ff;
background-color: #52c8ff;
}
.guidat-slider-bg {
background-color: #222;
cursor: ew-resize;
width: 40%;
margin-top: 2px;
float: right;
height: 21px;
background-color: #222;
cursor: ew-resize;
width: 40%;
margin-top: 2px;
float: right;
height: 21px;
}
.guidat-slider-fg {
background-color: #00aeff;
height: 20px;
background-color: #00aeff;
height: 20px;
}

1048
gui.js

File diff suppressed because it is too large Load Diff

View File

@ -1,31 +1,24 @@
<!doctype html>
<head>
<title>gui-dat</title>
<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="gui.css" media="screen" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="gui.js">
</script>
<script type="text/javascript" src="controllers/slider.js">
</script>
<script type="text/javascript" src="controllers/controller.js">
</script>
<script type="text/javascript" src="controllers/controller.boolean.js">
</script>
<script type="text/javascript" src="controllers/controller.function.js">
</script>
<script type="text/javascript" src="controllers/controller.number.js">
</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" src="gui.js"></script>
<script type="text/javascript" src="controllers/slider.js"></script>
<script type="text/javascript" src="controllers/controller.js"></script>
<script type="text/javascript" src="controllers/controller.boolean.js"></script>
<script type="text/javascript" src="controllers/controller.function.js"></script>
<script type="text/javascript" src="controllers/controller.number.js"></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">
//<![CDATA[
//<![CDATA[
window.onload = function() {
@ -52,59 +45,59 @@
// Fires a function called "explode"
gui.add(fizzyText, "explode").name("Explode!"); // Specify a custom name.
// Javascript for documentation
getCollapsables();
handleListening();
// Javascript for documentation
getCollapsables();
handleListening();
};
function toggle(e) {
var collapsable = this.childNodes[3],
wrapper = collapsable.childNodes[1];
if (this.className === 'collapsed') {
this.className = 'expanded';
collapsable.style.height = wrapper.clientHeight + 'px';
} else {
this.className = 'collapsed';
collapsable.style.height = '0px';
}
}
function getCollapsables() {
if (document.getElementsByClassName == undefined) {
document.getElementsByClassName = function(className)
{
var hasClassName = new RegExp("(?:^|\\s)" + className + "(?:$|\\s)");
var allElements = document.getElementsByTagName("*");
var results = [];
function toggle(e) {
var collapsable = this.childNodes[3],
wrapper = collapsable.childNodes[1];
if (this.className === 'collapsed') {
this.className = 'expanded';
collapsable.style.height = wrapper.clientHeight + 'px';
} else {
this.className = 'collapsed';
collapsable.style.height = '0px';
}
}
function getCollapsables() {
if (document.getElementsByClassName == undefined) {
document.getElementsByClassName = function(className)
{
var hasClassName = new RegExp("(?:^|\\s)" + className + "(?:$|\\s)");
var allElements = document.getElementsByTagName("*");
var results = [];
var element;
for (var i = 0; (element = allElements[i]) != null; i++) {
var elementClass = element.className;
if (elementClass && elementClass.indexOf(className) != -1 && hasClassName.test(elementClass))
results.push(element);
}
var element;
for (var i = 0; (element = allElements[i]) != null; i++) {
var elementClass = element.className;
if (elementClass && elementClass.indexOf(className) != -1 && hasClassName.test(elementClass))
results.push(element);
}
return results;
};
}
collapsed = document.getElementsByClassName('collapsed');
expanded = document.getElementsByClassName('expanded');
}
function handleListening() {
for(var i = 0; i < collapsed.length; i++) {
collapsed[i].addEventListener('click', toggle, false);
}
for(var j = 0; j < expanded.length; j++) {
expanded[i].addEventListener('click', toggle, false);
}
}
return results;
};
}
collapsed = document.getElementsByClassName('collapsed');
expanded = document.getElementsByClassName('expanded');
}
function handleListening() {
for(var i = 0; i < collapsed.length; i++) {
collapsed[i].addEventListener('click', toggle, false);
}
for(var j = 0; j < expanded.length; j++) {
expanded[i].addEventListener('click', toggle, false);
}
}
//]]>
</script>
@ -113,10 +106,10 @@
<body>
<div id="container">
<!-- GUIDAT logo -->
<!-- GUIDAT logo -->
<div id="helvetica-demo"></div>
<!-- It gives you this! -->
<!-- It gives you this! -->
<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>
@ -174,26 +167,26 @@ window.onload = function() {
<pre class="prettyprint">gui.add(obj, "propName").onChange(function(n) {
alert("You changed me to " + n);
});</pre>-->
<div class="collapsed">
<h2 class="section">Saving your parameters</h2>
<div class="collapsable">
<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>
<pre class="prettyprint last">
<div class="collapsed">
<h2 class="section">Saving your parameters</h2>
<div class="collapsable">
<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>
<pre class="prettyprint last">
// Make a button for the url function
gui.add(GUI, "saveURL");</pre>
</div>
</div>
</div>
<div class="collapsed">
<h2 class="section">Advanced saving</h2>
<div class="collapsable">
<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>
</div>
</div>
</div>
<div class="collapsed">
<h2 class="section">Advanced saving</h2>
<div class="collapsable">
<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>First, add the method <code>GUI.showSaveString()</code> to a gui object:</p>
<pre class="prettyprint">var gui = new GUI();
<p>First, add the method <code>GUI.showSaveString()</code> to a gui object:</p>
<pre class="prettyprint">var gui = new GUI();
// Add some stuff (and pretend I change their values);
gui.add(someObject, "someProperty");
@ -202,8 +195,8 @@ gui.add(someObject, "someOtherProperty");
// Make a save button.
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>
<pre class="prettyprint">
<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">
// Replace COPIED STRING with the value you got from showSaveString()
GUI.load("COPIED STRING");
@ -213,69 +206,69 @@ var gui = new GUI();
gui.add(someObject, "someProperty");
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>
</div>
</div>
<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 class="collapsed">
<h2 class="section">Choosing from a list of values</h2>
<div class="collapsable">
<div>
<div class="collapsed">
<h2 class="section">Choosing from a list of values</h2>
<div class="collapsable">
<div>
<pre class="prettyprint first last">gui.add(obj, "propertyName").options(1, 2, 3, 5, 8);
// Alternatively, you can specify custom labels using object syntax
gui.add(obj, "propertyName").options({'Small': 1, 'Medium': 2, 'Large': 3});
</pre>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="collapsed">
<h2 class="section">Listen for variable changes inside the GUI</h2>
<div class="collapsable">
<div>
<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) {
<div class="collapsed">
<h2 class="section">Listen for variable changes inside the GUI</h2>
<div class="collapsable">
<div>
<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) {
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 class="prettyprint">gui.add(obj, "propertyName").onFinishChange(function(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 class="prettyprint">gui.add(obj, "propertyName").onFinishChange(function(newValue) {
alert("You just finished changing me to " + newValue);
});</pre>
<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() {
<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() {
alert("You called a function with gui-dat");
});</pre>
</div>
</div>
</div>
<div class="collapsed">
<h2 class="section">Listen for variable changes outside of the GUI</h2>
<div class="collapsable">
<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>
<pre class="prettyprint last">gui.add(obj, "changingProperty").listen();</pre>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="collapsed">
<h2 class="section">Listen for variable changes outside of the GUI</h2>
<div class="collapsable">
<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>
<pre class="prettyprint last">gui.add(obj, "changingProperty").listen();</pre>
</div>
</div>
</div>
<div class="collapsed">
<h2 class="section">Advanced listening</h2>
<div class="collapsable">
<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>
<pre class="prettyprint">
<div class="collapsed">
<h2 class="section">Advanced listening</h2>
<div class="collapsable">
<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>
<pre class="prettyprint">
gui.autoListen = false; // disables internal interval
gui.add(obj, "changingProperty").listen();
// Make your own loop
setInterval(function() {
gui.listen(); // updates values you've marked with listen()
gui.listen(); // updates values you've marked with listen()
}, 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>
<pre class="prettyprint last">
<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">
gui.autoListen = false; // disables internal interval
gui.add(obj, "add");
gui.add(obj, "lotsa");
@ -283,26 +276,26 @@ gui.add(obj, "properties");
// Make your own loop
setInterval(function() {
gui.listenAll(); // updates ALL values managed by this gui
gui.listenAll(); // updates ALL values managed by this gui
}, 1000 / 60);</pre>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="collapsed">
<h2 class="section">Multiple panels and custom placement</h2>
<div class="collapsable">
<div>
<p>You can instantiate multiple <code>GUI</code> objects and name them however you'd like.</p>
<pre class="prettyprint">var gui1 = new GUI();
<div class="collapsed">
<h2 class="section">Multiple panels and custom placement</h2>
<div class="collapsable">
<div>
<p>You can instantiate multiple <code>GUI</code> objects and name them however you'd like.</p>
<pre class="prettyprint">var gui1 = new GUI();
var gui2 = new GUI();
// The name function overwrites the "Show Controls" text.
gui1.name("Utilities");
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>
<pre class="prettyprint last">
<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">
// Notice this belongs to the GUI class (uppercase)
// and not an instance thereof.
GUI.autoPlace = false;
@ -315,26 +308,26 @@ gui.domElement.style.top = "20px";
gui.domElement.style.left = "20px";
document.getElementById("my-gui-container").appendChild( gui.domElement );</pre>
</div>
</div>
</div>
</div>
</div>
<div class="collapsed">
<h2 class="section">Pro tips.</h2>
<div class="collapsable">
<div>
<ol id="secrets">
<li><strong>gui-dat</strong> panels are resizeable. Drag the show/hide button.</li>
<div class="collapsed">
<h2 class="section">Pro tips.</h2>
<div class="collapsable">
<div>
<ol id="secrets">
<li><strong>gui-dat</strong> panels are resizeable. Drag the show/hide button.</li>
<li>Pro tip #2 forthcoming.</li>
</ol>
</div>
</div>
</div>
<div class = "trans">&nbsp;</div>
<li>Pro tip #2 forthcoming.</li>
</ol>
</div>
</div>
</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>
</footer>
</body>
</html>