mirror of
https://github.com/scratchfoundation/scratch-paint.git
synced 2024-12-22 21:42:30 -05:00
Use createGradientObject in applyGradientTypeToSelection
This commit is contained in:
parent
1ecab99cfb
commit
f8da455005
1 changed files with 15 additions and 35 deletions
|
@ -273,57 +273,37 @@ const applyGradientTypeToSelection = function (gradientType, bitmapMode, applyTo
|
||||||
itemColor2 = getColorStringForTransparent(itemColor1);
|
itemColor2 = getColorStringForTransparent(itemColor1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let gradientTypeDiffers = false;
|
||||||
|
// If the item's gradient type differs from the gradient type we want to apply, then we change it
|
||||||
switch (gradientType) {
|
switch (gradientType) {
|
||||||
case GradientTypes.RADIAL: {
|
case GradientTypes.RADIAL: {
|
||||||
const hasRadialGradient = hasGradient && itemColor.gradient.radial;
|
const hasRadialGradient = hasGradient && itemColor.gradient.radial;
|
||||||
if (!hasRadialGradient) {
|
gradientTypeDiffers = !hasRadialGradient;
|
||||||
changed = true;
|
|
||||||
const halfLongestDimension = Math.max(item.bounds.width, item.bounds.height) / 2;
|
|
||||||
|
|
||||||
item[itemColorProp] = {
|
|
||||||
gradient: {
|
|
||||||
stops: [itemColor1, itemColor2],
|
|
||||||
radial: true
|
|
||||||
},
|
|
||||||
origin: item.position,
|
|
||||||
destination: item.position.add(new paper.Point(halfLongestDimension, 0))
|
|
||||||
};
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case GradientTypes.HORIZONTAL: {
|
case GradientTypes.HORIZONTAL: {
|
||||||
const hasHorizontalGradient = hasGradient && !itemColor.gradient.radial &&
|
const hasHorizontalGradient = hasGradient && !itemColor.gradient.radial &&
|
||||||
Math.abs(itemColor.origin.y - itemColor.destination.y) < 1e-8;
|
Math.abs(itemColor.origin.y - itemColor.destination.y) < 1e-8;
|
||||||
if (!hasHorizontalGradient) {
|
gradientTypeDiffers = !hasHorizontalGradient;
|
||||||
changed = true;
|
|
||||||
|
|
||||||
item[itemColorProp] = {
|
|
||||||
gradient: {
|
|
||||||
stops: [itemColor1, itemColor2]
|
|
||||||
},
|
|
||||||
origin: item.bounds.leftCenter,
|
|
||||||
destination: item.bounds.rightCenter
|
|
||||||
};
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case GradientTypes.VERTICAL: {
|
case GradientTypes.VERTICAL: {
|
||||||
const hasVerticalGradient = hasGradient && !itemColor.gradient.radial &&
|
const hasVerticalGradient = hasGradient && !itemColor.gradient.radial &&
|
||||||
Math.abs(itemColor.origin.x - itemColor.destination.x) < 1e-8;
|
Math.abs(itemColor.origin.x - itemColor.destination.x) < 1e-8;
|
||||||
if (!hasVerticalGradient) {
|
gradientTypeDiffers = !hasVerticalGradient;
|
||||||
changed = true;
|
|
||||||
|
|
||||||
item[itemColorProp] = {
|
|
||||||
gradient: {
|
|
||||||
stops: [itemColor1, itemColor2]
|
|
||||||
},
|
|
||||||
origin: item.bounds.topCenter,
|
|
||||||
destination: item.bounds.bottomCenter
|
|
||||||
};
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (gradientTypeDiffers) {
|
||||||
|
changed = true;
|
||||||
|
item[itemColorProp] = createGradientObject(
|
||||||
|
itemColor1,
|
||||||
|
itemColor2,
|
||||||
|
gradientType,
|
||||||
|
item.bounds
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return changed;
|
return changed;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue