Skip to content

Commit

Permalink
fixed mouseup & down events for canvas + added a simple demo for mous…
Browse files Browse the repository at this point in the history
…e usage
  • Loading branch information
dkln committed Jan 23, 2011
1 parent 07cac67 commit da783dc
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 3 deletions.
4 changes: 4 additions & 0 deletions demos/demo.coffee
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions demos/demo.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion lib/canvas_lib.js
Expand Up @@ -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;
Expand Down
8 changes: 7 additions & 1 deletion lib/stage.js
Expand Up @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion src/stage.coffee
Expand Up @@ -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)
Expand Down

0 comments on commit da783dc

Please sign in to comment.