23#ifndef VCL_RENDER_RENDER_APP_H
24#define VCL_RENDER_RENDER_APP_H
26#include "concepts/blocker_event_drawer.h"
27#include "concepts/canvas.h"
28#include "concepts/event_drawer.h"
29#include "concepts/window_manager.h"
31#include "read_buffer_types.h"
33#include <vclib/space/core/point.h>
58 typename WindowManagerT,
64 public WindowManagerT<RenderApp<WindowManagerT, CanvasT, Drawers...>>,
65 public CanvasT<RenderApp<WindowManagerT, CanvasT, Drawers...>>,
66 public Drawers<RenderApp<WindowManagerT, CanvasT, Drawers...>>...
73 "The first template parameter type of the RenderApp class must be a "
74 "class that satisfies the WindowManagerConcept.");
78 "The second template parameter type of the RenderApp class must be a "
79 "class that satisfies the CanvasConcept.");
83 "All the Drawer types must satisfy the DrawerConcept.");
88 using CanvasType::onInit;
89 using CanvasType::onPaint;
90 using CanvasType::onReadDepth;
91 using CanvasType::onResize;
92 using CanvasType::onScreenshot;
93 using CanvasType::setDefaultClearColor;
94 using CanvasType::size;
97 using WindowManagerType::displayId;
98 using WindowManagerType::winId;
101 using CanvasType::viewId;
106 using ParentType = WindowManagerType::ParentType;
119 const std::string& windowTitle,
122 ParentType*
parent =
nullptr) :
123 WindowManagerType(windowTitle, width, height,
parent),
125 (
void*) WindowManagerType::winId(),
126 width * WindowManagerType::dpiScale().x(),
127 height * WindowManagerType::dpiScale().y(),
128 WindowManagerType::displayId()),
130 width * WindowManagerType::dpiScale().x(),
131 height * WindowManagerType::dpiScale().y())...
155 template<
typename D,
typename...
Others>
167 if constexpr (
sizeof...(Others) > 0) {
182 CanvasType::onInit();
183 (
static_cast<Drawers<RenderApp>*
>(
this)->onInit(CanvasType::viewId()),
187 void wmResize(uint width, uint height)
189 CanvasType::onResize(width, height);
194 (
static_cast<Drawers<RenderApp>*
>(
this)->onResize(width, height), ...);
197 void wmPaint() { CanvasType::onPaint(); }
199 void wmSetModifiers(
const KeyModifiers& modifiers)
201 mKeyModifiers = modifiers;
204 void wmKeyPress(Key::Enum key)
208 auto lambda = [&]<
typename D>(
auto* t) {
211 return static_cast<D*
>(t)->onKeyPress(key, mKeyModifiers);
215 callEventFunForDrawers<Drawers<RenderApp>...>(lambda);
218 void wmKeyRelease(Key::Enum key)
222 auto lambda = [&]<
typename D>(
auto* t) {
225 return static_cast<D*
>(t)->onKeyRelease(key, mKeyModifiers);
229 callEventFunForDrawers<Drawers<RenderApp>...>(lambda);
232 void wmMouseMove(
double x,
double y)
236 auto lambda = [&]<
typename D>(
auto* t) {
239 return static_cast<D*
>(t)->onMouseMove(x, y, mKeyModifiers);
243 callEventFunForDrawers<Drawers<RenderApp>...>(lambda);
246 void wmMousePress(MouseButton::Enum button,
double x,
double y)
250 auto lambda = [&]<
typename D>(
auto* t) {
253 return static_cast<D*
>(t)->onMousePress(
254 button, x, y, mKeyModifiers);
258 callEventFunForDrawers<Drawers<RenderApp>...>(lambda);
261 void wmMouseRelease(MouseButton::Enum button,
double x,
double y)
265 auto lambda = [&]<
typename D>(
auto* t) {
268 return static_cast<D*
>(t)->onMouseRelease(
269 button, x, y, mKeyModifiers);
273 callEventFunForDrawers<Drawers<RenderApp>...>(lambda);
276 void wmMouseDoubleClick(MouseButton::Enum button,
double x,
double y)
280 auto lambda = [&]<
typename D>(
auto* t) {
283 return static_cast<D*
>(t)->onMouseDoubleClick(
284 button, x, y, mKeyModifiers);
288 callEventFunForDrawers<Drawers<RenderApp>...>(lambda);
291 void wmMouseScroll(
double x,
double y)
295 auto lambda = [&]<
typename D>(
auto* t) {
298 return static_cast<D*
>(t)->onMouseScroll(x, y, mKeyModifiers);
302 callEventFunForDrawers<Drawers<RenderApp>...>(lambda);
313 (
static_cast<Drawers<RenderApp>*
>(
this)->onDraw(CanvasType::viewId()),
317 void cnvDrawContent()
322 (
static_cast<Drawers<RenderApp>*
>(
this)->onDrawContent(
323 CanvasType::viewId()),
332 (
static_cast<Drawers<RenderApp>*
>(
this)->onDrawId(CanvasType::viewId()),
341 (...,
static_cast<Drawers<RenderApp>*
>(
this)->onPostDraw());
347 void* dWindowPtr() {
return WindowManagerType::windowPtr(); }
351 void dSetCanvasDefaultClearColor(
const Color& color)
353 CanvasType::setDefaultClearColor(color);
356 auto dCanvasFrameBuffer()
const {
return CanvasType::frameBuffer(); }
358 [[nodiscard]]
bool dReadDepth(
360 ReadBufferTypes::CallbackReadBuffer callback =
nullptr)
362 return CanvasType::onReadDepth(point, callback);
365 [[nodiscard]]
bool dReadId(
367 ReadBufferTypes::CallbackReadBuffer callback =
nullptr)
369 return CanvasType::onReadId(point, callback);
372 void dScreenshot(
const std::string& filename, uint multiplier = 1)
374 CanvasType::onScreenshot(filename, multiplier);
396 typename WindowManagerT,
426 r->wmResize(width, height);
468 r->wmKeyRelease(key);
484 r->wmMouseMove(x, y);
528 r->wmMouseRelease(
button, x, y);
550 r->wmMouseDoubleClick(
button, x, y);
567 r->wmMouseScroll(x, y);
585 typename WindowManagerT,
642 typename WindowManagerT,
683 return r->dCanvasSize();
696 r->dSetCanvasDefaultClearColor(color);
711 return r->dCanvasFrameBuffer();
732 ReadBufferTypes::CallbackReadBuffer
callback =
nullptr)
755 ReadBufferTypes::CallbackReadBuffer
callback =
nullptr)
A class representing a box in N-dimensional space.
Definition box.h:46
The Color class represents a 32 bit color.
Definition color.h:48
The Point class represents an N-dimensional point containing N scalar values.
Definition point.h:55
The RenderApp::CNV inner class is an Attorney that allow access to some private member functions of t...
Definition render_app.h:591
static void postDraw(RenderApp *r)
The CanvasType has finished drawing and has submitted the new frame, and asks the RenderApp to call t...
Definition render_app.h:625
static void drawContent(RenderApp *r)
The CanvasType wants to draw only the content of the objects, without any decorator (e....
Definition render_app.h:609
static void drawId(RenderApp *r)
The CanvasType wants to draw only the IDs of the objects, without any decorator (e....
Definition render_app.h:618
static void draw(RenderApp *r)
The CanvasType is ready to draw, and asks the RenderApp to call the onDraw(uint()) function for every...
Definition render_app.h:600
The RenderApp::DRW inner class is an Attorney that allow access to some private member functions of t...
Definition render_app.h:648
static void * windowPtr(RenderApp *r)
A Drawer object can request the window pointer of the window manager (the exact meaning of the window...
Definition render_app.h:671
static Point2< uint > canvasSize(const RenderApp *r)
A Drawer object can request the size of the canvas. This function is called by the Drawer object to r...
Definition render_app.h:681
static bool readDepth(RenderApp *r, const Point2i &point, ReadBufferTypes::CallbackReadBuffer callback=nullptr)
A Drawer object can request the depth value at a specific point on the canvas. This function is calle...
Definition render_app.h:729
static bool readId(RenderApp *r, const Point2i &point, ReadBufferTypes::CallbackReadBuffer callback=nullptr)
A Drawer object can request the ID at a specific point on the canvas. This function is called by the ...
Definition render_app.h:752
static void screenshot(RenderApp *r, const std::string &filename, uint multiplier=1)
A Drawer object can request a screenshot of the canvas. This function is called by the Drawer object ...
Definition render_app.h:769
static auto canvasFrameBuffer(const RenderApp *r)
A Drawer object can request the frame buffer of the canvas.
Definition render_app.h:709
static void setCanvasDefaultClearColor(RenderApp *r, const Color &color)
A Drawer object can set the default clear color of the canvas.
Definition render_app.h:694
The RenderApp::WM inner class is an Attorney that allow access to some private member functions of th...
Definition render_app.h:402
static void keyRelease(RenderApp *r, Key::Enum key)
The WindowManagerType calls this member function when a key is released.
Definition render_app.h:466
static void keyPress(RenderApp *r, Key::Enum key)
The WindowManagerType calls this member function when a key is pressed.
Definition render_app.h:454
static void paint(RenderApp *r)
The WindowManagerType calls this member function when the window triggers a paint event.
Definition render_app.h:433
static void init(RenderApp *r)
The WindowManagerType calls this member function when the window render backend is initialized....
Definition render_app.h:413
static void setModifiers(RenderApp *r, const KeyModifiers &modifiers)
The WindowManagerType calls this member function when the current modifiers are updated.
Definition render_app.h:439
static void mousePress(RenderApp *r, MouseButton::Enum button, double x, double y)
The WindowManagerType calls this member function when a mouse button is pressed.
Definition render_app.h:500
static void mouseScroll(RenderApp *r, double x, double y)
The WindowManagerType calls this member function when the mouse wheel is scrolled.
Definition render_app.h:565
static void resize(RenderApp *r, uint width, uint height)
The WindowManagerType calls this member function when the window is resized, telling the new width an...
Definition render_app.h:424
static void mouseRelease(RenderApp *r, MouseButton::Enum button, double x, double y)
The WindowManagerType calls this member function when a mouse button is released.
Definition render_app.h:522
static void mouseDoubleClick(RenderApp *r, MouseButton::Enum button, double x, double y)
The WindowManagerType calls this member function when a mouse button is double clicked.
Definition render_app.h:544
static void mouseMove(RenderApp *r, double x, double y)
The WindowManagerType calls this member function when the mouse cursor is moved.
Definition render_app.h:482
The RenderApp class is a template class that combines a canvas, a window manager, and a set of drawer...
Definition render_app.h:67
void callEventFunForDrawers(auto lambda)
Calls a lambda function - that represents an event - for every Drawer object listed in the template p...
Definition render_app.h:156
Definition blocker_event_drawer.h:33
The CanvasConcept concept is used to check if a class satisfies the requirements of the Canvas concep...
Definition canvas.h:99
Definition event_drawer.h:33
The WindowManagerConcept concept is used to check if a class satisfies the requirements of the Window...
Definition window_manager.h:95
Point2< int > Point2i
A convenience alias for a 2-dimensional Point with integer components.
Definition point.h:706