1 | /* === S Y N F I G ========================================================= */ |
---|
2 | /*! \file valuenodestaticlistremovesmart.cpp |
---|
3 | ** \brief Template File |
---|
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 "valuenodestaticlistremovesmart.h" |
---|
34 | #include "valuenodestaticlistremove.h" |
---|
35 | #include <synfigapp/canvasinterface.h> |
---|
36 | |
---|
37 | #include <synfigapp/general.h> |
---|
38 | |
---|
39 | #endif |
---|
40 | |
---|
41 | using namespace std; |
---|
42 | using namespace etl; |
---|
43 | using namespace synfig; |
---|
44 | using namespace synfigapp; |
---|
45 | using namespace Action; |
---|
46 | |
---|
47 | /* === M A C R O S ========================================================= */ |
---|
48 | |
---|
49 | ACTION_INIT(Action::ValueNodeStaticListRemoveSmart); |
---|
50 | ACTION_SET_NAME(Action::ValueNodeStaticListRemoveSmart,"ValueNodeStaticListRemoveSmart"); |
---|
51 | ACTION_SET_LOCAL_NAME(Action::ValueNodeStaticListRemoveSmart,N_("Remove Item (Smart)")); |
---|
52 | ACTION_SET_TASK(Action::ValueNodeStaticListRemoveSmart,"remove"); |
---|
53 | ACTION_SET_CATEGORY(Action::ValueNodeStaticListRemoveSmart,Action::CATEGORY_VALUEDESC|Action::CATEGORY_VALUENODE); |
---|
54 | ACTION_SET_PRIORITY(Action::ValueNodeStaticListRemoveSmart,-19); |
---|
55 | ACTION_SET_VERSION(Action::ValueNodeStaticListRemoveSmart,"0.0"); |
---|
56 | ACTION_SET_CVS_ID(Action::ValueNodeStaticListRemoveSmart,"$Id$"); |
---|
57 | |
---|
58 | /* === G L O B A L S ======================================================= */ |
---|
59 | |
---|
60 | /* === P R O C E D U R E S ================================================= */ |
---|
61 | |
---|
62 | /* === M E T H O D S ======================================================= */ |
---|
63 | |
---|
64 | Action::ValueNodeStaticListRemoveSmart::ValueNodeStaticListRemoveSmart() |
---|
65 | { |
---|
66 | index=0; |
---|
67 | time=0; |
---|
68 | origin=0.5f; |
---|
69 | set_dirty(true); |
---|
70 | } |
---|
71 | |
---|
72 | #ifdef _DEBUG |
---|
73 | Action::ValueNodeStaticListRemoveSmart::~ValueNodeStaticListRemoveSmart() |
---|
74 | { |
---|
75 | printf("%s:%d ~ValueNodeStaticListRemoveSmart()\n", __FILE__, __LINE__); |
---|
76 | } |
---|
77 | #endif |
---|
78 | |
---|
79 | Action::ParamVocab |
---|
80 | Action::ValueNodeStaticListRemoveSmart::get_param_vocab() |
---|
81 | { |
---|
82 | ParamVocab ret(Action::CanvasSpecific::get_param_vocab()); |
---|
83 | |
---|
84 | ret.push_back(ParamDesc("value_desc",Param::TYPE_VALUEDESC) |
---|
85 | .set_local_name(_("ValueDesc")) |
---|
86 | ); |
---|
87 | ret.push_back(ParamDesc("time",Param::TYPE_TIME) |
---|
88 | .set_local_name(_("Time")) |
---|
89 | .set_optional() |
---|
90 | ); |
---|
91 | ret.push_back(ParamDesc("origin",Param::TYPE_REAL) |
---|
92 | .set_local_name(_("Origin")) |
---|
93 | .set_optional() |
---|
94 | ); |
---|
95 | |
---|
96 | return ret; |
---|
97 | } |
---|
98 | |
---|
99 | bool |
---|
100 | Action::ValueNodeStaticListRemoveSmart::is_candidate(const ParamList &x) |
---|
101 | { |
---|
102 | if (!candidate_check(get_param_vocab(),x)) |
---|
103 | return false; |
---|
104 | |
---|
105 | ValueDesc value_desc(x.find("value_desc")->second.get_value_desc()); |
---|
106 | |
---|
107 | return (value_desc.parent_is_value_node() && |
---|
108 | // We need a static list. |
---|
109 | ValueNode_StaticList::Handle::cast_dynamic(value_desc.get_parent_value_node())); |
---|
110 | } |
---|
111 | |
---|
112 | bool |
---|
113 | Action::ValueNodeStaticListRemoveSmart::set_param(const synfig::String& name, const Action::Param ¶m) |
---|
114 | { |
---|
115 | if(name=="value_desc" && param.get_type()==Param::TYPE_VALUEDESC) |
---|
116 | { |
---|
117 | ValueDesc value_desc(param.get_value_desc()); |
---|
118 | |
---|
119 | if(!value_desc.parent_is_value_node()) |
---|
120 | return false; |
---|
121 | |
---|
122 | value_node=ValueNode_StaticList::Handle::cast_dynamic(value_desc.get_parent_value_node()); |
---|
123 | |
---|
124 | if(!value_node) |
---|
125 | return false; |
---|
126 | |
---|
127 | index=value_desc.get_index(); |
---|
128 | |
---|
129 | return true; |
---|
130 | } |
---|
131 | if(name=="time" && param.get_type()==Param::TYPE_TIME) |
---|
132 | { |
---|
133 | time=param.get_time(); |
---|
134 | |
---|
135 | return true; |
---|
136 | } |
---|
137 | if(name=="origin" && param.get_type()==Param::TYPE_REAL) |
---|
138 | { |
---|
139 | origin=param.get_real(); |
---|
140 | |
---|
141 | return true; |
---|
142 | } |
---|
143 | |
---|
144 | return Action::CanvasSpecific::set_param(name,param); |
---|
145 | } |
---|
146 | |
---|
147 | bool |
---|
148 | Action::ValueNodeStaticListRemoveSmart::is_ready()const |
---|
149 | { |
---|
150 | if(!value_node) |
---|
151 | return false; |
---|
152 | return Action::CanvasSpecific::is_ready(); |
---|
153 | } |
---|
154 | |
---|
155 | void |
---|
156 | Action::ValueNodeStaticListRemoveSmart::prepare() |
---|
157 | { |
---|
158 | clear(); |
---|
159 | |
---|
160 | // If we are in animate editing mode |
---|
161 | if(get_edit_mode()&MODE_ANIMATE) |
---|
162 | { |
---|
163 | Action::Handle action(Action::create("ActivepointSetOff")); |
---|
164 | |
---|
165 | if(!action) |
---|
166 | throw Error(_("Unable to find action (bug)")); |
---|
167 | |
---|
168 | action->set_param("canvas",get_canvas()); |
---|
169 | action->set_param("canvas_interface",get_canvas_interface()); |
---|
170 | action->set_param("time",time); |
---|
171 | action->set_param("origin",origin); |
---|
172 | action->set_param("value_desc",ValueDesc(value_node,index)); |
---|
173 | |
---|
174 | if(!action->is_ready()) |
---|
175 | throw Error(Error::TYPE_NOTREADY); |
---|
176 | |
---|
177 | add_action(action); |
---|
178 | } |
---|
179 | else |
---|
180 | { |
---|
181 | Action::Handle action(Action::create("ValueNodeStaticListRemove")); |
---|
182 | |
---|
183 | if(!action) |
---|
184 | throw Error(_("Unable to find action (bug)")); |
---|
185 | |
---|
186 | action->set_param("canvas",get_canvas()); |
---|
187 | action->set_param("canvas_interface",get_canvas_interface()); |
---|
188 | action->set_param("time",time); |
---|
189 | action->set_param("origin",origin); |
---|
190 | action->set_param("value_desc",ValueDesc(value_node,index)); |
---|
191 | |
---|
192 | if(!action->is_ready()) |
---|
193 | throw Error(Error::TYPE_NOTREADY); |
---|
194 | |
---|
195 | add_action(action); |
---|
196 | } |
---|
197 | } |
---|