ADTF Display Toolbox
Loading...
Searching...
No Matches
drawer.h
Go to the documentation of this file.
1
7#pragma once
8
9#ifdef WIN32
10 #include <windows.h>
11#endif
12
13#include <adtf_filtersdk.h>
14#include <adtffiltersdk/filter.h>
15#include <adtf_base.h>
16
22
23namespace adtf
24{
25
26namespace disptb
27{
28
29namespace drawerlib
30{
31
32namespace detail
33{
34class cDrawerImplementation
35{
36protected:
37 base::property_variable<tInt> m_nZOrder;
38 base::property_variable<tBool> m_bVisible;
39 base::property_variable<tFloat32> m_fTransX{0.0};
40 base::property_variable<tFloat32> m_fTransY{0.0};
41 base::property_variable<tFloat32> m_fScaleX{0.0};
42 base::property_variable<tFloat32> m_fScaleY{0.0};
43 base::property_variable<tFloat32> m_fRotate{0.0};
44 ucom::ant::object_ptr<streaming::IBindingObject> m_pBindingClient;
45 ucom::object_ptr<drawerlib::cDrawerManager> m_pDrawerManager;
46
47protected:
48 cDrawerImplementation(): m_nZOrder(1), m_bVisible(tTrue), m_pDrawerManager(ucom::make_object_ptr<cDrawerManager>())
49 {
50 }
51
52 virtual ~cDrawerImplementation() = default;
53
54protected:
59 tInt GetZOrderImpl() const
60 {
61 return m_nZOrder;
62 }
63
69 tBool IsVisibleImpl() const
70 {
71 return m_bVisible;
72 }
73
74 tResult OnDrawImpl(dengar::IDrawer* pDrawer, const ucom::ant::iobject_ptr<graphicslib::ICanvas>& pCanvas)
75 {
76 pCanvas->PushMatrix();
77 ApplyMatrix(pCanvas);
78
79 tResult nResult = ERR_NOERROR;
80
81 if (IsVisibleImpl())
82 {
83 nResult = pDrawer->Draw(pCanvas);
84 if (IS_FAILED(nResult))
85 {
86 LogDrawerError(nResult, pDrawer);
87 }
88 }
89
90 if (m_pDrawerManager->HasChildren())
91 {
92 for (auto* pChild : m_pDrawerManager->GetOrderedDrawerList())
93 {
94 nResult = pChild->OnDraw(pCanvas);
95 if (IS_FAILED(nResult))
96 {
97 LogDrawerError(nResult, pDrawer);
98 }
99 }
100 }
101
102 pCanvas->PopMatrix();
103
104 RETURN_NOERROR;
105 }
106
107 tResult Register(dengar::IDrawer* pDrawer)
108 {
109 ucom::object_ptr<IDrawerManager> pDrawerManager = nullptr;
110 if (IS_OK(m_pBindingClient->GetServerObject(pDrawerManager)))
111 {
112 pDrawerManager->RegisterManagedDrawer(pDrawer);
113 }
114 RETURN_NOERROR;
115 }
116
117 tVoid ClearChildren()
118 {
119 m_pDrawerManager->Clear();
120 }
121
122 static tVoid LogDrawerError(tResult nResult, dengar::IDrawer* pDrawer)
123 {
124 if (auto* pFilter = dynamic_cast<adtf::filter::cFilter*>(pDrawer))
125 {
126 util::cString strName{};
127 pFilter->GetName(adtf_string_intf(strName));
128 LOG_ERROR("Error %s:%s in Drawer %s", nResult.GetErrorString(), nResult.GetDescription(), strName.GetPtr());
129 }
130 }
131
132public:
139 tVoid ApplyMatrix(const ucom::ant::iobject_ptr<graphicslib::dengar::ICanvas>& pCanvas)
140 {
141 pCanvas->Translate(m_fTransX, m_fTransY, 0.0f);
142 pCanvas->Scale(m_fScaleX, m_fScaleY, 1.0f);
143 pCanvas->Rotate(m_fRotate, 0.0f, 0.0f, 1.0f);
144 }
145
156 tVoid SetMatrix(tFloat32 fTransX, tFloat32 fTransY, tFloat32 fScaleX, tFloat32 fScaleY, tFloat32 fRotate)
157 {
158 m_fTransX = fTransX;
159 m_fTransY = fTransY;
160 m_fScaleX = fScaleX;
161 m_fScaleY = fScaleY;
162 m_fRotate = fRotate;
163 }
164};
165} // namespace detail
166
167namespace dengar
168{
169
184class cDrawer : public ucom::catwo::object<filter::ant::cFilter, dengar::IDrawer>, public detail::cDrawerImplementation
185{
186public:
191 {
192 SetMatrix(0.0f, 0.0f, 1.0f, 1.0f, 0.0f);
193 THROW_IF_FAILED_DESC(RegisterProperties(), "Failed to register properties")
194 THROW_IF_FAILED(streaming::create_client<IDrawerManager>(*this, "drawer_manager"));
195 THROW_IF_FAILED(FindBindingObject("drawer_manager", m_pBindingClient));
196 THROW_IF_FAILED(streaming::create_server<IDrawerManager>(
197 *this, "_drawer_manager", ucom::ucom_object_ptr_cast<IDrawerManager>(m_pDrawerManager)));
198 }
199
203 virtual ~cDrawer() = default;
204
210 {
211 RETURN_IF_FAILED(RegisterPropertyVariable("Z-Order", m_nZOrder));
212 RETURN_IF_FAILED(RegisterPropertyVariable("Visible", m_bVisible));
213 RETURN_IF_FAILED(RegisterPropertyVariable("CS/TranslateX", m_fTransX));
214 RETURN_IF_FAILED(RegisterPropertyVariable("CS/TranslateY", m_fTransY));
215 RETURN_IF_FAILED(RegisterPropertyVariable("CS/ScaleX", m_fScaleX));
216 RETURN_IF_FAILED(RegisterPropertyVariable("CS/ScaleY", m_fScaleY));
217 RETURN_IF_FAILED(RegisterPropertyVariable("CS/Rotate", m_fRotate));
218 RETURN_NOERROR;
219 }
220
224 tInt GetZOrder() const override
225 {
226 return GetZOrderImpl();
227 }
228
232 tBool IsVisible() const override
233 {
234 return IsVisibleImpl();
235 }
236
243 virtual tResult Draw(const ucom::ant::iobject_ptr<graphicslib::dengar::ICanvas>& /*pCanvas*/) override
244 {
245 RETURN_NOERROR;
246 }
247
254 tResult OnDraw(const ucom::ant::iobject_ptr<graphicslib::dengar::ICanvas>& pCanvas) override
255 {
256 return OnDrawImpl(this, pCanvas);
257 }
258
259protected:
261 tResult Init(tInitStage eStage) override
262 {
263 if (eStage == tInitStage::StageGraphReady)
264 {
265 RETURN_IF_FAILED(Register(this));
266 }
267 RETURN_NOERROR;
268 }
269
270 tResult Shutdown(tInitStage eStage) override
271 {
272 if (eStage == tInitStage::StageGraphReady)
273 {
274 ClearChildren();
275 }
276 RETURN_NOERROR;
277 }
279};
280
281} // namespace dengar
282
283namespace florrum
284{
285
300class cDrawer : public ucom::catwo::object<filter::cFilter, florrum::IDrawer>, public detail::cDrawerImplementation
301{
302public:
307 {
308 SetMatrix(0.0f, 0.0f, 1.0f, 1.0f, 0.0f);
309
310 m_nZOrder.SetDescription("Value of the z-order.");
311 RegisterPropertyVariable("Z-Order", m_nZOrder);
312
313 m_bVisible.SetDescription("If enabled, drawer will be visible.");
314 RegisterPropertyVariable("Visible", m_bVisible);
315
316 m_fTransX.SetDescription("Value for the x-axis of the translation matrix to be multiplied with the current "
317 "matrix (note: z-value = 0.0).");
318 RegisterPropertyVariable("CS/TranslateX", m_fTransX);
319
320 m_fTransY.SetDescription("Value for the y-axis of the translation matrix to be multiplied with the current "
321 "matrix (note: z-value = 0.0).");
322 RegisterPropertyVariable("CS/TranslateY", m_fTransY);
323
324 m_fScaleX.SetDescription("Value for the uniform scale factor along the x-axis (note: z-value = 1.0).");
325 RegisterPropertyVariable("CS/ScaleX", m_fScaleX);
326
327 m_fScaleY.SetDescription("Value for the uniform scale factor along the y-axis (note: z-value = 1.0).");
328 RegisterPropertyVariable("CS/ScaleY", m_fScaleY);
329
330 m_fRotate.SetDescription("Value for the rotation angle degree around the vector x=0.0/y=0.0/z=1.0.");
331 RegisterPropertyVariable("CS/Rotate", m_fRotate);
332
333 THROW_IF_FAILED(streaming::create_client<IDrawerManager>(*this, "drawer_manager"));
334 SetDescription("drawer_manager", "IDrawerManager interface (client).");
335 THROW_IF_FAILED(FindBindingObject("drawer_manager", m_pBindingClient));
336 THROW_IF_FAILED(streaming::create_server<IDrawerManager>(
337 *this, "_drawer_manager", ucom::ucom_object_ptr_cast<IDrawerManager>(m_pDrawerManager)));
338 SetDescription("_drawer_manager", "IDrawerManager interface (server).");
339 }
340
344 virtual ~cDrawer() = default;
345
349 tInt GetZOrder() const override
350 {
351 return GetZOrderImpl();
352 }
353
357 tBool IsVisible() const override
358 {
359 return IsVisibleImpl();
360 }
361
368 virtual tResult Draw(const ucom::ant::iobject_ptr<graphicslib::dengar::ICanvas>& /*pCanvas*/) override
369 {
370 RETURN_NOERROR;
371 }
372
379 tResult OnDraw(const ucom::ant::iobject_ptr<graphicslib::dengar::ICanvas>& pCanvas) override
380 {
381 return OnDrawImpl(dynamic_cast<dengar::IDrawer*>(this), pCanvas);
382 }
383
390 virtual tResult ContextCreated(const ucom::ant::iobject_ptr<graphicslib::dengar::ICanvas>& /*pCanvas*/) override
391 {
392 RETURN_NOERROR;
393 }
394
402 tResult OnCreateContext(const ucom::ant::iobject_ptr<graphicslib::dengar::ICanvas>& pCanvas) final override
403 {
404 tResult nResult = ERR_NOERROR;
405 nResult = ContextCreated(pCanvas);
406 if (IS_FAILED(nResult))
407 {
408 LogDrawerError(nResult, this);
409 }
410
411 // TODO Register could happen later than OnCreateContext
412 // In which case we will actually have to repeat this for yet unknown children at the time of OnDraw
413 if (m_pDrawerManager->HasChildren())
414 {
415 for (auto* pChild : m_pDrawerManager->GetOrderedDrawerList())
416 {
417 if (auto* pNewChild = dynamic_cast<florrum::IDrawer*>(pChild))
418 {
419 nResult = pNewChild->OnCreateContext(pCanvas);
420 if (IS_FAILED(nResult))
421 {
422 LogDrawerError(nResult, this);
423 }
424 }
425 }
426 }
427
428 RETURN_NOERROR;
429 }
430
436 virtual tResult ContextDestroyed() override
437 {
438 RETURN_NOERROR;
439 }
440
447 tResult OnDestroyContext() final
448 {
449 tResult nResult = ERR_NOERROR;
450 nResult = ContextDestroyed();
451 if (IS_FAILED(nResult))
452 {
453 LogDrawerError(nResult, this);
454 }
455
456 if (m_pDrawerManager->HasChildren())
457 {
458 for (auto* pChild : m_pDrawerManager->GetOrderedDrawerList())
459 {
460 if (auto* pNewChild = dynamic_cast<florrum::IDrawer*>(pChild))
461 {
462 nResult = pNewChild->OnDestroyContext();
463 if (IS_FAILED(nResult))
464 {
465 LogDrawerError(nResult, this);
466 }
467 }
468 }
469 }
470
471 RETURN_NOERROR;
472 }
473
474protected:
476 tResult Init(tInitStage eStage) override
477 {
478 if (eStage == tInitStage::StageGraphReady)
479 {
480 RETURN_IF_FAILED(Register(dynamic_cast<dengar::IDrawer*>(this)));
481 }
482 RETURN_NOERROR;
483 }
484
485 tResult Shutdown(tInitStage eStage) override
486 {
487 if (eStage == tInitStage::StageGraphReady)
488 {
489 ClearChildren();
490 }
491 RETURN_NOERROR;
492 }
494};
495
496} // namespace florrum
497
498using florrum::cDrawer;
499
500} // namespace drawerlib
501} // namespace disptb
502} // namespace adtf
ADTF 2D Display Drawer interface.
Definition drawer_intf.h:31
virtual tResult Draw(const ucom::ant::iobject_ptr< disptb::graphicslib::dengar::ICanvas > &pCanvas)=0
This method is where the user code defines what is drawn on the canvas.
tInt GetZOrder() const override
The ZOrder defines the order of drawing the objects, if there are in the same coordinate space level.
Definition drawer.h:224
virtual ~cDrawer()=default
Destructor.
tResult RegisterProperties()
Registers all defined property variables.
Definition drawer.h:209
virtual tResult Draw(const ucom::ant::iobject_ptr< graphicslib::dengar::ICanvas > &) override
This method is where the user code defines what is drawn on the canvas.
Definition drawer.h:243
tResult OnDraw(const ucom::ant::iobject_ptr< graphicslib::dengar::ICanvas > &pCanvas) override
This method is called from the drawer manager to draw on the give canvas.
Definition drawer.h:254
tBool IsVisible() const override
Definition drawer.h:232
tInt GetZOrderImpl() const
The ZOrder defines the order of drawing the objects, if there are in the same coordinate space level.
Definition drawer.h:59
tBool IsVisibleImpl() const
IsVisible() is not the same as IsActive()!
Definition drawer.h:69
tVoid ApplyMatrix(const ucom::ant::iobject_ptr< graphicslib::dengar::ICanvas > &pCanvas)
This method is called before Drawing.
Definition drawer.h:139
tVoid SetMatrix(tFloat32 fTransX, tFloat32 fTransY, tFloat32 fScaleX, tFloat32 fScaleY, tFloat32 fRotate)
SetMatrix sets all parameter for the matrix to use in ApplyMatrix() Draw() don't need them because th...
Definition drawer.h:156
ADTF 2D Display Drawer interface.
Definition drawer_intf.h:78
tInt GetZOrder() const override
The ZOrder defines the order of drawing the objects, if there are in the same coordinate space level.
Definition drawer.h:349
virtual ~cDrawer()=default
Destructor.
virtual tResult Draw(const ucom::ant::iobject_ptr< graphicslib::dengar::ICanvas > &) override
This method is where the user code defines what is drawn on the canvas.
Definition drawer.h:368
virtual tResult ContextCreated(const ucom::ant::iobject_ptr< graphicslib::dengar::ICanvas > &) override
This method can be overwritten to define the desired behavior during the OnCreateContext event.
Definition drawer.h:390
virtual tResult ContextDestroyed() override
This method can be overwritten to define the desired behavior during the OnDestroyContext event.
Definition drawer.h:436
tResult OnCreateContext(const ucom::ant::iobject_ptr< graphicslib::dengar::ICanvas > &pCanvas) final override
This oneshot method is called once when the transition from runlevel 4 to runlevel 5 occurs The use o...
Definition drawer.h:402
tResult OnDraw(const ucom::ant::iobject_ptr< graphicslib::dengar::ICanvas > &pCanvas) override
This method is called from the drawer manager to draw on the give canvas.
Definition drawer.h:379
tBool IsVisible() const override
Definition drawer.h:357
tResult OnDestroyContext() final
This oneshot method is called once when the transition from runlevel 5 to runlevel 4 occurs The use o...
Definition drawer.h:447
Copyright © Audi Electronics Venture GmbH.
Copyright © Audi Electronics Venture GmbH.
Copyright © Audi Electronics Venture GmbH.
Copyright © Audi Electronics Venture GmbH.
Copyright © Audi Electronics Venture GmbH.
Namespace for functionality provided by the Display Toolbox.
Main namespace.