diff --git a/demos/demo.coffee b/demos/demo.coffee index 5222473..9d8df18 100644 --- a/demos/demo.coffee +++ b/demos/demo.coffee @@ -37,6 +37,10 @@ run = -> mouseShape.x = stage.mouseX mouseShape.y = stage.mouseY + stage.onMouseUp = => + if logo + Tween.to logo, 500, { x: stage.mouseX, y: stage.mouseY } + stage.addChild someShape stage.addChild otherShape stage.addChild mouseShape diff --git a/demos/demo.js b/demos/demo.js index d2e5d06..dfcba8f 100644 --- a/demos/demo.js +++ b/demos/demo.js @@ -30,6 +30,14 @@ mouseShape.x = stage.mouseX; return mouseShape.y = stage.mouseY; }, this); + stage.onMouseUp = __bind(function() { + if (logo) { + return Tween.to(logo, 500, { + x: stage.mouseX, + y: stage.mouseY + }); + } + }, this); stage.addChild(someShape); stage.addChild(otherShape); stage.addChild(mouseShape); diff --git a/lib/canvas_lib.js b/lib/canvas_lib.js index a500421..ee2bbd4 100644 --- a/lib/canvas_lib.js +++ b/lib/canvas_lib.js @@ -588,10 +588,16 @@ Stage = (function() { } }; Stage.prototype.handleCanvasMouseDown = function(event) { + if (this.onMouseDown && !this.mouseDown) { + this.onMouseDown(); + } return this.mouseDown = true; }; Stage.prototype.handleCanvasMouseUp = function(event) { - return this.mouseUp = false; + if (this.onMouseUp && this.mouseDown) { + this.onMouseUp(); + } + return this.mouseDown = false; }; Stage.prototype.mouseHasMoved = function() { return this.oldMouseX !== this.mouseX || this.oldMouseY !== this.mouseY; diff --git a/lib/stage.js b/lib/stage.js index cbc5abe..33ea626 100644 --- a/lib/stage.js +++ b/lib/stage.js @@ -153,10 +153,16 @@ Stage = (function() { } }; Stage.prototype.handleCanvasMouseDown = function(event) { + if (this.onMouseDown && !this.mouseDown) { + this.onMouseDown(); + } return this.mouseDown = true; }; Stage.prototype.handleCanvasMouseUp = function(event) { - return this.mouseUp = false; + if (this.onMouseUp && this.mouseDown) { + this.onMouseUp(); + } + return this.mouseDown = false; }; Stage.prototype.mouseHasMoved = function() { return this.oldMouseX !== this.mouseX || this.oldMouseY !== this.mouseY; diff --git a/src/stage.coffee b/src/stage.coffee index a8dc9ee..a6a29b5 100644 --- a/src/stage.coffee +++ b/src/stage.coffee @@ -133,10 +133,12 @@ class Stage @onMouseMove() if @onMouseMove handleCanvasMouseDown: (event) -> + @onMouseDown() if @onMouseDown && !@mouseDown @mouseDown = true handleCanvasMouseUp: (event) -> - @mouseUp = false + @onMouseUp() if @onMouseUp && @mouseDown + @mouseDown = false mouseHasMoved: -> (@oldMouseX != @mouseX || @oldMouseY != @mouseY)