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