1 /* === S Y N F I G ========================================================= */
2 /*! \file layer_duplicate.cpp
3 ** \brief Implementation of the "Duplicate" layer
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 ** Copyright (c) 2007 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.
22 /* ========================================================================= */
24 /* === H E A D E R S ======================================================= */
34 #include "layer_duplicate.h"
37 #include "paramdesc.h"
41 #include "valuenode.h"
46 /* === U S I N G =========================================================== */
48 using namespace synfig;
52 /* === G L O B A L S ======================================================= */
54 SYNFIG_LAYER_INIT(Layer_Duplicate);
55 SYNFIG_LAYER_SET_NAME(Layer_Duplicate,"duplicate");
56 SYNFIG_LAYER_SET_LOCAL_NAME(Layer_Duplicate,N_("Duplicate"));
57 SYNFIG_LAYER_SET_CATEGORY(Layer_Duplicate,N_("Other"));
58 SYNFIG_LAYER_SET_VERSION(Layer_Duplicate,"0.1");
59 SYNFIG_LAYER_SET_CVS_ID(Layer_Duplicate,"$Id$");
61 /* === M E M B E R S ======================================================= */
63 Layer_Duplicate::Layer_Duplicate():
64 Layer_Composite(1.0,Color::BLEND_COMPOSITE)
66 LinkableValueNode* index_value_node = ValueNode_Duplicate::create(Real(3));
67 connect_dynamic_param("index", index_value_node);
71 Layer_Duplicate::clone(const GUID& deriv_guid)const
73 printf("cloning layer duplicate\n");
74 Layer::Handle ret = (Layer::Handle)Layer_Composite::clone(deriv_guid);
76 const DynamicParamList &dpl = dynamic_param_list();
77 DynamicParamList::const_iterator iter = dpl.find("index");
79 // if we have a dynamic "index" parameter, make a new one in the clone
80 // it's not good to have two references to the same index valuenode,
81 // or nested duplicatations cause an infinite loop
82 if (iter != dpl.end())
83 ret->connect_dynamic_param(iter->first,iter->second->clone(deriv_guid));
89 Layer_Duplicate::set_param(const String ¶m, const ValueBase &value)
92 return Layer_Composite::set_param(param,value);
96 Layer_Duplicate::get_param(const String ¶m)const
103 return Layer_Composite::get_param(param);
107 Layer_Duplicate::set_time(Context context, Time time)const
109 context.set_time(time);
114 Layer_Duplicate::set_time(Context context, Time time, const Point &pos)const
116 context.set_time(time,pos);
121 Layer_Duplicate::get_color(Context context, const Point &pos)const
123 return context.get_color(pos);
127 Layer_Duplicate::get_param_vocab()const
130 ret=Layer_Composite::get_param_vocab();
132 ret.push_back(ParamDesc("index")
133 .set_local_name(_("Index"))
134 .set_description(_("Copy Index"))
140 ValueNode_Duplicate::Handle
141 Layer_Duplicate::get_duplicate_param()const
143 const DynamicParamList &dpl = dynamic_param_list();
144 DynamicParamList::const_iterator iter = dpl.find("index");
145 if (iter == dpl.end()) return NULL;
146 etl::rhandle<ValueNode> param(iter->second);
147 return ValueNode_Duplicate::Handle::cast_dynamic(param);
151 Layer_Duplicate::accelerated_render(Context context,Surface *surface,int quality, const RendDesc &renddesc, ProgressCallback *cb)const
154 return context.accelerated_render(surface,quality,renddesc,cb);
158 surface->set_wh(renddesc.get_w(),renddesc.get_h());
163 SuperCallback subimagecb;
167 handle<ValueNode_Duplicate> duplicate_param = get_duplicate_param();
168 if (!duplicate_param) return context.accelerated_render(surface,quality,renddesc,cb);
170 surface->set_wh(renddesc.get_w(),renddesc.get_h());
173 Color::BlendMethod blend_method(get_blend_method());
174 int steps = duplicate_param->count_steps(time_cur);
176 Mutex::Lock lock(mutex);
177 duplicate_param->reset_index(time_cur);
180 subimagecb=SuperCallback(cb,i*(5000/steps),(i+1)*(5000/steps),5000);
181 // \todo can we force a re-evaluation of all the variables without changing the time twice?
182 context.set_time(time_cur+1);
183 context.set_time(time_cur);
184 if(!context.accelerated_render(&tmp,quality,renddesc,&subimagecb)) return false;
186 Surface::alpha_pen apen(surface->begin());
187 apen.set_alpha(get_amount());
188 // \todo have a checkbox allowing use of 'behind' to reverse the order?
189 apen.set_blend_method(i ? blend_method : Color::BLEND_COMPOSITE);
192 } while (duplicate_param->step(time_cur));