1 /* === S Y N F I G ========================================================= */
2 /*! \file layer_solidcolor.cpp
3 ** \brief Implementation of the "Solid Color" layer
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 ** Copyright (c) 2007, 2008 Chris Moore
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.
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.
22 /* ========================================================================= */
24 /* === H E A D E R S ======================================================= */
33 #include "layer_solidcolor.h"
37 #include "paramdesc.h"
41 #include "valuenode.h"
45 /* === U S I N G =========================================================== */
49 using namespace synfig;
51 /* === G L O B A L S ======================================================= */
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$");
60 /* === P R O C E D U R E S ================================================= */
62 /* === M E T H O D S ======================================================= */
64 /* === E N T R Y P O I N T ================================================= */
66 Layer_SolidColor::Layer_SolidColor():
67 Layer_Composite(1.0,Color::BLEND_COMPOSITE),
70 Layer::Vocab voc(get_param_vocab());
71 Layer::fill_static(voc);
75 Layer_SolidColor::set_param(const String & param, const ValueBase &value)
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; } });
81 return Layer_Composite::set_param(param,value);
85 Layer_SolidColor::get_param(const String ¶m)const
92 return Layer_Composite::get_param(param);
96 Layer_SolidColor::get_param_vocab()const
98 Layer::Vocab ret(Layer_Composite::get_param_vocab());
100 ret.push_back(ParamDesc("color")
101 .set_local_name(_("Color"))
102 .set_description(_("Fill color of the layer"))
108 synfig::Layer::Handle
109 Layer_SolidColor::hit_check(synfig::Context context, const synfig::Point &point)const
111 if(get_blend_method()==Color::BLEND_STRAIGHT && get_amount()>=0.5)
112 return const_cast<Layer_SolidColor*>(this);
114 if(get_blend_method()==Color::BLEND_COMPOSITE && get_amount()*color.get_a()>=0.5)
115 return const_cast<Layer_SolidColor*>(this);
117 Layer::Handle layer(context.hit_check(point));
119 return layer?layer:const_cast<Layer_SolidColor*>(this);
123 Layer_SolidColor::get_color(Context context, const Point &pos)const
125 if(get_amount()==1.0 && get_blend_method()==Color::BLEND_STRAIGHT)
128 return Color::blend(color,context.get_color(pos),get_amount(),get_blend_method());
132 Layer_SolidColor::accelerated_render(Context context,Surface *surface,int quality, const RendDesc &renddesc, ProgressCallback *cb)const
134 if(get_amount()==1.0 && get_blend_method()==Color::BLEND_STRAIGHT)
136 // Mark our progress as starting
137 if(cb && !cb->amount_complete(0,1000))
140 surface->set_wh(renddesc.get_w(),renddesc.get_h());
141 surface->fill(color);
143 // Mark our progress as finished
144 if(cb && !cb->amount_complete(1000,1000))
150 SuperCallback supercb(cb,0,9500,10000);
152 if(!context.accelerated_render(surface,quality,renddesc,&supercb))
157 Surface::alpha_pen apen(surface->begin());
159 apen.set_value(color);
160 apen.set_alpha(get_amount());
161 apen.set_blend_method(get_blend_method());
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())
167 // Mark our progress as finished
168 if(cb && !cb->amount_complete(10000,10000))