src/RendererUtils.hpp
// Converts SSB path to cairo path
Converts SSB path to cairo path
Converts SSB path to cairo path
inline void path_to_cairo(SSBPath* path, cairo_t* ctx){
        const std::vector<SSBPath::Segment>& segments = path->segments;
            for(size_t i = 0; i < segments.size();)
                switch(segments[i].type){
                    case SSBPath::SegmentType::MOVE_TO:
                        cairo_move_to(ctx, segments[i].point.x, segments[i].point.y);
                        ++i;
                        break;
                    case SSBPath::SegmentType::LINE_TO:
                        cairo_line_to(ctx, segments[i].point.x, segments[i].point.y);
                        ++i;
                        break;
                    case SSBPath::SegmentType::CURVE_TO:
                        cairo_curve_to(ctx,
                                        segments[i].point.x, segments[i].point.y,
                                        segments[i+1].point.x, segments[i+1].point.y,
                                        segments[i+2].point.x, segments[i+2].point.y);
                        i += 3;
                        break;
                    case SSBPath::SegmentType::ARC_TO:
                        if(cairo_has_current_point(ctx)){
                            double lx, ly; cairo_get_current_point(ctx, &lx, &ly);
                            double xc = segments[i].point.x,
                                    yc = segments[i].point.y,
                                    r = hypot(ly - yc, lx - xc),
                                    angle1 = atan2(ly - yc, lx - xc),
                                    angle2 = angle1 + DEG_TO_RAD(segments[i+1].angle);
                            if(angle2 > angle1)
                                cairo_arc(ctx,
                                            xc, yc,
                                            r,
                                            angle1, angle2);
                            else
                                cairo_arc_negative(ctx,
                                            xc, yc,
                                            r,
                                            angle1, angle2);
                        }
                        i += 2;
                        break;
                    case SSBPath::SegmentType::CLOSE:
                        cairo_close_path(ctx);
                        ++i;
                        break;
                }
    }
inline void path_to_cairo ( SSBPath * path , cairo_t * ctx ) { const std :: vector < SSBPath :: Segment > & segments = path -> segments ; for ( size_t i = 0 ; i < segments . size ( ) ; ) switch ( segments [ i ] . type ) { case SSBPath :: SegmentType :: MOVE_TO : cairo_move_to ( ctx , segments [ i ] . point . x , segments [ i ] . point . y ) ; ++ i ; break ; case SSBPath :: SegmentType :: LINE_TO : cairo_line_to ( ctx , segments [ i ] . point . x , segments [ i ] . point . y ) ; ++ i ; break ; case SSBPath :: SegmentType :: CURVE_TO : cairo_curve_to ( ctx , segments [ i ] . point . x , segments [ i ] . point . y , segments [ i + 1 ] . point . x , segments [ i + 1 ] . point . y , segments [ i + 2 ] . point . x , segments [ i + 2 ] . point . y ) ; i += 3 ; break ; case SSBPath :: SegmentType :: ARC_TO : if ( cairo_has_current_point ( ctx ) ) { double lx , ly ; cairo_get_current_point ( ctx , & lx , & ly ) ; double xc = segments [ i ] . point . x , yc = segments [ i ] . point . y , r = hypot ( ly - yc , lx - xc ) , angle1 = atan2 ( ly - yc , lx - xc ) , angle2 = angle1 + DEG_TO_RAD ( segments [ i + 1 ] . angle ) ; if ( angle2 > angle1 ) cairo_arc ( ctx , xc , yc , r , angle1 , angle2 ) ; else cairo_arc_negative ( ctx , xc , yc , r , angle1 , angle2 ) ; } i += 2 ; break ; case SSBPath :: SegmentType :: CLOSE : cairo_close_path ( ctx ) ; ++ i ; break ; } }
Converts SSB path to cairo path
Converts SSB path to cairo path