mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-20 22:39:50 -05:00
Handle RGB alpha correctly.
This commit is contained in:
parent
b8b02417a0
commit
d56e5552b0
1 changed files with 7 additions and 1 deletions
|
@ -60,6 +60,7 @@ var Color = Base.extend(new function() {
|
||||||
var match = string.match(/^#(\w{1,2})(\w{1,2})(\w{1,2})$/),
|
var match = string.match(/^#(\w{1,2})(\w{1,2})(\w{1,2})$/),
|
||||||
components;
|
components;
|
||||||
if (match) {
|
if (match) {
|
||||||
|
// Hex
|
||||||
components = [0, 0, 0];
|
components = [0, 0, 0];
|
||||||
for (var i = 0; i < 3; i++) {
|
for (var i = 0; i < 3; i++) {
|
||||||
var value = match[i + 1];
|
var value = match[i + 1];
|
||||||
|
@ -67,6 +68,7 @@ var Color = Base.extend(new function() {
|
||||||
? value + value : value, 16) / 255;
|
? value + value : value, 16) / 255;
|
||||||
}
|
}
|
||||||
} else if (match = string.match(/^rgba?\((.*)\)$/)) {
|
} else if (match = string.match(/^rgba?\((.*)\)$/)) {
|
||||||
|
// RGB / RGBA
|
||||||
components = match[1].split(',');
|
components = match[1].split(',');
|
||||||
for (var i = 0, l = components.length; i < l; i++) {
|
for (var i = 0, l = components.length; i < l; i++) {
|
||||||
var value = parseFloat(components[i]);
|
var value = parseFloat(components[i]);
|
||||||
|
@ -542,8 +544,12 @@ var Color = Base.extend(new function() {
|
||||||
if (values.length > length)
|
if (values.length > length)
|
||||||
values = slice.call(values, 0, length);
|
values = slice.call(values, 0, length);
|
||||||
} else if (argType === 'string') {
|
} else if (argType === 'string') {
|
||||||
components = fromCSS(arg);
|
|
||||||
type = 'rgb';
|
type = 'rgb';
|
||||||
|
components = fromCSS(arg);
|
||||||
|
if (components.length === 4) {
|
||||||
|
alpha = components[3];
|
||||||
|
components.length--;
|
||||||
|
}
|
||||||
} else if (argType === 'object') {
|
} else if (argType === 'object') {
|
||||||
if (arg.constructor === Color) {
|
if (arg.constructor === Color) {
|
||||||
type = arg._type;
|
type = arg._type;
|
||||||
|
|
Loading…
Reference in a new issue