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

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

First release to xenial

File size: 3.7 KB
Line 
1/* === S Y N F I G ========================================================= */
2/*!     \file gradientset.cpp
3**      \brief Template File
4**
5**      $Id$
6**
7**      \legal
8**      Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9**
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.
14**
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.
19**      \endlegal
20*/
21/* ========================================================================= */
22
23/* === H E A D E R S ======================================================= */
24
25#ifdef USING_PCH
26#       include "pch.h"
27#else
28#ifdef HAVE_CONFIG_H
29#       include <config.h>
30#endif
31
32#include "layerparamset.h"
33#include "valuenodeconstset.h"
34#include "valuedescconnect.h"
35#include "waypointsetsmart.h"
36
37#include "gradientset.h"
38#include <synfigapp/canvasinterface.h>
39#include <synfigapp/main.h>
40
41#include <synfigapp/general.h>
42
43#endif
44
45using namespace std;
46using namespace etl;
47using namespace synfig;
48using namespace synfigapp;
49using namespace Action;
50
51/* === M A C R O S ========================================================= */
52
53ACTION_INIT(Action::GradientSet);
54ACTION_SET_NAME(Action::GradientSet,"GradientSet");
55ACTION_SET_LOCAL_NAME(Action::GradientSet,N_("Apply Default Gradient"));
56ACTION_SET_TASK(Action::GradientSet,"set");
57ACTION_SET_CATEGORY(Action::GradientSet,Action::CATEGORY_VALUEDESC);
58ACTION_SET_PRIORITY(Action::GradientSet,0);
59ACTION_SET_VERSION(Action::GradientSet,"0.0");
60ACTION_SET_CVS_ID(Action::GradientSet,"$Id$");
61
62/* === G L O B A L S ======================================================= */
63
64/* === P R O C E D U R E S ================================================= */
65
66/* === M E T H O D S ======================================================= */
67
68Action::GradientSet::GradientSet():
69        time(0)
70{
71}
72
73Action::ParamVocab
74Action::GradientSet::get_param_vocab()
75{
76        ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
77
78        ret.push_back(ParamDesc("value_desc",Param::TYPE_VALUEDESC)
79                .set_local_name(_("ValueDesc"))
80        );
81
82        ret.push_back(ParamDesc("time",Param::TYPE_TIME)
83                .set_local_name(_("Time"))
84                .set_optional()
85        );
86
87        return ret;
88}
89
90bool
91Action::GradientSet::is_candidate(const ParamList &x)
92{
93        if(!candidate_check(get_param_vocab(),x))
94                return false;
95        return x.find("value_desc")->second.get_value_desc().get_value_type()==type_gradient;
96}
97
98bool
99Action::GradientSet::set_param(const synfig::String& name, const Action::Param &param)
100{
101        if(name=="value_desc" && param.get_type()==Param::TYPE_VALUEDESC)
102        {
103                // Grab the value_desc
104                value_desc=param.get_value_desc();
105
106                // Grab the current gradient
107                gradient=synfigapp::Main::get_gradient();
108
109                return value_desc.get_value_type()==type_gradient;
110        }
111
112        if(name=="time" && param.get_type()==Param::TYPE_TIME)
113        {
114                time=param.get_time();
115
116                return true;
117        }
118
119        return Action::CanvasSpecific::set_param(name,param);
120}
121
122bool
123Action::GradientSet::is_ready()const
124{
125        if(!value_desc || value_desc.get_value_type()!=type_gradient)
126                return false;
127        return Action::CanvasSpecific::is_ready();
128}
129
130void
131Action::GradientSet::prepare()
132{
133        clear();
134
135        Action::Handle action;
136        action=Action::create("ValueDescSet");
137
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);
143
144        if(!action->is_ready())
145                throw Error(Error::TYPE_NOTREADY);
146
147        add_action_front(action);
148}
Note: See TracBrowser for help on using the repository browser.