source: synfigstudio/trunk/fuentes/src/synfigapp/actions/layerraise.cpp @ 481

Last change on this file since 481 was 481, checked in by jrpelegrina, 4 years ago

First release to xenial

File size: 4.1 KB
Line 
1/* === S Y N F I G ========================================================= */
2/*!     \file layerraise.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 "layerraise.h"
34#include "layermove.h"
35#include <synfigapp/canvasinterface.h>
36
37#include <synfigapp/general.h>
38
39#endif
40
41using namespace std;
42using namespace etl;
43using namespace synfig;
44using namespace synfigapp;
45using namespace Action;
46
47/* === M A C R O S ========================================================= */
48
49ACTION_INIT_NO_GET_LOCAL_NAME(Action::LayerRaise);
50ACTION_SET_NAME(Action::LayerRaise,"LayerRaise");
51ACTION_SET_LOCAL_NAME(Action::LayerRaise,N_("Raise Layer"));
52ACTION_SET_TASK(Action::LayerRaise,"raise");
53ACTION_SET_CATEGORY(Action::LayerRaise,Action::CATEGORY_LAYER);
54ACTION_SET_PRIORITY(Action::LayerRaise,9);
55ACTION_SET_VERSION(Action::LayerRaise,"0.0");
56ACTION_SET_CVS_ID(Action::LayerRaise,"$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
64Action::LayerRaise::LayerRaise()
65{
66}
67
68synfig::String
69Action::LayerRaise::get_local_name()const
70{
71        return get_layer_descriptions(layers, _("Raise Layer"), _("Raise Layers"));
72}
73
74Action::ParamVocab
75Action::LayerRaise::get_param_vocab()
76{
77        ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
78
79        ret.push_back(ParamDesc("layer",Param::TYPE_LAYER)
80                .set_local_name(_("Layer"))
81                .set_desc(_("Layer to be raised"))
82                .set_supports_multiple()
83        );
84
85        return ret;
86}
87
88bool
89Action::LayerRaise::is_candidate(const ParamList &x)
90{
91        if(!candidate_check(get_param_vocab(),x))
92                return false;
93        if(x.find("layer")->second.get_layer()->get_depth()==0)
94                return false;
95        return true;
96}
97
98bool
99Action::LayerRaise::set_param(const synfig::String& name, const Action::Param &param)
100{
101        if(name=="layer" && param.get_type()==Param::TYPE_LAYER)
102        {
103                layers.push_back(param.get_layer());
104
105                return true;
106        }
107
108        return Action::CanvasSpecific::set_param(name,param);
109}
110
111bool
112Action::LayerRaise::is_ready()const
113{
114        if(layers.empty())
115                return false;
116        return Action::CanvasSpecific::is_ready();
117}
118
119void
120Action::LayerRaise::prepare()
121{
122        std::list<synfig::Layer::Handle>::reverse_iterator iter;
123
124        clear();
125
126        for(iter=layers.rbegin();!(iter==layers.rend());++iter)
127        {
128                Layer::Handle layer(*iter);
129
130                Canvas::Handle subcanvas(layer->get_canvas());
131
132                // Find the iterator for the layer
133                Canvas::iterator iter=find(subcanvas->begin(),subcanvas->end(),layer);
134
135                // If we couldn't find the layer in the canvas, then bail
136                if(*iter!=layer)
137                        throw Error(_("This layer doesn't exist anymore."));
138
139                // If the subcanvas isn't the same as the canvas,
140                // then it had better be an inline canvas. If not,
141                // bail
142                //if(get_canvas()!=subcanvas && !subcanvas->is_inline())
143                //      throw Error(_("This layer doesn't belong to this canvas anymore"));
144
145                int new_index=iter-subcanvas->begin();
146
147                if(new_index==0)
148                        continue;
149
150                new_index--;
151
152                Action::Handle layer_move(LayerMove::create());
153
154                layer_move->set_param("canvas",get_canvas());
155                layer_move->set_param("canvas_interface",get_canvas_interface());
156                layer_move->set_param("layer",layer);
157                layer_move->set_param("new_index",new_index);
158
159                add_action_front(layer_move);
160        }
161}
Note: See TracBrowser for help on using the repository browser.