From d1f8cd904eec3aa36093d2933165622b901a5b8b Mon Sep 17 00:00:00 2001 From: falkTX Date: Sun, 25 May 2014 21:56:05 +0100 Subject: [PATCH] Misc fixing; Add DISTRHO_UI_USE_NANOVG macro, for NanoVG plugin UIs --- dgl/ImageSlider.hpp | 1 + dgl/NanoVG.hpp | 5 +++-- dgl/StandaloneWindow.hpp | 10 ++++++++-- dgl/Widget.hpp | 14 ++++++++------ dgl/src/ImageSlider.cpp | 6 +++--- dgl/src/Widget.cpp | 10 +++++----- distrho/DistrhoUI.hpp | 16 +++++++++++++++- distrho/src/DistrhoPluginChecks.h | 4 ++++ distrho/src/DistrhoUI.cpp | 4 +++- 9 files changed, 50 insertions(+), 20 deletions(-) diff --git a/dgl/ImageSlider.hpp b/dgl/ImageSlider.hpp index 0da8bd7d..d53edde5 100644 --- a/dgl/ImageSlider.hpp +++ b/dgl/ImageSlider.hpp @@ -89,6 +89,7 @@ private: void setAbsoluteY(int) const noexcept {} void setAbsolutePos(int, int) const noexcept {} void setAbsolutePos(const Point&) const noexcept {} + void setNeedsFullViewport(bool) const noexcept {} DISTRHO_LEAK_DETECTOR(ImageSlider) }; diff --git a/dgl/NanoVG.hpp b/dgl/NanoVG.hpp index 12f08434..f3b1b1de 100644 --- a/dgl/NanoVG.hpp +++ b/dgl/NanoVG.hpp @@ -770,7 +770,7 @@ public: int textBreakLines(const char* string, const char* end, float breakRowWidth, TextRow* rows, int maxRows); private: - NVGcontext* fContext; + NVGcontext* const fContext; DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(NanoVG) }; @@ -782,7 +782,8 @@ private: NanoVG Widget class. This class implements the NanoVG drawing API inside a DGL Widget. - onDisplay is implemented internally. + The drawing function onDisplay() is implemented internally but a + new onNanoDisplay() needs to be overridden instead. */ class NanoWidget : public Widget, public NanoVG diff --git a/dgl/StandaloneWindow.hpp b/dgl/StandaloneWindow.hpp index fefa5ab5..05a71854 100644 --- a/dgl/StandaloneWindow.hpp +++ b/dgl/StandaloneWindow.hpp @@ -51,17 +51,23 @@ protected: private: Widget* fWidget; - void _addWidget(Widget* const widget) override + void _addWidget(Widget* widget) override { if (fWidget == nullptr) + { fWidget = widget; + fWidget->setNeedsFullViewport(true); + } Window::_addWidget(widget); } - void _removeWidget(Widget* const widget) override + void _removeWidget(Widget* widget) override { if (fWidget == widget) + { + fWidget->setNeedsFullViewport(false); fWidget = nullptr; + } Window::_removeWidget(widget); } diff --git a/dgl/Widget.hpp b/dgl/Widget.hpp index c98dba00..5d112aa1 100644 --- a/dgl/Widget.hpp +++ b/dgl/Widget.hpp @@ -159,12 +159,6 @@ public: */ void hide(); - /** - Tell the parent window this widget this the full viewport. - When enabled, the local widget coordinates are ignored. - */ - void setNeedsFullViewport(bool yesNo) noexcept; - /** Get width. */ @@ -302,6 +296,14 @@ protected: */ virtual void onResize(const ResizeEvent&); + /** + Tell the parent window this widget this the full viewport. + When enabled, the local widget coordinates are ignored. + @note: This is an internal function; + You do not need it under normal circumstances. + */ + void setNeedsFullViewport(bool yesNo) noexcept; + private: Window& fParent; bool fNeedsFullViewport; diff --git a/dgl/src/ImageSlider.cpp b/dgl/src/ImageSlider.cpp index 89665e9b..f6a9f497 100644 --- a/dgl/src/ImageSlider.cpp +++ b/dgl/src/ImageSlider.cpp @@ -37,7 +37,7 @@ ImageSlider::ImageSlider(Window& parent, const Image& image, int id) noexcept fStartedY(0), fCallback(nullptr) { - setNeedsFullViewport(true); + Widget::setNeedsFullViewport(true); } ImageSlider::ImageSlider(Widget* widget, const Image& image, int id) noexcept @@ -55,7 +55,7 @@ ImageSlider::ImageSlider(Widget* widget, const Image& image, int id) noexcept fStartedY(0), fCallback(nullptr) { - setNeedsFullViewport(true); + Widget::setNeedsFullViewport(true); } ImageSlider::ImageSlider(const ImageSlider& imageSlider) noexcept @@ -76,7 +76,7 @@ ImageSlider::ImageSlider(const ImageSlider& imageSlider) noexcept fEndPos(imageSlider.fEndPos), fSliderArea(imageSlider.fSliderArea) { - setNeedsFullViewport(true); + Widget::setNeedsFullViewport(true); } int ImageSlider::getId() const noexcept diff --git a/dgl/src/Widget.cpp b/dgl/src/Widget.cpp index d58893d9..aee727b8 100644 --- a/dgl/src/Widget.cpp +++ b/dgl/src/Widget.cpp @@ -59,11 +59,6 @@ void Widget::hide() setVisible(false); } -void Widget::setNeedsFullViewport(bool yesNo) noexcept -{ - fNeedsFullViewport = yesNo; -} - int Widget::getWidth() const noexcept { return fArea.getWidth(); @@ -230,6 +225,11 @@ void Widget::onResize(const ResizeEvent&) { } +void Widget::setNeedsFullViewport(bool yesNo) noexcept +{ + fNeedsFullViewport = yesNo; +} + // ----------------------------------------------------------------------- END_NAMESPACE_DGL diff --git a/distrho/DistrhoUI.hpp b/distrho/DistrhoUI.hpp index 0448213a..98af2a01 100644 --- a/distrho/DistrhoUI.hpp +++ b/distrho/DistrhoUI.hpp @@ -22,12 +22,19 @@ #include "../dgl/Widget.hpp" +#if DISTRHO_UI_USE_NANOVG +# include "../dgl/NanoVG.hpp" +typedef DGL::NanoWidget UIWidget; +#else +typedef DGL::Widget UIWidget; +#endif + START_NAMESPACE_DISTRHO // ----------------------------------------------------------------------- // UI -class UI : public DGL::Widget +class UI : public UIWidget { public: UI(); @@ -91,6 +98,13 @@ private: friend class UIExporter; friend class UIExporterWindow; + // these should not be used + void setAbsoluteX(int) const noexcept {} + void setAbsoluteY(int) const noexcept {} + void setAbsolutePos(int, int) const noexcept {} + void setAbsolutePos(const DGL::Point&) const noexcept {} + void setNeedsFullViewport(bool) const noexcept {} + DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(UI) }; diff --git a/distrho/src/DistrhoPluginChecks.h b/distrho/src/DistrhoPluginChecks.h index a9073017..3a06ee42 100644 --- a/distrho/src/DistrhoPluginChecks.h +++ b/distrho/src/DistrhoPluginChecks.h @@ -63,6 +63,10 @@ # define DISTRHO_PLUGIN_IS_RT_SAFE 1 #endif +#ifndef DISTRHO_UI_USE_NANOVG +# define DISTRHO_UI_USE_NANOVG 0 +#endif + #define DISTRHO_UI_URI DISTRHO_PLUGIN_URI "#UI" #endif // DISTRHO_PLUGIN_CHECKS_H_INCLUDED diff --git a/distrho/src/DistrhoUI.cpp b/distrho/src/DistrhoUI.cpp index a91fe0e2..a2e0368e 100644 --- a/distrho/src/DistrhoUI.cpp +++ b/distrho/src/DistrhoUI.cpp @@ -31,12 +31,14 @@ double d_lastUiSampleRate = 0.0; // UI UI::UI() - : DGL::Widget(*DGL::dgl_lastUiParent), + : UIWidget(*DGL::dgl_lastUiParent), pData(new PrivateData()) { DISTRHO_SAFE_ASSERT(DGL::dgl_lastUiParent != nullptr); DGL::dgl_lastUiParent = nullptr; + + Widget::setNeedsFullViewport(true); } UI::~UI()