mirror of
https://github.com/overte-org/overte.git
synced 2025-04-19 13:23:36 +02:00
Add directory button
This commit is contained in:
parent
94cd0762bd
commit
f51feca37d
2 changed files with 87 additions and 0 deletions
|
@ -18,3 +18,4 @@ Script.load("notifications.js");
|
|||
Script.load("users.js");
|
||||
Script.load("grab.js");
|
||||
Script.load("pointer.js");
|
||||
Script.load("directory.js");
|
||||
|
|
86
examples/directory.js
Normal file
86
examples/directory.js
Normal file
|
@ -0,0 +1,86 @@
|
|||
//
|
||||
// directory.js
|
||||
// examples
|
||||
//
|
||||
// Created by David Rowe on 8 Jun 2015
|
||||
// Copyright 2015 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
|
||||
//
|
||||
|
||||
Script.include("libraries/globals.js");
|
||||
|
||||
var directory = (function () {
|
||||
|
||||
var DIRECTORY_URL = "https://metaverse.highfidelity.com/directory",
|
||||
directoryWindow,
|
||||
DIRECTORY_BUTTON_URL = HIFI_PUBLIC_BUCKET + "images/tools/directory.svg",
|
||||
BUTTON_WIDTH = 50,
|
||||
BUTTON_HEIGHT = 50,
|
||||
BUTTON_ALPHA = 0.9,
|
||||
BUTTON_MARGIN = 8,
|
||||
directoryButton,
|
||||
viewport;
|
||||
|
||||
function updateButtonPosition() {
|
||||
Overlays.editOverlay(directoryButton, {
|
||||
x: viewport.x - BUTTON_WIDTH - BUTTON_MARGIN,
|
||||
y: BUTTON_MARGIN
|
||||
});
|
||||
}
|
||||
|
||||
function onMousePressEvent(event) {
|
||||
var clickedOverlay;
|
||||
|
||||
clickedOverlay = Overlays.getOverlayAtPoint({ x: event.x, y: event.y });
|
||||
|
||||
if (clickedOverlay === directoryButton) {
|
||||
if (directoryWindow.url !== DIRECTORY_URL) {
|
||||
directoryWindow.setURL(DIRECTORY_URL);
|
||||
}
|
||||
directoryWindow.setVisible(true);
|
||||
directoryWindow.raise();
|
||||
}
|
||||
}
|
||||
|
||||
function onScriptUpdate() {
|
||||
var oldViewport = viewport;
|
||||
|
||||
viewport = Controller.getViewportDimensions();
|
||||
|
||||
if (viewport.x !== oldViewport.x || viewport.y !== oldViewport.y) {
|
||||
updateButtonPosition();
|
||||
}
|
||||
}
|
||||
|
||||
function setUp() {
|
||||
viewport = Controller.getViewportDimensions();
|
||||
|
||||
directoryWindow = new WebWindow('Directory', DIRECTORY_URL, 900, 700, false);
|
||||
directoryWindow.setVisible(false);
|
||||
|
||||
directoryButton = Overlays.addOverlay("image", {
|
||||
imageURL: DIRECTORY_BUTTON_URL,
|
||||
width: BUTTON_WIDTH,
|
||||
height: BUTTON_HEIGHT,
|
||||
x: viewport.x - BUTTON_WIDTH - BUTTON_MARGIN,
|
||||
y: BUTTON_MARGIN,
|
||||
alpha: BUTTON_ALPHA,
|
||||
visible: true
|
||||
});
|
||||
|
||||
updateButtonPosition();
|
||||
|
||||
Controller.mousePressEvent.connect(onMousePressEvent);
|
||||
|
||||
Script.update.connect(onScriptUpdate);
|
||||
}
|
||||
|
||||
function tearDown() {
|
||||
Overlays.deleteOverlay(directoryButton);
|
||||
}
|
||||
|
||||
setUp();
|
||||
Script.scriptEnding.connect(tearDown);
|
||||
}());
|
Loading…
Reference in a new issue