DPF

DISTRHO Plugin Framework
Log | Files | Refs | Submodules | README | LICENSE

commit 12061de4cadc1e04572adcafe8c6cbfdb23cdb5c
parent 8d66fbcd2666624a01efa5f90048d7d868064976
Author: falkTX <falktx@gmail.com>
Date:   Tue,  5 May 2015 13:26:53 +0200

App->Application; Use class namespace by default; Misc fixes

Diffstat:
Ddgl/App.hpp | 91-------------------------------------------------------------------------------
Adgl/Application.hpp | 91+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mdgl/Base.hpp | 72++++++++++++++++++++++++++++++++++++++++--------------------------------
Mdgl/ImageWidgets.hpp | 7++++---
Mdgl/Makefile | 2+-
Mdgl/StandaloneWindow.hpp | 10+++++-----
Mdgl/Widget.hpp | 4++--
Mdgl/Window.hpp | 12++++++------
Ddgl/src/App.cpp | 75---------------------------------------------------------------------------
Ddgl/src/AppPrivateData.hpp | 71-----------------------------------------------------------------------
Adgl/src/Application.cpp | 75+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Adgl/src/ApplicationPrivateData.hpp | 71+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mdgl/src/ImageWidgets.cpp | 100+++++++++++++++++++++++++------------------------------------------------------
Mdgl/src/Widget.cpp | 2+-
Mdgl/src/Window.cpp | 30++++++++++++++++--------------
Mdistrho/DistrhoUtils.hpp | 9+++++++++
16 files changed, 353 insertions(+), 369 deletions(-)

