2011-03-03 08:33:41 -05:00
|
|
|
var Group = Item.extend({
|
2011-02-16 16:06:24 -05:00
|
|
|
beans: true,
|
2011-02-12 13:12:23 -05:00
|
|
|
initialize: function(items) {
|
|
|
|
this.base();
|
2011-02-11 12:37:36 -05:00
|
|
|
this.children = [];
|
2011-02-13 11:26:24 -05:00
|
|
|
if (items) {
|
|
|
|
for (var i = 0, l = items.length; i < l; i++) {
|
2011-02-12 13:12:23 -05:00
|
|
|
this.appendTop(items[i]);
|
|
|
|
}
|
|
|
|
}
|
2011-02-11 12:37:36 -05:00
|
|
|
this.clipped = false;
|
|
|
|
},
|
|
|
|
|
2011-02-16 18:34:01 -05:00
|
|
|
getBounds: function() {
|
2011-02-20 21:32:39 -05:00
|
|
|
if (this.children.length) {
|
2011-02-16 18:34:01 -05:00
|
|
|
var rect = this.children[0].bounds;
|
|
|
|
var x1 = rect.x;
|
|
|
|
var y1 = rect.y;
|
|
|
|
var x2 = rect.x + rect.width;
|
|
|
|
var y2 = rect.y + rect.height;
|
2011-02-17 10:00:03 -05:00
|
|
|
for (var i = 1, l = this.children.length; i < l; i++) {
|
2011-02-16 18:34:01 -05:00
|
|
|
var rect2 = this.children[i].bounds;
|
|
|
|
x1 = Math.min(rect2.x, x1);
|
|
|
|
y1 = Math.min(rect2.y, y1);
|
|
|
|
x2 = Math.max(rect2.x + rect2.width, x1 + x2 - x1);
|
|
|
|
y2 = Math.max(rect2.y + rect2.height, y1 + y2 - y1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return new Rectangle(x1, y1, x2 - x1, y2 - y1);
|
|
|
|
},
|
|
|
|
|
2011-02-11 12:37:36 -05:00
|
|
|
/**
|
|
|
|
* Specifies whether the group item is to be clipped.
|
|
|
|
* When setting to true, the first child in the group is automatically
|
|
|
|
* defined as the clipping mask.
|
|
|
|
*
|
|
|
|
* Sample code:
|
|
|
|
* <code>
|
|
|
|
* var group = new Group();
|
|
|
|
* group.appendChild(path);
|
|
|
|
* group.clipped = true;
|
|
|
|
* </code>
|
|
|
|
* @return {@true if the group item is to be clipped}
|
|
|
|
*/
|
|
|
|
isClipped: function() {
|
2011-02-14 16:51:31 -05:00
|
|
|
return this._clipped;
|
2011-02-11 12:37:36 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
setClipped: function(clipped) {
|
2011-02-14 16:51:31 -05:00
|
|
|
this._clipped = clipped;
|
2011-02-11 12:37:36 -05:00
|
|
|
var child = this.firstChild;
|
2011-02-13 11:26:24 -05:00
|
|
|
if (child)
|
2011-02-11 12:37:36 -05:00
|
|
|
child.setClipMask(clipped);
|
2011-03-03 07:19:43 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
draw: function(ctx, param) {
|
|
|
|
for (var i = 0, l = this.children.length; i < l; i++) {
|
|
|
|
Item.draw(this.children[i], ctx, param);
|
|
|
|
if (this.clipped && i == 0)
|
|
|
|
ctx.clip();
|
|
|
|
}
|
2011-02-11 12:37:36 -05:00
|
|
|
}
|
2011-02-13 11:26:24 -05:00
|
|
|
});
|