Fix bugs in previous commit that caused FTBFS in synfig and ETL FTBFS with older...
[synfig.git] / synfig-studio / tags / stable / src / synfigapp / actions / colorset.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file colorset.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 "colorset.h"
38 #include <synfigapp/canvasinterface.h>
39 #include <synfigapp/main.h>
40
41 #include <synfigapp/general.h>
42
43 #endif
44
45 using namespace std;
46 using namespace etl;
47 using namespace synfig;
48 using namespace synfigapp;
49 using namespace Action;
50
51 /* === M A C R O S ========================================================= */
52
53 ACTION_INIT(Action::ColorSet);
54 ACTION_SET_NAME(Action::ColorSet,"color_set");
55 ACTION_SET_LOCAL_NAME(Action::ColorSet,N_("Apply Default Color"));
56 ACTION_SET_TASK(Action::ColorSet,"set");
57 ACTION_SET_CATEGORY(Action::ColorSet,Action::CATEGORY_VALUEDESC);
58 ACTION_SET_PRIORITY(Action::ColorSet,0);
59 ACTION_SET_VERSION(Action::ColorSet,"0.0");
60 ACTION_SET_CVS_ID(Action::ColorSet,"$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
68 Action::ColorSet::ColorSet():
69         time(0)
70 {
71 }
72
73 Action::ParamVocab
74 Action::ColorSet::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
90 bool
91 Action::ColorSet::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()==ValueBase::TYPE_COLOR;
96 }
97
98 bool
99 Action::ColorSet::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 color
107                 color=synfigapp::Main::get_foreground_color();
108
109                 return value_desc.get_value_type()==ValueBase::TYPE_COLOR;
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
122 bool
123 Action::ColorSet::is_ready()const
124 {
125         if(!value_desc || value_desc.get_value_type()!=ValueBase::TYPE_COLOR)
126                 return false;
127         return Action::CanvasSpecific::is_ready();
128 }
129
130 void
131 Action::ColorSet::prepare()
132 {
133         clear();
134
135         Action::Handle action;
136         action=Action::create("value_desc_set");
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(color));
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 }