Skip to content

Commit

Permalink
[render] get windowPtr from WindowManagers
Browse files Browse the repository at this point in the history
  • Loading branch information
alemuntoni committed Jan 9, 2025
1 parent 36c7594 commit f92446f
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 2 deletions.
2 changes: 2 additions & 0 deletions vclib/render/include/vclib/glfw/window_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,8 @@ class WindowManager
}

protected:
void* windowPtr() { return reinterpret_cast<void*>(mWindow); }

// callbacks
virtual void glfwFramebufferSizeCallback(
GLFWwindow*,
Expand Down
6 changes: 6 additions & 0 deletions vclib/render/include/vclib/qt/widget_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,12 @@ class WidgetManager :
}

protected:
void* windowPtr()
{
// TODO: probably ImGui Drawer needs something else here - QWidget*?
return reinterpret_cast<void*>(winId());
}

#if defined(VCLIB_RENDER_BACKEND_BGFX)
void resizeEvent(QResizeEvent* event) override
{
Expand Down
5 changes: 3 additions & 2 deletions vclib/render/include/vclib/render/drawers/plain_drawer.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ namespace vcl {
template<typename DerivedRenderer>
class PlainDrawer
{
protected:
using DRT = DerivedRenderer;

public:
PlainDrawer() = default;
PlainDrawer(uint, uint) {}
Expand All @@ -43,8 +46,6 @@ class PlainDrawer
virtual void onDrawContent(uint viewId) {}

protected:
using DRT = DerivedRenderer;

auto* derived() { return static_cast<DRT*>(this); }

const auto* derived() const { return static_cast<const DRT*>(this); }
Expand Down
18 changes: 18 additions & 0 deletions vclib/render/include/vclib/render/renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,8 @@ class Renderer :
/***** Member functions called by Drawer objects *****/
// Documentation is in the Renderer::DRW inner class

void* dWindowPtr() { return WindowManagerType::windowPtr(); }

vcl::Point2<uint> dCanvasSize() const { return CanvasType::size(); }

auto dCanvasFrameBuffer() const { return CanvasType::frameBuffer(); }
Expand Down Expand Up @@ -555,6 +557,22 @@ class Renderer<WindowManagerT, CanvasT, Drawers...>::DRW
//friend Drawers<Renderer<WindowManagerT, CanvasT, Drawers...>>...;
public: // TODO - remove this when C++26 is supported

/**
* @brief A Drawer object can request the window pointer of the window
* manager (the exact meaning of the window pointer depends on the window
* manager implementation).
*
* To get the window pointer, the Drawer object can call the `windowPtr()`
* function. To know the exact meaning of the window pointer, the Drawer
* object should refer to the documentation of the specific window manager
* implementation, and check the WINDOW_MANAGER_ID of the window manager,
* that is a static constant of the WindowManager class.
*
* @param r
* @return
*/
static void* windowPtr(Renderer* r) { return r->dWindowPtr(); }

/**
* @brief A Drawer object can request the size of the canvas. This function
* is called by the Drawer object to request the size of the canvas.
Expand Down

0 comments on commit f92446f

Please sign in to comment.