Merge pull request #231 from fsih/fillWithTransparent

Null checks for fill with transparent
This commit is contained in:
DD Liu 2017-12-19 13:34:29 -05:00 committed by GitHub
commit 9b5383eb50
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -5,6 +5,16 @@ import {isGroup} from './group';
const MIXED = 'scratch-paint/style-path/mixed';
// Check if the item color matches the incoming color. If the item color is a gradient, we assume
// that the incoming color never matches, since we don't support gradients yet.
const _colorMatch = function (itemColor, incomingColor) {
// @todo check whether the gradient has changed when we support gradients
if (itemColor && itemColor.type === 'gradient') return false;
// Either both are null or both are the same color when converted to CSS.
return (!itemColor && !incomingColor) ||
(itemColor && incomingColor && itemColor.toCSS() === new paper.Color(incomingColor).toCSS());
};
/**
* Called when setting fill color
* @param {string} colorString New color, css format
@ -22,16 +32,14 @@ const applyFillColorToSelection = function (colorString) {
if (child.children) {
for (const path of child.children) {
if (!path.data.isPGGlyphRect) {
if ((path.fillColor === null && colorString) ||
path.fillColor.toCSS() !== new paper.Color(colorString).toCSS()) {
if (!_colorMatch(path.fillColor, colorString)) {
changed = true;
path.fillColor = colorString;
}
}
}
} else if (!child.data.isPGGlyphRect) {
if ((child.fillColor === null && colorString) ||
child.fillColor.toCSS() !== new paper.Color(colorString).toCSS()) {
if (!_colorMatch(child.fillColor, colorString)) {
changed = true;
child.fillColor = colorString;
}
@ -41,8 +49,7 @@ const applyFillColorToSelection = function (colorString) {
if (isPointTextItem(item) && !colorString) {
colorString = 'rgba(0,0,0,0)';
}
if ((item.fillColor === null && colorString) ||
item.fillColor.toCSS() !== new paper.Color(colorString).toCSS()) {
if (!_colorMatch(item.fillColor, colorString)) {
changed = true;
item.fillColor = colorString;
}
@ -51,11 +58,6 @@ const applyFillColorToSelection = function (colorString) {
return changed;
};
const _strokeColorMatch = function (item, incomingColor) {
return (!item.strokeColor && !incomingColor) ||
(item.strokeColor && incomingColor && item.strokeColor.toCSS() === new paper.Color(incomingColor).toCSS());
};
/**
* Called when setting stroke color
* @param {string} colorString New color, css format
@ -74,7 +76,7 @@ const applyStrokeColorToSelection = function (colorString) {
if (child.children) {
for (const path of child.children) {
if (!path.data.isPGGlyphRect) {
if (!_strokeColorMatch(path, colorString)) {
if (!_colorMatch(path.strokeColor, colorString)) {
changed = true;
path.strokeColor = colorString;
}
@ -88,12 +90,12 @@ const applyStrokeColorToSelection = function (colorString) {
}
}
} else if (!item.data.isPGGlyphRect) {
if (!_strokeColorMatch(item, colorString)) {
if (!_colorMatch(item.strokeColor, colorString)) {
changed = true;
item.strokeColor = colorString;
}
}
} else if (!_strokeColorMatch(item, colorString)) {
} else if (!_colorMatch(item.strokeColor, colorString)) {
changed = true;
item.strokeColor = colorString;
}