ContextOverlay

This commit is contained in:
Zach Fox 2017-07-18 16:11:43 -07:00
parent 265f978a06
commit 8f6af3a1ab
8 changed files with 155 additions and 155 deletions

View file

@ -69,7 +69,7 @@
#include <EntityScriptClient.h>
#include <EntityScriptServerLogClient.h>
#include <EntityScriptingInterface.h>
#include "ui/overlays/HoverOverlayInterface.h"
#include "ui/overlays/ContextOverlayInterface.h"
#include <ErrorDialog.h>
#include <FileScriptingInterface.h>
#include <Finally.h>
@ -589,7 +589,7 @@ bool setupEssentials(int& argc, char** argv, bool runningMarkerExisted) {
DependencyManager::set<Snapshot>();
DependencyManager::set<CloseEventSender>();
DependencyManager::set<ResourceManager>();
DependencyManager::set<HoverOverlayInterface>();
DependencyManager::set<ContextOverlayInterface>();
return previousSessionCrashed;
}
@ -1325,7 +1325,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo
connect(overlays, &Overlays::mousePressOnOverlay, [=](const OverlayID& overlayID, const PointerEvent& event) {
auto thisOverlay = std::dynamic_pointer_cast<Web3DOverlay>(overlays->getOverlay(overlayID));
// Only Web overlays can have focus.
// Only Web overlays can have keyboard focus.
if (thisOverlay) {
setKeyboardFocusEntity(UNKNOWN_ENTITY_ID);
setKeyboardFocusOverlay(overlayID);
@ -1349,8 +1349,8 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo
connect(overlays,
SIGNAL(mousePressOnOverlay(const OverlayID&, const PointerEvent&)),
DependencyManager::get<HoverOverlayInterface>().data(),
SLOT(clickHoverOverlay(const OverlayID&, const PointerEvent&)));
DependencyManager::get<ContextOverlayInterface>().data(),
SLOT(clickContextOverlay(const OverlayID&, const PointerEvent&)));
// Add periodic checks to send user activity data
static int CHECK_NEARBY_AVATARS_INTERVAL_MS = 10000;
@ -2133,7 +2133,7 @@ void Application::initializeUi() {
surfaceContext->setContextProperty("ApplicationCompositor", &getApplicationCompositor());
surfaceContext->setContextProperty("AvatarInputs", AvatarInputs::getInstance());
surfaceContext->setContextProperty("HoverOverlay", DependencyManager::get<HoverOverlayInterface>().data());
surfaceContext->setContextProperty("ContextOverlay", DependencyManager::get<ContextOverlayInterface>().data());
if (auto steamClient = PluginManager::getInstance()->getSteamClientPlugin()) {
surfaceContext->setContextProperty("Steam", new SteamScriptingInterface(engine, steamClient.get()));
@ -5836,7 +5836,7 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEngine* scri
auto entityScriptServerLog = DependencyManager::get<EntityScriptServerLogClient>();
scriptEngine->registerGlobalObject("EntityScriptServerLog", entityScriptServerLog.data());
scriptEngine->registerGlobalObject("AvatarInputs", AvatarInputs::getInstance());
scriptEngine->registerGlobalObject("HoverOverlay", DependencyManager::get<HoverOverlayInterface>().data());
scriptEngine->registerGlobalObject("ContextOverlay", DependencyManager::get<ContextOverlayInterface>().data());
qScriptRegisterMetaType(scriptEngine, OverlayIDtoScriptValue, OverlayIDfromScriptValue);

View file

@ -0,0 +1,74 @@
//
// ContextOverlayInterface.cpp
// interface/src/ui/overlays
//
// Created by Zach Fox on 2017-07-14.
// Copyright 2017 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
//
#include "ContextOverlayInterface.h"
#include "Application.h"
#include <EntityTreeRenderer.h>
ContextOverlayInterface::ContextOverlayInterface() {
// "context_overlay" debug log category disabled by default.
// Create your own "qtlogging.ini" file and set your "QT_LOGGING_CONF" environment variable
// if you'd like to enable/disable certain categories.
// More details: http://doc.qt.io/qt-5/qloggingcategory.html#configuring-categories
QLoggingCategory::setFilterRules(QStringLiteral("hifi.context_overlay.debug=false"));
_entityScriptingInterface = DependencyManager::get<EntityScriptingInterface>();
_entityPropertyFlags += PROP_POSITION;
_entityPropertyFlags += PROP_ROTATION;
auto entityTreeRenderer = DependencyManager::get<EntityTreeRenderer>().data();
connect(entityTreeRenderer, SIGNAL(hoverEnterEntity(const EntityItemID&, const PointerEvent&)), this, SLOT(createContextOverlay(const EntityItemID&, const PointerEvent&)));
connect(entityTreeRenderer, SIGNAL(hoverLeaveEntity(const EntityItemID&, const PointerEvent&)), this, SLOT(destroyContextOverlay(const EntityItemID&, const PointerEvent&)));
}
void ContextOverlayInterface::createContextOverlay(const EntityItemID& entityItemID, const PointerEvent& event) {
qCDebug(context_overlay) << "Creating Context Overlay on top of entity with ID: " << entityItemID;
setCurrentEntityWithContextOverlay(entityItemID);
EntityItemProperties entityProperties = _entityScriptingInterface->getEntityProperties(entityItemID, _entityPropertyFlags);
if (_contextOverlayID == UNKNOWN_OVERLAY_ID || !qApp->getOverlays().isAddedOverlay(_contextOverlayID)) {
_contextOverlay = std::make_shared<Image3DOverlay>();
_contextOverlay->setAlpha(1.0f);
_contextOverlay->setPulseMin(0.75f);
_contextOverlay->setPulseMax(1.0f);
_contextOverlay->setColorPulse(1.0f);
_contextOverlay->setIgnoreRayIntersection(false);
_contextOverlay->setDrawInFront(true);
_contextOverlay->setURL("http://i.imgur.com/gksZygp.png");
_contextOverlay->setIsFacingAvatar(true);
_contextOverlay->setDimensions(glm::vec2(0.2f, 0.2f) * glm::distance(entityProperties.getPosition(), qApp->getCamera().getPosition()));
_contextOverlayID = qApp->getOverlays().addOverlay(_contextOverlay);
}
_contextOverlay->setPosition(entityProperties.getPosition());
_contextOverlay->setRotation(entityProperties.getRotation());
_contextOverlay->setVisible(true);
}
void ContextOverlayInterface::destroyContextOverlay(const EntityItemID& entityItemID, const PointerEvent& event) {
qCDebug(context_overlay) << "Destroying Context Overlay on top of entity with ID: " << entityItemID;
setCurrentEntityWithContextOverlay(QUuid());
qApp->getOverlays().deleteOverlay(_contextOverlayID);
_contextOverlay = NULL;
_contextOverlayID = UNKNOWN_OVERLAY_ID;
}
void ContextOverlayInterface::destroyContextOverlay(const EntityItemID& entityItemID) {
ContextOverlayInterface::destroyContextOverlay(entityItemID, PointerEvent());
}
void ContextOverlayInterface::clickContextOverlay(const OverlayID& overlayID, const PointerEvent& event) {
if (overlayID == _contextOverlayID) {
qCDebug(context_overlay) << "Clicked Context Overlay. Entity ID:" << _currentEntityWithContextOverlay << "Overlay ID:" << overlayID;
}
}

View file

@ -0,0 +1,57 @@
//
// ContextOverlayInterface.h
// interface/src/ui/overlays
//
// Created by Zach Fox on 2017-07-14.
// Copyright 2017 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
//
#pragma once
#ifndef hifi_ContextOverlayInterface_h
#define hifi_ContextOverlayInterface_h
#include <QtCore/QObject>
#include <QUuid>
#include <DependencyManager.h>
#include <PointerEvent.h>
#include "EntityScriptingInterface.h"
#include "ui/overlays/Image3DOverlay.h"
#include "ui/overlays/Overlays.h"
#include "EntityTree.h"
#include "ContextOverlayLogging.h"
/**jsdoc
* @namespace ContextOverlay
*/
class ContextOverlayInterface : public QObject, public Dependency {
Q_OBJECT
Q_PROPERTY(QUuid entityWithContextOverlay READ getCurrentEntityWithContextOverlay WRITE setCurrentEntityWithContextOverlay)
QSharedPointer<EntityScriptingInterface> _entityScriptingInterface;
EntityPropertyFlags _entityPropertyFlags;
OverlayID _contextOverlayID { UNKNOWN_OVERLAY_ID };
std::shared_ptr<Image3DOverlay> _contextOverlay { nullptr };
public:
ContextOverlayInterface();
Q_INVOKABLE QUuid getCurrentEntityWithContextOverlay() { return _currentEntityWithContextOverlay; }
void setCurrentEntityWithContextOverlay(const QUuid& entityID) { _currentEntityWithContextOverlay = entityID; }
public slots:
void createContextOverlay(const EntityItemID& entityItemID, const PointerEvent& event);
void destroyContextOverlay(const EntityItemID& entityItemID, const PointerEvent& event);
void destroyContextOverlay(const EntityItemID& entityItemID);
void clickContextOverlay(const OverlayID& overlayID, const PointerEvent& event);
private:
bool _verboseLogging { true };
QUuid _currentEntityWithContextOverlay{};
};
#endif // hifi_ContextOverlayInterface_h

View file

@ -1,5 +1,5 @@
//
// HoverOverlayLogging.cpp
// ContextOverlayLogging.cpp
// interface/src/ui/overlays
//
// Created by Zach Fox on 2017-07-17
@ -9,6 +9,6 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#include "HoverOverlayLogging.h"
#include "ContextOverlayLogging.h"
Q_LOGGING_CATEGORY(hover_overlay, "hifi.hover_overlay")
Q_LOGGING_CATEGORY(context_overlay, "hifi.context_overlay")

View file

@ -1,5 +1,5 @@
//
// HoverOverlayLogging.h
// ContextOverlayLogging.h
// interface/src/ui/overlays
//
// Created by Zach Fox on 2017-07-17
@ -10,11 +10,11 @@
//
#pragma once
#ifndef hifi_HoverOverlayLogging_h
#define hifi_HoverOverlayLogging_h
#ifndef hifi_ContextOverlayLogging_h
#define hifi_ContextOverlayLogging_h
#include <QLoggingCategory>
Q_DECLARE_LOGGING_CATEGORY(hover_overlay)
Q_DECLARE_LOGGING_CATEGORY(context_overlay)
#endif // hifi_HoverOverlayLogging_h
#endif // hifi_ContextOverlayLogging_h

View file

@ -1,74 +0,0 @@
//
// HoverOverlayInterface.cpp
// interface/src/ui/overlays
//
// Created by Zach Fox on 2017-07-14.
// Copyright 2017 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
//
#include "HoverOverlayInterface.h"
#include "Application.h"
#include <EntityTreeRenderer.h>
HoverOverlayInterface::HoverOverlayInterface() {
// "hover_overlay" debug log category disabled by default.
// Create your own "qtlogging.ini" file and set your "QT_LOGGING_CONF" environment variable
// if you'd like to enable/disable certain categories.
// More details: http://doc.qt.io/qt-5/qloggingcategory.html#configuring-categories
QLoggingCategory::setFilterRules(QStringLiteral("hifi.hover_overlay.debug=false"));
_entityScriptingInterface = DependencyManager::get<EntityScriptingInterface>();
_entityPropertyFlags += PROP_POSITION;
_entityPropertyFlags += PROP_ROTATION;
auto entityTreeRenderer = DependencyManager::get<EntityTreeRenderer>().data();
connect(entityTreeRenderer, SIGNAL(hoverEnterEntity(const EntityItemID&, const PointerEvent&)), this, SLOT(createHoverOverlay(const EntityItemID&, const PointerEvent&)));
connect(entityTreeRenderer, SIGNAL(hoverLeaveEntity(const EntityItemID&, const PointerEvent&)), this, SLOT(destroyHoverOverlay(const EntityItemID&, const PointerEvent&)));
}
void HoverOverlayInterface::createHoverOverlay(const EntityItemID& entityItemID, const PointerEvent& event) {
qCDebug(hover_overlay) << "Creating Hover Overlay on top of entity with ID: " << entityItemID;
setCurrentHoveredEntity(entityItemID);
EntityItemProperties entityProperties = _entityScriptingInterface->getEntityProperties(entityItemID, _entityPropertyFlags);
if (_hoverOverlayID == UNKNOWN_OVERLAY_ID || !qApp->getOverlays().isAddedOverlay(_hoverOverlayID)) {
_hoverOverlay = std::make_shared<Image3DOverlay>();
_hoverOverlay->setAlpha(1.0f);
_hoverOverlay->setPulseMin(0.75f);
_hoverOverlay->setPulseMax(1.0f);
_hoverOverlay->setColorPulse(1.0f);
_hoverOverlay->setIgnoreRayIntersection(false);
_hoverOverlay->setDrawInFront(true);
_hoverOverlay->setURL("http://i.imgur.com/gksZygp.png");
_hoverOverlay->setIsFacingAvatar(true);
_hoverOverlay->setDimensions(glm::vec2(0.2f, 0.2f) * glm::distance(entityProperties.getPosition(), qApp->getCamera().getPosition()));
_hoverOverlayID = qApp->getOverlays().addOverlay(_hoverOverlay);
}
_hoverOverlay->setPosition(entityProperties.getPosition());
_hoverOverlay->setRotation(entityProperties.getRotation());
_hoverOverlay->setVisible(true);
}
void HoverOverlayInterface::destroyHoverOverlay(const EntityItemID& entityItemID, const PointerEvent& event) {
qCDebug(hover_overlay) << "Destroying Hover Overlay on top of entity with ID: " << entityItemID;
setCurrentHoveredEntity(QUuid());
qApp->getOverlays().deleteOverlay(_hoverOverlayID);
_hoverOverlay = NULL;
_hoverOverlayID = UNKNOWN_OVERLAY_ID;
}
void HoverOverlayInterface::destroyHoverOverlay(const EntityItemID& entityItemID) {
HoverOverlayInterface::destroyHoverOverlay(entityItemID, PointerEvent());
}
void HoverOverlayInterface::clickHoverOverlay(const OverlayID& overlayID, const PointerEvent& event) {
if (overlayID == _hoverOverlayID) {
qCDebug(hover_overlay) << "Clicked Hover Overlay. Entity ID:" << _currentHoveredEntity << "Overlay ID:" << overlayID;
}
}

View file

@ -1,57 +0,0 @@
//
// HoverOverlayInterface.h
// interface/src/ui/overlays
//
// Created by Zach Fox on 2017-07-14.
// Copyright 2017 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
//
#pragma once
#ifndef hifi_HoverOverlayInterface_h
#define hifi_HoverOverlayInterface_h
#include <QtCore/QObject>
#include <QUuid>
#include <DependencyManager.h>
#include <PointerEvent.h>
#include "EntityScriptingInterface.h"
#include "ui/overlays/Image3DOverlay.h"
#include "ui/overlays/Overlays.h"
#include "EntityTree.h"
#include "HoverOverlayLogging.h"
/**jsdoc
* @namespace HoverOverlay
*/
class HoverOverlayInterface : public QObject, public Dependency {
Q_OBJECT
Q_PROPERTY(QUuid currentHoveredEntity READ getCurrentHoveredEntity WRITE setCurrentHoveredEntity)
QSharedPointer<EntityScriptingInterface> _entityScriptingInterface;
EntityPropertyFlags _entityPropertyFlags;
OverlayID _hoverOverlayID { UNKNOWN_OVERLAY_ID };
std::shared_ptr<Image3DOverlay> _hoverOverlay { nullptr };
public:
HoverOverlayInterface();
Q_INVOKABLE QUuid getCurrentHoveredEntity() { return _currentHoveredEntity; }
void setCurrentHoveredEntity(const QUuid& entityID) { _currentHoveredEntity = entityID; }
public slots:
void createHoverOverlay(const EntityItemID& entityItemID, const PointerEvent& event);
void destroyHoverOverlay(const EntityItemID& entityItemID, const PointerEvent& event);
void destroyHoverOverlay(const EntityItemID& entityItemID);
void clickHoverOverlay(const OverlayID& overlayID, const PointerEvent& event);
private:
bool _verboseLogging { true };
QUuid _currentHoveredEntity {};
};
#endif // hifi_HoverOverlayInterface_h

View file

@ -187,7 +187,7 @@ var DEFAULT_GRABBABLE_DATA = {
var USE_BLACKLIST = true;
var blacklist = [];
var entityWithHoverOverlay = false;
var entityWithContextOverlay = false;
var FORBIDDEN_GRAB_NAMES = ["Grab Debug Entity", "grab pointer"];
var FORBIDDEN_GRAB_TYPES = ["Unknown", "Light", "PolyLine", "Zone"];
@ -2203,9 +2203,9 @@ function MyController(hand) {
entityPropertiesCache.addEntity(rayPickInfo.entityID);
}
if (rayPickInfo.entityID && (entityWithHoverOverlay !== rayPickInfo.entityID)) {
if (entityWithHoverOverlay) {
HoverOverlay.destroyHoverOverlay(entityWithHoverOverlay);
if (rayPickInfo.entityID && (entityWithContextOverlay !== rayPickInfo.entityID)) {
if (entityWithContextOverlay) {
ContextOverlay.destroyContextOverlay(entityWithContextOverlay);
}
var pointerEvent = {
type: "Move",
@ -2216,8 +2216,8 @@ function MyController(hand) {
direction: rayPickInfo.searchRay.direction,
button: "None"
};
HoverOverlay.createHoverOverlay(rayPickInfo.entityID, pointerEvent);
entityWithHoverOverlay = rayPickInfo.entityID;
ContextOverlay.createContextOverlay(rayPickInfo.entityID, pointerEvent);
entityWithContextOverlay = rayPickInfo.entityID;
}
var candidateHotSpotEntities = Entities.findEntities(handPosition, MAX_EQUIP_HOTSPOT_RADIUS);
@ -3779,9 +3779,9 @@ function MyController(hand) {
this.release = function() {
this.turnOffVisualizations();
if (entityWithHoverOverlay) {
HoverOverlay.destroyHoverOverlay(entityWithHoverOverlay);
entityWithHoverOverlay = false;
if (entityWithContextOverlay) {
ContextOverlay.destroyContextOverlay(entityWithContextOverlay);
entityWithContextOverlay = false;
}
if (this.grabbedThingID !== null) {