mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-01 02:38:43 -05:00
Change PathStyle, CompoundPath and Path to work with new Color classes.
This commit is contained in:
parent
c386f38b86
commit
c2849b3692
3 changed files with 21 additions and 10 deletions
|
@ -16,17 +16,18 @@ PathStyle = Base.extend(new function() {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Item.inject(Base.each(keys, function(key) {
|
||||
|
||||
var isColor = !!(key.match(/Color$/));
|
||||
fields['set' + key.capitalize()] = function(value) {
|
||||
if(this.item && this.item.children) {
|
||||
for (var i = 0, l = this.item.children.length; i < l; i++) {
|
||||
this.item.children[i].style[key] = value;
|
||||
}
|
||||
} else {
|
||||
this['_' + key] = value;
|
||||
this['_' + key] = isColor ? Color.read(arguments) : value;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -29,8 +29,14 @@ CompoundPath = PathItem.extend(new function() {
|
|||
child.draw(ctx, true);
|
||||
}
|
||||
firstChild.setCtxStyles(ctx);
|
||||
if (firstChild.fillColor) ctx.fill();
|
||||
if (firstChild.strokeColor) ctx.stroke();
|
||||
if (firstChild.fillColor) {
|
||||
ctx.fillStyle = firstChild.fillColor.getCssString();
|
||||
ctx.fill();
|
||||
}
|
||||
if (firstChild.strokeColor) {
|
||||
ctx.strokeStyle = firstChild.strokeColor.getCssString();
|
||||
ctx.stroke();
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
|
|
|
@ -45,7 +45,7 @@ Path = PathItem.extend({
|
|||
var max = {
|
||||
x: p0.x,
|
||||
y: p0.y
|
||||
}
|
||||
};
|
||||
var coords = ['x', 'y'];
|
||||
function processSegment(segment) {
|
||||
var p1 = p0.add(prev.handleOut);
|
||||
|
@ -367,8 +367,14 @@ Path = PathItem.extend({
|
|||
}
|
||||
if(!compound) {
|
||||
this.setCtxStyles(ctx);
|
||||
if (this.fillColor) ctx.fill();
|
||||
if (this.strokeColor) ctx.stroke();
|
||||
if (this.fillColor) {
|
||||
ctx.fillStyle = this.fillColor.getCssString();
|
||||
ctx.fill();
|
||||
}
|
||||
if (this.strokeColor) {
|
||||
ctx.strokeStyle = this.strokeColor.getCssString();
|
||||
ctx.stroke();
|
||||
}
|
||||
}
|
||||
}
|
||||
}, new function() { // inject methods that require scoped privates
|
||||
|
@ -399,8 +405,6 @@ Path = PathItem.extend({
|
|||
};
|
||||
|
||||
var styleNames = {
|
||||
fillColor: 'fillStyle',
|
||||
strokeColor: 'strokeStyle',
|
||||
strokeWidth: 'lineWidth',
|
||||
strokeJoin: 'lineJoin',
|
||||
strokeCap: 'lineCap',
|
||||
|
@ -514,5 +518,5 @@ Path = PathItem.extend({
|
|||
ctx[styleNames[i]] = style;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue