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 @@