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
10 ** This package is free software; you can redistribute it and/or
11 ** modify it under the terms of the GNU General Public License as
12 ** published by the Free Software Foundation; either version 2 of
13 ** the License, or (at your option) any later version.
15 ** This package is distributed in the hope that it will be useful,
16 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 ** General Public License for more details.
21 /* ========================================================================= */
23 /* === H E A D E R S ======================================================= */
33 #include "valuenode_stripes.h"
34 #include "valuenode_const.h"
41 /* === U S I N G =========================================================== */
45 using namespace synfig;
47 /* === M A C R O S ========================================================= */
49 /* === G L O B A L S ======================================================= */
51 /* === P R O C E D U R E S ================================================= */
53 /* === M E T H O D S ======================================================= */
55 synfig::ValueNode_Stripes::ValueNode_Stripes():LinkableValueNode(synfig::ValueBase::TYPE_GRADIENT)
57 set_link("color1",ValueNode_Const::create(Color::alpha()));
58 set_link("color2",ValueNode_Const::create(Color::black()));
59 set_link("stripes",stripes_=ValueNode_Const::create(int(5)));
60 set_link("width",ValueNode_Const::create(0.5));
64 ValueNode_Stripes::create_new()const
66 return new ValueNode_Stripes();
70 ValueNode_Stripes::create(const ValueBase& x)
72 ValueBase::Type id(x.get_type());
74 if(id!=ValueBase::TYPE_GRADIENT)
77 throw runtime_error(String(_("Stripes"))+_(":Bad type ")+ValueBase::type_local_name(id));
80 ValueNode_Stripes* value_node=new ValueNode_Stripes();
82 assert(value_node->get_type()==id);
87 synfig::ValueNode_Stripes::~ValueNode_Stripes()
93 synfig::ValueNode_Stripes::operator()(Time t)const
95 const int total((*stripes_)(t).get(int()));
102 const Color color1((*color1_)(t).get(Color()));
103 const Color color2((*color2_)(t).get(Color()));
104 const float width(max(0.0,min(1.0,(*width_)(t).get(Real()))));
106 const float stripe_width_a(width/total);
107 const float stripe_width_b((1.0-width)/total);
111 float pos(float(i)/total+stripe_width_b/2);
112 ret.push_back(Gradient::CPoint(pos,color1));
113 ret.push_back(Gradient::CPoint(pos,color2));
115 ret.push_back(Gradient::CPoint(pos,color2));
116 ret.push_back(Gradient::CPoint(pos,color1));
122 ValueNode_Stripes::set_link_vfunc(int i,ValueNode::Handle value)
124 assert(i>=0 && i<link_count());
128 case 0: CHECK_TYPE_AND_SET_VALUE(color1_, ValueBase::TYPE_COLOR);
129 case 1: CHECK_TYPE_AND_SET_VALUE(color2_, ValueBase::TYPE_COLOR);
130 case 2: CHECK_TYPE_AND_SET_VALUE(stripes_, ValueBase::TYPE_INTEGER);
131 case 3: CHECK_TYPE_AND_SET_VALUE(width_, ValueBase::TYPE_REAL);
136 ValueNode::LooseHandle
137 ValueNode_Stripes::get_link_vfunc(int i)const
139 assert(i>=0 && i<link_count());
156 ValueNode_Stripes::link_count()const
162 ValueNode_Stripes::link_local_name(int i)const
164 assert(i>=0 && i<link_count());
173 return _("Stripe Count");
182 ValueNode_Stripes::link_name(int i)const
184 assert(i>=0 && i<link_count());
202 ValueNode_Stripes::get_link_index_from_name(const String &name)const
212 throw Exception::BadLinkName(name);
216 ValueNode_Stripes::get_name()const
222 ValueNode_Stripes::get_local_name()const
228 ValueNode_Stripes::check_type(ValueBase::Type type)
230 return type==ValueBase::TYPE_GRADIENT;