20 #ifndef hifi_Overlays_h
21 #define hifi_Overlays_h
23 #include <QMouseEvent>
24 #include <QReadWriteLock>
26 #include <PointerEvent.h>
27 #include <ScriptValue.h>
31 #include <EntityScriptingInterface.h>
47 class RayToOverlayIntersectionResult {
49 bool intersects {
false };
51 float distance { 0.0f };
52 BoxFace face { UNKNOWN_FACE };
53 glm::vec3 surfaceNormal;
54 glm::vec3 intersection;
55 QVariantMap extraInfo;
57 Q_DECLARE_METATYPE(RayToOverlayIntersectionResult);
58 ScriptValue RayToOverlayIntersectionResultToScriptValue(
ScriptEngine* engine,
const RayToOverlayIntersectionResult& value);
59 bool RayToOverlayIntersectionResultFromScriptValue(
const ScriptValue&
object, RayToOverlayIntersectionResult& value);
61 class ParabolaToOverlayIntersectionResult {
63 bool intersects {
false };
65 float distance { 0.0f };
66 float parabolicDistance { 0.0f };
67 BoxFace face { UNKNOWN_FACE };
68 glm::vec3 surfaceNormal;
69 glm::vec3 intersection;
70 QVariantMap extraInfo;
91 class Overlays :
public QObject {
94 Q_PROPERTY(QUuid keyboardFocusOverlay READ getKeyboardFocusOverlay WRITE setKeyboardFocusOverlay)
100 void update(
float deltatime);
101 void render(RenderArgs* renderArgs);
103 Overlay::Pointer take2DOverlay(
const QUuid&
id);
104 Overlay::Pointer get2DOverlay(
const QUuid&
id)
const;
107 QUuid addOverlay(Overlay* overlay) {
return add2DOverlay(Overlay::Pointer(overlay)); }
108 QUuid add2DOverlay(
const Overlay::Pointer& overlay);
110 RayToOverlayIntersectionResult findRayIntersectionVector(
const PickRay& ray,
bool precisionPicking,
111 const QVector<EntityItemID>& include,
112 const QVector<EntityItemID>& discard,
113 bool visibleOnly =
false,
bool collidableOnly =
false);
115 ParabolaToOverlayIntersectionResult findParabolaIntersectionVector(
const PickParabola& parabola,
bool precisionPicking,
116 const QVector<EntityItemID>& include,
117 const QVector<EntityItemID>& discard,
118 bool visibleOnly =
false,
bool collidableOnly =
false);
120 void cleanupAllOverlays();
137 QUuid addOverlay(
const QString& type,
const QVariant& properties);
146 QUuid cloneOverlay(
const QUuid&
id);
168 bool editOverlay(
const QUuid&
id,
const QVariant& properties);
196 bool editOverlays(
const QVariant& propertiesById);
203 void deleteOverlay(
const QUuid&
id);
220 QString getOverlayType(
const QUuid&
id);
290 QObject* getOverlayObject(
const QUuid&
id);
309 QUuid getOverlayAtPoint(
const glm::vec2& point);
341 RayToOverlayIntersectionResult findRayIntersection(
const PickRay& ray,
342 bool precisionPicking =
false,
345 bool visibleOnly =
false,
346 bool collidableOnly =
false);
374 QVector<QUuid> findOverlays(
const glm::vec3& center,
float radius);
394 bool isLoaded(
const QUuid&
id);
419 QSizeF textSize(
const QUuid&
id,
const QString& text);
441 bool isAddedOverlay(
const QUuid&
id);
481 void sendMousePressOnOverlay(
const QUuid&
id,
const PointerEvent& event);
489 void sendMouseReleaseOnOverlay(
const QUuid&
id,
const PointerEvent& event);
497 void sendMouseMoveOnOverlay(
const QUuid&
id,
const PointerEvent& event);
505 void sendHoverEnterOverlay(
const QUuid&
id,
const PointerEvent& event);
513 void sendHoverOverOverlay(
const QUuid&
id,
const PointerEvent& event);
521 void sendHoverLeaveOverlay(
const QUuid&
id,
const PointerEvent& event);
530 QUuid getKeyboardFocusOverlay() {
return DependencyManager::get<EntityScriptingInterface>()->getKeyboardFocusEntity(); }
540 void setKeyboardFocusOverlay(
const QUuid&
id) { DependencyManager::get<EntityScriptingInterface>()->setKeyboardFocusEntity(
id); }
564 void overlayDeleted(
const QUuid&
id);
588 void mousePressOnOverlay(
const QUuid&
id,
const PointerEvent& event);
597 void mouseDoublePressOnOverlay(
const QUuid&
id,
const PointerEvent& event);
607 void mouseReleaseOnOverlay(
const QUuid&
id,
const PointerEvent& event);
617 void mouseMoveOnOverlay(
const QUuid&
id,
const PointerEvent& event);
624 void mousePressOffOverlay();
631 void mouseDoublePressOffOverlay();
653 void hoverEnterOverlay(
const QUuid&
id,
const PointerEvent& event);
663 void hoverOverOverlay(
const QUuid&
id,
const PointerEvent& event);
673 void hoverLeaveOverlay(
const QUuid&
id,
const PointerEvent& event);
676 void cleanupOverlaysToDelete();
678 mutable QRecursiveMutex _mutex;
679 QMap<QUuid, Overlay::Pointer> _overlays;
680 QList<Overlay::Pointer> _overlaysToDelete;
682 unsigned int _stackOrder { 1 };
684 std::atomic<bool> _shuttingDown {
false };
686 PointerEvent calculateOverlayPointerEvent(
const QUuid&
id,
const PickRay& ray,
const RayToOverlayIntersectionResult& rayPickResult,
687 QMouseEvent* event, PointerEvent::EventType eventType);
689 static QString entityToOverlayType(
const QString& type);
690 static std::unordered_map<QString, QString> _entityToOverlayTypes;
691 static std::unordered_map<QString, QString> _overlayToEntityTypes;
694 void mousePressOnPointerEvent(
const QUuid&
id,
const PointerEvent& event);
695 void mousePressOffPointerEvent();
696 void mouseDoublePressOnPointerEvent(
const QUuid&
id,
const PointerEvent& event);
697 void mouseDoublePressOffPointerEvent();
698 void mouseReleasePointerEvent(
const QUuid&
id,
const PointerEvent& event);
699 void mouseMovePointerEvent(
const QUuid&
id,
const PointerEvent& event);
700 void hoverEnterPointerEvent(
const QUuid&
id,
const PointerEvent& event);
701 void hoverOverPointerEvent(
const QUuid&
id,
const PointerEvent& event);
702 void hoverLeavePointerEvent(
const QUuid&
id,
const PointerEvent& event);
707 #define ADD_TYPE_MAP(entity, overlay) \
708 _entityToOverlayTypes[#entity] = #overlay; \
709 _overlayToEntityTypes[#overlay] = #entity;
Represents a 2D or 3D pointer to the scripting engine. Exposed as PointerEvent
Definition: PointerEvent.h:30
Provides an engine-independent interface for a scripting engine.
Definition: ScriptEngine.h:93
[ScriptInterface] Provides an engine-independent interface for QScriptValue
Definition: ScriptValue.h:40