#include "image_drawer.h"
ADTF_PLUGIN_VERSION("Demo 2D Image Drawer Plugin",
disptb,
DISPTB_VERSION_MAJOR,
DISPTB_VERSION_MINOR,
DISPTB_VERSION_PATCH,
cImageDrawer)
cImageDrawer::cImageDrawer():
m_strColor("#00000000"),
m_strPath(""),
m_bEnableAlpha(tFalse),
m_pTexture(nullptr),
m_bRecreateTexture(tFalse)
{
m_strColor.SetDescription("Color key for transparency.");
RegisterPropertyVariable("Color", m_strColor);
m_bEnableAlpha.SetDescription("Adjustment for the alpha channel.");
RegisterPropertyVariable("EnableAlpha", m_bEnableAlpha);
m_strPath.SetDescription("Image file to load.");
m_strPath.SetFilenameExtensionFilter("Bitmap(*.bmp)");
RegisterPropertyVariable("Path", m_strPath);
SetDescription("Use this Drawer to paint a given image onto the canvas.");
SetHelpLink("$(ADTF_DISPLAY_TOOLBOX_DIR)/doc/displaytoolbox_html/page_2d_image_drawer_readme.html");
}
tResult cImageDrawer::Init(tInitStage eStage)
{
RETURN_IF_FAILED(cDrawer::Init(eStage));
adtf_util::cString color = m_strColor;
m_bRecreateTexture = tTrue;
RETURN_NOERROR;
}
tResult cImageDrawer::Shutdown(tInitStage eStage)
{
RETURN_IF_FAILED(cDrawer::Shutdown(eStage));
RETURN_NOERROR;
}
tResult cImageDrawer::RecreateTexture(const adtf::ucom::iobject_ptr<adtf::disptb::graphicslib::ICanvas>& pCanvas)
{
DestroyTexture();
adtf_util::cString strPath = m_strPath;
if (strPath.IsEmpty())
{
LOG_WARNING("No Image specified");
RETURN_ERROR(ERR_NOT_FOUND);
}
tResult oError;
if (IS_FAILED(oError = oImage.
Load(strPath)))
{
adtf_util::cFilename strFilename(m_strPath);
if (!strFilename.GetExtension().IsEqualNoCase(".bmp"))
{
LOG_ERROR("Unsupported image format. See documentation for supported formats.");
}
else
{
LOG_ERROR("Error while loading Image");
}
return oError;
};
{
RETURN_IF_FAILED(pCanvas->CreateTexture(&oImage, m_pTexture));
}
RETURN_NOERROR;
}
tVoid cImageDrawer::DestroyTexture()
{
if (m_pTexture)
{
m_pTexture->Release();
m_pTexture = nullptr;
}
}
tResult cImageDrawer::Draw(const adtf::ucom::iobject_ptr<adtf::disptb::graphicslib::ICanvas>& pCanvas)
{
if (m_bRecreateTexture)
{
RecreateTexture(pCanvas);
m_bRecreateTexture = tFalse;
}
if (m_pTexture)
{
tFloat32 fWidth = (tFloat32)m_pTexture->GetWidth();
tFloat32 fHeight = (tFloat32)m_pTexture->GetHeight();
tFloat32 vPoints[8];
vPoints[0] = -fWidth / 2 + fWidth; vPoints[1] = -fHeight / 2;
vPoints[2] = -fWidth / 2 + fWidth; vPoints[3] = -fHeight / 2 + fHeight;
vPoints[4] = -fWidth / 2; vPoints[5] = -fHeight / 2 + fHeight;
vPoints[6] = -fWidth / 2; vPoints[7] = -fHeight / 2;
if (m_bEnableAlpha)
{
pCanvas->EnableAlpha();
}
pCanvas->DrawTexture(m_pTexture, vPoints);
if (m_bEnableAlpha)
{
pCanvas->DisableAlpha();
}
}
RETURN_NOERROR;
}
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...
Image and bitmap handling.
static tResult SetTransparency(disptb::graphicslib::dengar::cImage *pImage, disptb::graphicslib::dengar::cColor oColor)
Helper method for setting transparency in bitmaps.
tResult Load(const tChar *strFile, tUInt32 nFlags=0)
Loads an image from a file.
Copyright © Audi Electronics Venture GmbH.
Copyright © Audi Electronics Venture GmbH.