mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-01-11 10:39:56 -05:00
Rewrote transparency block
Wrapping of the value is now handled by a new function, _wrapTransparency; _updatePenColor now handles the transparency value; DEFAULT_PEN_STATE now includes a transparency value (100).
This commit is contained in:
parent
f61366643d
commit
3185eb27e1
1 changed files with 17 additions and 6 deletions
|
@ -55,6 +55,7 @@ class Scratch3PenBlocks {
|
||||||
penDown: false,
|
penDown: false,
|
||||||
hue: 120,
|
hue: 120,
|
||||||
shade: 50,
|
shade: 50,
|
||||||
|
transparency: 100,
|
||||||
penAttributes: {
|
penAttributes: {
|
||||||
color4f: [0, 0, 1, 1],
|
color4f: [0, 0, 1, 1],
|
||||||
diameter: 1
|
diameter: 1
|
||||||
|
@ -183,11 +184,11 @@ class Scratch3PenBlocks {
|
||||||
penState.penAttributes.color4f[0] = rgb.r / 255.0;
|
penState.penAttributes.color4f[0] = rgb.r / 255.0;
|
||||||
penState.penAttributes.color4f[1] = rgb.g / 255.0;
|
penState.penAttributes.color4f[1] = rgb.g / 255.0;
|
||||||
penState.penAttributes.color4f[2] = rgb.b / 255.0;
|
penState.penAttributes.color4f[2] = rgb.b / 255.0;
|
||||||
penState.penAttributes.color4f[3] = 1;
|
penState.penAttributes.color4f[3] = penState.transparency / 100.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wrap a pen hue or shade values to the range [0,200).
|
* Wrap a pen hue or shade values to the range (0,200).
|
||||||
* @param {number} value - the pen hue or shade value to the proper range.
|
* @param {number} value - the pen hue or shade value to the proper range.
|
||||||
* @returns {number} the wrapped value.
|
* @returns {number} the wrapped value.
|
||||||
* @private
|
* @private
|
||||||
|
@ -197,6 +198,18 @@ class Scratch3PenBlocks {
|
||||||
if (value < 0) value += 200;
|
if (value < 0) value += 200;
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wrap a pen transparency value to the range (0, 100).
|
||||||
|
* @param {number} value - the pen transparency value to the proper range.
|
||||||
|
* @returns {number} the wrapped value.
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
_wrapTransparency (value) {
|
||||||
|
value = value % 100;
|
||||||
|
if (value < 0) value += 100;
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the block primitives implemented by this package.
|
* Retrieve the block primitives implemented by this package.
|
||||||
|
@ -382,8 +395,7 @@ class Scratch3PenBlocks {
|
||||||
*/
|
*/
|
||||||
changePenTransparencyBy (args, util) {
|
changePenTransparencyBy (args, util) {
|
||||||
const penState = this._getPenState(util.target);
|
const penState = this._getPenState(util.target);
|
||||||
const TRANSPARENCY = args.TRANSPARENCY / 100;
|
penState.transparency = this._wrapTransparency(penState.transparency + Cast.toNumber(args.TRANSPARENCY));
|
||||||
penState.penAttributes.color4f[3] = penState.penAttributes.color4f[3] + TRANSPARENCY;
|
|
||||||
this._updatePenColor(penState);
|
this._updatePenColor(penState);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -395,8 +407,7 @@ class Scratch3PenBlocks {
|
||||||
*/
|
*/
|
||||||
setPenTransparencyTo (args, util) {
|
setPenTransparencyTo (args, util) {
|
||||||
const penState = this._getPenState(util.target);
|
const penState = this._getPenState(util.target);
|
||||||
const TRANSPARENCY = MathUtil.clamp(args.TRANSPARENCY, 0, 100) / 100;
|
penState.transparency = this._wrapTransparency(Cast.toNumber(args.TRANSPARENCY));
|
||||||
penState.penAttributes.color4f[3] = TRANSPARENCY;
|
|
||||||
this._updatePenColor(penState);
|
this._updatePenColor(penState);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue