From 5828c320416c6f3f30f901c016384815e76bcff4 Mon Sep 17 00:00:00 2001 From: Brad Hefta-Gaub Date: Thu, 25 Feb 2016 08:31:11 -0800 Subject: [PATCH 1/6] add toggleOverlays menu item and action --- interface/src/Application.cpp | 11 ++++++++--- interface/src/Application.h | 2 ++ interface/src/Menu.cpp | 3 +++ interface/src/Menu.h | 1 + libraries/controllers/src/controllers/Actions.cpp | 1 + libraries/controllers/src/controllers/Actions.h | 1 + 6 files changed, 16 insertions(+), 3 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 7314bce0bd..45fa27db78 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -817,6 +817,8 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer) : } else if (action == controller::toInt(controller::Action::RETICLE_Y)) { auto oldPos = _compositor.getReticlePosition(); _compositor.setReticlePosition({ oldPos.x, oldPos.y + state }); + } else if (action == controller::toInt(controller::Action::TOGGLE_OVERLAY)) { + _overlayConductor.setEnabled(!_overlayConductor.getEnabled()); } } }); @@ -2030,9 +2032,7 @@ void Application::keyPressEvent(QKeyEvent* event) { Menu::getInstance()->setIsOptionChecked(MenuOption::ThirdPerson, !Menu::getInstance()->isOptionChecked(MenuOption::FirstPerson)); cameraMenuChanged(); break; - case Qt::Key_O: - _overlayConductor.setEnabled(!_overlayConductor.getEnabled()); - break; + case Qt::Key_Slash: Menu::getInstance()->triggerOption(MenuOption::Stats); break; @@ -2993,6 +2993,11 @@ void Application::updateThreads(float deltaTime) { } } +void Application::toggleOverlays() { + auto overlaysVisible = Menu::getInstance()->isOptionChecked(MenuOption::Overlays); + _overlayConductor.setEnabled(overlaysVisible); +} + void Application::cycleCamera() { auto menu = Menu::getInstance(); if (menu->isOptionChecked(MenuOption::FullscreenMirror)) { diff --git a/interface/src/Application.h b/interface/src/Application.h index 51b90bcb99..13dab6137e 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -149,6 +149,7 @@ public: const ApplicationOverlay& getApplicationOverlay() const { return _applicationOverlay; } ApplicationCompositor& getApplicationCompositor() { return _compositor; } const ApplicationCompositor& getApplicationCompositor() const { return _compositor; } + Overlays& getOverlays() { return _overlays; } bool isForeground() const { return _isForeground; } @@ -270,6 +271,7 @@ public slots: void cycleCamera(); void cameraMenuChanged(); + void toggleOverlays(); void reloadResourceCaches(); diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index 9c7788851c..bf8cd2e61e 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -255,6 +255,9 @@ Menu::Menu() { 0, true, qApp, SLOT(rotationModeChanged()), UNSPECIFIED_POSITION, "Advanced"); + // View > Overlays + addCheckableActionToQMenuAndActionHash(viewMenu, MenuOption::Overlays, 0, true, + qApp, SLOT(toggleOverlays())); // Navigate menu ---------------------------------- MenuWrapper* navigateMenu = addMenu("Navigate"); diff --git a/interface/src/Menu.h b/interface/src/Menu.h index 44a24ee895..ca5bf295db 100644 --- a/interface/src/Menu.h +++ b/interface/src/Menu.h @@ -247,6 +247,7 @@ namespace MenuOption { const QString OnePointCalibration = "1 Point Calibration"; const QString OnlyDisplayTopTen = "Only Display Top Ten"; const QString OutputMenu = "Display"; + const QString Overlays = "Overlays"; const QString PackageModel = "Package Model..."; const QString Pair = "Pair"; const QString PhysicsShowHulls = "Draw Collision Hulls"; diff --git a/libraries/controllers/src/controllers/Actions.cpp b/libraries/controllers/src/controllers/Actions.cpp index e6662caa37..dba856cbaa 100644 --- a/libraries/controllers/src/controllers/Actions.cpp +++ b/libraries/controllers/src/controllers/Actions.cpp @@ -61,6 +61,7 @@ namespace controller { makeButtonPair(Action::CONTEXT_MENU, "ContextMenu"), makeButtonPair(Action::TOGGLE_MUTE, "ToggleMute"), makeButtonPair(Action::CYCLE_CAMERA, "CycleCamera"), + makeButtonPair(Action::TOGGLE_OVERLAY, "ToggleOverlay"), makeAxisPair(Action::RETICLE_CLICK, "ReticleClick"), makeAxisPair(Action::RETICLE_X, "ReticleX"), diff --git a/libraries/controllers/src/controllers/Actions.h b/libraries/controllers/src/controllers/Actions.h index e77e5e5a93..efdc45cb3d 100644 --- a/libraries/controllers/src/controllers/Actions.h +++ b/libraries/controllers/src/controllers/Actions.h @@ -52,6 +52,7 @@ enum class Action { CONTEXT_MENU, TOGGLE_MUTE, CYCLE_CAMERA, + TOGGLE_OVERLAY, SHIFT, From 526f9dc2481940d0bf11e5f5020eecc23030d99e Mon Sep 17 00:00:00 2001 From: Brad Hefta-Gaub Date: Thu, 25 Feb 2016 08:41:38 -0800 Subject: [PATCH 2/6] check/uncheck the overlays menu when you toggle the overlays via some other mechanism --- interface/src/ui/OverlayConductor.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/interface/src/ui/OverlayConductor.cpp b/interface/src/ui/OverlayConductor.cpp index f777e5d4dc..4cc5e6d534 100644 --- a/interface/src/ui/OverlayConductor.cpp +++ b/interface/src/ui/OverlayConductor.cpp @@ -110,6 +110,8 @@ void OverlayConductor::setEnabled(bool enabled) { return; } + Menu::getInstance()->setIsOptionChecked(MenuOption::Overlays, enabled); + if (_enabled) { // alpha fadeOut the overlay mesh. qApp->getApplicationCompositor().fadeOut(); From 366aa39be8cc27d0545dc57740b97e893e4ecccd Mon Sep 17 00:00:00 2001 From: Brad Hefta-Gaub Date: Thu, 25 Feb 2016 14:46:08 -0800 Subject: [PATCH 3/6] handle startup overlay visibility correctly --- interface/src/Application.cpp | 16 +++++++++++++++- interface/src/Application.h | 1 + interface/src/Menu.cpp | 2 +- interface/src/ui/ApplicationCompositor.h | 2 +- interface/src/ui/ApplicationOverlay.cpp | 4 ---- interface/src/ui/OverlayConductor.cpp | 9 ++++----- interface/src/ui/OverlayConductor.h | 4 ++-- 7 files changed, 24 insertions(+), 14 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 45fa27db78..6845524631 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -1200,7 +1200,6 @@ void Application::initializeUi() { // OffscreenUi is a subclass of OffscreenQmlSurface specifically designed to // support the window management and scripting proxies for VR use offscreenUi->createDesktop(QString("hifi/Desktop.qml")); - connect(offscreenUi.data(), &OffscreenUi::showDesktop, this, &Application::showDesktop); // FIXME either expose so that dialogs can set this themselves or // do better detection in the offscreen UI of what has focus @@ -2435,6 +2434,17 @@ void Application::idle(uint64_t now) { if (_aboutToQuit) { return; // bail early, nothing to do here. } + + Stats::getInstance()->updateStats(); + AvatarInputs::getInstance()->update(); + + static bool firstIdle = true; + if (firstIdle) { + firstIdle = false; + auto offscreenUi = DependencyManager::get(); + connect(offscreenUi.data(), &OffscreenUi::showDesktop, this, &Application::showDesktop); + } + auto displayPlugin = getActiveDisplayPlugin(); // depending on whether we're throttling or not. @@ -2998,6 +3008,10 @@ void Application::toggleOverlays() { _overlayConductor.setEnabled(overlaysVisible); } +void Application::setOverlaysVisible(bool visible) { + _overlayConductor.setEnabled(visible); +} + void Application::cycleCamera() { auto menu = Menu::getInstance(); if (menu->isOptionChecked(MenuOption::FullscreenMirror)) { diff --git a/interface/src/Application.h b/interface/src/Application.h index 13dab6137e..aacf0b5b08 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -272,6 +272,7 @@ public slots: void cycleCamera(); void cameraMenuChanged(); void toggleOverlays(); + void setOverlaysVisible(bool visible); void reloadResourceCaches(); diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index bf8cd2e61e..a5795c5a3b 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -257,7 +257,7 @@ Menu::Menu() { // View > Overlays addCheckableActionToQMenuAndActionHash(viewMenu, MenuOption::Overlays, 0, true, - qApp, SLOT(toggleOverlays())); + qApp, SLOT(setOverlaysVisible(bool))); // Navigate menu ---------------------------------- MenuWrapper* navigateMenu = addMenu("Navigate"); diff --git a/interface/src/ui/ApplicationCompositor.h b/interface/src/ui/ApplicationCompositor.h index 7bdb97727f..b94afd2cce 100644 --- a/interface/src/ui/ApplicationCompositor.h +++ b/interface/src/ui/ApplicationCompositor.h @@ -131,7 +131,7 @@ private: float _textureAspectRatio { 1.0f }; int _hemiVerticesID { GeometryCache::UNKNOWN_ID }; - float _alpha { 1.0f }; + float _alpha { 0.0f }; // hidden by default float _prevAlpha { 1.0f }; float _fadeInAlpha { true }; float _oculusUIRadius { 1.0f }; diff --git a/interface/src/ui/ApplicationOverlay.cpp b/interface/src/ui/ApplicationOverlay.cpp index 67b5135e0c..998a64d81a 100644 --- a/interface/src/ui/ApplicationOverlay.cpp +++ b/interface/src/ui/ApplicationOverlay.cpp @@ -58,10 +58,6 @@ void ApplicationOverlay::renderOverlay(RenderArgs* renderArgs) { CHECK_GL_ERROR(); PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), "ApplicationOverlay::displayOverlay()"); - // TODO move to Application::idle()? - Stats::getInstance()->updateStats(); - AvatarInputs::getInstance()->update(); - buildFramebufferObject(); if (!_overlayFramebuffer) { diff --git a/interface/src/ui/OverlayConductor.cpp b/interface/src/ui/OverlayConductor.cpp index 4cc5e6d534..21b1aa879e 100644 --- a/interface/src/ui/OverlayConductor.cpp +++ b/interface/src/ui/OverlayConductor.cpp @@ -110,9 +110,12 @@ void OverlayConductor::setEnabled(bool enabled) { return; } + qDebug() << "OverlayConductor::setEnabled() enabled:" << enabled; Menu::getInstance()->setIsOptionChecked(MenuOption::Overlays, enabled); - if (_enabled) { + _enabled = enabled; // set the new value + + if (!_enabled) { // alpha fadeOut the overlay mesh. qApp->getApplicationCompositor().fadeOut(); @@ -122,8 +125,6 @@ void OverlayConductor::setEnabled(bool enabled) { // disable QML events auto offscreenUi = DependencyManager::get(); offscreenUi->getRootItem()->setEnabled(false); - - _enabled = false; } else { // alpha fadeIn the overlay mesh. qApp->getApplicationCompositor().fadeIn(); @@ -144,8 +145,6 @@ void OverlayConductor::setEnabled(bool enabled) { t.setRotation(glm::quat_cast(camMat)); qApp->getApplicationCompositor().setModelTransform(t); } - - _enabled = true; } } diff --git a/interface/src/ui/OverlayConductor.h b/interface/src/ui/OverlayConductor.h index 4b8c0134b5..b94c5be7dd 100644 --- a/interface/src/ui/OverlayConductor.h +++ b/interface/src/ui/OverlayConductor.h @@ -29,8 +29,8 @@ private: STANDING }; - Mode _mode = FLAT; - bool _enabled = true; + Mode _mode { FLAT }; + bool _enabled { false }; }; #endif From 519a90f2bdca815177b208c97d59ac3bc5e93271 Mon Sep 17 00:00:00 2001 From: Brad Hefta-Gaub Date: Thu, 25 Feb 2016 16:02:05 -0800 Subject: [PATCH 4/6] fix the overlays visible on startup case --- interface/src/Application.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 6845524631..df7b203bea 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -2438,11 +2438,14 @@ void Application::idle(uint64_t now) { Stats::getInstance()->updateStats(); AvatarInputs::getInstance()->update(); + // These tasks need to be done on our first idle, because we don't want the showing of + // overlay subwindows to do a showDesktop() until after the first time through static bool firstIdle = true; if (firstIdle) { firstIdle = false; auto offscreenUi = DependencyManager::get(); connect(offscreenUi.data(), &OffscreenUi::showDesktop, this, &Application::showDesktop); + _overlayConductor.setEnabled(Menu::getInstance()->isOptionChecked(MenuOption::Overlays)); } From e58081ca9c2d2dcfd3afb83edfd019edef888d03 Mon Sep 17 00:00:00 2001 From: Brad Hefta-Gaub Date: Thu, 25 Feb 2016 16:23:12 -0800 Subject: [PATCH 5/6] remove extra debug code --- interface/src/ui/OverlayConductor.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/interface/src/ui/OverlayConductor.cpp b/interface/src/ui/OverlayConductor.cpp index 21b1aa879e..324ec8583b 100644 --- a/interface/src/ui/OverlayConductor.cpp +++ b/interface/src/ui/OverlayConductor.cpp @@ -110,7 +110,6 @@ void OverlayConductor::setEnabled(bool enabled) { return; } - qDebug() << "OverlayConductor::setEnabled() enabled:" << enabled; Menu::getInstance()->setIsOptionChecked(MenuOption::Overlays, enabled); _enabled = enabled; // set the new value From bf0fb7258a49f59b29a5df740d49026e4f9e32c5 Mon Sep 17 00:00:00 2001 From: Brad Hefta-Gaub Date: Thu, 25 Feb 2016 22:01:10 -0800 Subject: [PATCH 6/6] CR feedback --- interface/src/Application.cpp | 7 ++++--- interface/src/ui/OverlayConductor.cpp | 23 ++++++++++++----------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index b072867400..64a9ef2029 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -818,7 +818,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer) : auto oldPos = _compositor.getReticlePosition(); _compositor.setReticlePosition({ oldPos.x, oldPos.y + state }); } else if (action == controller::toInt(controller::Action::TOGGLE_OVERLAY)) { - _overlayConductor.setEnabled(!_overlayConductor.getEnabled()); + toggleOverlays(); } } }); @@ -3003,8 +3003,9 @@ void Application::updateThreads(float deltaTime) { } void Application::toggleOverlays() { - auto overlaysVisible = Menu::getInstance()->isOptionChecked(MenuOption::Overlays); - _overlayConductor.setEnabled(overlaysVisible); + auto newOverlaysVisible = !_overlayConductor.getEnabled(); + Menu::getInstance()->setIsOptionChecked(MenuOption::Overlays, newOverlaysVisible); + _overlayConductor.setEnabled(newOverlaysVisible); } void Application::setOverlaysVisible(bool visible) { diff --git a/interface/src/ui/OverlayConductor.cpp b/interface/src/ui/OverlayConductor.cpp index 324ec8583b..113dad1ab5 100644 --- a/interface/src/ui/OverlayConductor.cpp +++ b/interface/src/ui/OverlayConductor.cpp @@ -114,17 +114,8 @@ void OverlayConductor::setEnabled(bool enabled) { _enabled = enabled; // set the new value - if (!_enabled) { - // alpha fadeOut the overlay mesh. - qApp->getApplicationCompositor().fadeOut(); - - // disable mouse clicks from script - qApp->getOverlays().disable(); - - // disable QML events - auto offscreenUi = DependencyManager::get(); - offscreenUi->getRootItem()->setEnabled(false); - } else { + // if the new state is visible/enabled... + if (_enabled) { // alpha fadeIn the overlay mesh. qApp->getApplicationCompositor().fadeIn(); @@ -144,6 +135,16 @@ void OverlayConductor::setEnabled(bool enabled) { t.setRotation(glm::quat_cast(camMat)); qApp->getApplicationCompositor().setModelTransform(t); } + } else { // other wise, if the new state is hidden/not enabled + // alpha fadeOut the overlay mesh. + qApp->getApplicationCompositor().fadeOut(); + + // disable mouse clicks from script + qApp->getOverlays().disable(); + + // disable QML events + auto offscreenUi = DependencyManager::get(); + offscreenUi->getRootItem()->setEnabled(false); } }