diff --git a/distrho/DistrhoUI.hpp b/distrho/DistrhoUI.hpp index eb3562b4..debbff14 100644 --- a/distrho/DistrhoUI.hpp +++ b/distrho/DistrhoUI.hpp @@ -20,7 +20,10 @@ #include "extra/LeakDetector.hpp" #include "src/DistrhoPluginChecks.h" -#if DISTRHO_UI_USE_NANOVG +#ifndef HAVE_DGL +# include "extra/ExternalWindow.hpp" +typedef DISTRHO_NAMESPACE::ExternalWindow UIWidget; +#elif DISTRHO_UI_USE_NANOVG # include "../dgl/NanoVG.hpp" typedef DGL::NanoWidget UIWidget; #else diff --git a/distrho/extra/Base64.hpp b/distrho/extra/Base64.hpp index b1cce48d..da661c17 100644 --- a/distrho/extra/Base64.hpp +++ b/distrho/extra/Base64.hpp @@ -1,6 +1,6 @@ /* * DISTRHO Plugin Framework (DPF) - * Copyright (C) 2012-2015 Filipe Coelho + * Copyright (C) 2012-2016 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 @@ -24,7 +24,30 @@ // ----------------------------------------------------------------------- // base64 stuff, based on http://www.adp-gmbh.ch/cpp/common/base64.html -// Copyright (C) 2004-2008 René Nyffenegger + +/* + Copyright (C) 2004-2008 René Nyffenegger + + This source code is provided 'as-is', without any express or implied + warranty. In no event will the author be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this source code must not be misrepresented; you must not + claim that you wrote the original source code. If you use this source code + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original source code. + + 3. This notice may not be removed or altered from any source distribution. + + René Nyffenegger rene.nyffenegger@adp-gmbh.ch +*/ // ----------------------------------------------------------------------- // Helpers diff --git a/distrho/extra/ExternalWindow.hpp b/distrho/extra/ExternalWindow.hpp new file mode 100644 index 00000000..1fe0a06f --- /dev/null +++ b/distrho/extra/ExternalWindow.hpp @@ -0,0 +1,63 @@ +/* + * DISTRHO Plugin Framework (DPF) + * Copyright (C) 2012-2016 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 + * permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD + * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN + * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL + * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER + * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef DISTRHO_EXTERNAL_WINDOW_HPP_INCLUDED +#define DISTRHO_EXTERNAL_WINDOW_HPP_INCLUDED + +#include "../DistrhoUtils.hpp" + +START_NAMESPACE_DISTRHO + +// ----------------------------------------------------------------------- +// ExternalWindow class + +class ExternalWindow +{ +public: + ExternalWindow(const uint w = 1, const uint h = 1) + : width(w), + height(h) {} + + uint getWidth() const noexcept + { + return width; + } + + uint getHeight() const noexcept + { + return height; + } + + void setSize(const uint w, const uint h) noexcept + { + DISTRHO_SAFE_ASSERT_RETURN(w > 0 && h > 0,) + + width = w; + height = h; + } + +private: + uint width; + uint height; + + DISTRHO_DECLARE_NON_COPY_CLASS(ExternalWindow) +}; + +// ----------------------------------------------------------------------- + +END_NAMESPACE_DISTRHO + +#endif // DISTRHO_EXTERNAL_WINDOW_HPP_INCLUDED diff --git a/distrho/src/DistrhoUI.cpp b/distrho/src/DistrhoUI.cpp index a49fab72..aa209679 100644 --- a/distrho/src/DistrhoUI.cpp +++ b/distrho/src/DistrhoUI.cpp @@ -35,17 +35,21 @@ uintptr_t g_nextWindowId = 0; /* ------------------------------------------------------------------------------------------------------------ * UI */ +#ifdef HAVE_DGL UI::UI(uint width, uint height) : UIWidget(*d_lastUiWindow), pData(new PrivateData()) { -#ifdef HAVE_DGL ((UIWidget*)this)->pData->needsFullViewport = false; -#endif if (width > 0 && height > 0) setSize(width, height); } +#else +UI::UI(uint width, uint height) + : UIWidget(width, height), + pData(new PrivateData()) {} +#endif UI::~UI() { diff --git a/distrho/src/DistrhoUIInternal.hpp b/distrho/src/DistrhoUIInternal.hpp index 23af37c8..d4394559 100644 --- a/distrho/src/DistrhoUIInternal.hpp +++ b/distrho/src/DistrhoUIInternal.hpp @@ -1,6 +1,6 @@ /* * DISTRHO Plugin Framework (DPF) - * Copyright (C) 2012-2015 Filipe Coelho + * Copyright (C) 2012-2016 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 @@ -18,12 +18,14 @@ #define DISTRHO_UI_INTERNAL_HPP_INCLUDED #include "../DistrhoUI.hpp" -#include "../../dgl/Application.hpp" -#include "../../dgl/Window.hpp" +#ifdef HAVE_DGL +# include "../../dgl/Application.hpp" +# include "../../dgl/Window.hpp" using DGL::Application; using DGL::IdleCallback; using DGL::Window; +#endif START_NAMESPACE_DISTRHO @@ -131,6 +133,7 @@ struct UI::PrivateData { // ----------------------------------------------------------------------- // Plugin Window, needed to take care of resize properly +#ifdef HAVE_DGL static inline UI* createUiWrapper(void* const dspPtr, Window* const window) { @@ -194,6 +197,18 @@ private: UI* const fUI; bool fIsReady; }; +#else +static inline +UI* createUiWrapper(void* const dspPtr, const uintptr_t winId) +{ + d_lastUiDspPtr = dspPtr; + g_nextWindowId = winId; + UI* const ret = createUI(); + d_lastUiDspPtr = nullptr; + g_nextWindowId = 0; + return ret; +} +#endif // ----------------------------------------------------------------------- // UI exporter class @@ -204,10 +219,14 @@ public: UIExporter(void* const ptr, const intptr_t winId, const editParamFunc editParamCall, const setParamFunc setParamCall, const setStateFunc setStateCall, const sendNoteFunc sendNoteCall, const setSizeFunc setSizeCall, void* const dspPtr = nullptr) +#ifdef HAVE_DGL : glApp(), glWindow(glApp, winId, dspPtr), fChangingSize(false), fUI(glWindow.getUI()), +#else + : fUI(createUiWrapper(dspPtr, winId)), +#endif fData((fUI != nullptr) ? fUI->pData : nullptr) { DISTRHO_SAFE_ASSERT_RETURN(fUI != nullptr,); @@ -225,24 +244,42 @@ public: uint getWidth() const noexcept { +#ifdef HAVE_DGL return glWindow.getWidth(); +#else + DISTRHO_SAFE_ASSERT_RETURN(fUI != nullptr, 1); + return fUI->getWidth(); +#endif } uint getHeight() const noexcept { +#ifdef HAVE_DGL return glWindow.getHeight(); +#else + DISTRHO_SAFE_ASSERT_RETURN(fUI != nullptr, 1); + return fUI->getHeight(); +#endif } bool isVisible() const noexcept { +#ifdef HAVE_DGL return glWindow.isVisible(); +#else + return true; +#endif } // ------------------------------------------------------------------- intptr_t getWindowId() const noexcept { +#ifdef HAVE_DGL return glWindow.getWindowId(); +#else + return 0; +#endif } // ------------------------------------------------------------------- @@ -285,6 +322,7 @@ public: // ------------------------------------------------------------------- +#ifdef HAVE_DGL void exec(IdleCallback* const cb) { DISTRHO_SAFE_ASSERT_RETURN(cb != nullptr,); @@ -352,6 +390,14 @@ public: return ! glApp.isQuiting(); } +#else + bool idle() { return true; } + void quit() {} + void setWindowSize(const uint width, const uint height, const bool updateUI = false) {} + void setWindowTitle(const char* const uiTitle) {} + void setWindowTransientWinId(const uintptr_t winId) {} + bool setWindowVisible(const bool yesNo) { return true; } +#endif // ------------------------------------------------------------------- @@ -371,6 +417,7 @@ public: } private: +#ifdef HAVE_DGL // ------------------------------------------------------------------- // DGL Application and Window for this widget @@ -379,6 +426,7 @@ private: // prevent recursion bool fChangingSize; +#endif // ------------------------------------------------------------------- // Widget and DistrhoUI data