mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-03 19:45:44 -05:00
Refacture CompoundPath to only use injection scope for methods that require getCurrentPath().
This commit is contained in:
parent
07fcc000cf
commit
26ebe2f2c0
1 changed files with 79 additions and 78 deletions
|
@ -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();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue