From c62b07d26f5bea4c246313f3ae4abfcef40e8382 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Thu, 30 Mar 2017 11:36:21 -0700 Subject: [PATCH] add setLandscape call to tablet --- interface/src/ui/overlays/Web3DOverlay.cpp | 7 ++++++ interface/src/ui/overlays/Web3DOverlay.h | 2 ++ .../src/TabletScriptingInterface.h | 14 +++++++++-- scripts/system/libraries/WebTablet.js | 23 +++++++++++-------- scripts/system/tablet-ui/tabletUI.js | 15 ++++++++++-- 5 files changed, 47 insertions(+), 14 deletions(-) diff --git a/interface/src/ui/overlays/Web3DOverlay.cpp b/interface/src/ui/overlays/Web3DOverlay.cpp index e05ae1aacd..8c1c54a585 100644 --- a/interface/src/ui/overlays/Web3DOverlay.cpp +++ b/interface/src/ui/overlays/Web3DOverlay.cpp @@ -270,6 +270,11 @@ void Web3DOverlay::render(RenderArgs* args) { } } + if (_mayNeedResize) { + _mayNeedResize = false; + _webSurface->resize(QSize(_resolution.x, _resolution.y)); + } + vec2 halfSize = getSize() / 2.0f; vec4 color(toGlm(getColor()), getAlpha()); @@ -491,6 +496,8 @@ void Web3DOverlay::setProperties(const QVariantMap& properties) { _inputMode = Touch; } } + + _mayNeedResize = true; } QVariant Web3DOverlay::getProperty(const QString& property) { diff --git a/interface/src/ui/overlays/Web3DOverlay.h b/interface/src/ui/overlays/Web3DOverlay.h index 6a35dec96d..1e3706ed25 100644 --- a/interface/src/ui/overlays/Web3DOverlay.h +++ b/interface/src/ui/overlays/Web3DOverlay.h @@ -87,6 +87,8 @@ private: uint8_t _desiredMaxFPS { 10 }; uint8_t _currentMaxFPS { 0 }; + bool _mayNeedResize { false }; + QMetaObject::Connection _mousePressConnection; QMetaObject::Connection _mouseReleaseConnection; QMetaObject::Connection _mouseMoveConnection; diff --git a/libraries/script-engine/src/TabletScriptingInterface.h b/libraries/script-engine/src/TabletScriptingInterface.h index 2e7b91fa4c..35b4f6d142 100644 --- a/libraries/script-engine/src/TabletScriptingInterface.h +++ b/libraries/script-engine/src/TabletScriptingInterface.h @@ -63,7 +63,7 @@ signals: * @returns {Signal} */ void tabletNotification(); - + private: void processMenuEvents(QObject* object, const QKeyEvent* event); void processTabletEvents(QObject* object, const QKeyEvent* event); @@ -85,6 +85,7 @@ class TabletProxy : public QObject { Q_OBJECT Q_PROPERTY(QString name READ getName) Q_PROPERTY(bool toolbarMode READ getToolbarMode WRITE setToolbarMode) + Q_PROPERTY(bool landscape READ getLandscape WRITE setLandscape) public: TabletProxy(QString name); @@ -173,6 +174,14 @@ public: */ Q_INVOKABLE bool onHomeScreen(); + /**jsdoc + * set tablet into our out of landscape mode + * @function TabletProxy#setLandscape + * @param landscape {bool} true for landscape, false for portrait + */ + Q_INVOKABLE void setLandscape(bool landscape) { _landscape = landscape; } + Q_INVOKABLE bool getLandscape() { return _landscape; } + QQuickItem* getTabletRoot() const { return _qmlTabletRoot; } QObject* getTabletSurface(); @@ -216,7 +225,7 @@ protected: void removeButtonsFromToolbar(); bool _initialScreen { false }; - QVariant _initialPath { "" }; + QVariant _initialPath { "" }; QString _name; std::mutex _mutex; std::vector> _tabletButtonProxies; @@ -227,6 +236,7 @@ protected: enum class State { Uninitialized, Home, Web, Menu, QML }; State _state { State::Uninitialized }; + bool _landscape { false }; }; /**jsdoc diff --git a/scripts/system/libraries/WebTablet.js b/scripts/system/libraries/WebTablet.js index 7fa1d5b437..4b51bc984c 100644 --- a/scripts/system/libraries/WebTablet.js +++ b/scripts/system/libraries/WebTablet.js @@ -113,6 +113,14 @@ WebTablet = function (url, width, dpi, hand, clientOnly, location) { this.dpi = DEFAULT_DPI * (DEFAULT_WIDTH / this.width); } + this.getDimensions = function() { + if (this.landscape) { + return { x: this.width * 2, y: this.height, z: this.depth }; + } else { + return { x: this.width, y: this.height, z: this.depth }; + } + }; + var modelURL = LOCAL_TABLET_MODEL_PATH; var tabletProperties = { name: "WebTablet Tablet", @@ -123,18 +131,10 @@ WebTablet = function (url, width, dpi, hand, clientOnly, location) { userData: JSON.stringify({ "grabbableKey": {"grabbable": true} }), - dimensions: {x: this.width, y: this.height, z: this.depth}, + dimensions: this.getDimensions(), parentID: AVATAR_SELF_ID }; - this.getDimensions = function() { - if (this.landscape) { - return { x: this.width * 2, y: this.height, z: this.depth }; - } else { - return { x: this.width, y: this.height, z: this.depth }; - } - }; - this.getTabletTextureResolution = function() { if (this.landscape) { return { x: TABLET_TEXTURE_RESOLUTION.x * 2, y: TABLET_TEXTURE_RESOLUTION.y }; @@ -215,7 +215,9 @@ WebTablet = function (url, width, dpi, hand, clientOnly, location) { } this.landscape = newLandscapeValue; Overlays.editOverlay(this.tabletEntityID, { dimensions: this.getDimensions() }); - Overlays.editOverlay(this.webOverlayID, { resolution: this.getTabletTextureResolution() }); + Overlays.editOverlay(this.webOverlayID, { + resolution: this.getTabletTextureResolution() + }); }; this.state = "idle"; @@ -508,6 +510,7 @@ WebTablet.prototype.mousePressEvent = function (event) { tablet.gotoHomeScreen(); this.setHomeButtonTexture(); } + Messages.sendLocalMessage("home", this.homeButtonID); } } else if (!HMD.active && (!overlayPickResults.intersects || overlayPickResults.overlayID !== this.webOverlayID)) { this.dragging = true; diff --git a/scripts/system/tablet-ui/tabletUI.js b/scripts/system/tablet-ui/tabletUI.js index 0291f4333a..c9ea1170bc 100644 --- a/scripts/system/tablet-ui/tabletUI.js +++ b/scripts/system/tablet-ui/tabletUI.js @@ -16,6 +16,7 @@ MyAvatar, Menu */ (function() { // BEGIN LOCAL_SCOPE + var _this = this; var tabletShown = false; var tabletRezzed = false; var activeHand = null; @@ -159,6 +160,7 @@ // close the WebTablet if it we go into toolbar mode. var toolbarMode = Tablet.getTablet("com.highfidelity.interface.tablet.system").toolbarMode; + var landscape = Tablet.getTablet("com.highfidelity.interface.tablet.system").landscape; if (tabletShown && toolbarMode) { closeTabletUI(); @@ -176,6 +178,9 @@ } updateTabletWidthFromSettings(); + if (UIWebTablet) { + UIWebTablet.setLandscape(landscape); + } if (validCheckTime - now > MSECS_PER_SEC) { validCheckTime = now; @@ -218,14 +223,20 @@ } - function toggleHand(channel, hand, senderUUID, localOnly) { + function handleMessage(channel, hand, senderUUID, localOnly) { if (channel === "toggleHand") { activeHand = JSON.parse(hand); } + if (channel === "home") { + if (UIWebTablet) { + Tablet.getTablet("com.highfidelity.interface.tablet.system").landscape = false; + } + } } Messages.subscribe("toggleHand"); - Messages.messageReceived.connect(toggleHand); + Messages.subscribe("home"); + Messages.messageReceived.connect(handleMessage); Script.setInterval(updateShowTablet, 100);