canvas: Refactor Path::addSegment with std::initializer_list
This commit is contained in:
@@ -9,10 +9,6 @@ set(HEADERS
|
|||||||
CanvasText.hxx
|
CanvasText.hxx
|
||||||
)
|
)
|
||||||
|
|
||||||
set(DETAIL_HEADERS
|
|
||||||
detail/add_segment_variadic.hxx
|
|
||||||
)
|
|
||||||
|
|
||||||
set(SOURCES
|
set(SOURCES
|
||||||
CanvasElement.cxx
|
CanvasElement.cxx
|
||||||
CanvasGroup.cxx
|
CanvasGroup.cxx
|
||||||
@@ -23,7 +19,6 @@ set(SOURCES
|
|||||||
)
|
)
|
||||||
|
|
||||||
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}")
|
|
||||||
|
|
||||||
add_boost_test(canvas_element
|
add_boost_test(canvas_element
|
||||||
SOURCES canvas_element_test.cpp
|
SOURCES canvas_element_test.cpp
|
||||||
|
|||||||
@@ -740,52 +740,63 @@ namespace canvas
|
|||||||
return _path->getTransformedBounds(m);
|
return _path->getTransformedBounds(m);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
|
Path& Path::addSegment(uint8_t cmd, std::initializer_list<float> coords)
|
||||||
|
{
|
||||||
|
_node->addChild("cmd")->setIntValue(cmd);
|
||||||
|
|
||||||
|
for(float coord: coords)
|
||||||
|
_node->addChild("coord")->setFloatValue(coord);
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
Path& Path::moveTo(float x_abs, float y_abs)
|
Path& Path::moveTo(float x_abs, float y_abs)
|
||||||
{
|
{
|
||||||
return addSegment(VG_MOVE_TO_ABS, x_abs, y_abs);
|
return addSegment(VG_MOVE_TO_ABS, {x_abs, y_abs});
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
Path& Path::move(float x_rel, float y_rel)
|
Path& Path::move(float x_rel, float y_rel)
|
||||||
{
|
{
|
||||||
return addSegment(VG_MOVE_TO_REL, x_rel, y_rel);
|
return addSegment(VG_MOVE_TO_REL, {x_rel, y_rel});
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
Path& Path::lineTo(float x_abs, float y_abs)
|
Path& Path::lineTo(float x_abs, float y_abs)
|
||||||
{
|
{
|
||||||
return addSegment(VG_LINE_TO_ABS, x_abs, y_abs);
|
return addSegment(VG_LINE_TO_ABS, {x_abs, y_abs});
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
Path& Path::line(float x_rel, float y_rel)
|
Path& Path::line(float x_rel, float y_rel)
|
||||||
{
|
{
|
||||||
return addSegment(VG_LINE_TO_REL, x_rel, y_rel);
|
return addSegment(VG_LINE_TO_REL, {x_rel, y_rel});
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
Path& Path::horizTo(float x_abs)
|
Path& Path::horizTo(float x_abs)
|
||||||
{
|
{
|
||||||
return addSegment(VG_HLINE_TO_ABS, x_abs);
|
return addSegment(VG_HLINE_TO_ABS, {x_abs});
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
Path& Path::horiz(float x_rel)
|
Path& Path::horiz(float x_rel)
|
||||||
{
|
{
|
||||||
return addSegment(VG_HLINE_TO_REL, x_rel);
|
return addSegment(VG_HLINE_TO_REL, {x_rel});
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
Path& Path::vertTo(float y_abs)
|
Path& Path::vertTo(float y_abs)
|
||||||
{
|
{
|
||||||
return addSegment(VG_VLINE_TO_ABS, y_abs);
|
return addSegment(VG_VLINE_TO_ABS, {y_abs});
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
Path& Path::vert(float y_rel)
|
Path& Path::vert(float y_rel)
|
||||||
{
|
{
|
||||||
return addSegment(VG_VLINE_TO_REL, y_rel);
|
return addSegment(VG_VLINE_TO_REL, {y_rel});
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -20,8 +20,8 @@
|
|||||||
#define CANVAS_PATH_HXX_
|
#define CANVAS_PATH_HXX_
|
||||||
|
|
||||||
#include "CanvasElement.hxx"
|
#include "CanvasElement.hxx"
|
||||||
#include <boost/preprocessor/iteration/iterate.hpp>
|
|
||||||
#include <simgear/math/SGRect.hxx>
|
#include <simgear/math/SGRect.hxx>
|
||||||
|
#include <initializer_list>
|
||||||
|
|
||||||
namespace simgear
|
namespace simgear
|
||||||
{
|
{
|
||||||
@@ -44,10 +44,8 @@ namespace canvas
|
|||||||
|
|
||||||
virtual osg::BoundingBox getTransformedBounds(const osg::Matrix& m) const;
|
virtual osg::BoundingBox getTransformedBounds(const osg::Matrix& m) const;
|
||||||
|
|
||||||
#define BOOST_PP_ITERATION_LIMITS (0, 6)
|
/** Add a segment with the given command and coordinates */
|
||||||
#define BOOST_PP_FILENAME_1 \
|
Path& addSegment(uint8_t cmd, std::initializer_list<float> coords = {});
|
||||||
<simgear/canvas/elements/detail/add_segment_variadic.hxx>
|
|
||||||
#include BOOST_PP_ITERATE()
|
|
||||||
|
|
||||||
/** Move path cursor */
|
/** Move path cursor */
|
||||||
Path& moveTo(float x_abs, float y_abs);
|
Path& moveTo(float x_abs, float y_abs);
|
||||||
|
|||||||
@@ -1,21 +0,0 @@
|
|||||||
#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
|
|
||||||
Reference in New Issue
Block a user