1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

LV2 Host: Query ComponentPeer directly for scale factor instead of using a cached value

This commit is contained in:
reuk 2025-09-23 21:37:27 +01:00
parent 0ba96f15a0
commit 167d9b64c3
No known key found for this signature in database

View file

@ -545,16 +545,29 @@ private:
/* Convert from the component's coordinate system to the hosted LV2's coordinate system. */ /* Convert from the component's coordinate system to the hosted LV2's coordinate system. */
Rectangle<int> componentToLv2Rect (Rectangle<int> r) const Rectangle<int> componentToLv2Rect (Rectangle<int> r) const
{ {
return localAreaToGlobal (r) * nativeScaleFactor * getDesktopScaleFactor(); const auto platformScale = getDesktopScaleFactor() * getPeerScale();
return (localAreaToGlobal (r.toFloat()) * platformScale).toNearestInt();
} }
/* Convert from the hosted LV2's coordinate system to the component's coordinate system. */ /* Convert from the hosted LV2's coordinate system to the component's coordinate system. */
Rectangle<int> lv2ToComponentRect (Rectangle<int> vr) const Rectangle<int> lv2ToComponentRect (Rectangle<int> vr) const
{ {
return getLocalArea (nullptr, vr / (nativeScaleFactor * getDesktopScaleFactor())); const auto platformScale = getDesktopScaleFactor() * getPeerScale();
return (getLocalArea (nullptr, vr.toFloat() / platformScale)).toNearestInt();
} }
float getEffectiveScale() const { return nativeScaleFactor * userScaleFactor; } float getPeerScale() const
{
if (auto* peer = getPeer())
return peer->getPlatformScaleFactor();
return 1.0f;
}
float getEffectiveScale() const
{
return getPeerScale() * userScaleFactor;
}
// If possible, try to keep platform-specific handing restricted to the implementation of // If possible, try to keep platform-specific handing restricted to the implementation of
// ViewComponent. Keep the interface of ViewComponent consistent on all platforms. // ViewComponent. Keep the interface of ViewComponent consistent on all platforms.
@ -660,20 +673,14 @@ private:
MessageManager::callAsync ([ref = Component::SafePointer<ConfiguredEditorComponent> (&window), platformScale] MessageManager::callAsync ([ref = Component::SafePointer<ConfiguredEditorComponent> (&window), platformScale]
{ {
if (auto* r = ref.getComponent()) if (auto* r = ref.getComponent())
{
if (approximatelyEqual (std::exchange (r->nativeScaleFactor, platformScale), platformScale))
return;
r->nativeScaleFactor = platformScale;
r->sendScaleFactorToPlugin(); r->sendScaleFactorToPlugin();
}
}); });
} }
}; };
LogicalResizeListener& resizeListener; LogicalResizeListener& resizeListener;
int lastWidth = 0, lastHeight = 0; int lastWidth = 0, lastHeight = 0;
float nativeScaleFactor = 1.0f, userScaleFactor = 1.0f; float userScaleFactor = 1.0f;
NativeScaleFactorNotifier scaleNotifier { this, ScaleNotifierCallback { *this } }; NativeScaleFactorNotifier scaleNotifier { this, ScaleNotifierCallback { *this } };
ViewComponent viewComponent { *this }; ViewComponent viewComponent { *this };
LV2_URID floatUrid, scaleFactorUrid; LV2_URID floatUrid, scaleFactorUrid;