diff --git a/js-lib/common.js b/js-lib/common.js index 0c2d312..ef402e7 100644 --- a/js-lib/common.js +++ b/js-lib/common.js @@ -18,7 +18,7 @@ ascii.Vector = function(x, y) { * @return {boolean} */ ascii.Vector.prototype.equals = function(other) { - return (this.x == other.x) && (this.y == other.y); + return (other != null) && (this.x == other.x) && (this.y == other.y); }; /** diff --git a/js-lib/controller.js b/js-lib/controller.js index 4626e84..f0db382 100644 --- a/js-lib/controller.js +++ b/js-lib/controller.js @@ -24,6 +24,7 @@ ascii.Controller = function(view, state) { /** @type {ascii.Vector} */ this.dragOrigin; /** @type {ascii.Vector} */ this.pressVector; + /** @type {ascii.Vector} */ this.lastMoveCell; /** @type {number} */ this.pressTimestamp; this.installDesktopBindings(); @@ -60,10 +61,14 @@ ascii.Controller.prototype.handleMove = function(position) { this.dragOrigin = this.view.offset; } - // Not dragging, so pass the mouse move on. + // Not dragging, so pass the mouse move on, but remove duplicates. if (this.dragOrigin == null && - ($.now() - this.pressTimestamp) >= DRAG_LATENCY) { + ($.now() - this.pressTimestamp) >= DRAG_LATENCY && + (this.lastMoveCell == null || + !this.view.screenToCell(position) + .equals(this.view.screenToCell(this.lastMoveCell)))) { this.stateController.handleDrawingMove(this.view.screenToCell(position)); + this.lastMoveCell = position; } // Drag in progress, update the view origin. @@ -87,6 +92,7 @@ ascii.Controller.prototype.handleRelease = function(position) { this.pressVector = null; this.pressTimestamp = 0; this.dragOrigin = null; + this.lastMoveCell = null; }; /** @@ -141,4 +147,5 @@ ascii.Controller.prototype.installTouchBindings = function() { e.originalEvent.touches[0].pageX, e.originalEvent.touches[0].pageY)); }); + // TODO: Handle pinch to zoom. }; diff --git a/js-lib/state-controller.js b/js-lib/state-controller.js index 988f81e..566e982 100644 --- a/js-lib/state-controller.js +++ b/js-lib/state-controller.js @@ -35,3 +35,4 @@ ascii.StateController.prototype.handleDrawingRelease = function(position) { ascii.StateController.prototype.handleDrawingMove = function(position) { this.state.setValue(position, 'O'); }; +