mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
VST3 Client: Attempt to preserve scale set by host
This commit is contained in:
parent
98e0ee75a3
commit
69e0727ffd
2 changed files with 54 additions and 31 deletions
|
|
@ -1786,8 +1786,7 @@ private:
|
|||
// constructor, we don't have a host plugFrame, so
|
||||
// ContentWrapperComponent::resizeHostWindow() won't do anything, and the content
|
||||
// wrapper component will be left at the wrong size.
|
||||
if (! approximatelyEqual (editorScaleFactor, owner->lastScaleFactorReceived))
|
||||
setContentScaleFactor (owner->lastScaleFactorReceived);
|
||||
applyScaleFactor (StoredScaleFactor{}.withInternal (owner->lastScaleFactorReceived));
|
||||
|
||||
// Check the host scale factor *before* calling addToDesktop, so that the initial
|
||||
// window size during addToDesktop is correct for the current platform scale factor.
|
||||
|
|
@ -1990,35 +1989,28 @@ private:
|
|||
return kResultFalse;
|
||||
}
|
||||
|
||||
tresult PLUGIN_API setContentScaleFactor (Steinberg::IPlugViewContentScaleSupport::ScaleFactor factor) override
|
||||
tresult PLUGIN_API setContentScaleFactor (const Steinberg::IPlugViewContentScaleSupport::ScaleFactor factor) override
|
||||
{
|
||||
#if ! JUCE_MAC
|
||||
if (! approximatelyEqual ((float) factor, editorScaleFactor))
|
||||
const auto scaleToApply = [&]
|
||||
{
|
||||
#if JUCE_WINDOWS && JUCE_WIN_PER_MONITOR_DPI_AWARE
|
||||
// Cubase 10 only sends integer scale factors, so correct this for fractional scales
|
||||
if (getHostType().type == PluginHostType::SteinbergCubase10)
|
||||
{
|
||||
auto hostWindowScale = (Steinberg::IPlugViewContentScaleSupport::ScaleFactor) getScaleFactorForWindow ((HWND) systemWindow);
|
||||
if (getHostType().type != PluginHostType::SteinbergCubase10)
|
||||
return factor;
|
||||
|
||||
if (hostWindowScale > 0.0 && ! approximatelyEqual (factor, hostWindowScale))
|
||||
factor = hostWindowScale;
|
||||
}
|
||||
const auto hostWindowScale = (Steinberg::IPlugViewContentScaleSupport::ScaleFactor) getScaleFactorForWindow (static_cast<HWND> (systemWindow));
|
||||
|
||||
if (hostWindowScale <= 0.0 || approximatelyEqual (factor, hostWindowScale))
|
||||
return factor;
|
||||
|
||||
return hostWindowScale;
|
||||
#else
|
||||
return factor;
|
||||
#endif
|
||||
}();
|
||||
|
||||
editorScaleFactor = (float) factor;
|
||||
|
||||
if (owner != nullptr)
|
||||
owner->lastScaleFactorReceived = editorScaleFactor;
|
||||
|
||||
if (component != nullptr)
|
||||
{
|
||||
#if JUCE_LINUX || JUCE_BSD
|
||||
const MessageManagerLock mmLock;
|
||||
#endif
|
||||
component->setEditorScaleFactor (editorScaleFactor);
|
||||
}
|
||||
}
|
||||
applyScaleFactor (scaleFactor.withHost (scaleToApply));
|
||||
|
||||
return kResultTrue;
|
||||
#else
|
||||
|
|
@ -2103,7 +2095,7 @@ private:
|
|||
|
||||
pluginEditor->setHostContext (editorHostContext.get());
|
||||
#if ! JUCE_MAC
|
||||
pluginEditor->setScaleFactor (owner.editorScaleFactor);
|
||||
pluginEditor->setScaleFactor (owner.scaleFactor.get());
|
||||
#endif
|
||||
|
||||
addAndMakeVisible (pluginEditor.get());
|
||||
|
|
@ -2234,10 +2226,10 @@ private:
|
|||
#if JUCE_WINDOWS && JUCE_WIN_PER_MONITOR_DPI_AWARE
|
||||
void checkHostWindowScaleFactor()
|
||||
{
|
||||
auto hostWindowScale = (float) getScaleFactorForWindow ((HWND) owner.systemWindow);
|
||||
const auto estimatedScale = (float) getScaleFactorForWindow (static_cast<HWND> (owner.systemWindow));
|
||||
|
||||
if (hostWindowScale > 0.0 && ! approximatelyEqual (hostWindowScale, owner.editorScaleFactor))
|
||||
owner.setContentScaleFactor (hostWindowScale);
|
||||
if (estimatedScale > 0.0)
|
||||
owner.applyScaleFactor (owner.scaleFactor.withInternal (estimatedScale));
|
||||
}
|
||||
|
||||
void timerCallback() override
|
||||
|
|
@ -2321,7 +2313,38 @@ private:
|
|||
|
||||
std::unique_ptr<Cubase10WindowResizeWorkaround> cubase10Workaround;
|
||||
#else
|
||||
float editorScaleFactor = 1.0f;
|
||||
class StoredScaleFactor
|
||||
{
|
||||
public:
|
||||
StoredScaleFactor withHost (float x) const { return withMember (*this, &StoredScaleFactor::host, x); }
|
||||
StoredScaleFactor withInternal (float x) const { return withMember (*this, &StoredScaleFactor::internal, x); }
|
||||
float get() const { return host.value_or (internal); }
|
||||
|
||||
private:
|
||||
std::optional<float> host;
|
||||
float internal = 1.0f;
|
||||
};
|
||||
|
||||
void applyScaleFactor (const StoredScaleFactor newFactor)
|
||||
{
|
||||
const auto previous = std::exchange (scaleFactor, newFactor).get();
|
||||
|
||||
if (previous == scaleFactor.get())
|
||||
return;
|
||||
|
||||
if (owner != nullptr)
|
||||
owner->lastScaleFactorReceived = scaleFactor.get();
|
||||
|
||||
if (component != nullptr)
|
||||
{
|
||||
#if JUCE_LINUX || JUCE_BSD
|
||||
const MessageManagerLock mmLock;
|
||||
#endif
|
||||
component->setEditorScaleFactor (scaleFactor.get());
|
||||
}
|
||||
}
|
||||
|
||||
StoredScaleFactor scaleFactor;
|
||||
|
||||
#if JUCE_WINDOWS
|
||||
WindowsHooks hooks;
|
||||
|
|
|
|||
|
|
@ -79,10 +79,10 @@ template <typename A, typename B>
|
|||
using DisableIfSameOrDerived = std::enable_if_t<! std::is_base_of_v<A, std::remove_reference_t<B>>>;
|
||||
|
||||
/** Copies an object, sets one of the copy's members to the specified value, and then returns the copy. */
|
||||
template <typename Object, typename OtherObject, typename Member>
|
||||
Object withMember (Object copy, Member OtherObject::* member, Member&& value)
|
||||
template <typename Object, typename OtherObject, typename Member, typename Other>
|
||||
Object withMember (Object copy, Member OtherObject::* member, Other&& value)
|
||||
{
|
||||
copy.*member = std::forward<Member> (value);
|
||||
copy.*member = std::forward<Other> (value);
|
||||
return copy;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue