]> git.mxchange.org Git - simgear.git/commitdiff
Canvas: add chainable helpers to Path for adding segments.
authorThomas Geymayer <tomgey@gmail.com>
Fri, 31 May 2013 17:16:04 +0000 (19:16 +0200)
committerThomas Geymayer <tomgey@gmail.com>
Fri, 31 May 2013 17:16:42 +0000 (19:16 +0200)
simgear/canvas/elements/CMakeLists.txt
simgear/canvas/elements/CanvasPath.cxx
simgear/canvas/elements/CanvasPath.hxx
simgear/canvas/elements/detail/add_segment_variadic.hxx [new file with mode: 0644]

index 6e5c2e93c1f57592a8632ea30c84023761a4adac..bd21c13d8fb123b89a49986dbdc6f8b57cd10a9a 100644 (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}")
\ No newline at end of file
+simgear_scene_component(canvas-elements canvas/elements "${SOURCES}" "${HEADERS}")
+simgear_component(canvas-elements/detail canvas/elements/detail "" "${DETAIL_HEADERS}")
\ No newline at end of file
index a62ab0803e2921ac1096f339e8d3a0a93833e235..5e9efa083b9e820655c8586764ead75caa5ef2a5 100644 (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)
   {
index 706f8cd715f53dda5ce17f120c6af57f0a2d5040..de7c65240d5cf8dffb728e765b8ddec8e7777961 100644 (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
diff --git a/simgear/canvas/elements/detail/add_segment_variadic.hxx b/simgear/canvas/elements/detail/add_segment_variadic.hxx
new file mode 100644 (file)
index 0000000..cb4f434
--- /dev/null
@@ -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