diff --git a/geometry.cpp b/geometry.cpp index df7980463e..3f89ab69c8 100644 --- a/geometry.cpp +++ b/geometry.cpp @@ -111,20 +111,6 @@ void GeomShape::Render(int x, int y) const } } -/*bool GeomShape::isOutlineClosed(const std::vector< Vector2 >& outline) const -{ - return outline -}*/ - -/*void GeomShape::dumpEdges() -{ - ofstream f("edges.dat"); - - for(unsigned int i=0;i* styles) { static FILLSTYLE* clearStyle=NULL; @@ -172,6 +158,7 @@ void GeomShape::TessellateGLU() gluTessCallback(tess,GLU_TESS_VERTEX_DATA,(void(*)())GLUCallbackVertex); gluTessCallback(tess,GLU_TESS_END_DATA,(void(*)())GLUCallbackEnd); gluTessCallback(tess,GLU_TESS_COMBINE_DATA,(void(*)())GLUCallbackCombine); + gluTessProperty(tess,GLU_TESS_WINDING_RULE,GLU_TESS_WINDING_ODD); //Let's create a vector of pointers to store temporary coordinates //passed to GLU @@ -261,14 +248,73 @@ void GeomShape::GLUCallbackCombine(GLdouble coords[3], void* vertex_data[4], *outData=obj->tmpVertices.back(); } -/*//Shape are compared using the minimum vertex -bool GeomShape::operator<(const GeomShape& r) const +void ShapesBuilder::joinOutlines() { - Vector2 vl=*min_element(outline.begin(),outline.end()); - Vector2 vr=*min_element(r.outline.begin(),r.outline.end()); + map< unsigned int, vector< vector > >::iterator it=shapesMap.begin(); + + for(;it!=shapesMap.end();it++) + { + vector< vector >& outlinesForColor=it->second; + //Repack outlines of the same color, avoiding excessive copying + for(int i=0;i=2); + //Already closed paths are ok + if(outlinesForColor[i].front()==outlinesForColor[i].back()) + continue; + for(int j=outlinesForColor.size()-1;j>=0;j--) + { + if(j==i || outlinesForColor[j].empty()) + continue; + if(outlinesForColor[i].front()==outlinesForColor[j].back()) + { + //Copy all the vertex but the origin in this one + outlinesForColor[j].insert(outlinesForColor[j].end(), + outlinesForColor[i].begin()+1, + outlinesForColor[i].end()); + //Invalidate the origin, but not the high level vector + outlinesForColor[i].clear(); + break; + } + } + } + } +} - if(vl >& outlinesForColor=shapesMap[color]; + //Search a suitable outline to attach this new vertex + for(unsigned int i=0;i=2); + if(outlinesForColor[i].front()==outlinesForColor[i].back()) + continue; + if(outlinesForColor[i].back()==v1) + { + outlinesForColor[i].push_back(v2); + return; + } + } + //No suitable outline found, create one + outlinesForColor.push_back(vector()); + outlinesForColor.back().reserve(2); + outlinesForColor.back().push_back(v1); + outlinesForColor.back().push_back(v2); +} + +void ShapesBuilder::outputShapes(vector< GeomShape >& shapes) +{ + //Let's join shape pieces together + joinOutlines(); + + map< unsigned int, vector< vector > >::iterator it=shapesMap.begin(); + + for(;it!=shapesMap.end();it++) + { + shapes.push_back(GeomShape()); + shapes.back().outlines.swap(it->second); + shapes.back().color=it->first; + } +} \ No newline at end of file diff --git a/geometry.h b/geometry.h index 67b28e4fc1..41eb1356fa 100644 --- a/geometry.h +++ b/geometry.h @@ -22,9 +22,7 @@ #include #include #include -/*#ifdef WIN32 -#include -#endif*/ +#include #include namespace lightspark @@ -72,7 +70,6 @@ friend class DefineShape3Tag; void SetStyles(const std::list* styles); const FILLSTYLE* style; arrayElem* varray; - bool isOutlineClosed(const std::vector& outline) const; bool hasFill; public: GeomShape():curTessTarget(0),style(NULL),varray(NULL),hasFill(false),color(0){} @@ -84,14 +81,18 @@ friend class DefineShape3Tag; unsigned int color; - //DEBUG - void dumpEdges(); - void Render(int x=0, int y=0) const; void BuildFromEdges(const std::list* styles); +}; - bool operator<(const GeomShape& r) const; - +class ShapesBuilder +{ +private: + std::map< unsigned int, std::vector< std::vector > > shapesMap; + void joinOutlines(); +public: + void extendOutlineForColor(unsigned int color, const Vector2& v1, const Vector2& v2); + void outputShapes(std::vector& shapes); }; class GlyphShape: public GeomShape diff --git a/tags.cpp b/tags.cpp index 2fb06dc434..98affd5655 100644 --- a/tags.cpp +++ b/tags.cpp @@ -1058,133 +1058,6 @@ void DefineShape3Tag::Render() glPopMatrix(); } -void FromShaperecordListToDump(SHAPERECORD* cur) -{ - ofstream f("record_dump"); - - int startX=0; - int startY=0; - - while(cur) - { - if(cur->TypeFlag) - { - if(cur->StraightFlag) - { - startX+=cur->DeltaX; - startY+=cur->DeltaY; - f << startX << ' ' << startY << endl; - } - else - { - startX+=cur->ControlDeltaX; - startY+=cur->ControlDeltaY; - f << startX << ' ' << startY << endl; - - startX+=cur->AnchorDeltaX; - startY+=cur->AnchorDeltaY; - f << startX << ' ' << startY << endl; - } - } - else - { - if(cur->StateMoveTo) - { - startX=cur->MoveDeltaX; - startY=cur->MoveDeltaY; - f << "//Move To" << endl; - f << startX << ' ' << startY << endl; - } - if(cur->StateLineStyle) - { - f << "//LS=" << cur->LineStyle << endl; - } - if(cur->StateFillStyle1) - { - f << "//FS1=" << cur->FillStyle1 << endl; - } - if(cur->StateFillStyle0) - { - f << "//FS0=" << cur->FillStyle0 << endl; - } - } - cur=cur->next; - } - f.close(); -} - -class ShapesBuilder -{ -private: - map< unsigned int, vector< vector > > shapesMap; -public: - void extendOutlineForColor(unsigned int color, const Vector2& v1, const Vector2& v2) - { - assert(color); - vector< vector >& outlinesForColor=shapesMap[color]; - //Search a suitable outline to attach this new vertex - for(unsigned int i=0;i=2); - if(outlinesForColor[i].front()==outlinesForColor[i].back()) - continue; - if(outlinesForColor[i].back()==v1) - { - outlinesForColor[i].push_back(v2); - return; - } - } - //No suitable outline found, create one - outlinesForColor.push_back(vector()); - outlinesForColor.back().reserve(2); - outlinesForColor.back().push_back(v1); - outlinesForColor.back().push_back(v2); - } - void joinOutlines() - { - map< unsigned int, vector< vector > >::iterator it=shapesMap.begin(); - - for(;it!=shapesMap.end();it++) - { - vector< vector >& outlinesForColor=it->second; - //Repack outlines of the same color, avoiding excessive copying - for(int i=0;i=2); - //Already closed paths are ok - if(outlinesForColor[i].front()==outlinesForColor[i].back()) - continue; - for(int j=outlinesForColor.size()-1;j>=0;j--) - { - if(j==i || outlinesForColor[j].empty()) - continue; - if(outlinesForColor[i].front()==outlinesForColor[j].back()) - { - //Copy all the vertex but the origin in this one - outlinesForColor[j].insert(outlinesForColor[j].end(), - outlinesForColor[i].begin()+1, - outlinesForColor[i].end()); - //Invalidate the origin, but not the high level vector - outlinesForColor[i].clear(); - break; - } - } - } - } - } - void outputShapes(vector& shapes) - { - map< unsigned int, vector< vector > >::iterator it=shapesMap.begin(); - - for(;it!=shapesMap.end();it++) - { - shapes.push_back(GeomShape()); - shapes.back().outlines.swap(it->second); - shapes.back().color=it->first; - } - } -}; - /*! \brief Generate a vector of shapes from a SHAPERECORD list * * \param cur SHAPERECORD list head * * \param shapes a vector to be populated with the shapes */ @@ -1260,9 +1133,6 @@ void lightspark::FromShaperecordListToShapeVector(SHAPERECORD* cur, vectornext; } - //Let's join shape pieces together - shapesBuilder.joinOutlines(); - shapesBuilder.outputShapes(shapes); }