7c9481168a47b926e12e9f6b35c35bcd0f928dcb
[synfig.git] / synfig-core / src / synfig / layer_composite.h
1 /* === S Y N F I G ========================================================= */
2 /*!     \file layer_composite.h
3 **      \brief Composite Layer Class Implementation
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 /* === S T A R T =========================================================== */
25
26 #ifndef __SYNFIG_LAYER_COMPOSITE_H
27 #define __SYNFIG_LAYER_COMPOSITE_H
28
29 /* === H E A D E R S ======================================================= */
30
31 #include "layer.h"
32 #include "color.h"
33
34 /* === M A C R O S ========================================================= */
35
36 /* === T Y P E D E F S ===================================================== */
37
38 /* === C L A S S E S & S T R U C T S ======================================= */
39
40 namespace synfig {
41
42 class Layer_NoDeform {};
43
44
45 /*!     \class Layer_Composite
46 **      \brief Base class for layers that put stuff on top of lower layers
47 */
48 class Layer_Composite : public Layer
49 {
50 private:
51         //! The amount of composite
52         float amount_;
53         //! The blend method for the composition
54         Color::BlendMethod blend_method_;
55         bool amount_static;
56         bool blend_method_static;
57
58 protected:
59         //! Default constructor. Not used directly.
60         Layer_Composite(
61                 float   amount=1.0,
62                 Color::BlendMethod      blend_method=Color::BLEND_COMPOSITE
63         ):
64                 amount_                         (amount),
65                 blend_method_           (blend_method),
66                 converted_blend_        (false),
67                 transparent_color_      (false),
68                 amount_static           (false),
69                 blend_method_static     (true)
70         { }
71         //! Converted blend is used to check if an old version of canvas
72         //! is used in the composition. Old Straight was used as new Composite
73         //! \todo verify this
74         bool converted_blend_;
75         //! Transparent color is used for old canvas versions.
76         //!Old Straight plus transparent color seems to be the same new than alpha over.
77         bool transparent_color_;
78
79 public:
80         //! Gets the amount of the layer
81         float get_amount()const { return amount_; }
82         //! Sets the amount of the layer and returns this layer
83         Layer_Composite& set_amount(float x) { amount_=x; return *this; }
84         //! Gets the blend method of the layer
85         Color::BlendMethod get_blend_method()const { return blend_method_; }
86         //! Sets the blend method of the layer and returns this layer
87         Layer_Composite& set_blend_method(Color::BlendMethod x) { blend_method_=x; return *this; }
88         //! Returns true is amount is 1 and blend method is straight
89         virtual bool is_solid_color()const { return amount_==1.0f && blend_method_==Color::BLEND_STRAIGHT; }
90         //! Returns true if the amount is zero.
91         bool is_disabled()const { return amount_==0.0f; }
92         //! Gets the parameter vocabulary. To be overrided by the derived.
93         virtual Vocab get_param_vocab()const;
94         //! Sets the value for the given parameter.
95         virtual bool set_param(const String &param, const ValueBase &value);
96         //! Gets the value of the given parameter
97         virtual ValueBase get_param(const String &param)const;
98         //!Returns the rectangle that includes the context of the layer and
99         //! the intersection of the layer in case it is active and not onto
100         virtual bool set_param_static(const String &param, const bool x);
101         virtual bool get_param_static(const String &param) const;
102         virtual Rect get_full_bounding_rect(Context context)const;
103         //! Renders the layer composited on the context and puts it on the target surface.
104         virtual bool accelerated_render(Context context,Surface *surface,int quality, const RendDesc &renddesc, ProgressCallback *cb)const;
105 }; // END of class Layer_Composite
106
107 }; // END of namespace synfig
108
109 /* === E N D =============================================================== */
110
111 #endif