diff --git a/examples/libraries/toolBars.js b/examples/libraries/toolBars.js index 3b712e2ea0..b705f22f6f 100644 --- a/examples/libraries/toolBars.js +++ b/examples/libraries/toolBars.js @@ -355,20 +355,52 @@ ToolBar = function(x, y, direction, optionalPersistenceKey, optionalInitialPosit }); } }; - that.windowDimensions = Controller.getViewportDimensions(); + + var recommendedRect = Controller.getRecommendedOverlayRect(); + var recommendedDimmensions = { x: recommendedRect.z - recommendedRect.x, y: recommendedRect.w - recommendedRect.y }; + print("recommendedDimmensions:"+JSON.stringify(recommendedDimmensions)); + that.windowDimensions = recommendedDimmensions; // Controller.getViewportDimensions(); + that.origin = { x: recommendedRect.x, y: recommendedRect.y }; // Maybe fixme: Keeping the same percent of the window size isn't always the right thing. // For example, maybe we want "keep the same percentage to whatever two edges are closest to the edge of screen". // If we change that, the places to do so are onResizeViewport, save (maybe), and the initial move based on Settings, below. that.onResizeViewport = function (newSize) { // Can be overridden or extended by clients. - var fractionX = that.x / that.windowDimensions.x; - var fractionY = that.y / that.windowDimensions.y; - that.windowDimensions = newSize || Controller.getViewportDimensions(); - that.move(fractionX * that.windowDimensions.x, fractionY * that.windowDimensions.y); + print("that.onResizeViewport().... newSize:"+JSON.stringify(newSize)); + + var recommendedRect = Controller.getRecommendedOverlayRect(); + print("that.onResizeViewport().... recommendedRect:"+JSON.stringify(recommendedRect)); + var recommendedDimmensions = { x: recommendedRect.z - recommendedRect.x, y: recommendedRect.w - recommendedRect.y }; + print("that.onResizeViewport().... recommendedDimmensions:"+JSON.stringify(recommendedDimmensions)); + + print("that.onResizeViewport().... that.x/that.y:"+that.x+","+that.y); + var originRelativeX = (that.x - that.origin.x); + var originRelativeY = (that.y - that.origin.y); + print("that.onResizeViewport().... originRelativeX/originRelativeY:"+originRelativeX+","+originRelativeY); + + var fractionX = originRelativeX / that.windowDimensions.x; + var fractionY = originRelativeY / that.windowDimensions.y; + print("that.onResizeViewport().... fractionX/fractionY:"+fractionX+","+fractionY); + + that.windowDimensions = newSize || recommendedDimmensions; + print("that.onResizeViewport().... that.windowDimensions:"+JSON.stringify(that.windowDimensions)); + + that.origin = { x: recommendedRect.x, y: recommendedRect.y }; + print("that.onResizeViewport().... that.origin:"+JSON.stringify(that.origin)); + + var newX = (fractionX * that.windowDimensions.x) + recommendedRect.x; + var newY = (fractionY * that.windowDimensions.y) + recommendedRect.y; + print("that.onResizeViewport().... newX/newY:"+newX+","+newY); + + that.move(newX, newY); }; if (optionalPersistenceKey) { this.fractionKey = optionalPersistenceKey + '.fraction'; this.save = function () { - var screenSize = Controller.getViewportDimensions(); + //var screenSize = Controller.getViewportDimensions(); + var recommendedRect = Controller.getRecommendedOverlayRect(); + var screenSize = { x: recommendedRect.z - recommendedRect.x, y: recommendedRect.w - recommendedRect.y }; + print("screenSize:"+JSON.stringify(screenSize)); + if (screenSize.x > 0 && screenSize.y > 0) { // Guard against invalid screen size that can occur at shut-down. var fraction = {x: that.x / screenSize.x, y: that.y / screenSize.y}; @@ -411,7 +443,9 @@ ToolBar = function(x, y, direction, optionalPersistenceKey, optionalInitialPosit that.move(that.dragOffsetX + event.x, that.dragOffsetY + event.y); }; that.checkResize = function () { // Can be overriden or extended, but usually not. See onResizeViewport. - var currentWindowSize = Controller.getViewportDimensions(); + var recommendedRect = Controller.getRecommendedOverlayRect(); + var currentWindowSize = { x: recommendedRect.z - recommendedRect.x, y: recommendedRect.w - recommendedRect.y }; + if ((currentWindowSize.x !== that.windowDimensions.x) || (currentWindowSize.y !== that.windowDimensions.y)) { that.onResizeViewport(currentWindowSize); } @@ -434,7 +468,10 @@ ToolBar = function(x, y, direction, optionalPersistenceKey, optionalInitialPosit } if (this.fractionKey || optionalInitialPositionFunction) { var savedFraction = JSON.parse(Settings.getValue(this.fractionKey) || '0'); // getValue can answer empty string - var screenSize = Controller.getViewportDimensions(); + //var screenSize = Controller.getViewportDimensions(); + var recommendedRect = Controller.getRecommendedOverlayRect(); + var screenSize = { x: recommendedRect.z - recommendedRect.x, y: recommendedRect.w - recommendedRect.y }; + print("screenSize:"+JSON.stringify(screenSize)); if (savedFraction) { // If we have saved data, keep the toolbar at the same proportion of the screen width/height. that.move(savedFraction.x * screenSize.x, savedFraction.y * screenSize.y); diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 3a0b0998c5..573fcabfa8 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -4885,6 +4885,10 @@ glm::uvec2 Application::getUiSize() const { return getActiveDisplayPlugin()->getRecommendedUiSize(); } +glm::uvec4 Application::getRecommendedOverlayRect() const { + return getActiveDisplayPlugin()->getRecommendedOverlayRect(); +} + QSize Application::getDeviceSize() const { return fromGlm(getActiveDisplayPlugin()->getRecommendedRenderSize()); } diff --git a/interface/src/Application.h b/interface/src/Application.h index 6bfad21525..3771d6e2d1 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -117,6 +117,7 @@ public: QRect getRenderingGeometry() const; glm::uvec2 getUiSize() const; + glm::uvec4 getRecommendedOverlayRect() const; QSize getDeviceSize() const; bool hasFocus() const; diff --git a/interface/src/scripting/ControllerScriptingInterface.cpp b/interface/src/scripting/ControllerScriptingInterface.cpp index f6e5b6364f..e9349782b5 100644 --- a/interface/src/scripting/ControllerScriptingInterface.cpp +++ b/interface/src/scripting/ControllerScriptingInterface.cpp @@ -80,6 +80,11 @@ glm::vec2 ControllerScriptingInterface::getViewportDimensions() const { return qApp->getUiSize(); } +glm::vec4 ControllerScriptingInterface::getRecommendedOverlayRect() const { + auto rect = qApp->getRecommendedOverlayRect(); + return vec4(rect.x, rect.y, rect.z, rect.w); +} + controller::InputController* ControllerScriptingInterface::createInputController(const QString& deviceName, const QString& tracker) { // This is where we retrieve the Device Tracker category and then the sub tracker within it auto icIt = _inputControllers.find(0); diff --git a/interface/src/scripting/ControllerScriptingInterface.h b/interface/src/scripting/ControllerScriptingInterface.h index 43bb6987db..d99237b07d 100644 --- a/interface/src/scripting/ControllerScriptingInterface.h +++ b/interface/src/scripting/ControllerScriptingInterface.h @@ -96,6 +96,7 @@ public slots: virtual void releaseJoystick(int joystickIndex); virtual glm::vec2 getViewportDimensions() const; + virtual glm::vec4 getRecommendedOverlayRect() const; /// Factory to create an InputController virtual controller::InputController* createInputController(const QString& deviceName, const QString& tracker); diff --git a/libraries/display-plugins/src/display-plugins/CompositorHelper.cpp b/libraries/display-plugins/src/display-plugins/CompositorHelper.cpp index b39fd8861d..ea62e5df39 100644 --- a/libraries/display-plugins/src/display-plugins/CompositorHelper.cpp +++ b/libraries/display-plugins/src/display-plugins/CompositorHelper.cpp @@ -34,6 +34,7 @@ static const float reticleSize = TWO_PI / 100.0f; static QString _tooltipId; const uvec2 CompositorHelper::VIRTUAL_SCREEN_SIZE = uvec2(3960, 1188); // ~10% more pixel density than old version, 72dx240d FOV +const uvec4 CompositorHelper::VIRTUAL_SCREEN_RECOMMENDED_OVERLAY_RECT = uvec4(956, 0, 3004, 1188); // don't include entire width only center 2048 const float CompositorHelper::VIRTUAL_UI_ASPECT_RATIO = (float)VIRTUAL_SCREEN_SIZE.x / (float)VIRTUAL_SCREEN_SIZE.y; const vec2 CompositorHelper::VIRTUAL_UI_TARGET_FOV = vec2(PI * 3.0f / 2.0f, PI * 3.0f / 2.0f / VIRTUAL_UI_ASPECT_RATIO); const vec2 CompositorHelper::MOUSE_EXTENTS_ANGULAR_SIZE = vec2(PI * 2.0f, PI * 0.95f); // horizontal: full sphere, vertical: ~5deg from poles diff --git a/libraries/display-plugins/src/display-plugins/CompositorHelper.h b/libraries/display-plugins/src/display-plugins/CompositorHelper.h index 062e5c1319..40afcbbac4 100644 --- a/libraries/display-plugins/src/display-plugins/CompositorHelper.h +++ b/libraries/display-plugins/src/display-plugins/CompositorHelper.h @@ -42,6 +42,7 @@ class CompositorHelper : public QObject, public Dependency { Q_PROPERTY(bool reticleOverDesktop READ getReticleOverDesktop WRITE setReticleOverDesktop) public: static const uvec2 VIRTUAL_SCREEN_SIZE; + static const uvec4 VIRTUAL_SCREEN_RECOMMENDED_OVERLAY_RECT; static const float VIRTUAL_UI_ASPECT_RATIO; static const vec2 VIRTUAL_UI_TARGET_FOV; static const vec2 MOUSE_EXTENTS_ANGULAR_SIZE; diff --git a/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.cpp b/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.cpp index 34e484a988..6d4412d78b 100644 --- a/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.cpp +++ b/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.cpp @@ -34,6 +34,11 @@ glm::uvec2 HmdDisplayPlugin::getRecommendedUiSize() const { return CompositorHelper::VIRTUAL_SCREEN_SIZE; } +glm::uvec4 HmdDisplayPlugin::getRecommendedOverlayRect() const { + return CompositorHelper::VIRTUAL_SCREEN_RECOMMENDED_OVERLAY_RECT; +} + + bool HmdDisplayPlugin::internalActivate() { _monoPreview = _container->getBoolSetting("monoPreview", DEFAULT_MONO_VIEW); diff --git a/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.h b/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.h index d16f03112f..dab7fbd0cc 100644 --- a/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.h +++ b/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.h @@ -26,6 +26,8 @@ public: void setEyeRenderPose(uint32_t frameIndex, Eye eye, const glm::mat4& pose) override final; bool isDisplayVisible() const override { return isHmdMounted(); } + glm::uvec4 getRecommendedOverlayRect() const override final; + virtual glm::mat4 getHeadPose() const override; diff --git a/libraries/plugins/src/plugins/DisplayPlugin.h b/libraries/plugins/src/plugins/DisplayPlugin.h index de6fe0c839..d316635c43 100644 --- a/libraries/plugins/src/plugins/DisplayPlugin.h +++ b/libraries/plugins/src/plugins/DisplayPlugin.h @@ -105,6 +105,12 @@ public: return aspect(getRecommendedRenderSize()); } + // The recommended bounds for primary overlay placement + virtual glm::uvec4 getRecommendedOverlayRect() const { + auto recommendedSize = getRecommendedUiSize(); + return glm::uvec4(0, 0, recommendedSize.x, recommendedSize.y); + } + // Stereo specific methods virtual glm::mat4 getEyeProjection(Eye eye, const glm::mat4& baseProjection) const { return baseProjection;