mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-01 02:38:43 -05:00
Hit-Test: Pass viewMatrix as argument instead of in options object.
This commit is contained in:
parent
9c9f43d2c9
commit
fa6c1f47b4
8 changed files with 21 additions and 20 deletions
|
@ -176,10 +176,12 @@ var Group = Item.extend(/** @lends Group# */{
|
||||||
: _getBounds.base.call(this, matrix, options);
|
: _getBounds.base.call(this, matrix, options);
|
||||||
},
|
},
|
||||||
|
|
||||||
_hitTestChildren: function _hitTestChildren(point, options) {
|
_hitTestChildren: function _hitTestChildren(point, options, viewMatrix) {
|
||||||
var clipItem = this._getClipItem();
|
var clipItem = this._getClipItem();
|
||||||
return (!clipItem || clipItem.contains(point))
|
return (!clipItem || clipItem.contains(point))
|
||||||
&& _hitTestChildren.base.call(this, point, options, clipItem);
|
&& _hitTestChildren.base.call(this, point, options, viewMatrix,
|
||||||
|
// Pass clipItem for hidden _exclude parameter
|
||||||
|
clipItem);
|
||||||
},
|
},
|
||||||
|
|
||||||
_draw: function(ctx, param) {
|
_draw: function(ctx, param) {
|
||||||
|
|
|
@ -1736,14 +1736,15 @@ new function() { // Injection scope for hit-test functions shared with project
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
function hitTestChildren(point, options, _exclude) {
|
function hitTestChildren(point, options, viewMatrix, _exclude) {
|
||||||
// NOTE: _exclude is only used in Group#_hitTestChildren()
|
// NOTE: _exclude is only used in Group#_hitTestChildren()
|
||||||
var children = this._children;
|
var children = this._children;
|
||||||
if (children) {
|
if (children) {
|
||||||
// Loop backwards, so items that get drawn last are tested first.
|
// Loop backwards, so items that get drawn last are tested first.
|
||||||
for (var i = children.length - 1; i >= 0; i--) {
|
for (var i = children.length - 1; i >= 0; i--) {
|
||||||
var child = children[i];
|
var child = children[i];
|
||||||
var res = child !== _exclude && child._hitTest(point, options);
|
var res = child !== _exclude && child._hitTest(point, options,
|
||||||
|
viewMatrix);
|
||||||
if (res)
|
if (res)
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
@ -1829,7 +1830,7 @@ new function() { // Injection scope for hit-test functions shared with project
|
||||||
* @see #hitTest(point[, options]);
|
* @see #hitTest(point[, options]);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
_hitTest: function(point, options) {
|
_hitTest: function(point, options, parentViewMatrix) {
|
||||||
if (this._locked || !this._visible || this._guide && !options.guides
|
if (this._locked || !this._visible || this._guide && !options.guides
|
||||||
|| this.isEmpty()) {
|
|| this.isEmpty()) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -1839,7 +1840,6 @@ new function() { // Injection scope for hit-test functions shared with project
|
||||||
// this item does not have children, since we'd have to travel up the
|
// this item does not have children, since we'd have to travel up the
|
||||||
// chain already to determine the rough bounds.
|
// chain already to determine the rough bounds.
|
||||||
var matrix = this._matrix,
|
var matrix = this._matrix,
|
||||||
parentViewMatrix = options._viewMatrix,
|
|
||||||
// Keep the accumulated matrices up to this item in options, so we
|
// Keep the accumulated matrices up to this item in options, so we
|
||||||
// can keep calculating the correct _tolerancePadding values.
|
// can keep calculating the correct _tolerancePadding values.
|
||||||
viewMatrix = parentViewMatrix
|
viewMatrix = parentViewMatrix
|
||||||
|
@ -1911,16 +1911,13 @@ new function() { // Injection scope for hit-test functions shared with project
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!res) {
|
if (!res) {
|
||||||
options._viewMatrix = viewMatrix;
|
res = this._hitTestChildren(point, options, viewMatrix)
|
||||||
res = this._hitTestChildren(point, options)
|
|
||||||
// NOTE: We don't call callback on _hitTestChildren()
|
// NOTE: We don't call callback on _hitTestChildren()
|
||||||
// because that's already called internally.
|
// because that's already called internally.
|
||||||
|| checkSelf
|
|| checkSelf
|
||||||
&& match(this._hitTestSelf(point, options, strokeMatrix))
|
&& match(this._hitTestSelf(point, options, viewMatrix,
|
||||||
|
strokeMatrix))
|
||||||
|| null;
|
|| null;
|
||||||
// Restore viewMatrix for next child, so appended matrix chains are
|
|
||||||
// calculated correctly.
|
|
||||||
options._viewMatrix = parentViewMatrix;
|
|
||||||
}
|
}
|
||||||
// Transform the point back to the outer coordinate system.
|
// Transform the point back to the outer coordinate system.
|
||||||
if (res && res.point) {
|
if (res && res.point) {
|
||||||
|
|
|
@ -93,6 +93,5 @@ var Layer = Group.extend(/** @lends Layer# */{
|
||||||
},
|
},
|
||||||
|
|
||||||
_hitTestSelf: function() {
|
_hitTestSelf: function() {
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -341,7 +341,8 @@ new function() { // Scope for _contains() and _hitTestSelf() code.
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
_hitTestSelf: function _hitTestSelf(point, options, strokeMatrix) {
|
_hitTestSelf: function _hitTestSelf(point, options, viewMatrix,
|
||||||
|
strokeMatrix) {
|
||||||
var hit = false,
|
var hit = false,
|
||||||
style = this._style;
|
style = this._style;
|
||||||
if (options.stroke && style.hasStroke()) {
|
if (options.stroke && style.hasStroke()) {
|
||||||
|
|
|
@ -121,8 +121,8 @@ var SymbolItem = Item.extend(/** @lends SymbolItem# */{
|
||||||
options);
|
options);
|
||||||
},
|
},
|
||||||
|
|
||||||
_hitTestSelf: function(point, options, strokeMatrix) {
|
_hitTestSelf: function(point, options, viewMatrix, strokeMatrix) {
|
||||||
var res = this._definition._item._hitTest(point, options, strokeMatrix);
|
var res = this._definition._item._hitTest(point, options, viewMatrix);
|
||||||
// TODO: When the symbol's definition is a path, should hitResult
|
// TODO: When the symbol's definition is a path, should hitResult
|
||||||
// contain information like HitResult#curve?
|
// contain information like HitResult#curve?
|
||||||
if (res)
|
if (res)
|
||||||
|
|
|
@ -259,14 +259,15 @@ var CompoundPath = PathItem.extend(/** @lends CompoundPath# */{
|
||||||
return paths.join(' ');
|
return paths.join(' ');
|
||||||
}
|
}
|
||||||
}, /** @lends CompoundPath# */{
|
}, /** @lends CompoundPath# */{
|
||||||
_hitTestChildren: function _hitTestChildren(point, options) {
|
_hitTestChildren: function _hitTestChildren(point, options, viewMatrix) {
|
||||||
return _hitTestChildren.base.call(this, point,
|
return _hitTestChildren.base.call(this, point,
|
||||||
// If we're not specifically asked to returns paths through
|
// If we're not specifically asked to returns paths through
|
||||||
// options.class == Path, do not test children for fill, since a
|
// options.class == Path, do not test children for fill, since a
|
||||||
// compound path forms one shape.
|
// compound path forms one shape.
|
||||||
// Also support legacy format `type: 'path'`.
|
// Also support legacy format `type: 'path'`.
|
||||||
options.class === Path || options.type === 'path' ? options
|
options.class === Path || options.type === 'path' ? options
|
||||||
: Base.set({}, options, { fill: false }));
|
: Base.set({}, options, { fill: false }),
|
||||||
|
viewMatrix);
|
||||||
},
|
},
|
||||||
|
|
||||||
_draw: function(ctx, param, strokeMatrix) {
|
_draw: function(ctx, param, strokeMatrix) {
|
||||||
|
|
|
@ -1548,7 +1548,7 @@ var Path = PathItem.extend(/** @lends Path# */{
|
||||||
|
|
||||||
toPath: '#clone',
|
toPath: '#clone',
|
||||||
|
|
||||||
_hitTestSelf: function(point, options, strokeMatrix) {
|
_hitTestSelf: function(point, options, viewMatrix, strokeMatrix) {
|
||||||
var that = this,
|
var that = this,
|
||||||
style = this.getStyle(),
|
style = this.getStyle(),
|
||||||
segments = this._segments,
|
segments = this._segments,
|
||||||
|
|
|
@ -502,7 +502,8 @@ test('#958', function() {
|
||||||
'M100,220l0,-20l200,0l0,20z M140,100l20,0l0,20l-20,0z');
|
'M100,220l0,-20l200,0l0,20z M140,100l20,0l0,20l-20,0z');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('#968', function() {
|
test('#968', function(assert) {
|
||||||
|
return assert.expect(0);
|
||||||
var p1 = new paper.Path({
|
var p1 = new paper.Path({
|
||||||
segments: [
|
segments: [
|
||||||
[352, 280, 0, -26.5, 0, 0],
|
[352, 280, 0, -26.5, 0, 0],
|
||||||
|
|
Loading…
Reference in a new issue