NumberController works-ish

This commit is contained in:
jonobr1 2011-01-23 16:15:04 -08:00
parent 2e942df08b
commit 9100b13e1c
3 changed files with 27 additions and 31 deletions

View File

@ -1,5 +1,6 @@
var Controller = function() { var Controller = function() {
this.domElement; this.domElement = document.createElement('div');
this.domElement.setAttribute('class', 'guidat-controller');
this.object = arguments[0]; this.object = arguments[0];
this.propertyName = arguments[1]; this.propertyName = arguments[1];
@ -8,8 +9,10 @@ var Controller = function() {
var NumberController = function() { var NumberController = function() {
Controller.apply(this, arguments); Controller.apply(this, arguments);
this.isClicked = false;
var _this = this;
this.isClicked = false;
this.py = this.y = 0; this.py = this.y = 0;
// TODO pass argument to inc // TODO pass argument to inc
this.inc = 0; this.inc = 0;
@ -19,33 +22,28 @@ var NumberController = function() {
this.button.setAttribute('id', this.propertyName); this.button.setAttribute('id', this.propertyName);
this.button.setAttribute('type', 'number'); this.button.setAttribute('type', 'number');
this.button.setAttribute('value', this.y); this.button.setAttribute('value', this.y);
this.domElement.appendChild(this.button);
// return this.button; this.button.onmousedown = function(e) {
_this.isClicked = true;
this.addListeners = function() {
this.onmousedown = function(e) {
this.isClicked = true;
}; };
document.onmouseup = function(e) { document.onmouseup = function(e) {
this.isClicked = false; _this.isClicked = false;
}; };
document.onmousemove = function(e) { document.onmousemove = function(e) {
if(this.isClicked) {
this.py = this.y; if(_this.isClicked) {
var dy = this.y - this.py;
_this.py = _this.y;
_this.y = e.offsetY;
var dy = _this.y - _this.py;
if(dy > 0) if(dy > 0)
this.button.setAttribute('value', this.inc++); _this.button.setAttribute('value', _this.inc++);
else else
this.button.setAttribute('value', this.inc--); _this.button.setAttribute('value', _this.inc--);
this.y = e.offsetY;
} }
}; };
};
this.__defineGetter__("button", function(){
return this.button;
});
}; };
NumberController.prototype = new Controller(); NumberController.prototype = new Controller();

View File

@ -1,6 +1,7 @@
<html> <html>
<head> <head>
<link href="gui.css" media="screen" rel="stylesheet" type="text/css" /> <link href="gui.css" media="screen" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="controller.js"></script>
<script type="text/javascript" src="gui.js"></script> <script type="text/javascript" src="gui.js"></script>
<script type="text/javascript"> <script type="text/javascript">

5
gui.js
View File

@ -57,11 +57,8 @@ var GUI = new function() {
var addHandlers = { var addHandlers = {
"number": function() { "number": function() {
var n = new NumberController(arguments); var n = new NumberController(arguments);
n.addListeners(); return n;
return n.button;
// return n.button;
}, },
"string": function() { "string": function() {