mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2024-12-29 09:22:22 -05:00
Group: allow passing of array of items to constructor and pass on ctx in draw function. Add tests for Group.
This commit is contained in:
parent
c1d2cab5d9
commit
7fdf439ef2
3 changed files with 26 additions and 4 deletions
|
@ -1,12 +1,18 @@
|
|||
GroupItem = Item.extend({
|
||||
initialize: function() {
|
||||
Group = Item.extend({
|
||||
initialize: function(items) {
|
||||
this.base();
|
||||
this.children = [];
|
||||
if(items) {
|
||||
for(var i = 0, l = items.length; i < l; i++) {
|
||||
this.appendTop(items[i]);
|
||||
}
|
||||
}
|
||||
this.clipped = false;
|
||||
},
|
||||
|
||||
draw: function() {
|
||||
draw: function(ctx) {
|
||||
for(var i = 0, l = this.children.length; i < l; i++) {
|
||||
this.children[i].draw();
|
||||
this.children[i].draw(ctx);
|
||||
}
|
||||
},
|
||||
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
<script type="text/javascript" src="tests/Rectangle.js"></script>
|
||||
<script type="text/javascript" src="tests/Document.js"></script>
|
||||
<script type="text/javascript" src="tests/Item.js"></script>
|
||||
<script type="text/javascript" src="tests/Group.js"></script>
|
||||
<script type="text/javascript" src="tests/Segment.js"></script>
|
||||
<script type="text/javascript" src="tests/Path.js"></script>
|
||||
<script type="text/javascript" src="tests/Path_Shapes.js"></script>
|
||||
|
|
15
test/tests/Group.js
Normal file
15
test/tests/Group.js
Normal file
|
@ -0,0 +1,15 @@
|
|||
module('Group');
|
||||
|
||||
test('new Group()', function() {
|
||||
var doc = new Doc();
|
||||
var group = new Group();
|
||||
equals(doc.activeLayer.children[0] == group, true);
|
||||
});
|
||||
|
||||
test('new Group([item])', function() {
|
||||
var doc = new Doc();
|
||||
var path = new Path();
|
||||
var group = new Group([path]);
|
||||
equals(doc.activeLayer.children.length == 1, true);
|
||||
equals(group.children[0] == path, true);
|
||||
});
|
Loading…
Reference in a new issue