Skip to content

Commit

Permalink
rewrote intersects method, which now leverages the new getIntersectio…
Browse files Browse the repository at this point in the history
…n method. fixed up unit tests. also fixed bug with getIntersection method
  • Loading branch information
ericdrowell committed Aug 19, 2012
1 parent f944409 commit e19dae3
Show file tree
Hide file tree
Showing 6 changed files with 136 additions and 141 deletions.
23 changes: 10 additions & 13 deletions dist/kinetic-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -3048,18 +3048,15 @@ Kinetic.Stage = Kinetic.Container.extend({

return {
shape: shape,
pixels: p
pixel: p
};
}
// if no shape mapped to that pixel, return pixel array
else if(p[0] > 0 || p[1] > 0 || p[2] > 0 || p[3] > 0) {
return {
pixels: p
pixel: p
};
}
else {
return null;
}
}

return null;
Expand Down Expand Up @@ -3157,7 +3154,7 @@ Kinetic.Stage = Kinetic.Container.extend({
if(obj) {
var shape = obj.shape;
if(shape) {
if(!go.drag.moving && obj.pixels[3] === 255 && (!this.targetShape || this.targetShape._id !== shape._id)) {
if(!go.drag.moving && obj.pixel[3] === 255 && (!this.targetShape || this.targetShape._id !== shape._id)) {
if(this.targetShape) {
this.targetShape._handleEvent('mouseout', evt, shape);
}
Expand Down Expand Up @@ -4100,11 +4097,11 @@ Kinetic.Shape = Kinetic.Node.extend({
intersects: function() {
var pos = Kinetic.Type._getXY(Array.prototype.slice.call(arguments));
var stage = this.getStage();

// TODO: need to re-implement

// default
return false;
var bufferCanvas = stage.bufferCanvas;
bufferCanvas.clear();
this._draw(bufferCanvas);
var obj = stage.getIntersection(pos);
return !!(obj && obj.pixel[3] > 0);
},
_draw: function(canvas) {
if(this.attrs.drawFunc) {
Expand Down Expand Up @@ -4158,7 +4155,7 @@ Kinetic.Shape = Kinetic.Node.extend({
this.attrs[key] = '';
}

// image is a special case
// image is a special case
if('image' in this.attrs) {
attrs.image = this.attrs.image;

Expand All @@ -4182,7 +4179,7 @@ Kinetic.Shape = Kinetic.Node.extend({
var key = bothLists[n];
this.attrs[key] = attrs[key];
}

// image is a special case
this.attrs.image = attrs.image;
}
Expand Down
4 changes: 2 additions & 2 deletions dist/kinetic-core.min.js

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions src/Shape.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,11 +313,11 @@ Kinetic.Shape = Kinetic.Node.extend({
intersects: function() {
var pos = Kinetic.Type._getXY(Array.prototype.slice.call(arguments));
var stage = this.getStage();

// TODO: need to re-implement

// default
return false;
var bufferCanvas = stage.bufferCanvas;
bufferCanvas.clear();
this._draw(bufferCanvas);
var obj = stage.getIntersection(pos);
return !!(obj && obj.pixel[3] > 0);
},
_draw: function(canvas) {
if(this.attrs.drawFunc) {
Expand Down Expand Up @@ -371,7 +371,7 @@ Kinetic.Shape = Kinetic.Node.extend({
this.attrs[key] = '';
}

// image is a special case
// image is a special case
if('image' in this.attrs) {
attrs.image = this.attrs.image;

Expand All @@ -395,7 +395,7 @@ Kinetic.Shape = Kinetic.Node.extend({
var key = bothLists[n];
this.attrs[key] = attrs[key];
}

// image is a special case
this.attrs.image = attrs.image;
}
Expand Down
9 changes: 3 additions & 6 deletions src/Stage.js
Original file line number Diff line number Diff line change
Expand Up @@ -369,18 +369,15 @@ Kinetic.Stage = Kinetic.Container.extend({

return {
shape: shape,
pixels: p
pixel: p
};
}
// if no shape mapped to that pixel, return pixel array
else if(p[0] > 0 || p[1] > 0 || p[2] > 0 || p[3] > 0) {
return {
pixels: p
pixel: p
};
}
else {
return null;
}
}

return null;
Expand Down Expand Up @@ -478,7 +475,7 @@ Kinetic.Stage = Kinetic.Container.extend({
if(obj) {
var shape = obj.shape;
if(shape) {
if(!go.drag.moving && obj.pixels[3] === 255 && (!this.targetShape || this.targetShape._id !== shape._id)) {
if(!go.drag.moving && obj.pixel[3] === 255 && (!this.targetShape || this.targetShape._id !== shape._id)) {
if(this.targetShape) {
this.targetShape._handleEvent('mouseout', evt, shape);
}
Expand Down
5 changes: 5 additions & 0 deletions tests/js/manualTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,11 @@ Test.prototype.tests = {
layer.add(greenEllipse);

stage.add(layer);

//greenEllipse.hide();
layer.draw();

//document.body.appendChild(layer.bufferCanvas.element);
},
'EVENTS - move mouse from shape in one group to shape in another group': function(containerId) {
var stage = new Kinetic.Stage({
Expand Down
Loading

0 comments on commit e19dae3

Please sign in to comment.