|
Carlos López |
d6e10f |
/* === S Y N F I G ========================================================= */
|
|
Carlos López |
d6e10f |
/*! \file layerzdepthrangeset.cpp
|
|
Carlos López |
d6e10f |
** \brief Template File
|
|
Carlos López |
d6e10f |
**
|
|
Carlos López |
d6e10f |
** $Id$
|
|
Carlos López |
d6e10f |
**
|
|
Carlos López |
d6e10f |
** \legal
|
|
Carlos López |
d6e10f |
** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
|
|
Carlos López |
d6e10f |
** Copyright (c) 2007, 2008 Chris Moore
|
|
Carlos López |
d6e10f |
**
|
|
Carlos López |
d6e10f |
** This package is free software; you can redistribute it and/or
|
|
Carlos López |
d6e10f |
** modify it under the terms of the GNU General Public License as
|
|
Carlos López |
d6e10f |
** published by the Free Software Foundation; either version 2 of
|
|
Carlos López |
d6e10f |
** the License, or (at your option) any later version.
|
|
Carlos López |
d6e10f |
**
|
|
Carlos López |
d6e10f |
** This package is distributed in the hope that it will be useful,
|
|
Carlos López |
d6e10f |
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Carlos López |
d6e10f |
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Carlos López |
d6e10f |
** General Public License for more details.
|
|
Carlos López |
d6e10f |
** \endlegal
|
|
Carlos López |
d6e10f |
*/
|
|
Carlos López |
d6e10f |
/* ========================================================================= */
|
|
Carlos López |
d6e10f |
|
|
Carlos López |
d6e10f |
/* === H E A D E R S ======================================================= */
|
|
Carlos López |
d6e10f |
|
|
Carlos López |
d6e10f |
#ifdef USING_PCH
|
|
Carlos López |
d6e10f |
# include "pch.h"
|
|
Carlos López |
d6e10f |
#else
|
|
Carlos López |
d6e10f |
#ifdef HAVE_CONFIG_H
|
|
Carlos López |
d6e10f |
# include <config.h></config.h>
|
|
Carlos López |
d6e10f |
#endif
|
|
Carlos López |
d6e10f |
|
|
bw |
94d8a6 |
#include <synfig general.h=""></synfig>
|
|
bw |
94d8a6 |
|
|
Carlos López |
d6e10f |
#include "layerzdepthrangeset.h"
|
|
Carlos López |
d6e10f |
#include "layeradd.h"
|
|
Carlos López |
d6e10f |
#include "layerremove.h"
|
|
Carlos López |
d6e10f |
#include <synfigapp canvasinterface.h=""></synfigapp>
|
|
Carlos López |
d6e10f |
|
|
|
abdbf2 |
#include <synfigapp localization.h=""></synfigapp>
|
|
Carlos López |
d6e10f |
|
|
Diego Barrios Romero |
dcc14d |
#include <synfig layer_group.h="" layers=""></synfig>
|
|
|
a53027 |
|
|
Carlos López |
d6e10f |
#endif
|
|
Carlos López |
d6e10f |
|
|
Carlos López |
d6e10f |
using namespace std;
|
|
Carlos López |
d6e10f |
using namespace etl;
|
|
Carlos López |
d6e10f |
using namespace synfig;
|
|
Carlos López |
d6e10f |
using namespace synfigapp;
|
|
Carlos López |
d6e10f |
using namespace Action;
|
|
Carlos López |
d6e10f |
|
|
Carlos López |
d6e10f |
/* === M A C R O S ========================================================= */
|
|
Carlos López |
d6e10f |
|
|
Carlos López |
d6e10f |
ACTION_INIT_NO_GET_LOCAL_NAME(Action::LayerZDepthRangeSet);
|
|
Carlos López |
d6e10f |
ACTION_SET_NAME(Action::LayerZDepthRangeSet,"LayerZDepthRangeSet");
|
|
Carlos Lopez |
deb9e8 |
ACTION_SET_LOCAL_NAME(Action::LayerZDepthRangeSet,N_("Make Z Range visible"));
|
|
Carlos López |
d6e10f |
ACTION_SET_TASK(Action::LayerZDepthRangeSet,"zdetph_range_set");
|
|
Carlos López |
d6e10f |
ACTION_SET_CATEGORY(Action::LayerZDepthRangeSet,Action::CATEGORY_LAYER);
|
|
Carlos López |
d6e10f |
ACTION_SET_PRIORITY(Action::LayerZDepthRangeSet,0);
|
|
Carlos López |
d6e10f |
ACTION_SET_VERSION(Action::LayerZDepthRangeSet,"0.0");
|
|
Carlos López |
d6e10f |
ACTION_SET_CVS_ID(Action::LayerZDepthRangeSet,"$Id$");
|
|
Carlos López |
d6e10f |
|
|
Carlos López |
a772f5 |
#define ZDEPTH_MAX 1e8
|
|
Carlos López |
e7bf77 |
#define ZDEPTH_EPS 0.0
|
|
Carlos López |
d6e10f |
/* === G L O B A L S ======================================================= */
|
|
Carlos López |
d6e10f |
|
|
Carlos López |
d6e10f |
/* === P R O C E D U R E S ================================================= */
|
|
Carlos López |
d6e10f |
|
|
Carlos López |
d6e10f |
/* === M E T H O D S ======================================================= */
|
|
Carlos López |
d6e10f |
|
|
Carlos López |
d6e10f |
Action::LayerZDepthRangeSet::LayerZDepthRangeSet()
|
|
Carlos López |
d6e10f |
{
|
|
Carlos López |
a772f5 |
z_depth=ZDEPTH_EPS;
|
|
Carlos López |
a772f5 |
z_position=ZDEPTH_MAX;
|
|
Carlos López |
d6e10f |
}
|
|
Carlos López |
d6e10f |
|
|
Carlos López |
d6e10f |
synfig::String
|
|
Carlos López |
d6e10f |
Action::LayerZDepthRangeSet::get_local_name()const
|
|
Carlos López |
d6e10f |
{
|
|
Carlos Lopez |
b964ee |
return get_layer_descriptions(layers, _("Make Z Range visible"), _("Make Z Range visible"));
|
|
Carlos López |
d6e10f |
}
|
|
Carlos López |
d6e10f |
|
|
Carlos López |
d6e10f |
Action::ParamVocab
|
|
Carlos López |
d6e10f |
Action::LayerZDepthRangeSet::get_param_vocab()
|
|
Carlos López |
d6e10f |
{
|
|
Carlos López |
d6e10f |
ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
|
|
Carlos López |
d6e10f |
|
|
Carlos López |
d6e10f |
ret.push_back(ParamDesc("layer",Param::TYPE_LAYER)
|
|
Carlos López |
d6e10f |
.set_local_name(_("Layer"))
|
|
Carlos Lopez |
b964ee |
.set_desc(_("Layer to make Z Range visible"))
|
|
Carlos López |
d6e10f |
.set_supports_multiple()
|
|
Carlos López |
d6e10f |
);
|
|
Carlos López |
d6e10f |
|
|
Carlos López |
d6e10f |
return ret;
|
|
Carlos López |
d6e10f |
}
|
|
Carlos López |
d6e10f |
|
|
Carlos López |
d6e10f |
bool
|
|
Carlos López |
d6e10f |
Action::LayerZDepthRangeSet::is_candidate(const ParamList &x)
|
|
Carlos López |
d6e10f |
{
|
|
Carlos López |
d6e10f |
if(!candidate_check(get_param_vocab(),x))
|
|
Carlos López |
d6e10f |
return false;
|
|
Carlos López |
d6e10f |
// Check if all layers belong to the same canvas
|
|
Carlos López |
d6e10f |
Canvas::Handle canvas=0;
|
|
Carlos López |
d6e10f |
for(ParamList::const_iterator i = x.begin(); i != x.end(); i++)
|
|
Carlos López |
d6e10f |
{
|
|
Carlos López |
d6e10f |
if (i->first == "layer" && i->second.get_type() == Param::TYPE_LAYER)
|
|
Carlos López |
d6e10f |
{
|
|
Carlos López |
d6e10f |
const Layer::Handle layer = i->second.get_layer();
|
|
Carlos López |
d6e10f |
if(layer.empty())
|
|
Carlos López |
d6e10f |
return false;
|
|
Carlos López |
d6e10f |
if(!canvas)
|
|
Carlos López |
d6e10f |
canvas=layer->get_canvas();
|
|
Carlos López |
a772f5 |
if(canvas && canvas->is_root())
|
|
Carlos López |
a772f5 |
return false;
|
|
Carlos López |
d0c315 |
if(canvas && !canvas->is_inline())
|
|
Carlos López |
d0c315 |
return false;
|
|
Carlos López |
d6e10f |
if(layer->get_canvas() && canvas && layer->get_canvas()!=canvas)
|
|
Carlos López |
d6e10f |
return false;
|
|
Carlos López |
d6e10f |
}
|
|
Carlos López |
d6e10f |
}
|
|
Carlos López |
d6e10f |
return true;
|
|
Carlos López |
d6e10f |
}
|
|
Carlos López |
d6e10f |
|
|
Carlos López |
d6e10f |
bool
|
|
Carlos López |
d6e10f |
Action::LayerZDepthRangeSet::set_param(const synfig::String& name, const Action::Param ¶m)
|
|
Carlos López |
d6e10f |
{
|
|
Carlos López |
d6e10f |
if(name=="layer" && param.get_type()==Param::TYPE_LAYER)
|
|
Carlos López |
d6e10f |
{
|
|
Carlos López |
d6e10f |
layers.push_back(param.get_layer());
|
|
Carlos López |
f0ebdb |
Layer::Handle layer=param.get_layer();
|
|
Carlos López |
f0ebdb |
if(layer)
|
|
Carlos López |
f0ebdb |
{
|
|
Carlos López |
f0ebdb |
// Expand position and depth to include the given layer
|
|
|
591d46 |
float layer_z_depth=layer->get_true_z_depth(Time(0));
|
|
Carlos López |
f0ebdb |
if(z_position > layer_z_depth)
|
|
Carlos López |
f0ebdb |
z_position=layer_z_depth;
|
|
Carlos Lopez |
deb9e8 |
if(z_position + z_depth <= layer_z_depth)
|
|
Carlos López |
e7bf77 |
z_depth=layer_z_depth - z_position;
|
|
Carlos López |
f0ebdb |
}
|
|
Carlos López |
d6e10f |
return true;
|
|
Carlos López |
d6e10f |
}
|
|
Carlos López |
d6e10f |
return Action::CanvasSpecific::set_param(name,param);
|
|
Carlos López |
d6e10f |
}
|
|
Carlos López |
d6e10f |
|
|
Carlos López |
d6e10f |
bool
|
|
Carlos López |
d6e10f |
Action::LayerZDepthRangeSet::is_ready()const
|
|
Carlos López |
d6e10f |
{
|
|
Carlos López |
d6e10f |
if(layers.empty())
|
|
Carlos López |
d6e10f |
return false;
|
|
Carlos López |
a772f5 |
if(z_position == ZDEPTH_MAX)
|
|
Carlos López |
f0ebdb |
return false;
|
|
Carlos López |
d6e10f |
return Action::CanvasSpecific::is_ready();
|
|
Carlos López |
d6e10f |
}
|
|
Carlos López |
d6e10f |
|
|
Carlos López |
d6e10f |
void
|
|
Carlos López |
d6e10f |
Action::LayerZDepthRangeSet::prepare()
|
|
Carlos López |
d6e10f |
{
|
|
Carlos López |
d6e10f |
if(!first_time())
|
|
Carlos López |
d6e10f |
return;
|
|
Carlos López |
d6e10f |
|
|
Carlos López |
d6e10f |
if(layers.empty())
|
|
Carlos López |
d6e10f |
throw Error(_("No layers selected"));
|
|
Carlos López |
d6e10f |
|
|
Carlos López |
a772f5 |
Layer::Handle layer=layers.front();
|
|
|
a53027 |
|
|
|
a53027 |
etl::handle<layer_group> paste=</layer_group>
|
|
|
a53027 |
etl::handle<layer_group>::cast_dynamic(</layer_group>
|
|
|
a53027 |
layer->get_parent_paste_canvas_layer() );
|
|
Carlos López |
a772f5 |
if(!paste)
|
|
|
c861dd |
throw Error(_("No Parent Group found!"));
|
|
Carlos López |
a772f5 |
// Z ENABLE
|
|
Carlos López |
a772f5 |
{
|
|
Carlos López |
a772f5 |
ValueBase new_value(true);
|
|
Carlos López |
a772f5 |
Action::Handle action(Action::create("ValueDescSet"));
|
|
Carlos López |
a772f5 |
if(!action)
|
|
Carlos López |
a772f5 |
throw Error(_("Unable to find action ValueDescSet (bug)"));
|
|
Carlos López |
a772f5 |
action->set_param("canvas",get_canvas());
|
|
Carlos López |
a772f5 |
action->set_param("canvas_interface",get_canvas_interface());
|
|
Carlos López |
a772f5 |
action->set_param("new_value",new_value);
|
|
|
a53027 |
action->set_param("value_desc",ValueDesc(Layer::Handle(paste), "z_range"));
|
|
Carlos Lopez |
1e938e |
action->set_param("recursive", true);
|
|
Carlos López |
a772f5 |
if(!action->is_ready())
|
|
Carlos López |
a772f5 |
throw Error(Error::TYPE_NOTREADY);
|
|
Carlos López |
a772f5 |
add_action(action);
|
|
Carlos López |
a772f5 |
}
|
|
Carlos López |
a772f5 |
// Z POSITION
|
|
Carlos López |
a772f5 |
{
|
|
Carlos López |
a772f5 |
ValueBase new_value(z_position);
|
|
Carlos López |
a772f5 |
Action::Handle action(Action::create("ValueDescSet"));
|
|
Carlos López |
a772f5 |
if(!action)
|
|
Carlos López |
a772f5 |
throw Error(_("Unable to find action ValueDescSet (bug)"));
|
|
Carlos López |
a772f5 |
action->set_param("canvas",get_canvas());
|
|
Carlos López |
a772f5 |
action->set_param("canvas_interface",get_canvas_interface());
|
|
Carlos López |
a772f5 |
action->set_param("new_value",new_value);
|
|
|
a53027 |
action->set_param("value_desc",ValueDesc(Layer::Handle(paste), "z_range_position"));
|
|
Carlos Lopez |
1e938e |
action->set_param("recursive", false);
|
|
Carlos López |
a772f5 |
if(!action->is_ready())
|
|
Carlos López |
a772f5 |
throw Error(Error::TYPE_NOTREADY);
|
|
Carlos López |
a772f5 |
add_action(action);
|
|
Carlos López |
a772f5 |
}
|
|
Carlos López |
a772f5 |
// Z DEPTH
|
|
Carlos López |
a772f5 |
{
|
|
Carlos López |
a772f5 |
ValueBase new_value(z_depth);
|
|
Carlos López |
a772f5 |
Action::Handle action(Action::create("ValueDescSet"));
|
|
Carlos López |
a772f5 |
if(!action)
|
|
Carlos López |
a772f5 |
throw Error(_("Unable to find action ValueDescSet (bug)"));
|
|
Carlos López |
a772f5 |
action->set_param("canvas",get_canvas());
|
|
Carlos López |
a772f5 |
action->set_param("canvas_interface",get_canvas_interface());
|
|
Carlos López |
a772f5 |
action->set_param("new_value",new_value);
|
|
|
a53027 |
action->set_param("value_desc",ValueDesc(Layer::Handle(paste), "z_range_depth"));
|
|
Carlos Lopez |
1e938e |
action->set_param("recursive", false);
|
|
Carlos López |
a772f5 |
if(!action->is_ready())
|
|
Carlos López |
a772f5 |
throw Error(Error::TYPE_NOTREADY);
|
|
Carlos López |
a772f5 |
add_action(action);
|
|
Carlos López |
a772f5 |
}
|
|
Carlos López |
a772f5 |
return;
|
|
Carlos López |
d6e10f |
}
|