mirror of
https://github.com/overte-org/overte.git
synced 2025-08-10 20:03:06 +02:00
Merge pull request #5583 from ZappoMan/clickToFocusWebEntity
make web entity focus click based
This commit is contained in:
commit
5d65937120
5 changed files with 32 additions and 5 deletions
|
@ -673,8 +673,10 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) :
|
||||||
auto& packetReceiver = nodeList->getPacketReceiver();
|
auto& packetReceiver = nodeList->getPacketReceiver();
|
||||||
packetReceiver.registerListener(PacketType::DomainConnectionDenied, this, "handleDomainConnectionDeniedPacket");
|
packetReceiver.registerListener(PacketType::DomainConnectionDenied, this, "handleDomainConnectionDeniedPacket");
|
||||||
|
|
||||||
|
// 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<EntityScriptingInterface>();
|
auto entityScriptingInterface = DependencyManager::get<EntityScriptingInterface>();
|
||||||
connect(entityScriptingInterface.data(), &EntityScriptingInterface::hoverEnterEntity, [this, entityScriptingInterface](const EntityItemID& entityItemID, const MouseEvent& event) {
|
connect(entityScriptingInterface.data(), &EntityScriptingInterface::clickDownOnEntity,
|
||||||
|
[this, entityScriptingInterface](const EntityItemID& entityItemID, const MouseEvent& event) {
|
||||||
if (_keyboardFocusedItem != entityItemID) {
|
if (_keyboardFocusedItem != entityItemID) {
|
||||||
_keyboardFocusedItem = UNKNOWN_ENTITY_ID;
|
_keyboardFocusedItem = UNKNOWN_ENTITY_ID;
|
||||||
auto properties = entityScriptingInterface->getEntityProperties(entityItemID);
|
auto properties = entityScriptingInterface->getEntityProperties(entityItemID);
|
||||||
|
@ -684,15 +686,16 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) :
|
||||||
if (webEntity) {
|
if (webEntity) {
|
||||||
webEntity->setProxyWindow(_window->windowHandle());
|
webEntity->setProxyWindow(_window->windowHandle());
|
||||||
_keyboardFocusedItem = entityItemID;
|
_keyboardFocusedItem = entityItemID;
|
||||||
|
_lastAcceptedKeyPress = usecTimestampNow();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
connect(entityScriptingInterface.data(), &EntityScriptingInterface::hoverLeaveEntity, [=](const EntityItemID& entityItemID, const MouseEvent& event) {
|
// If the user clicks somewhere where there is NO entity at all, we will release focus
|
||||||
if (_keyboardFocusedItem == entityItemID) {
|
connect(getEntities(), &EntityTreeRenderer::mousePressOffEntity,
|
||||||
_keyboardFocusedItem = UNKNOWN_ENTITY_ID;
|
[=](const RayToEntityIntersectionResult& entityItemID, const QMouseEvent* event, unsigned int deviceId) {
|
||||||
}
|
_keyboardFocusedItem = UNKNOWN_ENTITY_ID;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1270,6 +1273,7 @@ bool Application::event(QEvent* event) {
|
||||||
event->setAccepted(false);
|
event->setAccepted(false);
|
||||||
QCoreApplication::sendEvent(webEntity->getEventHandler(), event);
|
QCoreApplication::sendEvent(webEntity->getEventHandler(), event);
|
||||||
if (event->isAccepted()) {
|
if (event->isAccepted()) {
|
||||||
|
_lastAcceptedKeyPress = usecTimestampNow();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1986,6 +1990,15 @@ void Application::idle() {
|
||||||
return; // bail early, nothing to do here.
|
return; // bail early, nothing to do here.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Drop focus from _keyboardFocusedItem if no keyboard messages for 30 seconds
|
||||||
|
if (!_keyboardFocusedItem.isInvalidID()) {
|
||||||
|
const quint64 LOSE_FOCUS_AFTER_ELAPSED_TIME = 30 * USECS_PER_SECOND; // if idle for 30 seconds, drop focus
|
||||||
|
quint64 elapsedSinceAcceptedKeyPress = usecTimestampNow() - _lastAcceptedKeyPress;
|
||||||
|
if (elapsedSinceAcceptedKeyPress > LOSE_FOCUS_AFTER_ELAPSED_TIME) {
|
||||||
|
_keyboardFocusedItem = UNKNOWN_ENTITY_ID;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Normally we check PipelineWarnings, but since idle will often take more than 10ms we only show these idle timing
|
// Normally we check PipelineWarnings, but since idle will often take more than 10ms we only show these idle timing
|
||||||
// details if we're in ExtraDebugging mode. However, the ::update() and its subcomponents will show their timing
|
// details if we're in ExtraDebugging mode. However, the ::update() and its subcomponents will show their timing
|
||||||
// details normally.
|
// details normally.
|
||||||
|
|
|
@ -680,6 +680,7 @@ private:
|
||||||
DialogsManagerScriptingInterface* _dialogsManagerScriptingInterface = new DialogsManagerScriptingInterface();
|
DialogsManagerScriptingInterface* _dialogsManagerScriptingInterface = new DialogsManagerScriptingInterface();
|
||||||
|
|
||||||
EntityItemID _keyboardFocusedItem;
|
EntityItemID _keyboardFocusedItem;
|
||||||
|
quint64 _lastAcceptedKeyPress = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // hifi_Application_h
|
#endif // hifi_Application_h
|
||||||
|
|
|
@ -861,6 +861,8 @@ void EntityTreeRenderer::mousePressEvent(QMouseEvent* event, unsigned int device
|
||||||
if (entityScript.property("clickDownOnEntity").isValid()) {
|
if (entityScript.property("clickDownOnEntity").isValid()) {
|
||||||
entityScript.property("clickDownOnEntity").call(entityScript, entityScriptArgs);
|
entityScript.property("clickDownOnEntity").call(entityScript, entityScriptArgs);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
emit mousePressOffEntity(rayPickResult, event, deviceID);
|
||||||
}
|
}
|
||||||
_lastMouseEvent = MouseEvent(*event, deviceID);
|
_lastMouseEvent = MouseEvent(*event, deviceID);
|
||||||
_lastMouseEventValid = true;
|
_lastMouseEventValid = true;
|
||||||
|
|
|
@ -95,6 +95,7 @@ public:
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void mousePressOnEntity(const RayToEntityIntersectionResult& entityItemID, const QMouseEvent* event, unsigned int deviceId);
|
void mousePressOnEntity(const RayToEntityIntersectionResult& entityItemID, const QMouseEvent* event, unsigned int deviceId);
|
||||||
|
void mousePressOffEntity(const RayToEntityIntersectionResult& entityItemID, const QMouseEvent* event, unsigned int deviceId);
|
||||||
void mouseMoveOnEntity(const RayToEntityIntersectionResult& entityItemID, const QMouseEvent* event, unsigned int deviceId);
|
void mouseMoveOnEntity(const RayToEntityIntersectionResult& entityItemID, const QMouseEvent* event, unsigned int deviceId);
|
||||||
void mouseReleaseOnEntity(const RayToEntityIntersectionResult& entityItemID, const QMouseEvent* event, unsigned int deviceId);
|
void mouseReleaseOnEntity(const RayToEntityIntersectionResult& entityItemID, const QMouseEvent* event, unsigned int deviceId);
|
||||||
|
|
||||||
|
|
|
@ -56,6 +56,16 @@ RenderableWebEntityItem::~RenderableWebEntityItem() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderableWebEntityItem::render(RenderArgs* args) {
|
void RenderableWebEntityItem::render(RenderArgs* args) {
|
||||||
|
|
||||||
|
#ifdef WANT_EXTRA_DEBUGGING
|
||||||
|
{
|
||||||
|
gpu::Batch& batch = *args->_batch;
|
||||||
|
batch.setModelTransform(getTransformToCenter()); // we want to include the scale as well
|
||||||
|
glm::vec4 cubeColor{ 1.0f, 0.0f, 0.0f, 1.0f};
|
||||||
|
DependencyManager::get<DeferredLightingEffect>()->renderWireCube(batch, 1.0f, cubeColor);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
QOpenGLContext * currentContext = QOpenGLContext::currentContext();
|
QOpenGLContext * currentContext = QOpenGLContext::currentContext();
|
||||||
QSurface * currentSurface = currentContext->surface();
|
QSurface * currentSurface = currentContext->surface();
|
||||||
if (!_webSurface) {
|
if (!_webSurface) {
|
||||||
|
|
Loading…
Reference in a new issue