]> git.mxchange.org Git - simgear.git/blobdiff - simgear/canvas/elements/CanvasPath.cxx
Canvas: add chainable helpers to Path for adding segments.
[simgear.git] / simgear / canvas / elements / CanvasPath.cxx
index 9fde6782480117cce5eb7930edc271b18efc68d0..5e9efa083b9e820655c8586764ead75caa5ef2a5 100644 (file)
@@ -429,6 +429,9 @@ namespace canvas
        */
       void update()
       {
+        if( !vgHasContextSH() )
+          return;
+
         if( _attributes_dirty & PATH )
         {
           const VGbitfield caps = VG_PATH_CAPABILITY_APPEND_TO
@@ -476,14 +479,18 @@ namespace canvas
     _path( new PathDrawable(this) )
   {
     setDrawable(_path);
-    PathDrawable *path = _path.get();
 
-    addStyle("fill", &PathDrawable::setFill, path);
-    addStyle("fill-rule", &PathDrawable::setFillRule, path);
-    addStyle("stroke", &PathDrawable::setStroke, path);
-    addStyle("stroke-width", &PathDrawable::setStrokeWidth, path);
-    addStyle("stroke-dasharray", &PathDrawable::setStrokeDashArray, path);
-    addStyle("stroke-linecap", &PathDrawable::setStrokeLinecap, path);
+    if( !isInit<Path>() )
+    {
+      PathDrawableRef Path::*path = &Path::_path;
+
+      addStyle("fill", "color", &PathDrawable::setFill, path);
+      addStyle("fill-rule", "", &PathDrawable::setFillRule, path);
+      addStyle("stroke", "color", &PathDrawable::setStroke, path);
+      addStyle("stroke-width", "numeric", &PathDrawable::setStrokeWidth, path);
+      addStyle("stroke-dasharray", "", &PathDrawable::setStrokeDashArray, path);
+      addStyle("stroke-linecap", "", &PathDrawable::setStrokeLinecap, path);
+    }
 
     setupStyle();
   }
@@ -517,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)
   {