Merge pull request #1042 from mzgoddard/target-video-state

Configure video device with stage video settings
This commit is contained in:
kchadha 2018-04-13 09:12:25 -04:00 committed by GitHub
commit 0e0d09c235
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 65 additions and 6 deletions

View file

@ -80,10 +80,17 @@ class Scratch3VideoSensingBlocks {
// Clear target motion state values when the project starts. // Clear target motion state values when the project starts.
this.runtime.on(Runtime.PROJECT_RUN_START, this.reset.bind(this)); this.runtime.on(Runtime.PROJECT_RUN_START, this.reset.bind(this));
// Boot up the video, canvas to down/up sample the video stream, the // Kick off looping the analysis logic.
// preview skin and drawable, and kick off looping the analysis
// logic.
this._loop(); 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 * 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 * for example old frames, so the first analyzed frame will not be compared
@ -337,7 +386,7 @@ class Scratch3VideoSensingBlocks {
arguments: { arguments: {
TRANSPARENCY: { TRANSPARENCY: {
type: ArgumentType.NUMBER, type: ArgumentType.NUMBER,
defaultValue: 0 defaultValue: 50
} }
} }
} }
@ -407,6 +456,7 @@ class Scratch3VideoSensingBlocks {
*/ */
videoToggle (args) { videoToggle (args) {
const state = args.VIDEO_STATE; const state = args.VIDEO_STATE;
this.globalVideoState = state;
if (state === VideoState.OFF) { if (state === VideoState.OFF) {
this.runtime.ioDevices.video.disableVideo(); this.runtime.ioDevices.video.disableVideo();
} else { } else {
@ -424,6 +474,7 @@ class Scratch3VideoSensingBlocks {
* preview to * preview to
*/ */
setVideoTransparency (args) { setVideoTransparency (args) {
this.globalVideoTransparency = args.TRANSPARENCY;
this.runtime.ioDevices.video.setPreviewGhost(Number(args.TRANSPARENCY)); this.runtime.ioDevices.video.setPreviewGhost(Number(args.TRANSPARENCY));
} }
} }

View file

@ -140,9 +140,17 @@ class RenderedTarget extends Target {
/** /**
* The state of the video input (used by extensions with camera input). * The state of the video input (used by extensions with camera input).
* This property is global to the project and stored in the stage. * 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} * @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. * Available states for video input.
* @type {object} * @enum {string}
*/ */
static get VIDEO_STATE () { static get VIDEO_STATE () {
return { return {