diff --git a/dgl/App.hpp b/dgl/App.hpp @@ -1,91 +0,0 @@ -/* - * DISTRHO Plugin Framework (DPF) - * Copyright (C) 2012-2015 Filipe Coelho <falktx@falktx.com> - * - * 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 DGL_APP_HPP_INCLUDED -#define DGL_APP_HPP_INCLUDED - -#include "Base.hpp" - -START_NAMESPACE_DGL - -// ----------------------------------------------------------------------- -// Forward class names - -class Window; - -// ----------------------------------------------------------------------- - -/** - Base DGL Application class. - - One application instance is required for creating a window. - There's no single/global application instance in DGL, and multiple - windows can share the same app instance. - - In standalone mode an application will automatically quit its - event-loop when all its windows are closed. - */ -class App -{ -public: - /** - Constructor. - */ - App(); - - /** - Destructor. - */ - ~App(); - - /** - Idle function. - This runs the application event-loop once. - */ - void idle(); - - /** - Run the application event-loop until all Windows are closed. - idle() is called at regular intervals. - @note This function is meant for standalones only, *never* call this from plugins. - */ - void exec(); - - /** - Quit the application. - This stops the event-loop and closes all Windows. - */ - void quit(); - - /** - Check if the application is about to quit. - Returning true means there's no event-loop running at the moment (or it's just about to stop). - */ - bool isQuiting() const noexcept; - -private: - struct PrivateData; - PrivateData* const pData; - friend class Window; - - DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(App) -}; - -// ----------------------------------------------------------------------- - -END_NAMESPACE_DGL - -#endif // DGL_APP_HPP_INCLUDED diff --git a/dgl/Application.hpp b/dgl/Application.hpp @@ -0,0 +1,91 @@ +/* + * DISTRHO Plugin Framework (DPF) + * Copyright (C) 2012-2015 Filipe Coelho <falktx@falktx.com> + * + * 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 DGL_APP_HPP_INCLUDED +#define DGL_APP_HPP_INCLUDED + +#include "Base.hpp" + +START_NAMESPACE_DGL + +// ----------------------------------------------------------------------- +// Forward class names + +class Window; + +// ----------------------------------------------------------------------- + +/** + Base DGL Application class. + + One application instance is required for creating a window. + There's no single/global application instance in DGL, and multiple + windows can share the same app instance. + + In standalone mode an application will automatically quit its + event-loop when all its windows are closed. + */ +class Application +{ +public: + /** + Constructor. + */ + Application(); + + /** + Destructor. + */ + ~Application(); + + /** + Idle function. + This runs the application event-loop once. + */ + void idle(); + + /** + Run the application event-loop until all Windows are closed. + idle() is called at regular intervals. + @note This function is meant for standalones only, *never* call this from plugins. + */ + void exec(); + + /** + Quit the application. + This stops the event-loop and closes all Windows. + */ + void quit(); + + /** + Check if the application is about to quit. + Returning true means there's no event-loop running at the moment (or it's just about to stop). + */ + bool isQuiting() const noexcept; + +private: + struct PrivateData; + PrivateData* const pData; + friend class Window; + + DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(Application) +}; + +// ----------------------------------------------------------------------- + +END_NAMESPACE_DGL + +#endif // DGL_APP_HPP_INCLUDED diff --git a/dgl/Base.hpp b/dgl/Base.hpp @@ -121,50 +121,50 @@ START_NAMESPACE_DGL Convenience symbols for ASCII control characters. */ enum Char { - CHAR_BACKSPACE = 0x08, - CHAR_ESCAPE = 0x1B, - CHAR_DELETE = 0x7F + kCharBackspace = 0x08, + kCharEscape = 0x1B, + kCharDelete = 0x7F }; /** Keyboard modifier flags. */ enum Modifier { - MODIFIER_SHIFT = 1 << 0, /**< Shift key */ - MODIFIER_CTRL = 1 << 1, /**< Control key */ - MODIFIER_ALT = 1 << 2, /**< Alt/Option key */ - MODIFIER_SUPER = 1 << 3 /**< Mod4/Command/Windows key */ + kModifierShift = 1 << 0, /**< Shift key */ + kModifierControl = 1 << 1, /**< Control key */ + kModifierAlt = 1 << 2, /**< Alt/Option key */ + kModifierSuper = 1 << 3 /**< Mod4/Command/Windows key */ }; /** Special (non-Unicode) keyboard keys. */ enum Key { - KEY_F1 = 1, - KEY_F2, - KEY_F3, - KEY_F4, - KEY_F5, - KEY_F6, - KEY_F7, - KEY_F8, - KEY_F9, - KEY_F10, - KEY_F11, - KEY_F12, - KEY_LEFT, - KEY_UP, - KEY_RIGHT, - KEY_DOWN, - KEY_PAGE_UP, - KEY_PAGE_DOWN, - KEY_HOME, - KEY_END, - KEY_INSERT, - KEY_SHIFT, - KEY_CTRL, - KEY_ALT, - KEY_SUPER + kKeyF1 = 1, + kKeyF2, + kKeyF3, + kKeyF4, + kKeyF5, + kKeyF6, + kKeyF7, + kKeyF8, + kKeyF9, + kKeyF10, + kKeyF11, + kKeyF12, + kKeyLeft, + kKeyUp, + kKeyRight, + kKeyDown, + kKeyPageUp, + kKeyPageDown, + kKeyHome, + kKeyEnd, + kKeyInsert, + kKeyShift, + kKeyControl, + kKeyAlt, + kKeySuper }; // ----------------------------------------------------------------------- @@ -184,4 +184,12 @@ public: END_NAMESPACE_DGL +#ifndef DONT_SET_USING_DGL_NAMESPACE + // If your code uses a lot of DGL classes, then this will obviously save you + // a lot of typing, but can be disabled by setting DONT_SET_USING_DGL_NAMESPACE. + using namespace DGL_NAMESPACE; +#endif + +// ----------------------------------------------------------------------- + #endif // DGL_BASE_HPP_INCLUDED diff --git a/dgl/ImageWidgets.hpp b/dgl/ImageWidgets.hpp @@ -164,6 +164,8 @@ private: // ----------------------------------------------------------------------- +// note set range and step before setting the value + class ImageSlider : public Widget { public: @@ -178,10 +180,9 @@ public: explicit ImageSlider(Window& parent, const Image& image) noexcept; explicit ImageSlider(Widget* widget, const Image& image) noexcept; - explicit ImageSlider(const ImageSlider& imageSlider) noexcept; - ImageSlider& operator=(const ImageSlider& imageSlider) noexcept; float getValue() const noexcept; + void setValue(float value, bool sendCallback = false) noexcept; void setStartPos(const Point<int>& startPos) noexcept; void setStartPos(int x, int y) noexcept; @@ -191,7 +192,6 @@ public: void setInverted(bool inverted) noexcept; void setRange(float min, float max) noexcept; void setStep(float step) noexcept; - void setValue(float value, bool sendCallback = false) noexcept; void setCallback(Callback* callback) noexcept; @@ -210,6 +210,7 @@ private: bool fDragging; bool fInverted; + bool fValueIsSet; int fStartedX; int fStartedY; diff --git a/dgl/Makefile b/dgl/Makefile @@ -15,7 +15,7 @@ LINK_FLAGS += $(DGL_LIBS) # -------------------------------------------------------------- OBJS = \ - src/App.cpp.o \ + src/Application.cpp.o \ src/Color.cpp.o \ src/Geometry.cpp.o \ src/Image.cpp.o \ diff --git a/dgl/StandaloneWindow.hpp b/dgl/StandaloneWindow.hpp @@ -17,7 +17,7 @@ #ifndef DGL_STANDALONE_WINDOW_HPP_INCLUDED #define DGL_STANDALONE_WINDOW_HPP_INCLUDED -#include "App.hpp" +#include "Application.hpp" #include "Widget.hpp" #include "Window.hpp" @@ -25,19 +25,19 @@ START_NAMESPACE_DGL // ----------------------------------------------------------------------- -class StandaloneWindow : public App, +class StandaloneWindow : public Application, public Window { public: StandaloneWindow() - : App(), - Window((App&)*this), + : Application(), + Window((Application&)*this), fWidget(nullptr) {} void exec() { Window::show(); - App::exec(); + Application::exec(); } protected: diff --git a/dgl/Widget.hpp b/dgl/Widget.hpp @@ -30,7 +30,7 @@ END_NAMESPACE_DISTRHO START_NAMESPACE_DGL -class App; +class Application; class ImageSlider; class NanoWidget; class Window; @@ -287,7 +287,7 @@ public: Get this widget's window application. Same as calling getParentWindow().getApp(). */ - App& getParentApp() const noexcept; + Application& getParentApp() const noexcept; /** Get parent window, as passed in the constructor. diff --git a/dgl/Window.hpp b/dgl/Window.hpp @@ -23,7 +23,7 @@ START_NAMESPACE_DGL // ----------------------------------------------------------------------- -class App; +class Application; class Widget; class StandaloneWindow; @@ -67,9 +67,9 @@ public: buttons() {} }; - explicit Window(App& app); - explicit Window(App& app, Window& parent); - explicit Window(App& app, intptr_t parentId); + explicit Window(Application& app); + explicit Window(Application& app, Window& parent); + explicit Window(Application& app, intptr_t parentId); virtual ~Window(); void show(); @@ -99,7 +99,7 @@ public: void setTransientWinId(uintptr_t winId); - App& getApp() const noexcept; + Application& getApp() const noexcept; intptr_t getWindowId() const noexcept; void addIdleCallback(IdleCallback* const callback); @@ -116,7 +116,7 @@ protected: private: struct PrivateData; PrivateData* const pData; - friend class App; + friend class Application; friend class Widget; friend class StandaloneWindow; diff --git a/dgl/src/App.cpp b/dgl/src/App.cpp @@ -1,75 +0,0 @@ -/* - * DISTRHO Plugin Framework (DPF) - * Copyright (C) 2012-2015 Filipe Coelho <falktx@falktx.com> - * - * 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. - */ - -#include "AppPrivateData.hpp" -#include "../Window.hpp" - -START_NAMESPACE_DGL - -// ----------------------------------------------------------------------- - -App::App() - : pData(new PrivateData()), - leakDetector_App() {} - -App::~App() -{ - delete pData; -} - -void App::idle() -{ - for (std::list<Window*>::iterator it = pData->windows.begin(), ite = pData->windows.end(); it != ite; ++it) - { - Window* const window(*it); - window->_idle(); - } - - for (std::list<IdleCallback*>::iterator it = pData->idleCallbacks.begin(), ite = pData->idleCallbacks.end(); it != ite; ++it) - { - IdleCallback* const idleCallback(*it); - idleCallback->idleCallback(); - } -} - -void App::exec() -{ - for (; pData->doLoop;) - { - idle(); - d_msleep(10); - } -} - -void App::quit() -{ - pData->doLoop = false; - - for (std::list<Window*>::reverse_iterator rit = pData->windows.rbegin(), rite = pData->windows.rend(); rit != rite; ++rit) - { - Window* const window(*rit); - window->close(); - } -} - -bool App::isQuiting() const noexcept -{ - return !pData->doLoop; -} - -// ----------------------------------------------------------------------- - -END_NAMESPACE_DGL diff --git a/dgl/src/AppPrivateData.hpp b/dgl/src/AppPrivateData.hpp @@ -1,71 +0,0 @@ -/* - * DISTRHO Plugin Framework (DPF) - * Copyright (C) 2012-2015 Filipe Coelho <falktx@falktx.com> - * - * 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 DGL_APP_PRIVATE_DATA_HPP_INCLUDED -#define DGL_APP_PRIVATE_DATA_HPP_INCLUDED - -#include "../App.hpp" -#include "../../distrho/extra/Sleep.hpp" - -#include <list> - -START_NAMESPACE_DGL - -// ----------------------------------------------------------------------- - -struct App::PrivateData { - bool doLoop; - uint visibleWindows; - std::list<Window*> windows; - std::list<IdleCallback*> idleCallbacks; - - PrivateData() - : doLoop(true), - visibleWindows(0), - windows(), - idleCallbacks() {} - - ~PrivateData() - { - DISTRHO_SAFE_ASSERT(! doLoop); - DISTRHO_SAFE_ASSERT(visibleWindows == 0); - - windows.clear(); - idleCallbacks.clear(); - } - - void oneShown() noexcept - { - if (++visibleWindows == 1) - doLoop = true; - } - - void oneHidden() noexcept - { - DISTRHO_SAFE_ASSERT_RETURN(visibleWindows > 0,); - - if (--visibleWindows == 0) - doLoop = false; - } - - DISTRHO_DECLARE_NON_COPY_STRUCT(PrivateData) -}; - -// ----------------------------------------------------------------------- - -END_NAMESPACE_DGL - -#endif // DGL_APP_PRIVATE_DATA_HPP_INCLUDED diff --git a/dgl/src/Application.cpp b/dgl/src/Application.cpp @@ -0,0 +1,75 @@ +/* + * DISTRHO Plugin Framework (DPF) + * Copyright (C) 2012-2015 Filipe Coelho <falktx@falktx.com> + * + * 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. + */ + +#include "ApplicationPrivateData.hpp" +#include "../Window.hpp" + +START_NAMESPACE_DGL + +// ----------------------------------------------------------------------- + +Application::Application() + : pData(new PrivateData()), + leakDetector_Application() {} + +Application::~Application() +{ + delete pData; +} + +void Application::idle() +{ + for (std::list<Window*>::iterator it = pData->windows.begin(), ite = pData->windows.end(); it != ite; ++it) + { + Window* const window(*it); + window->_idle(); + } + + for (std::list<IdleCallback*>::iterator it = pData->idleCallbacks.begin(), ite = pData->idleCallbacks.end(); it != ite; ++it) + { + IdleCallback* const idleCallback(*it); + idleCallback->idleCallback(); + } +} + +void Application::exec() +{ + for (; pData->doLoop;) + { + idle(); + d_msleep(10); + } +} + +void Application::quit() +{ + pData->doLoop = false; + + for (std::list<Window*>::reverse_iterator rit = pData->windows.rbegin(), rite = pData->windows.rend(); rit != rite; ++rit) + { + Window* const window(*rit); + window->close(); + } +} + +bool Application::isQuiting() const noexcept +{ + return !pData->doLoop; +} + +// ----------------------------------------------------------------------- + +END_NAMESPACE_DGL diff --git a/dgl/src/ApplicationPrivateData.hpp b/dgl/src/ApplicationPrivateData.hpp @@ -0,0 +1,71 @@ +/* + * DISTRHO Plugin Framework (DPF) + * Copyright (C) 2012-2015 Filipe Coelho <falktx@falktx.com> + * + * 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 DGL_APP_PRIVATE_DATA_HPP_INCLUDED +#define DGL_APP_PRIVATE_DATA_HPP_INCLUDED + +#include "../Application.hpp" +#include "../../distrho/extra/Sleep.hpp" + +#include <list> + +START_NAMESPACE_DGL + +// ----------------------------------------------------------------------- + +struct Application::PrivateData { + bool doLoop; + uint visibleWindows; + std::list<Window*> windows; + std::list<IdleCallback*> idleCallbacks; + + PrivateData() + : doLoop(true), + visibleWindows(0), + windows(), + idleCallbacks() {} + + ~PrivateData() + { + DISTRHO_SAFE_ASSERT(! doLoop); + DISTRHO_SAFE_ASSERT(visibleWindows == 0); + + windows.clear(); + idleCallbacks.clear(); + } + + void oneShown() noexcept + { + if (++visibleWindows == 1) + doLoop = true; + } + + void oneHidden() noexcept + { + DISTRHO_SAFE_ASSERT_RETURN(visibleWindows > 0,); + + if (--visibleWindows == 0) + doLoop = false; + } + + DISTRHO_DECLARE_NON_COPY_STRUCT(PrivateData) +}; + +// ----------------------------------------------------------------------- + +END_NAMESPACE_DGL + +#endif // DGL_APP_PRIVATE_DATA_HPP_INCLUDED diff --git a/dgl/src/ImageWidgets.cpp b/dgl/src/ImageWidgets.cpp @@ -60,7 +60,7 @@ void ImageAboutWindow::onDisplay() bool ImageAboutWindow::onKeyboard(const KeyboardEvent& ev) { - if (ev.press && ev.key == CHAR_ESCAPE) + if (ev.press && ev.key == kCharEscape) { Window::close(); return true; @@ -591,7 +591,7 @@ bool ImageKnob::onMouse(const MouseEvent& ev) if (! contains(ev.pos)) return false; - if ((ev.mod & MODIFIER_SHIFT) != 0 && fUsingDefault) + if ((ev.mod & kModifierShift) != 0 && fUsingDefault) { setValue(fValueDef, true); fValueTmp = fValue; @@ -631,7 +631,7 @@ bool ImageKnob::onMotion(const MotionEvent& ev) { if (const int movX = ev.pos.getX() - fLastX) { - d = (ev.mod & MODIFIER_CTRL) ? 2000.0f : 200.0f; + d = (ev.mod & kModifierControl) ? 2000.0f : 200.0f; value = (fUsingLog ? _invlogscale(fValueTmp) : fValueTmp) + (float(fMaximum - fMinimum) / d * float(movX)); doVal = true; } @@ -640,7 +640,7 @@ bool ImageKnob::onMotion(const MotionEvent& ev) { if (const int movY = fLastY - ev.pos.getY()) { - d = (ev.mod & MODIFIER_CTRL) ? 2000.0f : 200.0f; + d = (ev.mod & kModifierControl) ? 2000.0f : 200.0f; value = (fUsingLog ? _invlogscale(fValueTmp) : fValueTmp) + (float(fMaximum - fMinimum) / d * float(movY)); doVal = true; } @@ -680,7 +680,7 @@ bool ImageKnob::onScroll(const ScrollEvent& ev) if (! contains(ev.pos)) return false; - const float d = (ev.mod & MODIFIER_CTRL) ? 2000.0f : 200.0f; + const float d = (ev.mod & kModifierControl) ? 2000.0f : 200.0f; float value = (fUsingLog ? _invlogscale(fValueTmp) : fValueTmp) + (float(fMaximum - fMinimum) / d * 10.f * ev.delta.getY()); if (fUsingLog) @@ -733,6 +733,7 @@ ImageSlider::ImageSlider(Window& parent, const Image& image) noexcept fValueTmp(fValue), fDragging(false), fInverted(false), + fValueIsSet(false), fStartedX(0), fStartedY(0), fCallback(nullptr), @@ -754,6 +755,7 @@ ImageSlider::ImageSlider(Widget* widget, const Image& image) noexcept fValueTmp(fValue), fDragging(false), fInverted(false), + fValueIsSet(false), fStartedX(0), fStartedY(0), fCallback(nullptr), @@ -765,50 +767,32 @@ ImageSlider::ImageSlider(Widget* widget, const Image& image) noexcept fNeedsFullViewport = true; } -ImageSlider::ImageSlider(const ImageSlider& imageSlider) noexcept - : Widget(imageSlider.getParentWindow()), - fImage(imageSlider.fImage), - fMinimum(imageSlider.fMinimum), - fMaximum(imageSlider.fMaximum), - fStep(imageSlider.fStep), - fValue(imageSlider.fValue), - fValueTmp(fValue), - fDragging(false), - fInverted(imageSlider.fInverted), - fStartedX(0), - fStartedY(0), - fCallback(imageSlider.fCallback), - fStartPos(imageSlider.fStartPos), - fEndPos(imageSlider.fEndPos), - fSliderArea(imageSlider.fSliderArea), - leakDetector_ImageSlider() +float ImageSlider::getValue() const noexcept { - fNeedsFullViewport = true; + return fValue; } -ImageSlider& ImageSlider::operator=(const ImageSlider& imageSlider) noexcept +void ImageSlider::setValue(float value, bool sendCallback) noexcept { - fImage = imageSlider.fImage; - fMinimum = imageSlider.fMinimum; - fMaximum = imageSlider.fMaximum; - fStep = imageSlider.fStep; - fValue = imageSlider.fValue; - fValueTmp = fValue; - fDragging = false; - fInverted = imageSlider.fInverted; - fStartedX = 0; - fStartedY = 0; - fCallback = imageSlider.fCallback; - fStartPos = imageSlider.fStartPos; - fEndPos = imageSlider.fEndPos; - fSliderArea = imageSlider.fSliderArea; + if (! fValueIsSet) + fValueIsSet = true; - return *this; -} + if (d_isEqual(fValue, value)) + return; -float ImageSlider::getValue() const noexcept -{ - return fValue; + fValue = value; + + if (d_isZero(fStep)) + fValueTmp = value; + + repaint(); + + if (sendCallback && fCallback != nullptr) + { + try { + fCallback->imageSliderValueChanged(this, fValue); + } DISTRHO_SAFE_EXCEPTION("ImageSlider::setValue"); + } } void ImageSlider::setStartPos(const Point<int>& startPos) noexcept @@ -844,12 +828,15 @@ void ImageSlider::setInverted(bool inverted) noexcept void ImageSlider::setRange(float min, float max) noexcept { + fMinimum = min; + fMaximum = max; + if (fValue < min) { fValue = min; repaint(); - if (fCallback != nullptr) + if (fCallback != nullptr && fValueIsSet) { try { fCallback->imageSliderValueChanged(this, fValue); @@ -861,16 +848,13 @@ void ImageSlider::setRange(float min, float max) noexcept fValue = max; repaint(); - if (fCallback != nullptr) + if (fCallback != nullptr && fValueIsSet) { try { fCallback->imageSliderValueChanged(this, fValue); } DISTRHO_SAFE_EXCEPTION("ImageSlider::setRange > max"); } } - - fMinimum = min; - fMaximum = max; } void ImageSlider::setStep(float step) noexcept @@ -878,26 +862,6 @@ void ImageSlider::setStep(float step) noexcept fStep = step; } -void ImageSlider::setValue(float value, bool sendCallback) noexcept -{ - if (d_isEqual(fValue, value)) - return; - - fValue = value; - - if (d_isZero(fStep)) - fValueTmp = value; - - repaint(); - - if (sendCallback && fCallback != nullptr) - { - try { - fCallback->imageSliderValueChanged(this, fValue); - } DISTRHO_SAFE_EXCEPTION("ImageSlider::setValue"); - } -} - void ImageSlider::setCallback(Callback* callback) noexcept { fCallback = callback; diff --git a/dgl/src/Widget.cpp b/dgl/src/Widget.cpp @@ -210,7 +210,7 @@ void Widget::setAbsolutePos(const Point<int>& pos) noexcept fParent.repaint(); } -App& Widget::getParentApp() const noexcept +Application& Widget::getParentApp() const noexcept { return fParent.getApp(); } diff --git a/dgl/src/Window.cpp b/dgl/src/Window.cpp @@ -17,10 +17,7 @@ // we need this for now //#define PUGL_GRAB_FOCUS 1 -#include "AppPrivateData.hpp" -#include "../Widget.hpp" -#include "../Window.hpp" -#include "../../distrho/extra/String.hpp" +#include "../../distrho/src/DistrhoDefines.h" #undef PUGL_HAVE_CAIRO #undef PUGL_HAVE_GL @@ -42,6 +39,11 @@ extern "C" { # error Unsupported platform #endif +#include "ApplicationPrivateData.hpp" +#include "../Widget.hpp" +#include "../Window.hpp" +#include "../../distrho/extra/String.hpp" + #define FOR_EACH_WIDGET(it) \ for (std::list<Widget*>::iterator it = fWidgets.begin(); it != fWidgets.end(); ++it) @@ -64,7 +66,7 @@ START_NAMESPACE_DGL // Window Private struct Window::PrivateData { - PrivateData(App& app, Window* const self) + PrivateData(Application& app, Window* const self) : fApp(app), fSelf(self), fView(puglInit()), @@ -93,7 +95,7 @@ struct Window::PrivateData { init(); } - PrivateData(App& app, Window* const self, Window& parent) + PrivateData(Application& app, Window* const self, Window& parent) : fApp(app), fSelf(self), fView(puglInit()), @@ -132,7 +134,7 @@ struct Window::PrivateData { #endif } - PrivateData(App& app, Window* const self, const intptr_t parentId) + PrivateData(Application& app, Window* const self, const intptr_t parentId) : fApp(app), fSelf(self), fView(puglInit()), @@ -884,9 +886,9 @@ struct Window::PrivateData { // ------------------------------------------------------------------- - App& fApp; - Window* fSelf; - PuglView* fView; + Application& fApp; + Window* fSelf; + PuglView* fView; bool fFirstInit; bool fVisible; @@ -990,15 +992,15 @@ struct Window::PrivateData { // ----------------------------------------------------------------------- // Window -Window::Window(App& app) +Window::Window(Application& app) : pData(new PrivateData(app, this)), leakDetector_Window() {} -Window::Window(App& app, Window& parent) +Window::Window(Application& app, Window& parent) : pData(new PrivateData(app, this, parent)), leakDetector_Window() {} -Window::Window(App& app, intptr_t parentId) +Window::Window(Application& app, intptr_t parentId) : pData(new PrivateData(app, this, parentId)), leakDetector_Window() {} @@ -1169,7 +1171,7 @@ void Window::setTransientWinId(uintptr_t winId) pData->setTransientWinId(winId); } -App& Window::getApp() const noexcept +Application& Window::getApp() const noexcept { return pData->fApp; } diff --git a/distrho/DistrhoUtils.hpp b/distrho/DistrhoUtils.hpp @@ -221,4 +221,13 @@ uint32_t d_nextPowerOf2(uint32_t size) noexcept // ----------------------------------------------------------------------- +#ifndef DONT_SET_USING_DISTRHO_NAMESPACE + // If your code uses a lot of DGL classes, then this will obviously save you + // a lot of typing, but can be disabled by setting DONT_SET_USING_DISTRHO_NAMESPACE. + namespace DISTRHO_NAMESPACE {} + using namespace DISTRHO_NAMESPACE; +#endif + +// ----------------------------------------------------------------------- + #endif // DISTRHO_UTILS_HPP_INCLUDED