Browse Source

VST3: Improved stability of scaled plug-in windows

tags/2021-05-28
ed 4 years ago
parent
commit
3c494b8a70
1 changed files with 62 additions and 74 deletions
  1. +62
    -74
      modules/juce_audio_plugin_client/VST3/juce_VST3_Wrapper.cpp

+ 62
- 74
modules/juce_audio_plugin_client/VST3/juce_VST3_Wrapper.cpp View File

@@ -1227,8 +1227,8 @@ private:
createContentWrapperComponentIfNeeded();
#if JUCE_WINDOWS || JUCE_LINUX
component->addToDesktop (0, parent);
component->setOpaque (true);
component->addToDesktop (0, (void*) systemWindow);
component->setVisible (true);
#if JUCE_WINDOWS && JUCE_WIN_PER_MONITOR_DPI_AWARE
@@ -1295,10 +1295,7 @@ private:
if (component != nullptr)
{
auto w = rect.getWidth();
auto h = rect.getHeight();
component->setSize (w, h);
component->setSize (rect.getWidth(), rect.getHeight());
#if JUCE_MAC
if (cubase10Workaround != nullptr)
@@ -1358,32 +1355,34 @@ private:
{
*rectToCheck = convertFromHostBounds (*rectToCheck);
auto transformScale = std::sqrt (std::abs (editor->getTransform().getDeterminant()));
auto minW = (double) constrainer->getMinimumWidth() * transformScale;
auto maxW = (double) constrainer->getMaximumWidth() * transformScale;
auto minH = (double) constrainer->getMinimumHeight() * transformScale;
auto maxH = (double) constrainer->getMaximumHeight() * transformScale;
auto editorBounds = editor->getLocalArea (component.get(),
Rectangle<int>::leftTopRightBottom (rectToCheck->left, rectToCheck->top,
rectToCheck->right, rectToCheck->bottom).toFloat());
auto width = (double) rectToCheck->right - (double) rectToCheck->left;
auto height = (double) rectToCheck->bottom - (double) rectToCheck->top;
auto minW = (float) constrainer->getMinimumWidth();
auto maxW = (float) constrainer->getMaximumWidth();
auto minH = (float) constrainer->getMinimumHeight();
auto maxH = (float) constrainer->getMaximumHeight();
width = jlimit (minW, maxW, width);
height = jlimit (minH, maxH, height);
auto width = jlimit (minW, maxW, editorBounds.getWidth());
auto height = jlimit (minH, maxH, editorBounds.getHeight());
auto aspectRatio = constrainer->getFixedAspectRatio();
auto aspectRatio = (float) constrainer->getFixedAspectRatio();
if (aspectRatio != 0.0)
{
bool adjustWidth = (width / height > aspectRatio);
if (getHostType().type == PluginHostType::SteinbergCubase9)
auto adjustWidth = [&]
{
if (editor->getWidth() == width && editor->getHeight() != height)
adjustWidth = true;
else if (editor->getHeight() == height && editor->getWidth() != width)
adjustWidth = false;
}
auto currentEditorBounds = editor->getBounds().toFloat();
auto stretchingBottom = (currentEditorBounds.getBottom() != editorBounds.getBottom());
auto stretchingRight = (currentEditorBounds.getRight() != editorBounds.getRight());
if (getHostType().isReaper() || stretchingBottom == stretchingRight)
return currentEditorBounds.getAspectRatio() > (width / height);
return stretchingBottom;
}();
if (adjustWidth)
{
@@ -1407,8 +1406,11 @@ private:
}
}
rectToCheck->right = rectToCheck->left + roundToInt (width);
rectToCheck->bottom = rectToCheck->top + roundToInt (height);
auto constrainedRect = component->getLocalArea (editor, Rectangle<float> (width, height))
.getSmallestIntegerContainer();
rectToCheck->right = rectToCheck->left + roundToInt (constrainedRect.getWidth());
rectToCheck->bottom = rectToCheck->top + roundToInt (constrainedRect.getHeight());
*rectToCheck = convertToHostBounds (*rectToCheck);
}
@@ -1443,16 +1445,7 @@ private:
owner->lastScaleFactorReceived = editorScaleFactor;
if (component != nullptr)
{
if (auto* editor = component->pluginEditor.get())
{
editor->setScaleFactor (editorScaleFactor);
component->resizeHostWindow();
component->setTopLeftPosition (0, 0);
component->repaint();
}
}
component->setEditorScaleFactor (editorScaleFactor);
}
return kResultTrue;
@@ -1564,21 +1557,18 @@ private:
if (resizingChild)
return;
auto b = getSizeToContainChild();
auto newBounds = getSizeToContainChild();
if (lastBounds != b)
if (newBounds != lastBounds)
{
lastBounds = b;
{
const ScopedValueSetter<bool> resizingParentSetter (resizingParent, true);
resizeHostWindow();
}
resizeHostWindow();
#if JUCE_LINUX
if (getHostType().isBitwigStudio())
repaint();
#endif
lastBounds = newBounds;
}
}
@@ -1595,28 +1585,12 @@ private:
return;
#endif
lastBounds = newBounds;
const ScopedValueSetter<bool> resizingChildSetter (resizingChild, true);
if (auto* constrainer = pluginEditor->getConstrainer())
{
auto aspectRatio = constrainer->getFixedAspectRatio();
if (aspectRatio != 0)
{
auto width = (double) lastBounds.getWidth();
auto height = (double) lastBounds.getHeight();
if (width / height > aspectRatio)
setBounds ({ 0, 0, roundToInt (height * aspectRatio), lastBounds.getHeight() });
else
setBounds ({ 0, 0, lastBounds.getWidth(), roundToInt (width / aspectRatio) });
}
const ScopedValueSetter<bool> resizingChildSetter (resizingChild, true);
pluginEditor->setBounds (pluginEditor->getLocalArea (this, newBounds).withPosition (0, 0));
}
pluginEditor->setTopLeftPosition (0, 0);
pluginEditor->setBounds (pluginEditor->getLocalArea (this, getLocalBounds()));
lastBounds = newBounds;
}
}
}
@@ -1634,31 +1608,45 @@ private:
{
if (pluginEditor != nullptr)
{
auto b = getSizeToContainChild();
auto w = b.getWidth();
auto h = b.getHeight();
auto host = getHostType();
#if JUCE_WINDOWS
setSize (w, h);
#endif
if (owner.plugFrame != nullptr)
{
auto newSize = convertToHostBounds ({ 0, 0, b.getWidth(), b.getHeight() });
auto editorBounds = getSizeToContainChild();
auto newSize = convertToHostBounds ({ 0, 0, editorBounds.getWidth(), editorBounds.getHeight() });
{
const ScopedValueSetter<bool> resizingParentSetter (resizingParent, true);
owner.plugFrame->resizeView (&owner, &newSize);
}
auto host = getHostType();
#if JUCE_MAC
if (host.isWavelab() || host.isReaper())
#else
if (host.isWavelab() || host.isAbletonLive() || host.isBitwigStudio())
#endif
setBounds (0, 0, w, h);
setBounds (editorBounds.withPosition (0, 0));
}
}
}
void setEditorScaleFactor (float scale)
{
if (pluginEditor != nullptr)
{
auto prevEditorBounds = pluginEditor->getLocalArea (this, lastBounds);
{
const ScopedValueSetter<bool> resizingChildSetter (resizingChild, true);
pluginEditor->setScaleFactor (scale);
pluginEditor->setBounds (prevEditorBounds.withPosition (0, 0));
}
lastBounds = getSizeToContainChild();
resizeHostWindow();
repaint();
}
}


Loading…
Cancel
Save