Skip to content

Commit

Permalink
updated internal path-drawing to reflect changes in of core
Browse files Browse the repository at this point in the history
  • Loading branch information
bgstaal committed Jun 1, 2013
1 parent 927e834 commit c56a699
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 34 deletions.
13 changes: 12 additions & 1 deletion example/src/testApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,16 @@ void testApp::_createStar()
float rad = i % 2 == 0 ? r2 : r;

ofPoint p(cos(angleStep*i)*rad, sin(angleStep*i)*rad);
_star.lineTo(p);

if (i == 0)
{
_star.moveTo(p);
}
else
{
_star.lineTo(p);
}

}

_star.close();
Expand Down Expand Up @@ -171,11 +180,13 @@ void testApp::keyPressed(int key)
{
if (_shivaVGRenderer->getLineCapStyle() == VG_CAP_ROUND)
{
cout << "cap square" << endl;
_shivaVGRenderer->setLineCapStyle(VG_CAP_SQUARE);
_shivaVGRenderer->setLineJoinStyle(VG_JOIN_MITER);
}
else
{
cout << "cap round" << endl;
_shivaVGRenderer->setLineCapStyle(VG_CAP_ROUND);
_shivaVGRenderer->setLineJoinStyle(VG_JOIN_ROUND);
}
Expand Down
54 changes: 22 additions & 32 deletions src/ofxShivaVGRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,10 @@ void ofxShivaVGRenderer::draw(ofPath &path)

// TODO: fill or stroke?

vector<ofSubPath> & paths = path.getSubPaths();
// vector<ofSubPath> & paths = path.getSubPaths();

simpleVGPath p;

for(int i=0;i<(int)paths.size();i++)
{
_draw(paths[i], p);
}
_doDrawPath(path, p);

ofColor prevColor;
if(path.getUseShapeColor()) prevColor = style.color;
Expand Down Expand Up @@ -138,37 +134,29 @@ void ofxShivaVGRenderer::draw(ofPath &path)
if(path.getUseShapeColor()) setColor(prevColor);
}

void ofxShivaVGRenderer::_draw(ofSubPath &path, simpleVGPath &p)
void ofxShivaVGRenderer::_doDrawPath(ofPath &path, simpleVGPath &p)
{
const vector<ofSubPath::Command> & commands = path.getCommands();
const vector<ofPath::Command> &commands = path.getCommands();

int i = 0;

for(vector<ofSubPath::Command>::const_iterator c = commands.begin(); c != commands.end(); ++c)
for(vector<ofPath::Command>::const_iterator c = commands.begin(); c != commands.end(); ++c)
{
switch(c->type)
{
case ofSubPath::Command::lineTo:
case ofPath::Command::moveTo:
p.moveTo(c->to.x, c->to.y);
_curvePoints.push_back(c->to);
break;

_curvePoints.clear();
case ofPath::Command::lineTo:

if (i == 0)
{
// if the first command in a subPath is a lineTo it should be
// interpeted as a moveTo command
// this makes up for the lack of a moveTo command in ofSubPath

p.moveTo(c->to.x, c->to.y);
_curvePoints.push_back(c->to);
}
else
{
p.lineTo(c->to.x, c->to.y);
}
_curvePoints.clear();
p.lineTo(c->to.x, c->to.y);

break;

case ofSubPath::Command::curveTo:
case ofPath::Command::curveTo:

_curvePoints.push_back(c->to);

Expand All @@ -191,29 +179,31 @@ void ofxShivaVGRenderer::_draw(ofSubPath &path, simpleVGPath &p)

break;

case ofSubPath::Command::bezierTo:
case ofPath::Command::bezierTo:
_curvePoints.clear();
p.cubicTo(c->cp1.x, c->cp1.y, c->cp2.x, c->cp2.y, c->to.x, c->to.y);
break;

case ofSubPath::Command::quadBezierTo:
case ofPath::Command::quadBezierTo:
_curvePoints.clear();
p.cubicTo(c->cp1.x, c->cp1.y, c->cp2.x, c->cp2.y, c->to.x, c->to.y);
break;

case ofSubPath::Command::arc:
ofLog(OF_LOG_WARNING, "Arcs are not implemented in the ofxShivaRenderer yet. Sory :-(");
case ofPath::Command::arc:
ofLog(OF_LOG_WARNING, "Arcs are not implemented in the ofxShivaRenderer yet. Sorry :-(");
break;

case ofSubPath::Command::arcNegative:
case ofPath::Command::arcNegative:
ofLog(OF_LOG_WARNING, "Arcs are not implemented in the ofxShivaRenderer yet. Sorry :-(");
break;

case ofPath::Command::close:
p.close();
break;
}

i++;
}

if (path.isClosed()) p.close();
}


Expand Down
2 changes: 1 addition & 1 deletion src/ofxShivaVGRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class ofxShivaVGRenderer : public ofGLRenderer
deque<ofPoint> _curvePoints;
ofFloatColor _bgColor;

void _draw(ofSubPath &path, simpleVGPath &toPath);
void _doDrawPath(ofPath &path, simpleVGPath &toPath);

};

Expand Down

0 comments on commit c56a699

Please sign in to comment.