Merge pull request #11003 from davidkelly/dk/placeholderHighlighting

Highlight using simple yellow bounding box
This commit is contained in:
David Kelly 2017-07-20 10:10:50 -07:00 committed by GitHub
commit c75a925bb6
3 changed files with 30 additions and 5 deletions

View file

@ -28,13 +28,16 @@ ContextOverlayInterface::ContextOverlayInterface() {
_entityPropertyFlags += PROP_POSITION;
_entityPropertyFlags += PROP_ROTATION;
_entityPropertyFlags += PROP_MARKETPLACE_ID;
_entityPropertyFlags += PROP_DIMENSIONS;
auto entityTreeRenderer = DependencyManager::get<EntityTreeRenderer>().data();
connect(entityTreeRenderer, SIGNAL(mousePressOnEntity(const EntityItemID&, const PointerEvent&)), this, SLOT(createOrDestroyContextOverlay(const EntityItemID&, const PointerEvent&)));
}
static const xColor BB_OVERLAY_COLOR = {255, 255, 0};
void ContextOverlayInterface::createOrDestroyContextOverlay(const EntityItemID& entityItemID, const PointerEvent& event) {
if (event.getButton() == PointerEvent::SecondaryButton) {
if (_enabled && event.getButton() == PointerEvent::SecondaryButton) {
EntityItemProperties entityProperties = _entityScriptingInterface->getEntityProperties(entityItemID, _entityPropertyFlags);
if (entityProperties.getMarketplaceID().length() != 0) {
@ -42,6 +45,18 @@ void ContextOverlayInterface::createOrDestroyContextOverlay(const EntityItemID&
_entityMarketplaceID = entityProperties.getMarketplaceID();
setCurrentEntityWithContextOverlay(entityItemID);
if (_bbOverlayID == UNKNOWN_OVERLAY_ID || !qApp->getOverlays().isAddedOverlay(_bbOverlayID)) {
_bbOverlay = std::make_shared<Cube3DOverlay>();
_bbOverlay->setIsSolid(false);
_bbOverlay->setColor(BB_OVERLAY_COLOR);
_bbOverlay->setDrawInFront(true);
_bbOverlayID = qApp->getOverlays().addOverlay(_bbOverlay);
}
_bbOverlay->setDimensions(entityProperties.getDimensions());
_bbOverlay->setRotation(entityProperties.getRotation());
_bbOverlay->setPosition(entityProperties.getPosition());
_bbOverlay->setVisible(true);
if (_contextOverlayID == UNKNOWN_OVERLAY_ID || !qApp->getOverlays().isAddedOverlay(_contextOverlayID)) {
_contextOverlay = std::make_shared<Image3DOverlay>();
_contextOverlay->setAlpha(1.0f);
@ -55,7 +70,7 @@ void ContextOverlayInterface::createOrDestroyContextOverlay(const EntityItemID&
_contextOverlayID = qApp->getOverlays().addOverlay(_contextOverlay);
}
_contextOverlay->setDimensions(glm::vec2(0.1f, 0.1f) * glm::distance(entityProperties.getPosition(), qApp->getCamera().getPosition()));
_contextOverlay->setDimensions(glm::vec2(0.05f, 0.05f) * glm::distance(entityProperties.getPosition(), qApp->getCamera().getPosition()));
_contextOverlay->setPosition(entityProperties.getPosition());
_contextOverlay->setRotation(entityProperties.getRotation());
_contextOverlay->setVisible(true);
@ -70,8 +85,11 @@ void ContextOverlayInterface::destroyContextOverlay(const EntityItemID& entityIt
setCurrentEntityWithContextOverlay(QUuid());
qApp->getOverlays().deleteOverlay(_contextOverlayID);
qApp->getOverlays().deleteOverlay(_bbOverlayID);
_contextOverlay = NULL;
_bbOverlay = NULL;
_contextOverlayID = UNKNOWN_OVERLAY_ID;
_bbOverlayID = UNKNOWN_OVERLAY_ID;
_entityMarketplaceID.clear();
}
@ -80,7 +98,7 @@ void ContextOverlayInterface::destroyContextOverlay(const EntityItemID& entityIt
}
void ContextOverlayInterface::clickContextOverlay(const OverlayID& overlayID, const PointerEvent& event) {
if (overlayID == _contextOverlayID && event.getButton() == PointerEvent::PrimaryButton) {
if (overlayID == _contextOverlayID && event.getButton() == PointerEvent::PrimaryButton) {
qCDebug(context_overlay) << "Clicked Context Overlay. Entity ID:" << _currentEntityWithContextOverlay << "Overlay ID:" << overlayID;
openMarketplace();
destroyContextOverlay(_currentEntityWithContextOverlay, PointerEvent());

View file

@ -22,6 +22,7 @@
#include "EntityScriptingInterface.h"
#include "ui/overlays/Image3DOverlay.h"
#include "ui/overlays/Cube3DOverlay.h"
#include "ui/overlays/Overlays.h"
#include "scripting/HMDScriptingInterface.h"
@ -35,17 +36,22 @@ class ContextOverlayInterface : public QObject, public Dependency {
Q_OBJECT
Q_PROPERTY(QUuid entityWithContextOverlay READ getCurrentEntityWithContextOverlay WRITE setCurrentEntityWithContextOverlay)
Q_PROPERTY(bool enabled READ getEnabled WRITE setEnabled);
QSharedPointer<EntityScriptingInterface> _entityScriptingInterface;
EntityPropertyFlags _entityPropertyFlags;
QSharedPointer<HMDScriptingInterface> _hmdScriptingInterface;
QSharedPointer<TabletScriptingInterface> _tabletScriptingInterface;
OverlayID _contextOverlayID { UNKNOWN_OVERLAY_ID };
OverlayID _bbOverlayID { UNKNOWN_OVERLAY_ID };
std::shared_ptr<Image3DOverlay> _contextOverlay { nullptr };
std::shared_ptr<Cube3DOverlay> _bbOverlay { nullptr };
public:
ContextOverlayInterface();
Q_INVOKABLE QUuid getCurrentEntityWithContextOverlay() { return _currentEntityWithContextOverlay; }
void setCurrentEntityWithContextOverlay(const QUuid& entityID) { _currentEntityWithContextOverlay = entityID; }
void setEnabled(bool enabled) { _enabled = enabled; }
bool getEnabled() { return _enabled; }
public slots:
void createOrDestroyContextOverlay(const EntityItemID& entityItemID, const PointerEvent& event);
@ -55,6 +61,7 @@ public slots:
private:
bool _verboseLogging { true };
bool _enabled { true };
QUuid _currentEntityWithContextOverlay{};
QString _entityMarketplaceID;

View file

@ -131,7 +131,7 @@ public slots:
OverlayID cloneOverlay(OverlayID id);
/**jsdoc
* Edit an overlay's properties.
* Edit an overlay's properties.
*
* @function Overlays.editOverlay
* @param {Overlays.OverlayID} overlayID The ID of the overlay to edit.
@ -337,7 +337,7 @@ private:
#endif
bool _enabled = true;
PointerEvent Overlays::calculateOverlayPointerEvent(OverlayID overlayID, PickRay ray, RayToOverlayIntersectionResult rayPickResult,
PointerEvent calculateOverlayPointerEvent(OverlayID overlayID, PickRay ray, RayToOverlayIntersectionResult rayPickResult,
QMouseEvent* event, PointerEvent::EventType eventType);
OverlayID _currentClickingOnOverlayID { UNKNOWN_OVERLAY_ID };