From ebf86b5f353f6849ac950d45b8a49461db5ea3c1 Mon Sep 17 00:00:00 2001 From: reuk Date: Mon, 27 Sep 2021 20:19:35 +0100 Subject: [PATCH] VST3 Host: Correctly size unscalable editors when DPI changes --- .../format_types/juce_VST3PluginFormat.cpp | 44 +++++++++---------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/modules/juce_audio_processors/format_types/juce_VST3PluginFormat.cpp b/modules/juce_audio_processors/format_types/juce_VST3PluginFormat.cpp index 839aac20f7..06d0ee3c84 100644 --- a/modules/juce_audio_processors/format_types/juce_VST3PluginFormat.cpp +++ b/modules/juce_audio_processors/format_types/juce_VST3PluginFormat.cpp @@ -1355,17 +1355,17 @@ private: //============================================================================== struct VST3PluginWindow : public AudioProcessorEditor, - public ComponentMovementWatcher, - public ComponentPeer::ScaleFactorListener, - public IPlugFrame + private ComponentMovementWatcher, + private ComponentPeer::ScaleFactorListener, + private IPlugFrame { VST3PluginWindow (AudioPluginInstance* owner, IPlugView* pluginView) - : AudioProcessorEditor (owner), - ComponentMovementWatcher (this), - view (pluginView, false) - #if JUCE_MAC - , embeddedComponent (*owner) - #endif + : AudioProcessorEditor (owner), + ComponentMovementWatcher (this), + view (pluginView, false) + #if JUCE_MAC + , embeddedComponent (*owner) + #endif { setSize (10, 10); setOpaque (true); @@ -1437,6 +1437,7 @@ struct VST3PluginWindow : public AudioProcessorEditor, bool keyStateChanged (bool /*isKeyDown*/) override { return true; } bool keyPressed (const KeyPress& /*key*/) override { return true; } +private: //============================================================================== void componentPeerChanged() override { @@ -1508,15 +1509,9 @@ struct VST3PluginWindow : public AudioProcessorEditor, void nativeScaleFactorChanged (double newScaleFactor) override { - if (approximatelyEqual ((float) newScaleFactor, nativeScaleFactor)) - return; - nativeScaleFactor = (float) newScaleFactor; - - if (pluginHandle != HandleFormat{} && scaleInterface != nullptr) - scaleInterface->setContentScaleFactor ((Steinberg::IPlugViewContentScaleSupport::ScaleFactor) nativeScaleFactor); - else - resizeToFit(); + updatePluginScale(); + componentMovedOrResized (false, true); } void resizeToFit() @@ -1564,7 +1559,6 @@ struct VST3PluginWindow : public AudioProcessorEditor, return kInvalidArgument; } -private: //============================================================================== static void resizeWithRect (Component& comp, const ViewRect& rect, float scaleFactor) { @@ -1599,11 +1593,7 @@ private: } warnOnFailure (view->attached ((void*) pluginHandle, defaultVST3WindowType)); - - if (scaleInterface != nullptr) - scaleInterface->setContentScaleFactor ((Steinberg::IPlugViewContentScaleSupport::ScaleFactor) nativeScaleFactor); - else - resizeToFit(); + updatePluginScale(); } } @@ -1617,6 +1607,14 @@ private: currentPeer->removeScaleFactorListener (this); } + void updatePluginScale() + { + if (scaleInterface != nullptr) + warnOnFailure (scaleInterface->setContentScaleFactor ((Steinberg::IPlugViewContentScaleSupport::ScaleFactor) nativeScaleFactor)); + else + resizeToFit(); + } + //============================================================================== Atomic refCount { 1 }; VSTComSmartPtr view;