From f53ccf7363b79397612ece27db0485a7d67e8c7b Mon Sep 17 00:00:00 2001 From: SamGondelman Date: Mon, 11 Feb 2019 13:45:36 -0800 Subject: [PATCH] fix create, working on mini tablet --- interface/src/ui/overlays/Overlays.cpp | 10 ++++- .../src/RenderableWebEntityItem.cpp | 2 +- libraries/ui/src/ui/OffscreenQmlSurface.cpp | 6 +-- scripts/system/libraries/WebTablet.js | 10 +++-- scripts/system/miniTablet.js | 41 ++++++++++++------- 5 files changed, 43 insertions(+), 26 deletions(-) diff --git a/interface/src/ui/overlays/Overlays.cpp b/interface/src/ui/overlays/Overlays.cpp index 8a0f3cfd8b..e1708c14fe 100644 --- a/interface/src/ui/overlays/Overlays.cpp +++ b/interface/src/ui/overlays/Overlays.cpp @@ -581,7 +581,15 @@ EntityItemProperties Overlays::convertOverlayToEntityProperties(QVariantMap& ove { auto iter = overlayProps.find("dimensions"); if (iter != overlayProps.end()) { - dimensions = vec3FromVariant(iter.value()); + bool valid = false; + dimensions = vec3FromVariant(iter.value(), valid); + if (!valid) { + dimensions = glm::vec3(vec2FromVariant(iter.value()), 0.0f); + } + } else if (!add) { + EntityPropertyFlags desiredProperties; + desiredProperties += PROP_DIMENSIONS; + dimensions = DependencyManager::get()->getEntityProperties(id, desiredProperties).getDimensions(); } } diff --git a/libraries/entities-renderer/src/RenderableWebEntityItem.cpp b/libraries/entities-renderer/src/RenderableWebEntityItem.cpp index ba136256cb..164adae8ce 100644 --- a/libraries/entities-renderer/src/RenderableWebEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableWebEntityItem.cpp @@ -452,5 +452,5 @@ QObject* WebEntityRenderer::getEventHandler() { } void WebEntityRenderer::emitScriptEvent(const QVariant& message) { - QMetaObject::invokeMethod(this, "scriptEventReceived", Q_ARG(QVariant, message)); + emit scriptEventReceived(message); } \ No newline at end of file diff --git a/libraries/ui/src/ui/OffscreenQmlSurface.cpp b/libraries/ui/src/ui/OffscreenQmlSurface.cpp index 71bb65509f..5f3957fe34 100644 --- a/libraries/ui/src/ui/OffscreenQmlSurface.cpp +++ b/libraries/ui/src/ui/OffscreenQmlSurface.cpp @@ -716,11 +716,7 @@ void OffscreenQmlSurface::setKeyboardRaised(QObject* object, bool raised, bool n } void OffscreenQmlSurface::emitScriptEvent(const QVariant& message) { - if (QThread::currentThread() != thread()) { - QMetaObject::invokeMethod(this, "emitScriptEvent", Qt::QueuedConnection, Q_ARG(QVariant, message)); - } else { - emit scriptEventReceived(message); - } + emit scriptEventReceived(message); } void OffscreenQmlSurface::emitWebEvent(const QVariant& message) { diff --git a/scripts/system/libraries/WebTablet.js b/scripts/system/libraries/WebTablet.js index a578ed0d97..c0e3178521 100644 --- a/scripts/system/libraries/WebTablet.js +++ b/scripts/system/libraries/WebTablet.js @@ -23,7 +23,6 @@ var SENSOR_TO_ROOM_MATRIX = -2; var CAMERA_MATRIX = -7; var ROT_Y_180 = {x: 0.0, y: 1.0, z: 0, w: 0}; var ROT_LANDSCAPE = {x: 1.0, y: 1.0, z: 0, w: 0}; -var ROT_LANDSCAPE_WINDOW = {x: 0.0, y: 0.0, z: 0.0, w: 0}; var TABLET_TEXTURE_RESOLUTION = { x: 480, y: 706 }; var INCHES_TO_METERS = 1 / 39.3701; @@ -286,16 +285,19 @@ WebTablet.prototype.setLandscape = function(newLandscapeValue) { this.landscape = newLandscapeValue; var cameraOrientation = Quat.cancelOutRollAndPitch(Camera.orientation); - Overlays.editOverlay(this.tabletEntityID, - { rotation: Quat.multiply(cameraOrientation, this.landscape ? ROT_LANDSCAPE : ROT_Y_180) }); + var tabletRotation = Quat.multiply(cameraOrientation, this.landscape ? ROT_LANDSCAPE : ROT_Y_180); + Overlays.editOverlay(this.tabletEntityID, { + rotation: tabletRotation + }); var tabletWidth = getTabletWidthFromSettings() * MyAvatar.sensorToWorldScale; var tabletScaleFactor = tabletWidth / TABLET_NATURAL_DIMENSIONS.x; var tabletHeight = TABLET_NATURAL_DIMENSIONS.y * tabletScaleFactor; var screenWidth = 0.9275 * tabletWidth; var screenHeight = 0.8983 * tabletHeight; + var screenRotation = Quat.angleAxis(180, Vec3.UP); Overlays.editOverlay(this.webOverlayID, { - rotation: Quat.multiply(cameraOrientation, ROT_LANDSCAPE_WINDOW), + localRotation: this.landscape ? Quat.multiply(screenRotation, Quat.angleAxis(-90, Vec3.FRONT)) : screenRotation, dimensions: {x: this.landscape ? screenHeight : screenWidth, y: this.landscape ? screenWidth : screenHeight, z: 0.1} }); }; diff --git a/scripts/system/miniTablet.js b/scripts/system/miniTablet.js index 780dacf85e..12550c9d9c 100644 --- a/scripts/system/miniTablet.js +++ b/scripts/system/miniTablet.js @@ -114,7 +114,7 @@ uiHand = LEFT_HAND, miniUIOverlay = null, MINI_UI_HTML = Script.resolvePath("./html/miniTablet.html"), - MINI_UI_DIMENSIONS = { x: 0.059, y: 0.0865 }, + MINI_UI_DIMENSIONS = { x: 0.059, y: 0.0865, z: 0.01 }, MINI_UI_WIDTH_PIXELS = 150, METERS_TO_INCHES = 39.3701, MINI_UI_DPI = MINI_UI_WIDTH_PIXELS / (MINI_UI_DIMENSIONS.x * METERS_TO_INCHES), @@ -172,18 +172,22 @@ function updateMutedStatus() { var isMuted = Audio.muted; - miniOverlayObject.emitScriptEvent(JSON.stringify({ - type: MUTE_MESSAGE, - on: isMuted, - icon: isMuted ? MUTE_ON_ICON : MUTE_OFF_ICON - })); + if (miniOverlayObject) { + miniOverlayObject.emitScriptEvent(JSON.stringify({ + type: MUTE_MESSAGE, + on: isMuted, + icon: isMuted ? MUTE_ON_ICON : MUTE_OFF_ICON + })); + } } function setGotoIcon() { - miniOverlayObject.emitScriptEvent(JSON.stringify({ - type: GOTO_MESSAGE, - icon: GOTO_ICON - })); + if (miniOverlayObject) { + miniOverlayObject.emitScriptEvent(JSON.stringify({ + type: GOTO_MESSAGE, + icon: GOTO_ICON + })); + } } function onWebEventReceived(data) { @@ -452,7 +456,7 @@ solid: true, grabbable: true, showKeyboardFocusHighlight: false, - displayInFront: true, + drawInFront: true, visible: false }); miniUIOverlay = Overlays.addOverlay("web3d", { @@ -465,14 +469,11 @@ alpha: 0, // Hide overlay while its content is being created. grabbable: false, showKeyboardFocusHighlight: false, - displayInFront: true, + drawInFront: true, visible: false }); miniUIOverlayEnabled = false; // This and alpha = 0 hides overlay while its content is being created. - - miniOverlayObject = Overlays.getOverlayObject(miniUIOverlay); - miniOverlayObject.webEventReceived.connect(onWebEventReceived); } function destroy() { @@ -978,6 +979,16 @@ } function updateState() { + if (!ui.miniOverlayObject) { + // Keep trying to connect the event bridge until we succeed + ui.miniOverlayObject = Overlays.getOverlayObject(ui.miniUIOverlay); + if (ui.miniOverlayObject) { + ui.miniOverlayObject.webEventReceived.connect(ui.onWebEventReceived); + ui.updateMutedStatus(); + ui.setGotoIcon(); + } + } + if (STATE_MACHINE[STATE_STRINGS[miniState]].update) { STATE_MACHINE[STATE_STRINGS[miniState]].update(); }