diff --git a/src/item/HitResult.js b/src/item/HitResult.js index f4a43189..73b9189f 100644 --- a/src/item/HitResult.js +++ b/src/item/HitResult.js @@ -39,7 +39,7 @@ HitResult = Base.extend(/** @lends HitResult# */{ * @property * @name HitResult#type * @type String('segment', 'handle-in', 'handle-out', 'stroke', 'fill', - * 'bounds', 'center') + * 'bounds', 'center', 'pixel') */ /** @@ -69,6 +69,15 @@ HitResult = Base.extend(/** @lends HitResult# */{ * @type CurveLocation */ + /** + * If the HitResult has a type of 'pixel', this property refers to the color + * of the pixel on the {@link Raster} that was hit. + * + * @property + * @name HitResult#color + * @type RgbColor + */ + /** * If the HitResult has a type of 'stroke', 'segment', 'handle-in' or * 'handle-out', this property refers to the Segment that was hit or that diff --git a/src/item/Raster.js b/src/item/Raster.js index 43543e5a..8630db29 100644 --- a/src/item/Raster.js +++ b/src/item/Raster.js @@ -397,6 +397,20 @@ var Raster = this.Raster = PlacedItem.extend(/** @lends Raster# */{ return this.getStrokeBounds(arguments[0]); }, + _hitTest: function(point, options) { + point = this._matrix._inverseTransform(point); + if (point.isInside(new Rectangle(this._size).setCenter(0, 0))) { + var that = this; + return new HitResult('pixel', that, { + offset: point.add(that._size.divide(2)).round(), + // Becomes HitResult#color + getColor: function() { + return that.getPixel(this.offset); + } + }); + } + }, + draw: function(ctx, param) { if (param.selection) { var bounds = new Rectangle(this._size).setCenter(0, 0);