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