my log
[synfig.git] / synfig-studio / trunk / src / synfigapp / actions / layerlower.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file layerlower.cpp
3 **      \brief Template File
4 **
5 **      $Id: layerlower.cpp,v 1.1.1.1 2005/01/07 03:34:37 darco Exp $
6 **
7 **      \legal
8 **      Copyright (c) 2002 Robert B. Quattlebaum Jr.
9 **
10 **      This software and associated documentation
11 **      are CONFIDENTIAL and PROPRIETARY property of
12 **      the above-mentioned copyright holder.
13 **
14 **      You may not copy, print, publish, or in any
15 **      other way distribute this software without
16 **      a prior written agreement with
17 **      the copyright holder.
18 **      \endlegal
19 */
20 /* ========================================================================= */
21
22 /* === H E A D E R S ======================================================= */
23
24 #ifdef USING_PCH
25 #       include "pch.h"
26 #else
27 #ifdef HAVE_CONFIG_H
28 #       include <config.h>
29 #endif
30
31 #include "layerlower.h"
32 #include "layermove.h"
33 #include <synfigapp/canvasinterface.h>
34
35 #endif
36
37 using namespace std;
38 using namespace etl;
39 using namespace synfig;
40 using namespace synfigapp;
41 using namespace Action;
42
43 /* === M A C R O S ========================================================= */
44
45 ACTION_INIT(Action::LayerLower);
46 ACTION_SET_NAME(Action::LayerLower,"layer_lower");
47 ACTION_SET_LOCAL_NAME(Action::LayerLower,"Lower Layer");
48 ACTION_SET_TASK(Action::LayerLower,"lower");
49 ACTION_SET_CATEGORY(Action::LayerLower,Action::CATEGORY_LAYER);
50 ACTION_SET_PRIORITY(Action::LayerLower,10);
51 ACTION_SET_VERSION(Action::LayerLower,"0.0");
52 ACTION_SET_CVS_ID(Action::LayerLower,"$Id: layerlower.cpp,v 1.1.1.1 2005/01/07 03:34:37 darco Exp $");
53
54 /* === G L O B A L S ======================================================= */
55
56 /* === P R O C E D U R E S ================================================= */
57
58 /* === M E T H O D S ======================================================= */
59
60 Action::LayerLower::LayerLower()
61 {
62 }
63
64 Action::ParamVocab
65 Action::LayerLower::get_param_vocab()
66 {
67         ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
68         
69         ret.push_back(ParamDesc("layer",Param::TYPE_LAYER)
70                 .set_local_name(_("Layer"))
71                 .set_desc(_("Layer to be lowered"))
72                 .set_supports_multiple()
73         );
74         
75         return ret;
76 }
77
78 bool
79 Action::LayerLower::is_canidate(const ParamList &x)
80 {
81         if(!canidate_check(get_param_vocab(),x))
82                 return false;
83         
84         Layer::Handle layer(x.find("layer")->second.get_layer());
85         //synfig::info("layer->get_depth()= %d ; layer->get_canvas()->size()=%d ;",layer->get_depth(),layer->get_canvas()->size());
86         if(layer->get_depth()+1>=layer->get_canvas()->size())
87                 return false;
88         return true;
89 }
90
91 bool
92 Action::LayerLower::set_param(const synfig::String& name, const Action::Param &param)
93 {
94         if(name=="layer" && param.get_type()==Param::TYPE_LAYER)
95         {
96                 layers.push_back(param.get_layer());
97                 
98                 return true;
99         }
100
101         return Action::CanvasSpecific::set_param(name,param);
102 }
103
104 bool
105 Action::LayerLower::is_ready()const
106 {
107         if(layers.empty())
108                 return false;
109         return Action::CanvasSpecific::is_ready();
110 }
111
112 void
113 Action::LayerLower::prepare()
114 {
115         std::list<synfig::Layer::Handle>::const_iterator iter;
116
117         clear();
118         
119         for(iter=layers.begin();iter!=layers.end();++iter)
120         {
121                 Layer::Handle layer(*iter);
122                 
123                 Canvas::Handle subcanvas(layer->get_canvas());
124                 
125                 // Find the iterator for the layer
126                 Canvas::iterator iter=find(subcanvas->begin(),subcanvas->end(),layer);
127                 
128                 // If we couldn't find the layer in the canvas, then bail
129                 if(*iter!=layer)
130                         throw Error(_("This layer doesn't exist anymore."));
131         
132                 // If the subcanvas isn't the same as the canvas,
133                 // then it had better be an inline canvas. If not,
134                 // bail
135                 //if(get_canvas()!=subcanvas && !subcanvas->is_inline())
136                 //      throw Error(_("This layer doesn't belong to this canvas anymore"));
137                 
138                 int new_index=iter-subcanvas->begin();
139                                 
140                 new_index++;
141                 
142                 // If this lowers the layer past the bottom then don't bother
143                 if(new_index==subcanvas->size())
144                         continue;
145                 
146                 Action::Handle layer_move(LayerMove::create());
147                 
148                 layer_move->set_param("canvas",get_canvas());
149                 layer_move->set_param("canvas_interface",get_canvas_interface());
150                 layer_move->set_param("layer",layer);
151                 layer_move->set_param("new_index",new_index);
152                 
153                 add_action_front(layer_move);
154         }
155 }