mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-19 14:10:14 -05:00
Merge branch 'master' of https://github.com/scriptographer/paper.js
This commit is contained in:
commit
ea9c9353e3
4 changed files with 29 additions and 23 deletions
|
@ -1 +1 @@
|
|||
Subproject commit b132459bef85f5cab58d9ae0732043f4c857c372
|
||||
Subproject commit 4a584d77db9af5298d35101addcde1cf1bdb7d7a
|
|
@ -71,15 +71,17 @@ var Group = this.Group = Item.extend({
|
|||
this.base();
|
||||
this._children = [];
|
||||
this._namedChildren = {};
|
||||
this._clipped = false;
|
||||
this.setChildren(!items || !Array.isArray(items)
|
||||
|| typeof items[0] !== 'object' ? arguments : items);
|
||||
},
|
||||
|
||||
clone: function() {
|
||||
var copy = this.base();
|
||||
copy._clipped = this._clipped;
|
||||
return copy;
|
||||
_getClipMask: function() {
|
||||
// TODO: Use caching once ChangeFlags.HIERARCHY is implemented
|
||||
for (var i = 0, l = this._children.length; i < l; i++) {
|
||||
var child = this._children[i];
|
||||
if (child._clipMask)
|
||||
return child;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -91,21 +93,24 @@ var Group = this.Group = Item.extend({
|
|||
* @bean
|
||||
*/
|
||||
isClipped: function() {
|
||||
return this._clipped;
|
||||
return !!this._getClipMask();
|
||||
},
|
||||
|
||||
setClipped: function(clipped) {
|
||||
this._clipped = clipped;
|
||||
var child = this.getFirstChild();
|
||||
if (child)
|
||||
child.setClipMask(clipped);
|
||||
return this;
|
||||
},
|
||||
|
||||
draw: function(ctx, param) {
|
||||
var clipMask = this._getClipMask();
|
||||
if (clipMask)
|
||||
Item.draw(clipMask, ctx, param);
|
||||
for (var i = 0, l = this._children.length; i < l; i++) {
|
||||
// the group is clipped on its first child
|
||||
param.clip = this._clipped && i == 0;
|
||||
Item.draw(this._children[i], ctx, param);
|
||||
var item = this._children[i];
|
||||
if (item != clipMask)
|
||||
Item.draw(item, ctx, param);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -85,21 +85,22 @@ var Item = this.Item = Base.extend({
|
|||
},
|
||||
|
||||
setName: function(name) {
|
||||
// Empty name '' is stored as undefined internally
|
||||
if ((name || '') === (this._name || ''))
|
||||
return;
|
||||
var children = this._parent._children,
|
||||
namedChildren = this._parent._namedChildren;
|
||||
if (name != this._name) {
|
||||
// If the item already had a name,
|
||||
// remove its property from the parent's children object:
|
||||
if (this._name)
|
||||
this._removeFromNamed();
|
||||
this._name = name || undefined;
|
||||
}
|
||||
// If the item already had a name,
|
||||
// remove its property from the parent's children object:
|
||||
if (this._name)
|
||||
this._removeFromNamed();
|
||||
if (name) {
|
||||
(namedChildren[name] = namedChildren[name] || []).push(this);
|
||||
children[name] = this;
|
||||
} else {
|
||||
delete children[name];
|
||||
} else if (this._name) {
|
||||
delete children[this._name];
|
||||
}
|
||||
this._name = name || undefined;
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -289,7 +290,7 @@ var Item = this.Item = Base.extend({
|
|||
|
||||
setClipMask: function(clipMask) {
|
||||
this._clipMask = clipMask;
|
||||
if (this._clipMask) {
|
||||
if (clipMask) {
|
||||
this.setFillColor(null);
|
||||
this.setStrokeColor(null);
|
||||
}
|
||||
|
|
|
@ -1249,7 +1249,7 @@ var Path = this.Path = PathItem.extend({
|
|||
dashArray = this.getDashArray() || [], // TODO: Always defined?
|
||||
hasDash = !!dashArray.length;
|
||||
|
||||
if (param.compound || param.selection || param.clip || fillColor
|
||||
if (param.compound || param.selection || this._clipMask || fillColor
|
||||
|| strokeColor && !hasDash) {
|
||||
drawSegments(ctx, this);
|
||||
}
|
||||
|
@ -1259,7 +1259,7 @@ var Path = this.Path = PathItem.extend({
|
|||
if (param.selection) {
|
||||
ctx.stroke();
|
||||
drawHandles(ctx, this._segments);
|
||||
} else if (param.clip) {
|
||||
} else if (this._clipMask) {
|
||||
ctx.clip();
|
||||
} else if (!param.compound && (fillColor || strokeColor)) {
|
||||
// If the path is part of a compound path or doesn't have a fill
|
||||
|
|
Loading…
Reference in a new issue