From df024aaf3b056e98d886612f9783b7a88709a104 Mon Sep 17 00:00:00 2001 From: attila Date: Tue, 24 Sep 2024 17:12:44 +0200 Subject: [PATCH] VST3 Host: Fix growing windows due to inaccurate coordinate operations Prior to this commit we used the integral version of localAreaToGlobal before multiplying its result by the scale factor. This multiplied the rounding error of localAreaToGlobal by the scale factor. Now we only round after all calculations have been carried out. --- .../format_types/juce_VST3PluginFormat.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/modules/juce_audio_processors/format_types/juce_VST3PluginFormat.cpp b/modules/juce_audio_processors/format_types/juce_VST3PluginFormat.cpp index 37e627e746..2312683ba4 100644 --- a/modules/juce_audio_processors/format_types/juce_VST3PluginFormat.cpp +++ b/modules/juce_audio_processors/format_types/juce_VST3PluginFormat.cpp @@ -1637,14 +1637,17 @@ private: /* Convert from the component's coordinate system to the hosted VST3's coordinate system. */ ViewRect componentToVST3Rect (Rectangle r) const { - const auto physical = localAreaToGlobal (r) * nativeScaleFactor * getDesktopScaleFactor(); + const auto combinedScale = nativeScaleFactor * getDesktopScaleFactor(); + const auto physical = (localAreaToGlobal (r.toFloat()) * combinedScale).toNearestInt(); return { 0, 0, physical.getWidth(), physical.getHeight() }; } /* Convert from the hosted VST3's coordinate system to the component's coordinate system. */ Rectangle vst3ToComponentRect (const ViewRect& vr) const { - return getLocalArea (nullptr, Rectangle { vr.right, vr.bottom } / (nativeScaleFactor * getDesktopScaleFactor())); + const auto combinedScale = nativeScaleFactor * getDesktopScaleFactor(); + const auto floatRect = Rectangle { (float) vr.right, (float) vr.bottom } / combinedScale; + return getLocalArea (nullptr, floatRect).toNearestInt(); } void componentMovedOrResized (bool, bool wasResized) override