1 /* === S Y N F I G ========================================================= */
2 /*! \file valuenode_switch.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 ======================================================= */
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 x)
85 assert(i>=0 && i<link_count());
89 if(x->get_type()!=get_type() && !PlaceholderValueNode::Handle::cast_dynamic(x))
92 signal_child_changed()(i);signal_value_changed()();
95 if(x->get_type()!=get_type() && !PlaceholderValueNode::Handle::cast_dynamic(x))
98 signal_child_changed()(i);signal_value_changed()();
102 signal_child_changed()(i);signal_value_changed()();
108 ValueNode::LooseHandle
109 ValueNode_Switch::get_link_vfunc(int i)const
111 assert(i>=0 && i<link_count());
114 case 0: return link_off_;
115 case 1: return link_on_;
116 case 2: return switch_;
122 ValueNode_Switch::link_count()const
128 ValueNode_Switch::link_name(int i)const
130 assert(i>=0 && i<link_count());
133 case 0: return "link_off";
134 case 1: return "link_on";
135 case 2: return "switch";
141 ValueNode_Switch::link_local_name(int i)const
143 assert(i>=0 && i<link_count());
146 case 0: return "Link Off";
147 case 1: return "Link On";
148 case 2: return "Switch";
154 ValueNode_Switch::get_link_index_from_name(const String &name)const
156 if(name=="link_off") return 0;
157 if(name=="link_on" ) return 1;
158 if(name=="switch" ) return 2;
159 throw Exception::BadLinkName(name);
163 ValueNode_Switch::operator()(Time t)const
165 return (*switch_)(t).get(bool()) ? (*link_on_)(t) : (*link_off_)(t);
170 ValueNode_Switch::get_name()const
176 ValueNode_Switch::get_local_name()const
182 ValueNode_Switch::check_type(ValueBase::Type type)