X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=synfig-studio%2Ftags%2Fsynfigstudio_0_61_05%2Fsynfig-studio%2Fsrc%2Fsynfigapp%2Factions%2Flayerencapsulate.cpp;fp=synfig-studio%2Ftags%2Fsynfigstudio_0_61_05%2Fsynfig-studio%2Fsrc%2Fsynfigapp%2Factions%2Flayerencapsulate.cpp;h=069fcee599cced4f8977b5072c216e0143732230;hb=7ba2096dd58b21ba3a08b28b5a6f70795f6ea265;hp=0000000000000000000000000000000000000000;hpb=043865a2284e71de646b09cc0f22b5674b95a454;p=synfig.git diff --git a/synfig-studio/tags/synfigstudio_0_61_05/synfig-studio/src/synfigapp/actions/layerencapsulate.cpp b/synfig-studio/tags/synfigstudio_0_61_05/synfig-studio/src/synfigapp/actions/layerencapsulate.cpp new file mode 100644 index 0000000..069fcee --- /dev/null +++ b/synfig-studio/tags/synfigstudio_0_61_05/synfig-studio/src/synfigapp/actions/layerencapsulate.cpp @@ -0,0 +1,217 @@ +/* === S Y N F I G ========================================================= */ +/*! \file layerraise.cpp +** \brief Template File +** +** $Id: layerencapsulate.cpp,v 1.1.1.1 2005/01/07 03:34:37 darco Exp $ +** +** \legal +** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley +** +** This package is free software; you can redistribute it and/or +** modify it under the terms of the GNU General Public License as +** published by the Free Software Foundation; either version 2 of +** the License, or (at your option) any later version. +** +** This package is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +** General Public License for more details. +** \endlegal +*/ +/* ========================================================================= */ + +/* === H E A D E R S ======================================================= */ + +#ifdef USING_PCH +# include "pch.h" +#else +#ifdef HAVE_CONFIG_H +# include +#endif + +#include "layerencapsulate.h" +#include "layeradd.h" +#include "layerremove.h" +#include + +#endif + +using namespace std; +using namespace etl; +using namespace synfig; +using namespace synfigapp; +using namespace Action; + +/* === M A C R O S ========================================================= */ + +ACTION_INIT(Action::LayerEncapsulate); +ACTION_SET_NAME(Action::LayerEncapsulate,"layer_encapsulate"); +ACTION_SET_LOCAL_NAME(Action::LayerEncapsulate,"Encapsulate"); +ACTION_SET_TASK(Action::LayerEncapsulate,"encapsulate"); +ACTION_SET_CATEGORY(Action::LayerEncapsulate,Action::CATEGORY_LAYER); +ACTION_SET_PRIORITY(Action::LayerEncapsulate,0); +ACTION_SET_VERSION(Action::LayerEncapsulate,"0.0"); +ACTION_SET_CVS_ID(Action::LayerEncapsulate,"$Id: layerencapsulate.cpp,v 1.1.1.1 2005/01/07 03:34:37 darco Exp $"); + +/* === G L O B A L S ======================================================= */ + +/* === P R O C E D U R E S ================================================= */ + +/* === M E T H O D S ======================================================= */ + +Action::LayerEncapsulate::LayerEncapsulate() +{ +} + +Action::ParamVocab +Action::LayerEncapsulate::get_param_vocab() +{ + ParamVocab ret(Action::CanvasSpecific::get_param_vocab()); + + ret.push_back(ParamDesc("layer",Param::TYPE_LAYER) + .set_local_name(_("Layer")) + .set_desc(_("Layer to be encapsulated")) + .set_supports_multiple() + ); + + return ret; +} + +bool +Action::LayerEncapsulate::is_canidate(const ParamList &x) +{ + return canidate_check(get_param_vocab(),x); +} + +bool +Action::LayerEncapsulate::set_param(const synfig::String& name, const Action::Param ¶m) +{ + if(name=="layer" && param.get_type()==Param::TYPE_LAYER) + { + layers.push_back(param.get_layer()); + + return true; + } + + return Action::CanvasSpecific::set_param(name,param); +} + +bool +Action::LayerEncapsulate::is_ready()const +{ + if(layers.empty()) + return false; + return Action::CanvasSpecific::is_ready(); +} + +int +Action::LayerEncapsulate::lowest_depth()const +{ + std::list::const_iterator iter; + int lowest_depth(0x7fffffff); + + for(iter=layers.begin();iter!=layers.end();++iter) + { + int depth((*iter)->get_depth()); + if(depthset_param("canvas",child_canvas); + + int target_depth(lowest_depth()); + + // Add the layer + { + Action::Handle action(LayerAdd::create()); + + action->set_param("canvas",get_canvas()); + action->set_param("canvas_interface",get_canvas_interface()); + action->set_param("new",new_layer); + + add_action(action); + } + + // Move the layer + { + Action::Handle action(Action::create("layer_move")); + + assert(action); + + action->set_param("canvas",get_canvas()); + action->set_param("canvas_interface",get_canvas_interface()); + action->set_param("layer",new_layer); + action->set_param("new_index",target_depth); + + add_action(action); + } + + std::list::reverse_iterator iter; + + for(iter=layers.rbegin();iter!=layers.rend();++iter) + { + Layer::Handle layer(*iter); + + Canvas::Handle subcanvas(layer->get_canvas()); + + // Find the iterator for the layer + Canvas::iterator iter=find(subcanvas->begin(),subcanvas->end(),layer); + + // If we couldn't find the layer in the canvas, then bail + if(*iter!=layer) + throw Error(_("This layer doesn't exist anymore.")); + + if(!subcanvas) + throw Error(_("This layer doesn't have a parent canvas")); + + // If the subcanvas isn't the same as the canvas, + // then it had better be an inline canvas. If not, + // bail + if(get_canvas()!=subcanvas && !subcanvas->is_inline()) + throw Error(_("This layer doesn't belong to this canvas anymore")); + + if(get_canvas()!=subcanvas) + throw Error(_("get_canvas()!=subcanvas")); + + // Remove the layer from the old canvas + { + Action::Handle action(LayerRemove::create()); + + action->set_param("canvas",subcanvas); + action->set_param("canvas_interface",get_canvas_interface()); + action->set_param("layer",layer); + + add_action(action); + } + // Add the layer to the new canvas + { + Action::Handle action(LayerAdd::create()); + + action->set_param("canvas",child_canvas); + action->set_param("canvas_interface",get_canvas_interface()); + action->set_param("new",layer); + + add_action(action); + } + } +}