Canvas: add chainable helpers to Path for adding segments.

This commit is contained in:
Thomas Geymayer
2013-05-31 19:16:04 +02:00
parent 13344fbb62
commit 2c879095d9
4 changed files with 107 additions and 2 deletions

View File

@@ -6,7 +6,11 @@ set(HEADERS
CanvasImage.hxx
CanvasMap.hxx
CanvasPath.hxx
CanvasText.hxx
CanvasText.hxx
)
set(DETAIL_HEADERS
detail/add_segment_variadic.hxx
)
set(SOURCES
@@ -18,4 +22,5 @@ set(SOURCES
CanvasText.cxx
)
simgear_scene_component(canvas-elements canvas/elements "${SOURCES}" "${HEADERS}")
simgear_scene_component(canvas-elements canvas/elements "${SOURCES}" "${HEADERS}")
simgear_component(canvas-elements/detail canvas/elements/detail "" "${DETAIL_HEADERS}")

View File

@@ -524,6 +524,60 @@ namespace canvas
return _path->getTransformedBounds(m);
}
//----------------------------------------------------------------------------
Path& Path::moveTo(float x_abs, float y_abs)
{
return addSegment(VG_MOVE_TO_ABS, x_abs, y_abs);
}
//----------------------------------------------------------------------------
Path& Path::move(float x_rel, float y_rel)
{
return addSegment(VG_MOVE_TO_REL, x_rel, y_rel);
}
//----------------------------------------------------------------------------
Path& Path::lineTo(float x_abs, float y_abs)
{
return addSegment(VG_LINE_TO_ABS, x_abs, y_abs);
}
//----------------------------------------------------------------------------
Path& Path::line(float x_rel, float y_rel)
{
return addSegment(VG_LINE_TO_REL, x_rel, y_rel);
}
//----------------------------------------------------------------------------
Path& Path::horizTo(float x_abs)
{
return addSegment(VG_HLINE_TO_ABS, x_abs);
}
//----------------------------------------------------------------------------
Path& Path::horiz(float x_rel)
{
return addSegment(VG_HLINE_TO_REL, x_rel);
}
//----------------------------------------------------------------------------
Path& Path::vertTo(float y_abs)
{
return addSegment(VG_VLINE_TO_ABS, y_abs);
}
//----------------------------------------------------------------------------
Path& Path::vert(float y_rel)
{
return addSegment(VG_VLINE_TO_REL, y_rel);
}
//----------------------------------------------------------------------------
Path& Path::close()
{
return addSegment(VG_CLOSE_PATH);
}
//----------------------------------------------------------------------------
void Path::childRemoved(SGPropertyNode* child)
{

View File

@@ -20,6 +20,7 @@
#define CANVAS_PATH_HXX_
#include "CanvasElement.hxx"
#include <boost/preprocessor/iteration/iterate.hpp>
namespace simgear
{
@@ -39,6 +40,30 @@ namespace canvas
virtual osg::BoundingBox getTransformedBounds(const osg::Matrix& m) const;
#define BOOST_PP_ITERATION_LIMITS (0, 6)
#define BOOST_PP_FILENAME_1 \
<simgear/canvas/elements/detail/add_segment_variadic.hxx>
#include BOOST_PP_ITERATE()
/** Move path cursor */
Path& moveTo(float x_abs, float y_abs);
Path& move(float x_rel, float y_rel);
/** Add a line */
Path& lineTo(float x_abs, float y_abs);
Path& line(float x_rel, float y_rel);
/** Add a horizontal line */
Path& horizTo(float x_abs);
Path& horiz(float x_rel);
/** Add a vertical line */
Path& vertTo(float y_abs);
Path& vert(float y_rel);
/** Close the path (implicit lineTo to first point of path) */
Path& close();
protected:
enum PathAttributes

View File

@@ -0,0 +1,21 @@
#ifndef CANVAS_PATH_HXX_
# error Canvas - do not include this file!
#endif
#define n BOOST_PP_ITERATION()
Path& addSegment( uint8_t cmd
BOOST_PP_COMMA_IF(n)
BOOST_PP_ENUM_PARAMS(n, float coord) )
{
_node->addChild("cmd")->setIntValue(cmd);
#define SG_CANVAS_PATH_SET_COORD(z, n, dummy)\
_node->addChild("coord")->setFloatValue(coord##n);
BOOST_PP_REPEAT(n, SG_CANVAS_PATH_SET_COORD, 0)
#undef SG_CANVAS_PATH_SET_COORD
return *this;
}
#undef n