From b7d9dc444bdf90aaf2e21b2002b5f2a8d7749b7c Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Mon, 17 Aug 2015 13:06:32 -0700 Subject: [PATCH] more work on clicking focus --- interface/src/Application.cpp | 30 ++++++++++++------- interface/src/Application.h | 1 + .../src/EntityTreeRenderer.cpp | 2 ++ .../src/EntityTreeRenderer.h | 1 + .../src/RenderableWebEntityItem.cpp | 9 ++++++ 5 files changed, 33 insertions(+), 10 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index a8c66c4689..5ae0872761 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -673,12 +673,13 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : auto& packetReceiver = nodeList->getPacketReceiver(); packetReceiver.registerListener(PacketType::DomainConnectionDenied, this, "handleDomainConnectionDeniedPacket"); + // If the user clicks an an entity, we will check that it's an unlocked web entity, and if so, set the focus to it auto entityScriptingInterface = DependencyManager::get(); connect(entityScriptingInterface.data(), &EntityScriptingInterface::clickDownOnEntity, [this, entityScriptingInterface](const EntityItemID& entityItemID, const MouseEvent& event) { if (_keyboardFocusedItem != entityItemID) { _keyboardFocusedItem = UNKNOWN_ENTITY_ID; - qDebug() << "_keyboardFocusedItem:" << UNKNOWN_ENTITY_ID; + qDebug() << "clickDownOnEntity.... _keyboardFocusedItem:" << UNKNOWN_ENTITY_ID; auto properties = entityScriptingInterface->getEntityProperties(entityItemID); if (EntityTypes::Web == properties.getType() && !properties.getLocked()) { auto entity = entityScriptingInterface->getEntityTree()->findEntityByID(entityItemID); @@ -686,21 +687,19 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : if (webEntity) { webEntity->setProxyWindow(_window->windowHandle()); _keyboardFocusedItem = entityItemID; - qDebug() << "_keyboardFocusedItem:" << entityItemID; + _lastAcceptedKeyPress = usecTimestampNow(); + qDebug() << "clickDownOnEntity.... _keyboardFocusedItem:" << entityItemID; } } } }); - /* - // FIXME - need a solution for unfocusing on delayed time - connect(entityScriptingInterface.data(), &EntityScriptingInterface::hoverLeaveEntity, [=](const EntityItemID& entityItemID, const MouseEvent& event) { - if (_keyboardFocusedItem == entityItemID) { - _keyboardFocusedItem = UNKNOWN_ENTITY_ID; - qDebug() << "_keyboardFocusedItem:" << UNKNOWN_ENTITY_ID; - } + // If the user clicks somewhere where there is NO entity at all, we will release focus + connect(getEntities(), &EntityTreeRenderer::mousePressOffEntity, + [=](const RayToEntityIntersectionResult& entityItemID, const QMouseEvent* event, unsigned int deviceId) { + _keyboardFocusedItem = UNKNOWN_ENTITY_ID; + qDebug() << "mousePressOffEntity... _keyboardFocusedItem:" << UNKNOWN_ENTITY_ID; }); - */ } void Application::aboutToQuit() { @@ -1277,6 +1276,7 @@ bool Application::event(QEvent* event) { event->setAccepted(false); QCoreApplication::sendEvent(webEntity->getEventHandler(), event); if (event->isAccepted()) { + _lastAcceptedKeyPress = usecTimestampNow(); return true; } } @@ -1286,6 +1286,16 @@ bool Application::event(QEvent* event) { default: break; } + + const quint64 LOSE_FOCUS_AFTER_ELAPSED_TIME = 30 * USECS_PER_SECOND; // if idle for 30 seconds, drop focus + quint64 elapsedSinceAcceptedKeyPress = usecTimestampNow() - _lastAcceptedKeyPress; + if (elapsedSinceAcceptedKeyPress > LOSE_FOCUS_AFTER_ELAPSED_TIME) { + _keyboardFocusedItem = UNKNOWN_ENTITY_ID; + qDebug() << "idle for 30 seconds.... _keyboardFocusedItem:" << UNKNOWN_ENTITY_ID; + } else { + qDebug() << "elapsedSinceAcceptedKeyPress:" << elapsedSinceAcceptedKeyPress; + } + } switch (event->type()) { diff --git a/interface/src/Application.h b/interface/src/Application.h index cec1325baf..e0d4fa559d 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -680,6 +680,7 @@ private: DialogsManagerScriptingInterface* _dialogsManagerScriptingInterface = new DialogsManagerScriptingInterface(); EntityItemID _keyboardFocusedItem; + quint64 _lastAcceptedKeyPress = 0; }; #endif // hifi_Application_h diff --git a/libraries/entities-renderer/src/EntityTreeRenderer.cpp b/libraries/entities-renderer/src/EntityTreeRenderer.cpp index 50f79e2ff3..72400dcefb 100644 --- a/libraries/entities-renderer/src/EntityTreeRenderer.cpp +++ b/libraries/entities-renderer/src/EntityTreeRenderer.cpp @@ -861,6 +861,8 @@ void EntityTreeRenderer::mousePressEvent(QMouseEvent* event, unsigned int device if (entityScript.property("clickDownOnEntity").isValid()) { entityScript.property("clickDownOnEntity").call(entityScript, entityScriptArgs); } + } else { + emit mousePressOffEntity(rayPickResult, event, deviceID); } _lastMouseEvent = MouseEvent(*event, deviceID); _lastMouseEventValid = true; diff --git a/libraries/entities-renderer/src/EntityTreeRenderer.h b/libraries/entities-renderer/src/EntityTreeRenderer.h index 39f088f06d..25eb87b422 100644 --- a/libraries/entities-renderer/src/EntityTreeRenderer.h +++ b/libraries/entities-renderer/src/EntityTreeRenderer.h @@ -95,6 +95,7 @@ public: signals: void mousePressOnEntity(const RayToEntityIntersectionResult& entityItemID, const QMouseEvent* event, unsigned int deviceId); + void mousePressOffEntity(const RayToEntityIntersectionResult& entityItemID, const QMouseEvent* event, unsigned int deviceId); void mouseMoveOnEntity(const RayToEntityIntersectionResult& entityItemID, const QMouseEvent* event, unsigned int deviceId); void mouseReleaseOnEntity(const RayToEntityIntersectionResult& entityItemID, const QMouseEvent* event, unsigned int deviceId); diff --git a/libraries/entities-renderer/src/RenderableWebEntityItem.cpp b/libraries/entities-renderer/src/RenderableWebEntityItem.cpp index 73aa6f2718..c8c5b10a61 100644 --- a/libraries/entities-renderer/src/RenderableWebEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableWebEntityItem.cpp @@ -56,6 +56,15 @@ RenderableWebEntityItem::~RenderableWebEntityItem() { } void RenderableWebEntityItem::render(RenderArgs* args) { + + // debug bounds on mac. + { + gpu::Batch& batch = *args->_batch; + batch.setModelTransform(getTransformToCenter()); // we want to include the scale as well + glm::vec4 cubeColor{ 1.0f, 0.0f, 0.0f, 1.0f}; + DependencyManager::get()->renderWireCube(batch, 1.0f, cubeColor); + } + QOpenGLContext * currentContext = QOpenGLContext::currentContext(); QSurface * currentSurface = currentContext->surface(); if (!_webSurface) {