#include "text_drawer.h"
#ifdef WIN32
#include <windows.h>
#undef CreateFont
#endif
ADTF_PLUGIN_VERSION("Demo 2D Text Drawer Plugin",
disptb,
DISPTB_VERSION_MAJOR,
DISPTB_VERSION_MINOR,
DISPTB_VERSION_PATCH,
cTextDrawer)
cTextDrawer::cTextDrawer() :
m_strText("Hello World!"),
m_strColor("#000000ff"),
m_bProjection(tTrue),
m_nFontSize(11),
m_nRotation(0)
{
m_strText.SetDescription("Text to display. Linebreaks with LF character are used as such.");
RegisterPropertyVariable("Text", m_strText);
m_strColor.SetDescription("Text color key in format #RRGGBBAA.");
RegisterPropertyVariable("Color", m_strColor);
m_bProjection.SetDescription("If enabled, scale and rotate the text according to the projection. Otherwise render projection-indepent.");
RegisterPropertyVariable("Projection", m_bProjection);
m_bFlip.SetDescription("If enabled, flip the text upside down");
RegisterPropertyVariable("Flip", m_bFlip);
m_nFontSize.SetDescription("Font size in pt.");
m_nFontSize.SetValidRange(1, 80);
RegisterPropertyVariable("Fontsize", m_nFontSize);
m_nRotation.SetDescription("Text rotation in degree.");
m_nRotation.SetValidRange(0, 360);
RegisterPropertyVariable("Rotation", m_nRotation);
SetDescription("Use this Drawer to paint a given string as pixels onto canvas.");
SetHelpLink("$(ADTF_DISPLAY_TOOLBOX_DIR)/doc/displaytoolbox_html/page_2d_text_drawer_readme.html");
}
tResult cTextDrawer::Init(tInitStage eStage)
{
RETURN_IF_FAILED(cDrawer::Init(eStage));
adtf_util::cString color = m_strColor;
RETURN_NOERROR;
}
tResult cTextDrawer::Shutdown(tInitStage eStage)
{
RETURN_IF_FAILED(cDrawer::Shutdown(eStage));
RETURN_NOERROR;
}
tResult cTextDrawer::Draw(const adtf::ucom::iobject_ptr<adtf::disptb::graphicslib::ICanvas>& pCanvas)
{
adtf_util::cString color = m_strColor;
adtf_util::cString text = m_strText;
pCanvas->Font(m_pFont);
pCanvas->SetFontAngle(*m_nRotation);
pCanvas->SetFlag(adtf::disptb::graphicslib::CANVAS_FLAG_TEXT_FLIP_HORIZONTALLY, *m_bFlip);
pCanvas->SetFlag(adtf::disptb::graphicslib::CANVAS_FLAG_TEXT_BASELINE_ON_TOP, tFalse);
pCanvas->SetFlag(adtf::disptb::graphicslib::CANVAS_FLAG_TEXT_SCALE_WITH_COORDINATE_SYSTEM, *m_bProjection);
pCanvas->SetFlag(adtf::disptb::graphicslib::CANVAS_FLAG_TEXT_ROTATE_WITH_COORDINATE_SYSTEM, *m_bProjection);
pCanvas->Color(&m_oColor);
pCanvas->OutputText(0, 0, "%s", text.GetPtr());
RETURN_NOERROR;
}
tResult cTextDrawer::ContextCreated(const adtf::ucom::iobject_ptr<adtf::disptb::graphicslib::ICanvas>& pCanvas)
{
RETURN_NOERROR;
}
tResult cTextDrawer::ContextDestroyed()
{
if(m_pFont)
{
delete m_pFont;
m_pFont = nullptr;
}
RETURN_NOERROR;
}
@ STYLE_Default
default font.
static tResult ColorFromString(const tChar *strColor, cColor &oColor)
Converts a hexadecimal color value into a cColor object The input format is like the HTML color defin...
Copyright © Audi Electronics Venture GmbH.
Copyright © Audi Electronics Venture GmbH.