mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-10 09:36:27 +02:00
Make tablet.qml work on Web3DOverlay
This commit is contained in:
parent
ab3c833dd5
commit
84db58dbc6
5 changed files with 63 additions and 20 deletions
|
@ -171,7 +171,7 @@ Item {
|
||||||
console.log("Tablet.onCompleted!");
|
console.log("Tablet.onCompleted!");
|
||||||
var component = Qt.createComponent("TabletButton.qml");
|
var component = Qt.createComponent("TabletButton.qml");
|
||||||
var buttons = [];
|
var buttons = [];
|
||||||
for (var i = 0; i < 5; i++) {
|
for (var i = 0; i < 6; i++) {
|
||||||
var button = component.createObject(flowMain);
|
var button = component.createObject(flowMain);
|
||||||
button.inDebugMode = true;
|
button.inDebugMode = true;
|
||||||
buttons.push(button);
|
buttons.push(button);
|
||||||
|
|
|
@ -18,16 +18,16 @@
|
||||||
#include <QtQuick/QQuickItem>
|
#include <QtQuick/QQuickItem>
|
||||||
#include <QtQml/QQmlContext>
|
#include <QtQml/QQmlContext>
|
||||||
|
|
||||||
|
#include <AbstractViewStateInterface.h>
|
||||||
|
#include <gpu/Batch.h>
|
||||||
#include <DependencyManager.h>
|
#include <DependencyManager.h>
|
||||||
#include <GeometryCache.h>
|
#include <GeometryCache.h>
|
||||||
#include <GeometryUtil.h>
|
#include <GeometryUtil.h>
|
||||||
#include <TextureCache.h>
|
|
||||||
#include <PathUtils.h>
|
|
||||||
#include <gpu/Batch.h>
|
|
||||||
#include <RegisteredMetaTypes.h>
|
|
||||||
#include <AbstractViewStateInterface.h>
|
|
||||||
|
|
||||||
#include <gl/OffscreenQmlSurface.h>
|
#include <gl/OffscreenQmlSurface.h>
|
||||||
|
#include <PathUtils.h>
|
||||||
|
#include <RegisteredMetaTypes.h>
|
||||||
|
#include <TabletScriptingInterface.h>
|
||||||
|
#include <TextureCache.h>
|
||||||
|
|
||||||
static const float DPI = 30.47f;
|
static const float DPI = 30.47f;
|
||||||
static const float INCHES_TO_METERS = 1.0f / 39.3701f;
|
static const float INCHES_TO_METERS = 1.0f / 39.3701f;
|
||||||
|
@ -36,7 +36,7 @@ static const float OPAQUE_ALPHA_THRESHOLD = 0.99f;
|
||||||
|
|
||||||
QString const Web3DOverlay::TYPE = "web3d";
|
QString const Web3DOverlay::TYPE = "web3d";
|
||||||
|
|
||||||
Web3DOverlay::Web3DOverlay() : _dpi(DPI) {
|
Web3DOverlay::Web3DOverlay() : _dpi(DPI) {
|
||||||
_touchDevice.setCapabilities(QTouchDevice::Position);
|
_touchDevice.setCapabilities(QTouchDevice::Position);
|
||||||
_touchDevice.setType(QTouchDevice::TouchScreen);
|
_touchDevice.setType(QTouchDevice::TouchScreen);
|
||||||
_touchDevice.setName("RenderableWebEntityItemTouchDevice");
|
_touchDevice.setName("RenderableWebEntityItemTouchDevice");
|
||||||
|
@ -57,6 +57,24 @@ Web3DOverlay::Web3DOverlay(const Web3DOverlay* Web3DOverlay) :
|
||||||
|
|
||||||
Web3DOverlay::~Web3DOverlay() {
|
Web3DOverlay::~Web3DOverlay() {
|
||||||
if (_webSurface) {
|
if (_webSurface) {
|
||||||
|
QQuickItem* rootItem = _webSurface->getRootItem();
|
||||||
|
|
||||||
|
// TABLET_UI_HACK: TODO: update this with rootTablet
|
||||||
|
if (rootItem && rootItem->objectName() == "tablet") {
|
||||||
|
auto tabletScriptingInterface = DependencyManager::get<TabletScriptingInterface>();
|
||||||
|
tabletScriptingInterface->setQmlTablet("com.highfidelity.interface.tablet.system", nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fix for crash in QtWebEngineCore when rapidly switching domains
|
||||||
|
// Call stop on the QWebEngineView before destroying OffscreenQMLSurface.
|
||||||
|
if (rootItem) {
|
||||||
|
QObject* obj = rootItem->findChild<QObject*>("webEngineView");
|
||||||
|
if (obj) {
|
||||||
|
// stop loading
|
||||||
|
QMetaObject::invokeMethod(obj, "stop");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_webSurface->pause();
|
_webSurface->pause();
|
||||||
_webSurface->disconnect(_connection);
|
_webSurface->disconnect(_connection);
|
||||||
|
|
||||||
|
@ -101,6 +119,32 @@ void Web3DOverlay::update(float deltatime) {
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Web3DOverlay::loadSourceURL() {
|
||||||
|
|
||||||
|
QUrl sourceUrl(_url);
|
||||||
|
if (sourceUrl.scheme() == "http" || sourceUrl.scheme() == "https" ||
|
||||||
|
_url.toLower().endsWith(".htm") || _url.toLower().endsWith(".html")) {
|
||||||
|
|
||||||
|
_webSurface->setBaseUrl(QUrl::fromLocalFile(PathUtils::resourcesPath() + "/qml/"));
|
||||||
|
_webSurface->load("Web3DOverlay.qml");
|
||||||
|
_webSurface->resume();
|
||||||
|
_webSurface->getRootItem()->setProperty("url", _url);
|
||||||
|
_webSurface->getRootItem()->setProperty("scriptURL", _scriptURL);
|
||||||
|
_webSurface->getRootContext()->setContextProperty("ApplicationInterface", qApp);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
_webSurface->setBaseUrl(QUrl::fromLocalFile(PathUtils::resourcesPath()));
|
||||||
|
_webSurface->load(_url, [&](QQmlContext* context, QObject* obj) {});
|
||||||
|
_webSurface->resume();
|
||||||
|
|
||||||
|
// TABLET_UI_HACK: TODO: update this to use rootTablet.
|
||||||
|
if (_webSurface->getRootItem() && _webSurface->getRootItem()->objectName() == "tablet") {
|
||||||
|
auto tabletScriptingInterface = DependencyManager::get<TabletScriptingInterface>();
|
||||||
|
tabletScriptingInterface->setQmlTablet("com.highfidelity.interface.tablet.system", _webSurface->getRootItem());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Web3DOverlay::render(RenderArgs* args) {
|
void Web3DOverlay::render(RenderArgs* args) {
|
||||||
if (!_visible || !getParentVisible()) {
|
if (!_visible || !getParentVisible()) {
|
||||||
return;
|
return;
|
||||||
|
@ -119,12 +163,9 @@ void Web3DOverlay::render(RenderArgs* args) {
|
||||||
// and the current rendering load)
|
// and the current rendering load)
|
||||||
_webSurface->setMaxFps(10);
|
_webSurface->setMaxFps(10);
|
||||||
_webSurface->create(currentContext);
|
_webSurface->create(currentContext);
|
||||||
_webSurface->setBaseUrl(QUrl::fromLocalFile(PathUtils::resourcesPath() + "/qml/"));
|
|
||||||
_webSurface->load("Web3DOverlay.qml");
|
loadSourceURL();
|
||||||
_webSurface->resume();
|
|
||||||
_webSurface->getRootItem()->setProperty("url", _url);
|
|
||||||
_webSurface->getRootItem()->setProperty("scriptURL", _scriptURL);
|
|
||||||
_webSurface->getRootContext()->setContextProperty("ApplicationInterface", qApp);
|
|
||||||
_webSurface->resize(QSize(_resolution.x, _resolution.y));
|
_webSurface->resize(QSize(_resolution.x, _resolution.y));
|
||||||
currentContext->makeCurrent(currentSurface);
|
currentContext->makeCurrent(currentSurface);
|
||||||
|
|
||||||
|
@ -150,7 +191,7 @@ void Web3DOverlay::render(RenderArgs* args) {
|
||||||
point.setPos(windowPoint);
|
point.setPos(windowPoint);
|
||||||
QList<QTouchEvent::TouchPoint> touchPoints;
|
QList<QTouchEvent::TouchPoint> touchPoints;
|
||||||
touchPoints.push_back(point);
|
touchPoints.push_back(point);
|
||||||
QTouchEvent* touchEvent = new QTouchEvent(QEvent::TouchEnd, nullptr, Qt::NoModifier, Qt::TouchPointReleased,
|
QTouchEvent* touchEvent = new QTouchEvent(QEvent::TouchEnd, nullptr, Qt::NoModifier, Qt::TouchPointReleased,
|
||||||
touchPoints);
|
touchPoints);
|
||||||
touchEvent->setWindow(_webSurface->getWindow());
|
touchEvent->setWindow(_webSurface->getWindow());
|
||||||
touchEvent->setDevice(&_touchDevice);
|
touchEvent->setDevice(&_touchDevice);
|
||||||
|
@ -167,7 +208,7 @@ void Web3DOverlay::render(RenderArgs* args) {
|
||||||
vec4 color(toGlm(getColor()), getAlpha());
|
vec4 color(toGlm(getColor()), getAlpha());
|
||||||
|
|
||||||
Transform transform = getTransform();
|
Transform transform = getTransform();
|
||||||
|
|
||||||
// FIXME: applyTransformTo causes tablet overlay to detach from tablet entity.
|
// FIXME: applyTransformTo causes tablet overlay to detach from tablet entity.
|
||||||
// Perhaps rather than deleting the following code it should be run only if isFacingAvatar() is true?
|
// Perhaps rather than deleting the following code it should be run only if isFacingAvatar() is true?
|
||||||
/*
|
/*
|
||||||
|
@ -237,7 +278,7 @@ void Web3DOverlay::handlePointerEvent(const PointerEvent& event) {
|
||||||
|
|
||||||
if (event.getType() == PointerEvent::Move) {
|
if (event.getType() == PointerEvent::Move) {
|
||||||
// Forward a mouse move event to the Web surface.
|
// Forward a mouse move event to the Web surface.
|
||||||
QMouseEvent* mouseEvent = new QMouseEvent(QEvent::MouseMove, windowPoint, windowPoint, windowPoint, Qt::NoButton,
|
QMouseEvent* mouseEvent = new QMouseEvent(QEvent::MouseMove, windowPoint, windowPoint, windowPoint, Qt::NoButton,
|
||||||
Qt::NoButton, Qt::NoModifier);
|
Qt::NoButton, Qt::NoModifier);
|
||||||
QCoreApplication::postEvent(_webSurface->getWindow(), mouseEvent);
|
QCoreApplication::postEvent(_webSurface->getWindow(), mouseEvent);
|
||||||
}
|
}
|
||||||
|
@ -338,7 +379,7 @@ void Web3DOverlay::setURL(const QString& url) {
|
||||||
_url = url;
|
_url = url;
|
||||||
if (_webSurface) {
|
if (_webSurface) {
|
||||||
AbstractViewStateInterface::instance()->postLambdaEvent([this, url] {
|
AbstractViewStateInterface::instance()->postLambdaEvent([this, url] {
|
||||||
_webSurface->getRootItem()->setProperty("url", url);
|
loadSourceURL();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,7 @@ public:
|
||||||
Web3DOverlay(const Web3DOverlay* Web3DOverlay);
|
Web3DOverlay(const Web3DOverlay* Web3DOverlay);
|
||||||
virtual ~Web3DOverlay();
|
virtual ~Web3DOverlay();
|
||||||
|
|
||||||
|
void loadSourceURL();
|
||||||
virtual void render(RenderArgs* args) override;
|
virtual void render(RenderArgs* args) override;
|
||||||
virtual const render::ShapeKey getShapeKey() override;
|
virtual const render::ShapeKey getShapeKey() override;
|
||||||
|
|
||||||
|
@ -46,7 +47,7 @@ public:
|
||||||
|
|
||||||
glm::vec2 getSize();
|
glm::vec2 getSize();
|
||||||
|
|
||||||
virtual bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, float& distance,
|
virtual bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, float& distance,
|
||||||
BoxFace& face, glm::vec3& surfaceNormal) override;
|
BoxFace& face, glm::vec3& surfaceNormal) override;
|
||||||
|
|
||||||
virtual Web3DOverlay* createClone() const override;
|
virtual Web3DOverlay* createClone() const override;
|
||||||
|
|
|
@ -366,6 +366,8 @@ void RenderableWebEntityItem::destroyWebSurface() {
|
||||||
tabletScriptingInterface->setQmlTablet("com.highfidelity.interface.tablet.system", nullptr);
|
tabletScriptingInterface->setQmlTablet("com.highfidelity.interface.tablet.system", nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Fix for crash in QtWebEngineCore when rapidly switching domains
|
||||||
|
// Call stop on the QWebEngineView before destroying OffscreenQMLSurface.
|
||||||
if (rootItem) {
|
if (rootItem) {
|
||||||
QObject* obj = rootItem->findChild<QObject*>("webEngineView");
|
QObject* obj = rootItem->findChild<QObject*>("webEngineView");
|
||||||
if (obj) {
|
if (obj) {
|
||||||
|
|
|
@ -27,7 +27,6 @@
|
||||||
|
|
||||||
Script.scriptEnding.connect(function () {
|
Script.scriptEnding.connect(function () {
|
||||||
tablet.removeButton(button);
|
tablet.removeButton(button);
|
||||||
button.clicked.disconnect(onClicked);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
}()); // END LOCAL_SCOPE
|
}()); // END LOCAL_SCOPE
|
||||||
|
|
Loading…
Reference in a new issue