Fix bugs in previous commit that caused FTBFS in synfig and ETL FTBFS with older...
[synfig.git] / synfig-core / tags / synfig_0_61_05 / synfig-core / src / synfig / layer_solidcolor.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file layer_solidcolor.cpp
3 **      \brief Template Header
4 **
5 **      $Id: layer_solidcolor.cpp,v 1.1.1.1 2005/01/04 01:23:14 darco Exp $
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 "layer_solidcolor.h"
33 #include "string.h"
34 #include "time.h"
35 #include "context.h"
36 #include "paramdesc.h"
37 #include "renddesc.h"
38 #include "surface.h"
39 #include "value.h"
40 #include "valuenode.h"
41
42 #endif
43
44 /* === U S I N G =========================================================== */
45
46 using namespace etl;
47 using namespace std;
48 using namespace synfig;
49
50 /* === G L O B A L S ======================================================= */
51
52 SYNFIG_LAYER_INIT(Layer_SolidColor);
53 SYNFIG_LAYER_SET_NAME(Layer_SolidColor,"SolidColor");
54 SYNFIG_LAYER_SET_LOCAL_NAME(Layer_SolidColor,_("Solid Color"));
55 SYNFIG_LAYER_SET_CATEGORY(Layer_SolidColor,_("Geometry"));
56 SYNFIG_LAYER_SET_VERSION(Layer_SolidColor,"0.1");
57 SYNFIG_LAYER_SET_CVS_ID(Layer_SolidColor,"$Id: layer_solidcolor.cpp,v 1.1.1.1 2005/01/04 01:23:14 darco Exp $");
58
59 /* === P R O C E D U R E S ================================================= */
60
61 /* === M E T H O D S ======================================================= */
62
63 /* === E N T R Y P O I N T ================================================= */
64
65 Layer_SolidColor::Layer_SolidColor():
66         Layer_Composite(1.0,Color::BLEND_STRAIGHT),
67         color(Color::black())
68 {
69 }
70         
71 bool
72 Layer_SolidColor::set_param(const String & param, const ValueBase &value)
73 {
74         IMPORT(color);
75         
76         return Layer_Composite::set_param(param,value);
77 }
78
79 ValueBase
80 Layer_SolidColor::get_param(const String &param)const
81 {
82         EXPORT(color);
83
84         EXPORT_NAME();
85         EXPORT_VERSION();
86                 
87         return Layer_Composite::get_param(param);       
88 }
89
90 Layer::Vocab
91 Layer_SolidColor::get_param_vocab()const
92 {
93         Layer::Vocab ret(Layer_Composite::get_param_vocab());
94         
95         ret.push_back(ParamDesc("color")
96                 .set_local_name(_("Color"))
97         );
98         
99         return ret;
100 }
101
102 synfig::Layer::Handle
103 Layer_SolidColor::hit_check(synfig::Context context, const synfig::Point &point)const
104 {
105         if(get_blend_method()==Color::BLEND_STRAIGHT && get_amount()>=0.5)
106                 return const_cast<Layer_SolidColor*>(this);
107         else
108         if(get_blend_method()==Color::BLEND_COMPOSITE && get_amount()*color.get_a()>=0.5)
109                 return const_cast<Layer_SolidColor*>(this);
110         
111         Layer::Handle layer(context.hit_check(point));
112         
113         return layer?layer:const_cast<Layer_SolidColor*>(this);
114 }
115
116 Color
117 Layer_SolidColor::get_color(Context context, const Point &pos)const
118 {
119         if(get_amount()==1.0 && get_blend_method()==Color::BLEND_STRAIGHT)
120                 return color;
121         else
122                 return Color::blend(color,context.get_color(pos),get_amount(),get_blend_method());
123 }
124         
125 bool
126 Layer_SolidColor::accelerated_render(Context context,Surface *surface,int quality, const RendDesc &renddesc, ProgressCallback *cb)const
127 {
128         if(get_amount()==1.0 && get_blend_method()==Color::BLEND_STRAIGHT)
129         {
130                 // Mark our progress as starting
131                 if(cb && !cb->amount_complete(0,1000))
132                         return false;
133                 
134                 surface->set_wh(renddesc.get_w(),renddesc.get_h());
135                 surface->fill(color);
136
137                 // Mark our progress as finished
138                 if(cb && !cb->amount_complete(1000,1000))
139                         return false;
140
141                 return true;
142         }
143
144         SuperCallback supercb(cb,0,9500,10000);
145
146         if(!context.accelerated_render(surface,quality,renddesc,&supercb))
147                 return false;
148
149         int x,y;
150
151         Surface::alpha_pen apen(surface->begin());
152
153         apen.set_value(color);
154         apen.set_alpha(get_amount());
155         apen.set_blend_method(get_blend_method());
156
157         for(y=0;y<renddesc.get_h();y++,apen.inc_y(),apen.dec_x(x))
158                 for(x=0;x<renddesc.get_w();x++,apen.inc_x())
159                         apen.put_value();
160
161         // Mark our progress as finished
162         if(cb && !cb->amount_complete(10000,10000))
163                 return false;
164
165         return true;
166 }