diff --git a/controller.js b/controller.js new file mode 100644 index 0000000..38a14fc --- /dev/null +++ b/controller.js @@ -0,0 +1,52 @@ +var Controller = function() { + this.domElement; + + this.object = arguments[0]; + this.propertyName = arguments[1]; +}; + +var NumberController = function() { + + Controller.apply(this, arguments); + this.isClicked = false; + + this.py = this.y = 0; + // TODO pass argument to inc + this.inc = 0; + this.button; + + this.button = document.createElement('input'); + this.button.setAttribute('id', this.propertyName); + this.button.setAttribute('type', 'number'); + this.button.setAttribute('value', this.y); + + // return this.button; + + this.addListeners = function() { + + this.onmousedown = function(e) { + this.isClicked = true; + }; + document.onmouseup = function(e) { + this.isClicked = false; + }; + document.onmousemove = function(e) { + if(this.isClicked) { + this.py = this.y; + var dy = this.y - this.py; + if(dy > 0) + this.button.setAttribute('value', this.inc++); + else + this.button.setAttribute('value', this.inc--); + this.y = e.offsetY; + } + }; + }; + + this.__defineGetter__("button", function(){ + return this.button; + }); +}; + +NumberController.prototype = new Controller(); +NumberController.prototype.constructor = NumberController; \ No newline at end of file diff --git a/gui.js b/gui.js index 16e1ae9..050d6ff 100644 --- a/gui.js +++ b/gui.js @@ -57,7 +57,11 @@ var GUI = new function() { var addHandlers = { "number": function() { - // + + var n = new NumberController(arguments); + n.addListeners(); + return n.button; + // return n.button; }, "string": function() { diff --git a/proto/draggable-button.html b/proto/draggable-button.html index a3fe807..225dd41 100644 --- a/proto/draggable-button.html +++ b/proto/draggable-button.html @@ -1,16 +1,29 @@