Refacture CompoundPath to only use injection scope for methods that require getCurrentPath().

This commit is contained in:
Jürg Lehni 2011-03-03 12:23:46 +00:00
parent 07fcc000cf
commit 26ebe2f2c0

View file

@ -1,14 +1,4 @@
CompoundPath = PathItem.extend(new function() {
function getCurrentPath(compoundPath) {
if (compoundPath.children.length) {
return compoundPath.children[compoundPath.children.length - 1];
} else {
throw Error('Use a moveTo() command first');
}
}
var fields = {
CompoundPath = PathItem.extend({
initialize: function(items) {
this.base();
this.children = [];
@ -68,6 +58,35 @@ CompoundPath = PathItem.extend(new function() {
path.moveTo.apply(path, arguments);
},
draw: function(ctx, param) {
var firstChild = this.children[0];
ctx.beginPath();
param.compound = true;
for (var i = 0, l = this.children.length; i < l; i++) {
Item.draw(this.children[i], ctx, param);
}
firstChild.setCtxStyles(ctx);
if (firstChild.fillColor) {
ctx.fillStyle = firstChild.fillColor.getCssString();
ctx.fill();
}
if (firstChild.strokeColor) {
ctx.strokeStyle = firstChild.strokeColor.getCssString();
ctx.stroke();
}
}
}, new function() {
function getCurrentPath(compoundPath) {
if (compoundPath.children.length) {
return compoundPath.children[compoundPath.children.length - 1];
} else {
throw Error('Use a moveTo() command first');
}
}
var fields = {
moveBy: function() {
var point = arguments.length ? Point.read(arguments) : new Point();
var path = getCurrentPath(this);
@ -90,22 +109,4 @@ CompoundPath = PathItem.extend(new function() {
});
return fields;
}, {
draw: function(ctx, param) {
var firstChild = this.children[0];
ctx.beginPath();
param.compound = true;
for (var i = 0, l = this.children.length; i < l; i++) {
Item.draw(this.children[i], ctx, param);
}
firstChild.setCtxStyles(ctx);
if (firstChild.fillColor) {
ctx.fillStyle = firstChild.fillColor.getCssString();
ctx.fill();
}
if (firstChild.strokeColor) {
ctx.strokeStyle = firstChild.strokeColor.getCssString();
ctx.stroke();
}
}
});