mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-23 14:32:59 -05:00
Set video device state and transparency from values in stage
Set the video device state and transparency to the values in the stage target when the video sensing extension is loaded. Changing video state and transparency from the extension's blocks will also store that setting to the stage target.
This commit is contained in:
parent
b9911332c7
commit
cef9f58c2a
1 changed files with 55 additions and 4 deletions
|
@ -54,10 +54,17 @@ class Scratch3VideoSensingBlocks {
|
|||
// Clear target motion state values when the project starts.
|
||||
this.runtime.on(Runtime.PROJECT_RUN_START, this.reset.bind(this));
|
||||
|
||||
// Boot up the video, canvas to down/up sample the video stream, the
|
||||
// preview skin and drawable, and kick off looping the analysis
|
||||
// logic.
|
||||
// Kick off looping the analysis logic.
|
||||
this._loop();
|
||||
|
||||
// Configure the video device with values from a globally stored
|
||||
// location.
|
||||
this.setVideoTransparency({
|
||||
TRANSPARENCY: this.globalVideoTransparency
|
||||
});
|
||||
this.videoToggle({
|
||||
VIDEO_STATE: this.globalVideoState
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -99,6 +106,48 @@ class Scratch3VideoSensingBlocks {
|
|||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* The transparency setting of the video preview stored in a value
|
||||
* accessible by any object connected to the virtual machine.
|
||||
* @type {number}
|
||||
*/
|
||||
get globalVideoTransparency () {
|
||||
const stage = this.runtime.getTargetForStage();
|
||||
if (stage) {
|
||||
return stage.videoTransparency;
|
||||
}
|
||||
return 50;
|
||||
}
|
||||
|
||||
set globalVideoTransparency (transparency) {
|
||||
const stage = this.runtime.getTargetForStage();
|
||||
if (stage) {
|
||||
stage.videoTransparency = transparency;
|
||||
}
|
||||
return transparency;
|
||||
}
|
||||
|
||||
/**
|
||||
* The video state of the video preview stored in a value accessible by any
|
||||
* object connected to the virtual machine.
|
||||
* @type {number}
|
||||
*/
|
||||
get globalVideoState () {
|
||||
const stage = this.runtime.getTargetForStage();
|
||||
if (stage) {
|
||||
return stage.videoState;
|
||||
}
|
||||
return VideoState.ON;
|
||||
}
|
||||
|
||||
set globalVideoState (state) {
|
||||
const stage = this.runtime.getTargetForStage();
|
||||
if (stage) {
|
||||
stage.videoState = state;
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset the extension's data motion detection data. This will clear out
|
||||
* for example old frames, so the first analyzed frame will not be compared
|
||||
|
@ -316,7 +365,7 @@ class Scratch3VideoSensingBlocks {
|
|||
arguments: {
|
||||
TRANSPARENCY: {
|
||||
type: ArgumentType.NUMBER,
|
||||
defaultValue: 0
|
||||
defaultValue: 50
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -386,6 +435,7 @@ class Scratch3VideoSensingBlocks {
|
|||
*/
|
||||
videoToggle (args) {
|
||||
const state = args.VIDEO_STATE;
|
||||
this.globalVideoState = state;
|
||||
if (state === VideoState.OFF) {
|
||||
this.runtime.ioDevices.video.disableVideo();
|
||||
} else {
|
||||
|
@ -403,6 +453,7 @@ class Scratch3VideoSensingBlocks {
|
|||
* preview to
|
||||
*/
|
||||
setVideoTransparency (args) {
|
||||
this.globalVideoTransparency = args.TRANSPARENCY;
|
||||
this.runtime.ioDevices.video.setPreviewGhost(Number(args.TRANSPARENCY));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue