1 /* === S Y N F I G ========================================================= */
2 /*! \file layerlower.cpp
3 ** \brief Template File
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 ** Copyright (c) 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.
22 /* ========================================================================= */
24 /* === H E A D E R S ======================================================= */
33 #include "layerlower.h"
34 #include "layermove.h"
35 #include <synfigapp/canvasinterface.h>
37 #include <synfigapp/general.h>
43 using namespace synfig;
44 using namespace synfigapp;
45 using namespace Action;
47 /* === M A C R O S ========================================================= */
49 ACTION_INIT_NO_GET_LOCAL_NAME(Action::LayerLower);
50 ACTION_SET_NAME(Action::LayerLower,"layer_lower");
51 ACTION_SET_LOCAL_NAME(Action::LayerLower,N_("Lower Layer"));
52 ACTION_SET_TASK(Action::LayerLower,"lower");
53 ACTION_SET_CATEGORY(Action::LayerLower,Action::CATEGORY_LAYER);
54 ACTION_SET_PRIORITY(Action::LayerLower,10);
55 ACTION_SET_VERSION(Action::LayerLower,"0.0");
56 ACTION_SET_CVS_ID(Action::LayerLower,"$Id$");
58 /* === G L O B A L S ======================================================= */
60 /* === P R O C E D U R E S ================================================= */
62 /* === M E T H O D S ======================================================= */
64 Action::LayerLower::LayerLower()
69 Action::LayerLower::get_local_name()const
71 return get_layer_descriptions(layers, _("Lower Layer"), _("Lower Layers"));
75 Action::LayerLower::get_param_vocab()
77 ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
79 ret.push_back(ParamDesc("layer",Param::TYPE_LAYER)
80 .set_local_name(_("Layer"))
81 .set_desc(_("Layer to be lowered"))
82 .set_supports_multiple()
89 Action::LayerLower::is_candidate(const ParamList &x)
91 if(!candidate_check(get_param_vocab(),x))
94 Layer::Handle layer(x.find("layer")->second.get_layer());
95 //synfig::info("layer->get_depth()= %d ; layer->get_canvas()->size()=%d ;",layer->get_depth(),layer->get_canvas()->size());
96 if(layer->get_depth()+1>=layer->get_canvas()->size())
102 Action::LayerLower::set_param(const synfig::String& name, const Action::Param ¶m)
104 if(name=="layer" && param.get_type()==Param::TYPE_LAYER)
106 layers.push_back(param.get_layer());
111 return Action::CanvasSpecific::set_param(name,param);
115 Action::LayerLower::is_ready()const
119 return Action::CanvasSpecific::is_ready();
123 Action::LayerLower::prepare()
125 std::list<synfig::Layer::Handle>::const_iterator iter;
129 for(iter=layers.begin();iter!=layers.end();++iter)
131 Layer::Handle layer(*iter);
133 Canvas::Handle subcanvas(layer->get_canvas());
135 // Find the iterator for the layer
136 Canvas::iterator iter=find(subcanvas->begin(),subcanvas->end(),layer);
138 // If we couldn't find the layer in the canvas, then bail
140 throw Error(_("This layer doesn't exist anymore."));
142 // If the subcanvas isn't the same as the canvas,
143 // then it had better be an inline canvas. If not,
145 //if(get_canvas()!=subcanvas && !subcanvas->is_inline())
146 // throw Error(_("This layer doesn't belong to this canvas anymore"));
148 int new_index=iter-subcanvas->begin();
152 // If this lowers the layer past the bottom then don't bother
153 if(new_index==subcanvas->size())
156 Action::Handle layer_move(LayerMove::create());
158 layer_move->set_param("canvas",get_canvas());
159 layer_move->set_param("canvas_interface",get_canvas_interface());
160 layer_move->set_param("layer",layer);
161 layer_move->set_param("new_index",new_index);
163 add_action_front(layer_move);