1 /* === S Y N F I G ========================================================= */
2 /*! \file valuenode_switch.cpp
3 ** \brief Implementation of the "Switch" valuenode conversion.
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 ** Copyright (c) 2007, 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 ======================================================= */
33 #include "valuenode_switch.h"
34 #include "valuenode_const.h"
39 /* === U S I N G =========================================================== */
43 using namespace synfig;
45 /* === M A C R O S ========================================================= */
47 /* === G L O B A L S ======================================================= */
49 /* === P R O C E D U R E S ================================================= */
51 /* === M E T H O D S ======================================================= */
53 ValueNode_Switch::ValueNode_Switch(const ValueBase::Type &x):
58 ValueNode_Switch::ValueNode_Switch(const ValueNode::Handle &x):
59 LinkableValueNode(x->get_type())
61 Vocab ret(get_children_vocab());
62 set_children_vocab(ret);
63 set_link("link_off",x);
64 set_link("link_on",x);
65 set_link("switch",ValueNode_Const::create(bool(false)));
69 ValueNode_Switch::create(const ValueBase &x)
71 return new ValueNode_Switch(ValueNode_Const::create(x));
75 ValueNode_Switch::create_new()const
77 return new ValueNode_Switch(get_type());
80 ValueNode_Switch::~ValueNode_Switch()
86 ValueNode_Switch::set_link_vfunc(int i,ValueNode::Handle value)
88 assert(i>=0 && i<link_count());
92 case 0: CHECK_TYPE_AND_SET_VALUE(link_off_, get_type());
93 case 1: CHECK_TYPE_AND_SET_VALUE(link_on_, get_type());
94 case 2: CHECK_TYPE_AND_SET_VALUE(switch_, ValueBase::TYPE_BOOL);
99 ValueNode::LooseHandle
100 ValueNode_Switch::get_link_vfunc(int i)const
102 assert(i>=0 && i<link_count());
106 case 0: return link_off_;
107 case 1: return link_on_;
108 case 2: return switch_;
114 ValueNode_Switch::link_count()const
120 ValueNode_Switch::link_name(int i)const
122 assert(i>=0 && i<link_count());
126 case 0: return "link_off";
127 case 1: return "link_on";
128 case 2: return "switch";
134 ValueNode_Switch::link_local_name(int i)const
136 assert(i>=0 && i<link_count());
140 case 0: return "Link Off";
141 case 1: return "Link On";
142 case 2: return "Switch";
148 ValueNode_Switch::get_link_index_from_name(const String &name)const
150 if(name=="link_off") return 0;
151 if(name=="link_on" ) return 1;
152 if(name=="switch" ) return 2;
153 throw Exception::BadLinkName(name);
157 ValueNode_Switch::operator()(Time t)const
159 if (getenv("SYNFIG_DEBUG_VALUENODE_OPERATORS"))
160 printf("%s:%d operator()\n", __FILE__, __LINE__);
162 return (*switch_)(t).get(bool()) ? (*link_on_)(t) : (*link_off_)(t);
167 ValueNode_Switch::get_name()const
173 ValueNode_Switch::get_local_name()const
179 ValueNode_Switch::check_type(ValueBase::Type type)
186 LinkableValueNode::Vocab
187 ValueNode_Switch::get_children_vocab_vfunc()const
189 if(children_vocab.size())
190 return children_vocab;
192 LinkableValueNode::Vocab ret;
194 ret.push_back(ParamDesc(ValueBase(),"link_off")
195 .set_local_name(_("Link Off"))
196 .set_description(_("The value node returned when the switch is off"))
199 ret.push_back(ParamDesc(ValueBase(),"link_on")
200 .set_local_name(_("Link On"))
201 .set_description(_("The value node returned when the switch is on"))
204 ret.push_back(ParamDesc(ValueBase(),"switch")
205 .set_local_name(_("Switch"))
206 .set_description(_("When checked, returns 'Link On', otherwise returns 'Link Off'"))