More descriptions for layer parameters
[synfig.git] / synfig-core / src / synfig / layer_solidcolor.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file layer_solidcolor.cpp
3 **      \brief Implementation of the "Solid Color" layer
4 **
5 **      $Id$
6 **
7 **      \legal
8 **      Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 **      Copyright (c) 2007, 2008 Chris Moore
10 **
11 **      This package is free software; you can redistribute it and/or
12 **      modify it under the terms of the GNU General Public License as
13 **      published by the Free Software Foundation; either version 2 of
14 **      the License, or (at your option) any later version.
15 **
16 **      This package is distributed in the hope that it will be useful,
17 **      but WITHOUT ANY WARRANTY; without even the implied warranty of
18 **      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 **      General Public License for more details.
20 **      \endlegal
21 */
22 /* ========================================================================= */
23
24 /* === H E A D E R S ======================================================= */
25
26 #ifdef USING_PCH
27 #       include "pch.h"
28 #else
29 #ifdef HAVE_CONFIG_H
30 #       include <config.h>
31 #endif
32
33 #include "layer_solidcolor.h"
34 #include "string.h"
35 #include "time.h"
36 #include "context.h"
37 #include "paramdesc.h"
38 #include "renddesc.h"
39 #include "surface.h"
40 #include "value.h"
41 #include "valuenode.h"
42
43 #endif
44
45 /* === U S I N G =========================================================== */
46
47 using namespace etl;
48 using namespace std;
49 using namespace synfig;
50
51 /* === G L O B A L S ======================================================= */
52
53 SYNFIG_LAYER_INIT(Layer_SolidColor);
54 SYNFIG_LAYER_SET_NAME(Layer_SolidColor,"SolidColor"); // todo: use solid_color
55 SYNFIG_LAYER_SET_LOCAL_NAME(Layer_SolidColor,N_("Solid Color"));
56 SYNFIG_LAYER_SET_CATEGORY(Layer_SolidColor,N_("Geometry"));
57 SYNFIG_LAYER_SET_VERSION(Layer_SolidColor,"0.1");
58 SYNFIG_LAYER_SET_CVS_ID(Layer_SolidColor,"$Id$");
59
60 /* === P R O C E D U R E S ================================================= */
61
62 /* === M E T H O D S ======================================================= */
63
64 /* === E N T R Y P O I N T ================================================= */
65
66 Layer_SolidColor::Layer_SolidColor():
67         Layer_Composite(1.0,Color::BLEND_COMPOSITE),
68         color(Color::black())
69 {
70         Layer::Vocab voc(get_param_vocab());
71         Layer::fill_static(voc);
72 }
73
74 bool
75 Layer_SolidColor::set_param(const String & param, const ValueBase &value)
76 {
77         IMPORT_PLUS(color, { if (color.get_a() == 0) { if (converted_blend_) {
78                                         set_blend_method(Color::BLEND_ALPHA_OVER);
79                                         color.set_a(1); } else transparent_color_ = true; } });
80
81         return Layer_Composite::set_param(param,value);
82 }
83
84 ValueBase
85 Layer_SolidColor::get_param(const String &param)const
86 {
87         EXPORT(color);
88
89         EXPORT_NAME();
90         EXPORT_VERSION();
91
92         return Layer_Composite::get_param(param);
93 }
94
95 Layer::Vocab
96 Layer_SolidColor::get_param_vocab()const
97 {
98         Layer::Vocab ret(Layer_Composite::get_param_vocab());
99
100         ret.push_back(ParamDesc("color")
101                 .set_local_name(_("Color"))
102                 .set_description(_("Fill color of the layer"))
103         );
104
105         return ret;
106 }
107
108 synfig::Layer::Handle
109 Layer_SolidColor::hit_check(synfig::Context context, const synfig::Point &point)const
110 {
111         if(get_blend_method()==Color::BLEND_STRAIGHT && get_amount()>=0.5)
112                 return const_cast<Layer_SolidColor*>(this);
113         else
114         if(get_blend_method()==Color::BLEND_COMPOSITE && get_amount()*color.get_a()>=0.5)
115                 return const_cast<Layer_SolidColor*>(this);
116
117         Layer::Handle layer(context.hit_check(point));
118
119         return layer?layer:const_cast<Layer_SolidColor*>(this);
120 }
121
122 Color
123 Layer_SolidColor::get_color(Context context, const Point &pos)const
124 {
125         if(get_amount()==1.0 && get_blend_method()==Color::BLEND_STRAIGHT)
126                 return color;
127         else
128                 return Color::blend(color,context.get_color(pos),get_amount(),get_blend_method());
129 }
130
131 bool
132 Layer_SolidColor::accelerated_render(Context context,Surface *surface,int quality, const RendDesc &renddesc, ProgressCallback *cb)const
133 {
134         if(get_amount()==1.0 && get_blend_method()==Color::BLEND_STRAIGHT)
135         {
136                 // Mark our progress as starting
137                 if(cb && !cb->amount_complete(0,1000))
138                         return false;
139
140                 surface->set_wh(renddesc.get_w(),renddesc.get_h());
141                 surface->fill(color);
142
143                 // Mark our progress as finished
144                 if(cb && !cb->amount_complete(1000,1000))
145                         return false;
146
147                 return true;
148         }
149
150         SuperCallback supercb(cb,0,9500,10000);
151
152         if(!context.accelerated_render(surface,quality,renddesc,&supercb))
153                 return false;
154
155         int x,y;
156
157         Surface::alpha_pen apen(surface->begin());
158
159         apen.set_value(color);
160         apen.set_alpha(get_amount());
161         apen.set_blend_method(get_blend_method());
162
163         for(y=0;y<renddesc.get_h();y++,apen.inc_y(),apen.dec_x(x))
164                 for(x=0;x<renddesc.get_w();x++,apen.inc_x())
165                         apen.put_value();
166
167         // Mark our progress as finished
168         if(cb && !cb->amount_complete(10000,10000))
169                 return false;
170
171         return true;
172 }