Removed trailing whitespace. Converted tabs to 4 spaces.

This commit is contained in:
Szymon Nowak 2011-02-10 21:50:57 +01:00
parent ac562a2deb
commit 3895cc188e
7 changed files with 797 additions and 797 deletions

View File

@ -1,20 +1,20 @@
GUI.BooleanController = function() {
this.type = "boolean";
GUI.Controller.apply(this, arguments);
this.type = "boolean";
GUI.Controller.apply(this, arguments);
var _this = this;
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);
input.checked = !input.checked;
e.preventDefault();
_this.setValue(input.checked);
}, false);
input.addEventListener('mouseup', function(e) {
input.checked = !input.checked; // counteracts default.
input.checked = !input.checked; // counteracts default.
}, false);
this.domElement.style.cursor = "pointer";
@ -22,17 +22,17 @@ GUI.BooleanController = function() {
this.domElement.appendChild(input);
this.updateDisplay = function() {
input.checked = _this.getValue();
input.checked = _this.getValue();
};
this.setValue = function(val) {
if (typeof val != "boolean") {
try {
val = eval(val);
} catch (e) {}
}
return GUI.Controller.prototype.setValue.call(this, val);
if (typeof val != "boolean") {
try {
val = eval(val);
} catch (e) {}
}
return GUI.Controller.prototype.setValue.call(this, val);
}
};

View File

@ -1,30 +1,30 @@
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.fire();
}, false);
this.domElement.addEventListener('click', function() {
_this.fire();
}, false);
this.domElement.style.cursor = "pointer";
this.propertyNameElement.style.cursor = "pointer";
this.domElement.style.cursor = "pointer";
this.propertyNameElement.style.cursor = "pointer";
var fireFunction = null;
this.onFire = function(fnc) {
fireFunction = fnc;
return this;
}
var fireFunction = null;
this.onFire = function(fnc) {
fireFunction = fnc;
return this;
}
this.fire = function() {
if (fireFunction != null) {
fireFunction.call(this);
}
_this.object[_this.propertyName].call(_this.object);
};
this.fire = function() {
if (fireFunction != null) {
fireFunction.call(this);
}
_this.object[_this.propertyName].call(_this.object);
};
};
GUI.extendController(GUI.FunctionController);

View File

