Version 0.1

This commit is contained in:
George Michael Brower 2011-01-26 19:45:34 -07:00
parent fe260b5dca
commit f62a04c8e9
6 changed files with 694 additions and 215 deletions

View File

@ -18,7 +18,7 @@ h1 {
font-weight: 800; font-weight: 800;
text-transform: lowercase; text-transform: lowercase;
line-height: 80px; line-height: 80px;
margin: 20px 0 0 0; margin: 20px 0 20px 0;
} }
h1 a:link, h1 a:visited, h1 a:hover, h1 a:active { h1 a:link, h1 a:visited, h1 a:hover, h1 a:active {
@ -26,20 +26,27 @@ h1 a:link, h1 a:visited, h1 a:hover, h1 a:active {
margin-right: 7px; margin-right: 7px;
} }
h1 span {
}
h1 img { h1 img {
width: 45px; width: 45px;
height: 45px; height: 45px;
-moz-border-radius: 9px; -moz-border-radius: 9px;
border-radius: 9px; border-radius: 9px;
margin-bottom: 20px; margin-bottom: 8px;
} }
h2 { h2 {
margin-top: 30px;
font-size: 18px; font-size: 18px;
margin-bottom: 24px;
}
#helvetica-demo {
position: absolute;
left: 0;
top: 0;
width: 800;
height: 300;
z-index: -1;
} }
pre { pre {
@ -50,17 +57,35 @@ pre {
font: 10px Monaco, monospace; font: 10px Monaco, monospace;
} }
p { font-size: 125%; max-width: 530px; line-height: 18px; margin-bottom: 36px; } p, ul {
font-size: 125%;
max-width: 530px;
line-height: 18px;
margin-bottom: 24px;
}
li {
margin-left: 18px;
}
ul#desc {
list-style: circle;
font-size: 100%;
max-width: 380px;
}
a:link { a:link {
color: #00aeff; color: #00aeff;
} }
a:visited { a:visited {
color: #0fa954; color: #0fa954;
} }
a:hover { a:hover {
color: #e61d5f; color: #e61d5f;
} }
a:active { a:active {
color: #54396e; color: #54396e;
} }
@ -71,18 +96,23 @@ width: 510px;
padding: 10px; padding: 10px;
} }
#columns { pre a:link,
position: fixed; pre a:visited,
bottom: 0; pre a:active {
left: 0; color: #ccc;
width: 100%;
height: 10px;
} }
#columns div { pre a:hover {
float: left; color: #e61d5f;
width : auto; }
height: 10px;
code {
font: 10px Monaco, monospace;
}
code strong {
font-weight: normal;
color: #e61d5f;
} }
/* SPAN elements with the classes below are added by prettyprint. */ /* SPAN elements with the classes below are added by prettyprint. */

View File

