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:
Jonathan Puckey 2011-02-12 19:12:23 +01:00
parent c1d2cab5d9
commit 7fdf439ef2
3 changed files with 26 additions and 4 deletions

View file

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

View file

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