Add window size as plugin state
This commit is contained in:
parent
a5c42b5460
commit
541a994adf
2 changed files with 44 additions and 4 deletions
|
@ -310,6 +310,7 @@ class CardinalPlugin : public CardinalBasePlugin
|
||||||
float* fAudioBufferIn;
|
float* fAudioBufferIn;
|
||||||
float* fAudioBufferOut;
|
float* fAudioBufferOut;
|
||||||
std::string fAutosavePath;
|
std::string fAutosavePath;
|
||||||
|
String fWindowSize;
|
||||||
|
|
||||||
// for base/context handling
|
// for base/context handling
|
||||||
bool fIsActive;
|
bool fIsActive;
|
||||||
|
@ -323,7 +324,7 @@ class CardinalPlugin : public CardinalBasePlugin
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CardinalPlugin()
|
CardinalPlugin()
|
||||||
: CardinalBasePlugin(kModuleParameters + kWindowParameterCount, 0, 1),
|
: CardinalBasePlugin(kModuleParameters + kWindowParameterCount, 0, 2),
|
||||||
fInitializer(this),
|
fInitializer(this),
|
||||||
fAudioBufferIn(nullptr),
|
fAudioBufferIn(nullptr),
|
||||||
fAudioBufferOut(nullptr),
|
fAudioBufferOut(nullptr),
|
||||||
|
@ -642,10 +643,17 @@ protected:
|
||||||
|
|
||||||
void initState(const uint32_t index, String& stateKey, String& defaultStateValue) override
|
void initState(const uint32_t index, String& stateKey, String& defaultStateValue) override
|
||||||
{
|
{
|
||||||
DISTRHO_SAFE_ASSERT_RETURN(index == 0,);
|
|
||||||
|
|
||||||
stateKey = "patch";
|
|
||||||
defaultStateValue = "";
|
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
|
String getState(const char* const key) const override
|
||||||
{
|
{
|
||||||
|
if (std::strcmp(key, "windowSize") == 0)
|
||||||
|
return fWindowSize;
|
||||||
|
|
||||||
if (std::strcmp(key, "patch") != 0)
|
if (std::strcmp(key, "patch") != 0)
|
||||||
return String();
|
return String();
|
||||||
if (fAutosavePath.empty())
|
if (fAutosavePath.empty())
|
||||||
|
@ -707,6 +718,12 @@ protected:
|
||||||
|
|
||||||
void setState(const char* const key, const char* const value) override
|
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)
|
if (std::strcmp(key, "patch") != 0)
|
||||||
return;
|
return;
|
||||||
if (fAutosavePath.empty())
|
if (fAutosavePath.empty())
|
||||||
|
|
|
@ -273,6 +273,18 @@ protected:
|
||||||
|
|
||||||
void stateChanged(const char* key, const char* value) override
|
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);
|
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
|
void uiFocus(const bool focus, CrossingMode) override
|
||||||
{
|
{
|
||||||
if (focus)
|
if (focus)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue