mirror of
https://github.com/scratchfoundation/scratch-paint.git
synced 2024-12-23 14:02:50 -05:00
Merge pull request #231 from fsih/fillWithTransparent
Null checks for fill with transparent
This commit is contained in:
commit
9b5383eb50
1 changed files with 16 additions and 14 deletions
|
@ -5,6 +5,16 @@ import {isGroup} from './group';
|
||||||
|
|
||||||
const MIXED = 'scratch-paint/style-path/mixed';
|
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
|
* Called when setting fill color
|
||||||
* @param {string} colorString New color, css format
|
* @param {string} colorString New color, css format
|
||||||
|
@ -22,16 +32,14 @@ const applyFillColorToSelection = function (colorString) {
|
||||||
if (child.children) {
|
if (child.children) {
|
||||||
for (const path of child.children) {
|
for (const path of child.children) {
|
||||||
if (!path.data.isPGGlyphRect) {
|
if (!path.data.isPGGlyphRect) {
|
||||||
if ((path.fillColor === null && colorString) ||
|
if (!_colorMatch(path.fillColor, colorString)) {
|
||||||
path.fillColor.toCSS() !== new paper.Color(colorString).toCSS()) {
|
|
||||||
changed = true;
|
changed = true;
|
||||||
path.fillColor = colorString;
|
path.fillColor = colorString;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (!child.data.isPGGlyphRect) {
|
} else if (!child.data.isPGGlyphRect) {
|
||||||
if ((child.fillColor === null && colorString) ||
|
if (!_colorMatch(child.fillColor, colorString)) {
|
||||||
child.fillColor.toCSS() !== new paper.Color(colorString).toCSS()) {
|
|
||||||
changed = true;
|
changed = true;
|
||||||
child.fillColor = colorString;
|
child.fillColor = colorString;
|
||||||
}
|
}
|
||||||
|
@ -41,8 +49,7 @@ const applyFillColorToSelection = function (colorString) {
|
||||||
if (isPointTextItem(item) && !colorString) {
|
if (isPointTextItem(item) && !colorString) {
|
||||||
colorString = 'rgba(0,0,0,0)';
|
colorString = 'rgba(0,0,0,0)';
|
||||||
}
|
}
|
||||||
if ((item.fillColor === null && colorString) ||
|
if (!_colorMatch(item.fillColor, colorString)) {
|
||||||
item.fillColor.toCSS() !== new paper.Color(colorString).toCSS()) {
|
|
||||||
changed = true;
|
changed = true;
|
||||||
item.fillColor = colorString;
|
item.fillColor = colorString;
|
||||||
}
|
}
|
||||||
|
@ -51,11 +58,6 @@ const applyFillColorToSelection = function (colorString) {
|
||||||
return changed;
|
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
|
* Called when setting stroke color
|
||||||
* @param {string} colorString New color, css format
|
* @param {string} colorString New color, css format
|
||||||
|
@ -74,7 +76,7 @@ const applyStrokeColorToSelection = function (colorString) {
|
||||||
if (child.children) {
|
if (child.children) {
|
||||||
for (const path of child.children) {
|
for (const path of child.children) {
|
||||||
if (!path.data.isPGGlyphRect) {
|
if (!path.data.isPGGlyphRect) {
|
||||||
if (!_strokeColorMatch(path, colorString)) {
|
if (!_colorMatch(path.strokeColor, colorString)) {
|
||||||
changed = true;
|
changed = true;
|
||||||
path.strokeColor = colorString;
|
path.strokeColor = colorString;
|
||||||
}
|
}
|
||||||
|
@ -88,12 +90,12 @@ const applyStrokeColorToSelection = function (colorString) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (!item.data.isPGGlyphRect) {
|
} else if (!item.data.isPGGlyphRect) {
|
||||||
if (!_strokeColorMatch(item, colorString)) {
|
if (!_colorMatch(item.strokeColor, colorString)) {
|
||||||
changed = true;
|
changed = true;
|
||||||
item.strokeColor = colorString;
|
item.strokeColor = colorString;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (!_strokeColorMatch(item, colorString)) {
|
} else if (!_colorMatch(item.strokeColor, colorString)) {
|
||||||
changed = true;
|
changed = true;
|
||||||
item.strokeColor = colorString;
|
item.strokeColor = colorString;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue