From 6a65fa7c9c2f97fe5b263762b7379470d92d0f1f Mon Sep 17 00:00:00 2001 From: jmoenig Date: Wed, 8 May 2019 00:45:22 +0200 Subject: [PATCH] integrated video capture control into global settings prims in Sensing --- HISTORY.md | 3 +++ snap.html | 6 +++--- src/blocks.js | 6 ++++-- src/objects.js | 17 ++++++----------- src/threads.js | 37 ++++++++++++++++++++++++++++++------- 5 files changed, 46 insertions(+), 23 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index 9e4b113c..8568f9d8 100755 --- a/HISTORY.md +++ b/HISTORY.md @@ -77,6 +77,9 @@ * German * French +### 2019-05-08 +* Blocks, Objects, Threads: integrated video capture control into global settings prims in Sensing + ### 2019-05-07 * Blocks, Objects, Threads, Video: optimized video motion detection * Objects: actually stop the webcam, i.e. all tracks of the media stream when stopping video diff --git a/snap.html b/snap.html index 524337aa..860e7f90 100755 --- a/snap.html +++ b/snap.html @@ -6,9 +6,9 @@ - - - + + + diff --git a/src/blocks.js b/src/blocks.js index 993532e4..702be911 100644 --- a/src/blocks.js +++ b/src/blocks.js @@ -148,7 +148,7 @@ CustomCommandBlockMorph, SymbolMorph, ToggleButtonMorph, DialMorph*/ // Global stuff //////////////////////////////////////////////////////// -modules.blocks = '2019-May-07'; +modules.blocks = '2019-May-08'; var SyntaxElementMorph; var BlockMorph; @@ -1441,7 +1441,9 @@ SyntaxElementMorph.prototype.labelPart = function (spec) { false, { 'turbo mode' : ['turbo mode'], - 'flat line ends' : ['flat line ends'] + 'flat line ends' : ['flat line ends'], + 'video capture' : ['video capture'], + 'mirror video' : ['mirror video'] }, true ); diff --git a/src/objects.js b/src/objects.js index fffe1b9c..04ab2c29 100644 --- a/src/objects.js +++ b/src/objects.js @@ -84,7 +84,7 @@ BlockEditorMorph, BlockDialogMorph, PrototypeHatBlockMorph, localize, TableMorph, TableFrameMorph, normalizeCanvas, BooleanSlotMorph, HandleMorph, AlignmentMorph, Process, XML_Element, VectorPaintEditorMorph*/ -modules.objects = '2019-May-07'; +modules.objects = '2019-May-08'; var SpriteMorph; var StageMorph; @@ -1360,13 +1360,8 @@ SpriteMorph.prototype.initBlocks = function () { category: 'other', spec: 'code of %cmdRing' }, + // Video motion - doSetVideo: { - type: 'command', - category: 'sensing', - spec: 'turn video %vid', - defaults: ['on'] - }, doSetVideoTransparency: { type: 'command', category: 'sensing', @@ -2337,7 +2332,6 @@ SpriteMorph.prototype.blockTemplates = function (category) { blocks.push('-'); if (SpriteMorph.prototype.enableVideo) { - blocks.push(block('doSetVideo')); blocks.push(block('doSetVideoTransparency')); blocks.push(block('reportMotionOn')); blocks.push('-'); @@ -7011,7 +7005,9 @@ StageMorph.prototype.init = function (globals) { this.remixID = null; + // video motion detection, do not persist this.cameraCanvas = null; + this.mirrorVideo = true; this.videoElement = null; this.videoTransparency = 50; this.videoMotion = null; @@ -7274,7 +7270,7 @@ StageMorph.prototype.colorFiltered = function (aColor, excludedSprite) { return morph; }; -StageMorph.prototype.startVideo = function(isFlipped) { +StageMorph.prototype.startVideo = function() { var myself = this; function noCameraSupport() { @@ -7304,7 +7300,7 @@ StageMorph.prototype.startVideo = function(isFlipped) { this.videoElement.hidden = true; document.body.appendChild(this.videoElement); } - this.videoElement.isFlipped = isFlipped; + this.videoElement.isFlipped = !this.mirrorVideo; if (!this.videoMotion) { this.videoMotion = new VideoMotion( this.dimensions.x, @@ -8056,7 +8052,6 @@ StageMorph.prototype.blockTemplates = function (category) { blocks.push('-'); if (SpriteMorph.prototype.enableVideo) { - blocks.push(block('doSetVideo')); blocks.push(block('doSetVideoTransparency')); blocks.push(block('reportMotionOnStage')); blocks.push('-'); diff --git a/src/threads.js b/src/threads.js index ee5b5032..b3cf4078 100644 --- a/src/threads.js +++ b/src/threads.js @@ -61,7 +61,7 @@ StageMorph, SpriteMorph, StagePrompterMorph, Note, modules, isString, copy, isNil, WatcherMorph, List, ListWatcherMorph, alert, console, TableMorph, Color, TableFrameMorph, ColorSlotMorph, isSnapObject, Map, newCanvas, Symbol*/ -modules.threads = '2019-May-07'; +modules.threads = '2019-May-08'; var ThreadManager; var Process; @@ -2021,23 +2021,46 @@ Process.prototype.reportIsFastTracking = function () { }; Process.prototype.doSetGlobalFlag = function (name, bool) { + var stage = this.homeContext.receiver.parentThatIsA(StageMorph); name = this.inputOption(name); this.assertType(bool, 'Boolean'); - if (name === 'turbo mode') { + switch (name) { + case 'turbo mode': this.doSetFastTracking(bool); - } - if (name === 'flat line ends') { + break; + case 'flat line ends': SpriteMorph.prototype.useFlatLineEnds = bool; + break; + case 'video capture': + if (bool) { + stage.startVideo(); + } else { + stage.stopVideo(); + } + break; + case 'mirror video': + stage.mirrorVideo = bool; + if (stage.videoElement) { + stage.videoElement.isFlipped = !bool; + } + break; } }; Process.prototype.reportGlobalFlag = function (name) { + var stage = this.homeContext.receiver.parentThatIsA(StageMorph); name = this.inputOption(name); - if (name === 'turbo mode') { + switch (name) { + case 'turbo mode': return this.reportIsFastTracking(); - } - if (name === 'flat line ends') { + case 'flat line ends': return SpriteMorph.prototype.useFlatLineEnds; + case 'video capture': + return !isNil(stage.videoElement); + case 'mirror video': + return stage.mirrorVideo; + default: + return ''; } };