2011-01-25 08:22:04 +00:00
|
|
|
var Controller = function() {
|
|
|
|
|
2011-01-29 04:04:33 +00:00
|
|
|
this.parent = arguments[0];
|
|
|
|
this.object = arguments[1];
|
|
|
|
this.propertyName = arguments[2];
|
2011-01-26 01:55:59 +00:00
|
|
|
|
2011-01-31 15:47:07 +00:00
|
|
|
if (arguments.length > 0) this.initialValue = this.propertyName[this.object];
|
|
|
|
|
2011-01-25 08:22:04 +00:00
|
|
|
this.domElement = document.createElement('div');
|
|
|
|
this.domElement.setAttribute('class', 'guidat-controller ' + this.type);
|
|
|
|
|
|
|
|
this.propertyNameElement = document.createElement('span');
|
|
|
|
this.propertyNameElement.setAttribute('class', 'guidat-propertyname');
|
2011-01-29 04:04:33 +00:00
|
|
|
this.name(this.propertyName);
|
2011-01-25 08:22:04 +00:00
|
|
|
this.domElement.appendChild(this.propertyNameElement);
|
|
|
|
|
2011-02-01 04:02:22 +00:00
|
|
|
this.timeElement = document.createElement('div');
|
|
|
|
this.timeElement.setAttribute('class', 'guidat-time');
|
|
|
|
this.domElement.appendChild(this.timeElement);
|
|
|
|
|
|
|
|
|
2011-01-29 04:04:33 +00:00
|
|
|
GUI.makeUnselectable(this.domElement);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
Controller.prototype.changeFunction = null;
|
|
|
|
|
|
|
|
Controller.prototype.name = function(n) {
|
|
|
|
this.propertyNameElement.innerHTML = n;
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
2011-01-31 15:47:07 +00:00
|
|
|
Controller.prototype.reset = function() {
|
|
|
|
this.setValue(this.initialValue);
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
2011-01-29 04:04:33 +00:00
|
|
|
Controller.prototype.listen = function() {
|
|
|
|
this.parent.listenTo(this);
|
2011-01-31 15:47:07 +00:00
|
|
|
return this;
|
2011-01-29 04:04:33 +00:00
|
|
|
}
|
2011-01-29 04:28:12 +00:00
|
|
|
|
|
|
|
Controller.prototype.unlisten = function() {
|
2011-02-01 03:06:34 +00:00
|
|
|
this.parent.unlistenTo(this); // <--- hasn't been tested yet
|
2011-01-31 15:47:07 +00:00
|
|
|
return this;
|
2011-01-29 04:28:12 +00:00
|
|
|
}
|
2011-01-29 04:04:33 +00:00
|
|
|
|
|
|
|
Controller.prototype.setValue = function(n) {
|
|
|
|
this.object[this.propertyName] = n;
|
|
|
|
if (this.changeFunction != null) {
|
|
|
|
this.changeFunction.call(this, n);
|
|
|
|
}
|
2011-01-29 04:28:12 +00:00
|
|
|
// Whenever you call setValue, the display will be updated automatically.
|
|
|
|
// This reduces some clutter in subclasses. We can also use this method for listen().
|
2011-01-29 04:04:33 +00:00
|
|
|
this.updateDisplay();
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
Controller.prototype.getValue = function() {
|
|
|
|
return this.object[this.propertyName];
|
|
|
|
}
|
|
|
|
|
|
|
|
Controller.prototype.updateDisplay = function() {}
|
2011-01-25 08:22:04 +00:00
|
|
|
|
2011-01-29 04:04:33 +00:00
|
|
|
Controller.prototype.onChange = function(fnc) {
|
|
|
|
this.changeFunction = fnc;
|
|
|
|
return this;
|
2011-01-29 04:28:12 +00:00
|
|
|
}
|