| @@ -98,6 +98,8 @@ public: | |||
| bool isResizable() const noexcept; | |||
| void setResizable(bool yesNo); | |||
| void setGeometryConstraints(uint width, uint height, bool aspect); | |||
| uint getWidth() const noexcept; | |||
| uint getHeight() const noexcept; | |||
| Size<uint> getSize() const noexcept; | |||
| @@ -549,6 +549,15 @@ struct Window::PrivateData { | |||
| // ------------------------------------------------------------------- | |||
| void setGeometryConstraints(uint width, uint height, bool aspect) | |||
| { | |||
| DISTRHO_SAFE_ASSERT_RETURN(fResizable,); | |||
| puglUpdateGeometryConstraints(fView, width, height, aspect); | |||
| } | |||
| // ------------------------------------------------------------------- | |||
| void setSize(uint width, uint height, const bool forced = false) | |||
| { | |||
| if (width <= 1 || height <= 1) | |||
| @@ -1236,6 +1245,11 @@ void Window::setResizable(bool yesNo) | |||
| pData->setResizable(yesNo); | |||
| } | |||
| void Window::setGeometryConstraints(uint width, uint height, bool aspect) | |||
| { | |||
| pData->setGeometryConstraints(width, height, aspect); | |||
| } | |||
| uint Window::getWidth() const noexcept | |||
| { | |||
| return pData->fWidth; | |||
| @@ -54,13 +54,20 @@ public: | |||
| UI class constructor. | |||
| The UI should be initialized to a default state that matches the plugin side. | |||
| */ | |||
| UI(uint width = 0, uint height = 0); | |||
| UI(uint width = 0, uint height = 0, bool userResizable = false); | |||
| /** | |||
| Destructor. | |||
| */ | |||
| virtual ~UI(); | |||
| /** | |||
| Set geometry constraints for the UI when resized by the user. | |||
| This is a convenience function that calls getParentWindow().setGeometryConstraints() | |||
| @see Window::setGeometryConstraints(uint,uint,bool) | |||
| */ | |||
| void setGeometryConstraints(uint minWidth, uint minHeight, bool keepAspectRatio); | |||
| /* -------------------------------------------------------------------------------------------------------- | |||
| * Host state */ | |||
| @@ -37,9 +37,9 @@ const char* g_nextBundlePath = nullptr; | |||
| * UI */ | |||
| #ifdef HAVE_DGL | |||
| UI::UI(uint width, uint height) | |||
| UI::UI(uint width, uint height, bool userResizable) | |||
| : UIWidget(*d_lastUiWindow), | |||
| pData(new PrivateData()) | |||
| pData(new PrivateData(userResizable)) | |||
| { | |||
| ((UIWidget*)this)->pData->needsFullViewport = false; | |||
| @@ -47,9 +47,9 @@ UI::UI(uint width, uint height) | |||
| setSize(width, height); | |||
| } | |||
| #else | |||
| UI::UI(uint width, uint height) | |||
| UI::UI(uint width, uint height, bool userResizable) | |||
| : UIWidget(width, height), | |||
| pData(new PrivateData()) {} | |||
| pData(new PrivateData(userResizable)) {} | |||
| #endif | |||
| UI::~UI() | |||
| @@ -57,6 +57,11 @@ UI::~UI() | |||
| delete pData; | |||
| } | |||
| void UI::setGeometryConstraints(uint minWidth, uint minHeight, bool keepAspectRatio) | |||
| { | |||
| return getParentWindow().setGeometryConstraints(minWidth, minHeight, keepAspectRatio); | |||
| } | |||
| /* ------------------------------------------------------------------------------------------------------------ | |||
| * Host state */ | |||
| @@ -60,6 +60,9 @@ struct UI::PrivateData { | |||
| void* dspPtr; | |||
| #endif | |||
| // UI | |||
| const bool userResizable; | |||
| // Callbacks | |||
| void* callbacksPtr; | |||
| editParamFunc editParamCallbackFunc; | |||
| @@ -68,12 +71,13 @@ struct UI::PrivateData { | |||
| sendNoteFunc sendNoteCallbackFunc; | |||
| setSizeFunc setSizeCallbackFunc; | |||
| PrivateData() noexcept | |||
| PrivateData(bool resizable) noexcept | |||
| : sampleRate(d_lastUiSampleRate), | |||
| parameterOffset(0), | |||
| #if DISTRHO_PLUGIN_WANT_DIRECT_ACCESS | |||
| dspPtr(d_lastUiDspPtr), | |||
| #endif | |||
| userResizable(resizable), | |||
| callbacksPtr(nullptr), | |||
| editParamCallbackFunc(nullptr), | |||
| setParamCallbackFunc(nullptr), | |||
| @@ -155,9 +159,9 @@ public: | |||
| fIsReady(false) | |||
| { | |||
| DISTRHO_SAFE_ASSERT_RETURN(fUI != nullptr,); | |||
| DISTRHO_SAFE_ASSERT_RETURN(fUI->pData != nullptr,); | |||
| // set window size | |||
| setResizable(false); | |||
| setResizable(fUI->pData->userResizable); | |||
| setSize(fUI->getWidth(), fUI->getHeight()); | |||
| } | |||
| @@ -182,6 +186,7 @@ protected: | |||
| { | |||
| DISTRHO_SAFE_ASSERT_RETURN(fUI != nullptr,); | |||
| fUI->setSize(width, height); | |||
| fUI->uiReshape(width, height); | |||
| fIsReady = true; | |||
| } | |||
| @@ -18,6 +18,8 @@ | |||
| #include "DistrhoUI.hpp" | |||
| #include "Window.hpp" | |||
| START_NAMESPACE_DISTRHO | |||
| // ----------------------------------------------------------------------------------------------------------- | |||
| @@ -26,13 +28,16 @@ class InfoExampleUI : public UI | |||
| { | |||
| public: | |||
| InfoExampleUI() | |||
| : UI(405, 256) | |||
| : UI(405, 256, true), | |||
| fScale(1.0f) | |||
| { | |||
| std::memset(fParameters, 0, sizeof(float)*kParameterCount); | |||
| std::memset(fStrBuf, 0, sizeof(char)*(0xff+1)); | |||
| fSampleRate = getSampleRate(); | |||
| fFont = createFontFromFile("sans", "/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf"); | |||
| setGeometryConstraints(405, 256, false); | |||
| } | |||
| protected: | |||
| @@ -69,13 +74,13 @@ protected: | |||
| */ | |||
| void onNanoDisplay() override | |||
| { | |||
| static const float lineHeight = 20; | |||
| const float lineHeight = 20 * fScale; | |||
| fontSize(15.0f); | |||
| fontSize(15.0f * fScale); | |||
| textLineHeight(lineHeight); | |||
| float x = 0; | |||
| float y = 15; | |||
| float x = 0.0f * fScale; | |||
| float y = 15.0f * fScale; | |||
| // buffer size | |||
| drawLeft(x, y, "Buffer Size:"); | |||
| @@ -104,8 +109,8 @@ protected: | |||
| y+=lineHeight; | |||
| // BBT | |||
| x = 200; | |||
| y = 15; | |||
| x = 200.0f * fScale; | |||
| y = 15.0f * fScale; | |||
| const bool validBBT(fParameters[kParameterTimeValidBBT] > 0.5f); | |||
| drawLeft(x, y, "BBT Valid:"); | |||
| @@ -148,6 +153,14 @@ protected: | |||
| y+=lineHeight; | |||
| } | |||
| void onResize(const ResizeEvent& ev) override | |||
| { | |||
| fScale = static_cast<float>(ev.size.getHeight())/256.0f; | |||
| UI::onResize(ev); | |||
| } | |||
| // ------------------------------------------------------------------------------------------------------- | |||
| private: | |||
| @@ -155,8 +168,9 @@ private: | |||
| float fParameters[kParameterCount]; | |||
| double fSampleRate; | |||
| // font | |||
| // UI stuff | |||
| FontId fFont; | |||
| float fScale; | |||
| // temp buf for text | |||
| char fStrBuf[0xff+1]; | |||
| @@ -190,7 +204,7 @@ private: | |||
| beginPath(); | |||
| fillColor(200, 200, 200); | |||
| textAlign(ALIGN_RIGHT|ALIGN_TOP); | |||
| textBox(x, y, 100, text); | |||
| textBox(x, y, 100 * fScale, text); | |||
| closePath(); | |||
| } | |||
| @@ -199,7 +213,7 @@ private: | |||
| beginPath(); | |||
| fillColor(255, 255, 255); | |||
| textAlign(ALIGN_LEFT|ALIGN_TOP); | |||
| textBox(x+105, y, 100, text); | |||
| textBox(x + (105 * fScale), y, 100 * fScale, text); | |||
| closePath(); | |||
| } | |||