Merge pull request #403 from griffpatch/feature/Support-ARGB-for-pen

Fix for Support ARGB for pen #393
This commit is contained in:
Andrew Sliwinski 2017-01-27 17:07:43 -05:00 committed by GitHub
commit de4035055b
4 changed files with 16 additions and 11 deletions

View file

@ -258,6 +258,9 @@ Scratch3PenBlocks.prototype.setPenColorToColor = function (args, util) {
penState.penAttributes.color4f[0] = rgb.r / 255.0;
penState.penAttributes.color4f[1] = rgb.g / 255.0;
penState.penAttributes.color4f[2] = rgb.b / 255.0;
if (rgb.hasOwnProperty('a')) { // Will there always be an 'a'?
penState.penAttributes.color4f[3] = rgb.a / 255.0;
}
};
/**

View file

@ -40,10 +40,11 @@ Color.decimalToHex = function (decimal) {
* @return {RGBObject} rgb - {r: red [0,255], g: green [0,255], b: blue [0,255]}.
*/
Color.decimalToRgb = function (decimal) {
var a = (decimal >> 24) & 0xFF;
var r = (decimal >> 16) & 0xFF;
var g = (decimal >> 8) & 0xFF;
var b = decimal & 0xFF;
return {r: r, g: g, b: b};
return {r: r, g: g, b: b, a: a > 0 ? a : 255};
};
/**

View file

@ -99,13 +99,14 @@ test('toRbgColorObject', function (t) {
t.deepEqual(cast.toRgbColorObject('#ffffff'), {r: 255, g: 255, b: 255});
// Decimal (minimal, see "color" util tests)
t.deepEqual(cast.toRgbColorObject(0), {r: 0, g: 0, b: 0});
t.deepEqual(cast.toRgbColorObject(1), {r: 0, g: 0, b: 1});
t.deepEqual(cast.toRgbColorObject(16777215), {r: 255, g: 255, b: 255});
t.deepEqual(cast.toRgbColorObject(0), {a: 255, r: 0, g: 0, b: 0});
t.deepEqual(cast.toRgbColorObject(1), {a: 255, r: 0, g: 0, b: 1});
t.deepEqual(cast.toRgbColorObject(16777215), {a: 255, r: 255, g: 255, b: 255});
t.deepEqual(cast.toRgbColorObject('0x80010203'), {a: 128, r: 1, g: 2, b: 3});
// Malformed
t.deepEqual(cast.toRgbColorObject('ffffff'), {r: 0, g: 0, b: 0});
t.deepEqual(cast.toRgbColorObject('foobar'), {r: 0, g: 0, b: 0});
t.deepEqual(cast.toRgbColorObject('ffffff'), {a: 255, r: 0, g: 0, b: 0});
t.deepEqual(cast.toRgbColorObject('foobar'), {a: 255, r: 0, g: 0, b: 0});
t.end();
});

View file

@ -47,11 +47,11 @@ test('decimalToHex', function (t) {
});
test('decimalToRgb', function (t) {
t.deepEqual(color.decimalToRgb(0), {r: 0, g: 0, b: 0});
t.deepEqual(color.decimalToRgb(1), {r: 0, g: 0, b: 1});
t.deepEqual(color.decimalToRgb(16777215), {r: 255, g: 255, b: 255});
t.deepEqual(color.decimalToRgb(-16777215), {r: 0, g: 0, b: 1});
t.deepEqual(color.decimalToRgb(99999999), {r: 245, g: 224, b: 255});
t.deepEqual(color.decimalToRgb(0), {a: 255, r: 0, g: 0, b: 0});
t.deepEqual(color.decimalToRgb(1), {a: 255, r: 0, g: 0, b: 1});
t.deepEqual(color.decimalToRgb(16777215), {a: 255, r: 255, g: 255, b: 255});
t.deepEqual(color.decimalToRgb(-16777215), {a: 255, r: 0, g: 0, b: 1});
t.deepEqual(color.decimalToRgb(99999999), {a: 5, r: 245, g: 224, b: 255});
t.end();
});