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
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 ======================================================= */
32 #include "valuenode_switch.h"
33 #include "valuenode_const.h"
38 /* === U S I N G =========================================================== */
42 using namespace synfig;
44 /* === M A C R O S ========================================================= */
46 /* === G L O B A L S ======================================================= */
48 /* === P R O C E D U R E S ================================================= */
50 /* === M E T H O D S ======================================================= */
52 ValueNode_Switch::ValueNode_Switch(const ValueBase::Type &x):
57 ValueNode_Switch::ValueNode_Switch(const ValueNode::Handle &x):
58 LinkableValueNode(x->get_type())
60 set_link("link_off",x);
61 set_link("link_on",x);
62 set_link("switch",ValueNode_Const::create(bool(false)));
66 ValueNode_Switch::create(const ValueBase &x)
68 return new ValueNode_Switch(ValueNode_Const::create(x));
72 ValueNode_Switch::create_new()const
74 return new ValueNode_Switch(get_type());
77 ValueNode_Switch::~ValueNode_Switch()
83 ValueNode_Switch::set_link_vfunc(int i,ValueNode::Handle value)
85 assert(i>=0 && i<link_count());
89 case 0: CHECK_TYPE_AND_SET_VALUE(link_off_, get_type());
90 case 1: CHECK_TYPE_AND_SET_VALUE(link_on_, get_type());
91 case 2: CHECK_TYPE_AND_SET_VALUE(switch_, ValueBase::TYPE_BOOL);
96 ValueNode::LooseHandle
97 ValueNode_Switch::get_link_vfunc(int i)const
99 assert(i>=0 && i<link_count());
103 case 0: return link_off_;
104 case 1: return link_on_;
105 case 2: return switch_;
111 ValueNode_Switch::link_count()const
117 ValueNode_Switch::link_name(int i)const
119 assert(i>=0 && i<link_count());
123 case 0: return "link_off";
124 case 1: return "link_on";
125 case 2: return "switch";
131 ValueNode_Switch::link_local_name(int i)const
133 assert(i>=0 && i<link_count());
137 case 0: return "Link Off";
138 case 1: return "Link On";
139 case 2: return "Switch";
145 ValueNode_Switch::get_link_index_from_name(const String &name)const
147 if(name=="link_off") return 0;
148 if(name=="link_on" ) return 1;
149 if(name=="switch" ) return 2;
150 throw Exception::BadLinkName(name);
154 ValueNode_Switch::operator()(Time t)const
156 return (*switch_)(t).get(bool()) ? (*link_on_)(t) : (*link_off_)(t);
161 ValueNode_Switch::get_name()const
167 ValueNode_Switch::get_local_name()const
173 ValueNode_Switch::check_type(ValueBase::Type type)