Remove Group#_clipped and solely use Item#_clipMask to handle clipping internally.

This commit is contained in:
Jürg Lehni 2011-06-17 13:56:02 +01:00
parent 30087d046a
commit f4d15200ee
3 changed files with 9 additions and 14 deletions

View file

@ -71,17 +71,10 @@ 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;
},
/**
* Specifies whether the group item is to be clipped.
* When setting to {@code true}, the first child in the group is
@ -91,20 +84,22 @@ var Group = this.Group = Item.extend({
* @bean
*/
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) {
this._clipped = clipped;
var child = this.getFirstChild();
if (child)
child.setClipMask(clipped);
return this;
},
draw: function(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);
}
}

View file

@ -290,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);
}

View file

@ -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