@ -1,30 +1,27 @@
function DynamicText(message, width, height, textAscent) { function FizzyText(message) {
var _this = this; var _this = this;
var width = 550;
var height = 200;
var textAscent = 82;
var textLeft = 80;
this.growthSpeed = 0.5; this.growthSpeed = 0.5;
this.minSize = 0; this.minSize = 0;
this.maxSize = 3; this.maxSize = 3.2;
this.noiseScale = 300; this.noiseScale = 300;
this.noiseStrength = 10; this.noiseStrength = 10;
this.stepSize = 1; this.speed = 0.4;
this.displayOutline = false; this.displayOutline = false;
var message = message;
this.width = width;
this.height = height;
this.textAscent = textAscent; this.textAscent = textAscent;
var colors = [
"#00aeff", var colors = ["#00aeff", "#0fa954", "#54396e", "#e61d5f"];
"#0fa954",
"#54396e",
"#e61d5f"
]
var r = document.createElement('canvas'); var r = document.createElement('canvas');
var s = r.getContext('2d'); var s = r.getContext('2d');
@ -54,7 +51,7 @@ function DynamicText(message, width, height, textAscent) {
s.fillRect(0, 0, width, height); s.fillRect(0, 0, width, height);
s.fillStyle = "#222"; s.fillStyle = "#222";
s.fillText(m, 0, textAscent); s.fillText(m, textLeft, textAscent);
// Pull reference // Pull reference
var imageData = s.getImageData(0, 0, width, height); var imageData = s.getImageData(0, 0, width, height);
@ -69,8 +66,8 @@ function DynamicText(message, width, height, textAscent) {
if (_this.displayOutline) { if (_this.displayOutline) {
g.globalCompositeOperation = "source-over"; g.globalCompositeOperation = "source-over";
g.strokeStyle = "#000"; g.strokeStyle = "#000";
g.lineWidth = .25; g.lineWidth = .5;
g.strokeText(message, 0, textAscent); g.strokeText(message, textLeft, textAscent);
} }
g.globalCompositeOperation = "darker"; g.globalCompositeOperation = "darker";
@ -83,12 +80,20 @@ function DynamicText(message, width, height, textAscent) {
}; };
var getPosition = function (i) { var getPosition = function (i) {
return { x: (i - (width * 4) * Math.floor(i/(width * 4))) / 4, y: Math.floor(i/(width * 4)) }; return {
x: (i - (width * 4) * Math.floor(i / (width * 4))) / 4,
y: Math.floor(i / (width * 4))
};
}; };
var getColor = function (x, y) { var getColor = function (x, y) {
var base = (Math.floor(y) * width + Math.floor(x)) * 4; var base = (Math.floor(y) * width + Math.floor(x)) * 4;
var c = { r: pixels[base + 0], g: pixels[base + 1], b: pixels[base + 2], a: pixels[base + 3]}; var c = {
r: pixels[base + 0],
g: pixels[base + 1],
b: pixels[base + 2],
a: pixels[base + 3]
};
return "rgb(" + c.r + "," + c.g + "," + c.b + ")"; return "rgb(" + c.r + "," + c.g + "," + c.b + ")";
}; };
@ -102,37 +107,59 @@ function DynamicText(message, width, height, textAscent) {
createBitmap(message); createBitmap(message);
}); });
createBitmap(message); this.explode = function() {
var mag = Math.random()*30+30;
for (var i in particles) {
var angle= Math.random()*Math.PI*2;
particles[i].vx = Math.cos(angle)*mag;
particles[i].vy = Math.sin(angle)*mag;
}
};
this.message = message;
setInterval(render, 30); setInterval(render, 30);
function Particle(x, y, c) { function Particle(x, y, c) {
this.p = { x: x, y: y }; this.x = x;
this.y = y;
this.vx = 0;
this.vy = 0;
this.r = 0; this.r = 0;
this.render = function () { this.render = function () {
var c = getColor(this.x, this.y); var c = getColor(this.x, this.y);
var angle = noise(this.x / _this.noiseScale, this.y / _this.noiseScale) * _this.noiseStrength;
var angle = noise(this.p.x/_this.noiseScale, this.p.y/_this.noiseScale) * _this.noiseStrength; var onScreen = this.x > 0 && this.x < width &&
var c = getColor(this.p.x, this.p.y); this.y > 0 && this.y < height;
if (c == "rgb(255,255,255)") { var isBlack = c != "rgb(255,255,255)" &&
this.r -= _this.growthSpeed; onScreen;
} else {
if (isBlack) {
this.r += _this.growthSpeed; this.r += _this.growthSpeed;
} else {
this.r -= _this.growthSpeed;
} }
this.p.x += Math.cos(angle) * _this.stepSize; this.vx *= 0.5;
this.p.y += -Math.sin(angle) * _this.stepSize; this.vy *= 0.5;
this.x += Math.cos(angle) * _this.speed + this.vx;
this.y += -Math.sin(angle) * _this.speed + this.vy;
this.r = constrain(this.r, _this.minSize, _this.maxSize); this.r = constrain(this.r, _this.minSize, _this.maxSize);
if (this.r <= _this.minSize) { if (this.r <= _this.minSize) {
this.p.x = Math.random() * width; this.x = Math.random() * width;
this.p.y = Math.random() * height; this.y = Math.random() * height;
}
if (this.r <= 0) {
return;
} }
g.beginPath(); g.beginPath();
g.arc(this.p.x, this.p.y, this.r, 0, Math.PI*2, false); g.arc(this.x, this.y, this.r, 0, Math.PI * 2, false);
g.fill(); g.fill();
} }
} }
var constrain = function (v, o1, o2) { var constrain = function (v, o1, o2) {
if (v < o1) v = o1; if (v < o1) v = o1;
else if (v > o2) v = o2; else if (v > o2) v = o2;

489
gui-tobeminified.js Normal file
View File

@ -0,0 +1,489 @@
// This version of gui.js appends the style definitions via javascript.
var GUI = new function() {
var _this = this;
var controllers = [];
var style = '#guidat{color:#fff;position:fixed;width:280px;z-index:200;opacity:.97;top:0;left:100%;margin-left:-300px;background-color:#fff;-moz-transition:margin-top .2s ease-out;-webkit-transition:margin-top .2s ease-out;transition:margin-top .2s ease-out;-webkit-box-shadow:0 0 10px rgba(0,0,0,0.3);-moz-box-shadow:0 0 10px rgba(0,0,0,0.3);box-shadow:0 0 10px rgba(0,0,0,0.3)}#guidat,#guidat input{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)}#guidat-toggle{text-decoration:none;cursor:pointer;color:#fff;background-color:#222;text-align:center;display:block;padding:5px}#guidat-toggle:hover{background-color:#000}.guidat-controller{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 .15s linear;-webkit-transition:background-color .15s linear;transition:background-color .15s linear}.guidat-controller.boolean:hover,.guidat-controller.function:hover{background-color:#000}.guidat-controller input{float:right;outline:none;border:0;padding:4px;margin-top:2px;background-color:#222}.guidat-controller input:hover{background-color:#444}.guidat-controller input:focus{background-color:#555}.guidat-controller.number{border-left:5px solid #00aeff}.guidat-controller.string{border-left:5px solid #1ed36f}.guidat-controller.string input{border:0;color:#1ed36f;margin-right:2px;width:148px}.guidat-controller.boolean{border-left:5px solid #54396e}.guidat-controller.function{border-left:5px solid #e61d5f}.guidat-controller.number input[type=text]{width:35px;margin-left:5px;margin-right:2px;color:#00aeff}#guidat .guidat-controller.boolean input{margin-top:6px;margin-right:2px;font-size:20px}.guidat-controller:last-child{border-bottom:none;-webkit-box-shadow:0 1px 3px rgba(0,0,0,0.5);-moz-box-shadow:0 1px 3px rgba(0,0,0,0.5);box-shadow:0 1px 3px rgba(0,0,0,0.5)}.guidat-propertyname{padding:5px;padding-top:7px;cursor:default;display:inline-block}.guidat-slider-bg:hover,.guidat-slider-bg.active{background-color:#444}.guidat-slider-bg:hover .guidat-slider-fg,.guidat-slider-bg.active .guidat-slider-fg{background-color:#52c8ff}.guidat-slider-bg{background-color:#222;cursor:ew-resize;width:40%;margin-top:2px;float:right;height:21px}.guidat-slider-fg{background-color:#00aeff;height:20px}'
this.add = function() {
// We need to call GUI.start() before .add()
if (!started) {
error("Make sure to call GUI.start() in the window.onload function");
return;
}
var object = arguments[0];
var propertyName = arguments[1];
// Have we already added this?
if (alreadyControlled(object, propertyName)) {
error("Controller for \"" + propertyName+"\" already added.");
return;
}
var value = object[propertyName];
// Does this value exist? Is it accessible?
if (value == undefined) {
error(object + " either has no property \""+propertyName+"\", or the property is inaccessible.");
return;
}
var type = typeof value;
var handler = addHandlers[type];
// Do we know how to deal with this data type?
if (handler == undefined) {
error("Cannot create controller for data type \""+type+"\"");
return;
}
var controllerObject = handler.apply(this, arguments);
// Were we able to make the controller?
if (!controllerObject) {
error("Error creating controller for \""+propertyName+"\".");
return;
}
// Success.
controllerContainer.appendChild(controllerObject.domElement);
controllers.push(controllerObject);
return controllerObject;
}
var addHandlers = {
"number": function() {
return construct(NumberController, arguments);
},
"string": function() {
return construct(StringController, arguments);
},
"boolean": function() {
return construct(BooleanController, arguments);
},
"function": function() {
return construct(FunctionController, arguments);
},
};
var alreadyControlled = function(object, propertyName) {
for (var i in controllers) {
if (controllers[i].object == object &&
controllers[i].propertyName == propertyName) {
return true;
}
}
return false;
};
var error = function(str) {
if (typeof console.log == 'function') {
console.error("[GUI ERROR] " + str);
}
};
var construct = function(constructor, args) {
function F() {
return constructor.apply(this, args);
}
F.prototype = constructor.prototype;
return new F();
};
// GUI ... GUI
this.domElement = null;
var controllerContainer;
var started = false;
var open = false;
// TODO: obtain this dynamically?
var domElementMarginTop = 300;
this.start = function() {
var styleSheet = document.createElement('style');
styleSheet.setAttribute('type', 'text/css');
styleSheet.innerHTML = style;
document.getElementsByTagName('head')[0].appendChild(styleSheet);
this.domElement = document.createElement('div');
this.domElement.setAttribute('id', 'guidat');
controllerContainer = document.createElement('div');
controllerContainer.setAttribute('id', 'guidat-controllers');
toggleButton = document.createElement('a');
toggleButton.setAttribute('id', 'guidat-toggle');
toggleButton.setAttribute('href', '#');
toggleButton.innerHTML = "Show Controls";
toggleButton.addEventListener('click', function(e) {
_this.toggle();
e.preventDefault();
}, false);
this.domElement.appendChild(controllerContainer);
this.domElement.appendChild(toggleButton);
this.domElement.style.marginTop = -domElementMarginTop+"px";
document.body.appendChild(this.domElement);
started = true;
};
this.toggle = function() {
if (open) {
this.hide();
} else {
this.show();
}
};
this.show = function() {
this.domElement.style.marginTop = 0+"px";
toggleButton.innerHTML = "Hide Controls";
open = true;
}
this.hide = function() {
this.domElement.style.marginTop = -domElementMarginTop+"px";
toggleButton.innerHTML = "Show Controls";
open = false;
}
};
// TODO: Leaving the window while dragging the slider and then removing the mouse
// still leaves slider in focus.
// TODO: Problem with multiple sliders.
var 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.fg = document.createElement('div');
this.domElement.setAttribute('class', 'guidat-slider-bg');
this.fg.setAttribute('class', 'guidat-slider-fg');
this.domElement.appendChild(this.fg);
var map = function(v, i1, i2, o1, o2) {
var v = o1 + (o2 - o1) * ((v - i1) / (i2 - i1));
if (v < o1) v = o1;
else if (v > o2) v = o2;
return v;
}
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 = 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 = map(e.pageX, pos[0], pos[0] + _this.domElement.offsetWidth, min, max);
val = Math.round(val/step)*step;
numberController.updateValue(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);
}, false);
document.addEventListener('mouseup', function(e) {
_this.domElement.setAttribute('class', 'guidat-slider-bg');
_this.fg.setAttribute('class', 'guidat-slider-fg');
clicked = false;
}, false);
document.addEventListener('mousemove', onDrag, false);
this.value = initValue;
}
var Controller = function() {
var onChange = null;
this.setName = function(n) {
this.propertyNameElement.innerHTML = n;
}
this.setValue = function(n) {
this.object[this.propertyName] = n;
if (onChange != null) {
onChange.call(this, n);
}
}
this.getValue = function() {
return this.object[this.propertyName];
}
this.onChange = function(fnc) {
onChange = fnc;
}
this.makeUnselectable = function(elem) {
elem.onselectstart = function() { return false; };
elem.style.MozUserSelect = "none";
elem.style.KhtmlUserSelect = "none";
elem.unselectable = "on";
}
this.makeSelectable = function(elem) {
elem.onselectstart = function() { };
elem.style.MozUserSelect = "auto";
elem.style.KhtmlUserSelect = "auto";
elem.unselectable = "off";
}
this.domElement = document.createElement('div');
this.domElement.setAttribute('class', 'guidat-controller ' + this.type);
this.object = arguments[0];
this.propertyName = arguments[1];
this.propertyNameElement = document.createElement('span');
this.propertyNameElement.setAttribute('class', 'guidat-propertyname');
this.setName(this.propertyName);
this.domElement.appendChild(this.propertyNameElement);
this.makeUnselectable(this.domElement);
};
var BooleanController = function() {
this.type = "boolean";
Controller.apply(this, arguments);
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);
}, false);
input.addEventListener('mouseup', function(e) {
input.checked = !input.checked; // counteracts default.
}, false);
this.domElement.style.cursor = "pointer";
this.propertyNameElement.style.cursor = "pointer";
this.domElement.appendChild(input);
};
BooleanController.prototype = new Controller();
BooleanController.prototype.constructor = BooleanController;
var FunctionController = function() {
this.type = "function";
var _this = this;
Controller.apply(this, arguments);
this.domElement.addEventListener('click', function() {
_this.object[_this.propertyName].call(_this.object);
}, false);
this.domElement.style.cursor = "pointer";
this.propertyNameElement.style.cursor = "pointer";
};
FunctionController.prototype = new Controller();
FunctionController.prototype.constructor = FunctionController;
// TODO: Provide alternate controllers for non-html5 browsers?
var NumberController = function() {
this.type = "number";
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 min = arguments[2];
var max = arguments[3];
var step = arguments[4];
if (!step) {
if (min && max) {
step = (max-min)*0.01;
} else {
step = 1;
}
}
var numberField = document.createElement('input');
numberField.setAttribute('id', this.propertyName);
// Little up and down arrows are pissing me off.
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 Slider(this, min, max, step, this.getValue());
this.domElement.appendChild(slider.domElement);
}
numberField.addEventListener('blur', function(e) {
var val = parseFloat(this.value);
if (!isNaN(val)) {
_this.updateValue(val);
} else {
this.value = _this.getValue();
}
}, false);
numberField.addEventListener('mousewheel', function(e) {
e.preventDefault();
this.updateValue(_this.getValue() + Math.abs(e.wheelDeltaY)/e.wheelDeltaY*step);
return false;
}, false);
numberField.addEventListener('mousedown', function(e) {
py = y = e.pageY;
clickedNumberField = true;
document.addEventListener('mousemove', dragNumberField, false);
}, false);
document.addEventListener('mouseup', function(e) {
document.removeEventListener('mousemove', dragNumberField, false);
_this.makeSelectable(GUI.domElement);
_this.makeSelectable(numberField);
if (clickedNumberField && !draggedNumberField) {
numberField.focus();
numberField.select();
}
draggedNumberField = false;
clickedNumberField = false;
}, false);
// Kinda nast
if (navigator.appVersion.indexOf('chrome') != -1) {
document.addEventListener('mouseout', function(e) {
document.removeEventListener('mousemove', dragNumberField, false);
}, 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.
_this.makeUnselectable(GUI.domElement);
_this.makeUnselectable(numberField);
py = y;
y = e.pageY;
var dy = py - y;
var newVal = _this.getValue() + dy*step;
_this.updateValue(newVal);
return false;
}
this.updateValue = function(val) {
val = parseFloat(val);
if (min != undefined && val <= min) {
val = min;
} else if (max != undefined && val >= max) {
val = max;
}
_this.setValue(val);
numberField.value = _this.getValue();
if (slider) slider.value = _this.getValue();
}
};
NumberController.prototype = new Controller();
NumberController.prototype.constructor = NumberController;
var StringController = function() {
this.type = "string";
var _this = this;
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();
}, false);
input.addEventListener('keyup', function() {
_this.setValue(input.value);
}, false);
this.domElement.appendChild(input);
};
StringController.prototype = new Controller();
StringController.prototype.constructor = StringController;

