Add extra control blocks for video transparency and on/off control

This commit is contained in:
Corey Frang 2018-04-03 17:46:31 -04:00 committed by Michael "Z" Goddard
parent e4bd9cf6b2
commit 90166dc732
No known key found for this signature in database
GPG key ID: 762CD40DD5349872
3 changed files with 55 additions and 13 deletions

View file

@ -41,11 +41,7 @@ class Scratch3VideoSensingBlocks {
// Boot up the video, canvas to down/up sample the video stream, the
// preview skin and drawable, and kick off looping the analysis
// logic.
this.runtime.ioDevices.video.requestVideo()
.then(({release}) => {
this.releaseVideo = release;
this._loop();
});
this._loop();
}
}
@ -218,6 +214,14 @@ class Scratch3VideoSensingBlocks {
return 2;
}
get VIDEO_STATE_INFO () {
return [
{name: 'off'},
{name: 'on'},
{name: 'on-flipped'}
];
}
/**
* @returns {object} metadata for this extension and its blocks.
*/
@ -255,11 +259,33 @@ class Scratch3VideoSensingBlocks {
defaultValue: 10
}
}
},
{
opcode: 'videoToggle',
text: 'turn video [VIDEO_STATE]',
arguments: {
VIDEO_STATE: {
type: ArgumentType.NUMBER,
menu: 'VIDEO_STATE',
defaultValue: 1
}
}
},
{
opcode: 'setVideoTransparency',
text: 'set video transparency to [TRANSPARENCY]',
arguments: {
TRANSPARENCY: {
type: ArgumentType.NUMBER,
defaultValue: 0
}
}
}
],
menus: {
MOTION_DIRECTION: this._buildMenu(this.MOTION_DIRECTION_INFO),
STAGE_SPRITE: this._buildMenu(this.STAGE_SPRITE_INFO)
STAGE_SPRITE: this._buildMenu(this.STAGE_SPRITE_INFO),
VIDEO_STATE: this._buildMenu(this.VIDEO_STATE_INFO)
}
};
}
@ -312,6 +338,20 @@ class Scratch3VideoSensingBlocks {
const state = this._analyzeLocalMotion(util.target);
return state.motionAmount > Number(args.REFERENCE);
}
videoToggle (args) {
const state = Number(args.VIDEO_STATE);
// 1 == off, 2 & 3 are on (3 is flipped)
if (state > 1) {
this.runtime.ioDevices.video.requestVideo();
} else {
this.runtime.ioDevices.video.disableVideo();
}
}
setVideoTransparency (args) {
this.runtime.ioDevices.video.setPreviewGhost(Number(args.TRANSPARENCY));
}
}
module.exports = Scratch3VideoSensingBlocks;

View file

@ -201,7 +201,7 @@ class Video {
*/
setPreviewGhost (ghost) {
if (this._drawable) {
this._drawable.updateProperties({ghost});
this.runtime.renderer.updateDrawableProperties(this._drawable, {ghost});
}
}
@ -248,7 +248,7 @@ class Video {
_disablePreview () {
if (this._skin && this._drawable) {
this._skin.clear();
this._drawable.updateProperties({visible: false});
this.runtime.renderer.updateDrawableProperties(this._drawable, {visible: false});
}
this._renderPreviewFrame = null;
}
@ -272,7 +272,9 @@ class Video {
// if we haven't already created and started a preview frame render loop, do so
if (!this._renderPreviewFrame) {
this._drawable.updateProperties({visible: true});
renderer.updateDrawableProperties(this._drawable, {
visible: true
});
this._renderPreviewFrame = () => {
if (!this._renderPreviewFrame) {

View file

@ -980,17 +980,17 @@ const specMap = {
// ]
// },
'setVideoState': {
opcode: 'sensing_videotoggle',
opcode: 'videoSensing.videoToggle',
argMap: [
{
type: 'input',
inputOp: 'sensing_videotogglemenu',
inputName: 'VIDEOTOGGLEMENU'
inputOp: 'videoSensing.menu.VIDEO_STATE',
inputName: 'VIDEO_STATE'
}
]
},
'setVideoTransparency': {
opcode: 'sensing_setvideotransparency',
opcode: 'videoSensing.setVideoTransparency',
argMap: [
{
type: 'input',