mirror of
https://github.com/overte-org/overte.git
synced 2025-08-06 19:59:28 +02:00
Fix the timer display
This commit is contained in:
parent
b954d5b0e9
commit
6b26f5f3a3
1 changed files with 26 additions and 24 deletions
|
@ -9,6 +9,8 @@
|
||||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
//
|
//
|
||||||
|
|
||||||
|
/* globals HIFI_PUBLIC_BUCKET:true, Tool, ToolBar */
|
||||||
|
|
||||||
HIFI_PUBLIC_BUCKET = "http://s3.amazonaws.com/hifi-public/";
|
HIFI_PUBLIC_BUCKET = "http://s3.amazonaws.com/hifi-public/";
|
||||||
Script.include("/~/system/libraries/toolBars.js");
|
Script.include("/~/system/libraries/toolBars.js");
|
||||||
|
|
||||||
|
@ -47,7 +49,7 @@ setupTimer();
|
||||||
var watchStop = false;
|
var watchStop = false;
|
||||||
|
|
||||||
function setupToolBar() {
|
function setupToolBar() {
|
||||||
if (toolBar != null) {
|
if (toolBar !== null) {
|
||||||
print("Multiple calls to Recorder.js:setupToolBar()");
|
print("Multiple calls to Recorder.js:setupToolBar()");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -112,15 +114,15 @@ function setupTimer() {
|
||||||
text: (0.00).toFixed(3),
|
text: (0.00).toFixed(3),
|
||||||
backgroundColor: COLOR_OFF,
|
backgroundColor: COLOR_OFF,
|
||||||
x: 0, y: 0,
|
x: 0, y: 0,
|
||||||
width: 0, height: 0,
|
width: 200, height: 37,
|
||||||
leftMargin: 10, topMargin: 10,
|
leftMargin: 5, topMargin: 10,
|
||||||
alpha: 1.0, backgroundAlpha: 1.0,
|
alpha: 1.0, backgroundAlpha: 1.0,
|
||||||
visible: true
|
visible: true
|
||||||
});
|
});
|
||||||
|
|
||||||
slider = { x: 0, y: 0,
|
slider = { x: 0, y: 0,
|
||||||
w: 200, h: 20,
|
w: 200, h: 20,
|
||||||
pos: 0.0, // 0.0 <= pos <= 1.0
|
pos: 0.0 // 0.0 <= pos <= 1.0
|
||||||
};
|
};
|
||||||
slider.background = Overlays.addOverlay("text", {
|
slider.background = Overlays.addOverlay("text", {
|
||||||
text: "",
|
text: "",
|
||||||
|
@ -148,16 +150,17 @@ function updateTimer() {
|
||||||
var text = "";
|
var text = "";
|
||||||
if (Recording.isRecording()) {
|
if (Recording.isRecording()) {
|
||||||
text = formatTime(Recording.recorderElapsed());
|
text = formatTime(Recording.recorderElapsed());
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
text = formatTime(Recording.playerElapsed()) + " / " +
|
text = formatTime(Recording.playerElapsed()) + " / " + formatTime(Recording.playerLength());
|
||||||
formatTime(Recording.playerLength());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var timerWidth = text.length * 8 + ((Recording.isRecording()) ? 15 : 0);
|
||||||
|
|
||||||
Overlays.editOverlay(timer, {
|
Overlays.editOverlay(timer, {
|
||||||
text: text
|
text: text,
|
||||||
})
|
width: timerWidth
|
||||||
toolBar.changeSpacing(text.length * 8 + ((Recording.isRecording()) ? 15 : 0), spacing);
|
});
|
||||||
|
toolBar.changeSpacing(timerWidth, spacing);
|
||||||
|
|
||||||
if (Recording.isRecording()) {
|
if (Recording.isRecording()) {
|
||||||
slider.pos = 1.0;
|
slider.pos = 1.0;
|
||||||
|
@ -173,7 +176,7 @@ function updateTimer() {
|
||||||
function formatTime(time) {
|
function formatTime(time) {
|
||||||
var MIN_PER_HOUR = 60;
|
var MIN_PER_HOUR = 60;
|
||||||
var SEC_PER_MIN = 60;
|
var SEC_PER_MIN = 60;
|
||||||
var MSEC_PER_SEC = 1000;
|
var MSEC_DIGITS = 3;
|
||||||
|
|
||||||
var hours = Math.floor(time / (SEC_PER_MIN * MIN_PER_HOUR));
|
var hours = Math.floor(time / (SEC_PER_MIN * MIN_PER_HOUR));
|
||||||
time -= hours * (SEC_PER_MIN * MIN_PER_HOUR);
|
time -= hours * (SEC_PER_MIN * MIN_PER_HOUR);
|
||||||
|
@ -184,11 +187,9 @@ function formatTime(time) {
|
||||||
var seconds = time;
|
var seconds = time;
|
||||||
|
|
||||||
var text = "";
|
var text = "";
|
||||||
text += (hours > 0) ? hours + ":" :
|
text += (hours > 0) ? hours + ":" : "";
|
||||||
"";
|
text += (minutes > 0) ? ((minutes < 10 && text !== "") ? "0" : "") + minutes + ":" : "";
|
||||||
text += (minutes > 0) ? ((minutes < 10 && text != "") ? "0" : "") + minutes + ":" :
|
text += ((seconds < 10 && text !== "") ? "0" : "") + seconds.toFixed(MSEC_DIGITS);
|
||||||
"";
|
|
||||||
text += ((seconds < 10 && text != "") ? "0" : "") + seconds.toFixed(3);
|
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -205,16 +206,16 @@ function moveUI() {
|
||||||
|
|
||||||
Overlays.editOverlay(slider.background, {
|
Overlays.editOverlay(slider.background, {
|
||||||
x: slider.x,
|
x: slider.x,
|
||||||
y: slider.y,
|
y: slider.y
|
||||||
});
|
});
|
||||||
Overlays.editOverlay(slider.foreground, {
|
Overlays.editOverlay(slider.foreground, {
|
||||||
x: slider.x,
|
x: slider.x,
|
||||||
y: slider.y,
|
y: slider.y
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function mousePressEvent(event) {
|
function mousePressEvent(event) {
|
||||||
clickedOverlay = Overlays.getOverlayAtPoint({ x: event.x, y: event.y });
|
var clickedOverlay = Overlays.getOverlayAtPoint({ x: event.x, y: event.y });
|
||||||
|
|
||||||
if (recordIcon === toolBar.clicked(clickedOverlay, false) && !Recording.isPlaying()) {
|
if (recordIcon === toolBar.clicked(clickedOverlay, false) && !Recording.isPlaying()) {
|
||||||
if (!Recording.isRecording()) {
|
if (!Recording.isRecording()) {
|
||||||
|
@ -226,7 +227,8 @@ function mousePressEvent(event) {
|
||||||
toolBar.setAlpha(ALPHA_OFF, loadIcon);
|
toolBar.setAlpha(ALPHA_OFF, loadIcon);
|
||||||
} else {
|
} else {
|
||||||
Recording.stopRecording();
|
Recording.stopRecording();
|
||||||
toolBar.selectTool(recordIcon, true );
|
toolBar.selectTool(recordIcon, true);
|
||||||
|
Recording.setPlayerTime(0);
|
||||||
Recording.loadLastRecording();
|
Recording.loadLastRecording();
|
||||||
toolBar.setAlpha(ALPHA_ON, playIcon);
|
toolBar.setAlpha(ALPHA_ON, playIcon);
|
||||||
toolBar.setAlpha(ALPHA_ON, playLoopIcon);
|
toolBar.setAlpha(ALPHA_ON, playLoopIcon);
|
||||||
|
@ -263,7 +265,7 @@ function mousePressEvent(event) {
|
||||||
toolBar.setAlpha(ALPHA_OFF, loadIcon);
|
toolBar.setAlpha(ALPHA_OFF, loadIcon);
|
||||||
}
|
}
|
||||||
} else if (saveIcon === toolBar.clicked(clickedOverlay)) {
|
} else if (saveIcon === toolBar.clicked(clickedOverlay)) {
|
||||||
if (!Recording.isRecording() && !Recording.isPlaying() && Recording.playerLength() != 0) {
|
if (!Recording.isRecording() && !Recording.isPlaying() && Recording.playerLength() !== 0) {
|
||||||
recordingFile = Window.save("Save recording to file", ".", "Recordings (*.hfr)");
|
recordingFile = Window.save("Save recording to file", ".", "Recordings (*.hfr)");
|
||||||
if (!(recordingFile === "null" || recordingFile === null || recordingFile === "")) {
|
if (!(recordingFile === "null" || recordingFile === null || recordingFile === "")) {
|
||||||
Recording.saveRecording(recordingFile);
|
Recording.saveRecording(recordingFile);
|
||||||
|
@ -282,8 +284,8 @@ function mousePressEvent(event) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (Recording.playerLength() > 0 &&
|
} else if (Recording.playerLength() > 0 &&
|
||||||
slider.x < event.x && event.x < slider.x + slider.w &&
|
slider.x < event.x && event.x < slider.x + slider.w &&
|
||||||
slider.y < event.y && event.y < slider.y + slider.h) {
|
slider.y < event.y && event.y < slider.y + slider.h) {
|
||||||
isSliding = true;
|
isSliding = true;
|
||||||
slider.pos = (event.x - slider.x) / slider.w;
|
slider.pos = (event.x - slider.x) / slider.w;
|
||||||
Recording.setPlayerTime(slider.pos * Recording.playerLength());
|
Recording.setPlayerTime(slider.pos * Recording.playerLength());
|
||||||
|
@ -308,7 +310,7 @@ function mouseReleaseEvent(event) {
|
||||||
|
|
||||||
function update() {
|
function update() {
|
||||||
var newDimensions = Controller.getViewportDimensions();
|
var newDimensions = Controller.getViewportDimensions();
|
||||||
if (windowDimensions.x != newDimensions.x || windowDimensions.y != newDimensions.y) {
|
if (windowDimensions.x !== newDimensions.x || windowDimensions.y !== newDimensions.y) {
|
||||||
windowDimensions = newDimensions;
|
windowDimensions = newDimensions;
|
||||||
moveUI();
|
moveUI();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue