DPF

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

commit 8ba6a786aa8472ad948fd865e2977ad4041a52a1
parent 9c2f68f6bfa3de2e73080fa665c7f88b7debdb67
Author: falkTX <falktx@falktx.com>
Date:   Sat,  1 May 2021 14:54:06 +0100

Put IdleCallback stuff directly in Application class

Signed-off-by: falkTX <falktx@falktx.com>

Diffstat:
Mdgl/Application.hpp | 13+++++++++++++
Mdgl/src/Application.cpp | 14++++++++++++++
Mdgl/src/ApplicationPrivateData.cpp | 6+++++-
3 files changed, 32 insertions(+), 1 deletion(-)

diff --git a/dgl/Application.hpp b/dgl/Application.hpp @@ -76,6 +76,19 @@ public: */ bool isQuiting() const noexcept; + /** + Add a callback function to be triggered on every idle cycle. + You can add more than one, and remove them at anytime with removeIdleCallback(). + Idle callbacks trigger right after OS event handling and Window idle events (within the same cycle). + There are no guarantees in terms of timing. + */ + void addIdleCallback(IdleCallback* const callback); + + /** + Remove an idle callback previously added via addIdleCallback(). + */ + void removeIdleCallback(IdleCallback* const callback); + private: struct PrivateData; PrivateData* const pData; diff --git a/dgl/src/Application.cpp b/dgl/src/Application.cpp @@ -53,6 +53,20 @@ bool Application::isQuiting() const noexcept return pData->isQuitting; } +void Application::addIdleCallback(IdleCallback* const callback) +{ + DISTRHO_SAFE_ASSERT_RETURN(callback != nullptr,) + + pData->idleCallbacks.push_back(callback); +} + +void Application::removeIdleCallback(IdleCallback* const callback) +{ + DISTRHO_SAFE_ASSERT_RETURN(callback != nullptr,) + + pData->idleCallbacks.remove(callback); +} + // -------------------------------------------------------------------------------------------------------------------- END_NAMESPACE_DGL diff --git a/dgl/src/ApplicationPrivateData.cpp b/dgl/src/ApplicationPrivateData.cpp @@ -78,7 +78,11 @@ void Application::PrivateData::oneWindowHidden() noexcept void Application::PrivateData::idle(const uint timeoutInMs) { - puglUpdate(world, timeoutInMs == 0 ? 0.0 : static_cast<double>(timeoutInMs) / 1000.0); + const double timeoutInSeconds = timeoutInMs != 0 + ? static_cast<double>(timeoutInMs) / 1000.0 + : 0.0; + + puglUpdate(world, timeoutInSeconds); #ifndef DPF_TEST_APPLICATION_CPP for (std::list<Window*>::iterator it = windows.begin(), ite = windows.end(); it != ite; ++it)