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)->onPostDraw());
338 void* dWindowPtr() {
return WindowManagerType::windowPtr(); }
342 void dSetCanvasDefaultClearColor(
const Color& color)
344 CanvasType::setDefaultClearColor(color);
347 auto dCanvasFrameBuffer()
const {
return CanvasType::frameBuffer(); }
349 [[nodiscard]]
bool dReadDepth(
351 ReadBufferTypes::CallbackReadBuffer callback =
nullptr)
353 return CanvasType::onReadDepth(point, callback);
356 void dScreenshot(
const std::string& filename, uint width, uint height)
358 CanvasType::onScreenshot(filename, width, height);
380 typename WindowManagerT,
410 r->wmResize(width, height);
452 r->wmKeyRelease(key);
468 r->wmMouseMove(x, y);
512 r->wmMouseRelease(
button, x, y);
534 r->wmMouseDoubleClick(
button, x, y);
551 r->wmMouseScroll(x, y);
569 typename WindowManagerT,
617 typename WindowManagerT,
658 return r->dCanvasSize();
671 r->dSetCanvasDefaultClearColor(color);
686 return r->dCanvasFrameBuffer();
704 ReadBufferTypes::CallbackReadBuffer
callback =
nullptr)
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:58
The RenderApp::CNV inner class is an Attorney that allow access to some private member functions of t...
Definition render_app.h:575
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:600
static void drawContent(RenderApp *r)
The CanvasType wants to draw only the content of the objects, without any decorator (e....
Definition render_app.h:593
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:584
The RenderApp::DRW inner class is an Attorney that allow access to some private member functions of t...
Definition render_app.h:623
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:646
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:656
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:701
static auto canvasFrameBuffer(const RenderApp *r)
A Drawer object can request the frame buffer of the canvas.
Definition render_app.h:684
static void screenshot(RenderApp *r, const std::string &filename, uint width=0, uint height=0)
A Drawer object can request a screenshot of the canvas. This function is called by the Drawer object ...
Definition render_app.h:720
static void setCanvasDefaultClearColor(RenderApp *r, const Color &color)
A Drawer object can set the default clear color of the canvas.
Definition render_app.h:669
The RenderApp::WM inner class is an Attorney that allow access to some private member functions of th...
Definition render_app.h:386
static void keyRelease(RenderApp *r, Key::Enum key)
The WindowManagerType calls this member function when a key is released.
Definition render_app.h:450
static void keyPress(RenderApp *r, Key::Enum key)
The WindowManagerType calls this member function when a key is pressed.
Definition render_app.h:438
static void paint(RenderApp *r)
The WindowManagerType calls this member function when the window triggers a paint event.
Definition render_app.h:417
static void init(RenderApp *r)
The WindowManagerType calls this member function when the window render backend is initialized....
Definition render_app.h:397
static void setModifiers(RenderApp *r, const KeyModifiers &modifiers)
The WindowManagerType calls this member function when the current modifiers are updated.
Definition render_app.h:423
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:484
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:549
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:408
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:506
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:528
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:466
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
A class representing a line segment in n-dimensional space. The class is parameterized by a PointConc...
Definition segment.h:43
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:102
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:731