|
|
14e74e |
/* === S Y N F I G ========================================================= */
|
|
|
64e779 |
/*! \file layeraddframe.cpp
|
|
|
14e74e |
** \brief Template File
|
|
|
14e74e |
**
|
|
|
14e74e |
** $Id$
|
|
|
14e74e |
**
|
|
|
14e74e |
** \legal
|
|
[d.j.a.y] Jerome Blanchi |
5293a9 |
** Copyright (c) 2014 Ivan Mahonin
|
|
[d.j.a.y] Jerome Blanchi |
5293a9 |
** Copyright (c) 2016 Jérôme Blanchi
|
|
|
14e74e |
**
|
|
|
14e74e |
** This package is free software; you can redistribute it and/or
|
|
|
14e74e |
** modify it under the terms of the GNU General Public License as
|
|
|
14e74e |
** published by the Free Software Foundation; either version 2 of
|
|
|
14e74e |
** the License, or (at your option) any later version.
|
|
|
14e74e |
**
|
|
|
14e74e |
** This package is distributed in the hope that it will be useful,
|
|
|
14e74e |
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
14e74e |
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
14e74e |
** General Public License for more details.
|
|
|
14e74e |
** \endlegal
|
|
|
14e74e |
*/
|
|
|
14e74e |
/* ========================================================================= */
|
|
|
14e74e |
|
|
|
14e74e |
/* === H E A D E R S ======================================================= */
|
|
|
14e74e |
|
|
|
14e74e |
#ifdef USING_PCH
|
|
|
14e74e |
# include "pch.h"
|
|
|
14e74e |
#else
|
|
|
14e74e |
#ifdef HAVE_CONFIG_H
|
|
|
14e74e |
# include <config.h></config.h>
|
|
|
14e74e |
#endif
|
|
|
14e74e |
|
|
bw |
94d8a6 |
#include <synfig general.h=""></synfig>
|
|
bw |
94d8a6 |
|
|
|
64e779 |
#include "layeraddframe.h"
|
|
|
64e779 |
#include "layercopy.h"
|
|
|
14e74e |
#include <synfig context.h=""></synfig>
|
|
|
14e74e |
#include <synfigapp canvasinterface.h=""></synfigapp>
|
|
|
14e74e |
#include <synfigapp instance.h=""></synfigapp>
|
|
|
abdbf2 |
#include <synfigapp localization.h=""></synfigapp>
|
|
|
14e74e |
|
|
|
14e74e |
#endif
|
|
|
14e74e |
|
|
|
14e74e |
using namespace std;
|
|
|
14e74e |
using namespace etl;
|
|
|
14e74e |
using namespace synfig;
|
|
|
14e74e |
using namespace synfigapp;
|
|
|
14e74e |
using namespace Action;
|
|
|
14e74e |
|
|
|
14e74e |
/* === M A C R O S ========================================================= */
|
|
|
14e74e |
|
|
|
64e779 |
ACTION_INIT(Action::LayerAddFrame);
|
|
|
64e779 |
ACTION_SET_NAME(Action::LayerAddFrame,"LayerAddFrame");
|
|
|
64e779 |
ACTION_SET_LOCAL_NAME(Action::LayerAddFrame,N_("Make New Frame"));
|
|
|
64e779 |
ACTION_SET_TASK(Action::LayerAddFrame,"add_frame");
|
|
|
64e779 |
ACTION_SET_CATEGORY(Action::LayerAddFrame,Action::CATEGORY_LAYER);
|
|
|
64e779 |
ACTION_SET_PRIORITY(Action::LayerAddFrame,0);
|
|
|
64e779 |
ACTION_SET_VERSION(Action::LayerAddFrame,"0.0");
|
|
|
64e779 |
ACTION_SET_CVS_ID(Action::LayerAddFrame,"$Id$");
|
|
|
14e74e |
|
|
|
14e74e |
/* === G L O B A L S ======================================================= */
|
|
|
14e74e |
|
|
|
14e74e |
/* === P R O C E D U R E S ================================================= */
|
|
|
14e74e |
|
|
|
14e74e |
/* === M E T H O D S ======================================================= */
|
|
|
14e74e |
|
|
|
64e779 |
Action::LayerAddFrame::LayerAddFrame():
|
|
|
14e74e |
time(0)
|
|
|
14e74e |
{
|
|
|
14e74e |
}
|
|
|
14e74e |
|
|
|
14e74e |
Action::ParamVocab
|
|
|
64e779 |
Action::LayerAddFrame::get_param_vocab()
|
|
|
14e74e |
{
|
|
|
14e74e |
ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
|
|
|
14e74e |
|
|
|
14e74e |
ret.push_back(ParamDesc("layer",Param::TYPE_LAYER)
|
|
|
14e74e |
.set_local_name(_("Layer"))
|
|
|
64e779 |
.set_desc(_("New frame should be added into this Switch Layer"))
|
|
|
64e779 |
);
|
|
|
64e779 |
ret.push_back(ParamDesc("time",Param::TYPE_TIME)
|
|
|
64e779 |
.set_local_name(_("Time"))
|
|
|
64e779 |
.set_optional()
|
|
|
14e74e |
);
|
|
|
14e74e |
|
|
|
14e74e |
return ret;
|
|
|
14e74e |
}
|
|
|
14e74e |
|
|
|
14e74e |
bool
|
|
|
64e779 |
Action::LayerAddFrame::is_candidate(const ParamList &x)
|
|
|
14e74e |
{
|
|
[d.j.a.y] Jerome Blanchi |
5293a9 |
if (!candidate_check(get_param_vocab(),x)) return false;
|
|
[d.j.a.y] Jerome Blanchi |
5293a9 |
|
|
[d.j.a.y] Jerome Blanchi |
5293a9 |
Layer::Handle layer=x.find("layer")->second.get_layer();
|
|
[d.j.a.y] Jerome Blanchi |
5293a9 |
if(!layer) return false;
|
|
[d.j.a.y] Jerome Blanchi |
5293a9 |
|
|
[d.j.a.y] Jerome Blanchi |
5293a9 |
if (!etl::handle<layer_switch>::cast_dynamic(layer)) return false;</layer_switch>
|
|
[d.j.a.y] Jerome Blanchi |
5293a9 |
|
|
[d.j.a.y] Jerome Blanchi |
5293a9 |
return true;
|
|
|
14e74e |
}
|
|
|
14e74e |
|
|
|
14e74e |
bool
|
|
|
64e779 |
Action::LayerAddFrame::set_param(const synfig::String& name, const Action::Param ¶m)
|
|
|
14e74e |
{
|
|
|
14e74e |
if(name=="layer" && param.get_type()==Param::TYPE_LAYER)
|
|
|
14e74e |
{
|
|
|
64e779 |
layer_switch = etl::handle<layer_switch>::cast_dynamic(param.get_layer());</layer_switch>
|
|
|
64e779 |
if (layer_switch)
|
|
|
14e74e |
{
|
|
|
64e779 |
layer_base = layer_switch->get_current_layer();
|
|
|
64e779 |
if (!layer_base) layer_switch = NULL;
|
|
|
14e74e |
}
|
|
|
64e779 |
return layer_switch;
|
|
|
14e74e |
}
|
|
|
14e74e |
if(name=="time" && param.get_type()==Param::TYPE_TIME)
|
|
|
14e74e |
{
|
|
|
14e74e |
time=param.get_time();
|
|
|
14e74e |
return true;
|
|
|
14e74e |
}
|
|
|
14e74e |
|
|
|
14e74e |
return Action::CanvasSpecific::set_param(name,param);
|
|
|
14e74e |
}
|
|
|
14e74e |
|
|
|
14e74e |
bool
|
|
|
64e779 |
Action::LayerAddFrame::is_ready()const
|
|
|
14e74e |
{
|
|
|
64e779 |
if(!layer_switch)
|
|
|
14e74e |
return false;
|
|
|
14e74e |
return Action::CanvasSpecific::is_ready();
|
|
|
14e74e |
}
|
|
|
14e74e |
|
|
|
14e74e |
void
|
|
|
64e779 |
Action::LayerAddFrame::prepare()
|
|
|
14e74e |
{
|
|
|
14e74e |
if(!first_time())
|
|
|
14e74e |
return;
|
|
|
14e74e |
|
|
|
64e779 |
// check canvas for switch
|
|
|
64e779 |
Canvas::Handle subcanvas(layer_switch->get_canvas());
|
|
|
64e779 |
Canvas::iterator iter=find(subcanvas->begin(),subcanvas->end(),layer_switch);
|
|
|
64e779 |
if(*iter!=layer_switch)
|
|
|
64e779 |
throw Error(_("Switch layer doesn't exist anymore."));
|
|
|
14e74e |
if(get_canvas()!=subcanvas && !subcanvas->is_inline())
|
|
|
64e779 |
throw Error(_("Switch layer doesn't belong to this canvas anymore"));
|
|
|
64e779 |
|
|
|
64e779 |
// check canvas for base
|
|
|
64e779 |
subcanvas = layer_base->get_canvas();
|
|
|
64e779 |
if (!subcanvas->is_inline())
|
|
|
64e779 |
throw Error(_("Only inline canvas supported"));
|
|
|
64e779 |
iter=find(subcanvas->begin(),subcanvas->end(),layer_base);
|
|
|
64e779 |
if(*iter!=layer_base)
|
|
|
64e779 |
throw Error(_("Base frame layer doesn't exist anymore."));
|
|
|
64e779 |
if(layer_switch->get_sub_canvas() != subcanvas)
|
|
|
64e779 |
throw Error(_("Base frame layer doesn't belong to switch layer canvas anymore"));
|
|
|
64e779 |
|
|
|
64e779 |
// generate name
|
|
|
64e779 |
String description, filename, filename_param;
|
|
[d.j.a.y] Jerome Blanchi |
ae6cdc |
get_canvas_interface()
|
|
[d.j.a.y] Jerome Blanchi |
ae6cdc |
->get_instance()
|
|
[d.j.a.y] Jerome Blanchi |
ae6cdc |
->generate_new_name(
|
|
|
300bf8 |
layer_base,
|
|
|
300bf8 |
description,
|
|
|
300bf8 |
filename,
|
|
|
300bf8 |
filename_param );
|
|
|
14e74e |
|
|
|
14e74e |
{
|
|
|
64e779 |
Action::Handle action(Action::create("LayerCopy"));
|
|
|
14e74e |
action->set_param("canvas",subcanvas);
|
|
|
14e74e |
action->set_param("canvas_interface",get_canvas_interface());
|
|
|
64e779 |
action->set_param("layer",layer_base);
|
|
|
14e74e |
add_action(action);
|
|
|
14e74e |
}
|
|
|
14e74e |
{
|
|
|
14e74e |
Action::Handle action(Action::create("ValueDescSet"));
|
|
|
64e779 |
action->set_param("canvas",get_canvas());
|
|
|
14e74e |
action->set_param("canvas_interface",get_canvas_interface());
|
|
|
14e74e |
action->set_param("value_desc",ValueDesc(Layer::Handle(layer_switch), "layer_name"));
|
|
|
14e74e |
action->set_param("time",time);
|
|
|
64e779 |
action->set_param("new_value",ValueBase(description));
|
|
|
1ab288 |
action->set_param("animate",true);
|
|
|
14e74e |
add_action(action);
|
|
|
14e74e |
}
|
|
|
14e74e |
}
|
|
|
14e74e |
|