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 if (getenv("SYNFIG_DEBUG_VALUENODE_OPERATORS"))
97 printf("%s:%d operator()\n", __FILE__, __LINE__);
99 const int total((*stripes_)(t).get(int()));
106 const Color color1((*color1_)(t).get(Color()));
107 const Color color2((*color2_)(t).get(Color()));
108 const float width(max(0.0,min(1.0,(*width_)(t).get(Real()))));
110 const float stripe_width_a(width/total);
111 const float stripe_width_b((1.0-width)/total);
115 float pos(float(i)/total+stripe_width_b/2);
116 ret.push_back(Gradient::CPoint(pos,color1));
117 ret.push_back(Gradient::CPoint(pos,color2));
119 ret.push_back(Gradient::CPoint(pos,color2));
120 ret.push_back(Gradient::CPoint(pos,color1));
126 ValueNode_Stripes::set_link_vfunc(int i,ValueNode::Handle value)
128 assert(i>=0 && i<link_count());
132 case 0: CHECK_TYPE_AND_SET_VALUE(color1_, ValueBase::TYPE_COLOR);
133 case 1: CHECK_TYPE_AND_SET_VALUE(color2_, ValueBase::TYPE_COLOR);
134 case 2: CHECK_TYPE_AND_SET_VALUE(stripes_, ValueBase::TYPE_INTEGER);
135 case 3: CHECK_TYPE_AND_SET_VALUE(width_, ValueBase::TYPE_REAL);
140 ValueNode::LooseHandle
141 ValueNode_Stripes::get_link_vfunc(int i)const
143 assert(i>=0 && i<link_count());
160 ValueNode_Stripes::link_count()const
166 ValueNode_Stripes::link_local_name(int i)const
168 assert(i>=0 && i<link_count());
177 return _("Stripe Count");
186 ValueNode_Stripes::link_name(int i)const
188 assert(i>=0 && i<link_count());
206 ValueNode_Stripes::get_link_index_from_name(const String &name)const
216 throw Exception::BadLinkName(name);
220 ValueNode_Stripes::get_name()const
226 ValueNode_Stripes::get_local_name()const
232 ValueNode_Stripes::check_type(ValueBase::Type type)
234 return type==ValueBase::TYPE_GRADIENT;