From 6a7f102e0e877e02e46b0f4dfdf0884ef7d0d71c Mon Sep 17 00:00:00 2001 From: Paul Walker Date: Tue, 21 Jun 2022 19:45:22 -0400 Subject: [PATCH] A first attempt at improving the adjust size approach This is a first shot at making adjust size / set size work. It naively just applies aspect ratio to with which makes corner and bottom drags work but not side drags. An algorithm to work for all drags without knowing the direction of the user gesture which is stable continues to elude me, but I wanted at least something more reasonable in teh codebase before I go on vacation. Addresses #56 --- clap-libs/clap-helpers | 2 +- src/wrapper/clap-juce-wrapper.cpp | 42 ++++++++++++++++++++++++++++++- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/clap-libs/clap-helpers b/clap-libs/clap-helpers index 2bb43c1..b101259 160000 --- a/clap-libs/clap-helpers +++ b/clap-libs/clap-helpers @@ -1 +1 @@ -Subproject commit 2bb43c18788c689708ead6f127a2d75e772ab389 +Subproject commit b101259ae06964c76c6806f02ec07847acb7b6dc diff --git a/src/wrapper/clap-juce-wrapper.cpp b/src/wrapper/clap-juce-wrapper.cpp index 87a4fd1..e1b6737 100644 --- a/src/wrapper/clap-juce-wrapper.cpp +++ b/src/wrapper/clap-juce-wrapper.cpp @@ -108,6 +108,10 @@ JUCE_BEGIN_IGNORE_WARNINGS_MSVC(4996) // allow strncpy #define CLAP_MISBEHAVIOUR_HANDLER_LEVEL "Ignore" #endif +// This is useful for debugging overrides +// #undef CLAP_MISBEHAVIOUR_HANDLER_LEVEL +// #define CLAP_MISBEHAVIOUR_HANDLER_LEVEL Terminate + /* * A little class that sets an atomic bool to a value across its lifetime and * restores it on exit. @@ -992,6 +996,7 @@ class ClapJuceWrapper : public clap::helpers::Plugin< return editor->isResizable(); return true; } + bool guiAdjustSize(uint32_t *w, uint32_t *h) noexcept override { if (!editor) @@ -1000,7 +1005,42 @@ class ClapJuceWrapper : public clap::helpers::Plugin< if (!editor->isResizable()) return false; - editor->setSize(static_cast(*w), static_cast(*h)); + auto cst = editor->getConstrainer(); + + if (!cst) + return true; // we have no constraints. Whaever is fine! + + auto minW = (uint32_t)cst->getMinimumWidth(); + auto maxW = (uint32_t)cst->getMaximumWidth(); + auto minH = (uint32_t)cst->getMinimumHeight(); + auto maxH = (uint32_t)cst->getMaximumHeight(); + + auto width = std::clamp(*w, minW, maxW); + auto height = std::clamp(*h, minH, maxH); + + auto aspectRatio = (float)cst->getFixedAspectRatio(); + + if (aspectRatio != 0.0) + { + // This is an unsatisfactory but stable algorithm + width = aspectRatio * height; + } + + *w = width; + *h = height; + + return true; + } + + bool guiSetSize(uint32_t width, uint32_t height) noexcept override + { + if (!editor) + return false; + + if (!editor->isResizable()) + return false; + + editor->setSize(static_cast(width), static_cast(height)); return true; }