mirror of
https://github.com/dataarts/dat.gui.git
synced 2024-12-12 04:08:27 +00:00
merged szimeks formatting with current branch
This commit is contained in:
commit
5d43707a21
@ -1,20 +1,20 @@
|
|||||||
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";
|
||||||
@ -22,18 +22,18 @@ GUI.BooleanController = function() {
|
|||||||
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);
|
@ -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.object[_this.propertyName].call(_this.object);
|
|
||||||
if (fireFunction != null) {
|
|
||||||
fireFunction.call(this);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
this.fire = function() {
|
||||||
|
if (fireFunction != null) {
|
||||||
|
fireFunction.call(this);
|
||||||
|
}
|
||||||
|
_this.object[_this.propertyName].call(_this.object);
|
||||||
|
};
|
||||||
};
|
};
|
||||||
GUI.extendController(GUI.FunctionController);
|
GUI.extendController(GUI.FunctionController);
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
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);
|
||||||
@ -22,75 +22,76 @@ 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;
|
||||||
}
|
};
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
GUI.NumberController = function() {
|
GUI.NumberController = function() {
|
||||||
|
|
||||||
this.type = "number";
|
this.type = "number";
|
||||||
|
|
||||||
GUI.Controller.apply(this, arguments);
|
GUI.Controller.apply(this, arguments);
|
||||||
|
|
||||||
@ -12,18 +12,18 @@ GUI.NumberController = function() {
|
|||||||
|
|
||||||
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');
|
||||||
@ -38,116 +38,115 @@ GUI.NumberController = function() {
|
|||||||
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);
|
}, false);
|
||||||
|
|
||||||
// Handle up arrow and down arrow
|
// Handle up arrow and down arrow
|
||||||
numberField.addEventListener('keydown', function(e) {
|
numberField.addEventListener('keydown', function(e) {
|
||||||
switch(e.keyCode) {
|
var newVal;
|
||||||
case 38: // up
|
switch(e.keyCode) {
|
||||||
var newVal = _this.getValue() + step;
|
case 38: // up
|
||||||
_this.setValue(newVal);
|
newVal = _this.getValue() + step;
|
||||||
break;
|
_this.setValue(newVal);
|
||||||
case 40: // down
|
break;
|
||||||
var newVal = _this.getValue() - step;
|
case 40: // down
|
||||||
_this.setValue(newVal);
|
newVal = _this.getValue() - step;
|
||||||
break;
|
_this.setValue(newVal);
|
||||||
}
|
break;
|
||||||
}, false);
|
}
|
||||||
|
}, 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.
|
|
||||||
|
|
||||||
GUI.makeUnselectable(_this.parent.domElement);
|
// We don't want to be highlighting this field as we scroll.
|
||||||
GUI.makeUnselectable(numberField);
|
// Or any other fields in this gui for that matter ...
|
||||||
|
// TODO: Make makeUselectable go through each element and child element.
|
||||||
|
|
||||||
if(slider) slider.domElement.className += ' active';
|
GUI.makeUnselectable(_this.parent.domElement);
|
||||||
|
GUI.makeUnselectable(numberField);
|
||||||
|
|
||||||
py = y;
|
if(slider) slider.domElement.className += ' active';
|
||||||
y = e.pageY;
|
|
||||||
var dy = py - y;
|
py = y;
|
||||||
var newVal = _this.getValue() + dy*step;
|
y = e.pageY;
|
||||||
_this.setValue(newVal);
|
var dy = py - y;
|
||||||
return false;
|
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);
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
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');
|
||||||
@ -13,31 +13,31 @@ GUI.StringController = function() {
|
|||||||
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.options = function() {
|
||||||
_this.domElement.removeChild(input);
|
_this.domElement.removeChild(input);
|
||||||
return GUI.Controller.prototype.options.apply(this, arguments);
|
return GUI.Controller.prototype.options.apply(this, arguments);
|
||||||
};
|
};
|
||||||
|
|
||||||
this.domElement.appendChild(input);
|
this.domElement.appendChild(input);
|
||||||
|
@ -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 onDrag = function(e) {
|
||||||
var _this = this;
|
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);
|
||||||
|
};
|
||||||
|
|
||||||
var x, px;
|
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);
|
||||||
|
|
||||||
this.domElement = document.createElement('div');
|
var mouseup = function(e) {
|
||||||
this.domElement.setAttribute('class', 'guidat-slider-bg');
|
_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);
|
||||||
|
};
|
||||||
|
|
||||||
this.fg = document.createElement('div');
|
var x, px;
|
||||||
this.fg.setAttribute('class', 'guidat-slider-fg');
|
|
||||||
|
|
||||||
this.domElement.appendChild(this.fg);
|
this.domElement = document.createElement('div');
|
||||||
|
this.domElement.setAttribute('class', 'guidat-slider-bg');
|
||||||
|
|
||||||
var findPos = function(obj) {
|
this.fg = document.createElement('div');
|
||||||
var curleft = curtop = 0;
|
this.fg.setAttribute('class', 'guidat-slider-fg');
|
||||||
if (obj.offsetParent) {
|
|
||||||
do {
|
|
||||||
curleft += obj.offsetLeft;
|
|
||||||
curtop += obj.offsetTop;
|
|
||||||
} while (obj = obj.offsetParent);
|
|
||||||
return [curleft,curtop];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this.__defineSetter__('value', function(e) {
|
this.domElement.appendChild(this.fg);
|
||||||
var pct = GUI.map(e, min, max, 0, 100);
|
|
||||||
this.fg.style.width = pct+"%";
|
|
||||||
});
|
|
||||||
|
|
||||||
var onDrag = function(e) {
|
var findPos = function(obj) {
|
||||||
if (!clicked) return;
|
var curleft = 0, curtop = 0;
|
||||||
var pos = findPos(_this.domElement);
|
if (obj.offsetParent) {
|
||||||
var val = GUI.map(e.pageX, pos[0], pos[0] + _this.domElement.offsetWidth, min, max);
|
do {
|
||||||
val = Math.round(val/step)*step;
|
curleft += obj.offsetLeft;
|
||||||
numberController.setValue(val);
|
curtop += obj.offsetTop;
|
||||||
}
|
} while ((obj = obj.offsetParent));
|
||||||
|
return [curleft,curtop];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
this.domElement.addEventListener('mousedown', function(e) {
|
this.__defineSetter__('value', function(e) {
|
||||||
clicked = true;
|
var pct = GUI.map(e, min, max, 0, 100);
|
||||||
x = px = e.pageX;
|
this.fg.style.width = pct+"%";
|
||||||
_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 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);
|
||||||
|
};
|
||||||
|
|
||||||
var mouseup = function(e) {
|
this.domElement.addEventListener('mousedown', function(e) {
|
||||||
_this.domElement.setAttribute('class', 'guidat-slider-bg');
|
clicked = true;
|
||||||
_this.fg.setAttribute('class', 'guidat-slider-fg');
|
x = px = e.pageX;
|
||||||
numberController.domElement.className = numberController.domElement.className.replace(' active', '');
|
_this.domElement.setAttribute('class', 'guidat-slider-bg active');
|
||||||
clicked = false;
|
_this.fg.setAttribute('class', 'guidat-slider-fg active');
|
||||||
if (numberController.finishChangeFunction != null) {
|
onDrag(e);
|
||||||
numberController.finishChangeFunction.call(this, numberController.getValue());
|
document.addEventListener('mouseup', mouseup, false);
|
||||||
}
|
}, false);
|
||||||
document.removeEventListener('mouseup', mouseup, 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);
|
document.addEventListener('mousemove', onDrag, false);
|
||||||
|
|
||||||
this.value = initValue;
|
this.value = initValue;
|
||||||
|
|
||||||
}
|
};
|
||||||
|
161
gui.css
161
gui.css
@ -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;
|
||||||
}
|
}
|
||||||
|
293
index.html
293
index.html
@ -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>
|
||||||
@ -175,25 +168,25 @@ window.onload = function() {
|
|||||||
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"> </div>
|
<div class = "trans"> </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>
|
||||||
|
Loading…
Reference in New Issue
Block a user