mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
VST Host: Ensure editor windows open at correct size
Previously, on hi res displays, "Plogue AlterEgo" was opening with a window that was too large, because the window size was applied before the scale factor was known. When the scale factor was updated, the window size was not changed if the window was hidden, so the window would remain too large when it was shown.
This commit is contained in:
parent
8f1ba916ff
commit
462c3a8dd4
1 changed files with 20 additions and 25 deletions
|
|
@ -2977,7 +2977,9 @@ public:
|
|||
void nativeScaleFactorChanged (double newScaleFactor) override
|
||||
{
|
||||
setScaleFactorAndDispatchMessage (newScaleFactor);
|
||||
componentMovedOrResized (true, true);
|
||||
#if JUCE_WINDOWS
|
||||
resizeToFit();
|
||||
#endif
|
||||
}
|
||||
|
||||
void setScaleFactorAndDispatchMessage (double newScaleFactor)
|
||||
|
|
@ -3278,40 +3280,33 @@ private:
|
|||
|
||||
//==============================================================================
|
||||
#if JUCE_WINDOWS
|
||||
bool willCauseRecursiveResize (int w, int h)
|
||||
{
|
||||
auto newScreenBounds = Rectangle<int> (w, h).withPosition (getScreenPosition());
|
||||
return Desktop::getInstance().getDisplays().getDisplayForRect (newScreenBounds)->scale != nativeScaleFactor;
|
||||
}
|
||||
|
||||
bool isWindowSizeCorrectForPlugin (int w, int h)
|
||||
{
|
||||
if (! isShowing() || pluginRefusesToResize)
|
||||
if (pluginRefusesToResize)
|
||||
return true;
|
||||
|
||||
return (isWithin (w, getWidth(), 5) && isWithin (h, getHeight(), 5));
|
||||
}
|
||||
|
||||
void resizeToFit()
|
||||
{
|
||||
Vst2::ERect* rect = nullptr;
|
||||
dispatch (Vst2::effEditGetRect, 0, 0, &rect, 0);
|
||||
|
||||
auto w = roundToInt ((rect->right - rect->left) / nativeScaleFactor);
|
||||
auto h = roundToInt ((rect->bottom - rect->top) / nativeScaleFactor);
|
||||
|
||||
if (! isWindowSizeCorrectForPlugin (w, h))
|
||||
{
|
||||
updateSizeFromEditor (w, h);
|
||||
sizeCheckCount = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void checkPluginWindowSize()
|
||||
{
|
||||
if (! pluginRespondsToDPIChanges)
|
||||
{
|
||||
Vst2::ERect* rect = nullptr;
|
||||
dispatch (Vst2::effEditGetRect, 0, 0, &rect, 0);
|
||||
|
||||
auto w = roundToInt ((rect->right - rect->left) / nativeScaleFactor);
|
||||
auto h = roundToInt ((rect->bottom - rect->top) / nativeScaleFactor);
|
||||
|
||||
if (! isWindowSizeCorrectForPlugin (w, h))
|
||||
{
|
||||
// If plug-in isn't DPI aware then we need to resize our window, but this may cause a recursive resize
|
||||
// so add a check
|
||||
if (! willCauseRecursiveResize (w, h))
|
||||
updateSizeFromEditor (w, h);
|
||||
|
||||
sizeCheckCount = 0;
|
||||
}
|
||||
}
|
||||
resizeToFit();
|
||||
}
|
||||
|
||||
// hooks to get keyboard events from VST windows..
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue