mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-20 22:39:50 -05:00
Implement standard behavior of #_hitTest() for items without children, based on #_contains().
This should cover the minimum of what's needed for PointText.
This commit is contained in:
parent
463a00bd1e
commit
fe10c99d1b
5 changed files with 18 additions and 4 deletions
|
@ -1322,6 +1322,10 @@ var Item = Base.extend(Callback, /** @lends Item# */{
|
||||||
}
|
}
|
||||||
// We only implement it here for items with rectangular content,
|
// We only implement it here for items with rectangular content,
|
||||||
// for anything else we need to override #contains()
|
// for anything else we need to override #contains()
|
||||||
|
// TODO: There currently is no caching for the results of direct calls
|
||||||
|
// to this._getBounds('getBounds') (without the application of the
|
||||||
|
// internal matrix). Performance improvements could be achieved if
|
||||||
|
// these were cached too. See #_getCachedBounds().
|
||||||
return point.isInside(this._getBounds('getBounds'));
|
return point.isInside(this._getBounds('getBounds'));
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -1420,6 +1424,8 @@ var Item = Base.extend(Callback, /** @lends Item# */{
|
||||||
var res = this._children[i].hitTest(point, options);
|
var res = this._children[i].hitTest(point, options);
|
||||||
if (res) return res;
|
if (res) return res;
|
||||||
}
|
}
|
||||||
|
} else if (this.hasFill() && this._contains(point)) {
|
||||||
|
return new HitResult('fill', this);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -81,10 +81,9 @@ var Shape = Item.extend(/** @lends Shape# */{
|
||||||
return matrix ? matrix._transformBounds(rect) : rect;
|
return matrix ? matrix._transformBounds(rect) : rect;
|
||||||
},
|
},
|
||||||
|
|
||||||
_hitTest: function(point, options) {
|
_hitTest: function _hitTest(point, options) {
|
||||||
if (this.hasFill() && this.contains(point))
|
|
||||||
return new HitResult('fill', this);
|
|
||||||
// TODO: Implement stroke!
|
// TODO: Implement stroke!
|
||||||
|
return _hitTest.base.apply(this, arguments);
|
||||||
},
|
},
|
||||||
|
|
||||||
statics: {
|
statics: {
|
||||||
|
|
|
@ -331,6 +331,7 @@ var Project = PaperScopeItem.extend(/** @lends Project# */{
|
||||||
if (item._boundsSelected) {
|
if (item._boundsSelected) {
|
||||||
// We need to call the internal _getBounds, to get non-
|
// We need to call the internal _getBounds, to get non-
|
||||||
// transformed bounds.
|
// transformed bounds.
|
||||||
|
// TODO: Implement caching for these too!
|
||||||
var coords = mx._transformCorners(
|
var coords = mx._transformCorners(
|
||||||
item._getBounds('getBounds'));
|
item._getBounds('getBounds'));
|
||||||
// Now draw a rectangle that connects the transformed
|
// Now draw a rectangle that connects the transformed
|
||||||
|
|
|
@ -12,6 +12,8 @@
|
||||||
|
|
||||||
// Register a jsDump parser for Base.
|
// Register a jsDump parser for Base.
|
||||||
QUnit.jsDump.setParser('Base', function (obj, stack) {
|
QUnit.jsDump.setParser('Base', function (obj, stack) {
|
||||||
|
// Just compare the string representation of classes inheriting from Base,
|
||||||
|
// since they hide the internal values.
|
||||||
return obj.toString();
|
return obj.toString();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -14,9 +14,15 @@ module('TextItem');
|
||||||
|
|
||||||
test('PointText', function() {
|
test('PointText', function() {
|
||||||
var text = new PointText({
|
var text = new PointText({
|
||||||
|
font: 'Arial',
|
||||||
|
fontSize: 14,
|
||||||
point: [100, 100],
|
point: [100, 100],
|
||||||
content: 'Hello World!'
|
content: 'Hello World!'
|
||||||
});
|
});
|
||||||
equals(text.point, { x: 100, y: 100 });
|
|
||||||
equals(text.fillColor, { red: 0, green: 0, blue: 0 }, 'text.fillColor should be black by default');
|
equals(text.fillColor, { red: 0, green: 0, blue: 0 }, 'text.fillColor should be black by default');
|
||||||
|
equals(text.point, { x: 100, y: 100 });
|
||||||
|
equals(text.bounds.point, { x: 100, y: 87.4 });
|
||||||
|
equals(function() {
|
||||||
|
return text.hitTest(text.bounds.center) != null;
|
||||||
|
}, true);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue