1 /* === S Y N F I G ========================================================= */
2 /*! \file valuenode_subtract.cpp
3 ** \brief Template File
5 ** $Id: valuenode_stripes.cpp,v 1.1.1.1 2005/01/04 01:23:15 darco Exp $
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("synfig::ValueNode_Stripes:Bad type "+ValueBase::type_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::set_color1(ValueNode::Handle a)
95 if(a->get_type()!=ValueBase::TYPE_COLOR)
104 synfig::ValueNode_Stripes::set_color2(ValueNode::Handle a)
106 if(a->get_type()!=ValueBase::TYPE_COLOR)
115 synfig::ValueNode_Stripes::set_width(ValueNode::Handle x)
117 if(x->get_type()!=ValueBase::TYPE_REAL)
126 synfig::ValueNode_Stripes::set_stripes(ValueNode::Handle b)
128 if(b->get_type()!=ValueBase::TYPE_INTEGER)
135 synfig::ValueNode_Stripes::operator()(Time t)const
137 const int total((*stripes_)(t).get(int()));
144 const Color color1((*color1_)(t).get(Color()));
145 const Color color2((*color2_)(t).get(Color()));
146 const float width(max(0.0,min(1.0,(*width_)(t).get(Real()))));
148 const float stripe_width_a(width/total);
149 const float stripe_width_b((1.0-width)/total);
153 float pos(float(i)/total+stripe_width_b/2);
154 ret.push_back(Gradient::CPoint(pos,color1));
155 ret.push_back(Gradient::CPoint(pos,color2));
157 ret.push_back(Gradient::CPoint(pos,color2));
158 ret.push_back(Gradient::CPoint(pos,color1));
164 ValueNode_Stripes::set_link_vfunc(int i,ValueNode::Handle x)
166 assert(i>=0 && i<link_count());
170 if(set_color1(x)) { signal_child_changed()(i);signal_value_changed()(); return true; }
171 else { return false; }
173 if(set_color2(x)) { signal_child_changed()(i);signal_value_changed()(); return true; }
174 else { return false; }
176 if(set_stripes(x)) { signal_child_changed()(i);signal_value_changed()(); return true; }
177 else { return false; }
179 if(set_width(x)) { signal_child_changed()(i);signal_value_changed()(); return true; }
180 else { return false; }
186 ValueNode::LooseHandle
187 ValueNode_Stripes::get_link_vfunc(int i)const
189 assert(i>=0 && i<link_count());
205 ValueNode_Stripes::link_count()const
211 ValueNode_Stripes::link_local_name(int i)const
213 assert(i>=0 && i<link_count());
221 return _("Stripe Count");
229 ValueNode_Stripes::link_name(int i)const
231 assert(i>=0 && i<link_count());
247 ValueNode_Stripes::get_link_index_from_name(const String &name)const
257 throw Exception::BadLinkName(name);
261 ValueNode_Stripes::get_name()const
267 ValueNode_Stripes::get_local_name()const
273 ValueNode_Stripes::check_type(ValueBase::Type type)
275 return type==ValueBase::TYPE_GRADIENT;