@ -1,10 +1,10 @@
GUI.Controller = function() {
this.parent = arguments[0];
this.parent = arguments[0];
this.object = arguments[1];
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.setAttribute('class', 'guidat-controller ' + this.type);
@ -22,75 +22,75 @@ GUI.Controller.prototype.changeFunction = null;
GUI.Controller.prototype.finishChangeFunction = null;
GUI.Controller.prototype.name = function(n) {
this.propertyNameElement.innerHTML = n;
return this;
this.propertyNameElement.innerHTML = n;
return this;
};
GUI.Controller.prototype.reset = function() {
this.setValue(this.initialValue);
return this;
this.setValue(this.initialValue);
return this;
};
GUI.Controller.prototype.listen = function() {
this.parent.listenTo(this);
return this;
this.parent.listenTo(this);
return this;
}
GUI.Controller.prototype.unlisten = function() {
this.parent.unlistenTo(this); // <--- hasn't been tested yet
return this;
this.parent.unlistenTo(this); // <--- hasn't been tested yet
return this;
}
GUI.Controller.prototype.setValue = function(n) {
this.object[this.propertyName] = n;
if (this.changeFunction != null) {
this.changeFunction.call(this, n);
}
this.updateDisplay();
return this;
this.object[this.propertyName] = n;
if (this.changeFunction != null) {
this.changeFunction.call(this, n);
}
this.updateDisplay();
return this;
}
GUI.Controller.prototype.getValue = function() {
return this.object[this.propertyName];
return this.object[this.propertyName];
}
GUI.Controller.prototype.updateDisplay = function() {}
GUI.Controller.prototype.onChange = function(fnc) {
this.changeFunction = fnc;
return this;
this.changeFunction = fnc;
return this;
}
GUI.Controller.prototype.onFinishChange = function(fnc) {
this.finishChangeFunction = fnc;
return this;
this.finishChangeFunction = fnc;
return this;
}
GUI.Controller.prototype.options = function() {
var _this = this;
var select = document.createElement('select');
if (arguments.length == 1) {
var arr = arguments[0];
for (var i in arr) {
var opt = document.createElement('option');
opt.innerHTML = i;
opt.setAttribute('value', arr[i]);
select.appendChild(opt);
}
} else {
for (var i = 0; i < arguments.length; i++) {
var opt = document.createElement('option');
opt.innerHTML = arguments[i];
opt.setAttribute('value', arguments[i]);
select.appendChild(opt);
}
}
var _this = this;
var select = document.createElement('select');
if (arguments.length == 1) {
var arr = arguments[0];
for (var i in arr) {
var opt = document.createElement('option');
opt.innerHTML = i;
opt.setAttribute('value', arr[i]);
select.appendChild(opt);
}
} else {
for (var i = 0; i < arguments.length; i++) {
var opt = document.createElement('option');
opt.innerHTML = arguments[i];
opt.setAttribute('value', arguments[i]);
select.appendChild(opt);
}
}
select.addEventListener('change', function() {
_this.setValue(this.value);
if (_this.finishChangeFunction != null) {
_this.finishChangeFunction.call(this, _this.getValue());
}
});
_this.domElement.appendChild(select);
return this;
select.addEventListener('change', function() {
_this.setValue(this.value);
if (_this.finishChangeFunction != null) {
_this.finishChangeFunction.call(this, _this.getValue());
}
});
_this.domElement.appendChild(select);
return this;
}

View File

@ -1,6 +1,6 @@
GUI.NumberController = function() {
this.type = "number";
this.type = "number";
GUI.Controller.apply(this, arguments);
@ -19,11 +19,11 @@ GUI.NumberController = function() {
var step = arguments[5];
if (!step) {
if (min != undefined && max != undefined) {
step = (max-min)*0.01;
} else {
step = 1;
}
if (min != undefined && max != undefined) {
step = (max-min)*0.01;
} else {
step = 1;
}
}
var numberField = document.createElement('input');
@ -38,113 +38,113 @@ GUI.NumberController = function() {
var slider;
if (min != undefined && max != undefined) {
slider = new GUI.Slider(this, min, max, step, this.getValue());
this.domElement.appendChild(slider.domElement);
slider = new GUI.Slider(this, min, max, step, this.getValue());
this.domElement.appendChild(slider.domElement);
}
numberField.addEventListener('blur', function(e) {
var val = parseFloat(this.value);
console.log(val);
if (!isNaN(val)) {
_this.setValue(val);
_this.setValue(val);
}
}, false);
numberField.addEventListener('mousewheel', function(e) {
e.preventDefault();
_this.setValue(_this.getValue() + Math.abs(e.wheelDeltaY)/e.wheelDeltaY*step);
return false;
e.preventDefault();
_this.setValue(_this.getValue() + Math.abs(e.wheelDeltaY)/e.wheelDeltaY*step);
return false;
}, false);
numberField.addEventListener('mousedown', function(e) {
py = y = e.pageY;
clickedNumberField = true;
clickedNumberField = true;
document.addEventListener('mousemove', dragNumberField, false);
document.addEventListener('mouseup', mouseup, false);
document.addEventListener('mouseup', mouseup, false);
}, false);
// Handle up arrow and down arrow
numberField.addEventListener('keydown', function(e) {
switch(e.keyCode) {
case 38: // up
var newVal = _this.getValue() + step;
_this.setValue(newVal);
break;
case 40: // down
var newVal = _this.getValue() - step;
_this.setValue(newVal);
break;
}
}, false);
// Handle up arrow and down arrow
numberField.addEventListener('keydown', function(e) {
switch(e.keyCode) {
case 38: // up
var newVal = _this.getValue() + step;
_this.setValue(newVal);
break;
case 40: // down
var newVal = _this.getValue() - step;
_this.setValue(newVal);
break;
}
}, false);
var mouseup = function(e) {
document.removeEventListener('mousemove', dragNumberField, false);
GUI.makeSelectable(_this.parent.domElement);
GUI.makeSelectable(numberField);
if (clickedNumberField && !draggedNumberField) {
numberField.focus();
numberField.select();
numberField.focus();
numberField.select();
}
draggedNumberField = false;
clickedNumberField = false;
if (_this.finishChangeFunction != null) {
_this.finishChangeFunction.call(this, _this.getValue());
}
document.removeEventListener('mouseup', mouseup, false);
}
if (_this.finishChangeFunction != null) {
_this.finishChangeFunction.call(this, _this.getValue());
}
document.removeEventListener('mouseup', mouseup, false);
}
var dragNumberField = function(e) {
draggedNumberField = true;
e.preventDefault();
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.
// 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.
GUI.makeUnselectable(_this.parent.domElement);
GUI.makeUnselectable(numberField);
GUI.makeUnselectable(_this.parent.domElement);
GUI.makeUnselectable(numberField);
py = y;
y = e.pageY;
var dy = py - y;
var newVal = _this.getValue() + dy*step;
_this.setValue(newVal);
return false;
py = y;
y = e.pageY;
var dy = py - y;
var newVal = _this.getValue() + dy*step;
_this.setValue(newVal);
return false;
}
this.options = function() {
_this.noSlider();
_this.domElement.removeChild(numberField);
return GUI.Controller.prototype.options.apply(this, arguments);
_this.noSlider();
_this.domElement.removeChild(numberField);
return GUI.Controller.prototype.options.apply(this, arguments);
};
this.noSlider = function() {
if (slider) {
_this.domElement.removeChild(slider.domElement);
}
return this;
if (slider) {
_this.domElement.removeChild(slider.domElement);
}
return this;
};
this.setValue = function(val) {
val = parseFloat(val);
val = parseFloat(val);
if (min != undefined && val <= min) {
val = min;
} else if (max != undefined && val >= max) {
val = max;
}
if (min != undefined && val <= min) {
val = min;
} else if (max != undefined && val >= max) {
val = max;
}
return GUI.Controller.prototype.setValue.call(this, val);
return GUI.Controller.prototype.setValue.call(this, val);
}
this.updateDisplay = function() {
numberField.value = GUI.roundToDecimal(_this.getValue(), 4);
if (slider) slider.value = _this.getValue();
}
}
};
GUI.extendController(GUI.NumberController);

View File

@ -1,8 +1,8 @@
GUI.StringController = function() {
this.type = "string";
this.type = "string";
var _this = this;
var _this = this;
GUI.Controller.apply(this, arguments);
var input = document.createElement('input');
@ -13,31 +13,31 @@ GUI.StringController = function() {
input.setAttribute('spellcheck', 'false');
this.domElement.addEventListener('mouseup', function() {
input.focus();
input.select();
input.focus();
input.select();
}, false);
// TODO: getting messed up on ctrl a
input.addEventListener('keyup', function(e) {
if (e.keyCode == 13 && _this.finishChangeFunction != null) {
_this.finishChangeFunction.call(this, _this.getValue());
}
if (e.keyCode == 13 && _this.finishChangeFunction != null) {
_this.finishChangeFunction.call(this, _this.getValue());
}
_this.setValue(input.value);
}, false);
input.addEventListener('blur', function() {
if (_this.finishChangeFunction != null) {
_this.finishChangeFunction.call(this, _this.getValue());
}
if (_this.finishChangeFunction != null) {
_this.finishChangeFunction.call(this, _this.getValue());
}
}, false);
this.updateDisplay = function() {
input.value = _this.getValue();
input.value = _this.getValue();
}
this.options = function() {
_this.domElement.removeChild(input);
return GUI.Controller.prototype.options.apply(this, arguments);
_this.domElement.removeChild(input);
return GUI.Controller.prototype.options.apply(this, arguments);
};
this.domElement.appendChild(input);

View File

@ -1,69 +1,69 @@
GUI.Slider = function(numberController, min, max, step, initValue) {
var min = min;
var max = max;
var step = step;
var min = min;
var max = max;
var step = step;
var clicked = false;
var _this = this;
var clicked = false;
var _this = this;
var x, px;
var x, px;
this.domElement = document.createElement('div');
this.domElement.setAttribute('class', 'guidat-slider-bg');
this.domElement = document.createElement('div');
this.domElement.setAttribute('class', 'guidat-slider-bg');
this.fg = document.createElement('div');
this.fg.setAttribute('class', 'guidat-slider-fg');
this.fg = document.createElement('div');
this.fg.setAttribute('class', 'guidat-slider-fg');
this.domElement.appendChild(this.fg);
this.domElement.appendChild(this.fg);
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];
}
}
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 = GUI.map(e, min, max, 0, 100);
this.fg.style.width = pct+"%";
});
this.__defineSetter__('value', function(e) {
var pct = GUI.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 = GUI.map(e.pageX, pos[0], pos[0] + _this.domElement.offsetWidth, min, max);
val = Math.round(val/step)*step;
numberController.setValue(val);
}
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);
}
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);
document.addEventListener('mouseup', mouseup, false);
}, false);
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);
document.addEventListener('mouseup', mouseup, false);
}, 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);
};
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;
}

924
gui.js

File diff suppressed because it is too large Load Diff