diff --git a/src/item/Item.js b/src/item/Item.js index 7ea0be97..ae3c9a4d 100644 --- a/src/item/Item.js +++ b/src/item/Item.js @@ -1276,6 +1276,27 @@ var Item = this.Item = Base.extend(Callback, { return raster; }, + // DOCS: Document Item#contains(point) + /** + * Checks wether the item's geometry contains the given point in local + * coordinates. + * + * @param {Point} point The point to check in local coordinates + */ + contains: function(point) { + point = Point.read(arguments); + if (this._children) { + for (var i = this._children.length - 1; i >= 0; i--) { + if (this._children[i].contains(point)) + return true; + } + return false; + } + // We only implement it here for items with rectangular content, + // for anything else we need to override #contains() + return point.isInside(this._getBounds('getBounds')); + }, + /** * Perform a hit test on the item (and its children, if it is a * {@link Group} or {@link Layer}) at the location of the specified point. diff --git a/src/item/Raster.js b/src/item/Raster.js index d5b0f498..9f6f8fa6 100644 --- a/src/item/Raster.js +++ b/src/item/Raster.js @@ -523,7 +523,7 @@ var Raster = this.Raster = Item.extend(/** @lends Raster# */{ }, _hitTest: function(point, options) { - if (point.isInside(this._getBounds())) { + if (this.contains(point)) { var that = this; return new HitResult('pixel', that, { offset: point.add(that._size.divide(2)).round(), diff --git a/src/item/Shape.js b/src/item/Shape.js index 9d42cc9f..9909e52c 100644 --- a/src/item/Shape.js +++ b/src/item/Shape.js @@ -65,15 +65,20 @@ var Shape = this.Shape = Item.extend(/** @lends Shape# */{ } }, + contains: function(point) { + point = Point.read(arguments); + // TODO: Implement. + }, + _getBounds: function(getter, matrix) { var rect = new Rectangle(this._size).setCenter(0, 0); return matrix ? matrix._transformBounds(rect) : rect; }, _hitTest: function(point, options) { - // TODO: Implement! - if (point.isInside(this._getBounds())) { - } + if (this.hasFill() && this.contains(point)) + return new HitResult('fill', this); + // TODO: Implement stokre! }, statics: { diff --git a/src/path/Path.js b/src/path/Path.js index 12b6bc0b..98420041 100644 --- a/src/path/Path.js +++ b/src/path/Path.js @@ -1604,6 +1604,7 @@ var Path = this.Path = PathItem.extend(/** @lends Path# */{ && this._parent._style.getFillColor()); }, + // DOCS: Document Path#contains() contains: function(point) { point = Point.read(arguments); // If the path is not closed, we should not bail out in case it has a