DPF

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

commit 21330021cea0854dc6f21a0c718e0e3692dc441f
parent 55916eb0fba3a829a6e50bd38371b6ad37912292
Author: falkTX <falktx@falktx.com>
Date:   Fri, 11 Mar 2022 09:47:32 +0000

Add window offset related functions

Diffstat:
Mdgl/Window.hpp | 35+++++++++++++++++++++++++++++++++++
Mdgl/src/Window.cpp | 42++++++++++++++++++++++++++++++++++++++++++
Mdgl/src/pugl.cpp | 12++++++++++++
Mdgl/src/pugl.hpp | 8++++++--
Mdistrho/src/DistrhoUIInternal.hpp | 9+++++++++
5 files changed, 104 insertions(+), 2 deletions(-)

diff --git a/dgl/Window.hpp b/dgl/Window.hpp @@ -207,6 +207,41 @@ public: void setResizable(bool resizable); /** + Get X offset, typically 0. + */ + int getOffsetX() const noexcept; + + /** + Get Y offset, typically 0. + */ + int getOffsetY() const noexcept; + + /** + Get offset. + */ + Point<int> getOffset() const noexcept; + + /** + Set X offset. + */ + void setOffsetX(int x); + + /** + Set Y offset. + */ + void setOffsetY(int y); + + /** + Set offset using @a x and @a y values. + */ + void setOffset(int x, int y); + + /** + Set offset. + */ + void setOffset(const Point<int>& offset); + + /** Get width. */ uint getWidth() const noexcept; diff --git a/dgl/src/Window.cpp b/dgl/src/Window.cpp @@ -155,6 +155,48 @@ void Window::setResizable(const bool resizable) pData->setResizable(resizable); } +int Window::getOffsetX() const noexcept +{ + DISTRHO_SAFE_ASSERT_RETURN(pData->view != nullptr, 0); + + return puglGetFrame(pData->view).x; +} + +int Window::getOffsetY() const noexcept +{ + DISTRHO_SAFE_ASSERT_RETURN(pData->view != nullptr, 0); + + return puglGetFrame(pData->view).y; +} + +Point<int> Window::getOffset() const noexcept +{ + DISTRHO_SAFE_ASSERT_RETURN(pData->view != nullptr, Point<int>()); + + const PuglRect rect = puglGetFrame(pData->view); + return Point<int>(rect.x, rect.y); +} + +void Window::setOffsetX(const int x) +{ + setOffset(x, getOffsetY()); +} + +void Window::setOffsetY(const int y) +{ + setOffset(getOffsetX(), y); +} + +void Window::setOffset(const int x, const int y) +{ + puglSetWindowOffset(pData->view, x, y); +} + +void Window::setOffset(const Point<int>& offset) +{ + setOffset(offset.getX(), offset.getY()); +} + uint Window::getWidth() const noexcept { DISTRHO_SAFE_ASSERT_RETURN(pData->view != nullptr, 0); diff --git a/dgl/src/pugl.cpp b/dgl/src/pugl.cpp @@ -340,6 +340,18 @@ PuglStatus puglSetGeometryConstraints(PuglView* const view, const uint width, co } // -------------------------------------------------------------------------------------------------------------------- +// set window offset without changing size + +PuglStatus puglSetWindowOffset(PuglView* const view, const int x, const int y) +{ + // TODO custom setFrame version + PuglRect rect = puglGetFrame(view); + rect.x = x; + rect.y = y; + return puglSetFrame(view, rect); +} + +// -------------------------------------------------------------------------------------------------------------------- // set window size with default size and without changing frame x/y position PuglStatus puglSetWindowSize(PuglView* const view, const uint width, const uint height) diff --git a/dgl/src/pugl.hpp b/dgl/src/pugl.hpp @@ -81,11 +81,15 @@ puglSetMatchingBackendForCurrentBuild(PuglView* view); // Combine puglSetMinSize and puglSetAspectRatio PUGL_API PuglStatus -puglSetGeometryConstraints(PuglView* view, unsigned int width, unsigned int height, bool aspect); +puglSetGeometryConstraints(PuglView* view, uint width, uint height, bool aspect); + +// set window offset without changing size +PUGL_API PuglStatus +puglSetWindowOffset(PuglView* view, int x, int y); // set window size with default size and without changing frame x/y position PUGL_API PuglStatus -puglSetWindowSize(PuglView* view, unsigned int width, unsigned int height); +puglSetWindowSize(PuglView* view, uint width, uint height); // DGL specific, build-specific drawing prepare PUGL_API void diff --git a/distrho/src/DistrhoUIInternal.hpp b/distrho/src/DistrhoUIInternal.hpp @@ -284,6 +284,15 @@ public: // ------------------------------------------------------------------- + void setWindowOffset(const int x, const int y) + { +#if DISTRHO_PLUGIN_HAS_EXTERNAL_UI + // TODO +#else + uiData->window->setOffset(x, y); +#endif + } + #ifdef DISTRHO_PLUGIN_TARGET_VST3 void setWindowSizeForVST3(const uint width, const uint height) {