#include "gcl_drawer.h"
using namespace adtf_util;
using namespace ddl;
using namespace adtf::ucom;
using namespace adtf::base;
using namespace adtf::streaming;
using namespace adtf::mediadescription;
using namespace adtf::filter;
using namespace adtf::disptb::graphicslib;
cGCLDrawer::cGCLDrawer()
{
m_strFontName.SetDescription("Font to use for the overlay.");
RegisterPropertyVariable("font/name", m_strFontName);
m_nSmallFontSize.SetDescription("Size for the small font overlay.");
RegisterPropertyVariable("font/size/small", m_nSmallFontSize);
m_nMediumFontSize.SetDescription("Size for the medium font overlay.");
RegisterPropertyVariable("font/size/medium", m_nMediumFontSize);
m_nHugeFontSize.SetDescription("Size for the huge font overlay.");
RegisterPropertyVariable("font/size/huge", m_nHugeFontSize);
m_bFlipTextHorizontally.SetDescription(
"Whether the text direction will be with or opposed "
"the x-axis direction (false: with the x-axis direction, true: opposed the x-axis direction).");
RegisterPropertyVariable("flip_text_horizontally", m_bFlipTextHorizontally);
object_ptr<IStreamType> pType = make_object_ptr<cStreamType>(stream_meta_type_gcl());
create_pin(*this, m_oReader, "in1", pType);
SetDescription("in1", "Input pin for GCL commands.");
SetDescription("Use this Drawer to paint a received GCL-Commands onto the canvas.");
SetHelpLink("$(ADTF_DISPLAY_TOOLBOX_DIR)/doc/html/page_2d_gcl_drawer_readme.html");
}
tResult cGCLDrawer::Init(tInitStage eStage)
{
RETURN_IF_FAILED(cDrawer::Init(eStage));
RETURN_NOERROR;
}
tResult cGCLDrawer::Shutdown(tInitStage eStage)
{
RETURN_IF_FAILED(cDrawer::Shutdown(eStage));
RETURN_NOERROR;
}
tResult cGCLDrawer::Draw(const adtf::ucom::iobject_ptr<adtf::disptb::graphicslib::ICanvas>& pCanvas)
{
const auto pPreviousSample = m_pLastSample;
if (IS_FAILED(m_oReader.GetLastSample(m_pLastSample)) || !m_pLastSample)
{
m_pLastSample.Reset();
m_oGCLBlock.Free();
}
if (m_pLastSample != pPreviousSample)
{
GetGCLBlockFromSample(m_pLastSample);
}
if (m_oGCLBlock.GetSize() > 0)
{
pCanvas->EnableAlpha();
cRect rcArea(0, 0, 0, 0);
pCanvas->PushFlags();
m_oGCLProcessor.Process(pCanvas.Get(), m_oGCLBlock.GetPtr(), static_cast<tInt>(m_oGCLBlock.GetSize()), 0, 0,
rcArea);
pCanvas->PopFlags();
pCanvas->DisableAlpha();
}
RETURN_NOERROR;
}
tResult cGCLDrawer::ContextCreated(const adtf::ucom::iobject_ptr<adtf::disptb::graphicslib::ICanvas>& pCanvas)
{
RETURN_IF_FAILED(CreateFonts(pCanvas));
RETURN_NOERROR;
}
tInt cGCLDrawer::GetGCLBlockFromSample(const adtf::ucom::iobject_ptr<const adtf::streaming::ISample>& pSample)
{
tInt nCmdSize = -1;
adtf::ucom::object_ptr_shared_locked<const adtf::streaming::ISampleBuffer> pBuffer;
if (IS_OK(pSample->Lock(pBuffer)))
{
nCmdSize = (tInt) pBuffer->GetSize();
if (nCmdSize > 0)
{
pBuffer->Read(adtf_memory_intf(m_oGCLBlock));
}
else
{
m_oGCLBlock.Free();
}
}
return nCmdSize;
}
tResult cGCLDrawer::CreateFonts(const adtf::ucom::iobject_ptr<adtf::disptb::graphicslib::ICanvas>& pCanvas)
{
cString strFontName = m_strFontName;
strFontName = strFontName.IsNotEmpty() ? strFontName : cString("Arial");
tInt nSmallSize = m_nSmallFontSize;
nSmallSize = nSmallSize > 0 ? nSmallSize : 11;
tInt nMediumSize = m_nMediumFontSize;
nMediumSize = nMediumSize > 0 ? nMediumSize : 16;
tInt nHugeSize = m_nHugeFontSize;
nHugeSize = nHugeSize > 0 ? nHugeSize : 24;
RETURN_IF_FAILED(m_oGCLProcessor.SetFonts(m_pSmallFont.get(), m_pNormalFont.get(), m_pHugeFont.get()));
RETURN_NOERROR;
}
@ STYLE_Default
default font.
Copyright © Audi Electronics Venture GmbH.
@ CANVAS_FLAG_TEXT_BASELINE_ON_TOP
Set the text baseline on top of the text (0: baseline is on button of a glyphe, 1: baseline is on top...
@ CANVAS_FLAG_TEXT_FLIP_HORIZONTALLY
Set the text direction with or opposed the x-axis direction (0: with the x-axis direction,...
@ CANVAS_FLAG_TEXT_ROTATE_WITH_COORDINATE_SYSTEM
Set the text to scale with the level of zoom.
@ CANVAS_FLAG_TEXT_SCALE_WITH_COORDINATE_SYSTEM
Set the text to scale with the coordinatesystem.
#include "createobject_filter.h"
#include <cmath>
using namespace adtf_util;
using namespace ddl;
using namespace adtf::ucom;
using namespace adtf::base;
using namespace adtf::streaming;
using namespace adtf::mediadescription;
using namespace adtf::filter;
using namespace adtf::disptb::graphicslib;
cObjectGenerator::cObjectGenerator()
{
CreateRunner("object_trigger", cTimerTriggerHint(std::chrono::milliseconds{100}));
SetDescription("object_trigger", "Runner to periodically trigger the function which generates the GCL commands.");
object_ptr<IStreamType> pStreamType = make_object_ptr<cStreamType>(stream_meta_type_gcl());
m_oPinWriter = CreateOutputPin("out_GCLList", pStreamType);
SetDescription("out_GCLList", "Output pin for generated GCL commands.");
SetDescription("Use this Filter to create GCL commands.");
SetHelpLink("$(ADTF_DISPLAY_TOOLBOX_DIR)/doc/html/page_2d_gcl_drawer_readme.html");
}
cObjectGenerator::~cObjectGenerator()
{
}
tResult cObjectGenerator::Process(adtf::base::tNanoSeconds tmTimeOfTrigger, adtf::streaming::IRunner* )
{
RETURN_IF_FAILED(CreateObjects(tmTimeOfTrigger));
RETURN_NOERROR;
}
tResult cObjectGenerator::CreateObjects(adtf::base::tNanoSeconds tmTimeOfTrigger)
{
m_pCommandBlock->Reset();
cString strText = "red text in rectangle";
strText = "small blue text";
strText = "medium red text";
strText = "huge black text";
{
constexpr tInt nX = -50;
constexpr tInt nY = 50;
constexpr tInt nRadius = 30;
constexpr tUInt64 nTicksPerSecond = 1000000000;
constexpr tUInt64 nTicksPerMinute = 60000000000;
constexpr tFloat64 fTwoPi = 2 * 3.14159265358979311600;
nX + static_cast<tInt>(std::sin((tmTimeOfTrigger.nCount % nTicksPerSecond) * fTwoPi / nTicksPerSecond) *
nRadius),
nY + static_cast<tInt>(std::cos((tmTimeOfTrigger.nCount % nTicksPerSecond) * fTwoPi / nTicksPerSecond) *
nRadius));
nX + static_cast<tInt>(std::sin((tmTimeOfTrigger.nCount % nTicksPerMinute) * fTwoPi / nTicksPerMinute) *
nRadius),
nY + static_cast<tInt>(std::cos((tmTimeOfTrigger.nCount % nTicksPerMinute) * fTwoPi / nTicksPerMinute) *
nRadius));
}
object_ptr<ISample> pSample;
RETURN_IF_FAILED(alloc_sample(pSample, tmTimeOfTrigger));
{
object_ptr_locked<ISampleBuffer> pBuffer;
RETURN_IF_FAILED(pSample->WriteLock(pBuffer, m_pCommandBlock->GetSize()));
pBuffer->Write(adtf_memory_buffer<tVoid>(m_pCommandBlock->GetPtr(), m_pCommandBlock->GetSize()));
}
m_oPinWriter->Write(pSample);
RETURN_NOERROR;
}
static tResult GetDynamicMemoryBlock(IDynamicMemoryBlock *&pCommandBlock)
Creates and returns a pointer to the IDynamicMemoryBlock interface.
static tResult StoreData(tUInt32 *&pCommandBlock, tUInt32 nParam)
Stores one tUInt32 in the buffer.
static tResult FreeDynamicMemoryBlock(IDynamicMemoryBlock *&pCommandBlock)
Deallocates or frees a dynamic memory block.
static tResult StoreCommand(tUInt32 *&pCommandBlock, tUInt32 nCommandId)
Stores a GCL command in the buffer.
Copyright © Audi Electronics Venture GmbH.
@ GCL_CMD_LINEWIDTH
Sets width for line drawing operations.
@ GCL_CMD_DRAWCIRCLE
Draws a circle at the specified point and with the given diameter.
@ GCL_CMD_TEXT_SIZE_HUGE
Sets current font to huge font.
@ GCL_CMD_TEXT_SIZE_SMALL
Sets current font to small font.
@ GCL_CMD_DRAWLINE
Draws a line between the specified points.
@ GCL_CMD_TEXT_SIZE_NORMAL
Sets current font to normal font.
@ GCL_CMD_LINETO
Draws a line from the current position to the specified coordinate.
@ GCL_CMD_FGCOL
Sets foreground color.
@ GCL_CMD_END
Marks the end of the GCL buffer.
@ GCL_CMD_FILLRECT
Draws a filled rectangle.
@ GCL_CMD_MOVETO
Moves the drawing cursor to the specified coordinate.
@ GCL_CMD_TEXT
Generates text output at specified coordinate.