Signed-off-by: falkTX <falktx@falktx.com>pull/338/head
| @@ -397,10 +397,10 @@ public: | |||
| void runAsModal(bool blockWait = false); | |||
| /** | |||
| Get the size constraint set for the Window. | |||
| Get the geometry constraints set for the Window. | |||
| @see setGeometryConstraints | |||
| */ | |||
| Size<uint> getMinimumSizeConstraint(bool& keepAspectRatio); | |||
| Size<uint> getGeometryConstraints(bool& keepAspectRatio); | |||
| /** | |||
| Set geometry constraints for the Window when resized by the user, and optionally scale contents automatically. | |||
| @@ -346,7 +346,7 @@ void Window::runAsModal(bool blockWait) | |||
| pData->runAsModal(blockWait); | |||
| } | |||
| Size<uint> Window::getMinimumSizeConstraint(bool& keepAspectRatio) | |||
| Size<uint> Window::getGeometryConstraints(bool& keepAspectRatio) | |||
| { | |||
| keepAspectRatio = pData->keepAspectRatio; | |||
| return Size<uint>(pData->minWidth, pData->minHeight); | |||
| @@ -295,7 +295,8 @@ public: | |||
| */ | |||
| void setSize(uint width, uint height) | |||
| { | |||
| DISTRHO_SAFE_ASSERT_UINT2_RETURN(width > 1 && height > 1, width, height,); | |||
| DISTRHO_SAFE_ASSERT_UINT_RETURN(width > 1, width,); | |||
| DISTRHO_SAFE_ASSERT_UINT_RETURN(height > 1, height,); | |||
| if (pData.width == width && pData.height == height) | |||
| return; | |||
| @@ -314,10 +315,24 @@ public: | |||
| { | |||
| if (pData.title == title) | |||
| return; | |||
| pData.title = title; | |||
| titleChanged(title); | |||
| } | |||
| /** | |||
| Set geometry constraints for the Window when resized by the user. | |||
| */ | |||
| void setGeometryConstraints(uint minimumWidth, uint minimumHeight, bool keepAspectRatio = false) | |||
| { | |||
| DISTRHO_SAFE_ASSERT_UINT_RETURN(minimumWidth > 0, minimumWidth,); | |||
| DISTRHO_SAFE_ASSERT_UINT_RETURN(minimumHeight > 0, minimumHeight,); | |||
| pData.minWidth = minimumWidth; | |||
| pData.minHeight = minimumHeight; | |||
| pData.keepAspectRatio = keepAspectRatio; | |||
| } | |||
| /* -------------------------------------------------------------------------------------------------------- | |||
| * TopLevelWidget-like calls - actions called by the host */ | |||
| @@ -339,6 +354,7 @@ public: | |||
| { | |||
| if (pData.visible == visible) | |||
| return; | |||
| pData.visible = visible; | |||
| visibilityChanged(visible); | |||
| } | |||
| @@ -351,6 +367,7 @@ public: | |||
| { | |||
| if (pData.transientWinId == winId) | |||
| return; | |||
| pData.transientWinId = winId; | |||
| transientParentWindowChanged(winId); | |||
| } | |||
| @@ -388,39 +405,35 @@ protected: | |||
| A callback for when the window size changes. | |||
| @note WIP this might need to get fed back into the host somehow. | |||
| */ | |||
| virtual void sizeChanged(uint width, uint height) | |||
| virtual void sizeChanged(uint /* width */, uint /* height */) | |||
| { | |||
| // unused, meant for custom implementations | |||
| return; (void)width; (void)height; | |||
| } | |||
| /** | |||
| A callback for when the window title changes. | |||
| @note WIP this might need to get fed back into the host somehow. | |||
| */ | |||
| virtual void titleChanged(const char* title) | |||
| virtual void titleChanged(const char* /* title */) | |||
| { | |||
| // unused, meant for custom implementations | |||
| return; (void)title; | |||
| } | |||
| /** | |||
| A callback for when the window visibility changes. | |||
| @note WIP this might need to get fed back into the host somehow. | |||
| */ | |||
| virtual void visibilityChanged(bool visible) | |||
| virtual void visibilityChanged(bool /* visible */) | |||
| { | |||
| // unused, meant for custom implementations | |||
| return; (void)visible; | |||
| } | |||
| /** | |||
| A callback for when the transient parent window changes. | |||
| */ | |||
| virtual void transientParentWindowChanged(uintptr_t winId) | |||
| virtual void transientParentWindowChanged(uintptr_t /* winId */) | |||
| { | |||
| // unused, meant for custom implementations | |||
| return; (void)winId; | |||
| } | |||
| private: | |||
| @@ -533,6 +546,9 @@ private: | |||
| uint height; | |||
| double scaleFactor; | |||
| String title; | |||
| uint minWidth; | |||
| uint minHeight; | |||
| bool keepAspectRatio; | |||
| bool isQuitting; | |||
| bool isStandalone; | |||
| bool visible; | |||
| @@ -544,6 +560,9 @@ private: | |||
| height(1), | |||
| scaleFactor(1.0), | |||
| title(), | |||
| minWidth(0), | |||
| minHeight(0), | |||
| keepAspectRatio(false), | |||
| isQuitting(false), | |||
| isStandalone(false), | |||
| visible(false) {} | |||
| @@ -132,9 +132,16 @@ public: | |||
| return uiData->window->getScaleFactor(); | |||
| } | |||
| Size<uint> getMinimumSizeConstraint(bool& keepAspectRatio) | |||
| bool getGeometryConstraints(uint& minimumWidth, uint& minimumHeight, bool& keepAspectRatio) const noexcept | |||
| { | |||
| return uiData->window->getMinimumSizeConstraint(keepAspectRatio); | |||
| #if DISTRHO_PLUGIN_HAS_EXTERNAL_UI | |||
| uiData->window->getGeometryConstraints(minimumWidth, minimumHeight, keepAspectRatio); | |||
| #else | |||
| const Size<uint> size(uiData->window->getGeometryConstraints(keepAspectRatio)); | |||
| minimumWidth = size.getWidth(); | |||
| minimumHeight = size.getHeight(); | |||
| #endif | |||
| return true; | |||
| } | |||
| bool isResizable() const noexcept | |||
| @@ -272,8 +279,10 @@ public: | |||
| void setWindowSizeForVST3(const uint width, const uint height) | |||
| { | |||
| ui->setSize(width, height); | |||
| #if !DISTRHO_PLUGIN_HAS_EXTERNAL_UI | |||
| uiData->window->setSize(width, height); | |||
| // uiData->app.idle(); | |||
| #endif | |||
| } | |||
| void setWindowTitle(const char* const uiTitle) | |||
| @@ -152,6 +152,12 @@ public: | |||
| void setTitle(const char* const title) { ui->setTitle(title); } | |||
| void setVisible(const bool visible) { ui->setVisible(visible); } | |||
| uintptr_t getNativeWindowHandle() const noexcept { return ui->getNativeWindowHandle(); } | |||
| void getGeometryConstraints(uint& minimumWidth, uint& minimumHeight, bool& keepAspectRatio) const noexcept | |||
| { | |||
| minimumWidth = ui->pData.minWidth; | |||
| minimumHeight = ui->pData.minHeight; | |||
| keepAspectRatio = ui->pData.keepAspectRatio; | |||
| } | |||
| DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(PluginWindow) | |||
| }; | |||
| @@ -75,10 +75,11 @@ struct ScopedUTF16String { | |||
| // -------------------------------------------------------------------------------------------------------------------- | |||
| static bool checkSizeConstraint(const Size<uint>& size, const bool keepAspectRatio, v3_view_rect* const rect) | |||
| static bool checkSizeConstraint(const uint minimumWidth, const uint minimumHeight, const bool keepAspectRatio, | |||
| v3_view_rect* const rect) | |||
| { | |||
| const int32_t minWidth = static_cast<int32_t>(size.getWidth()); | |||
| const int32_t minHeight = static_cast<int32_t>(size.getHeight()); | |||
| const int32_t minWidth = static_cast<int32_t>(minimumWidth); | |||
| const int32_t minHeight = static_cast<int32_t>(minimumHeight); | |||
| bool changed = false; | |||
| if (keepAspectRatio) | |||
| @@ -92,10 +93,10 @@ static bool checkSizeConstraint(const Size<uint>& size, const bool keepAspectRat | |||
| // fix width | |||
| if (reqRatio > ratio) | |||
| rect->right = static_cast<uint>(rect->bottom * ratio + 0.5); | |||
| rect->right = static_cast<int32_t>(rect->bottom * ratio + 0.5); | |||
| // fix height | |||
| else | |||
| rect->bottom = static_cast<uint>(static_cast<double>(rect->right) / ratio + 0.5); | |||
| rect->bottom = static_cast<int32_t>(static_cast<double>(rect->right) / ratio + 0.5); | |||
| } | |||
| } | |||
| @@ -255,9 +256,10 @@ public: | |||
| v3_result checkSizeConstraint(v3_view_rect* const rect) | |||
| { | |||
| uint minimumWidth, minimumHeight; | |||
| bool keepAspectRatio; | |||
| const Size<uint> size(fUI.getMinimumSizeConstraint(keepAspectRatio)); | |||
| return ::checkSizeConstraint(size, keepAspectRatio, rect) ? V3_FALSE : V3_TRUE; | |||
| fUI.getGeometryConstraints(minimumWidth, minimumHeight, keepAspectRatio); | |||
| return ::checkSizeConstraint(minimumWidth, minimumHeight, keepAspectRatio, rect) ? V3_FALSE : V3_TRUE; | |||
| } | |||
| // ---------------------------------------------------------------------------------------------------------------- | |||
| @@ -1261,9 +1263,10 @@ struct dpf_plugin_view : v3_plugin_view_cpp { | |||
| UIExporter tmpUI(nullptr, 0, view->sampleRate, | |||
| nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, | |||
| view->instancePointer, scaleFactor); | |||
| uint minimumWidth, minimumHeight; | |||
| bool keepAspectRatio; | |||
| const Size<uint> size(tmpUI.getMinimumSizeConstraint(keepAspectRatio)); | |||
| return ::checkSizeConstraint(size, keepAspectRatio, rect) ? V3_FALSE : V3_TRUE; | |||
| tmpUI.getGeometryConstraints(minimumWidth, minimumHeight, keepAspectRatio); | |||
| return ::checkSizeConstraint(minimumWidth, minimumHeight, keepAspectRatio, rect) ? V3_FALSE : V3_TRUE; | |||
| } | |||
| }; | |||