commit 4430cd248559eb34041ed202c31cb46ce9e04754
parent bc3e18d381d21963cf442d4c2b7165228e9d2d4d
Author: falkTX <falktx@falktx.com>
Date: Sun, 28 Aug 2022 05:36:13 +0100
Introduce DISTRHO_UI_DEFAULT_WIDTH/HEIGHT macros, useful in VST2/3
Diffstat:
5 files changed, 67 insertions(+), 13 deletions(-)
diff --git a/distrho/DistrhoInfo.hpp b/distrho/DistrhoInfo.hpp
@@ -619,6 +619,24 @@ START_NAMESPACE_DISTRHO
#define DISTRHO_UI_CUSTOM_WIDGET_TYPE
/**
+ Default UI width to use when creating initial and temporary windows.@n
+ Setting this macro allows to skip a temporary UI from being created in certain VST2 and VST3 hosts.
+ (which would normally be done for knowing the UI size before host creates a window for it)
+
+ When this macro is defined, the companion DISTRHO_UI_DEFAULT_HEIGHT macro must be defined as well.
+ */
+#define DISTRHO_UI_DEFAULT_WIDTH 300
+
+/**
+ Default UI height to use when creating initial and temporary windows.@n
+ Setting this macro allows to skip a temporary UI from being created in certain VST2 and VST3 hosts.
+ (which would normally be done for knowing the UI size before host creates a window for it)
+
+ When this macro is defined, the companion DISTRHO_UI_DEFAULT_WIDTH macro must be defined as well.
+ */
+#define DISTRHO_UI_DEFAULT_HEIGHT 300
+
+/**
Whether the %UI uses NanoVG for drawing instead of the default raw OpenGL calls.@n
When enabled your %UI instance will subclass @ref NanoWidget instead of @ref Widget.
*/
diff --git a/distrho/src/DistrhoPluginChecks.h b/distrho/src/DistrhoPluginChecks.h
@@ -184,6 +184,17 @@
#endif
// -----------------------------------------------------------------------
+// Make sure both default width and height are provided
+
+#if defined(DISTRHO_UI_DEFAULT_WIDTH) && !defined(DISTRHO_UI_DEFAULT_HEIGHT)
+# error DISTRHO_UI_DEFAULT_WIDTH is defined but DISTRHO_UI_DEFAULT_HEIGHT is not
+#endif
+
+#if defined(DISTRHO_UI_DEFAULT_HEIGHT) && !defined(DISTRHO_UI_DEFAULT_WIDTH)
+# error DISTRHO_UI_DEFAULT_HEIGHT is defined but DISTRHO_UI_DEFAULT_WIDTH is not
+#endif
+
+// -----------------------------------------------------------------------
// Prevent users from messing about with DPF internals
#ifdef DISTRHO_UI_IS_STANDALONE
diff --git a/distrho/src/DistrhoPluginVST2.cpp b/distrho/src/DistrhoPluginVST2.cpp
@@ -575,17 +575,25 @@ public:
}
else
{
+ double scaleFactor = fLastScaleFactor;
+ #if defined(DISTRHO_UI_DEFAULT_WIDTH) && defined(DISTRHO_UI_DEFAULT_HEIGHT)
+ fVstRect.right = DISTRHO_UI_DEFAULT_WIDTH;
+ fVstRect.bottom = DISTRHO_UI_DEFAULT_HEIGHT;
+ if (d_isZero(scaleFactor))
+ scaleFactor = 1.0;
+ #else
UIExporter tmpUI(nullptr, 0, fPlugin.getSampleRate(),
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, d_nextBundlePath,
- fPlugin.getInstancePointer(), fLastScaleFactor);
- fVstRect.right = tmpUI.getWidth();
+ fPlugin.getInstancePointer(), scaleFactor);
+ fVstRect.right = tmpUI.getWidth();
fVstRect.bottom = tmpUI.getHeight();
-# ifdef DISTRHO_OS_MAC
- const double scaleFactor = tmpUI.getScaleFactor();
+ scaleFactor = tmpUI.getScaleFactor();
+ tmpUI.quit();
+ #endif
+ #ifdef DISTRHO_OS_MAC
fVstRect.right /= scaleFactor;
fVstRect.bottom /= scaleFactor;
-# endif
- tmpUI.quit();
+ #endif
}
*(ERect**)ptr = &fVstRect;
return 1;
diff --git a/distrho/src/DistrhoUI.cpp b/distrho/src/DistrhoUI.cpp
@@ -202,13 +202,23 @@ UI::PrivateData::createNextWindow(UI* const ui, const uint width, const uint hei
* UI */
UI::UI(const uint width, const uint height, const bool automaticallyScaleAndSetAsMinimumSize)
- : UIWidget(UI::PrivateData::createNextWindow(this, width, height)),
+ : UIWidget(UI::PrivateData::createNextWindow(this,
+ #ifdef DISTRHO_UI_DEFAULT_WIDTH
+ width == 0 ? DISTRHO_UI_DEFAULT_WIDTH :
+ #endif
+ width,
+ #ifdef DISTRHO_UI_DEFAULT_WIDTH
+ height == 0 ? DISTRHO_UI_DEFAULT_WIDTH :
+ #endif
+ height)),
uiData(UI::PrivateData::s_nextPrivateData)
{
#if !DISTRHO_PLUGIN_HAS_EXTERNAL_UI
if (width != 0 && height != 0)
{
+ #ifndef DISTRHO_UI_DEFAULT_WIDTH
Widget::setSize(width, height);
+ #endif
if (automaticallyScaleAndSetAsMinimumSize)
setGeometryConstraints(width, height, true, true, true);
diff --git a/distrho/src/DistrhoUIVST3.cpp b/distrho/src/DistrhoUIVST3.cpp
@@ -1473,19 +1473,26 @@ struct dpf_plugin_view : v3_plugin_view_cpp {
view->sizeRequestedBeforeBeingAttached = true;
- const float lastScaleFactor = view->scale != nullptr ? view->scale->scaleFactor : 0.0f;
+ double scaleFactor = view->scale != nullptr ? view->scale->scaleFactor : 0.0;
+ #if defined(DISTRHO_UI_DEFAULT_WIDTH) && defined(DISTRHO_UI_DEFAULT_HEIGHT)
+ rect->right = DISTRHO_UI_DEFAULT_WIDTH;
+ rect->bottom = DISTRHO_UI_DEFAULT_HEIGHT;
+ if (d_isZero(scaleFactor))
+ scaleFactor = 1.0;
+ #else
UIExporter tmpUI(nullptr, 0, view->sampleRate,
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, d_nextBundlePath,
- view->instancePointer, lastScaleFactor);
- rect->left = rect->top = 0;
- rect->right = tmpUI.getWidth();
+ view->instancePointer, scaleFactor);
+ rect->right = tmpUI.getWidth();
rect->bottom = tmpUI.getHeight();
+ scaleFactor = tmpUI.getScaleFactor();
+ tmpUI.quit();
+ #endif
+ rect->left = rect->top = 0;
#ifdef DISTRHO_OS_MAC
- const double scaleFactor = tmpUI.getScaleFactor();
rect->right /= scaleFactor;
rect->bottom /= scaleFactor;
#endif
- tmpUI.quit();
return V3_OK;
}