DPF

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

commit c6f5d34be6ee0a292f044edaa47c72c8a71257a5
parent 2795c66b1654b6fda8f5a892057ffb625508a60f
Author: JP Cimalando <jpcima@users.noreply.github.com>
Date:   Thu, 27 Dec 2018 11:27:31 +0100

dgl: add the Context structure

Diffstat:
Mdgl/Base.hpp | 25+++++++++++++++++++++++++
Mdgl/Widget.hpp | 4+---
Mdgl/Window.hpp | 4+---
Mdgl/src/Widget.cpp | 4+---
Mdgl/src/Window.cpp | 19++++++++++++-------
5 files changed, 40 insertions(+), 16 deletions(-)

diff --git a/dgl/Base.hpp b/dgl/Base.hpp @@ -184,6 +184,15 @@ enum Key { kKeySuper }; +/** + Type of graphics context. + */ +enum ContextType +{ + kContextGL, + kContextCairo +}; + // ----------------------------------------------------------------------- // Base DGL classes @@ -197,6 +206,22 @@ public: virtual void idleCallback() = 0; }; +/** + Graphics context. + */ +struct Context +{ + ContextType type; + union { +#ifdef HAVE_DGL + struct { /* nothing for now */ } gl; +#endif +#ifdef HAVE_DCAIRO + struct { cairo_t* graphics; } cairo; +#endif + }; +}; + // ----------------------------------------------------------------------- END_NAMESPACE_DGL diff --git a/dgl/Widget.hpp b/dgl/Widget.hpp @@ -312,9 +312,7 @@ public: */ Window& getParentWindow() const noexcept; -#ifdef HAVE_DCAIRO - cairo_t* getContext() const noexcept; -#endif + const Context& getContext() const noexcept; /** Check if this widget contains the point defined by @a x and @a y. diff --git a/dgl/Window.hpp b/dgl/Window.hpp @@ -119,9 +119,7 @@ public: Application& getApp() const noexcept; intptr_t getWindowId() const noexcept; -#ifdef HAVE_DCAIRO - cairo_t* getContext() const noexcept; -#endif + const Context& getContext() const noexcept; void addIdleCallback(IdleCallback* const callback); void removeIdleCallback(IdleCallback* const callback); diff --git a/dgl/src/Widget.cpp b/dgl/src/Widget.cpp @@ -189,12 +189,10 @@ Window& Widget::getParentWindow() const noexcept return pData->parent; } -#ifdef HAVE_DCAIRO -cairo_t* Widget::getContext() const noexcept +const Context& Widget::getContext() const noexcept { return pData->parent.getContext(); } -#endif bool Widget::contains(int x, int y) const noexcept { diff --git a/dgl/src/Window.cpp b/dgl/src/Window.cpp @@ -214,13 +214,14 @@ struct Window::PrivateData { } #ifdef HAVE_DGL - PuglContextType contextType = PUGL_GL; + const ContextType contextType = kContextGL; #endif #ifdef HAVE_DCAIRO - PuglContextType contextType = PUGL_CAIRO; + const ContextType contextType = kContextCairo; #endif + fContext.type = contextType; - puglInitContextType(fView, contextType); + puglInitContextType(fView, (PuglContextType)contextType); puglInitUserResizable(fView, fResizable); puglInitWindowSize(fView, static_cast<int>(fWidth), static_cast<int>(fHeight)); @@ -1059,6 +1060,7 @@ struct Window::PrivateData { Application& fApp; Window* fSelf; + Context fContext; PuglView* fView; bool fFirstInit; @@ -1384,12 +1386,15 @@ intptr_t Window::getWindowId() const noexcept return puglGetNativeWindow(pData->fView); } -#ifdef HAVE_DCAIRO -cairo_t* Window::getContext() const noexcept +const Context& Window::getContext() const noexcept { - return (cairo_t*)puglGetContext(pData->fView); -} + Context& context = pData->fContext; +#ifdef HAVE_DCAIRO + if (context.type == kContextCairo) + context.cairo.graphics = (cairo_t*)puglGetContext(pData->fView); #endif + return context; +} void Window::_addWidget(Widget* const widget) {