1 /* === S Y N F I G ========================================================= */
2 /*! \file gradientset.cpp
3 ** \brief Template File
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
10 ** This package is free software; you can redistribute it and/or
11 ** modify it under the terms of the GNU General Public License as
12 ** published by the Free Software Foundation; either version 2 of
13 ** the License, or (at your option) any later version.
15 ** This package is distributed in the hope that it will be useful,
16 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 ** General Public License for more details.
21 /* ========================================================================= */
23 /* === H E A D E R S ======================================================= */
32 #include "layerparamset.h"
33 #include "valuenodeconstset.h"
34 #include "valuedescconnect.h"
35 #include "waypointsetsmart.h"
37 #include "gradientset.h"
38 #include <synfigapp/canvasinterface.h>
39 #include <synfigapp/main.h>
41 #include <synfigapp/general.h>
47 using namespace synfig;
48 using namespace synfigapp;
49 using namespace Action;
51 /* === M A C R O S ========================================================= */
53 ACTION_INIT(Action::GradientSet);
54 ACTION_SET_NAME(Action::GradientSet,"gradient_set");
55 ACTION_SET_LOCAL_NAME(Action::GradientSet,N_("Apply Default Gradient"));
56 ACTION_SET_TASK(Action::GradientSet,"set");
57 ACTION_SET_CATEGORY(Action::GradientSet,Action::CATEGORY_VALUEDESC);
58 ACTION_SET_PRIORITY(Action::GradientSet,0);
59 ACTION_SET_VERSION(Action::GradientSet,"0.0");
60 ACTION_SET_CVS_ID(Action::GradientSet,"$Id$");
62 /* === G L O B A L S ======================================================= */
64 /* === P R O C E D U R E S ================================================= */
66 /* === M E T H O D S ======================================================= */
68 Action::GradientSet::GradientSet():
74 Action::GradientSet::get_param_vocab()
76 ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
78 ret.push_back(ParamDesc("value_desc",Param::TYPE_VALUEDESC)
79 .set_local_name(_("ValueDesc"))
82 ret.push_back(ParamDesc("time",Param::TYPE_TIME)
83 .set_local_name(_("Time"))
91 Action::GradientSet::is_candidate(const ParamList &x)
93 if(!candidate_check(get_param_vocab(),x))
95 return x.find("value_desc")->second.get_value_desc().get_value_type()==ValueBase::TYPE_GRADIENT;
99 Action::GradientSet::set_param(const synfig::String& name, const Action::Param ¶m)
101 if(name=="value_desc" && param.get_type()==Param::TYPE_VALUEDESC)
103 // Grab the value_desc
104 value_desc=param.get_value_desc();
106 // Grab the current gradient
107 gradient=synfigapp::Main::get_gradient();
109 return value_desc.get_value_type()==ValueBase::TYPE_GRADIENT;
112 if(name=="time" && param.get_type()==Param::TYPE_TIME)
114 time=param.get_time();
119 return Action::CanvasSpecific::set_param(name,param);
123 Action::GradientSet::is_ready()const
125 if(!value_desc || value_desc.get_value_type()!=ValueBase::TYPE_GRADIENT)
127 return Action::CanvasSpecific::is_ready();
131 Action::GradientSet::prepare()
135 Action::Handle action;
136 action=Action::create("value_desc_set");
138 action->set_param("canvas",get_canvas());
139 action->set_param("canvas_interface",get_canvas_interface());
140 action->set_param("value_desc",value_desc);
141 action->set_param("new_value",ValueBase(gradient));
142 action->set_param("time",time);
144 if(!action->is_ready())
145 throw Error(Error::TYPE_NOTREADY);
147 add_action_front(action);