add 3 second timer shutter function (fixes #2) - webgbcam - [fork] gameboy webcam
HTML git clone git://src.adamsgaard.dk/webgbcam
DIR Log
DIR Files
DIR Refs
DIR README
DIR LICENSE
---
DIR commit 90730d612a47d2933b00b32cb7f5914f07dbee7f
DIR parent 1b3def0c0e1f8a69b12cd0d53b0c98f205358a0e
HTML Author: Erin Pinheiro <hello@mynameiser.in>
Date: Sat, 31 Oct 2020 18:23:33 -0300
add 3 second timer shutter function (fixes #2)
Diffstat:
M app.js | 21 ++++++++++++++++++---
M index.html | 1 +
M sw.js | 5 +++--
M ui-main.png | 0
A ui-timer.png | 0
5 files changed, 22 insertions(+), 5 deletions(-)
---
DIR diff --git a/app.js b/app.js
@@ -189,7 +189,8 @@ const cameraStream = document.querySelector("#camera-stream"),
uiMain = document.querySelector("#ui-main"),
uiCapture = document.querySelector("#ui-capture"),
uiSettings = document.querySelector("#ui-settings"),
- uiHidden = document.querySelector("#ui-hidden");
+ uiHidden = document.querySelector("#ui-hidden"),
+ uiTimer = document.querySelector("#ui-timer");
var amountOfCameras = 0;
var currentFacingMode = 'user';
var appScale;
@@ -380,6 +381,12 @@ var buttons = {
y:0,
width:15,
height:15
+ },
+ timer: {
+ x:33,
+ y:131,
+ width:13,
+ height:13
}
};
@@ -543,6 +550,11 @@ function restartCamera() {
window.onorientationchange = restartCamera;
window.onresize = restartCamera;
+function captureImage() {
+ cameraStream.pause();
+ currentUI = uiCapture;
+}
+
function initCameraUI() {
initAppScaling();
@@ -554,8 +566,7 @@ function initCameraUI() {
if(currentUI === uiMain) {
if(isInside(mousePos, buttons.bottomLeft) || isInside(mousePos, buttons.screenHotspot)) {
// shutter
- cameraStream.pause();
- currentUI = uiCapture;
+ captureImage();
} else if(isInside(mousePos, buttons.bottomRight)) {
// switch camera
switchCameras();
@@ -565,6 +576,10 @@ function initCameraUI() {
} else if(isInside(mousePos, buttons.hideUI)) {
// hide UI buttons
currentUI = uiHidden;
+ } else if(isInside(mousePos, buttons.timer)) {
+ // change UI to timer and trigger 3s delay to capture
+ currentUI = uiTimer;
+ setTimeout(captureImage, 3000);
}
} else if(currentUI === uiCapture) {
if(isInside(mousePos, buttons.bottomLeft)) {
DIR diff --git a/index.html b/index.html
@@ -42,6 +42,7 @@
<img src="ui-settings.png" id="ui-settings" />
<img src="ui-capture.png" id="ui-capture" />
<img src="ui-hidden.png" id="ui-hidden" />
+ <img src="ui-timer.png" id="ui-timer" />
</div>
<script src="app.js"></script>
DIR diff --git a/sw.js b/sw.js
@@ -1,4 +1,4 @@
-const cacheName = 'webgbcam-v1'
+const cacheName = 'webgbcam-v2'
self.addEventListener('install', function(e) {
e.waitUntil(
@@ -13,7 +13,8 @@ self.addEventListener('install', function(e) {
'ui-capture.png',
'ui-settings.png',
'ui-main.png',
- 'ui-hidden.png'
+ 'ui-hidden.png',
+ 'ui-timer.png'
]);
})
);
DIR diff --git a/ui-main.png b/ui-main.png
Binary files differ.
DIR diff --git a/ui-timer.png b/ui-timer.png
Binary files differ.