Signed-off-by: falkTX <falktx@falktx.com>pull/281/head
| @@ -387,6 +387,13 @@ protected: | |||
| */ | |||
| virtual void onReshape(uint width, uint height); | |||
| /** | |||
| A function called when scale factor requested for this window changes. | |||
| The default implementation does nothing. | |||
| WARNING function needs a proper name | |||
| */ | |||
| virtual void onScaleFactorChanged(double scaleFactor); | |||
| #ifndef DGL_FILE_BROWSER_DISABLED | |||
| /** | |||
| A function called when a path is selected by the user, as triggered by openFileBrowser(). | |||
| @@ -136,10 +136,36 @@ void Window::setHeight(const uint height) | |||
| setSize(getWidth(), height); | |||
| } | |||
| void Window::setSize(const uint width, const uint height) | |||
| void Window::setSize(uint width, uint height) | |||
| { | |||
| DISTRHO_SAFE_ASSERT_UINT2_RETURN(width > 1 && height > 1, width, height,); | |||
| if (pData->isEmbed) | |||
| { | |||
| // handle geometry constraints here | |||
| if (width < pData->minWidth) | |||
| width = pData->minWidth; | |||
| if (height < pData->minHeight) | |||
| height = pData->minHeight; | |||
| if (pData->keepAspectRatio) | |||
| { | |||
| const double ratio = static_cast<double>(pData->minWidth) | |||
| / static_cast<double>(pData->minHeight); | |||
| const double reqRatio = static_cast<double>(width) | |||
| / static_cast<double>(height); | |||
| if (d_isNotEqual(ratio, reqRatio)) | |||
| { | |||
| // fix width | |||
| if (reqRatio > ratio) | |||
| width = height * ratio; | |||
| // fix height | |||
| else | |||
| height = width / ratio; | |||
| } | |||
| } | |||
| } | |||
| // FIXME add default and min props for this | |||
| if (pData->minWidth == 0 && pData->minHeight == 0) | |||
| puglSetDefaultSize(pData->view, static_cast<int>(width), static_cast<int>(height)); | |||
| @@ -250,8 +276,7 @@ void Window::setGeometryConstraints(const uint minimumWidth, | |||
| DISTRHO_SAFE_ASSERT_RETURN(minimumHeight > 0,); | |||
| if (pData->isEmbed) { | |||
| // Did you forget to set DISTRHO_UI_USER_RESIZABLE ? | |||
| DISTRHO_SAFE_ASSERT_RETURN(isResizable(),); | |||
| // nothing to do here | |||
| } else if (! isResizable()) { | |||
| setResizable(true); | |||
| } | |||
| @@ -259,6 +284,7 @@ void Window::setGeometryConstraints(const uint minimumWidth, | |||
| pData->minWidth = minimumWidth; | |||
| pData->minHeight = minimumHeight; | |||
| pData->autoScaling = automaticallyScale; | |||
| pData->keepAspectRatio = keepAspectRatio; | |||
| const double scaleFactor = pData->scaleFactor; | |||
| @@ -290,6 +316,10 @@ void Window::onReshape(uint, uint) | |||
| puglFallbackOnResize(pData->view); | |||
| } | |||
| void Window::onScaleFactorChanged(double) | |||
| { | |||
| } | |||
| #ifndef DGL_FILE_BROWSER_DISABLED | |||
| void Window::onFileSelected(const char*) | |||
| { | |||
| @@ -88,6 +88,7 @@ Window::PrivateData::PrivateData(Application& a, Window* const s) | |||
| autoScaleFactor(1.0), | |||
| minWidth(0), | |||
| minHeight(0), | |||
| keepAspectRatio(false), | |||
| #ifdef DISTRHO_OS_WINDOWS | |||
| win32SelectedFile(nullptr), | |||
| #endif | |||
| @@ -110,6 +111,7 @@ Window::PrivateData::PrivateData(Application& a, Window* const s, PrivateData* c | |||
| autoScaleFactor(1.0), | |||
| minWidth(0), | |||
| minHeight(0), | |||
| keepAspectRatio(false), | |||
| #ifdef DISTRHO_OS_WINDOWS | |||
| win32SelectedFile(nullptr), | |||
| #endif | |||
| @@ -136,6 +138,7 @@ Window::PrivateData::PrivateData(Application& a, Window* const s, | |||
| autoScaleFactor(1.0), | |||
| minWidth(0), | |||
| minHeight(0), | |||
| keepAspectRatio(false), | |||
| #ifdef DISTRHO_OS_WINDOWS | |||
| win32SelectedFile(nullptr), | |||
| #endif | |||
| @@ -167,6 +170,7 @@ Window::PrivateData::PrivateData(Application& a, Window* const s, | |||
| autoScaleFactor(1.0), | |||
| minWidth(0), | |||
| minHeight(0), | |||
| keepAspectRatio(false), | |||
| #ifdef DISTRHO_OS_WINDOWS | |||
| win32SelectedFile(nullptr), | |||
| #endif | |||
| @@ -67,8 +67,9 @@ struct Window::PrivateData : IdleCallback { | |||
| bool autoScaling; | |||
| double autoScaleFactor; | |||
| /** Pugl minWidth, minHeight access. */ | |||
| /** Pugl geometry constraints access. */ | |||
| uint minWidth, minHeight; | |||
| bool keepAspectRatio; | |||
| #ifdef DISTRHO_OS_WINDOWS | |||
| /** Selected file for openFileBrowser on windows, stored for fake async operation. */ | |||
| @@ -264,6 +264,15 @@ protected: | |||
| */ | |||
| virtual void uiReshape(uint width, uint height); | |||
| /** | |||
| Window scale factor function, called when the scale factor changes. | |||
| This function is for plugin UIs to be able to override Window::onScaleFactorChanged(double). | |||
| The default implementation does nothing. | |||
| WARNING function needs a proper name | |||
| */ | |||
| virtual void uiScaleFactorChanged(double scaleFactor); | |||
| # ifndef DGL_FILE_BROWSER_DISABLED | |||
| /** | |||
| Window file selected function, called when a path is selected by the user, as triggered by openFileBrowser(). | |||
| @@ -285,7 +294,7 @@ protected: | |||
| This is overriden here so the host knows when the UI is resized by you. | |||
| @see Widget::onResize(const ResizeEvent&) | |||
| */ | |||
| // void onResize(const ResizeEvent& ev) override; | |||
| void onResize(const ResizeEvent& ev) override; | |||
| #endif | |||
| // ------------------------------------------------------------------------------------------------------- | |||
| @@ -116,7 +116,7 @@ public: | |||
| setParameterValueCallback, | |||
| setStateCallback, | |||
| sendNoteCallback, | |||
| setSizeCallback, | |||
| nullptr, // window size | |||
| nullptr, // file request | |||
| nullptr, // bundle | |||
| fPlugin.getInstancePointer(), | |||
| @@ -495,11 +495,6 @@ protected: | |||
| fPlugin.setParameterValue(index, value); | |||
| } | |||
| void setSize(const uint width, const uint height) | |||
| { | |||
| fUI.setWindowSize(width, height); | |||
| } | |||
| # if DISTRHO_PLUGIN_WANT_MIDI_INPUT | |||
| void sendNote(const uint8_t channel, const uint8_t note, const uint8_t velocity) | |||
| { | |||
| @@ -681,11 +676,6 @@ private: | |||
| thisPtr->setParameterValue(index, value); | |||
| } | |||
| static void setSizeCallback(void* ptr, uint width, uint height) | |||
| { | |||
| thisPtr->setSize(width, height); | |||
| } | |||
| # if DISTRHO_PLUGIN_WANT_MIDI_INPUT | |||
| static void sendNoteCallback(void* ptr, uint8_t channel, uint8_t note, uint8_t velocity) | |||
| { | |||
| @@ -23,8 +23,6 @@ | |||
| #endif | |||
| #if DISTRHO_PLUGIN_HAS_UI | |||
| # undef DISTRHO_UI_USER_RESIZABLE | |||
| # define DISTRHO_UI_USER_RESIZABLE 0 | |||
| # include "DistrhoUIInternal.hpp" | |||
| # include "../extra/RingBuffer.hpp" | |||
| #endif | |||
| @@ -386,7 +384,7 @@ protected: | |||
| void setSize(const uint width, const uint height) | |||
| { | |||
| fUI.setWindowSize(width, height); | |||
| // fUI.setWindowSize(width, height); | |||
| hostCallback(audioMasterSizeWindow, width, height); | |||
| } | |||
| @@ -156,6 +156,10 @@ void UI::uiReshape(uint, uint) | |||
| pData->fallbackOnResize(); | |||
| } | |||
| void UI::uiScaleFactorChanged(double) | |||
| { | |||
| } | |||
| # ifndef DGL_FILE_BROWSER_DISABLED | |||
| void UI::uiFileBrowserSelected(const char*) | |||
| { | |||
| @@ -165,21 +169,14 @@ void UI::uiFileBrowserSelected(const char*) | |||
| /* ------------------------------------------------------------------------------------------------------------ | |||
| * UI Resize Handling, internal */ | |||
| // void UI::onResize(const ResizeEvent& ev) | |||
| // { | |||
| // if (uiData->resizeInProgress) | |||
| // return; | |||
| // | |||
| // UIWidget::onResize(ev); | |||
| // | |||
| // const uint width = ev.size.getWidth(); | |||
| // const uint height = ev.size.getHeight(); | |||
| // | |||
| // /* | |||
| // pData->window.setSize(width, height); | |||
| // */ | |||
| // uiData->setSizeCallback(width, height); | |||
| // } | |||
| void UI::onResize(const ResizeEvent& ev) | |||
| { | |||
| UIWidget::onResize(ev); | |||
| const uint width = ev.size.getWidth(); | |||
| const uint height = ev.size.getHeight(); | |||
| uiData->setSizeCallback(width, height); | |||
| } | |||
| #endif // !DISTRHO_PLUGIN_HAS_EXTERNAL_UI | |||
| // ----------------------------------------------------------------------------------------------------------- | |||
| @@ -98,7 +98,7 @@ class UIDssi : public IdleCallback | |||
| public: | |||
| UIDssi(const OscData& oscData, const char* const uiTitle, const double sampleRate) | |||
| : fUI(this, 0, sampleRate, nullptr, | |||
| setParameterCallback, setStateCallback, sendNoteCallback, setSizeCallback, nullptr), | |||
| setParameterCallback, setStateCallback, sendNoteCallback, nullptr, nullptr), | |||
| fHostClosed(false), | |||
| fOscData(oscData) | |||
| { | |||
| @@ -208,11 +208,6 @@ protected: | |||
| } | |||
| #endif | |||
| void setSize(const uint width, const uint height) | |||
| { | |||
| fUI.setWindowSize(width, height); | |||
| } | |||
| private: | |||
| UIExporter fUI; | |||
| bool fHostClosed; | |||
| @@ -241,11 +236,6 @@ private: | |||
| } | |||
| #endif | |||
| static void setSizeCallback(void* ptr, uint width, uint height) | |||
| { | |||
| uiPtr->setSize(width, height); | |||
| } | |||
| #undef uiPtr | |||
| }; | |||
| @@ -208,7 +208,7 @@ public: | |||
| int lv2ui_resize(uint width, uint height) | |||
| { | |||
| // FIXME | |||
| // this comes from the host | |||
| // fUI.setWindowSize(width, height, true); | |||
| return 0; | |||
| } | |||
| @@ -334,7 +334,7 @@ protected: | |||
| void setSize(const uint width, const uint height) | |||
| { | |||
| fUI.setWindowSize(width, height); | |||
| // fUI.setWindowSize(width, height); | |||
| if (fUiResize != nullptr && ! fWinIdWasNull) | |||
| fUiResize->ui_resize(fUiResize->handle, width, height); | |||
| @@ -30,6 +30,11 @@ | |||
| # define DISTRHO_UI_IS_STANDALONE 0 | |||
| #endif | |||
| #if defined(DISTRHO_PLUGIN_TARGET_VST) | |||
| # undef DISTRHO_UI_USER_RESIZABLE | |||
| # define DISTRHO_UI_USER_RESIZABLE 0 | |||
| #endif | |||
| START_NAMESPACE_DISTRHO | |||
| using DGL_NAMESPACE::Application; | |||
| @@ -244,6 +249,13 @@ protected: | |||
| ui->uiReshape(width, height); | |||
| } | |||
| void onScaleFactorChanged(const double scaleFactor) override | |||
| { | |||
| DISTRHO_SAFE_ASSERT_RETURN(ui != nullptr,); | |||
| ui->uiScaleFactorChanged(scaleFactor); | |||
| } | |||
| # ifndef DGL_FILE_BROWSER_DISABLED | |||
| void onFileSelected(const char* const filename) override | |||
| { | |||