Fix bugs in previous commit that caused FTBFS in synfig and ETL FTBFS with older...
[synfig.git] / synfig-core / tags / synfig_0_61_06 / src / modules / lyr_std / insideout.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file insideout.cpp
3 **      \brief Template Header
4 **
5 **      $Id$
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 ** === N O T E S ===========================================================
22 **
23 ** ========================================================================= */
24
25 /* === H E A D E R S ======================================================= */
26
27 #ifdef USING_PCH
28 #       include "pch.h"
29 #else
30 #ifdef HAVE_CONFIG_H
31 #       include <config.h>
32 #endif
33
34 #include "insideout.h"
35
36 #include <synfig/string.h>
37 #include <synfig/time.h>
38 #include <synfig/context.h>
39 #include <synfig/paramdesc.h>
40 #include <synfig/renddesc.h>
41 #include <synfig/surface.h>
42 #include <synfig/value.h>
43 #include <synfig/valuenode.h>
44 #include <synfig/transform.h>
45
46 #endif
47
48 /* === M A C R O S ========================================================= */
49
50 /* === G L O B A L S ======================================================= */
51
52 SYNFIG_LAYER_INIT(InsideOut);
53 SYNFIG_LAYER_SET_NAME(InsideOut,"inside_out");
54 SYNFIG_LAYER_SET_LOCAL_NAME(InsideOut,_("InsideOut"));
55 SYNFIG_LAYER_SET_CATEGORY(InsideOut,_("Distortions"));
56 SYNFIG_LAYER_SET_VERSION(InsideOut,"0.1");
57 SYNFIG_LAYER_SET_CVS_ID(InsideOut,"$Id$");
58
59 /* === P R O C E D U R E S ================================================= */
60
61 /* === M E T H O D S ======================================================= */
62
63 InsideOut::InsideOut():
64         origin(0,0)
65 {
66 }
67
68 bool
69 InsideOut::set_param(const String & param, const ValueBase &value)
70 {
71         IMPORT(origin);
72         return false;
73 }
74
75 ValueBase
76 InsideOut::get_param(const String & param)const
77 {
78         EXPORT(origin);
79
80         EXPORT_NAME();
81         EXPORT_VERSION();
82
83         return ValueBase();
84 }
85
86 synfig::Layer::Handle
87 InsideOut::hit_check(synfig::Context context, const synfig::Point &p)const
88 {
89         Point pos(p-origin);
90         Real inv_mag=pos.inv_mag();
91         Point invpos(pos*inv_mag*inv_mag);
92         return context.hit_check(invpos+origin);
93 }
94
95 Color
96 InsideOut::get_color(Context context, const Point &p)const
97 {
98         Point pos(p-origin);
99         Real inv_mag=pos.inv_mag();
100         Point invpos(pos*inv_mag*inv_mag);
101         return context.get_color(invpos+origin);
102 }
103
104 class InsideOut_Trans : public Transform
105 {
106         etl::handle<const InsideOut> layer;
107 public:
108         InsideOut_Trans(const InsideOut* x):layer(x) { }
109
110         synfig::Vector perform(const synfig::Vector& x)const
111         {
112                 Point pos(x-layer->origin);
113                 Real inv_mag=pos.inv_mag();
114                 if(!isnan(inv_mag))
115                         return (pos*(inv_mag*inv_mag)+layer->origin);
116                 return x;
117         }
118
119         synfig::Vector unperform(const synfig::Vector& x)const
120         {
121                 Point pos(x-layer->origin);
122                 Real inv_mag=pos.inv_mag();
123                 if(!isnan(inv_mag))
124                         return (pos*(inv_mag*inv_mag)+layer->origin);
125                 return x;
126         }
127 };
128 etl::handle<Transform>
129 InsideOut::get_transform()const
130 {
131         return new InsideOut_Trans(this);
132 }
133
134 Layer::Vocab
135 InsideOut::get_param_vocab()const
136 {
137         Layer::Vocab ret;
138
139         ret.push_back(ParamDesc("origin")
140                 .set_local_name(_("Origin"))
141                 .set_description(_("Defines the where the center will be"))
142         );
143
144         return ret;
145 }