Merged into Jono's new index.html

This commit is contained in:
George Michael Brower 2011-01-25 01:26:18 -07:00
commit a559aa20e5
8 changed files with 63 additions and 300 deletions

View File

@ -1,25 +0,0 @@
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;

View File

@ -1,12 +0,0 @@
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;

View File

@ -1,42 +0,0 @@
var Controller = function() {
this.setName = function(n) {
this.propertyNameElement.innerHTML = n;
}
this.setValue = function(n) {
this.object[this.propertyName] = n;
}
this.getValue = function() {
return this.object[this.propertyName];
}
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);
};

View File

@ -1,132 +0,0 @@
// TODO: How do we intercept the press up/down event on number fields?
// TODO: Provide alternate controllers for non-html5 browsers?
// TODO: Firefox is retarded?
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 draggedNumberField.
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 && max &&
(navigator.appVersion.indexOf("chrome") != -1 || navigator.appVersion.indexOf("Safari") != -1)) {
slider = document.createElement('input');
slider.setAttribute('type', 'range');
slider.setAttribute('value', this.getValue());
slider.setAttribute('min', min);
slider.setAttribute('max', max);
slider.setAttribute('step', step);
slider.addEventListener('change', function(e) {
updateValue(this.value);
}, false);
this.domElement.appendChild(slider);
}
numberField.addEventListener('blur', function(e) {
var val = parseFloat(this.value);
if (!isNaN(val)) {
updateValue(val);
}
}, false);
numberField.addEventListener('mousewheel', function(e) {
e.preventDefault();
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);
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;
updateValue(newVal);
return false;
}
var updateValue = function(val) {
val = parseFloat(val);
if (min && val <= min) {
val = min;
} else if (max && 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;

View File

@ -1,27 +0,0 @@
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;

BIN
favicon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

View File

@ -1,57 +1,60 @@
<html> <!doctype html>
<head> <head>
<link href="gui.css" media="screen" rel="stylesheet" type="text/css" /> <title>GUI-DAT</title>
<link href="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.js"></script> <link rel="icon" type="image/ico" href="favicon.ico">
<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 id="demo" type="text/javascript">
var controllableObject =
{
numberProperty: 20,
constrainedNum: 0,
textProperty: "a string",
anotherTextProperty: "another string",
booleanProperty: false,
anotherBooleanProperty: false,
functionProperty: function() {
alert("I am a function!");
}
};
window.onload = function() { <link href="gui.css" media="screen" rel="stylesheet" type="text/css" />
<link href="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>
prettyPrint(); <script type="text/javascript" src="gui.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 id="demo" type="text/javascript">
var controllableObject =
{
numberProperty: 20,
constrainedNum: 0,
textProperty: "a string",
anotherTextProperty: "another string",
booleanProperty: false,
anotherBooleanProperty: false,
functionProperty: function() {
alert("I am a function!");
}
};
GUI.start(); window.onload = function() {
// Creates a number box prettyPrint();
GUI.add(controllableObject, "numberProperty");
// Creates a slider (min, max) GUI.start();
GUI.add(controllableObject, "constrainedNum", -100, 100)
// Creates a text field // Creates a number box
GUI.add(controllableObject, "textProperty"); GUI.add(controllableObject, "numberProperty");
// Creates a checkbox // Creates a slider (min, max)
GUI.add(controllableObject, "booleanProperty"); GUI.add(controllableObject, "constrainedNum", -100, 100)
// Creates a button // Creates a text field
GUI.add(controllableObject, "functionProperty") GUI.add(controllableObject, "textProperty");
.setName("Fire a Function");
}; // Creates a checkbox
</script> GUI.add(controllableObject, "booleanProperty");
</head>
<body> // Creates a button
<pre id="demo-pre" class="prettyprint"> GUI.add(controllableObject, "functionProperty")
.setName("Fire a Function");
};
</script>
</head>
<body>
<pre id="demo-pre" class="prettyprint">
var controllableObject = var controllableObject =
{ {
numberProperty: 20, numberProperty: 20,
@ -84,6 +87,9 @@ window.onload = function() {
.setName("Fire a Function"); .setName("Fire a Function");
}; };
</pre> </pre>
</body> <footer>
By <a href="http://georgemichaelbrower.com">George Michael Brower</a>, <a href="">Jono Brandel</a>, and <a href="https://github.com/jonobr1/GUI-DAT">you</a>.
</footer>
</body>
</html> </html>

View File

@ -1,5 +0,0 @@
var Slider = function() {
this.domElement = document.createElement('canvas');
}