Fix a minor bug in CompoundPath#contains(), improve comments and clean up code.

This commit is contained in:
Jürg Lehni 2013-10-18 19:49:05 +02:00
parent 304ecbc3be
commit 1fc9f882ca
2 changed files with 15 additions and 12 deletions

View file

@ -1539,10 +1539,11 @@ var Item = Base.extend(Callback, /** @lends Item# */{
},
_hitTest: function(point, options) {
if (this._children) {
var children = this._children;
if (children) {
// Loop backwards, so items that get drawn last are tested first
for (var i = this._children.length - 1, res; i >= 0; i--)
if (res = this._children[i].hitTest(point, options))
for (var i = children.length - 1, res; i >= 0; i--)
if (res = children[i].hitTest(point, options))
return res;
} else if (options.fill && this.hasFill() && this._contains(point)) {
return new HitResult('fill', this);
@ -2224,6 +2225,8 @@ var Item = Base.extend(Callback, /** @lends Item# */{
* circle.fillColor = new Color(1, 0, 0);
*/
// TODO: Find a better name than selectedColor. It should also be used for
// guides, etc.
/**
* {@grouptitle Selection Style}
*

View file

@ -199,7 +199,7 @@ var CompoundPath = PathItem.extend(/** @lends CompoundPath# */{
param = Base.merge({ compound: true });
// Return early if the compound path doesn't have any children:
if (children.length === 0)
return [];
return false;
ctx.beginPath();
for (var i = 0, l = children.length; i < l; i++)
children[i]._draw(ctx, param);
@ -222,16 +222,16 @@ var CompoundPath = PathItem.extend(/** @lends CompoundPath# */{
},
_hitTest: function _hitTest(point, options) {
// Do not test children for fill, since a compound path forms one shape.
// options.compoundChildren allows to specifically do so, see below.
var res = _hitTest.base.call(this, point,
Base.merge(options, { fill: false }));
if (!res && options.fill && this.hasFill()) {
if (options.compoundChildren) {
var children = this._children;
for (var i = children.length - 1; i >= 0 && !res; i--)
res = children[i]._hitTest(point, options);
} else if (this._contains(point)) {
res = new HitResult('fill', this);
}
// If asked to query all children seperately, perform the same loop as
// Item#hitTest() now on the compound children.
if (!res && options.compoundChildren) {
var children = this._children;
for (var i = children.length - 1; i >= 0 && !res; i--)
res = children[i]._hitTest(point, options);
}
return res;
},