From 371df35013ba72628dc0335cc4b08d6d47bf2bf3 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Wed, 29 Mar 2017 14:16:14 -0700 Subject: [PATCH 1/5] remove code related to tablet being a model rather than an overlay. start on landscape mode --- interface/src/Application.cpp | 8 -- interface/src/Application.h | 3 - interface/src/ui/PreferencesDialog.cpp | 7 -- .../src/TabletScriptingInterface.cpp | 5 +- scripts/system/libraries/WebTablet.js | 92 ++++++++----------- scripts/system/tablet-ui/tabletUI.js | 43 +++------ 6 files changed, 54 insertions(+), 104 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 25a585ea34..9601d7bd50 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -548,7 +548,6 @@ const float DEFAULT_HMD_TABLET_SCALE_PERCENT = 100.0f; const float DEFAULT_DESKTOP_TABLET_SCALE_PERCENT = 75.0f; const bool DEFAULT_DESKTOP_TABLET_BECOMES_TOOLBAR = true; const bool DEFAULT_HMD_TABLET_BECOMES_TOOLBAR = false; -const bool DEFAULT_TABLET_VISIBLE_TO_OTHERS = false; const bool DEFAULT_PREFER_AVATAR_FINGER_OVER_STYLUS = true; Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bool runServer, QString runServerPathOption) : @@ -571,7 +570,6 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo _desktopTabletScale("desktopTabletScale", DEFAULT_DESKTOP_TABLET_SCALE_PERCENT), _desktopTabletBecomesToolbarSetting("desktopTabletBecomesToolbar", DEFAULT_DESKTOP_TABLET_BECOMES_TOOLBAR), _hmdTabletBecomesToolbarSetting("hmdTabletBecomesToolbar", DEFAULT_HMD_TABLET_BECOMES_TOOLBAR), - _tabletVisibleToOthersSetting("tabletVisibleToOthers", DEFAULT_TABLET_VISIBLE_TO_OTHERS), _preferAvatarFingerOverStylusSetting("preferAvatarFingerOverStylus", DEFAULT_PREFER_AVATAR_FINGER_OVER_STYLUS), _constrainToolbarPosition("toolbar/constrainToolbarToCenterX", true), _scaleMirror(1.0f), @@ -2359,11 +2357,6 @@ void Application::setHmdTabletBecomesToolbarSetting(bool value) { updateSystemTabletMode(); } -void Application::setTabletVisibleToOthersSetting(bool value) { - _tabletVisibleToOthersSetting.set(value); - updateSystemTabletMode(); -} - void Application::setPreferAvatarFingerOverStylus(bool value) { _preferAvatarFingerOverStylusSetting.set(value); } @@ -3788,7 +3781,6 @@ void Application::loadSettings() { } getMyAvatar()->loadData(); - setTabletVisibleToOthersSetting(false); _settingsLoaded = true; } diff --git a/interface/src/Application.h b/interface/src/Application.h index 0a5fcd78f1..44c0f127c2 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -220,8 +220,6 @@ public: void setDesktopTabletBecomesToolbarSetting(bool value); bool getHmdTabletBecomesToolbarSetting() { return _hmdTabletBecomesToolbarSetting.get(); } void setHmdTabletBecomesToolbarSetting(bool value); - bool getTabletVisibleToOthersSetting() { return _tabletVisibleToOthersSetting.get(); } - void setTabletVisibleToOthersSetting(bool value); bool getPreferAvatarFingerOverStylus() { return _preferAvatarFingerOverStylusSetting.get(); } void setPreferAvatarFingerOverStylus(bool value); @@ -569,7 +567,6 @@ private: Setting::Handle _desktopTabletScale; Setting::Handle _desktopTabletBecomesToolbarSetting; Setting::Handle _hmdTabletBecomesToolbarSetting; - Setting::Handle _tabletVisibleToOthersSetting; Setting::Handle _preferAvatarFingerOverStylusSetting; Setting::Handle _constrainToolbarPosition; diff --git a/interface/src/ui/PreferencesDialog.cpp b/interface/src/ui/PreferencesDialog.cpp index 5983d7cc25..a12d9020ae 100644 --- a/interface/src/ui/PreferencesDialog.cpp +++ b/interface/src/ui/PreferencesDialog.cpp @@ -102,13 +102,6 @@ void setupPreferences() { auto setter = [](bool value) { qApp->setHmdTabletBecomesToolbarSetting(value); }; preferences->addPreference(new CheckPreference(UI_CATEGORY, "HMD Tablet Becomes Toolbar", getter, setter)); } - // TODO - // Note: If this code is added back, you must remove the line "setTabletVisibleToOthersSetting(false)" from Application::loadSettings() - /*{ - auto getter = []()->bool { return qApp->getTabletVisibleToOthersSetting(); }; - auto setter = [](bool value) { qApp->setTabletVisibleToOthersSetting(value); }; - preferences->addPreference(new CheckPreference(UI_CATEGORY, "Tablet Is Visible To Others", getter, setter)); - }*/ { auto getter = []()->bool { return qApp->getPreferAvatarFingerOverStylus(); }; auto setter = [](bool value) { qApp->setPreferAvatarFingerOverStylus(value); }; diff --git a/libraries/script-engine/src/TabletScriptingInterface.cpp b/libraries/script-engine/src/TabletScriptingInterface.cpp index c287fbcfe7..636edb1182 100644 --- a/libraries/script-engine/src/TabletScriptingInterface.cpp +++ b/libraries/script-engine/src/TabletScriptingInterface.cpp @@ -662,7 +662,10 @@ const QString OBJECT_NAME_KEY = "objectName"; const QString STABLE_ORDER_KEY = "stableOrder"; static int s_stableOrder = 1; -TabletButtonProxy::TabletButtonProxy(const QVariantMap& properties) : _uuid(QUuid::createUuid()), _stableOrder(++s_stableOrder), _properties(properties) { +TabletButtonProxy::TabletButtonProxy(const QVariantMap& properties) : + _uuid(QUuid::createUuid()), + _stableOrder(++s_stableOrder), + _properties(properties) { // this is used to uniquely identify this button. _properties[UUID_KEY] = _uuid; _properties[OBJECT_NAME_KEY] = _uuid.toString(); diff --git a/scripts/system/libraries/WebTablet.js b/scripts/system/libraries/WebTablet.js index e2d2791536..198dabb11f 100644 --- a/scripts/system/libraries/WebTablet.js +++ b/scripts/system/libraries/WebTablet.js @@ -35,7 +35,7 @@ var TABLET_NATURAL_DIMENSIONS = {x: 33.797, y: 50.129, z: 2.269}; var HOME_BUTTON_TEXTURE = "http://hifi-content.s3.amazonaws.com/alan/dev/tablet-with-home-button.fbx/tablet-with-home-button.fbm/button-close.png"; // var HOME_BUTTON_TEXTURE = Script.resourcesPath() + "meshes/tablet-with-home-button.fbx/tablet-with-home-button.fbm/button-close.png"; -var TABLET_MODEL_PATH = "http://hifi-content.s3.amazonaws.com/alan/dev/tablet-with-home-button.fbx"; +// var TABLET_MODEL_PATH = "http://hifi-content.s3.amazonaws.com/alan/dev/tablet-with-home-button.fbx"; var LOCAL_TABLET_MODEL_PATH = Script.resourcesPath() + "meshes/tablet-with-home-button.fbx"; // returns object with two fields: @@ -105,6 +105,7 @@ WebTablet = function (url, width, dpi, hand, clientOnly, location) { var tabletScaleFactor = this.width / TABLET_NATURAL_DIMENSIONS.x; this.height = TABLET_NATURAL_DIMENSIONS.y * tabletScaleFactor; this.depth = TABLET_NATURAL_DIMENSIONS.z * tabletScaleFactor; + this.landscape = false; if (dpi) { this.dpi = dpi; @@ -112,13 +113,7 @@ WebTablet = function (url, width, dpi, hand, clientOnly, location) { this.dpi = DEFAULT_DPI * (DEFAULT_WIDTH / this.width); } - var modelURL; - if (Settings.getValue("tabletVisibleToOthers")) { - modelURL = TABLET_MODEL_PATH; - } else { - modelURL = LOCAL_TABLET_MODEL_PATH; - } - + var modelURL = LOCAL_TABLET_MODEL_PATH; var tabletProperties = { name: "WebTablet Tablet", type: "Model", @@ -132,6 +127,14 @@ WebTablet = function (url, width, dpi, hand, clientOnly, location) { 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 }; + } + }; + // compute position, rotation & parentJointIndex of the tablet this.calculateTabletAttachmentProperties(hand, true, tabletProperties); if (location) { @@ -141,13 +144,7 @@ WebTablet = function (url, width, dpi, hand, clientOnly, location) { this.cleanUpOldTablets(); - if (Settings.getValue("tabletVisibleToOthers")) { - this.tabletEntityID = Entities.addEntity(tabletProperties, clientOnly); - this.tabletIsOverlay = false; - } else { - this.tabletEntityID = Overlays.addOverlay("model", tabletProperties); - this.tabletIsOverlay = true; - } + this.tabletEntityID = Overlays.addOverlay("model", tabletProperties); if (this.webOverlayID) { Overlays.deleteOverlay(this.webOverlayID); @@ -188,13 +185,14 @@ WebTablet = function (url, width, dpi, hand, clientOnly, location) { if (_this.homeButtonID == senderID) { var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system"); var onHomeScreen = tablet.onHomeScreen(); + var isMessageOpen; if (onHomeScreen) { - var isMessageOpen = tablet.isMessageDialogOpen(); + isMessageOpen = tablet.isMessageDialogOpen(); if (isMessageOpen === false) { HMD.closeTablet(); } } else { - var isMessageOpen = tablet.isMessageDialogOpen(); + isMessageOpen = tablet.isMessageDialogOpen(); if (isMessageOpen === false) { tablet.gotoHomeScreen(); _this.setHomeButtonTexture(); @@ -203,6 +201,14 @@ WebTablet = function (url, width, dpi, hand, clientOnly, location) { } }; + this.setLandscape = function(newLandscapeValue) { + if (this.landscape == newLandscapeValue) { + return; + } + this.landscape = newLandscapeValue; + Overlays.editOverlay(this.tabletEntityID, this.getDimensions()); + }; + this.state = "idle"; this.getRoot = function() { @@ -210,16 +216,12 @@ WebTablet = function (url, width, dpi, hand, clientOnly, location) { }; this.getLocation = function() { - if (this.tabletIsOverlay) { - var location = Overlays.getProperty(this.tabletEntityID, "localPosition"); - var orientation = Overlays.getProperty(this.tabletEntityID, "localOrientation"); - return { - localPosition: location, - localRotation: orientation - }; - } else { - return Entities.getEntityProperties(_this.tabletEntityID, ["localPosition", "localRotation"]); - } + var location = Overlays.getProperty(this.tabletEntityID, "localPosition"); + var orientation = Overlays.getProperty(this.tabletEntityID, "localOrientation"); + return { + localPosition: location, + localRotation: orientation + }; }; this.clicked = false; @@ -285,11 +287,7 @@ WebTablet.prototype.setWidth = function (width) { this.dpi = DEFAULT_DPI * (DEFAULT_WIDTH / this.width); // update tablet model dimensions - if (this.tabletIsOverlay) { - Overlays.editOverlay(this.tabletEntityID, {dimensions: {x: this.width, y: this.height, z: this.depth}}); - } else { - Entities.editEntity(this.tabletEntityID, {dimensions: {x: this.width, y: this.height, z: this.depth}}); - } + Overlays.editOverlay(this.tabletEntityID, { dimensions: this.getDimensions() }); // update webOverlay var WEB_ENTITY_Z_OFFSET = (this.depth / 2); @@ -309,11 +307,7 @@ WebTablet.prototype.setWidth = function (width) { WebTablet.prototype.destroy = function () { Overlays.deleteOverlay(this.webOverlayID); - if (this.tabletIsOverlay) { - Overlays.deleteOverlay(this.tabletEntityID); - } else { - Entities.deleteEntity(this.tabletEntityID); - } + Overlays.deleteOverlay(this.tabletEntityID); Overlays.deleteOverlay(this.homeButtonID); HMD.displayModeChanged.disconnect(this.myOnHmdChanged); @@ -488,11 +482,7 @@ WebTablet.prototype.getPosition = function () { WebTablet.prototype.mousePressEvent = function (event) { var pickRay = Camera.computePickRay(event.x, event.y); var entityPickResults; - if (this.tabletIsOverlay) { - entityPickResults = Overlays.findRayIntersection(pickRay, true, [this.tabletEntityID]); - } else { - entityPickResults = Entities.findRayIntersection(pickRay, true, [this.tabletEntityID]); - } + entityPickResults = Overlays.findRayIntersection(pickRay, true, [this.tabletEntityID]); if (entityPickResults.intersects && (entityPickResults.entityID === this.tabletEntityID || entityPickResults.overlayID === this.tabletEntityID)) { var overlayPickResults = Overlays.findRayIntersection(pickRay, true, [this.webOverlayID, this.homeButtonID], []); @@ -514,11 +504,7 @@ WebTablet.prototype.mousePressEvent = function (event) { this.dragging = true; var invCameraXform = new Xform(Camera.orientation, Camera.position).inv(); this.initialLocalIntersectionPoint = invCameraXform.xformPoint(entityPickResults.intersection); - if (this.tabletIsOverlay) { - this.initialLocalPosition = Overlays.getProperty(this.tabletEntityID, "localPosition"); - } else { - this.initialLocalPosition = Entities.getEntityProperties(this.tabletEntityID, ["localPosition"]).localPosition; - } + this.initialLocalPosition = Overlays.getProperty(this.tabletEntityID, "localPosition"); } } }; @@ -564,15 +550,9 @@ WebTablet.prototype.mouseMoveEvent = function (event) { var localIntersectionPoint = Vec3.sum(localPickRay.origin, Vec3.multiply(localPickRay.direction, result.distance)); var localOffset = Vec3.subtract(localIntersectionPoint, this.initialLocalIntersectionPoint); var localPosition = Vec3.sum(this.initialLocalPosition, localOffset); - if (this.tabletIsOverlay) { - Overlays.editOverlay(this.tabletEntityID, { - localPosition: localPosition - }); - } else { - Entities.editEntity(this.tabletEntityID, { - localPosition: localPosition - }); - } + Overlays.editOverlay(this.tabletEntityID, { + localPosition: localPosition + }); } } }; diff --git a/scripts/system/tablet-ui/tabletUI.js b/scripts/system/tablet-ui/tabletUI.js index a010cb0a9c..0291f4333a 100644 --- a/scripts/system/tablet-ui/tabletUI.js +++ b/scripts/system/tablet-ui/tabletUI.js @@ -33,7 +33,7 @@ if (!UIWebTablet) { return false; } - if (UIWebTablet.tabletIsOverlay && Overlays.getProperty(HMD.tabletID, "type") != "model") { + if (Overlays.getProperty(HMD.tabletID, "type") != "model") { if (debugTablet) { print("TABLET is invalid due to frame: " + JSON.stringify(Overlays.getProperty(HMD.tabletID, "type"))); } @@ -96,7 +96,7 @@ tabletShown = true; if (!tabletRezzed || !tabletIsValid()) { - closeTabletUI() + closeTabletUI(); rezTablet(); } @@ -107,9 +107,7 @@ var tabletProperties = {}; UIWebTablet.calculateTabletAttachmentProperties(activeHand, true, tabletProperties); tabletProperties.visible = true; - if (UIWebTablet.tabletIsOverlay) { - Overlays.editOverlay(HMD.tabletID, tabletProperties); - } + Overlays.editOverlay(HMD.tabletID, tabletProperties); Overlays.editOverlay(HMD.homeButtonID, { visible: true }); Overlays.editOverlay(HMD.tabletScreenID, { visible: true }); Overlays.editOverlay(HMD.tabletScreenID, { maxFPS: 90 }); @@ -122,22 +120,14 @@ return; } - if (UIWebTablet.tabletIsOverlay) { - if (debugTablet) { - print("TABLET hide"); - } - if (Settings.getValue("tabletVisibleToOthers")) { - closeTabletUI(); - } else { - // Overlays.editOverlay(HMD.tabletID, { localPosition: { x: -1000, y: 0, z:0 } }); - Overlays.editOverlay(HMD.tabletID, { visible: false }); - Overlays.editOverlay(HMD.homeButtonID, { visible: false }); - Overlays.editOverlay(HMD.tabletScreenID, { visible: false }); - Overlays.editOverlay(HMD.tabletScreenID, { maxFPS: 1 }); - } - } else { - closeTabletUI(); + if (debugTablet) { + print("TABLET hide"); } + + Overlays.editOverlay(HMD.tabletID, { visible: false }); + Overlays.editOverlay(HMD.homeButtonID, { visible: false }); + Overlays.editOverlay(HMD.tabletScreenID, { visible: false }); + Overlays.editOverlay(HMD.tabletScreenID, { maxFPS: 1 }); } function closeTabletUI() { @@ -169,7 +159,6 @@ // close the WebTablet if it we go into toolbar mode. var toolbarMode = Tablet.getTablet("com.highfidelity.interface.tablet.system").toolbarMode; - var visibleToOthers = Settings.getValue("tabletVisibleToOthers"); if (tabletShown && toolbarMode) { closeTabletUI(); @@ -205,20 +194,16 @@ // check for change in tablet scale. if (HMD.showTablet && !tabletShown && !toolbarMode) { - UserActivityLogger.openedTablet(visibleToOthers); + UserActivityLogger.openedTablet(false); showTabletUI(); } else if (!HMD.showTablet && tabletShown) { UserActivityLogger.closedTablet(); - if (visibleToOthers) { - closeTabletUI(); - } else { - hideTabletUI(); - } + hideTabletUI(); } // if the tablet is an overlay, attempt to pre-create it and then hide it so that when it's // summoned, it will appear quickly. - if (!toolbarMode && !visibleToOthers) { + if (!toolbarMode) { if (now - preMakeTime > MSECS_PER_SEC) { preMakeTime = now; if (!tabletIsValid()) { @@ -273,7 +258,7 @@ Script.scriptEnding.connect(function () { var tabletID = HMD.tabletID; Entities.deleteEntity(tabletID); - Overlays.deleteOverlay(tabletID) + Overlays.deleteOverlay(tabletID); HMD.tabletID = null; HMD.homeButtonID = null; HMD.tabletScreenID = null; From ce9eb1a37770bac9b4c746ecae2e7dfff4a0a09b Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Wed, 29 Mar 2017 14:21:38 -0700 Subject: [PATCH 2/5] more tablet landscape changes --- scripts/system/libraries/WebTablet.js | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/scripts/system/libraries/WebTablet.js b/scripts/system/libraries/WebTablet.js index 198dabb11f..7fa1d5b437 100644 --- a/scripts/system/libraries/WebTablet.js +++ b/scripts/system/libraries/WebTablet.js @@ -135,6 +135,14 @@ WebTablet = function (url, width, dpi, hand, clientOnly, location) { } }; + this.getTabletTextureResolution = function() { + if (this.landscape) { + return { x: TABLET_TEXTURE_RESOLUTION.x * 2, y: TABLET_TEXTURE_RESOLUTION.y }; + } else { + return TABLET_TEXTURE_RESOLUTION; + } + }; + // compute position, rotation & parentJointIndex of the tablet this.calculateTabletAttachmentProperties(hand, true, tabletProperties); if (location) { @@ -158,7 +166,7 @@ WebTablet = function (url, width, dpi, hand, clientOnly, location) { url: url, localPosition: { x: 0, y: WEB_ENTITY_Y_OFFSET, z: -WEB_ENTITY_Z_OFFSET }, localRotation: Quat.angleAxis(180, Y_AXIS), - resolution: TABLET_TEXTURE_RESOLUTION, + resolution: this.getTabletTextureResolution(), dpi: this.dpi, color: { red: 255, green: 255, blue: 255 }, alpha: 1.0, @@ -206,7 +214,8 @@ WebTablet = function (url, width, dpi, hand, clientOnly, location) { return; } this.landscape = newLandscapeValue; - Overlays.editOverlay(this.tabletEntityID, this.getDimensions()); + Overlays.editOverlay(this.tabletEntityID, { dimensions: this.getDimensions() }); + Overlays.editOverlay(this.webOverlayID, { resolution: this.getTabletTextureResolution() }); }; this.state = "idle"; @@ -350,15 +359,15 @@ WebTablet.prototype.calculateWorldAttitudeRelativeToCamera = function (windowPos // clamp window pos so 2d tablet is not off-screen. var TABLET_TEXEL_PADDING = {x: 60, y: 90}; - var X_CLAMP = (DESKTOP_TABLET_SCALE / 100) * ((TABLET_TEXTURE_RESOLUTION.x / 2) + TABLET_TEXEL_PADDING.x); - var Y_CLAMP = (DESKTOP_TABLET_SCALE / 100) * ((TABLET_TEXTURE_RESOLUTION.y / 2) + TABLET_TEXEL_PADDING.y); + var X_CLAMP = (DESKTOP_TABLET_SCALE / 100) * ((this.getTabletTextureResolution().x / 2) + TABLET_TEXEL_PADDING.x); + var Y_CLAMP = (DESKTOP_TABLET_SCALE / 100) * ((this.getTabletTextureResolution().y / 2) + TABLET_TEXEL_PADDING.y); windowPos.x = clamp(windowPos.x, X_CLAMP, Window.innerWidth - X_CLAMP); windowPos.y = clamp(windowPos.y, Y_CLAMP, Window.innerHeight - Y_CLAMP); var fov = (Settings.getValue('fieldOfView') || DEFAULT_VERTICAL_FIELD_OF_VIEW) * (Math.PI / 180); var MAX_PADDING_FACTOR = 2.2; - var PADDING_FACTOR = Math.min(Window.innerHeight / TABLET_TEXTURE_RESOLUTION.y, MAX_PADDING_FACTOR); - var TABLET_HEIGHT = (TABLET_TEXTURE_RESOLUTION.y / this.dpi) * INCHES_TO_METERS; + var PADDING_FACTOR = Math.min(Window.innerHeight / this.getTabletTextureResolution().y, MAX_PADDING_FACTOR); + var TABLET_HEIGHT = (this.getTabletTextureResolution().y / this.dpi) * INCHES_TO_METERS; var WEB_ENTITY_Z_OFFSET = (this.depth / 2); // calcualte distance from camera From 36ad3af48ee7b576f28ea56065711ec8c803f33c Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Thu, 30 Mar 2017 11:35:24 -0700 Subject: [PATCH 3/5] attempt to avoid a hang on shutdown --- libraries/fbx/src/OBJReader.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/fbx/src/OBJReader.cpp b/libraries/fbx/src/OBJReader.cpp index c1bb72dff8..3b68af075e 100644 --- a/libraries/fbx/src/OBJReader.cpp +++ b/libraries/fbx/src/OBJReader.cpp @@ -294,7 +294,7 @@ QNetworkReply* OBJReader::request(QUrl& url, bool isTest) { QObject::connect(netReply, SIGNAL(finished()), &loop, SLOT(quit())); loop.exec(); // Nothing is going to happen on this whole run thread until we get this static const int WAIT_TIMEOUT_MS = 500; - while (qApp && !aboutToQuit && !netReply->isReadable()) { + while (!aboutToQuit && qApp && !netReply->isReadable()) { netReply->waitForReadyRead(WAIT_TIMEOUT_MS); // so we might as well block this thread waiting for the response, rather than } QObject::disconnect(connection); From c62b07d26f5bea4c246313f3ae4abfcef40e8382 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Thu, 30 Mar 2017 11:36:21 -0700 Subject: [PATCH 4/5] 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); From 715493922e2f9990d2e95ad996af8ff5f0b3e648 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Thu, 30 Mar 2017 17:33:01 -0700 Subject: [PATCH 5/5] code review --- scripts/system/libraries/WebTablet.js | 71 ++++++++++++++------------- 1 file changed, 36 insertions(+), 35 deletions(-) diff --git a/scripts/system/libraries/WebTablet.js b/scripts/system/libraries/WebTablet.js index 4b51bc984c..f9d37a0086 100644 --- a/scripts/system/libraries/WebTablet.js +++ b/scripts/system/libraries/WebTablet.js @@ -113,14 +113,6 @@ 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", @@ -135,14 +127,6 @@ WebTablet = function (url, width, dpi, hand, clientOnly, location) { parentID: AVATAR_SELF_ID }; - this.getTabletTextureResolution = function() { - if (this.landscape) { - return { x: TABLET_TEXTURE_RESOLUTION.x * 2, y: TABLET_TEXTURE_RESOLUTION.y }; - } else { - return TABLET_TEXTURE_RESOLUTION; - } - }; - // compute position, rotation & parentJointIndex of the tablet this.calculateTabletAttachmentProperties(hand, true, tabletProperties); if (location) { @@ -209,31 +193,12 @@ WebTablet = function (url, width, dpi, hand, clientOnly, location) { } }; - this.setLandscape = function(newLandscapeValue) { - if (this.landscape == newLandscapeValue) { - return; - } - this.landscape = newLandscapeValue; - Overlays.editOverlay(this.tabletEntityID, { dimensions: this.getDimensions() }); - Overlays.editOverlay(this.webOverlayID, { - resolution: this.getTabletTextureResolution() - }); - }; - this.state = "idle"; this.getRoot = function() { return Entities.getWebViewRoot(_this.tabletEntityID); }; - this.getLocation = function() { - var location = Overlays.getProperty(this.tabletEntityID, "localPosition"); - var orientation = Overlays.getProperty(this.tabletEntityID, "localOrientation"); - return { - localPosition: location, - localRotation: orientation - }; - }; this.clicked = false; this.myOnHmdChanged = function () { @@ -272,6 +237,42 @@ WebTablet = function (url, width, dpi, hand, clientOnly, location) { Camera.modeUpdated.connect(this.myCameraModeChanged); }; +WebTablet.prototype.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 }; + } +}; + +WebTablet.prototype.getTabletTextureResolution = function() { + if (this.landscape) { + return { x: TABLET_TEXTURE_RESOLUTION.x * 2, y: TABLET_TEXTURE_RESOLUTION.y }; + } else { + return TABLET_TEXTURE_RESOLUTION; + } +}; + +WebTablet.prototype.setLandscape = function(newLandscapeValue) { + if (this.landscape == newLandscapeValue) { + return; + } + this.landscape = newLandscapeValue; + Overlays.editOverlay(this.tabletEntityID, { dimensions: this.getDimensions() }); + Overlays.editOverlay(this.webOverlayID, { + resolution: this.getTabletTextureResolution() + }); +}; + +WebTablet.prototype.getLocation = function() { + var location = Overlays.getProperty(this.tabletEntityID, "localPosition"); + var orientation = Overlays.getProperty(this.tabletEntityID, "localOrientation"); + return { + localPosition: location, + localRotation: orientation + }; +}; + WebTablet.prototype.setHomeButtonTexture = function() { Entities.editEntity(this.tabletEntityID, {textures: JSON.stringify({"tex.close": HOME_BUTTON_TEXTURE})}); };