more updates
[synfig.git] / synfig-core / trunk / src / synfig / layer_solidcolor.cpp
1 /* === S I N F 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 Robert B. Quattlebaum Jr.
9 **
10 **      This software and associated documentation
11 **      are CONFIDENTIAL and PROPRIETARY property of
12 **      the above-mentioned copyright holder.
13 **
14 **      You may not copy, print, publish, or in any
15 **      other way distribute this software without
16 **      a prior written agreement with
17 **      the copyright holder.
18 **      \endlegal
19 */
20 /* ========================================================================= */
21
22 /* === H E A D E R S ======================================================= */
23
24 #ifdef USING_PCH
25 #       include "pch.h"
26 #else
27 #ifdef HAVE_CONFIG_H
28 #       include <config.h>
29 #endif
30
31 #include "layer_solidcolor.h"
32 #include "string.h"
33 #include "time.h"
34 #include "context.h"
35 #include "paramdesc.h"
36 #include "renddesc.h"
37 #include "surface.h"
38 #include "value.h"
39 #include "valuenode.h"
40
41 #endif
42
43 /* === U S I N G =========================================================== */
44
45 using namespace etl;
46 using namespace std;
47 using namespace sinfg;
48
49 /* === G L O B A L S ======================================================= */
50
51 SINFG_LAYER_INIT(Layer_SolidColor);
52 SINFG_LAYER_SET_NAME(Layer_SolidColor,"SolidColor");
53 SINFG_LAYER_SET_LOCAL_NAME(Layer_SolidColor,_("Solid Color"));
54 SINFG_LAYER_SET_CATEGORY(Layer_SolidColor,_("Geometry"));
55 SINFG_LAYER_SET_VERSION(Layer_SolidColor,"0.1");
56 SINFG_LAYER_SET_CVS_ID(Layer_SolidColor,"$Id: layer_solidcolor.cpp,v 1.1.1.1 2005/01/04 01:23:14 darco Exp $");
57
58 /* === P R O C E D U R E S ================================================= */
59
60 /* === M E T H O D S ======================================================= */
61
62 /* === E N T R Y P O I N T ================================================= */
63
64 Layer_SolidColor::Layer_SolidColor():
65         Layer_Composite(1.0,Color::BLEND_STRAIGHT),
66         color(Color::black())
67 {
68 }
69         
70 bool
71 Layer_SolidColor::set_param(const String & param, const ValueBase &value)
72 {
73         IMPORT(color);
74         
75         return Layer_Composite::set_param(param,value);
76 }
77
78 ValueBase
79 Layer_SolidColor::get_param(const String &param)const
80 {
81         EXPORT(color);
82
83         EXPORT_NAME();
84         EXPORT_VERSION();
85                 
86         return Layer_Composite::get_param(param);       
87 }
88
89 Layer::Vocab
90 Layer_SolidColor::get_param_vocab()const
91 {
92         Layer::Vocab ret(Layer_Composite::get_param_vocab());
93         
94         ret.push_back(ParamDesc("color")
95                 .set_local_name(_("Color"))
96         );
97         
98         return ret;
99 }
100
101 sinfg::Layer::Handle
102 Layer_SolidColor::hit_check(sinfg::Context context, const sinfg::Point &point)const
103 {
104         if(get_blend_method()==Color::BLEND_STRAIGHT && get_amount()>=0.5)
105                 return const_cast<Layer_SolidColor*>(this);
106         else
107         if(get_blend_method()==Color::BLEND_COMPOSITE && get_amount()*color.get_a()>=0.5)
108                 return const_cast<Layer_SolidColor*>(this);
109         
110         Layer::Handle layer(context.hit_check(point));
111         
112         return layer?layer:const_cast<Layer_SolidColor*>(this);
113 }
114
115 Color
116 Layer_SolidColor::get_color(Context context, const Point &pos)const
117 {
118         if(get_amount()==1.0 && get_blend_method()==Color::BLEND_STRAIGHT)
119                 return color;
120         else
121                 return Color::blend(color,context.get_color(pos),get_amount(),get_blend_method());
122 }
123         
124 bool
125 Layer_SolidColor::accelerated_render(Context context,Surface *surface,int quality, const RendDesc &renddesc, ProgressCallback *cb)const
126 {
127         if(get_amount()==1.0 && get_blend_method()==Color::BLEND_STRAIGHT)
128         {
129                 // Mark our progress as starting
130                 if(cb && !cb->amount_complete(0,1000))
131                         return false;
132                 
133                 surface->set_wh(renddesc.get_w(),renddesc.get_h());
134                 surface->fill(color);
135
136                 // Mark our progress as finished
137                 if(cb && !cb->amount_complete(1000,1000))
138                         return false;
139
140                 return true;
141         }
142
143         SuperCallback supercb(cb,0,9500,10000);
144
145         if(!context.accelerated_render(surface,quality,renddesc,&supercb))
146                 return false;
147
148         int x,y;
149
150         Surface::alpha_pen apen(surface->begin());
151
152         apen.set_value(color);
153         apen.set_alpha(get_amount());
154         apen.set_blend_method(get_blend_method());
155
156         for(y=0;y<renddesc.get_h();y++,apen.inc_y(),apen.dec_x(x))
157                 for(x=0;x<renddesc.get_w();x++,apen.inc_x())
158                         apen.put_value();
159
160         // Mark our progress as finished
161         if(cb && !cb->amount_complete(10000,10000))
162                 return false;
163
164         return true;
165 }