mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-07 13:22:07 -05:00
Remove Group#_clipped and solely use Item#_clipMask to handle clipping internally.
This commit is contained in:
parent
30087d046a
commit
f4d15200ee
3 changed files with 9 additions and 14 deletions
|
@ -71,17 +71,10 @@ var Group = this.Group = Item.extend({
|
||||||
this.base();
|
this.base();
|
||||||
this._children = [];
|
this._children = [];
|
||||||
this._namedChildren = {};
|
this._namedChildren = {};
|
||||||
this._clipped = false;
|
|
||||||
this.setChildren(!items || !Array.isArray(items)
|
this.setChildren(!items || !Array.isArray(items)
|
||||||
|| typeof items[0] !== 'object' ? arguments : items);
|
|| typeof items[0] !== 'object' ? arguments : items);
|
||||||
},
|
},
|
||||||
|
|
||||||
clone: function() {
|
|
||||||
var copy = this.base();
|
|
||||||
copy._clipped = this._clipped;
|
|
||||||
return copy;
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specifies whether the group item is to be clipped.
|
* Specifies whether the group item is to be clipped.
|
||||||
* When setting to {@code true}, the first child in the group is
|
* When setting to {@code true}, the first child in the group is
|
||||||
|
@ -91,20 +84,22 @@ var Group = this.Group = Item.extend({
|
||||||
* @bean
|
* @bean
|
||||||
*/
|
*/
|
||||||
isClipped: function() {
|
isClipped: function() {
|
||||||
return this._clipped;
|
for (var i = 0, l = this._children.length; i < l; i++) {
|
||||||
|
if (this._children[i]._clipMask)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
},
|
},
|
||||||
|
|
||||||
setClipped: function(clipped) {
|
setClipped: function(clipped) {
|
||||||
this._clipped = clipped;
|
|
||||||
var child = this.getFirstChild();
|
var child = this.getFirstChild();
|
||||||
if (child)
|
if (child)
|
||||||
child.setClipMask(clipped);
|
child.setClipMask(clipped);
|
||||||
|
return this;
|
||||||
},
|
},
|
||||||
|
|
||||||
draw: function(ctx, param) {
|
draw: function(ctx, param) {
|
||||||
for (var i = 0, l = this._children.length; i < l; i++) {
|
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);
|
Item.draw(this._children[i], ctx, param);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -290,7 +290,7 @@ var Item = this.Item = Base.extend({
|
||||||
|
|
||||||
setClipMask: function(clipMask) {
|
setClipMask: function(clipMask) {
|
||||||
this._clipMask = clipMask;
|
this._clipMask = clipMask;
|
||||||
if (this._clipMask) {
|
if (clipMask) {
|
||||||
this.setFillColor(null);
|
this.setFillColor(null);
|
||||||
this.setStrokeColor(null);
|
this.setStrokeColor(null);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1249,7 +1249,7 @@ var Path = this.Path = PathItem.extend({
|
||||||
dashArray = this.getDashArray() || [], // TODO: Always defined?
|
dashArray = this.getDashArray() || [], // TODO: Always defined?
|
||||||
hasDash = !!dashArray.length;
|
hasDash = !!dashArray.length;
|
||||||
|
|
||||||
if (param.compound || param.selection || param.clip || fillColor
|
if (param.compound || param.selection || this._clipMask || fillColor
|
||||||
|| strokeColor && !hasDash) {
|
|| strokeColor && !hasDash) {
|
||||||
drawSegments(ctx, this);
|
drawSegments(ctx, this);
|
||||||
}
|
}
|
||||||
|
@ -1259,7 +1259,7 @@ var Path = this.Path = PathItem.extend({
|
||||||
if (param.selection) {
|
if (param.selection) {
|
||||||
ctx.stroke();
|
ctx.stroke();
|
||||||
drawHandles(ctx, this._segments);
|
drawHandles(ctx, this._segments);
|
||||||
} else if (param.clip) {
|
} else if (this._clipMask) {
|
||||||
ctx.clip();
|
ctx.clip();
|
||||||
} else if (!param.compound && (fillColor || strokeColor)) {
|
} else if (!param.compound && (fillColor || strokeColor)) {
|
||||||
// If the path is part of a compound path or doesn't have a fill
|
// If the path is part of a compound path or doesn't have a fill
|
||||||
|
|
Loading…
Reference in a new issue