From 402093179a87f524ce4f4eaec7db2094f6a8f155 Mon Sep 17 00:00:00 2001
From: "Mr.doob"
Date: Sat, 29 Jan 2011 00:44:54 +0000
Subject: [PATCH 01/54] Removed google analytics (to avoid lag when reloading
:S) Updated "pretified" code.
---
index.html | 27 +++++++++------------------
1 file changed, 9 insertions(+), 18 deletions(-)
diff --git a/index.html b/index.html
index e08f68e..d5bb603 100644
--- a/index.html
+++ b/index.html
@@ -48,16 +48,6 @@
gui.add(fizzyText, "explode").setName('Explode!'); // Specify a custom name.
};
-
- var _gaq = _gaq || [];
- _gaq.push(['_setAccount', 'UA-20996084-1']);
- _gaq.push(['_trackPageview']);
-
- (function() {
- var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
- ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
- var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
- })();
@@ -81,24 +71,25 @@ window.onload = function() {
var fizzyText = new FizzyText("gui-dat");
- GUI.start();
+ var gui = new GUI();
+ document.body.appendChild( gui.domElement );
// Text field
- GUI.add(fizzyText, "message");
+ gui.add(fizzyText, "message");
// Sliders with min and max
- GUI.add(fizzyText, "maxSize", 0.5, 7);
- GUI.add(fizzyText, "growthSpeed", 0.01, 1);
- GUI.add(fizzyText, "speed", 0.1, 2);
+ gui.add(fizzyText, "maxSize", 0.5, 7);
+ gui.add(fizzyText, "growthSpeed", 0.01, 1);
+ gui.add(fizzyText, "speed", 0.1, 2);
// Sliders with min, max and increment.
- GUI.add(fizzyText, "noiseStrength", 10, 100, 5);
+ gui.add(fizzyText, "noiseStrength", 10, 100, 5);
// Boolean checkbox
- GUI.add(fizzyText, "displayOutline");
+ gui.add(fizzyText, "displayOutline");
// Fires a function called "explode"
- GUI.add(fizzyText, "explode").setName('Explode!'); // Specify a custom name.
+ gui.add(fizzyText, "explode").setName('Explode!'); // Specify a custom name.
};
From d770dbb0c20e41a3ab38605d46ceff5e69696461 Mon Sep 17 00:00:00 2001
From: "Mr.doob"
Date: Sat, 29 Jan 2011 01:23:20 +0000
Subject: [PATCH 02/54] Hacked in a Controllers Watcher. It would be nice if
the controllers had the last value cached so setValue will execute only if
_value != value. Added a setWatched example in the demo.
---
controllers/controller.js | 13 ++++++--
controllers/controller.number.js | 10 ++----
demo/demo.js | 11 +++++--
gui.js | 21 ++++++++----
index.html | 55 +++++++++++++++++---------------
5 files changed, 65 insertions(+), 45 deletions(-)
diff --git a/controllers/controller.js b/controllers/controller.js
index ad90e73..ab9ae44 100644
--- a/controllers/controller.js
+++ b/controllers/controller.js
@@ -9,6 +9,15 @@ var Controller = function() {
return this;
}
+ this.setWatched = function() {
+ this.parent.watchController(this);
+ return this;
+ }
+
+ this.getValue = function() {
+ return this.object[this.propertyName];
+ }
+
this.setValue = function(n) {
this.object[this.propertyName] = n;
if (onChange != null) {
@@ -17,8 +26,8 @@ var Controller = function() {
return this;
}
- this.getValue = function() {
- return this.object[this.propertyName];
+ this.watchValue = function() {
+ this.updateValue(this.object[this.propertyName]);
}
this.onChange = function(fnc) {
diff --git a/controllers/controller.number.js b/controllers/controller.number.js
index 80d299b..0907c1c 100644
--- a/controllers/controller.number.js
+++ b/controllers/controller.number.js
@@ -20,15 +20,9 @@ var NumberController = function() {
var step = arguments[4];
if (!step) {
- if (min != undefined && max != undefined) {
- step = (max-min)*0.01;
- } else {
- step = 1;
- }
+ step = min != undefined && max != undefined ? (max-min)*0.01: 1;
}
- console.log("step " + step);
-
var numberField = document.createElement('input');
numberField.setAttribute('id', this.propertyName);
@@ -94,7 +88,7 @@ var NumberController = function() {
// 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(_this.parent.domElement);
_this.makeUnselectable(numberField);
py = y;
diff --git a/demo/demo.js b/demo/demo.js
index 9ac306c..0a4298a 100644
--- a/demo/demo.js
+++ b/demo/demo.js
@@ -1,15 +1,18 @@
function FizzyText(message) {
+ var that = this;
+
// These are the variables that we manipulate with gui-dat.
// Notice they're all defined with "this". That makes them public.
// Otherwise, gui-dat can't see them.
-
+
this.growthSpeed = 0.5; // how fast do particles change size?
this.maxSize = 3.2; // how big can they get?
this.noiseStrength = 10; // how turbulent is the flow?
this.speed = 0.4; // how fast do particles move?
this.displayOutline = false; // should we draw the message as a stroke?
-
+ this.framesRendered = 0;
+
// __defineGetter__ and __defineSetter__ makes JavaScript believe that
// we've defined a variable 'this.message'. This way, whenever we
// change the message variable, we can call some more functions.
@@ -98,6 +101,8 @@ function FizzyText(message) {
// Called once per frame, updates the animation.
var render = function () {
+ that.framesRendered ++;
+
g.clearRect(0, 0, width, height);
if (_this.displayOutline) {
@@ -216,4 +221,4 @@ function FizzyText(message) {
return v;
}
-}
\ No newline at end of file
+}
diff --git a/gui.js b/gui.js
index 96baa02..c9f1e8c 100644
--- a/gui.js
+++ b/gui.js
@@ -22,6 +22,13 @@ var GUI = function () {
this.domElement.appendChild(controllerContainer);
this.domElement.appendChild(toggleButton);
+ // Controllers Watcher
+ setInterval( function() {
+ for (var c in controllersWatched) {
+ controllersWatched[c].watchValue();
+ }
+ }, 1000 / 60 );
+
var handlerTypes = {
"number": NumberController,
"string": StringController,
@@ -96,16 +103,16 @@ var GUI = function () {
return controllerObject;
+ };
+
+ this.watchController = function(c) {
+
+ controllersWatched.push(c);
+
}
this.toggle = function() {
-
- if (open) {
- this.hide();
- } else {
- this.show();
- }
-
+ open ? this.hide() : this.show();
};
this.show = function() {
diff --git a/index.html b/index.html
index d5bb603..ff4dbc8 100644
--- a/index.html
+++ b/index.html
@@ -2,8 +2,8 @@
gui-dat
-
-
+
+
@@ -17,37 +17,42 @@
-
-
-
-
+
+
+
@@ -89,7 +94,7 @@ window.onload = function() {
gui.add(fizzyText, "displayOutline");
// Fires a function called "explode"
- gui.add(fizzyText, "explode").setName('Explode!'); // Specify a custom name.
+ gui.add(fizzyText, "explode").setName("Explode!"); // Specify a custom name.
};
From a3b3e38d1dfd96461ac41d4cb4ee764e6bcb7942 Mon Sep 17 00:00:00 2001
From: "Mr.doob"
Date: Sat, 29 Jan 2011 01:34:57 +0000
Subject: [PATCH 03/54] Merged with jonobr1 branch.
---
README | 59 ++++++++++++++++++++++++++++++++----------------------
README.md | 44 ++++++++++++++++++++++++++++++++++++++++
index.html | 18 ++++++++++++++---
3 files changed, 94 insertions(+), 27 deletions(-)
create mode 100644 README.md
diff --git a/README b/README
index 426e5b2..1f8431a 100644
--- a/README
+++ b/README
@@ -1,31 +1,42 @@
- var controllableObject =
- {
- numberProperty: 20,
- anotherNumberProperty: 0,
- textProperty: "a string",
- booleanProperty: false,
- functionProperty: function() {
- alert("I am a function!");
- }
- };
+# gui-dat
+**gui-dat** is a lightweight controller library for JavaScript. It allows you to easily manipulate variables and fire functions on the fly.
+## Basic Usage
+
+
++ ui-dat will infer the type of the property you're trying to add (based on its initial value) and create the corresponding control.
++ The properties must be public, i.e. defined by `**this**.prop = value`.
+## Monitor variable changes outside of the GUI
+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 listen() method
+ GUI.add(obj, "propName").listen();
+## Fire a function when someone uses a control
+ GUI.add(obj, "propName").onChange(function(n) {
+ alert("You changed me to " + n);
+ });
+Initiated by [George Michael Brower]:http://georgemichaelbrower.com/ and [Jono Brandel]:http://jonobr1.com/ of the Data Arts Team, Google Creative Lab.
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..415cd25
--- /dev/null
+++ b/README.md
@@ -0,0 +1,44 @@
+# gui-dat
+**gui-dat** is a lightweight controller library for JavaScript. It allows you to easily manipulate variables and fire functions on the fly.
+## Basic Usage
+
+
++ ui-dat will infer the type of the property you're trying to add (based on its initial value) and create the corresponding control.
++ The properties must be public, i.e. defined by `this.prop = value`.
+
+Monitor variable changes outside of the GUI
+--------------------------------------------------
+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 listen() method
+ GUI.add(obj, "propName").listen();
+## Fire a function when someone uses a control
+ GUI.add(obj, "propName").onChange(function(n) {
+ alert("You changed me to " + n);
+ });
+Initiated by [George Michael Brower](http://georgemichaelbrower.com/) and [Jono Brandel](http://jonobr1.com/) of the Data Arts Team, Google Creative Lab.
diff --git a/index.html b/index.html
index ff4dbc8..259cc21 100644
--- a/index.html
+++ b/index.html
@@ -104,8 +104,20 @@ window.onload = function() {
gui-dat will infer the type of the property you're trying to add (based on its initial value) and create the corresponding control.
The properties must be public, i.e. defined by this.prop = value.
-
+
+
+
+
+
From fe172c75fb4beb4bc7def2805d18175d7c6a335b Mon Sep 17 00:00:00 2001
From: "Mr.doob"
Date: Sat, 29 Jan 2011 02:25:48 +0000
Subject: [PATCH 04/54] Added updateValue method to StringController (so
watched string controllers update). Moved easing from margin-top to height.
It's now showing an ugly scrollbar jump. Hmm...
---
controllers/controller.string.js | 50 ++++++++++++++++++--------------
gui.css | 8 ++---
2 files changed, 32 insertions(+), 26 deletions(-)
diff --git a/controllers/controller.string.js b/controllers/controller.string.js
index aa955ea..835ba39 100644
--- a/controllers/controller.string.js
+++ b/controllers/controller.string.js
@@ -1,27 +1,33 @@
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);
+
+ 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);
+
+ this.updateValue = function(val) {
+ input.setAttribute('value', val);
+ }
+
};
StringController.prototype = new Controller();
-StringController.prototype.constructor = StringController;
\ No newline at end of file
+StringController.prototype.constructor = StringController;
diff --git a/gui.css b/gui.css
index 98a57a8..d035320 100644
--- a/gui.css
+++ b/gui.css
@@ -8,9 +8,6 @@
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: 0px 0px 10px rgba(0, 0, 0, 0.3);
-moz-box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.3);
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.3);
@@ -26,6 +23,9 @@
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;
}
#guidat-toggle {
@@ -155,4 +155,4 @@ width: 148px;
.guidat-slider-fg {
background-color: #00aeff;
height: 20px;
-}
\ No newline at end of file
+}
From f736507fd460001e7b160324f9bc33b00515d2b2 Mon Sep 17 00:00:00 2001
From: jonobr1
Date: Fri, 28 Jan 2011 19:55:43 -0700
Subject: [PATCH 05/54] Merged in mr doobs changes for watchers and changed
setName to name
---
controllers/controller.js | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/controllers/controller.js b/controllers/controller.js
index ab9ae44..92c770f 100644
--- a/controllers/controller.js
+++ b/controllers/controller.js
@@ -4,7 +4,7 @@ var Controller = function() {
this.parent = null;
- this.setName = function(n) {
+ this.name = function(n) {
this.propertyNameElement.innerHTML = n;
return this;
}
@@ -57,7 +57,7 @@ var Controller = function() {
this.propertyNameElement = document.createElement('span');
this.propertyNameElement.setAttribute('class', 'guidat-propertyname');
- this.setName(this.propertyName);
+ this.name(this.propertyName);
this.domElement.appendChild(this.propertyNameElement);
this.makeUnselectable(this.domElement);
From a4d600f3b063d9b58054733c4ec1c0fe90001d80 Mon Sep 17 00:00:00 2001
From: jonobr1
Date: Fri, 28 Jan 2011 20:03:56 -0700
Subject: [PATCH 06/54] why does README keep popping back up?
---
README | 42 ------------------------------------------
1 file changed, 42 deletions(-)
delete mode 100644 README
diff --git a/README b/README
deleted file mode 100644
index 1f8431a..0000000
--- a/README
+++ /dev/null
@@ -1,42 +0,0 @@
-# gui-dat
-**gui-dat** is a lightweight controller library for JavaScript. It allows you to easily manipulate variables and fire functions on the fly.
-## Basic Usage
-
-
-+ ui-dat will infer the type of the property you're trying to add (based on its initial value) and create the corresponding control.
-+ The properties must be public, i.e. defined by `**this**.prop = value`.
-## Monitor variable changes outside of the GUI
-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 listen() method
- GUI.add(obj, "propName").listen();
-## Fire a function when someone uses a control
- GUI.add(obj, "propName").onChange(function(n) {
- alert("You changed me to " + n);
- });
-Initiated by [George Michael Brower]:http://georgemichaelbrower.com/ and [Jono Brandel]:http://jonobr1.com/ of the Data Arts Team, Google Creative Lab.
From 092419bdad4e49333b8f8194a27035572d34225a Mon Sep 17 00:00:00 2001
From: jonobr1
Date: Fri, 28 Jan 2011 20:17:57 -0700
Subject: [PATCH 07/54] updated index.html doc to reflect setWatched()
---
index.html | 3 +++
1 file changed, 3 insertions(+)
diff --git a/index.html b/index.html
index 259cc21..245dd3d 100644
--- a/index.html
+++ b/index.html
@@ -93,6 +93,9 @@ window.onload = function() {
// Boolean checkbox
gui.add(fizzyText, "displayOutline");
+ // Watches a property
+ gui.add(fizzyText, "framesRendered").setWatched();
+
// Fires a function called "explode"
gui.add(fizzyText, "explode").setName("Explode!"); // Specify a custom name.
From 2dc271fa44ac2aec43ffedd197fbe56bde299464 Mon Sep 17 00:00:00 2001
From: jonobr1
Date: Fri, 28 Jan 2011 20:22:05 -0700
Subject: [PATCH 08/54] updated index to reflect the new listen() and
onChange() functionality
---
controllers/controller.js | 2 +-
index.html | 8 ++++----
2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/controllers/controller.js b/controllers/controller.js
index 92c770f..0fa37ff 100644
--- a/controllers/controller.js
+++ b/controllers/controller.js
@@ -9,7 +9,7 @@ var Controller = function() {
return this;
}
- this.setWatched = function() {
+ this.listen = function() {
this.parent.watchController(this);
return this;
}
diff --git a/index.html b/index.html
index 245dd3d..416e06a 100644
--- a/index.html
+++ b/index.html
@@ -46,7 +46,7 @@
gui.add(fizzyText, "displayOutline");
// Watches a property
- gui.add(fizzyText, "framesRendered").setWatched();
+ gui.add(fizzyText, "framesRendered").listen();
// Fires a function called "explode"
gui.add(fizzyText, "explode").setName("Explode!"); // Specify a custom name.
@@ -94,7 +94,7 @@ window.onload = function() {
gui.add(fizzyText, "displayOutline");
// Watches a property
- gui.add(fizzyText, "framesRendered").setWatched();
+ gui.add(fizzyText, "framesRendered").listen();
// Fires a function called "explode"
gui.add(fizzyText, "explode").setName("Explode!"); // Specify a custom name.
@@ -108,7 +108,7 @@ window.onload = function() {
The properties must be public, i.e. defined by this.prop = value.