Fix bugs in previous commit that caused FTBFS in synfig and ETL FTBFS with older...
[synfig.git] / synfig-studio / tags / synfigstudio_0_61_05 / synfig-studio / src / synfigapp / actions / colorset.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file colorset.cpp
3 **      \brief Template File
4 **
5 **      $Id: colorset.cpp,v 1.1.1.1 2005/01/07 03:34:37 darco Exp $
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 #endif
42
43 using namespace std;
44 using namespace etl;
45 using namespace synfig;
46 using namespace synfigapp;
47 using namespace Action;
48
49 /* === M A C R O S ========================================================= */
50
51 ACTION_INIT(Action::ColorSet);
52 ACTION_SET_NAME(Action::ColorSet,"color_set");
53 ACTION_SET_LOCAL_NAME(Action::ColorSet,"Apply Default Color");
54 ACTION_SET_TASK(Action::ColorSet,"set");
55 ACTION_SET_CATEGORY(Action::ColorSet,Action::CATEGORY_VALUEDESC);
56 ACTION_SET_PRIORITY(Action::ColorSet,0);
57 ACTION_SET_VERSION(Action::ColorSet,"0.0");
58 ACTION_SET_CVS_ID(Action::ColorSet,"$Id: colorset.cpp,v 1.1.1.1 2005/01/07 03:34:37 darco Exp $");
59
60 /* === G L O B A L S ======================================================= */
61
62 /* === P R O C E D U R E S ================================================= */
63
64 /* === M E T H O D S ======================================================= */
65
66 Action::ColorSet::ColorSet():
67         time(0)
68 {
69 }
70
71 Action::ParamVocab
72 Action::ColorSet::get_param_vocab()
73 {
74         ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
75         
76         ret.push_back(ParamDesc("value_desc",Param::TYPE_VALUEDESC)
77                 .set_local_name(_("ValueDesc"))
78         );
79
80         ret.push_back(ParamDesc("time",Param::TYPE_TIME)
81                 .set_local_name(_("Time"))
82                 .set_optional()
83         );
84         
85         return ret;
86 }
87
88 bool
89 Action::ColorSet::is_canidate(const ParamList &x)
90 {
91         if(!canidate_check(get_param_vocab(),x))
92                 return false;
93         return x.find("value_desc")->second.get_value_desc().get_value_type()==ValueBase::TYPE_COLOR;
94 }
95
96 bool
97 Action::ColorSet::set_param(const synfig::String& name, const Action::Param &param)
98 {
99         if(name=="value_desc" && param.get_type()==Param::TYPE_VALUEDESC)
100         {
101                 // Grab the value_desc
102                 value_desc=param.get_value_desc();
103                 
104                 // Grab the current color
105                 color=synfigapp::Main::get_foreground_color();
106                 
107                 return value_desc.get_value_type()==ValueBase::TYPE_COLOR;
108         }
109
110         if(name=="time" && param.get_type()==Param::TYPE_TIME)
111         {
112                 time=param.get_time();
113                 
114                 return true;
115         }
116
117         return Action::CanvasSpecific::set_param(name,param);
118 }
119
120 bool
121 Action::ColorSet::is_ready()const
122 {
123         if(!value_desc || value_desc.get_value_type()!=ValueBase::TYPE_COLOR)
124                 return false;
125         return Action::CanvasSpecific::is_ready();
126 }
127
128 void
129 Action::ColorSet::prepare()
130 {
131         clear();
132         
133         Action::Handle action;
134         action=Action::create("value_desc_set");
135                 
136         action->set_param("canvas",get_canvas());
137         action->set_param("canvas_interface",get_canvas_interface());
138         action->set_param("value_desc",value_desc);
139         action->set_param("new_value",ValueBase(color));
140         action->set_param("time",time);
141         
142         if(!action->is_ready())
143                 throw Error(Error::TYPE_NOTREADY);
144
145         add_action_front(action);
146 }