added support for image hit detection with new color mapping algo

This commit is contained in:
Eric Rowell
2012-08-14 23:52:53 -07:00
parent 02c6c7276f
commit bae57488cf
6 changed files with 49 additions and 41 deletions

View File

@@ -11,7 +11,7 @@ Kinetic.Plugins = {};
Kinetic.Global = {
BUBBLE_WHITELIST: ['mousedown', 'mousemove', 'mouseup', 'mouseover', 'mouseout', 'click', 'dblclick', 'touchstart', 'touchmove', 'touchend', 'tap', 'dbltap', 'dragstart', 'dragmove', 'dragend'],
BUFFER_WHITELIST: ['fill', 'stroke', 'textFill', 'textStroke'],
BUFFER_BLACKLIST: ['shadow'],
BUFFER_BLACKLIST: ['shadow', 'image'],
stages: [],
idCounter: 0,
tempNodes: {},

View File

@@ -355,7 +355,12 @@ Kinetic.Shape = Kinetic.Node.extend({
var wl = Kinetic.Global.BUFFER_WHITELIST;
var bl = Kinetic.Global.BUFFER_BLACKLIST;
var attrs = {};
if(canvas.name === 'buffer') {
if('image' in this.attrs) {
this.attrs.fill = '#' + this.colorKey;
}
for(var n = 0; n < wl.length; n++) {
var key = wl[n];
attrs[key] = this.attrs[key];
@@ -368,13 +373,14 @@ Kinetic.Shape = Kinetic.Node.extend({
attrs[key] = this.attrs[key];
this.attrs[key] = '';
}
context.globalAlpha = 1;
}
this.attrs.drawFunc.call(this, canvas.getContext());
if(canvas.name === 'buffer') {
var bothLists = wl.concat(bl);
var bothLists = wl.concat(bl);
for(var n = 0; n < bothLists.length; n++) {
var key = bothLists[n];
this.attrs[key] = attrs[key];

View File

@@ -19,16 +19,17 @@ Kinetic.Image = Kinetic.Shape.extend({
this._super(config);
},
drawFunc: function(context) {
var width = this.getWidth();
var height = this.getHeight();
context.beginPath();
context.rect(0, 0, width, height);
context.closePath();
this.fill(context);
this.stroke(context);
if(this.attrs.image) {
var width = this.getWidth();
var height = this.getHeight();
context.beginPath();
context.rect(0, 0, width, height);
context.closePath();
this.fill(context);
this.stroke(context);
context.beginPath();
// if cropping
if(this.attrs.crop && this.attrs.crop.width && this.attrs.crop.height) {
var cropX = this.attrs.crop.x ? this.attrs.crop.x : 0;