2011-03-07 00:50:44 +00:00
|
|
|
/*
|
|
|
|
* Paper.js
|
|
|
|
*
|
|
|
|
* This file is part of Paper.js, a JavaScript Vector Graphics Library,
|
|
|
|
* based on Scriptographer.org and designed to be largely API compatible.
|
2011-03-08 01:41:50 +00:00
|
|
|
* http://paperjs.org/
|
2011-03-07 00:50:44 +00:00
|
|
|
* http://scriptographer.org/
|
|
|
|
*
|
2011-03-08 01:41:50 +00:00
|
|
|
* Distributed under the MIT license. See LICENSE file for details.
|
|
|
|
*
|
2011-03-07 00:50:44 +00:00
|
|
|
* Copyright (c) 2011, Juerg Lehni & Jonathan Puckey
|
|
|
|
* http://lehni.org/ & http://jonathanpuckey.com/
|
|
|
|
*
|
2011-03-08 01:41:50 +00:00
|
|
|
* All rights reserved.
|
2011-03-07 00:50:44 +00:00
|
|
|
*/
|
|
|
|
|
2011-03-04 13:34:31 +00:00
|
|
|
var Group = this.Group = Item.extend({
|
2011-02-16 22:06:24 +01:00
|
|
|
beans: true,
|
2011-03-06 15:15:21 +00:00
|
|
|
|
2011-02-12 19:12:23 +01:00
|
|
|
initialize: function(items) {
|
|
|
|
this.base();
|
2011-02-11 18:37:36 +01:00
|
|
|
this.children = [];
|
2011-02-13 16:26:24 +00:00
|
|
|
if (items) {
|
|
|
|
for (var i = 0, l = items.length; i < l; i++) {
|
2011-02-12 19:12:23 +01:00
|
|
|
this.appendTop(items[i]);
|
|
|
|
}
|
|
|
|
}
|
2011-03-05 01:26:12 +00:00
|
|
|
this.setClipped(false);
|
2011-02-11 18:37:36 +01:00
|
|
|
},
|
2011-03-03 22:45:17 +00:00
|
|
|
|
2011-02-11 18:37:36 +01: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 22:51:31 +01:00
|
|
|
return this._clipped;
|
2011-02-11 18:37:36 +01:00
|
|
|
},
|
2011-03-03 22:45:17 +00:00
|
|
|
|
2011-02-11 18:37:36 +01:00
|
|
|
setClipped: function(clipped) {
|
2011-02-14 22:51:31 +01:00
|
|
|
this._clipped = clipped;
|
2011-02-11 18:37:36 +01:00
|
|
|
var child = this.firstChild;
|
2011-02-13 16:26:24 +00:00
|
|
|
if (child)
|
2011-02-11 18:37:36 +01:00
|
|
|
child.setClipMask(clipped);
|
2011-03-03 12:19:43 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
draw: function(ctx, param) {
|
|
|
|
for (var i = 0, l = this.children.length; i < l; i++) {
|
|
|
|
Item.draw(this.children[i], ctx, param);
|
2011-03-05 01:26:12 +00:00
|
|
|
if (this._clipped && i == 0)
|
2011-03-03 12:19:43 +00:00
|
|
|
ctx.clip();
|
|
|
|
}
|
2011-02-11 18:37:36 +01:00
|
|
|
}
|
2011-02-13 16:26:24 +00:00
|
|
|
});
|