mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-23 14:32:59 -05:00
Merge pull request #1042 from mzgoddard/target-video-state
Configure video device with stage video settings
This commit is contained in:
commit
0e0d09c235
2 changed files with 65 additions and 6 deletions
|
@ -80,10 +80,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
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -125,6 +132,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
|
||||
|
@ -337,7 +386,7 @@ class Scratch3VideoSensingBlocks {
|
|||
arguments: {
|
||||
TRANSPARENCY: {
|
||||
type: ArgumentType.NUMBER,
|
||||
defaultValue: 0
|
||||
defaultValue: 50
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -407,6 +456,7 @@ class Scratch3VideoSensingBlocks {
|
|||
*/
|
||||
videoToggle (args) {
|
||||
const state = args.VIDEO_STATE;
|
||||
this.globalVideoState = state;
|
||||
if (state === VideoState.OFF) {
|
||||
this.runtime.ioDevices.video.disableVideo();
|
||||
} else {
|
||||
|
@ -424,6 +474,7 @@ class Scratch3VideoSensingBlocks {
|
|||
* preview to
|
||||
*/
|
||||
setVideoTransparency (args) {
|
||||
this.globalVideoTransparency = args.TRANSPARENCY;
|
||||
this.runtime.ioDevices.video.setPreviewGhost(Number(args.TRANSPARENCY));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -140,9 +140,17 @@ class RenderedTarget extends Target {
|
|||
/**
|
||||
* The state of the video input (used by extensions with camera input).
|
||||
* This property is global to the project and stored in the stage.
|
||||
*
|
||||
* Defaults to ON. This setting does not turn the video by itself. A
|
||||
* video extension once loaded will set the video device to this
|
||||
* setting. Set to ON when a video extension is added in the editor the
|
||||
* video will start ON. If the extension is loaded as part of loading a
|
||||
* saved project the extension will see the value set when the stage
|
||||
* was loaded from the saved values including the video state.
|
||||
*
|
||||
* @type {string}
|
||||
*/
|
||||
this.videoState = RenderedTarget.VIDEO_STATE.OFF;
|
||||
this.videoState = RenderedTarget.VIDEO_STATE.ON;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -211,7 +219,7 @@ class RenderedTarget extends Target {
|
|||
|
||||
/**
|
||||
* Available states for video input.
|
||||
* @type {object}
|
||||
* @enum {string}
|
||||
*/
|
||||
static get VIDEO_STATE () {
|
||||
return {
|
||||
|
|
Loading…
Reference in a new issue