CompoundPath cleanups.

This commit is contained in:
Jonathan Puckey 2011-04-21 21:12:48 +02:00
parent 1ea0a811b5
commit 11063af8df

View file

@ -19,9 +19,8 @@ var CompoundPath = this.CompoundPath = PathItem.extend({
this.base(); this.base();
this.children = []; this.children = [];
if (items) { if (items) {
for (var i = 0, l = items.length; i < l; i++) { for (var i = 0, l = items.length; i < l; i++)
this.appendTop(items[i]); this.appendTop(items[i]);
}
} }
}, },
@ -29,11 +28,11 @@ var CompoundPath = this.CompoundPath = PathItem.extend({
// code (from a utility script?) // code (from a utility script?)
getBounds: function() { getBounds: function() {
if (this.children.length) { if (this.children.length) {
var rect = this.children[0].getBounds(); var rect = this.children[0].getBounds(),
var x1 = rect.x; x1 = rect.x,
var y1 = rect.y; y1 = rect.y,
var x2 = rect.x + rect.width; x2 = rect.x + rect.width,
var y2 = rect.y + rect.height; y2 = rect.y + rect.height;
for (var i = 1, l = this.children.length; i < l; i++) { for (var i = 1, l = this.children.length; i < l; i++) {
var rect2 = this.children[i].getBounds(); var rect2 = this.children[i].getBounds();
x1 = Math.min(rect2.x, x1); x1 = Math.min(rect2.x, x1);
@ -64,9 +63,8 @@ var CompoundPath = this.CompoundPath = PathItem.extend({
}, },
smooth: function() { smooth: function() {
for (var i = 0, l = this.children.length; i < l; i++) { for (var i = 0, l = this.children.length; i < l; i++)
this.children[i].smooth(); this.children[i].smooth();
}
}, },
moveTo: function() { moveTo: function() {
@ -79,9 +77,8 @@ var CompoundPath = this.CompoundPath = PathItem.extend({
var firstChild = this.children[0]; var firstChild = this.children[0];
ctx.beginPath(); ctx.beginPath();
param.compound = true; param.compound = true;
for (var i = 0, l = this.children.length; i < l; i++) { for (var i = 0, l = this.children.length; i < l; i++)
Item.draw(this.children[i], ctx, param); Item.draw(this.children[i], ctx, param);
}
firstChild.setContextStyles(ctx); firstChild.setContextStyles(ctx);
var fillColor = firstChild.getFillColor(), var fillColor = firstChild.getFillColor(),
strokeColor = firstChild.getStrokeColor(); strokeColor = firstChild.getStrokeColor();
@ -106,15 +103,14 @@ var CompoundPath = this.CompoundPath = PathItem.extend({
var fields = { var fields = {
moveBy: function() { moveBy: function() {
var point = arguments.length ? Point.read(arguments) : new Point(); var point = arguments.length ? Point.read(arguments) : new Point(),
var path = getCurrentPath(this); path = getCurrentPath(this),
var current = path.segments[path.segments.length - 1]._point; current = path.segments[path.segments.length - 1]._point;
this.moveTo(current.add(point)); this.moveTo(current.add(point));
}, },
closePath: function() { closePath: function() {
var path = getCurrentPath(this); getCurrentPath(this).closed = true;
path.closed = true;
} }
}; };