From cb5f80bf789667ab2134008bceb93c7a91263371 Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Mon, 17 Aug 2015 15:56:56 -0700 Subject: [PATCH] Add highlighting of keyboard focused items --- interface/src/Application.cpp | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 621210cc4e..449afae5d1 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -112,9 +112,7 @@ #include "InterfaceActionFactory.h" #include "avatar/AvatarManager.h" - #include "audio/AudioScope.h" - #include "devices/DdeFaceTracker.h" #include "devices/EyeTracker.h" #include "devices/Faceshift.h" @@ -148,6 +146,8 @@ #include "ui/AddressBarDialog.h" #include "ui/UpdateDialog.h" +#include "ui/overlays/Cube3DOverlay.h" + // ON WIndows PC, NVidia Optimus laptop, we want to enable NVIDIA GPU // FIXME seems to be broken. #if defined(Q_OS_WIN) @@ -172,7 +172,6 @@ public: void call() { _fun(); } }; - using namespace std; // Starfield information @@ -299,6 +298,13 @@ bool setupEssentials(int& argc, char** argv) { return true; } +// FIXME move to header, or better yet, design some kind of UI manager +// to take care of highlighting keyboard focused items, rather than +// continuing to overburden Application.cpp +Cube3DOverlay* _keyboardFocusHighlight{ nullptr }; +int _keyboardFocusHighlightID{ -1 }; + + Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : QApplication(argc, argv), _dependencyManagerIsSetup(setupEssentials(argc, argv)), @@ -687,6 +693,23 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : webEntity->setProxyWindow(_window->windowHandle()); _keyboardFocusedItem = entityItemID; _lastAcceptedKeyPress = usecTimestampNow(); + if (_keyboardFocusHighlightID < 0 || !getOverlays().isAddedOverlay(_keyboardFocusHighlightID)) { + _keyboardFocusHighlight = new Cube3DOverlay(); + _keyboardFocusHighlight->setAlpha(1.0f); + _keyboardFocusHighlight->setBorderSize(1.0f); + _keyboardFocusHighlight->setColor({ 0xFF, 0xEF, 0x00 }); + _keyboardFocusHighlight->setIsSolid(false); + _keyboardFocusHighlight->setPulseMin(0.5); + _keyboardFocusHighlight->setPulseMax(1.0); + _keyboardFocusHighlight->setColorPulse(1.0); + _keyboardFocusHighlight->setIgnoreRayIntersection(true); + _keyboardFocusHighlight->setDrawInFront(true); + } + _keyboardFocusHighlight->setRotation(webEntity->getRotation()); + _keyboardFocusHighlight->setPosition(webEntity->getPosition()); + _keyboardFocusHighlight->setDimensions(webEntity->getDimensions() * 1.05f); + _keyboardFocusHighlight->setVisible(true); + _keyboardFocusHighlightID = getOverlays().addOverlay(_keyboardFocusHighlight); } } } @@ -696,6 +719,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : connect(getEntities(), &EntityTreeRenderer::mousePressOffEntity, [=](const RayToEntityIntersectionResult& entityItemID, const QMouseEvent* event, unsigned int deviceId) { _keyboardFocusedItem = UNKNOWN_ENTITY_ID; + _keyboardFocusHighlight->setVisible(false); }); } @@ -707,6 +731,11 @@ void Application::aboutToQuit() { } void Application::cleanupBeforeQuit() { + if (_keyboardFocusHighlightID > 0) { + getOverlays().deleteOverlay(_keyboardFocusHighlightID); + _keyboardFocusHighlightID = -1; + } + _keyboardFocusHighlight = nullptr; _entities.clear(); // this will allow entity scripts to properly shutdown