Fix bugs in previous commit that caused FTBFS in synfig and ETL FTBFS with older...
[synfig.git] / synfig-core / tags / stable / src / modules / mod_geometry / circle.h
1 /* === S Y N F I G ========================================================= */
2 /*!     \file circle.h
3 **      \brief Header file for implementation of the "Circle" layer
4 **
5 **      $Id$
6 **
7 **      \legal
8 **      Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 **      Copyright (c) 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 /* === H E A D E R S ======================================================= */
25
26 #ifndef __SYNFIG_LAYER_CIRCLE_H__
27 #define __SYNFIG_LAYER_CIRCLE_H__
28
29 /* -- H E A D E R S --------------------------------------------------------- */
30
31 #include <synfig/layer_composite.h>
32 #include <synfig/color.h>
33 #include <synfig/vector.h>
34
35 using namespace synfig;
36 using namespace std;
37 using namespace etl;
38
39 /* -- M A C R O S ----------------------------------------------------------- */
40
41 /* -- T Y P E D E F S ------------------------------------------------------- */
42
43 /* -- S T R U C T S & C L A S S E S ----------------------------------------- */
44
45 class Circle : public synfig::Layer_Composite, public synfig::Layer_NoDeform
46 {
47         SYNFIG_LAYER_MODULE_EXT
48 private:
49         synfig::Color color;
50         synfig::Point origin;
51         synfig::Real radius;
52         synfig::Real feather;
53         bool invert;
54         int falloff;
55
56         //Caching system for circle
57         struct CircleDataCache
58         {
59                 Real inner_radius;
60                 Real outer_radius;
61
62                 Real inner_radius_sqd;
63                 Real outer_radius_sqd;
64
65                 Real diff_sqd;
66                 Real double_feather;
67         };
68
69         typedef Real    FALLOFF_FUNC(const CircleDataCache &c, const Real &mag_sqd);
70
71         FALLOFF_FUNC    *falloff_func;
72         CircleDataCache cache;
73
74         void constructcache();
75
76         static  Real    SqdFalloff(const CircleDataCache &c, const Real &mag_sqd);
77         static  Real    InvSqdFalloff(const CircleDataCache &c, const Real &mag_sqd);
78         static  Real    SqrtFalloff(const CircleDataCache &c, const Real &mag_sqd);
79         static  Real    InvSqrtFalloff(const CircleDataCache &c, const Real &mag_sqd);
80         static  Real    LinearFalloff(const CircleDataCache &c, const Real &mag_sqd);
81         static  Real    InvLinearFalloff(const CircleDataCache &c, const Real &mag_sqd);
82         static  Real    SigmondFalloff(const CircleDataCache &c, const Real &mag_sqd);
83         static  Real    InvSigmondFalloff(const CircleDataCache &c, const Real &mag_sqd);
84         static  Real    CosineFalloff(const CircleDataCache &c, const Real &mag_sqd);
85         static  Real    InvCosineFalloff(const CircleDataCache &c, const Real &mag_sqd);
86
87         FALLOFF_FUNC    *GetFalloffFunc()const;
88         bool ImportParameters(const String &param, const ValueBase &value);
89
90 public:
91         enum Falloff
92         {
93                 FALLOFF_SQUARED         =0,
94                 FALLOFF_INTERPOLATION_LINEAR            =1,
95                 FALLOFF_SMOOTH          =2,
96                 FALLOFF_COSINE          =2,
97                 FALLOFF_SIGMOND         =3,
98                 FALLOFF_SQRT            =4
99         };
100
101         Circle();
102
103         virtual bool set_param(const String &param, const ValueBase &value);
104
105         virtual ValueBase get_param(const String &param)const;
106
107         virtual Color get_color(Context context, const Point &pos)const;
108
109         virtual bool accelerated_render(Context context,Surface *surface,int quality, const RendDesc &renddesc, ProgressCallback *cb)const;
110
111         virtual synfig::Rect get_full_bounding_rect(synfig::Context context)const;
112         virtual synfig::Rect get_bounding_rect()const;
113
114         synfig::Layer::Handle hit_check(synfig::Context context, const synfig::Point &point)const;
115
116         virtual Vocab get_param_vocab()const;
117 };
118
119 /* -- E X T E R N S --------------------------------------------------------- */
120
121
122 /* -- E N D ----------------------------------------------------------------- */
123
124 #endif