Example #1
0
bool
Layer_Polygon::set_param(const String & param, const ValueBase &value)
{
	if(	param=="vector_list" && param_vector_list.get_type()==value.get_type())
	{
		param_vector_list=value;
		Layer_Shape::clear();
		add_polygon(value.get_list_of(Vector()));
		sync();
		return true;
	}

	return Layer_Shape::set_param(param,value);
}
ValueBase
synfig::convert_bline_to_wplist(const ValueBase& bline)
{
	// returns if the parameter is not a list or if it is a list, it is empty
	if(bline.empty())
		return ValueBase(type_list);
	// returns if the contained type is not blinepoint
	if(bline.get_contained_type()!=type_bline_point)
		return ValueBase(type_list);

	std::vector<WidthPoint> ret;
	std::vector<BLinePoint> list(bline.get_list_of(BLinePoint()));
	std::vector<BLinePoint>::const_iterator iter;
	Real position, totalpoints, i(0);
	totalpoints=(Real)list.size();
	// Inserts all the points at the positions given by the bline
	// positions are 0.0 to 1.0 equally spaced based on the number of blinepoints
	for(iter=list.begin();iter!=list.end();++iter)
	{
		position=i/totalpoints;
		ret.push_back(WidthPoint(position,iter->get_width()));
		i=i+1.0;
	}
	// If the bline is not looped then make the cups type rounded for the
	// first and last width points.
	// In the future when this function is used to convert old blines to
	// new wlines the end and start cups should be readed from the oultline
	// layer
	if(!bline.get_loop())
	{
		std::vector<WidthPoint>::iterator iter;
		iter=ret.end();
		iter--;
		iter->set_side_type_after(WidthPoint::TYPE_ROUNDED);
		iter=ret.begin();
		iter->set_side_type_before(WidthPoint::TYPE_ROUNDED);
	}

	return ValueBase(ret);
}