diff --git a/src/CardinalPlugin.cpp b/src/CardinalPlugin.cpp index ca4b7a5..cd423b5 100644 --- a/src/CardinalPlugin.cpp +++ b/src/CardinalPlugin.cpp @@ -310,6 +310,7 @@ class CardinalPlugin : public CardinalBasePlugin float* fAudioBufferIn; float* fAudioBufferOut; std::string fAutosavePath; + String fWindowSize; // for base/context handling bool fIsActive; @@ -323,7 +324,7 @@ class CardinalPlugin : public CardinalBasePlugin public: CardinalPlugin() - : CardinalBasePlugin(kModuleParameters + kWindowParameterCount, 0, 1), + : CardinalBasePlugin(kModuleParameters + kWindowParameterCount, 0, 2), fInitializer(this), fAudioBufferIn(nullptr), fAudioBufferOut(nullptr), @@ -642,10 +643,17 @@ protected: void initState(const uint32_t index, String& stateKey, String& defaultStateValue) override { - DISTRHO_SAFE_ASSERT_RETURN(index == 0,); - - stateKey = "patch"; defaultStateValue = ""; + + switch (index) + { + case 0: + stateKey = "patch"; + break; + case 1: + stateKey = "windowSize"; + break; + } } /* -------------------------------------------------------------------------------------------------------- @@ -683,6 +691,9 @@ protected: String getState(const char* const key) const override { + if (std::strcmp(key, "windowSize") == 0) + return fWindowSize; + if (std::strcmp(key, "patch") != 0) return String(); if (fAutosavePath.empty()) @@ -707,6 +718,12 @@ protected: void setState(const char* const key, const char* const value) override { + if (std::strcmp(key, "windowSize") == 0) + { + fWindowSize = value; + return; + } + if (std::strcmp(key, "patch") != 0) return; if (fAutosavePath.empty()) diff --git a/src/CardinalUI.cpp b/src/CardinalUI.cpp index 72239a7..390c80b 100644 --- a/src/CardinalUI.cpp +++ b/src/CardinalUI.cpp @@ -273,6 +273,18 @@ protected: void stateChanged(const char* key, const char* value) override { + if (std::strcmp(key, "windowSize") != 0) + return; + + int width = 0; + int height = 0; + std::sscanf(value, "%i:%i", &width, &height); + + if (width > 0 && height > 0) + { + const double scaleFactor = getScaleFactor(); + setSize(width * scaleFactor, height * scaleFactor); + } } // ------------------------------------------------------------------------------------------------------- @@ -479,6 +491,17 @@ protected: return fContext->event->handleKey(fLastMousePos, key, ev.keycode, action, mods); } + void onResize(const ResizeEvent& ev) override + { + UI::onResize(ev); + + const double scaleFactor = getScaleFactor(); + char sizeString[64]; + std::snprintf(sizeString, sizeof(sizeString), "%d:%d", + (int)(ev.size.getWidth() / scaleFactor), (int)(ev.size.getHeight() / scaleFactor)); + setState("windowSize", sizeString); + } + void uiFocus(const bool focus, CrossingMode) override { if (focus)