From d0f01fdec2c36cc491c5af0dec97081f548feaaa Mon Sep 17 00:00:00 2001 From: pacien Date: Thu, 19 Jul 2018 00:50:11 +0200 Subject: Add timer --- pointless/viewer/screen.js | 9 ++++++++- pointless/viewer/stage.js | 4 ++-- pointless/viewer/timer.js | 37 +++++++++++++++++++++++++++++++++++++ pointless/viewer/viewer.css | 16 ++++++++++++++++ 4 files changed, 63 insertions(+), 3 deletions(-) create mode 100644 pointless/viewer/timer.js (limited to 'pointless') diff --git a/pointless/viewer/screen.js b/pointless/viewer/screen.js index 0c1c3ad..28f4f55 100644 --- a/pointless/viewer/screen.js +++ b/pointless/viewer/screen.js @@ -8,7 +8,7 @@ "use strict"; class Screen { - constructor(window, secondary=false) { + constructor(window, secondary=false, withTimer=false) { this.window = window; this.secondary = secondary; this.canvas = window.document.getElementById("screen"); @@ -19,11 +19,18 @@ class Screen { this.window.addEventListener("resize", function() { self._refreshPage(); }); + + this.timer = withTimer ? new Timer(window) : null; + this.pageTurnCount = 0; } setPage(page) { + if (this.pageTurnCount === 1 && this.timer != null) + this.timer.start(); + this.page = page; this._refreshPage(); + this.pageTurnCount++; } _resizeScreen(ratio) { diff --git a/pointless/viewer/stage.js b/pointless/viewer/stage.js index 8c36981..68fdb45 100644 --- a/pointless/viewer/stage.js +++ b/pointless/viewer/stage.js @@ -17,8 +17,8 @@ class Stage { var self = this; this.projector.addEventListener("load", function() { - self.audienceScreen = new Screen(self.projector, false); - self.presenterScreen = new Screen(window, true); + self.audienceScreen = new Screen(self.projector, false, false); + self.presenterScreen = new Screen(window, true, true); onReady(); }); diff --git a/pointless/viewer/timer.js b/pointless/viewer/timer.js new file mode 100644 index 0000000..4f19986 --- /dev/null +++ b/pointless/viewer/timer.js @@ -0,0 +1,37 @@ +/* + * timer.js + * Part of Pointless Viewer, a Beamer presentation viewer + * Copyright 2018 Pacien TRAN-GIRARD + * License: GNU GPL v3 + */ + +"use strict"; + +class Timer { + constructor(window) { + this.display = window.document.getElementById("timer"); + this.startTime = null; + this._setDisplay(0); + } + + start() { + if (this.startTime != null) return; + this.startTime = Date.now(); + + var self = this; + setInterval(function() { + self._runTimer(); + }, 1000); + } + + _runTimer() { + var timeDelta = Math.floor((Date.now() - this.startTime) / 1000); + this._setDisplay(timeDelta); + } + + _setDisplay(seconds) { + var dateObj = new Date(null); + dateObj.setSeconds(seconds); + this.display.textContent = dateObj.toISOString().substr(11, 8); + } +} diff --git a/pointless/viewer/viewer.css b/pointless/viewer/viewer.css index dee9802..14db376 100644 --- a/pointless/viewer/viewer.css +++ b/pointless/viewer/viewer.css @@ -17,3 +17,19 @@ body { left: 50%; transform: translateX(-50%) translateY(-50%); } + +.notification { + position: absolute; + bottom: 0; + left: 50%; + transform: translateX(-50%); + padding: 0.5rem 1rem; + border-radius: 1rem 1rem 0 0; + background-color: black; + font-family: sans-serif; + font-size: 1.6rem; +} + +.notification:empty { + display: none; +} -- cgit v1.2.3