Merge branch 'master' of github.com:jonobr1/GUI-DAT

This commit is contained in:
jonobr1 2011-01-24 23:16:08 -08:00
commit c73deb8f41
3 changed files with 50 additions and 9 deletions

View File

@ -9,15 +9,30 @@ var NumberController = function() {
var _this = this; 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 y = py = 0;
var min = arguments[2]; var min = arguments[2];
var max = arguments[3]; var max = arguments[3];
var step = arguments[4] || (max - min) * 0.01; var step = arguments[4];
if (!step) {
if (min && max) {
step = (max-min)*0.01;
} else {
step = 1;
}
}
var numberField = document.createElement('input'); var numberField = document.createElement('input');
numberField.setAttribute('id', this.propertyName); numberField.setAttribute('id', this.propertyName);
numberField.setAttribute('type', this.type);
// Little up and down arrows are pissing me off.
numberField.setAttribute('type', 'text');
numberField.setAttribute('value', this.getValue()); numberField.setAttribute('value', this.getValue());
if (step) numberField.setAttribute('step', step); if (step) numberField.setAttribute('step', step);
@ -35,9 +50,6 @@ var NumberController = function() {
slider.setAttribute('min', min); slider.setAttribute('min', min);
slider.setAttribute('max', max); slider.setAttribute('max', max);
numberField.setAttribute('min', min);
numberField.setAttribute('max', max);
slider.setAttribute('step', step); slider.setAttribute('step', step);
slider.addEventListener('change', function(e) { slider.addEventListener('change', function(e) {
updateValue(this.value); updateValue(this.value);
@ -60,6 +72,7 @@ var NumberController = function() {
numberField.addEventListener('mousedown', function(e) { numberField.addEventListener('mousedown', function(e) {
py = y = e.pageY; py = y = e.pageY;
clickedNumberField = true;
document.addEventListener('mousemove', dragNumberField, false); document.addEventListener('mousemove', dragNumberField, false);
}, false); }, false);
@ -67,6 +80,12 @@ var NumberController = function() {
document.removeEventListener('mousemove', dragNumberField, false); document.removeEventListener('mousemove', dragNumberField, false);
_this.makeSelectable(GUI.domElement); _this.makeSelectable(GUI.domElement);
_this.makeSelectable(numberField); _this.makeSelectable(numberField);
if (clickedNumberField && !draggedNumberField) {
numberField.focus();
numberField.select();
}
draggedNumberField = false;
clickedNumberField = false;
}, false); }, false);
if(navigator.appVersion.indexOf('chrome') != -1) { if(navigator.appVersion.indexOf('chrome') != -1) {
@ -76,18 +95,27 @@ var NumberController = function() {
} }
var dragNumberField = function(e) { var dragNumberField = function(e) {
draggedNumberField = true;
e.preventDefault(); 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(GUI.domElement);
_this.makeUnselectable(numberField); _this.makeUnselectable(numberField);
py = y; py = y;
y = e.pageY; y = e.pageY;
var dy = py - y; var dy = py - y;
var newVal = _this.getValue() + dy*step; var newVal = _this.getValue() + dy*step;
updateValue(newVal); updateValue(newVal);
return false; return false;
} }
var updateValue = function(val) { var updateValue = function(val) {
val = parseFloat(val);
if (min && val <= min) { if (min && val <= min) {
val = min; val = min;
} else if (max && val >= max) { } else if (max && val >= max) {

14
gui.css
View File

@ -47,21 +47,25 @@
} }
.guidat-controller.boolean:hover, .guidat-controller.boolean:hover,
.guidat-controller.function:hover{ .guidat-controller.function:hover {
background-color: #000; background-color: #000;
} }
.guidat-controller input { .guidat-controller input {
float: right; float: right;
outline: none; outline: none;
border: 0; border: 0;
padding: 2px; padding: 2px;
} }
.guidat-controller.number { .guidat-controller.number {
border-left: 5px solid #00aeff ; border-left: 5px solid #00aeff ;
} }
.guidat-controller.string { .guidat-controller.string {
border-left: 5px solid #1ed36f; border-left: 5px solid #1ed36f;
} }
.guidat-controller.string input { .guidat-controller.string input {
border: 0; border: 0;
text-align: right; text-align: right;
@ -69,18 +73,22 @@
background-color: rgba(0,0,0,0); background-color: rgba(0,0,0,0);
} }
.guidat-controller.boolean { .guidat-controller.boolean {
border-left: 5px solid #54396e; border-left: 5px solid #54396e;
} }
.guidat-controller.function { .guidat-controller.function {
border-left: 5px solid #e61d5f; border-left: 5px solid #e61d5f;
} }
.guidat-controller.number input[type=number] {
.guidat-controller.number input[type=text] {
width: 45px; width: 45px;
margin-left: 10px; margin-left: 10px;
} }
.guidat-controller.number input[type=slider] { .guidat-controller.number input[type=slider] {
width: 45px; width: 50%;
} }

5
slider.js Normal file
View File

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