From 7951826e4961896274e2aa12d045eea1898be864 Mon Sep 17 00:00:00 2001 From: SamGondelman Date: Thu, 26 Oct 2017 16:10:27 -0700 Subject: [PATCH] more advanced laser focusing --- interface/src/Application.cpp | 14 +++++---- interface/src/raypick/LaserPointer.cpp | 14 --------- interface/src/raypick/LaserPointer.h | 2 -- .../src/raypick/RayPickScriptingInterface.cpp | 1 - .../src/raypick/RayPickScriptingInterface.h | 31 +++++++++++++++++++ interface/src/ui/overlays/Overlays.cpp | 8 +++-- libraries/pointers/src/pointers/Pointer.cpp | 2 ++ libraries/pointers/src/pointers/Pointer.h | 2 +- libraries/shared/src/PointerEvent.h | 4 +++ 9 files changed, 51 insertions(+), 27 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 991d9eaecd..0db422953f 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -1472,13 +1472,15 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo // 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, + connect(entityScriptingInterface.data(), &EntityScriptingInterface::mousePressOnEntity, [this](const EntityItemID& entityItemID, const PointerEvent& event) { - if (getEntities()->wantsKeyboardFocus(entityItemID)) { - setKeyboardFocusOverlay(UNKNOWN_OVERLAY_ID); - setKeyboardFocusEntity(entityItemID); - } else { - setKeyboardFocusEntity(UNKNOWN_ENTITY_ID); + if (event.shouldFocus()) { + if (getEntities()->wantsKeyboardFocus(entityItemID)) { + setKeyboardFocusOverlay(UNKNOWN_OVERLAY_ID); + setKeyboardFocusEntity(entityItemID); + } else { + setKeyboardFocusEntity(UNKNOWN_ENTITY_ID); + } } }); diff --git a/interface/src/raypick/LaserPointer.cpp b/interface/src/raypick/LaserPointer.cpp index 988f3023be..b8122a2388 100644 --- a/interface/src/raypick/LaserPointer.cpp +++ b/interface/src/raypick/LaserPointer.cpp @@ -49,20 +49,6 @@ LaserPointer::~LaserPointer() { } } -void LaserPointer::disable() { - Parent::disable(); - withWriteLock([&] { - if (!_currentRenderState.empty()) { - if (_renderStates.find(_currentRenderState) != _renderStates.end()) { - disableRenderState(_renderStates[_currentRenderState]); - } - if (_defaultRenderStates.find(_currentRenderState) != _defaultRenderStates.end()) { - disableRenderState(_defaultRenderStates[_currentRenderState].second); - } - } - }); -} - void LaserPointer::setRenderState(const std::string& state) { withWriteLock([&] { if (!_currentRenderState.empty() && state != _currentRenderState) { diff --git a/interface/src/raypick/LaserPointer.h b/interface/src/raypick/LaserPointer.h index fbe293ea75..167de88385 100644 --- a/interface/src/raypick/LaserPointer.h +++ b/interface/src/raypick/LaserPointer.h @@ -58,8 +58,6 @@ public: const bool faceAvatar, const bool centerEndY, const bool lockEnd, const bool distanceScaleEnd, const bool enabled); ~LaserPointer(); - void disable() override; - void setRenderState(const std::string& state) override; // You cannot use editRenderState to change the overlay type of any part of the laser pointer. You can only edit the properties of the existing overlays. void editRenderState(const std::string& state, const QVariant& startProps, const QVariant& pathProps, const QVariant& endProps) override; diff --git a/interface/src/raypick/RayPickScriptingInterface.cpp b/interface/src/raypick/RayPickScriptingInterface.cpp index b89f89aab5..92bf3ec521 100644 --- a/interface/src/raypick/RayPickScriptingInterface.cpp +++ b/interface/src/raypick/RayPickScriptingInterface.cpp @@ -14,7 +14,6 @@ #include #include "GLMHelpers.h" -#include "PickScriptingInterface.h" #include #include "StaticRayPick.h" diff --git a/interface/src/raypick/RayPickScriptingInterface.h b/interface/src/raypick/RayPickScriptingInterface.h index e7c5dfd5dd..b0d36f482c 100644 --- a/interface/src/raypick/RayPickScriptingInterface.h +++ b/interface/src/raypick/RayPickScriptingInterface.h @@ -16,8 +16,24 @@ #include "RegisteredMetaTypes.h" #include +#include "PickScriptingInterface.h" + class RayPickScriptingInterface : public QObject, public Dependency { Q_OBJECT + Q_PROPERTY(unsigned int PICK_NOTHING READ PICK_NOTHING CONSTANT) + Q_PROPERTY(unsigned int PICK_ENTITIES READ PICK_ENTITIES CONSTANT) + Q_PROPERTY(unsigned int PICK_OVERLAYS READ PICK_OVERLAYS CONSTANT) + Q_PROPERTY(unsigned int PICK_AVATARS READ PICK_AVATARS CONSTANT) + Q_PROPERTY(unsigned int PICK_HUD READ PICK_HUD CONSTANT) + Q_PROPERTY(unsigned int PICK_COARSE READ PICK_COARSE CONSTANT) + Q_PROPERTY(unsigned int PICK_INCLUDE_INVISIBLE READ PICK_INCLUDE_INVISIBLE CONSTANT) + Q_PROPERTY(unsigned int PICK_INCLUDE_NONCOLLIDABLE READ PICK_INCLUDE_NONCOLLIDABLE CONSTANT) + Q_PROPERTY(unsigned int PICK_ALL_INTERSECTIONS READ PICK_ALL_INTERSECTIONS CONSTANT) + Q_PROPERTY(unsigned int INTERSECTED_NONE READ INTERSECTED_NONE CONSTANT) + Q_PROPERTY(unsigned int INTERSECTED_ENTITY READ INTERSECTED_ENTITY CONSTANT) + Q_PROPERTY(unsigned int INTERSECTED_OVERLAY READ INTERSECTED_OVERLAY CONSTANT) + Q_PROPERTY(unsigned int INTERSECTED_AVATAR READ INTERSECTED_AVATAR CONSTANT) + Q_PROPERTY(unsigned int INTERSECTED_HUD READ INTERSECTED_HUD CONSTANT) SINGLETON_DEPENDENCY public slots: @@ -30,6 +46,21 @@ public slots: Q_INVOKABLE void setPrecisionPicking(const QUuid& uid, const bool precisionPicking); Q_INVOKABLE void setIgnoreItems(const QUuid& uid, const QScriptValue& ignoreEntities); Q_INVOKABLE void setIncludeItems(const QUuid& uid, const QScriptValue& includeEntities); + + static unsigned int PICK_NOTHING() { return PickScriptingInterface::PICK_NOTHING(); } + static unsigned int PICK_ENTITIES() { return PickScriptingInterface::PICK_ENTITIES(); } + static unsigned int PICK_OVERLAYS() { return PickScriptingInterface::PICK_OVERLAYS(); } + static unsigned int PICK_AVATARS() { return PickScriptingInterface::PICK_AVATARS(); } + static unsigned int PICK_HUD() { return PickScriptingInterface::PICK_HUD(); } + static unsigned int PICK_COARSE() { return PickScriptingInterface::PICK_COARSE(); } + static unsigned int PICK_INCLUDE_INVISIBLE() { return PickScriptingInterface::PICK_INCLUDE_INVISIBLE(); } + static unsigned int PICK_INCLUDE_NONCOLLIDABLE() { return PickScriptingInterface::PICK_INCLUDE_NONCOLLIDABLE(); } + static unsigned int PICK_ALL_INTERSECTIONS() { return PickScriptingInterface::PICK_ALL_INTERSECTIONS(); } + static unsigned int INTERSECTED_NONE() { return PickScriptingInterface::INTERSECTED_NONE(); } + static unsigned int INTERSECTED_ENTITY() { return PickScriptingInterface::INTERSECTED_ENTITY(); } + static unsigned int INTERSECTED_OVERLAY() { return PickScriptingInterface::INTERSECTED_OVERLAY(); } + static unsigned int INTERSECTED_AVATAR() { return PickScriptingInterface::INTERSECTED_AVATAR(); } + static unsigned int INTERSECTED_HUD() { return PickScriptingInterface::INTERSECTED_HUD(); } }; #endif // hifi_RayPickScriptingInterface_h diff --git a/interface/src/ui/overlays/Overlays.cpp b/interface/src/ui/overlays/Overlays.cpp index 05dcc1148a..b37a376de3 100644 --- a/interface/src/ui/overlays/Overlays.cpp +++ b/interface/src/ui/overlays/Overlays.cpp @@ -908,9 +908,11 @@ void Overlays::mousePressPointerEvent(const OverlayID& overlayID, const PointerE thisOverlay = std::static_pointer_cast(getOverlay(overlayID)); } if (thisOverlay) { - // Focus keyboard on web overlays - DependencyManager::get()->setKeyboardFocusEntity(UNKNOWN_ENTITY_ID); - setKeyboardFocusOverlay(overlayID); + if (event.shouldFocus()) { + // Focus keyboard on web overlays + DependencyManager::get()->setKeyboardFocusEntity(UNKNOWN_ENTITY_ID); + setKeyboardFocusOverlay(overlayID); + } // Send to web overlay QMetaObject::invokeMethod(thisOverlay.get(), "handlePointerEvent", Q_ARG(PointerEvent, event)); diff --git a/libraries/pointers/src/pointers/Pointer.cpp b/libraries/pointers/src/pointers/Pointer.cpp index 1ee725645f..0075762f02 100644 --- a/libraries/pointers/src/pointers/Pointer.cpp +++ b/libraries/pointers/src/pointers/Pointer.cpp @@ -119,9 +119,11 @@ void Pointer::generatePointerEvents(const QVariantMap& pickResult) { } // Trigger begin + const std::string SHOULD_FOCUS_BUTTON = "Focus"; for (const std::string& button : newButtons) { hoveredEvent.setType(PointerEvent::Press); hoveredEvent.setButton(PointerEvent::PrimaryButton); + hoveredEvent.setShouldFocus(button == SHOULD_FOCUS_BUTTON); if (hoveredObject.type == ENTITY) { emit pointerManager->triggerBeginEntity(hoveredObject.objectID, hoveredEvent); } else if (hoveredObject.type == OVERLAY) { diff --git a/libraries/pointers/src/pointers/Pointer.h b/libraries/pointers/src/pointers/Pointer.h index 4e965cd73c..595daebc33 100644 --- a/libraries/pointers/src/pointers/Pointer.h +++ b/libraries/pointers/src/pointers/Pointer.h @@ -77,8 +77,8 @@ public: QUuid getRayUID() { return _pickUID; } protected: - bool _enabled; const QUuid _pickUID; + bool _enabled; virtual PointerEvent buildPointerEvent(const QUuid& uid, const QVariantMap& pickResult) const = 0; diff --git a/libraries/shared/src/PointerEvent.h b/libraries/shared/src/PointerEvent.h index 63c063cd01..074e5ab79b 100644 --- a/libraries/shared/src/PointerEvent.h +++ b/libraries/shared/src/PointerEvent.h @@ -55,9 +55,11 @@ public: Button getButton() const { return _button; } uint32_t getButtons() const { return _buttons; } Qt::KeyboardModifiers getKeyboardModifiers() const { return _keyboardModifiers; } + bool shouldFocus() const { return _shouldFocus; } void setType(EventType type) { _type = type; } void setButton(Button button) { _button = button; } + void setShouldFocus(bool focus) { _shouldFocus = focus; } private: EventType _type; @@ -70,6 +72,8 @@ private: Button _button { NoButtons }; // button associated with this event, (if type is Press, this will be the button that is pressed) uint32_t _buttons { NoButtons }; // the current state of all the buttons. Qt::KeyboardModifiers _keyboardModifiers; // set of keys held when event was generated + + bool _shouldFocus { true }; }; QDebug& operator<<(QDebug& dbg, const PointerEvent& p);