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