Browse Source

dgl: add the Context structure

pull/99/head
JP Cimalando Filipe Coelho <falktx@falktx.com> 5 years ago
parent
commit
c6f5d34be6
5 changed files with 40 additions and 16 deletions
  1. +25
    -0
      dgl/Base.hpp
  2. +1
    -3
      dgl/Widget.hpp
  3. +1
    -3
      dgl/Window.hpp
  4. +1
    -3
      dgl/src/Widget.cpp
  5. +12
    -7
      dgl/src/Window.cpp

+ 25
- 0
dgl/Base.hpp View File

@@ -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


+ 1
- 3
dgl/Widget.hpp View File

@@ -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.


+ 1
- 3
dgl/Window.hpp View File

@@ -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);


+ 1
- 3
dgl/src/Widget.cpp View File

@@ -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
{


+ 12
- 7
dgl/src/Window.cpp View File

@@ -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)
{


Loading…
Cancel
Save