1 /* === S Y N F I G ========================================================= */
2 /*! \file layer_solidcolor.cpp
3 ** \brief Template Header
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 ** Copyright (c) 2007 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_STRAIGHT),
73 Layer_SolidColor::set_param(const String & param, const ValueBase &value)
77 return Layer_Composite::set_param(param,value);
81 Layer_SolidColor::get_param(const String ¶m)const
88 return Layer_Composite::get_param(param);
92 Layer_SolidColor::get_param_vocab()const
94 Layer::Vocab ret(Layer_Composite::get_param_vocab());
96 ret.push_back(ParamDesc("color")
97 .set_local_name(_("Color"))
103 synfig::Layer::Handle
104 Layer_SolidColor::hit_check(synfig::Context context, const synfig::Point &point)const
106 if(get_blend_method()==Color::BLEND_STRAIGHT && get_amount()>=0.5)
107 return const_cast<Layer_SolidColor*>(this);
109 if(get_blend_method()==Color::BLEND_COMPOSITE && get_amount()*color.get_a()>=0.5)
110 return const_cast<Layer_SolidColor*>(this);
112 Layer::Handle layer(context.hit_check(point));
114 return layer?layer:const_cast<Layer_SolidColor*>(this);
118 Layer_SolidColor::get_color(Context context, const Point &pos)const
120 if(get_amount()==1.0 && get_blend_method()==Color::BLEND_STRAIGHT)
123 return Color::blend(color,context.get_color(pos),get_amount(),get_blend_method());
127 Layer_SolidColor::accelerated_render(Context context,Surface *surface,int quality, const RendDesc &renddesc, ProgressCallback *cb)const
129 if(get_amount()==1.0 && get_blend_method()==Color::BLEND_STRAIGHT)
131 // Mark our progress as starting
132 if(cb && !cb->amount_complete(0,1000))
135 surface->set_wh(renddesc.get_w(),renddesc.get_h());
136 surface->fill(color);
138 // Mark our progress as finished
139 if(cb && !cb->amount_complete(1000,1000))
145 SuperCallback supercb(cb,0,9500,10000);
147 if(!context.accelerated_render(surface,quality,renddesc,&supercb))
152 Surface::alpha_pen apen(surface->begin());
154 apen.set_value(color);
155 apen.set_alpha(get_amount());
156 apen.set_blend_method(get_blend_method());
158 for(y=0;y<renddesc.get_h();y++,apen.inc_y(),apen.dec_x(x))
159 for(x=0;x<renddesc.get_w();x++,apen.inc_x())
162 // Mark our progress as finished
163 if(cb && !cb->amount_complete(10000,10000))