1 | /* === S Y N F I G ========================================================= */ |
---|
2 | /*! \file valuenodestaticlistinsert.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 "valuenodestaticlistinsert.h" |
---|
34 | #include <synfigapp/canvasinterface.h> |
---|
35 | |
---|
36 | #include <synfigapp/general.h> |
---|
37 | |
---|
38 | #endif |
---|
39 | |
---|
40 | using namespace std; |
---|
41 | using namespace etl; |
---|
42 | using namespace synfig; |
---|
43 | using namespace synfigapp; |
---|
44 | using namespace Action; |
---|
45 | |
---|
46 | /* === M A C R O S ========================================================= */ |
---|
47 | |
---|
48 | ACTION_INIT(Action::ValueNodeStaticListInsert); |
---|
49 | ACTION_SET_NAME(Action::ValueNodeStaticListInsert,"ValueNodeStaticListInsert"); |
---|
50 | ACTION_SET_LOCAL_NAME(Action::ValueNodeStaticListInsert,N_("Insert Item")); |
---|
51 | ACTION_SET_TASK(Action::ValueNodeStaticListInsert,"insert"); |
---|
52 | ACTION_SET_CATEGORY(Action::ValueNodeStaticListInsert,Action::CATEGORY_VALUEDESC|Action::CATEGORY_VALUENODE|Action::CATEGORY_HIDDEN); |
---|
53 | ACTION_SET_PRIORITY(Action::ValueNodeStaticListInsert,-20); |
---|
54 | ACTION_SET_VERSION(Action::ValueNodeStaticListInsert,"0.0"); |
---|
55 | ACTION_SET_CVS_ID(Action::ValueNodeStaticListInsert,"$Id$"); |
---|
56 | |
---|
57 | /* === G L O B A L S ======================================================= */ |
---|
58 | |
---|
59 | /* === P R O C E D U R E S ================================================= */ |
---|
60 | |
---|
61 | /* === M E T H O D S ======================================================= */ |
---|
62 | |
---|
63 | Action::ValueNodeStaticListInsert::ValueNodeStaticListInsert() |
---|
64 | { |
---|
65 | index=0; |
---|
66 | time=0; |
---|
67 | origin=0.5f; |
---|
68 | set_dirty(true); |
---|
69 | } |
---|
70 | |
---|
71 | Action::ParamVocab |
---|
72 | Action::ValueNodeStaticListInsert::get_param_vocab() |
---|
73 | { |
---|
74 | ParamVocab ret(Action::CanvasSpecific::get_param_vocab()); |
---|
75 | |
---|
76 | ret.push_back(ParamDesc("value_desc",Param::TYPE_VALUEDESC) |
---|
77 | .set_local_name(_("ValueDesc")) |
---|
78 | ); |
---|
79 | ret.push_back(ParamDesc("time",Param::TYPE_TIME) |
---|
80 | .set_local_name(_("Time")) |
---|
81 | .set_optional() |
---|
82 | ); |
---|
83 | ret.push_back(ParamDesc("origin",Param::TYPE_REAL) |
---|
84 | .set_local_name(_("Origin")) |
---|
85 | .set_optional() |
---|
86 | ); |
---|
87 | ret.push_back(ParamDesc("item",Param::TYPE_VALUENODE) |
---|
88 | .set_local_name(_("ValueNode to insert")) |
---|
89 | .set_optional() |
---|
90 | ); |
---|
91 | |
---|
92 | return ret; |
---|
93 | } |
---|
94 | |
---|
95 | bool |
---|
96 | Action::ValueNodeStaticListInsert::is_candidate(const ParamList &x) |
---|
97 | { |
---|
98 | if (!candidate_check(get_param_vocab(),x)) |
---|
99 | return false; |
---|
100 | |
---|
101 | ValueDesc value_desc(x.find("value_desc")->second.get_value_desc()); |
---|
102 | |
---|
103 | return (value_desc.parent_is_value_node() && |
---|
104 | // We need a static list. |
---|
105 | ValueNode_StaticList::Handle::cast_dynamic(value_desc.get_parent_value_node())); |
---|
106 | } |
---|
107 | |
---|
108 | // called from two places - both set 'canvas' and 'canvasinterface', and then: |
---|
109 | // |
---|
110 | // ValueNodeStaticListRotateOrder::prepare() sets "value_desc", "item" |
---|
111 | // action->set_param("item",child); <- sets item=list_entry=child |
---|
112 | // action->set_param("value_desc",ValueDesc(value_node,0)); <- sets value_node=value_node, index=0, list_entry=item |
---|
113 | // |
---|
114 | // ValueNodeStaticListInsertSmart::prepare() sets "time", "origin", "value_desc" |
---|
115 | // action->set_param("time",time); |
---|
116 | // action->set_param("origin",origin); |
---|
117 | // action->set_param("value_desc",ValueDesc(value_node,index)); <- sets value_node=value_node, index=index, list_entry=create_list_entry(...) |
---|
118 | // |
---|
119 | // all the perform() does is value_node->add(list_entry,index); |
---|
120 | // |
---|
121 | bool |
---|
122 | Action::ValueNodeStaticListInsert::set_param(const synfig::String& name, const Action::Param ¶m) |
---|
123 | { |
---|
124 | if(name=="value_desc" && param.get_type()==Param::TYPE_VALUEDESC) |
---|
125 | { |
---|
126 | ValueDesc value_desc(param.get_value_desc()); |
---|
127 | |
---|
128 | if(!value_desc.parent_is_value_node()) |
---|
129 | return false; |
---|
130 | |
---|
131 | value_node=ValueNode_StaticList::Handle::cast_dynamic(value_desc.get_parent_value_node()); |
---|
132 | |
---|
133 | if(!value_node) |
---|
134 | return false; |
---|
135 | |
---|
136 | index=value_desc.get_index(); |
---|
137 | |
---|
138 | if(item) |
---|
139 | list_entry=item; |
---|
140 | else |
---|
141 | list_entry=value_node->create_list_entry(index,time,origin); |
---|
142 | |
---|
143 | return true; |
---|
144 | } |
---|
145 | if(name=="time" && param.get_type()==Param::TYPE_TIME) |
---|
146 | { |
---|
147 | time=param.get_time(); |
---|
148 | |
---|
149 | return true; |
---|
150 | } |
---|
151 | if(name=="item" && param.get_type()==Param::TYPE_VALUENODE) |
---|
152 | { |
---|
153 | item=param.get_value_node(); |
---|
154 | if(item) |
---|
155 | list_entry=item; |
---|
156 | |
---|
157 | return true; |
---|
158 | } |
---|
159 | if(name=="origin" && param.get_type()==Param::TYPE_REAL) |
---|
160 | { |
---|
161 | origin=param.get_real(); |
---|
162 | |
---|
163 | return true; |
---|
164 | } |
---|
165 | |
---|
166 | return Action::CanvasSpecific::set_param(name,param); |
---|
167 | } |
---|
168 | |
---|
169 | bool |
---|
170 | Action::ValueNodeStaticListInsert::is_ready()const |
---|
171 | { |
---|
172 | if(!value_node) |
---|
173 | return false; |
---|
174 | return Action::CanvasSpecific::is_ready(); |
---|
175 | } |
---|
176 | |
---|
177 | void |
---|
178 | Action::ValueNodeStaticListInsert::perform() |
---|
179 | { |
---|
180 | if(index>value_node->link_count()) |
---|
181 | index=value_node->link_count(); |
---|
182 | |
---|
183 | value_node->add(list_entry,index); |
---|
184 | |
---|
185 | // Signal that a layer has been inserted |
---|
186 | value_node->changed(); |
---|
187 | /*_if(get_canvas_interface()) |
---|
188 | { |
---|
189 | get_canvas_interface()->signal_value_node_changed()(value_node); |
---|
190 | } |
---|
191 | else synfig::warning("CanvasInterface not set on action");*/ |
---|
192 | } |
---|
193 | |
---|
194 | void |
---|
195 | Action::ValueNodeStaticListInsert::undo() |
---|
196 | { |
---|
197 | value_node->erase(*(value_node->list.begin()+index)); |
---|
198 | |
---|
199 | // Signal that a layer has been inserted |
---|
200 | value_node->changed(); |
---|
201 | /*_if(get_canvas_interface()) |
---|
202 | { |
---|
203 | get_canvas_interface()->signal_value_node_changed()(value_node); |
---|
204 | } |
---|
205 | else synfig::warning("CanvasInterface not set on action");*/ |
---|
206 | } |
---|