From adcbb0b7606d4a80daaf49a270897e7b7c534fa1 Mon Sep 17 00:00:00 2001 From: Zach Fox Date: Mon, 14 Nov 2016 18:09:00 -0800 Subject: [PATCH] Code clarity and potential bugfix --- interface/src/ui/SnapshotAnimated.cpp | 36 +++++++++--------- scripts/system/html/js/SnapshotReview.js | 47 ++++++++++++------------ 2 files changed, 42 insertions(+), 41 deletions(-) diff --git a/interface/src/ui/SnapshotAnimated.cpp b/interface/src/ui/SnapshotAnimated.cpp index a9c6394426..80f0077184 100644 --- a/interface/src/ui/SnapshotAnimated.cpp +++ b/interface/src/ui/SnapshotAnimated.cpp @@ -45,50 +45,50 @@ void SnapshotAnimated::saveSnapshotAnimated(bool includeAnimated, QString pathSt frame = frame.convertToFormat(QImage::Format_RGBA8888); // If this is the first frame... - if (snapshotAnimatedTimestamp == 0) + if (SnapshotAnimated::snapshotAnimatedTimestamp == 0) { // Write out the header and beginning of the GIF file - GifBegin(&(snapshotAnimatedGifWriter), qPrintable(pathAnimatedSnapshot), frame.width(), frame.height(), SNAPSNOT_ANIMATED_FRAME_DELAY_MSEC / 10); + GifBegin(&(SnapshotAnimated::snapshotAnimatedGifWriter), qPrintable(pathAnimatedSnapshot), frame.width(), frame.height(), SNAPSNOT_ANIMATED_FRAME_DELAY_MSEC / 10); // Write the first to the gif - GifWriteFrame(&(snapshotAnimatedGifWriter), + GifWriteFrame(&(SnapshotAnimated::snapshotAnimatedGifWriter), (uint8_t*)frame.bits(), frame.width(), frame.height(), SNAPSNOT_ANIMATED_FRAME_DELAY_MSEC / 10); // Record the current frame timestamp - snapshotAnimatedTimestamp = QDateTime::currentMSecsSinceEpoch(); - snapshotAnimatedFirstFrameTimestamp = snapshotAnimatedTimestamp; + SnapshotAnimated::snapshotAnimatedTimestamp = QDateTime::currentMSecsSinceEpoch(); + SnapshotAnimated::snapshotAnimatedFirstFrameTimestamp = SnapshotAnimated::snapshotAnimatedTimestamp; } else { // If that was the last frame... - if ((snapshotAnimatedTimestamp - snapshotAnimatedFirstFrameTimestamp) >= (SNAPSNOT_ANIMATED_DURATION_SECS * 1000)) + if ((SnapshotAnimated::snapshotAnimatedTimestamp - SnapshotAnimated::snapshotAnimatedFirstFrameTimestamp) >= (SNAPSNOT_ANIMATED_DURATION_SECS * 1000)) { - // Reset the current frame timestamp - snapshotAnimatedTimestamp = 0; - snapshotAnimatedFirstFrameTimestamp = 0; - // Write out the end of the GIF - GifEnd(&(snapshotAnimatedGifWriter)); // Stop the snapshot QTimer - snapshotAnimatedTimer.stop(); + SnapshotAnimated::snapshotAnimatedTimer.stop(); + // Reset the current frame timestamp + SnapshotAnimated::snapshotAnimatedTimestamp = 0; + SnapshotAnimated::snapshotAnimatedFirstFrameTimestamp = 0; + // Write out the end of the GIF + GifEnd(&(SnapshotAnimated::snapshotAnimatedGifWriter)); + // Let the dependency manager know that the snapshots have been taken. emit dm->snapshotTaken(pathStillSnapshot, pathAnimatedSnapshot, false); - qDebug() << "still: " << pathStillSnapshot << "anim: " << pathAnimatedSnapshot; - //emit dm->snapshotTaken("C:\\Users\\Zach Fox\\Desktop\\hifi-snap-by-zfox-on-2016-11-14_17-07-33.jpg", "C:\\Users\\Zach Fox\\Desktop\\hifi-snap-by-zfox-on-2016-11-14_17-10-02.gif", false); } + // If that was an intermediate frame... else { // Variable used to determine how long the current frame took to pack qint64 framePackStartTime = QDateTime::currentMSecsSinceEpoch(); // Write the frame to the gif - GifWriteFrame(&(snapshotAnimatedGifWriter), + GifWriteFrame(&(SnapshotAnimated::snapshotAnimatedGifWriter), (uint8_t*)frame.bits(), frame.width(), frame.height(), - round(((float)(QDateTime::currentMSecsSinceEpoch() - snapshotAnimatedTimestamp + snapshotAnimatedLastWriteFrameDuration)) / 10)); + round(((float)(QDateTime::currentMSecsSinceEpoch() - SnapshotAnimated::snapshotAnimatedTimestamp + SnapshotAnimated::snapshotAnimatedLastWriteFrameDuration)) / 10)); // Record how long it took for the current frame to pack - snapshotAnimatedLastWriteFrameDuration = QDateTime::currentMSecsSinceEpoch() - framePackStartTime; + SnapshotAnimated::snapshotAnimatedLastWriteFrameDuration = QDateTime::currentMSecsSinceEpoch() - framePackStartTime; // Record the current frame timestamp - snapshotAnimatedTimestamp = QDateTime::currentMSecsSinceEpoch(); + SnapshotAnimated::snapshotAnimatedTimestamp = QDateTime::currentMSecsSinceEpoch(); } } }); diff --git a/scripts/system/html/js/SnapshotReview.js b/scripts/system/html/js/SnapshotReview.js index ccd70c40b2..b2b7030b73 100644 --- a/scripts/system/html/js/SnapshotReview.js +++ b/scripts/system/html/js/SnapshotReview.js @@ -12,30 +12,31 @@ var paths = [], idCounter = 0, useCheckboxes; function addImage(data) { - if (data.localPath) { - var div = document.createElement("DIV"), - input = document.createElement("INPUT"), - label = document.createElement("LABEL"), - img = document.createElement("IMG"), - id = "p" + idCounter++; - function toggle() { data.share = input.checked; } - img.src = data.localPath; - div.appendChild(img); - data.share = true; - if (useCheckboxes) { // I'd rather use css, but the included stylesheet is quite particular. - // Our stylesheet(?) requires input.id to match label.for. Otherwise input doesn't display the check state. - label.setAttribute('for', id); // cannot do label.for = - input.id = id; - input.type = "checkbox"; - input.checked = (id === "p0"); - input.addEventListener('change', toggle); - div.class = "property checkbox"; - div.appendChild(input); - div.appendChild(label); - } - document.getElementById("snapshot-images").appendChild(div); - paths.push(data); + if (!data.localPath) { + return; } + var div = document.createElement("DIV"), + input = document.createElement("INPUT"), + label = document.createElement("LABEL"), + img = document.createElement("IMG"), + id = "p" + idCounter++; + function toggle() { data.share = input.checked; } + img.src = data.localPath; + div.appendChild(img); + data.share = true; + if (useCheckboxes) { // I'd rather use css, but the included stylesheet is quite particular. + // Our stylesheet(?) requires input.id to match label.for. Otherwise input doesn't display the check state. + label.setAttribute('for', id); // cannot do label.for = + input.id = id; + input.type = "checkbox"; + input.checked = (id === "p0"); + input.addEventListener('change', toggle); + div.class = "property checkbox"; + div.appendChild(input); + div.appendChild(label); + } + document.getElementById("snapshot-images").appendChild(div); + paths.push(data); } function handleShareButtons(shareMsg) { var openFeed = document.getElementById('openFeed');