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::operator()(Time t)const
116 if (getenv("SYNFIG_DEBUG_VALUENODE_OPERATORS"))
117 printf("%s:%d operator()\n", __FILE__, __LINE__);
119 return (*switch_)(t).get(bool()) ? (*link_on_)(t) : (*link_off_)(t);
124 ValueNode_Switch::get_name()const
130 ValueNode_Switch::get_local_name()const
136 ValueNode_Switch::check_type(ValueBase::Type type)
143 LinkableValueNode::Vocab
144 ValueNode_Switch::get_children_vocab_vfunc()const
146 if(children_vocab.size())
147 return children_vocab;
149 LinkableValueNode::Vocab ret;
151 ret.push_back(ParamDesc(ValueBase(),"link_off")
152 .set_local_name(_("Link Off"))
153 .set_description(_("The value node returned when the switch is off"))
156 ret.push_back(ParamDesc(ValueBase(),"link_on")
157 .set_local_name(_("Link On"))
158 .set_description(_("The value node returned when the switch is on"))
161 ret.push_back(ParamDesc(ValueBase(),"switch")
162 .set_local_name(_("Switch"))
163 .set_description(_("When checked, returns 'Link On', otherwise returns 'Link Off'"))