#include <simgear/scene/util/parse_color.hxx>
#include <osg/Drawable>
-#include <osg/BlendFunc>
#include <vg/openvg.h>
#include <cassert>
*/
void setFill(const std::string& fill)
{
- if( fill == "none" )
+ if( fill.empty() || fill == "none" )
{
_mode &= ~VG_FILL_PATH;
}
*/
void setStroke(const std::string& stroke)
{
- if( stroke == "none" )
+ if( stroke.empty() || stroke == "none" )
{
_mode &= ~VG_STROKE_PATH;
}
{
osg::BoundingBox bb;
- osg::Vec2f cur; // VG "Current point" (in local coordinates)
+ osg::Vec2f cur(0, 0), // VG "Current point" (in local coordinates)
+ sub(0, 0); // beginning of current sub path
VGubyte cmd_index = 0;
for( size_t i = 0, ci = 0;
i < _cmds.size() && ci < _coords.size();
switch( cmd )
{
case VG_CLOSE_PATH:
+ cur = sub;
break;
case VG_MOVE_TO:
case VG_LINE_TO:
}
if( num_coords > 0 )
+ {
cur = points[ num_coords - 1 ];
+
+ if( cmd == VG_MOVE_TO )
+ sub = cur;
+ }
}
return bb;
*/
void update()
{
+ if( !vgHasContextSH() )
+ return;
+
if( _attributes_dirty & PATH )
{
const VGbitfield caps = VG_PATH_CAPABILITY_APPEND_TO
};
};
+ //----------------------------------------------------------------------------
+ const std::string Path::TYPE_NAME = "path";
+
+ //----------------------------------------------------------------------------
+ void Path::staticInit()
+ {
+ if( isInit<Path>() )
+ return;
+
+ 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);
+ }
+
//----------------------------------------------------------------------------
Path::Path( const CanvasWeakPtr& canvas,
const SGPropertyNode_ptr& node,
Element(canvas, node, parent_style, parent),
_path( new PathDrawable(this) )
{
- setDrawable(_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);
- }
+ staticInit();
+ setDrawable(_path);
setupStyle();
}
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)
{