Remove ancient trunk folder from svn repository
[synfig.git] / 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$
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::ColorSetFromOC);
54 ACTION_SET_NAME(Action::ColorSetFromOC, "ColorSetFromOC");
55 ACTION_SET_LOCAL_NAME(Action::ColorSetFromOC, N_("Apply Outline Color"));
56 ACTION_SET_TASK(Action::ColorSetFromOC, "set");
57 ACTION_SET_CATEGORY(Action::ColorSetFromOC, Action::CATEGORY_VALUEDESC);
58 ACTION_SET_PRIORITY(Action::ColorSetFromOC, 0);
59 ACTION_SET_VERSION(Action::ColorSetFromOC, "0.0");
60 ACTION_SET_CVS_ID(Action::ColorSetFromOC, "$Id$");
61
62 ACTION_INIT(Action::ColorSetFromFC);
63 ACTION_SET_NAME(Action::ColorSetFromFC, "ColorSetFromFC");
64 ACTION_SET_LOCAL_NAME(Action::ColorSetFromFC, N_("Apply Fill Color"));
65 ACTION_SET_TASK(Action::ColorSetFromFC, "set");
66 ACTION_SET_CATEGORY(Action::ColorSetFromFC, Action::CATEGORY_VALUEDESC);
67 ACTION_SET_PRIORITY(Action::ColorSetFromFC, 0);
68 ACTION_SET_VERSION(Action::ColorSetFromFC, "0.0");
69 ACTION_SET_CVS_ID(Action::ColorSetFromFC, "$Id$");
70
71 /* === G L O B A L S ======================================================= */
72
73 /* === P R O C E D U R E S ================================================= */
74
75 /* === M E T H O D S ======================================================= */
76
77 Action::ColorSet::ColorSet(bool use_outline_color):
78   time(0), use_outline_color(use_outline_color)
79 {
80 }
81
82 Action::ParamVocab
83 Action::ColorSet::get_param_vocab()
84 {
85         ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
86
87         ret.push_back(ParamDesc("value_desc",Param::TYPE_VALUEDESC)
88                 .set_local_name(_("ValueDesc"))
89                 .set_supports_multiple()
90         );
91
92         ret.push_back(ParamDesc("time",Param::TYPE_TIME)
93                 .set_local_name(_("Time"))
94                 .set_optional()
95         );
96
97         return ret;
98 }
99
100 bool
101 Action::ColorSet::is_candidate(const ParamList &x)
102 {
103         if (!candidate_check(get_param_vocab(), x))
104                 return false;
105
106         std::multimap<synfig::String, Param>::const_iterator iter;
107         for (iter = x.begin(); iter != x.end(); ++iter)
108         {
109                 if (iter->first == "value_desc" &&
110                                 iter->second.get_value_desc().get_value_type() != ValueBase::TYPE_COLOR)
111                         return false;
112         }
113
114         return true;
115 }
116
117 bool
118 Action::ColorSet::set_param(const synfig::String& name, const Action::Param &param)
119 {
120         if (name == "value_desc" && param.get_type() == Param::TYPE_VALUEDESC)
121         {
122                 // Grab the value_desc
123                 ValueDesc value_desc = param.get_value_desc();
124                 if (value_desc.get_value_type() != ValueBase::TYPE_COLOR)
125                         return false;
126
127                 value_desc_list.push_back(value_desc);
128
129                 // Grab the current outline or fill color
130                 if (use_outline_color)
131                         color = synfigapp::Main::get_outline_color();
132                 else
133                         color = synfigapp::Main::get_fill_color();
134
135                 return true;
136         }
137
138         if (name == "time" && param.get_type() == Param::TYPE_TIME)
139         {
140                 time = param.get_time();
141
142                 return true;
143         }
144
145         return Action::CanvasSpecific::set_param(name, param);
146 }
147
148 bool
149 Action::ColorSet::is_ready() const
150 {
151         if (value_desc_list.size() == 0)
152                 return false;
153
154         return Action::CanvasSpecific::is_ready();
155 }
156
157 void
158 Action::ColorSet::prepare()
159 {
160         clear();
161
162         std::list<ValueDesc>::iterator iter;
163         for (iter = value_desc_list.begin(); iter != value_desc_list.end(); ++iter)
164         {
165                 ValueDesc& value_desc(*iter);
166
167                 Action::Handle action = Action::create("ValueDescSet");
168                 action->set_param("canvas", get_canvas());
169                 action->set_param("canvas_interface", get_canvas_interface());
170                 action->set_param("value_desc", value_desc);
171                 action->set_param("new_value", ValueBase(color));
172                 action->set_param("time", time);
173
174                 if (!action->is_ready())
175                         throw Error(Error::TYPE_NOTREADY);
176
177                 add_action_front(action);
178         }
179 }