1 /* === S Y N F I G ========================================================= */
2 /*! \file valuenode_range.cpp
3 ** \brief Template File
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_range.h"
34 #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_Range::ValueNode_Range(const ValueBase &value):
57 LinkableValueNode(value.get_type())
59 ValueBase::Type id(value.get_type());
63 case ValueBase::TYPE_ANGLE:
64 set_link("min",ValueNode_Const::create(value.get(Angle())));
65 set_link("max",ValueNode_Const::create(value.get(Angle())));
66 set_link("link",ValueNode_Const::create(value.get(Angle())));
68 case ValueBase::TYPE_INTEGER:
69 set_link("min",ValueNode_Const::create(value.get(int())));
70 set_link("max",ValueNode_Const::create(value.get(int())));
71 set_link("link",ValueNode_Const::create(value.get(int())));
73 case ValueBase::TYPE_REAL:
74 set_link("min",ValueNode_Const::create(value.get(Real())));
75 set_link("max",ValueNode_Const::create(value.get(Real())));
76 set_link("link",ValueNode_Const::create(value.get(Real())));
78 case ValueBase::TYPE_TIME:
79 set_link("min",ValueNode_Const::create(value.get(Time())));
80 set_link("max",ValueNode_Const::create(value.get(Time())));
81 set_link("link",ValueNode_Const::create(value.get(Time())));
85 throw runtime_error("synfig::ValueNode_Range:Bad type "+ValueBase::type_name(id));
88 assert(min_->get_type()==id);
89 assert(max_->get_type()==id);
90 assert(link_->get_type()==id);
91 assert(get_type()==id);
97 ValueNode_Range::create_new()const
99 return new ValueNode_Range(get_type());
103 ValueNode_Range::create(const ValueBase& value)
105 return new ValueNode_Range(value);
108 synfig::ValueNode_Range::~ValueNode_Range()
113 #define min(x,y) (x>y ? y : x)
114 #define max(x,y) (x>y ? x : y)
115 #define range(low,high,input) (min(high,max(low,input)))
118 synfig::ValueNode_Range::operator()(Time t)const
120 if(!min_ || !max_ || !link_)
121 throw runtime_error(strprintf("ValueNode_Range: %s",_("Some of my parameters aren't set!")));
125 case ValueBase::TYPE_ANGLE:
126 return range((*min_)(t).get(Angle()), (*max_)(t).get(Angle()), (*link_)(t).get(Angle()));
127 case ValueBase::TYPE_INTEGER:
128 return range((*min_)(t).get(int()), (*max_)(t).get(int()), (*link_)(t).get(int()));
129 case ValueBase::TYPE_REAL:
130 return range((*min_)(t).get(Real()), (*max_)(t).get(Real()), (*link_)(t).get(Real()));
131 case ValueBase::TYPE_TIME:
132 return range((*min_)(t).get(Time()), (*max_)(t).get(Time()), (*link_)(t).get(Time()));
141 ValueNode_Range::set_link_vfunc(int i,ValueNode::Handle value)
148 signal_child_changed()(i);signal_value_changed()();
152 signal_child_changed()(i);signal_value_changed()();
156 signal_child_changed()(i);signal_value_changed()();
163 ValueNode::LooseHandle
164 ValueNode_Range::get_link_vfunc(int i)const
171 case 2: return link_;
177 ValueNode_Range::link_count()const
183 ValueNode_Range::link_local_name(int i)const
188 case 0: return _("Min");
189 case 1: return _("Max");
190 case 2: return _("Link");
191 default: return String();
196 ValueNode_Range::link_name(int i)const
201 case 0: return "min";
202 case 1: return "max";
203 case 2: return "link";
204 default: return String();
209 ValueNode_Range::get_link_index_from_name(const String &name)const
211 printf("%s:%d link_index_from_name\n", __FILE__, __LINE__);
212 if(name=="min") return 0;
213 if(name=="max") return 1;
214 if(name=="link") return 2;
215 throw Exception::BadLinkName(name);
219 ValueNode_Range::get_name()const
225 ValueNode_Range::get_local_name()const
231 ValueNode_Range::check_type(ValueBase::Type type)
233 return type==ValueBase::TYPE_ANGLE
234 || type==ValueBase::TYPE_INTEGER
235 || type==ValueBase::TYPE_REAL
236 || type==ValueBase::TYPE_TIME;