#include "coord_space_drawer.h"
ADTF_PLUGIN_VERSION("Demo 2D Coordinate Space Drawer Plugin",
disptb,
DISPTB_VERSION_MAJOR,
DISPTB_VERSION_MINOR,
DISPTB_VERSION_PATCH,
cCoordSpaceDrawer)
cCoordSpaceDrawer::cCoordSpaceDrawer()
{
m_fRange.SetDescription("Range for drawing.");
RegisterPropertyVariable("range", m_fRange);
m_fStep.SetDescription("Step for drawing.");
RegisterPropertyVariable("step", m_fStep);
m_bGrid.SetDescription("If enabled, the grid is visible");
RegisterPropertyVariable("grid", m_bGrid);
SetDescription("Use this Drawer to paint a grid based coordinate system onto the canvas.");
SetHelpLink("$(ADTF_DISPLAY_TOOLBOX_DIR)/doc/displaytoolbox_html/page_2d_coordinate_space_drawer_readme.html");
}
tResult cCoordSpaceDrawer::Init(tInitStage eStage)
{
RETURN_IF_FAILED(cDrawer::Init(eStage));
RETURN_NOERROR;
}
tResult cCoordSpaceDrawer::Shutdown(tInitStage eStage)
{
RETURN_IF_FAILED(cDrawer::Shutdown(eStage));
RETURN_NOERROR;
}
tResult cCoordSpaceDrawer::Draw(const adtf::ucom::iobject_ptr<adtf::disptb::graphicslib::ICanvas>& o_pCanvas)
{
tInt nSteps = (tInt)(m_fRange / m_fStep);
o_pCanvas->Color(192, 192, 192);
if (m_bGrid)
{
tFloat32 iLen = m_fRange;
for (tInt i = 0; i <= nSteps; i++)
{
tFloat32 iStep = i * m_fStep;
o_pCanvas->DrawLine(iStep, -iLen, iStep, iLen);
o_pCanvas->DrawLine(-iLen, iStep, iLen, iStep);
o_pCanvas->DrawLine(-iStep, -iLen, -iStep, iLen);
o_pCanvas->DrawLine(-iLen, -iStep, iLen, -iStep);
}
}
o_pCanvas->Color(0, 0, 0);
o_pCanvas->DrawLine(tInt(-m_fRange), 0, tInt(m_fRange), 0);
o_pCanvas->DrawLine(0, tInt(-m_fRange), 0, tInt(m_fRange));
for (tInt i = 0; i <= nSteps; i++)
{
tFloat32 iLen = (i % 5 == 0) ? (tFloat32) 4.0 : (tFloat32) 2.0;
iLen = (i % 10 == 0) ? 6 : iLen;
tFloat32 iStep = i * m_fStep;
o_pCanvas->DrawLine(iStep, 0.0, iStep, iLen);
o_pCanvas->DrawLine(0.0, iStep, iLen, iStep);
o_pCanvas->DrawLine(-iStep, 0.0, -iStep, iLen);
o_pCanvas->DrawLine(0.0, -iStep, iLen, -iStep);
}
RETURN_NOERROR;
}