1 /* === S Y N F I G ========================================================= */
2 /*! \file valuenode_stripes.cpp
3 ** \brief Implementation of the "Stripes" valuenode conversion.
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 ** Copyright (c) 2008 Chris Moore
11 ** This package is free software; you can redistribute it and/or
12 ** modify it under the terms of the GNU General Public License as
13 ** published by the Free Software Foundation; either version 2 of
14 ** the License, or (at your option) any later version.
16 ** This package is distributed in the hope that it will be useful,
17 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 ** General Public License for more details.
22 /* ========================================================================= */
24 /* === H E A D E R S ======================================================= */
34 #include "valuenode_stripes.h"
35 #include "valuenode_const.h"
42 /* === U S I N G =========================================================== */
46 using namespace synfig;
48 /* === M A C R O S ========================================================= */
50 /* === G L O B A L S ======================================================= */
52 /* === P R O C E D U R E S ================================================= */
54 /* === M E T H O D S ======================================================= */
56 synfig::ValueNode_Stripes::ValueNode_Stripes():LinkableValueNode(synfig::ValueBase::TYPE_GRADIENT)
58 set_link("color1",ValueNode_Const::create(Color::alpha()));
59 set_link("color2",ValueNode_Const::create(Color::black()));
60 set_link("stripes",stripes_=ValueNode_Const::create(int(5)));
61 set_link("width",ValueNode_Const::create(0.5));
65 ValueNode_Stripes::create_new()const
67 return new ValueNode_Stripes();
71 ValueNode_Stripes::create(const ValueBase& x)
73 ValueBase::Type id(x.get_type());
75 if(id!=ValueBase::TYPE_GRADIENT)
78 throw runtime_error(String(_("Stripes"))+_(":Bad type ")+ValueBase::type_local_name(id));
81 ValueNode_Stripes* value_node=new ValueNode_Stripes();
83 assert(value_node->get_type()==id);
88 synfig::ValueNode_Stripes::~ValueNode_Stripes()
94 synfig::ValueNode_Stripes::operator()(Time t)const
96 const int total((*stripes_)(t).get(int()));
103 const Color color1((*color1_)(t).get(Color()));
104 const Color color2((*color2_)(t).get(Color()));
105 const float width(max(0.0,min(1.0,(*width_)(t).get(Real()))));
107 const float stripe_width_a(width/total);
108 const float stripe_width_b((1.0-width)/total);
112 float pos(float(i)/total+stripe_width_b/2);
113 ret.push_back(Gradient::CPoint(pos,color1));
114 ret.push_back(Gradient::CPoint(pos,color2));
116 ret.push_back(Gradient::CPoint(pos,color2));
117 ret.push_back(Gradient::CPoint(pos,color1));
123 ValueNode_Stripes::set_link_vfunc(int i,ValueNode::Handle value)
125 assert(i>=0 && i<link_count());
129 case 0: CHECK_TYPE_AND_SET_VALUE(color1_, ValueBase::TYPE_COLOR);
130 case 1: CHECK_TYPE_AND_SET_VALUE(color2_, ValueBase::TYPE_COLOR);
131 case 2: CHECK_TYPE_AND_SET_VALUE(stripes_, ValueBase::TYPE_INTEGER);
132 case 3: CHECK_TYPE_AND_SET_VALUE(width_, ValueBase::TYPE_REAL);
137 ValueNode::LooseHandle
138 ValueNode_Stripes::get_link_vfunc(int i)const
140 assert(i>=0 && i<link_count());
157 ValueNode_Stripes::link_count()const
163 ValueNode_Stripes::link_local_name(int i)const
165 assert(i>=0 && i<link_count());
174 return _("Stripe Count");
183 ValueNode_Stripes::link_name(int i)const
185 assert(i>=0 && i<link_count());
203 ValueNode_Stripes::get_link_index_from_name(const String &name)const
213 throw Exception::BadLinkName(name);
217 ValueNode_Stripes::get_name()const
223 ValueNode_Stripes::get_local_name()const
229 ValueNode_Stripes::check_type(ValueBase::Type type)
231 return type==ValueBase::TYPE_GRADIENT;