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 Vocab ret(get_children_vocab());
59 set_children_vocab(ret);
60 set_link("color1",ValueNode_Const::create(Color::alpha()));
61 set_link("color2",ValueNode_Const::create(Color::black()));
62 set_link("stripes",stripes_=ValueNode_Const::create(int(5)));
63 set_link("width",ValueNode_Const::create(0.5));
67 ValueNode_Stripes::create_new()const
69 return new ValueNode_Stripes();
73 ValueNode_Stripes::create(const ValueBase& x)
75 ValueBase::Type id(x.get_type());
77 if(id!=ValueBase::TYPE_GRADIENT)
80 throw runtime_error(String(_("Stripes"))+_(":Bad type ")+ValueBase::type_local_name(id));
83 ValueNode_Stripes* value_node=new ValueNode_Stripes();
85 assert(value_node->get_type()==id);
90 synfig::ValueNode_Stripes::~ValueNode_Stripes()
96 synfig::ValueNode_Stripes::operator()(Time t)const
98 if (getenv("SYNFIG_DEBUG_VALUENODE_OPERATORS"))
99 printf("%s:%d operator()\n", __FILE__, __LINE__);
101 const int total((*stripes_)(t).get(int()));
108 const Color color1((*color1_)(t).get(Color()));
109 const Color color2((*color2_)(t).get(Color()));
110 const float width(max(0.0,min(1.0,(*width_)(t).get(Real()))));
112 const float stripe_width_a(width/total);
113 const float stripe_width_b((1.0-width)/total);
117 float pos(float(i)/total+stripe_width_b/2);
118 ret.push_back(Gradient::CPoint(pos,color1));
119 ret.push_back(Gradient::CPoint(pos,color2));
121 ret.push_back(Gradient::CPoint(pos,color2));
122 ret.push_back(Gradient::CPoint(pos,color1));
128 ValueNode_Stripes::set_link_vfunc(int i,ValueNode::Handle value)
130 assert(i>=0 && i<link_count());
134 case 0: CHECK_TYPE_AND_SET_VALUE(color1_, ValueBase::TYPE_COLOR);
135 case 1: CHECK_TYPE_AND_SET_VALUE(color2_, ValueBase::TYPE_COLOR);
136 case 2: CHECK_TYPE_AND_SET_VALUE(stripes_, ValueBase::TYPE_INTEGER);
137 case 3: CHECK_TYPE_AND_SET_VALUE(width_, ValueBase::TYPE_REAL);
142 ValueNode::LooseHandle
143 ValueNode_Stripes::get_link_vfunc(int i)const
145 assert(i>=0 && i<link_count());
162 ValueNode_Stripes::get_name()const
168 ValueNode_Stripes::get_local_name()const
174 ValueNode_Stripes::check_type(ValueBase::Type type)
176 return type==ValueBase::TYPE_GRADIENT;
179 LinkableValueNode::Vocab
180 ValueNode_Stripes::get_children_vocab_vfunc()const
182 if(children_vocab.size())
183 return children_vocab;
185 LinkableValueNode::Vocab ret;
187 ret.push_back(ParamDesc(ValueBase(),"color1")
188 .set_local_name(_("Color 1"))
189 .set_description(_("One color of the gradient stripes"))
192 ret.push_back(ParamDesc(ValueBase(),"color2")
193 .set_local_name(_("Color 2"))
194 .set_description(_("Other color of the gradient stripes"))
197 ret.push_back(ParamDesc(ValueBase(),"stripes")
198 .set_local_name(_("Stripe Count"))
199 .set_description(_("Number of stripes in the gradient"))
202 ret.push_back(ParamDesc(ValueBase(),"width")
203 .set_local_name(_("Width"))
204 .set_description(_("Width of stripes in the gradient between [0,1]"))