Add window size as plugin state

This commit is contained in:
falkTX 2021-10-27 03:20:18 +01:00
parent a5c42b5460
commit 541a994adf
2 changed files with 44 additions and 4 deletions

View file

@ -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)