184dda7a3a032f38a934681d1d50c43b3cc1f88d
[synfig.git] / synfig-core / src / synfig / valuenode_timestring.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file valuenode_timestring.cpp
3 **      \brief Implementation of the "TimeString" valuenode conversion.
4 **
5 **      $Id$
6 **
7 **      \legal
8 **      Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 **      Copyright (c) 2008 Chris Moore
10 **
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.
15 **
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
21 */
22 /* ========================================================================= */
23
24 /* === H E A D E R S ======================================================= */
25
26 #ifdef USING_PCH
27 #       include "pch.h"
28 #else
29 #ifdef HAVE_CONFIG_H
30 #       include <config.h>
31 #endif
32
33 #include "valuenode_timestring.h"
34 #include "valuenode_const.h"
35 #include "canvas.h"
36 #include "general.h"
37
38 #endif
39
40 /* === U S I N G =========================================================== */
41
42 using namespace std;
43 using namespace etl;
44 using namespace synfig;
45
46 /* === M A C R O S ========================================================= */
47
48 /* === G L O B A L S ======================================================= */
49
50 /* === P R O C E D U R E S ================================================= */
51
52 /* === M E T H O D S ======================================================= */
53
54 ValueNode_TimeString::ValueNode_TimeString(const ValueBase &value):
55         LinkableValueNode(value.get_type())
56 {
57         switch(value.get_type())
58         {
59         case ValueBase::TYPE_STRING:
60                 set_link("time",ValueNode_Const::create(Time(0)));
61                 break;
62         default:
63                 throw Exception::BadType(ValueBase::type_local_name(value.get_type()));
64         }
65 }
66
67 LinkableValueNode*
68 ValueNode_TimeString::create_new()const
69 {
70         return new ValueNode_TimeString(get_type());
71 }
72
73 ValueNode_TimeString*
74 ValueNode_TimeString::create(const ValueBase &x)
75 {
76         return new ValueNode_TimeString(x);
77 }
78
79 ValueNode_TimeString::~ValueNode_TimeString()
80 {
81         unlink_all();
82 }
83
84 ValueBase
85 ValueNode_TimeString::operator()(Time t)const
86 {
87         if (getenv("SYNFIG_DEBUG_VALUENODE_OPERATORS"))
88                 printf("%s:%d operator()\n", __FILE__, __LINE__);
89
90         Time time((*time_)(t).get(Time()));
91
92         switch (get_type())
93         {
94         case ValueBase::TYPE_STRING:
95                 if (get_root_canvas())
96                         return time.get_string(get_root_canvas()->rend_desc().get_frame_rate());
97                 else
98                         return time.get_string();
99         default:
100                 break;
101         }
102
103         assert(0);
104         return ValueBase();
105 }
106
107 String
108 ValueNode_TimeString::get_name()const
109 {
110         return "timestring";
111 }
112
113 String
114 ValueNode_TimeString::get_local_name()const
115 {
116         return _("Time String");
117 }
118
119 bool
120 ValueNode_TimeString::set_link_vfunc(int i,ValueNode::Handle value)
121 {
122         assert(i>=0 && i<link_count());
123
124         switch(i)
125         {
126         case 0: CHECK_TYPE_AND_SET_VALUE(time_, ValueBase::TYPE_TIME);
127         }
128         return false;
129 }
130
131 ValueNode::LooseHandle
132 ValueNode_TimeString::get_link_vfunc(int i)const
133 {
134         assert(i>=0 && i<link_count());
135
136         switch(i)
137         {
138         case 0: return time_;
139         }
140
141         return 0;
142 }
143
144 int
145 ValueNode_TimeString::link_count()const
146 {
147         return 1;
148 }
149
150 String
151 ValueNode_TimeString::link_name(int i)const
152 {
153         assert(i>=0 && i<link_count());
154
155         switch(i)
156         {
157                 case 0: return "time";
158         }
159         return String();
160 }
161
162 String
163 ValueNode_TimeString::link_local_name(int i)const
164 {
165         assert(i>=0 && i<link_count());
166
167         switch(i)
168         {
169                 case 0: return _("Time");
170         }
171         return String();
172 }
173
174 int
175 ValueNode_TimeString::get_link_index_from_name(const String &name)const
176 {
177         if (name=="time") return 0;
178
179         throw Exception::BadLinkName(name);
180 }
181
182 bool
183 ValueNode_TimeString::check_type(ValueBase::Type type)
184 {
185         return
186                 type==ValueBase::TYPE_STRING;
187 }
188
189 LinkableValueNode::Vocab
190 ValueNode_TimeString::get_param_vocab()const
191 {
192         LinkableValueNode::Vocab ret;
193
194         ret.push_back(ParamDesc(ValueBase(),"time")
195                 .set_local_name(_("Time"))
196                 .set_description(_("The time that is converted to string"))
197         );
198
199         return ret;
200 }