ADTF_DISPLAY_TOOLBOX  3.8.0 (ADTF 3.14.3)
Source Code for Demo 2D Example Drawer
Location
./src/examples/src/example_drawer
This example shows:
  • how to create a custom drawer
  • how to add new properties to the derived drawer implementation.
  • how to use the canvas inside the Draw method.
Header
#pragma once
#include <adtf_base.h>
#include <adtf_utils.h>
#include <adtf_systemsdk.h>
#include <adtf_filtersdk.h>
class cExampleDrawer :
public adtf::ucom::object<adtf::disptb::drawerlib::cDrawer>
{
public:
ADTF_CLASS_ID_NAME(
cExampleDrawer,
"demo_example.2d_drawer.disptb.cid",
"Demo 2D Drawer Example"
);
/*
* Constructor
*/
cExampleDrawer();
/*
* Destructor
*/
~cExampleDrawer() = default;
tResult Init(tInitStage eStage) override;
tResult Shutdown(tInitStage eStage) override;
tResult Draw(const adtf::ucom::iobject_ptr<adtf::disptb::graphicslib::ICanvas>& pCanvas) override;
private:
adtf::base::property_variable<tInt> m_propColorRed = 255;
adtf::base::property_variable<tInt> m_propColorGreen = 0;
adtf::base::property_variable<tInt> m_propColorBlue = 0;
adtf::base::property_variable<tFloat32> m_propCircleX1 = -150.0;
adtf::base::property_variable<tFloat32> m_propCircleX2 = 150.0;
adtf::base::property_variable<tFloat32> m_propCircleY1 = -150.0;
adtf::base::property_variable<tFloat32> m_propCircleY2 = 150.0;
};
Copyright © Audi Electronics Venture GmbH.
Copyright © Audi Electronics Venture GmbH.
Implementation
#include "example_drawer.h"
ADTF_PLUGIN_VERSION("Demo 2D Drawer Example Plugin",
disptb,
DISPTB_VERSION_MAJOR,
DISPTB_VERSION_MINOR,
DISPTB_VERSION_PATCH,
cExampleDrawer)
cExampleDrawer::cExampleDrawer()
{
m_propColorRed.SetDescription("Value for red content of color to draw a circle.");
RegisterPropertyVariable("RGB-Color-Red", m_propColorRed);
m_propColorGreen.SetDescription("Value for green content of color to draw a circle.");
RegisterPropertyVariable("RGB-Color-Green", m_propColorGreen);
m_propColorBlue.SetDescription("Value for blue content of color to draw a circle.");
RegisterPropertyVariable("RGB-Color-Blue", m_propColorBlue);
m_propCircleX1.SetDescription("Value for the x-axis of the first corner to draw a circle.");
RegisterPropertyVariable("Circle-Coords-X1", m_propCircleX1);
m_propCircleX2.SetDescription("Value for the x-axis of the second corner to draw a circle.");
RegisterPropertyVariable("Circle-Coords-X2", m_propCircleX2);
m_propCircleY1.SetDescription("Value for the y-axis of the first corner to draw a circle.");
RegisterPropertyVariable("Circle-Coords-Y1", m_propCircleY1);
m_propCircleY2.SetDescription("Value for the x-axis of the second corner to draw a circle.");
RegisterPropertyVariable("Circle-Coords-Y2", m_propCircleY2);
SetDescription("Use this Drawer to paint a simple circle onto the canvas.");
SetHelpLink("$(ADTF_DISPLAY_TOOLBOX_DIR)/doc/displaytoolbox_html/page_2d_example_drawer_readme.html");
}
tResult cExampleDrawer::Init(tInitStage eStage)
{
RETURN_IF_FAILED(cDrawer::Init(eStage));
RETURN_NOERROR;
}
tResult cExampleDrawer::Shutdown(tInitStage eStage)
{
RETURN_IF_FAILED(cDrawer::Shutdown(eStage));
RETURN_NOERROR;
}
tResult cExampleDrawer::Draw(const adtf::ucom::iobject_ptr<adtf::disptb::graphicslib::ICanvas>& pCanvas)
{
pCanvas->Color(
m_propColorRed,
m_propColorGreen,
m_propColorBlue
);
pCanvas->DrawCircle(
m_propCircleX1,
m_propCircleY1,
m_propCircleX2,
m_propCircleY2
);
RETURN_NOERROR;
}