overte-HifiExperiments/scripts/system/snapshot.js
David Kelly 1d7cdff2bc Snapshot button plus script
Minor change to allow snapshots to not notify (though the old way
with CTRL+S still does).  Added button to do it, saves them to disk.

The plan is for us to add UI to share (or not) the snapshot.  That's
why we are not going through the notifications.  Also, the
script makes sure to hide/unhide hud and overlays.  Next we will upload
the pick to AWS via data-web (if you are logged in), and _then_ make
the share UI.
2016-08-01 18:21:01 -07:00

66 lines
1.8 KiB
JavaScript

//
// snapshot.js
//
// Created by David Kelly on 1 August 2016
// Copyright 2016 High Fidelity, Inc
//
// Distributed under the Apache License, Version 2.0
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
var SNAPSHOT_DELAY = 500; // 500ms
var toolBar = Toolbars.getToolbar("com.highfidelity.interface.toolbar.system");
var resetOverlays;
var button = toolBar.addButton({
objectName: "snapshot",
imageURL: Script.resolvePath("assets/images/tools/snap.svg"),
visible: true,
buttonState: 1,
defaultState: 1,
hoverState: 1,
alpha: 0.9,
});
function onClicked() {
// update button states
resetOverlays = Menu.isOptionChecked("Overlays");
Window.snapshotTaken.connect(resetButtons);
button.writeProperty("buttonState", 0);
button.writeProperty("defaultState", 0);
button.writeProperty("hoverState", 2);
// hide overlays if they are on
if (resetOverlays) {
Menu.setIsOptionChecked("Overlays", false);
}
// hide hud
toolBar.writeProperty("visible", false);
// take snapshot (with no notification)
Script.setTimeout(function () {
Window.takeSnapshot(false);
}, SNAPSHOT_DELAY);
}
function resetButtons(path, notify) {
// show overlays if they were on
if (resetOverlays) {
Menu.setIsOptionChecked("Overlays", true);
}
// show hud
toolBar.writeProperty("visible", true);
// update button states
button.writeProperty("buttonState", 1);
button.writeProperty("defaultState", 1);
button.writeProperty("hoverState", 3);
Window.snapshotTaken.disconnect(resetButtons);
}
button.clicked.connect(onClicked);
Script.scriptEnding.connect(function () {
toolBar.removeButton("snapshot");
button.clicked.disconnect(onClicked);
});