Tidying.
[synfig.git] / synfig-core / trunk / src / synfig / valuenode_cos.cpp
blobf3e47930ea2b41cf5ce4f3495fde71cb9a1d4ded
1 /* === S Y N F I G ========================================================= */
2 /*! \file valuenode_cos.cpp
3 ** \brief Implementation of the "Cos" valuenode conversion.
4 **
5 ** $Id$
6 **
7 ** \legal
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.
20 ** \endlegal
22 /* ========================================================================= */
24 /* === H E A D E R S ======================================================= */
26 #ifdef USING_PCH
27 # include "pch.h"
28 #else
29 #ifdef HAVE_CONFIG_H
30 # include <config.h>
31 #endif
33 #include "valuenode_cos.h"
34 #include "valuenode_const.h"
35 #include "general.h"
37 #endif
39 /* === U S I N G =========================================================== */
41 using namespace std;
42 using namespace etl;
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_Cos::ValueNode_Cos(const ValueBase &value):
54 LinkableValueNode(value.get_type())
56 switch(value.get_type())
58 case ValueBase::TYPE_REAL:
59 set_link("angle",ValueNode_Const::create(Angle::deg(0)));
60 set_link("amp",ValueNode_Const::create(value.get(Real())));
61 break;
62 default:
63 throw Exception::BadType(ValueBase::type_local_name(value.get_type()));
66 DCAST_HACK_ENABLE();
69 LinkableValueNode*
70 ValueNode_Cos::create_new()const
72 return new ValueNode_Cos(get_type());
75 ValueNode_Cos*
76 ValueNode_Cos::create(const ValueBase &x)
78 return new ValueNode_Cos(x);
81 ValueNode_Cos::~ValueNode_Cos()
83 unlink_all();
86 ValueBase
87 ValueNode_Cos::operator()(Time t)const
89 if (getenv("SYNFIG_DEBUG_VALUENODE_OPERATORS"))
90 printf("%s:%d operator()\n", __FILE__, __LINE__);
92 return
93 Angle::cos(
94 (*angle_)(t).get(Angle())
95 ).get() * (*amp_)(t).get(Real());
99 String
100 ValueNode_Cos::get_name()const
102 return "cos";
105 String
106 ValueNode_Cos::get_local_name()const
108 return _("Cos");
111 bool
112 ValueNode_Cos::check_type(ValueBase::Type type)
114 return type==ValueBase::TYPE_REAL;
117 bool
118 ValueNode_Cos::set_link_vfunc(int i,ValueNode::Handle value)
120 assert(i>=0 && i<link_count());
122 switch(i)
124 case 0: CHECK_TYPE_AND_SET_VALUE(angle_, ValueBase::TYPE_ANGLE);
125 case 1: CHECK_TYPE_AND_SET_VALUE(amp_, ValueBase::TYPE_REAL);
128 return false;
131 ValueNode::LooseHandle
132 ValueNode_Cos::get_link_vfunc(int i)const
134 assert(i>=0 && i<link_count());
136 switch(i)
138 case 0: return angle_;
139 case 1: return amp_;
142 return 0;
146 ValueNode_Cos::link_count()const
148 return 2;
151 String
152 ValueNode_Cos::link_name(int i)const
154 assert(i>=0 && i<link_count());
156 switch(i)
158 case 0: return "angle";
159 case 1: return "amp";
162 return String();
165 String
166 ValueNode_Cos::link_local_name(int i)const
168 assert(i>=0 && i<link_count());
170 switch(i)
172 case 0: return _("Angle");
173 case 1: return _("Amplitude");
176 return String();
180 ValueNode_Cos::get_link_index_from_name(const String &name)const
182 if(name=="angle") return 0;
183 if(name=="amp") return 1;
185 throw Exception::BadLinkName(name);