View File

@ -94,7 +94,7 @@
border: 0; border: 0;
color: #1ed36f; color: #1ed36f;
margin-right: 2px; margin-right: 2px;
width: 53%; width: 148px;
} }
.guidat-controller.boolean { .guidat-controller.boolean {

1
gui.min.js vendored Normal file

File diff suppressed because one or more lines are too long

View File

@ -1,66 +1,34 @@
<!doctype html> <!doctype html>
<head> <head>
<title>GUI-DAT</title> <title>gui-dat</title>
<link rel="icon" type="image/gif" href="demo/assets/favicon.gif"> <link rel="icon" type="image/gif" href="demo/assets/favicon.gif">
<link href="gui.css" media="screen" rel="stylesheet" type="text/css" />
<link href="demo/demo.css" media="screen" rel="stylesheet" type="text/css" /> <link href="demo/demo.css" media="screen" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="http://google-code-prettify.googlecode.com/svn/trunk/src/prettify.js"></script> <script type="text/javascript" src="gui.min.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.string.js"></script>
<script type="text/javascript" src="controllers/controller.number.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="demo/improvedNoise.js"></script> <script type="text/javascript" src="demo/improvedNoise.js"></script>
<script type="text/javascript" src="demo/demo.js"></script> <script type="text/javascript" src="demo/demo.js"></script>
<script type="text/javascript"> <script type="text/javascript">
var controllableObject =
{
numberProperty: 20,
constrainedNum: 0,
notchedNum: 240,
pageTitle: "gui-dat",
anotherTextProperty: "another string",
booleanProperty: false,
anotherBooleanProperty: false,
functionProperty: function() {
alert("I am a function!");
}
};
window.onload = function() { window.onload = function() {
var testDisplay = new DynamicText("gui-dat", 600, 100, 75); var fizzyText = new FizzyText("gui-dat");
prettyPrint();
GUI.start(); GUI.start();
// Creates a number box // Text field
GUI.add(testDisplay, "maxSize", 1, 5); GUI.add(fizzyText, "message");
// Creates a slider (min, max) // Sliders with min and max
GUI.add(testDisplay, "growthSpeed", 0.01, 1); GUI.add(fizzyText, "maxSize", 0.5, 7);
GUI.add(fizzyText, "growthSpeed", 0.01, 1);
GUI.add(fizzyText, "speed", 0.1, 2);
// Creates a slider (min, max) // Sliders with min, max and increment.
GUI.add(testDisplay, "noiseStrength", 10, 100); GUI.add(fizzyText, "noiseStrength", 10, 100, 5);
// Creates a slider (min, max) // Boolean checkbox
GUI.add(testDisplay, "stepSize", 1, 4); GUI.add(fizzyText, "displayOutline");
// Creates a text field GUI.add(fizzyText, "explode")
GUI.add(testDisplay, "message");
// Creates a checkbox
GUI.add(testDisplay, "displayOutline");
// Creates a button
GUI.add(controllableObject, "functionProperty")
.setName("Fire a Function");
}; };
@ -76,60 +44,24 @@
</script> </script>
</head> </head>
<body> <body>
<h1><a href = "http://twitter.com/guidat"><img src = "demo/assets/favicon.gif" border = "0" alt = "GUI-DAT flag" /></a><span id = "helvetica-demo"></span></h1> <div id = "helvetica-demo"></div>
<h1><a href = "http://twitter.com/guidat"><img src = "demo/assets/favicon.gif" border = "0" alt = "GUI-DAT flag" /></a></h1>
<p> <p>
<strong>gui-dat</strong> is a lightweight controller library for JavaScript. It allows you to easily manipulate variables and fire functions on the fly. <strong>gui-dat</strong> is a lightweight controller library for JavaScript. It allows you to easily manipulate variables and fire functions on the fly.
</p> </p>
<p>&bull; <a href="#"><strong>Download the minified source</strong></a> <small>[2.3kb]</small><br/> <ul>
&bull; <a href="http://github.com/jonobr1/GUI-DAT">Contribute on GitHub!</a></p> <li><a href=""><strong>Download the minified source</strong></a> <small>[9.8kb]</small></li>
<li><a href="http://github.com/jonobr1/GUI-DAT">Contribute on GitHub!</a></p></li>
</ul>
<h2>Basic Usage</h2> <h2>Basic Usage</h2>
<pre id="demo-pre" class="prettyprint"><span class="tag">&lt;script</span><span class="pln"> </span><span class="atn">type</span><span class="pun">=</span><span class="atv">"text/javascript"</span><span class="pln"> </span><span class="atn">src</span><span class="pun">=</span><span class="atv">"gui.min.js"</span><span class="tag">&gt;&lt;/script&gt;</span><span class="pln"><br></span><span class="tag">&lt;script</span><span class="pln"> </span><span class="atn">type</span><span class="pun">=</span><span class="atv">"text/javascript"</span><span class="tag">&gt;</span><span class="pln"><br><br>window</span><span class="pun">.</span><span class="pln">onload </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">function</span><span class="pun">()</span><span class="pln"> </span><span class="pun">{</span><span class="pln"><br><br>&nbsp; &nbsp;</span><span class="kwd">var</span><span class="pln"> fizzyText </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">new</span><span class="pln"> </span><span class="typ"><a href="demo/demo.js">FizzyText</a></span><span class="pun">(</span><span class="str">"gui-dat"</span><span class="pun">);</span><span class="pln"><br><br>&nbsp; &nbsp;GUI</span><span class="pun">.</span><span class="pln">start</span><span class="pun">();</span><span class="pln"><br>&nbsp; &nbsp;<br>&nbsp; &nbsp;</span><span class="com">// Adds a text field</span><span class="pln"><br>&nbsp; &nbsp;GUI</span><span class="pun">.</span><span class="pln">add</span><span class="pun">(</span><span class="pln">fizzyText</span><span class="pun">,</span><span class="pln"> </span><span class="str">"message"</span><span class="pun">);</span><span class="pln"><br>&nbsp; &nbsp;<br>&nbsp; &nbsp;</span><span class="com">// Adds sliders with min and max</span><span class="pln"><br>&nbsp; &nbsp;GUI</span><span class="pun">.</span><span class="pln">add</span><span class="pun">(</span><span class="pln">fizzyText</span><span class="pun">,</span><span class="pln"> </span><span class="str">"maxSize"</span><span class="pun">,</span><span class="pln"> </span><span class="lit">0.5</span><span class="pun">,</span><span class="pln"> </span><span class="lit">7</span><span class="pun">);</span><span class="pln"><br>&nbsp; &nbsp;GUI</span><span class="pun">.</span><span class="pln">add</span><span class="pun">(</span><span class="pln">fizzyText</span><span class="pun">,</span><span class="pln"> </span><span class="str">"growthSpeed"</span><span class="pun">,</span><span class="pln"> </span><span class="lit">0.01</span><span class="pun">,</span><span class="pln"> </span><span class="lit">1</span><span class="pun">);</span><span class="pln"><br>&nbsp; &nbsp;GUI</span><span class="pun">.</span><span class="pln">add</span><span class="pun">(</span><span class="pln">fizzyText</span><span class="pun">,</span><span class="pln"> </span><span class="str">"speed"</span><span class="pun">,</span><span class="pln"> </span><span class="lit">0.1</span><span class="pun">,</span><span class="pln"> </span><span class="lit">2</span><span class="pun">);</span><span class="pln"><br>&nbsp; &nbsp;<br>&nbsp; &nbsp;</span><span class="com">// Adds sliders with min, max and increment.</span><span class="pln"><br>&nbsp; &nbsp;GUI</span><span class="pun">.</span><span class="pln">add</span><span class="pun">(</span><span class="pln">fizzyText</span><span class="pun">,</span><span class="pln"> </span><span class="str">"noiseStrength"</span><span class="pun">,</span><span class="pln"> </span><span class="lit">10</span><span class="pun">,</span><span class="pln"> </span><span class="lit">100</span><span class="pun">,</span><span class="pln"> </span><span class="lit">5</span><span class="pun">);</span><span class="pln"><br>&nbsp; &nbsp;<br>&nbsp; &nbsp;</span><span class="com">// Adds a boolean checkbox</span><span class="pln"><br>&nbsp; &nbsp;GUI</span><span class="pun">.</span><span class="pln">add</span><span class="pun">(</span><span class="pln">fizzyText</span><span class="pun">,</span><span class="pln"> </span><span class="str">"displayOutline"</span><span class="pun">);</span><span class="pln"><br><br>&nbsp; &nbsp;</span><span class="com">// Adds a function button</span><span class="pln"><br>&nbsp; &nbsp;GUI</span><span class="pun">.</span><span class="pln">add</span><span class="pun">(</span><span class="pln">fizzyText</span><span class="pun">,</span><span class="pln"> </span><span class="str">"explode"</span><span class="pun">)</span><span class="pln"><br>&nbsp; &nbsp;<br></span><span class="pun">};</span><span class="pln"><br><br></span><span class="tag">&lt;/script&gt;</span></pre>
<pre id="demo-pre" class="prettyprint"> <ul id="desc">
&lt;script type=&quot;text/javascript&quot; src=&quot;gui.min.js&quot;&gt;&lt;/script&gt; <li><strong>gui-dat</strong> will infer the type of the property you're trying to add<br/>(based on its initial value) and create the corresponding control.</li>
&lt;script type=&quot;text/javascript&quot;&gt; <li>The properties must be public, i.e. defined by <code><strong>this</strong>.prop = value</code>.</li>
</ul>
var controllableObject =
{
numberProperty: 20,
constrainedNum: 0,
notchedNum: 240,
textProperty: &quot;a string&quot;,
anotherTextProperty: &quot;another string&quot;,
booleanProperty: false,
anotherBooleanProperty: false,
functionProperty: function() {
alert(&quot;I am a function!&quot;);
}
};
window.onload = function() {
GUI.start();
// Creates a number box
GUI.add(controllableObject, &quot;numberProperty&quot;);
// Creates a slider (min, max)
GUI.add(controllableObject, &quot;constrainedNum&quot;, -100, 100)
// Creates a slider with notches
GUI.add(controllableObject, &quot;notchedNum&quot;, 0, 800, 100)
// Creates a text field
GUI.add(controllableObject, &quot;textProperty&quot;);
// Creates a checkbox
GUI.add(controllableObject, &quot;booleanProperty&quot;);
// Creates a button
GUI.add(controllableObject, &quot;functionProperty&quot;)
.setName(&quot;Fire a Function&quot;);
};
&lt;/script&gt;</pre>
<footer> <footer>
By <a href="http://georgemichaelbrower.com/">George Michael Brower</a>, <a href="http://jonobr1.com/">Jono Brandel</a>, and <a href="http://github.com/jonobr1/GUI-DAT">you</a>. By <a href="http://georgemichaelbrower.com/">George Michael Brower</a>, <a href="http://jonobr1.com/">Jono Brandel</a>, and <a href="http://github.com/jonobr1/GUI-DAT">you</a>.
</footer> </footer>