summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJP Cimalando <jpcima@users.noreply.github.com>2018-12-27 11:27:58 +0100
committerFilipe Coelho <falktx@falktx.com>2019-01-06 19:10:11 +0100
commitc6f5d34be6ee0a292f044edaa47c72c8a71257a5 (patch)
treece207a3c1fd3b58eecc5f7a8ef40dfbd121eb916
parent2795c66b1654b6fda8f5a892057ffb625508a60f (diff)
dgl: add the Context structure
-rw-r--r--dgl/Base.hpp25
-rw-r--r--dgl/Widget.hpp4
-rw-r--r--dgl/Window.hpp4
-rw-r--r--dgl/src/Widget.cpp4
-rw-r--r--dgl/src/Window.cpp19
5 files changed, 40 insertions, 16 deletions
diff --git a/dgl/Base.hpp b/dgl/Base.hpp
index b8bef580..dc6bdb8f 100644
--- 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
index f3e0ede0..4e39d552 100644
--- 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
index 0b44f7f9..c5de5762 100644
--- 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
index 1698c4db..7a87fd6f 100644
--- 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
index d254f8f9..f6124273 100644
--- 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)
{