From 1623dd7b853b96c3d13a7f8c0872615336ea7edd Mon Sep 17 00:00:00 2001 From: falkTX Date: Wed, 27 Feb 2019 13:34:02 +0100 Subject: [PATCH] Introduce DISTRHO_UI_USER_RESIZABLE macro, remove runtime checks Signed-off-by: falkTX --- dgl/Window.hpp | 4 ++-- dgl/src/Window.cpp | 10 +++++----- distrho/DistrhoInfo.hpp | 10 +++++++++- distrho/DistrhoUI.hpp | 10 ++-------- distrho/src/DistrhoPluginChecks.h | 6 +++++- distrho/src/DistrhoPluginLV2export.cpp | 20 +++++++++++++++----- distrho/src/DistrhoUI.cpp | 15 +++++---------- distrho/src/DistrhoUIInternal.hpp | 9 +++------ examples/ExternalUI/ExternalExampleUI.cpp | 4 ++-- examples/Info/DistrhoPluginInfo.h | 3 ++- examples/Info/InfoExampleUI.cpp | 4 ++-- examples/Meters/DistrhoPluginInfo.h | 3 ++- examples/Meters/ExampleUIMeters.cpp | 4 ++-- 13 files changed, 56 insertions(+), 46 deletions(-) diff --git a/dgl/Window.hpp b/dgl/Window.hpp index bc686c2c..465bb1cb 100644 --- a/dgl/Window.hpp +++ b/dgl/Window.hpp @@ -1,6 +1,6 @@ /* * DISTRHO Plugin Framework (DPF) - * Copyright (C) 2012-2016 Filipe Coelho + * Copyright (C) 2012-2019 Filipe Coelho * * Permission to use, copy, modify, and/or distribute this software for any purpose with * or without fee is hereby granted, provided that the above copyright notice and this @@ -77,7 +77,7 @@ public: explicit Window(Application& app); explicit Window(Application& app, Window& parent); - explicit Window(Application& app, intptr_t parentId); + explicit Window(Application& app, intptr_t parentId, bool resizable); virtual ~Window(); void show(); diff --git a/dgl/src/Window.cpp b/dgl/src/Window.cpp index d155f3b4..47b2e458 100644 --- a/dgl/src/Window.cpp +++ b/dgl/src/Window.cpp @@ -1,6 +1,6 @@ /* * DISTRHO Plugin Framework (DPF) - * Copyright (C) 2012-2018 Filipe Coelho + * Copyright (C) 2012-2019 Filipe Coelho * * Permission to use, copy, modify, and/or distribute this software for any purpose with * or without fee is hereby granted, provided that the above copyright notice and this @@ -147,13 +147,13 @@ struct Window::PrivateData { #endif } - PrivateData(Application& app, Window* const self, const intptr_t parentId) + PrivateData(Application& app, Window* const self, const intptr_t parentId, const bool resizable) : fApp(app), fSelf(self), fView(puglInit()), fFirstInit(true), fVisible(parentId != 0), - fResizable(parentId == 0), + fResizable(resizable), fUsingEmbed(parentId != 0), fWidth(1), fHeight(1), @@ -1155,8 +1155,8 @@ Window::Window(Application& app) Window::Window(Application& app, Window& parent) : pData(new PrivateData(app, this, parent)) {} -Window::Window(Application& app, intptr_t parentId) - : pData(new PrivateData(app, this, parentId)) {} +Window::Window(Application& app, intptr_t parentId, bool resizable) + : pData(new PrivateData(app, this, parentId, resizable)) {} Window::~Window() { diff --git a/distrho/DistrhoInfo.hpp b/distrho/DistrhoInfo.hpp index 7a4661e4..b38976f1 100644 --- a/distrho/DistrhoInfo.hpp +++ b/distrho/DistrhoInfo.hpp @@ -1,6 +1,6 @@ /* * DISTRHO Plugin Framework (DPF) - * Copyright (C) 2012-2016 Filipe Coelho + * Copyright (C) 2012-2019 Filipe Coelho * * Permission to use, copy, modify, and/or distribute this software for any purpose with * or without fee is hereby granted, provided that the above copyright notice and this @@ -555,6 +555,14 @@ START_NAMESPACE_DISTRHO */ #define DISTRHO_UI_USE_NANOVG 1 +/** + Wherever the %UI is resizable to any size by the user.@n + By default this is false, and resizing is only allowed under the plugin UI control,@n + Enabling this options makes it possible for the user to resize the plugin UI at anytime. + @see UI::setGeometryConstraints(uint, uint, bool, bool) + */ +#define DISTRHO_UI_USER_RESIZABLE 1 + /** The %UI URI when exporting in LV2 format.@n By default this is set to @ref DISTRHO_PLUGIN_URI with "#UI" as suffix. diff --git a/distrho/DistrhoUI.hpp b/distrho/DistrhoUI.hpp index 244b25bc..0fa45b20 100644 --- a/distrho/DistrhoUI.hpp +++ b/distrho/DistrhoUI.hpp @@ -1,6 +1,6 @@ /* * DISTRHO Plugin Framework (DPF) - * Copyright (C) 2012-2018 Filipe Coelho + * Copyright (C) 2012-2019 Filipe Coelho * * Permission to use, copy, modify, and/or distribute this software for any purpose with * or without fee is hereby granted, provided that the above copyright notice and this @@ -55,19 +55,13 @@ public: UI class constructor. The UI should be initialized to a default state that matches the plugin side. */ - UI(uint width = 0, uint height = 0, bool userResizable = false); + UI(uint width = 0, uint height = 0); /** Destructor. */ virtual ~UI(); - /** - Wherever this UI is resizable by the user. - This simply returns the value passed in the constructor. - */ - bool isUserResizable() const noexcept; - #if !DISTRHO_PLUGIN_HAS_EXTERNAL_UI /** Set geometry constraints for the UI when resized by the user, and optionally scale UI automatically. diff --git a/distrho/src/DistrhoPluginChecks.h b/distrho/src/DistrhoPluginChecks.h index 24f25d8e..2c543b17 100644 --- a/distrho/src/DistrhoPluginChecks.h +++ b/distrho/src/DistrhoPluginChecks.h @@ -1,6 +1,6 @@ /* * DISTRHO Plugin Framework (DPF) - * Copyright (C) 2012-2016 Filipe Coelho + * Copyright (C) 2012-2019 Filipe Coelho * * Permission to use, copy, modify, and/or distribute this software for any purpose with * or without fee is hereby granted, provided that the above copyright notice and this @@ -85,6 +85,10 @@ # define DISTRHO_PLUGIN_WANT_TIMEPOS 0 #endif +#ifndef DISTRHO_UI_USER_RESIZABLE +# define DISTRHO_UI_USER_RESIZABLE 0 +#endif + #ifndef DISTRHO_UI_USE_NANOVG # define DISTRHO_UI_USE_NANOVG 0 #endif diff --git a/distrho/src/DistrhoPluginLV2export.cpp b/distrho/src/DistrhoPluginLV2export.cpp index 9d2c7a7d..4a27f787 100644 --- a/distrho/src/DistrhoPluginLV2export.cpp +++ b/distrho/src/DistrhoPluginLV2export.cpp @@ -1,6 +1,6 @@ /* * DISTRHO Plugin Framework (DPF) - * Copyright (C) 2012-2018 Filipe Coelho + * Copyright (C) 2012-2019 Filipe Coelho * * Permission to use, copy, modify, and/or distribute this software for any purpose with * or without fee is hereby granted, provided that the above copyright notice and this @@ -139,12 +139,17 @@ void lv2_generate_ttl(const char* const basename) # endif manifestString += "\n"; # if DISTRHO_PLUGIN_HAS_EMBED_UI - // TODO: pluginUI.isUserResizable() +# if DISTRHO_UI_USER_RESIZABLE + manifestString += " lv2:optionalFeature ui:resize ,\n"; + manifestString += " ui:touch ;\n"; + manifestString += "\n"; +# else // DISTRHO_UI_USER_RESIZABLE manifestString += " lv2:optionalFeature ui:noUserResize ,\n"; manifestString += " ui:resize ,\n"; manifestString += " ui:touch ;\n"; manifestString += "\n"; -# endif +# endif // DISTRHO_UI_USER_RESIZABLE +# endif // DISTRHO_PLUGIN_HAS_EMBED_UI manifestString += " lv2:requiredFeature <" LV2_DATA_ACCESS_URI "> ,\n"; manifestString += " <" LV2_INSTANCE_ACCESS_URI "> ,\n"; manifestString += " <" LV2_OPTIONS__options "> ,\n"; @@ -630,12 +635,17 @@ void lv2_generate_ttl(const char* const basename) # endif uiString += "\n"; # if DISTRHO_PLUGIN_HAS_EMBED_UI - // TODO: pluginUI.isUserResizable() +# if DISTRHO_UI_USER_RESIZABLE + uiString += " lv2:optionalFeature ui:resize ,\n"; + uiString += " ui:touch ;\n"; + uiString += "\n"; +# else // DISTRHO_UI_USER_RESIZABLE uiString += " lv2:optionalFeature ui:noUserResize ,\n"; uiString += " ui:resize ,\n"; uiString += " ui:touch ;\n"; uiString += "\n"; -# endif +# endif // DISTRHO_UI_USER_RESIZABLE +# endif // DISTRHO_PLUGIN_HAS_EMBED_UI uiString += " lv2:requiredFeature <" LV2_OPTIONS__options "> ,\n"; uiString += " <" LV2_URID__map "> ;\n"; diff --git a/distrho/src/DistrhoUI.cpp b/distrho/src/DistrhoUI.cpp index a9502161..4170c82b 100644 --- a/distrho/src/DistrhoUI.cpp +++ b/distrho/src/DistrhoUI.cpp @@ -1,6 +1,6 @@ /* * DISTRHO Plugin Framework (DPF) - * Copyright (C) 2012-2018 Filipe Coelho + * Copyright (C) 2012-2019 Filipe Coelho * * Permission to use, copy, modify, and/or distribute this software for any purpose with * or without fee is hereby granted, provided that the above copyright notice and this @@ -37,13 +37,13 @@ Window* d_lastUiWindow = nullptr; * UI */ #if DISTRHO_PLUGIN_HAS_EXTERNAL_UI -UI::UI(uint width, uint height, bool userResizable) +UI::UI(uint width, uint height) : UIWidget(width, height), - pData(new PrivateData(userResizable)) {} + pData(new PrivateData()) {} #else -UI::UI(uint width, uint height, bool userResizable) +UI::UI(uint width, uint height) : UIWidget(*d_lastUiWindow), - pData(new PrivateData(userResizable)) + pData(new PrivateData()) { ((UIWidget*)this)->pData->needsFullViewport = false; @@ -57,11 +57,6 @@ UI::~UI() delete pData; } -bool UI::isUserResizable() const noexcept -{ - return pData->userResizable; -} - #if !DISTRHO_PLUGIN_HAS_EXTERNAL_UI void UI::setGeometryConstraints(uint minWidth, uint minHeight, bool keepAspectRatio, bool automaticallyScale) { diff --git a/distrho/src/DistrhoUIInternal.hpp b/distrho/src/DistrhoUIInternal.hpp index 4ea26580..b81e1501 100644 --- a/distrho/src/DistrhoUIInternal.hpp +++ b/distrho/src/DistrhoUIInternal.hpp @@ -1,6 +1,6 @@ /* * DISTRHO Plugin Framework (DPF) - * Copyright (C) 2012-2018 Filipe Coelho + * Copyright (C) 2012-2019 Filipe Coelho * * Permission to use, copy, modify, and/or distribute this software for any purpose with * or without fee is hereby granted, provided that the above copyright notice and this @@ -64,7 +64,6 @@ struct UI::PrivateData { #endif // UI - const bool userResizable; bool automaticallyScale; bool resizeInProgress; uint minWidth; @@ -78,13 +77,12 @@ struct UI::PrivateData { sendNoteFunc sendNoteCallbackFunc; setSizeFunc setSizeCallbackFunc; - PrivateData(const bool resizable) noexcept + PrivateData() noexcept : sampleRate(d_lastUiSampleRate), parameterOffset(0), #if DISTRHO_PLUGIN_WANT_DIRECT_ACCESS dspPtr(d_lastUiDspPtr), #endif - userResizable(resizable), automaticallyScale(false), resizeInProgress(false), minWidth(0), @@ -178,14 +176,13 @@ class UIExporterWindow : public Window { public: UIExporterWindow(Application& app, const intptr_t winId, void* const dspPtr) - : Window(app, winId), + : Window(app, winId, DISTRHO_UI_USER_RESIZABLE), fUI(createUiWrapper(dspPtr, this)), fIsReady(false) { DISTRHO_SAFE_ASSERT_RETURN(fUI != nullptr,); DISTRHO_SAFE_ASSERT_RETURN(fUI->pData != nullptr,); - setResizable(fUI->pData->userResizable); setSize(fUI->getWidth(), fUI->getHeight()); } diff --git a/examples/ExternalUI/ExternalExampleUI.cpp b/examples/ExternalUI/ExternalExampleUI.cpp index 66cfc85b..bb5bf835 100644 --- a/examples/ExternalUI/ExternalExampleUI.cpp +++ b/examples/ExternalUI/ExternalExampleUI.cpp @@ -1,6 +1,6 @@ /* * DISTRHO Plugin Framework (DPF) - * Copyright (C) 2012-2018 Filipe Coelho + * Copyright (C) 2012-2019 Filipe Coelho * * Permission to use, copy, modify, and/or distribute this software for any purpose with * or without fee is hereby granted, provided that the above copyright notice and this @@ -61,7 +61,7 @@ class ExternalExampleUI : public UI { public: ExternalExampleUI() - : UI(405, 256, true), + : UI(405, 256), fFifo(-1), fValue(0.0f), fExternalScript(getNextBundlePath()) diff --git a/examples/Info/DistrhoPluginInfo.h b/examples/Info/DistrhoPluginInfo.h index 03e80b91..c10a3739 100644 --- a/examples/Info/DistrhoPluginInfo.h +++ b/examples/Info/DistrhoPluginInfo.h @@ -1,6 +1,6 @@ /* * DISTRHO Plugin Framework (DPF) - * Copyright (C) 2012-2015 Filipe Coelho + * Copyright (C) 2012-2019 Filipe Coelho * * Permission to use, copy, modify, and/or distribute this software for any purpose with * or without fee is hereby granted, provided that the above copyright notice and this @@ -26,6 +26,7 @@ #define DISTRHO_PLUGIN_NUM_INPUTS 2 #define DISTRHO_PLUGIN_NUM_OUTPUTS 2 #define DISTRHO_PLUGIN_WANT_TIMEPOS 1 +#define DISTRHO_UI_USER_RESIZABLE 1 #define DISTRHO_UI_USE_NANOVG 1 enum Parameters { diff --git a/examples/Info/InfoExampleUI.cpp b/examples/Info/InfoExampleUI.cpp index a86ba780..647fc4ca 100644 --- a/examples/Info/InfoExampleUI.cpp +++ b/examples/Info/InfoExampleUI.cpp @@ -1,6 +1,6 @@ /* * DISTRHO Plugin Framework (DPF) - * Copyright (C) 2012-2015 Filipe Coelho + * Copyright (C) 2012-2019 Filipe Coelho * * Permission to use, copy, modify, and/or distribute this software for any purpose with * or without fee is hereby granted, provided that the above copyright notice and this @@ -28,7 +28,7 @@ class InfoExampleUI : public UI { public: InfoExampleUI() - : UI(405, 256, true), + : UI(405, 256), fScale(1.0f) { std::memset(fParameters, 0, sizeof(float)*kParameterCount); diff --git a/examples/Meters/DistrhoPluginInfo.h b/examples/Meters/DistrhoPluginInfo.h index f00d09a3..9c101dba 100644 --- a/examples/Meters/DistrhoPluginInfo.h +++ b/examples/Meters/DistrhoPluginInfo.h @@ -1,6 +1,6 @@ /* * DISTRHO Plugin Framework (DPF) - * Copyright (C) 2012-2018 Filipe Coelho + * Copyright (C) 2012-2019 Filipe Coelho * * Permission to use, copy, modify, and/or distribute this software for any purpose with * or without fee is hereby granted, provided that the above copyright notice and this @@ -26,6 +26,7 @@ #define DISTRHO_PLUGIN_NUM_INPUTS 2 #define DISTRHO_PLUGIN_NUM_OUTPUTS 2 #define DISTRHO_PLUGIN_WANT_STATE 1 +#define DISTRHO_UI_USER_RESIZABLE 1 #define DISTRHO_UI_USE_NANOVG 1 #define METER_COLOR_GREEN 0 diff --git a/examples/Meters/ExampleUIMeters.cpp b/examples/Meters/ExampleUIMeters.cpp index 3aa952fe..8ee8c5ec 100644 --- a/examples/Meters/ExampleUIMeters.cpp +++ b/examples/Meters/ExampleUIMeters.cpp @@ -1,6 +1,6 @@ /* * DISTRHO Plugin Framework (DPF) - * Copyright (C) 2012-2018 Filipe Coelho + * Copyright (C) 2012-2019 Filipe Coelho * * Permission to use, copy, modify, and/or distribute this software for any purpose with * or without fee is hereby granted, provided that the above copyright notice and this @@ -34,7 +34,7 @@ class ExampleUIMeters : public UI { public: ExampleUIMeters() - : UI(128, 512, true), + : UI(128, 512), // default color is green fColor(93, 231, 61), // which is value 0