1 /* === S I N F 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 Robert B. Quattlebaum Jr.
10 ** This software and associated documentation
11 ** are CONFIDENTIAL and PROPRIETARY property of
12 ** the above-mentioned copyright holder.
14 ** You may not copy, print, publish, or in any
15 ** other way distribute this software without
16 ** a prior written agreement with
17 ** the copyright holder.
20 /* ========================================================================= */
22 /* === H E A D E R S ======================================================= */
32 #include "valuenode_stripes.h"
33 #include "valuenode_const.h"
40 /* === U S I N G =========================================================== */
44 using namespace sinfg;
46 /* === M A C R O S ========================================================= */
48 /* === G L O B A L S ======================================================= */
50 /* === P R O C E D U R E S ================================================= */
52 /* === M E T H O D S ======================================================= */
54 sinfg::ValueNode_Stripes::ValueNode_Stripes():LinkableValueNode(sinfg::ValueBase::TYPE_GRADIENT)
56 set_link("color1",ValueNode_Const::create(Color::alpha()));
57 set_link("color2",ValueNode_Const::create(Color::black()));
58 set_link("stripes",stripes_=ValueNode_Const::create(int(5)));
59 set_link("width",ValueNode_Const::create(0.5));
63 ValueNode_Stripes::create_new()const
65 return new ValueNode_Stripes();
69 ValueNode_Stripes::create(const ValueBase& x)
71 ValueBase::Type id(x.get_type());
73 if(id!=ValueBase::TYPE_GRADIENT)
76 throw runtime_error("sinfg::ValueNode_Stripes:Bad type "+ValueBase::type_name(id));
79 ValueNode_Stripes* value_node=new ValueNode_Stripes();
81 assert(value_node->get_type()==id);
86 sinfg::ValueNode_Stripes::~ValueNode_Stripes()
92 sinfg::ValueNode_Stripes::set_color1(ValueNode::Handle a)
94 if(a->get_type()!=ValueBase::TYPE_COLOR)
103 sinfg::ValueNode_Stripes::set_color2(ValueNode::Handle a)
105 if(a->get_type()!=ValueBase::TYPE_COLOR)
114 sinfg::ValueNode_Stripes::set_width(ValueNode::Handle x)
116 if(x->get_type()!=ValueBase::TYPE_REAL)
125 sinfg::ValueNode_Stripes::set_stripes(ValueNode::Handle b)
127 if(b->get_type()!=ValueBase::TYPE_INTEGER)
134 sinfg::ValueNode_Stripes::operator()(Time t)const
136 const int total((*stripes_)(t).get(int()));
143 const Color color1((*color1_)(t).get(Color()));
144 const Color color2((*color2_)(t).get(Color()));
145 const float width(max(0.0,min(1.0,(*width_)(t).get(Real()))));
147 const float stripe_width_a(width/total);
148 const float stripe_width_b((1.0-width)/total);
152 float pos(float(i)/total+stripe_width_b/2);
153 ret.push_back(Gradient::CPoint(pos,color1));
154 ret.push_back(Gradient::CPoint(pos,color2));
156 ret.push_back(Gradient::CPoint(pos,color2));
157 ret.push_back(Gradient::CPoint(pos,color1));
163 ValueNode_Stripes::set_link_vfunc(int i,ValueNode::Handle x)
165 assert(i>=0 && i<link_count());
169 if(set_color1(x)) { signal_child_changed()(i);signal_value_changed()(); return true; }
170 else { return false; }
172 if(set_color2(x)) { signal_child_changed()(i);signal_value_changed()(); return true; }
173 else { return false; }
175 if(set_stripes(x)) { signal_child_changed()(i);signal_value_changed()(); return true; }
176 else { return false; }
178 if(set_width(x)) { signal_child_changed()(i);signal_value_changed()(); return true; }
179 else { return false; }
185 ValueNode::LooseHandle
186 ValueNode_Stripes::get_link_vfunc(int i)const
188 assert(i>=0 && i<link_count());
204 ValueNode_Stripes::link_count()const
210 ValueNode_Stripes::link_local_name(int i)const
212 assert(i>=0 && i<link_count());
220 return _("Stripe Count");
228 ValueNode_Stripes::link_name(int i)const
230 assert(i>=0 && i<link_count());
246 ValueNode_Stripes::get_link_index_from_name(const String &name)const
256 throw Exception::BadLinkName(name);
260 ValueNode_Stripes::get_name()const
266 ValueNode_Stripes::get_local_name()const
272 ValueNode_Stripes::check_type(ValueBase::Type type)
274 return type==ValueBase::TYPE_GRADIENT;