Showing the changes to interface/src/Application.cpp (1 of 7 files). Show all
Unified · Split
| @@ -1045,70 +1045,24 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer) : · 1044 unmodified lines | |||
| 1045 | // 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 | 1045 | // 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 |
| 1046 | auto entityScriptingInterface = DependencyManager::get<EntityScriptingInterface>(); | 1046 | auto entityScriptingInterface = DependencyManager::get<EntityScriptingInterface>(); |
| 1047 | connect(entityScriptingInterface.data(), &EntityScriptingInterface::clickDownOnEntity, | 1047 | connect(entityScriptingInterface.data(), &EntityScriptingInterface::clickDownOnEntity, |
| 1048 | [this, entityScriptingInterface](const EntityItemID& entityItemID, const MouseEvent& event) { | 1048 | [this](const EntityItemID& entityItemID, const MouseEvent& event) { |
| 1049 | if (_keyboardFocusedItem != entityItemID) { | 1049 | setKeyboardFocusEntity(entityItemID); |
| 1050 | _keyboardFocusedItem = UNKNOWN_ENTITY_ID; | ||
| 1051 | auto properties = entityScriptingInterface->getEntityProperties(entityItemID); | ||
| 1052 | if (EntityTypes::Web == properties.getType() && !properties.getLocked() && properties.getVisible()) { | ||
| 1053 | auto entity = entityScriptingInterface->getEntityTree()->findEntityByID(entityItemID); | ||
| 1054 | RenderableWebEntityItem* webEntity = dynamic_cast<RenderableWebEntityItem*>(entity.get()); | ||
| 1055 | if (webEntity) { | ||
| 1056 | webEntity->setProxyWindow(_window->windowHandle()); | ||
| 1057 | if (_keyboardMouseDevice->isActive()) { | ||
| 1058 | _keyboardMouseDevice->pluginFocusOutEvent(); | ||
| 1059 | } | ||
| 1060 | _keyboardFocusedItem = entityItemID; | ||
| 1061 | _lastAcceptedKeyPress = usecTimestampNow(); | ||
| 1062 | if (_keyboardFocusHighlightID < 0 || !getOverlays().isAddedOverlay(_keyboardFocusHighlightID)) { | ||
| 1063 | _keyboardFocusHighlight = new Cube3DOverlay(); | ||
| 1064 | _keyboardFocusHighlight->setAlpha(1.0f); | ||
| 1065 | _keyboardFocusHighlight->setBorderSize(1.0f); | ||
| 1066 | _keyboardFocusHighlight->setColor({ 0xFF, 0xEF, 0x00 }); | ||
| 1067 | _keyboardFocusHighlight->setIsSolid(false); | ||
| 1068 | _keyboardFocusHighlight->setPulseMin(0.5); | ||
| 1069 | _keyboardFocusHighlight->setPulseMax(1.0); | ||
| 1070 | _keyboardFocusHighlight->setColorPulse(1.0); | ||
| 1071 | _keyboardFocusHighlight->setIgnoreRayIntersection(true); | ||
| 1072 | _keyboardFocusHighlight->setDrawInFront(true); | ||
| 1073 | } | ||
| 1074 | _keyboardFocusHighlight->setRotation(webEntity->getRotation()); | ||
| 1075 | _keyboardFocusHighlight->setPosition(webEntity->getPosition()); | ||
| 1076 | _keyboardFocusHighlight->setDimensions(webEntity->getDimensions() * 1.05f); | ||
| 1077 | _keyboardFocusHighlight->setVisible(true); | ||
| 1078 | _keyboardFocusHighlightID = getOverlays().addOverlay(_keyboardFocusHighlight); | ||
| 1079 | } | ||
| 1080 | } | ||
| 1081 | if (_keyboardFocusedItem == UNKNOWN_ENTITY_ID && _keyboardFocusHighlight) { | ||
| 1082 | _keyboardFocusHighlight->setVisible(false); | ||
| 1083 | } | ||
| 1084 | |||
| 1085 | } | ||
| 1086 | }); | 1050 | }); |
| 1087 | 1051 | ||
| 1088 | connect(entityScriptingInterface.data(), &EntityScriptingInterface::deletingEntity, | 1052 | connect(entityScriptingInterface.data(), &EntityScriptingInterface::deletingEntity, [=](const EntityItemID& entityItemID) { |
| 1089 | [=](const EntityItemID& entityItemID) { | 1053 | if (entityItemID == _keyboardFocusedItem.get()) { |
| 1090 | if (entityItemID == _keyboardFocusedItem) { | 1054 | setKeyboardFocusEntity(UNKNOWN_ENTITY_ID); |
| 1091 | _keyboardFocusedItem = UNKNOWN_ENTITY_ID; | ||
| 1092 | if (_keyboardFocusHighlight) { | ||
| 1093 | _keyboardFocusHighlight->setVisible(false); | ||
| 1094 | } | ||
| 1095 | } | 1055 | } |
| 1096 | }); | 1056 | }); |
| 1097 | 1057 | ||
| 1098 | // If the user clicks somewhere where there is NO entity at all, we will release focus | 1058 | // If the user clicks somewhere where there is NO entity at all, we will release focus |
| 1099 | connect(getEntities(), &EntityTreeRenderer::mousePressOffEntity, | 1059 | connect(getEntities(), &EntityTreeRenderer::mousePressOffEntity, |
| 1100 | [=](const RayToEntityIntersectionResult& entityItemID, const QMouseEvent* event) { | 1060 | [=](const RayToEntityIntersectionResult& entityItemID, const QMouseEvent* event) { |
| 1101 | _keyboardFocusedItem = UNKNOWN_ENTITY_ID; | 1061 | setKeyboardFocusEntity(UNKNOWN_ENTITY_ID); |
| 1102 | if (_keyboardFocusHighlight) { | ||
| 1103 | _keyboardFocusHighlight->setVisible(false); | ||
| 1104 | } | ||
| 1105 | }); | 1062 | }); |
| 1106 | 1063 | ||
| 1107 | connect(this, &Application::aboutToQuit, [=]() { | 1064 | connect(this, &Application::aboutToQuit, [=]() { |
| 1108 | _keyboardFocusedItem = UNKNOWN_ENTITY_ID; | 1065 | setKeyboardFocusEntity(UNKNOWN_ENTITY_ID); |
| 1109 | if (_keyboardFocusHighlight) { | ||
| 1110 | _keyboardFocusHighlight->setVisible(false); | ||
| 1111 | } | ||
| 1112 | }); | 1066 | }); |
| 1113 | 1067 | ||
| 1114 | // Add periodic checks to send user activity data | 1068 | // Add periodic checks to send user activity data |
| @@ -1334,11 +1288,13 @@ void Application::cleanupBeforeQuit() { · 219 unmodified lines | |||
| 1334 | // FIXME: once we move to shared pointer for the INputDevice we shoud remove this naked delete: | 1288 | // FIXME: once we move to shared pointer for the INputDevice we shoud remove this naked delete: |
| 1335 | _applicationStateDevice.reset(); | 1289 | _applicationStateDevice.reset(); |
| 1336 | 1290 | ||
| 1337 | if (_keyboardFocusHighlightID > 0) { | 1291 | { |
| 1338 | getOverlays().deleteOverlay(_keyboardFocusHighlightID); | 1292 | if (_keyboardFocusHighlightID > 0) { |
| 1339 | _keyboardFocusHighlightID = -1; | 1293 | getOverlays().deleteOverlay(_keyboardFocusHighlightID); |
| 1294 | _keyboardFocusHighlightID = -1; | ||
| 1295 | } | ||
| 1296 | _keyboardFocusHighlight = nullptr; | ||
| 1340 | } | 1297 | } |
| 1341 | _keyboardFocusHighlight = nullptr; | ||
| 1342 | 1298 | ||
| 1343 | auto nodeList = DependencyManager::get<NodeList>(); | 1299 | auto nodeList = DependencyManager::get<NodeList>(); |
| 1344 | 1300 | ||
| @@ -2063,12 +2019,13 @@ bool Application::event(QEvent* event) { · 718 unmodified lines | |||
| 2063 | return true; | 2019 | return true; |
| 2064 | } | 2020 | } |
| 2065 | 2021 | ||
| 2066 | if (!_keyboardFocusedItem.isInvalidID()) { | 2022 | { |
| 2067 | switch (event->type()) { | 2023 | if (!_keyboardFocusedItem.get().isInvalidID()) { |
| 2024 | switch (event->type()) { | ||
| 2068 | case QEvent::KeyPress: | 2025 | case QEvent::KeyPress: |
| 2069 | case QEvent::KeyRelease: { | 2026 | case QEvent::KeyRelease: { |
| 2070 | auto entityScriptingInterface = DependencyManager::get<EntityScriptingInterface>(); | 2027 | auto entityScriptingInterface = DependencyManager::get<EntityScriptingInterface>(); |
| 2071 | auto entity = entityScriptingInterface->getEntityTree()->findEntityByID(_keyboardFocusedItem); | 2028 | auto entity = entityScriptingInterface->getEntityTree()->findEntityByID(_keyboardFocusedItem.get()); |
| 2072 | RenderableWebEntityItem* webEntity = dynamic_cast<RenderableWebEntityItem*>(entity.get()); | 2029 | RenderableWebEntityItem* webEntity = dynamic_cast<RenderableWebEntityItem*>(entity.get()); |
| 2073 | if (webEntity && webEntity->getEventHandler()) { | 2030 | if (webEntity && webEntity->getEventHandler()) { |
| 2074 | event->setAccepted(false); | 2031 | event->setAccepted(false); |
| @@ -2083,6 +2040,7 @@ bool Application::event(QEvent* event) { · 8 unmodified lines | |||
| 2083 | 2040 | ||
| 2084 | default: | 2041 | default: |
| 2085 | break; | 2042 | break; |
| 2043 | } | ||
| 2086 | } | 2044 | } |
| 2087 | } | 2045 | } |
| 2088 | 2046 | ||
| @@ -2920,12 +2878,24 @@ void Application::idle(float nsecsElapsed) { · 831 unmodified lines | |||
| 2920 | _simCounter.increment(); | 2878 | _simCounter.increment(); |
| 2921 | 2879 | ||
| 2922 | PerformanceTimer perfTimer("idle"); | 2880 | PerformanceTimer perfTimer("idle"); |
| 2881 | |||
| 2923 | // Drop focus from _keyboardFocusedItem if no keyboard messages for 30 seconds | 2882 | // Drop focus from _keyboardFocusedItem if no keyboard messages for 30 seconds |
| 2924 | if (!_keyboardFocusedItem.isInvalidID()) { | 2883 | { |
| 2925 | const quint64 LOSE_FOCUS_AFTER_ELAPSED_TIME = 30 * USECS_PER_SECOND; // if idle for 30 seconds, drop focus | 2884 | if (!_keyboardFocusedItem.get().isInvalidID()) { |
| 2926 | quint64 elapsedSinceAcceptedKeyPress = usecTimestampNow() - _lastAcceptedKeyPress; | 2885 | const quint64 LOSE_FOCUS_AFTER_ELAPSED_TIME = 30 * USECS_PER_SECOND; // if idle for 30 seconds, drop focus |
| 2927 | if (elapsedSinceAcceptedKeyPress > LOSE_FOCUS_AFTER_ELAPSED_TIME) { | 2886 | quint64 elapsedSinceAcceptedKeyPress = usecTimestampNow() - _lastAcceptedKeyPress; |
| 2928 | _keyboardFocusedItem = UNKNOWN_ENTITY_ID; | 2887 | if (elapsedSinceAcceptedKeyPress > LOSE_FOCUS_AFTER_ELAPSED_TIME) { |
| 2888 | setKeyboardFocusEntity(UNKNOWN_ENTITY_ID); | ||
| 2889 | } else { | ||
| 2890 | // update position of highlight overlay | ||
| 2891 | auto entityScriptingInterface = DependencyManager::get<EntityScriptingInterface>(); | ||
| 2892 | auto entity = entityScriptingInterface->getEntityTree()->findEntityByID(_keyboardFocusedItem.get()); | ||
| 2893 | RenderableWebEntityItem* webEntity = dynamic_cast<RenderableWebEntityItem*>(entity.get()); | ||
| 2894 | if (webEntity && _keyboardFocusHighlight) { | ||
| 2895 | _keyboardFocusHighlight->setRotation(webEntity->getRotation()); | ||
| 2896 | _keyboardFocusHighlight->setPosition(webEntity->getPosition()); | ||
| 2897 | } | ||
| 2898 | } | ||
| 2929 | } | 2899 | } |
| 2930 | } | 2900 | } |
| 2931 | 2901 | ||
| @@ -3505,6 +3475,84 @@ void Application::rotationModeChanged() const { · 573 unmodified lines | |||
| 3505 | } | 3475 | } |
| 3506 | } | 3476 | } |
| 3507 | 3477 | ||
| 3478 | QUuid Application::getKeyboardFocusEntity() const { | ||
| 3479 | return _keyboardFocusedItem.get(); | ||
| 3480 | } | ||
| 3481 | |||
| 3482 | void Application::setKeyboardFocusEntity(QUuid id) { | ||
| 3483 | EntityItemID entityItemID(id); | ||
| 3484 | setKeyboardFocusEntity(entityItemID); | ||
| 3485 | } | ||
| 3486 | |||
| 3487 | void Application::setKeyboardFocusEntity(EntityItemID entityItemID) { | ||
| 3488 | auto entityScriptingInterface = DependencyManager::get<EntityScriptingInterface>(); | ||
| 3489 | if (_keyboardFocusedItem.get() != entityItemID) { | ||
| 3490 | _keyboardFocusedItem.set(UNKNOWN_ENTITY_ID); | ||
| 3491 | auto properties = entityScriptingInterface->getEntityProperties(entityItemID); | ||
| 3492 | if (EntityTypes::Web == properties.getType() && !properties.getLocked() && properties.getVisible()) { | ||
| 3493 | auto entity = entityScriptingInterface->getEntityTree()->findEntityByID(entityItemID); | ||
| 3494 | RenderableWebEntityItem* webEntity = dynamic_cast<RenderableWebEntityItem*>(entity.get()); | ||
| 3495 | if (webEntity) { | ||
| 3496 | webEntity->setProxyWindow(_window->windowHandle()); | ||
| 3497 | if (_keyboardMouseDevice->isActive()) { | ||
| 3498 | _keyboardMouseDevice->pluginFocusOutEvent(); | ||
| 3499 | } | ||
| 3500 | _keyboardFocusedItem.set(entityItemID); | ||
| 3501 | _lastAcceptedKeyPress = usecTimestampNow(); | ||
| 3502 | if (_keyboardFocusHighlightID < 0 || !getOverlays().isAddedOverlay(_keyboardFocusHighlightID)) { | ||
| 3503 | _keyboardFocusHighlight = new Cube3DOverlay(); | ||
| 3504 | _keyboardFocusHighlight->setAlpha(1.0f); | ||
| 3505 | _keyboardFocusHighlight->setBorderSize(1.0f); | ||
| 3506 | _keyboardFocusHighlight->setColor({ 0xFF, 0xEF, 0x00 }); | ||
| 3507 | _keyboardFocusHighlight->setIsSolid(false); | ||
| 3508 | _keyboardFocusHighlight->setPulseMin(0.5); | ||
| 3509 | _keyboardFocusHighlight->setPulseMax(1.0); | ||
| 3510 | _keyboardFocusHighlight->setColorPulse(1.0); | ||
| 3511 | _keyboardFocusHighlight->setIgnoreRayIntersection(true); | ||
| 3512 | _keyboardFocusHighlight->setDrawInFront(true); | ||
| 3513 | } | ||
| 3514 | _keyboardFocusHighlight->setRotation(webEntity->getRotation()); | ||
| 3515 | _keyboardFocusHighlight->setPosition(webEntity->getPosition()); | ||
| 3516 | _keyboardFocusHighlight->setDimensions(webEntity->getDimensions() * 1.05f); | ||
| 3517 | _keyboardFocusHighlight->setVisible(true); | ||
| 3518 | _keyboardFocusHighlightID = getOverlays().addOverlay(_keyboardFocusHighlight); | ||
| 3519 | } | ||
| 3520 | } | ||
| 3521 | if (_keyboardFocusedItem.get() == UNKNOWN_ENTITY_ID && _keyboardFocusHighlight) { | ||
| 3522 | _keyboardFocusHighlight->setVisible(false); | ||
| 3523 | } | ||
| 3524 | } | ||
| 3525 | } | ||
| 3526 | |||
| 3527 | void Application::sendEntityMouseMoveEvent(QUuid id, glm::vec3 intersectionPoint) { | ||
| 3528 | QMouseEvent mouseEvent(QEvent::MouseMove, QPoint(0, 0), QPoint(0, 0), | ||
| 3529 | Qt::NoButton, Qt::NoButton, Qt::NoModifier); | ||
| 3530 | sendEntityMouseEvent(id, mouseEvent, intersectionPoint); | ||
| 3531 | } | ||
| 3532 | |||
| 3533 | void Application::sendEntityLeftMouseDownEvent(QUuid id, glm::vec3 intersectionPoint) { | ||
| 3534 | QMouseEvent mouseEvent(QEvent::MouseButtonPress, QPoint(0, 0), QPoint(0, 0), | ||
| 3535 | Qt::LeftButton, Qt::NoButton, Qt::NoModifier); | ||
| 3536 | sendEntityMouseEvent(id, mouseEvent, intersectionPoint); | ||
| 3537 | } | ||
| 3538 | |||
| 3539 | void Application::sendEntityLeftMouseUpEvent(QUuid id, glm::vec3 intersectionPoint) { | ||
| 3540 | QMouseEvent mouseEvent(QEvent::MouseButtonRelease, QPoint(0, 0), QPoint(0, 0), | ||
| 3541 | Qt::LeftButton, Qt::NoButton, Qt::NoModifier); | ||
| 3542 | sendEntityMouseEvent(id, mouseEvent, intersectionPoint); | ||
| 3543 | } | ||
| 3544 | |||
| 3545 | void Application::sendEntityMouseEvent(const QUuid& id, const QMouseEvent& mouseEvent, const glm::vec3& intersectionPoint) { | ||
| 3546 | auto entityScriptingInterface = DependencyManager::get<EntityScriptingInterface>(); | ||
| 3547 | EntityItemID entityItemID(id); | ||
| 3548 | auto properties = entityScriptingInterface->getEntityProperties(entityItemID); | ||
| 3549 | if (EntityTypes::Web == properties.getType() && !properties.getLocked() && properties.getVisible()) { | ||
| 3550 | auto entity = entityScriptingInterface->getEntityTree()->findEntityByID(entityItemID); | ||
| 3551 | RenderableWebEntityItem* webEntity = dynamic_cast<RenderableWebEntityItem*>(entity.get()); | ||
| 3552 | webEntity->handleMouseEvent(mouseEvent, intersectionPoint); | ||
| 3553 | } | ||
| 3554 | } | ||
| 3555 | |||
| 3508 | void Application::updateDialogs(float deltaTime) const { | 3556 | void Application::updateDialogs(float deltaTime) const { |
| 3509 | PerformanceTimer perfTimer("updateDialogs"); | 3557 | PerformanceTimer perfTimer("updateDialogs"); |
| 3510 | bool showWarnings = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings); | 3558 | bool showWarnings = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings); |