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