History

Merge pull request #8335 from hyperlogic/feature/hand-controller-web-entity-integration

handControllerGrab and web entity input integration

Brad Hefta-Gaub committed 10 years ago

Commit 21bc06f2 parents 52cd222 d015c5c21 files · +1069 −318Browse files

Showing the changes to interface/src/Application.cpp (1 of 21 files). Show all

Unified · Split

interface/src/Application.cpp+139−74
@@ -1067,70 +1067,23 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer) : · 1066 unmodified lines
10671067 // 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
10681068 auto entityScriptingInterface = DependencyManager::get<EntityScriptingInterface>();
10691069 connect(entityScriptingInterface.data(), &EntityScriptingInterface::clickDownOnEntity,
1070− [this, entityScriptingInterface](const EntityItemID& entityItemID, const MouseEvent& event) {
1071− if (_keyboardFocusedItem != entityItemID) {
1072− _keyboardFocusedItem = UNKNOWN_ENTITY_ID;
1073− auto properties = entityScriptingInterface->getEntityProperties(entityItemID);
1074− if (EntityTypes::Web == properties.getType() && !properties.getLocked() && properties.getVisible()) {
1075− auto entity = entityScriptingInterface->getEntityTree()->findEntityByID(entityItemID);
1076− RenderableWebEntityItem* webEntity = dynamic_cast<RenderableWebEntityItem*>(entity.get());
1077− if (webEntity) {
1078− webEntity->setProxyWindow(_window->windowHandle());
1079− if (_keyboardMouseDevice->isActive()) {
1080− _keyboardMouseDevice->pluginFocusOutEvent();
1081− }
1082− _keyboardFocusedItem = entityItemID;
1083− _lastAcceptedKeyPress = usecTimestampNow();
1084− if (_keyboardFocusHighlightID < 0 || !getOverlays().isAddedOverlay(_keyboardFocusHighlightID)) {
1085− _keyboardFocusHighlight = new Cube3DOverlay();
1086− _keyboardFocusHighlight->setAlpha(1.0f);
1087− _keyboardFocusHighlight->setBorderSize(1.0f);
1088− _keyboardFocusHighlight->setColor({ 0xFF, 0xEF, 0x00 });
1089− _keyboardFocusHighlight->setIsSolid(false);
1090− _keyboardFocusHighlight->setPulseMin(0.5);
1091− _keyboardFocusHighlight->setPulseMax(1.0);
1092− _keyboardFocusHighlight->setColorPulse(1.0);
1093− _keyboardFocusHighlight->setIgnoreRayIntersection(true);
1094− _keyboardFocusHighlight->setDrawInFront(true);
1095− }
1096− _keyboardFocusHighlight->setRotation(webEntity->getRotation());
1097− _keyboardFocusHighlight->setPosition(webEntity->getPosition());
1098− _keyboardFocusHighlight->setDimensions(webEntity->getDimensions() * 1.05f);
1099− _keyboardFocusHighlight->setVisible(true);
1100− _keyboardFocusHighlightID = getOverlays().addOverlay(_keyboardFocusHighlight);
1101− }
1102− }
1103− if (_keyboardFocusedItem == UNKNOWN_ENTITY_ID && _keyboardFocusHighlight) {
1104− _keyboardFocusHighlight->setVisible(false);
1105− }
1106−
1107− }
1070+ [this](const EntityItemID& entityItemID, const PointerEvent& event) {
1071+ setKeyboardFocusEntity(entityItemID);
11081072 });
11091073
1110− connect(entityScriptingInterface.data(), &EntityScriptingInterface::deletingEntity,
1111− [=](const EntityItemID& entityItemID) {
1112− if (entityItemID == _keyboardFocusedItem) {
1113− _keyboardFocusedItem = UNKNOWN_ENTITY_ID;
1114− if (_keyboardFocusHighlight) {
1115− _keyboardFocusHighlight->setVisible(false);
1116− }
1074+ connect(entityScriptingInterface.data(), &EntityScriptingInterface::deletingEntity, [=](const EntityItemID& entityItemID) {
1075+ if (entityItemID == _keyboardFocusedItem.get()) {
1076+ setKeyboardFocusEntity(UNKNOWN_ENTITY_ID);
11171077 }
11181078 });
11191079
11201080 // If the user clicks somewhere where there is NO entity at all, we will release focus
1121− connect(getEntities(), &EntityTreeRenderer::mousePressOffEntity,
1122− [=](const RayToEntityIntersectionResult& entityItemID, const QMouseEvent* event) {
1123− _keyboardFocusedItem = UNKNOWN_ENTITY_ID;
1124− if (_keyboardFocusHighlight) {
1125− _keyboardFocusHighlight->setVisible(false);
1126− }
1081+ connect(getEntities(), &EntityTreeRenderer::mousePressOffEntity, [=]() {
1082+ setKeyboardFocusEntity(UNKNOWN_ENTITY_ID);
11271083 });
11281084
11291085 connect(this, &Application::aboutToQuit, [=]() {
1130− _keyboardFocusedItem = UNKNOWN_ENTITY_ID;
1131− if (_keyboardFocusHighlight) {
1132− _keyboardFocusHighlight->setVisible(false);
1133− }
1086+ setKeyboardFocusEntity(UNKNOWN_ENTITY_ID);
11341087 });
11351088
11361089 // Add periodic checks to send user activity data
@@ -1403,11 +1356,13 @@ void Application::cleanupBeforeQuit() { · 266 unmodified lines
14031356 // FIXME: once we move to shared pointer for the INputDevice we shoud remove this naked delete:
14041357 _applicationStateDevice.reset();
14051358
1406− if (_keyboardFocusHighlightID > 0) {
1407− getOverlays().deleteOverlay(_keyboardFocusHighlightID);
1408− _keyboardFocusHighlightID = -1;
1359+ {
1360+ if (_keyboardFocusHighlightID > 0) {
1361+ getOverlays().deleteOverlay(_keyboardFocusHighlightID);
1362+ _keyboardFocusHighlightID = -1;
1363+ }
1364+ _keyboardFocusHighlight = nullptr;
14091365 }
1410− _keyboardFocusHighlight = nullptr;
14111366
14121367 auto nodeList = DependencyManager::get<NodeList>();
14131368
@@ -2122,16 +2077,16 @@ bool Application::event(QEvent* event) { · 708 unmodified lines
21222077 return true;
21232078 }
21242079
2125− if (!_keyboardFocusedItem.isInvalidID()) {
2126− switch (event->type()) {
2080+ {
2081+ if (!_keyboardFocusedItem.get().isInvalidID()) {
2082+ switch (event->type()) {
21272083 case QEvent::KeyPress:
21282084 case QEvent::KeyRelease: {
21292085 auto entityScriptingInterface = DependencyManager::get<EntityScriptingInterface>();
2130− auto entity = entityScriptingInterface->getEntityTree()->findEntityByID(_keyboardFocusedItem);
2131− RenderableWebEntityItem* webEntity = dynamic_cast<RenderableWebEntityItem*>(entity.get());
2132− if (webEntity && webEntity->getEventHandler()) {
2086+ auto entity = getEntities()->getTree()->findEntityByID(_keyboardFocusedItem.get());
2087+ if (entity && entity->getEventHandler()) {
21332088 event->setAccepted(false);
2134− QCoreApplication::sendEvent(webEntity->getEventHandler(), event);
2089+ QCoreApplication::sendEvent(entity->getEventHandler(), event);
21352090 if (event->isAccepted()) {
21362091 _lastAcceptedKeyPress = usecTimestampNow();
21372092 return true;
@@ -2142,6 +2097,7 @@ bool Application::event(QEvent* event) { · 4 unmodified lines
21422097
21432098 default:
21442099 break;
2100+ }
21452101 }
21462102 }
21472103
@@ -2691,7 +2647,10 @@ void Application::mouseMoveEvent(QMouseEvent* event) { · 543 unmodified lines
26912647 event->screenPos(), button,
26922648 buttons, event->modifiers());
26932649
2694− getEntities()->mouseMoveEvent(&mappedEvent);
2650+ if (compositor.getReticleVisible() || !isHMDMode() || !compositor.getReticleOverDesktop() ||
2651+ getOverlays().getOverlayAtPoint(glm::vec2(transformedPos.x(), transformedPos.y()))) {
2652+ getEntities()->mouseMoveEvent(&mappedEvent);
2653+ }
26952654 _controllerScriptingInterface->emitMouseMoveEvent(&mappedEvent); // send events to any registered scripts
26962655
26972656 // if one of our scripts have asked to capture this event, then stop processing it
@@ -2981,14 +2940,6 @@ void Application::idle(float nsecsElapsed) { · 283 unmodified lines
29812940 _simCounter.increment();
29822941
29832942 PerformanceTimer perfTimer("idle");
2984− // Drop focus from _keyboardFocusedItem if no keyboard messages for 30 seconds
2985− if (!_keyboardFocusedItem.isInvalidID()) {
2986− const quint64 LOSE_FOCUS_AFTER_ELAPSED_TIME = 30 * USECS_PER_SECOND; // if idle for 30 seconds, drop focus
2987− quint64 elapsedSinceAcceptedKeyPress = usecTimestampNow() - _lastAcceptedKeyPress;
2988− if (elapsedSinceAcceptedKeyPress > LOSE_FOCUS_AFTER_ELAPSED_TIME) {
2989− _keyboardFocusedItem = UNKNOWN_ENTITY_ID;
2990− }
2991− }
29922943
29932944 // Normally we check PipelineWarnings, but since idle will often take more than 10ms we only show these idle timing
29942945 // details if we're in ExtraDebugging mode. However, the ::update() and its subcomponents will show their timing
@@ -3002,6 +2953,27 @@ void Application::idle(float nsecsElapsed) { · 7 unmodified lines
30022953 static const float BIGGEST_DELTA_TIME_SECS = 0.25f;
30032954 update(glm::clamp(secondsSinceLastUpdate, 0.0f, BIGGEST_DELTA_TIME_SECS));
30042955 }
2956+
2957+
2958+ // Drop focus from _keyboardFocusedItem if no keyboard messages for 30 seconds
2959+ {
2960+ if (!_keyboardFocusedItem.get().isInvalidID()) {
2961+ const quint64 LOSE_FOCUS_AFTER_ELAPSED_TIME = 30 * USECS_PER_SECOND; // if idle for 30 seconds, drop focus
2962+ quint64 elapsedSinceAcceptedKeyPress = usecTimestampNow() - _lastAcceptedKeyPress;
2963+ if (elapsedSinceAcceptedKeyPress > LOSE_FOCUS_AFTER_ELAPSED_TIME) {
2964+ setKeyboardFocusEntity(UNKNOWN_ENTITY_ID);
2965+ } else {
2966+ // update position of highlight overlay
2967+ auto entityScriptingInterface = DependencyManager::get<EntityScriptingInterface>();
2968+ auto entity = getEntities()->getTree()->findEntityByID(_keyboardFocusedItem.get());
2969+ if (entity && _keyboardFocusHighlight) {
2970+ _keyboardFocusHighlight->setRotation(entity->getRotation());
2971+ _keyboardFocusHighlight->setPosition(entity->getPosition());
2972+ }
2973+ }
2974+ }
2975+ }
2976+
30052977 {
30062978 PerformanceTimer perfTimer("pluginIdle");
30072979 PerformanceWarning warn(showWarnings, "Application::idle()... pluginIdle()");
@@ -3586,6 +3558,54 @@ void Application::rotationModeChanged() const { · 578 unmodified lines
35863558 }
35873559 }
35883560
3561+QUuid Application::getKeyboardFocusEntity() const {
3562+ return _keyboardFocusedItem.get();
3563+}
3564+
3565+void Application::setKeyboardFocusEntity(QUuid id) {
3566+ EntityItemID entityItemID(id);
3567+ setKeyboardFocusEntity(entityItemID);
3568+}
3569+
3570+void Application::setKeyboardFocusEntity(EntityItemID entityItemID) {
3571+ auto entityScriptingInterface = DependencyManager::get<EntityScriptingInterface>();
3572+ if (_keyboardFocusedItem.get() != entityItemID) {
3573+ _keyboardFocusedItem.set(UNKNOWN_ENTITY_ID);
3574+ auto properties = entityScriptingInterface->getEntityProperties(entityItemID);
3575+ if (!properties.getLocked() && properties.getVisible()) {
3576+ auto entity = getEntities()->getTree()->findEntityByID(entityItemID);
3577+ if (entity && entity->wantsKeyboardFocus()) {
3578+ entity->setProxyWindow(_window->windowHandle());
3579+ if (_keyboardMouseDevice->isActive()) {
3580+ _keyboardMouseDevice->pluginFocusOutEvent();
3581+ }
3582+ _keyboardFocusedItem.set(entityItemID);
3583+ _lastAcceptedKeyPress = usecTimestampNow();
3584+ if (_keyboardFocusHighlightID < 0 || !getOverlays().isAddedOverlay(_keyboardFocusHighlightID)) {
3585+ _keyboardFocusHighlight = new Cube3DOverlay();
3586+ _keyboardFocusHighlight->setAlpha(1.0f);
3587+ _keyboardFocusHighlight->setBorderSize(1.0f);
3588+ _keyboardFocusHighlight->setColor({ 0xFF, 0xEF, 0x00 });
3589+ _keyboardFocusHighlight->setIsSolid(false);
3590+ _keyboardFocusHighlight->setPulseMin(0.5);
3591+ _keyboardFocusHighlight->setPulseMax(1.0);
3592+ _keyboardFocusHighlight->setColorPulse(1.0);
3593+ _keyboardFocusHighlight->setIgnoreRayIntersection(true);
3594+ _keyboardFocusHighlight->setDrawInFront(false);
3595+ }
3596+ _keyboardFocusHighlight->setRotation(entity->getRotation());
3597+ _keyboardFocusHighlight->setPosition(entity->getPosition());
3598+ _keyboardFocusHighlight->setDimensions(entity->getDimensions() * 1.05f);
3599+ _keyboardFocusHighlight->setVisible(true);
3600+ _keyboardFocusHighlightID = getOverlays().addOverlay(_keyboardFocusHighlight);
3601+ }
3602+ }
3603+ if (_keyboardFocusedItem.get() == UNKNOWN_ENTITY_ID && _keyboardFocusHighlight) {
3604+ _keyboardFocusHighlight->setVisible(false);
3605+ }
3606+ }
3607+}
3608+
35893609 void Application::updateDialogs(float deltaTime) const {
35903610 PerformanceTimer perfTimer("updateDialogs");
35913611 bool showWarnings = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings);
@@ -5642,3 +5662,48 @@ bool Application::makeRenderingContextCurrent() { · 2050 unmodified lines
56425662 bool Application::isForeground() const {
56435663 return _isForeground && !_window->isMinimized();
56445664 }
5665+
5666+void Application::sendMousePressOnEntity(QUuid id, PointerEvent event) {
5667+ EntityItemID entityItemID(id);
5668+ emit getEntities()->mousePressOnEntity(entityItemID, event);
5669+}
5670+
5671+void Application::sendMouseMoveOnEntity(QUuid id, PointerEvent event) {
5672+ EntityItemID entityItemID(id);
5673+ emit getEntities()->mouseMoveOnEntity(entityItemID, event);
5674+}
5675+
5676+void Application::sendMouseReleaseOnEntity(QUuid id, PointerEvent event) {
5677+ EntityItemID entityItemID(id);
5678+ emit getEntities()->mouseReleaseOnEntity(entityItemID, event);
5679+}
5680+
5681+void Application::sendClickDownOnEntity(QUuid id, PointerEvent event) {
5682+ EntityItemID entityItemID(id);
5683+ emit getEntities()->clickDownOnEntity(entityItemID, event);
5684+}
5685+
5686+void Application::sendHoldingClickOnEntity(QUuid id, PointerEvent event) {
5687+ EntityItemID entityItemID(id);
5688+ emit getEntities()->holdingClickOnEntity(entityItemID, event);
5689+}
5690+
5691+void Application::sendClickReleaseOnEntity(QUuid id, PointerEvent event) {
5692+ EntityItemID entityItemID(id);
5693+ emit getEntities()->clickReleaseOnEntity(entityItemID, event);
5694+}
5695+
5696+void Application::sendHoverEnterEntity(QUuid id, PointerEvent event) {
5697+ EntityItemID entityItemID(id);
5698+ emit getEntities()->hoverEnterEntity(entityItemID, event);
5699+}
5700+
5701+void Application::sendHoverOverEntity(QUuid id, PointerEvent event) {
5702+ EntityItemID entityItemID(id);
5703+ emit getEntities()->hoverOverEntity(entityItemID, event);
5704+}
5705+
5706+void Application::sendHoverLeaveEntity(QUuid id, PointerEvent event) {
5707+ EntityItemID entityItemID(id);
5708+ emit getEntities()->hoverLeaveEntity(entityItemID, event);
5709+}