diff --git a/js-lib/common.js b/js-lib/common.js index fc24c29..f93389a 100644 --- a/js-lib/common.js +++ b/js-lib/common.js @@ -11,13 +11,7 @@ ascii.Position = function(x, y) { /** type {Number} */ this.y = y; }; -goog.provide('ascii.Blah'); - -/** - * @constructor - */ -ascii.Blah = function(x, y) { - /** type {Number} */ this.x = x; - /** type {Number} */ this.y = y; +ascii.Position.prototype.equals = function(other) { + return (this.x == other.x) + && (this.y == other.y); }; - diff --git a/js-lib/controller.js b/js-lib/controller.js index 624d567..557b934 100644 --- a/js-lib/controller.js +++ b/js-lib/controller.js @@ -11,29 +11,33 @@ goog.require('ascii.View'); * @constructor */ ascii.Controller = function(view) { - /** type {ascii.View} */ - this.view = view; - /** type {ascii.Position} */ - this.clickPosition; + /** type {ascii.View} */ this.view = view; + /** type {ascii.StateControler */ this.stateController; + /** type {ascii.Position} */ this.pressPosition; this.installDesktopBindings(); }; ascii.Controller.prototype.handlePress = function(x, y) { - this.clickPosition = new ascii.Position(x, y); + this.pressPosition = new ascii.Position(x, y); }; ascii.Controller.prototype.handleMove = function(x, y) { if (this.clickPosition) { // Drag has started. - this.view.offset.x -= (x - this.clickPosition.x)/this.view.zoom; - this.view.offset.y -= (y - this.clickPosition.y)/this.view.zoom; + this.view.offset.x -= (x - this.pressPosition.x)/this.view.zoom; + this.view.offset.y -= (y - this.pressPosition.y)/this.view.zoom; this.clickPosition = new ascii.Position(x, y); } }; ascii.Controller.prototype.handleRelease = function(x, y) { - this.clickPosition = null; + if (this.pressPosition.equals(new ascii.Position(x, y))) { + // We should handle this as a 'click' as there was no dragging involved. + // Hand off to the state controller, as this will initiate a modification of the diagram itself. + // TODO: Work out how to pass off work into state-controller. + } + this.pressPosition = null; }; ascii.Controller.prototype.handleZoom = function(delta) {