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) {
|
Item.inject(Base.each(keys, function(key) {
|
||||||
|
|
||||||
|
var isColor = !!(key.match(/Color$/));
|
||||||
fields['set' + key.capitalize()] = function(value) {
|
fields['set' + key.capitalize()] = function(value) {
|
||||||
if(this.item && this.item.children) {
|
if(this.item && this.item.children) {
|
||||||
for (var i = 0, l = this.item.children.length; i < l; i++) {
|
for (var i = 0, l = this.item.children.length; i < l; i++) {
|
||||||
this.item.children[i].style[key] = value;
|
this.item.children[i].style[key] = value;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this['_' + key] = value;
|
this['_' + key] = isColor ? Color.read(arguments) : value;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -29,8 +29,14 @@ CompoundPath = PathItem.extend(new function() {
|
||||||
child.draw(ctx, true);
|
child.draw(ctx, true);
|
||||||
}
|
}
|
||||||
firstChild.setCtxStyles(ctx);
|
firstChild.setCtxStyles(ctx);
|
||||||
if (firstChild.fillColor) ctx.fill();
|
if (firstChild.fillColor) {
|
||||||
if (firstChild.strokeColor) ctx.stroke();
|
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 = {
|
var max = {
|
||||||
x: p0.x,
|
x: p0.x,
|
||||||
y: p0.y
|
y: p0.y
|
||||||
}
|
};
|
||||||
var coords = ['x', 'y'];
|
var coords = ['x', 'y'];
|
||||||
function processSegment(segment) {
|
function processSegment(segment) {
|
||||||
var p1 = p0.add(prev.handleOut);
|
var p1 = p0.add(prev.handleOut);
|
||||||
|
@ -367,8 +367,14 @@ Path = PathItem.extend({
|
||||||
}
|
}
|
||||||
if(!compound) {
|
if(!compound) {
|
||||||
this.setCtxStyles(ctx);
|
this.setCtxStyles(ctx);
|
||||||
if (this.fillColor) ctx.fill();
|
if (this.fillColor) {
|
||||||
if (this.strokeColor) ctx.stroke();
|
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
|
}, new function() { // inject methods that require scoped privates
|
||||||
|
@ -399,8 +405,6 @@ Path = PathItem.extend({
|
||||||
};
|
};
|
||||||
|
|
||||||
var styleNames = {
|
var styleNames = {
|
||||||
fillColor: 'fillStyle',
|
|
||||||
strokeColor: 'strokeStyle',
|
|
||||||
strokeWidth: 'lineWidth',
|
strokeWidth: 'lineWidth',
|
||||||
strokeJoin: 'lineJoin',
|
strokeJoin: 'lineJoin',
|
||||||
strokeCap: 'lineCap',
|
strokeCap: 'lineCap',
|
||||||
|
@ -514,5 +518,5 @@ Path = PathItem.extend({
|
||||||
ctx[styleNames[i]] = style;
|
ctx[styleNames[i]] = style;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue