From 21a88423dd6e2f67dbce222777dfa0075a6e2955 Mon Sep 17 00:00:00 2001 From: ed Date: Tue, 8 Jan 2019 17:11:20 +0000 Subject: [PATCH] VST3: More resizing fixes when using a fixed aspect ratio --- .../VST3/juce_VST3_Wrapper.cpp | 72 +++++++++++++------ 1 file changed, 50 insertions(+), 22 deletions(-) diff --git a/modules/juce_audio_plugin_client/VST3/juce_VST3_Wrapper.cpp b/modules/juce_audio_plugin_client/VST3/juce_VST3_Wrapper.cpp index 675df873ac..bd85680056 100644 --- a/modules/juce_audio_plugin_client/VST3/juce_VST3_Wrapper.cpp +++ b/modules/juce_audio_plugin_client/VST3/juce_VST3_Wrapper.cpp @@ -987,37 +987,65 @@ private: { if (auto* constrainer = editor->getConstrainer()) { + auto minW = (double) constrainer->getMinimumWidth(); + auto maxW = (double) constrainer->getMaximumWidth(); + auto minH = (double) constrainer->getMinimumHeight(); + auto maxH = (double) constrainer->getMaximumHeight(); + + auto width = (double) (rectToCheck->right - rectToCheck->left); + auto height = (double) (rectToCheck->bottom - rectToCheck->top); + #if JUCE_WINDOWS && JUCE_WIN_PER_MONITOR_DPI_AWARE - auto juceRect = editor->getLocalArea (component.get(), - Rectangle::leftTopRightBottom (rectToCheck->left, rectToCheck->top, - rectToCheck->right, rectToCheck->bottom) / editorScaleFactor); - #else - auto juceRect = editor->getLocalArea (component.get(), - { rectToCheck->left, rectToCheck->top, rectToCheck->right, rectToCheck->bottom }); + width /= editorScaleFactor; + height /= editorScaleFactor; #endif - Rectangle limits (0, 0, constrainer->getMaximumWidth(), constrainer->getMaximumHeight()); + width = jlimit (minW, maxW, width); + height = jlimit (minH, maxH, height); - auto currentRect = editor->getBounds(); + auto aspectRatio = constrainer->getFixedAspectRatio(); - if (getHostType().isReaper() && constrainer->getFixedAspectRatio() != 0.0) - constrainer->checkBounds (juceRect, currentRect, limits, false, false, true, true); - else - constrainer->checkBounds (juceRect, currentRect, limits, - juceRect.getY() != currentRect.getY() && juceRect.getBottom() == currentRect.getBottom(), - juceRect.getX() != currentRect.getX() && juceRect.getRight() == currentRect.getRight(), - juceRect.getY() == currentRect.getY() && juceRect.getBottom() != currentRect.getBottom(), - juceRect.getX() == currentRect.getX() && juceRect.getRight() != currentRect.getRight()); + if (aspectRatio != 0.0) + { + bool adjustWidth = (width / height > aspectRatio); - juceRect = component->getLocalArea (editor, juceRect); + if (getHostType().type == PluginHostType::SteinbergCubase9) + { + if (editor->getWidth() == width && editor->getHeight() != height) + adjustWidth = true; + else if (editor->getHeight() == height && editor->getWidth() != width) + adjustWidth = false; + } + + if (adjustWidth) + { + width = height * aspectRatio; + + if (width > maxW || width < minW) + { + width = jlimit (minW, maxW, width); + height = width / aspectRatio; + } + } + else + { + height = width / aspectRatio; + + if (height > maxH || height < minH) + { + height = jlimit (minH, maxH, height); + width = height * aspectRatio; + } + } + } #if JUCE_WINDOWS && JUCE_WIN_PER_MONITOR_DPI_AWARE - rectToCheck->right = rectToCheck->left + roundToInt (juceRect.getWidth() * editorScaleFactor); - rectToCheck->bottom = rectToCheck->top + roundToInt (juceRect.getHeight() * editorScaleFactor); - #else - rectToCheck->right = rectToCheck->left + juceRect.getWidth(); - rectToCheck->bottom = rectToCheck->top + juceRect.getHeight(); + width *= editorScaleFactor; + height *= editorScaleFactor; #endif + + rectToCheck->right = rectToCheck->left + roundToInt (width); + rectToCheck->bottom = rectToCheck->top + roundToInt (height); } }