Skip to content

Commit

Permalink
A first attempt at improving the adjust size approach
Browse files Browse the repository at this point in the history
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 free-audio#56
  • Loading branch information
baconpaul committed Jun 22, 2022
1 parent 2439077 commit 6a7f102
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
42 changes: 41 additions & 1 deletion src/wrapper/clap-juce-wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand All @@ -1000,7 +1005,42 @@ class ClapJuceWrapper : public clap::helpers::Plugin<
if (!editor->isResizable())
return false;

editor->setSize(static_cast<int>(*w), static_cast<int>(*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<int>(width), static_cast<int>(height));
return true;
}

Expand Down

0 comments on commit 6a7f102

Please sign in to comment.