Fix bugs in previous commit that caused FTBFS in synfig and ETL FTBFS with older...
[synfig.git] / synfig-core / tags / synfig_0_61_05 / synfig-core / src / modules / lyr_std / insideout.cpp
1 /*! ========================================================================
2 ** Synfig
3 ** Template File
4 ** $Id: insideout.cpp,v 1.1.1.1 2005/01/04 01:23:10 darco Exp $
5 **
6 **      Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
7 **
8 **      This package is free software; you can redistribute it and/or
9 **      modify it under the terms of the GNU General Public License as
10 **      published by the Free Software Foundation; either version 2 of
11 **      the License, or (at your option) any later version.
12 **
13 **      This package is distributed in the hope that it will be useful,
14 **      but WITHOUT ANY WARRANTY; without even the implied warranty of
15 **      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 **      General Public License for more details.
17 **
18 ** === N O T E S ===========================================================
19 **
20 ** ========================================================================= */
21
22 /* === H E A D E R S ======================================================= */
23
24 #ifdef USING_PCH
25 #       include "pch.h"
26 #else
27 #ifdef HAVE_CONFIG_H
28 #       include <config.h>
29 #endif
30
31 #include "insideout.h"
32
33 #include <synfig/string.h>
34 #include <synfig/time.h>
35 #include <synfig/context.h>
36 #include <synfig/paramdesc.h>
37 #include <synfig/renddesc.h>
38 #include <synfig/surface.h>
39 #include <synfig/value.h>
40 #include <synfig/valuenode.h>
41 #include <synfig/transform.h>
42
43 #endif
44
45 /* === M A C R O S ========================================================= */
46
47 /* === G L O B A L S ======================================================= */
48
49 SYNFIG_LAYER_INIT(InsideOut);
50 SYNFIG_LAYER_SET_NAME(InsideOut,"inside_out");
51 SYNFIG_LAYER_SET_LOCAL_NAME(InsideOut,_("InsideOut"));
52 SYNFIG_LAYER_SET_CATEGORY(InsideOut,_("Distortions"));
53 SYNFIG_LAYER_SET_VERSION(InsideOut,"0.1");
54 SYNFIG_LAYER_SET_CVS_ID(InsideOut,"$Id: insideout.cpp,v 1.1.1.1 2005/01/04 01:23:10 darco Exp $");
55
56 /* === P R O C E D U R E S ================================================= */
57
58 /* === M E T H O D S ======================================================= */
59
60 InsideOut::InsideOut():
61         origin(0,0)
62 {
63 }
64         
65 bool
66 InsideOut::set_param(const String & param, const ValueBase &value)
67 {
68         IMPORT(origin);
69         return false;
70 }
71
72 ValueBase
73 InsideOut::get_param(const String & param)const
74 {
75         EXPORT(origin);
76         
77         EXPORT_NAME();
78         EXPORT_VERSION();
79                 
80         return ValueBase();     
81 }
82
83 synfig::Layer::Handle
84 InsideOut::hit_check(synfig::Context context, const synfig::Point &p)const
85 {
86         Point pos(p-origin);
87         Real inv_mag=pos.inv_mag();
88         Point invpos(pos*inv_mag*inv_mag);
89         return context.hit_check(invpos+origin);
90 }
91
92 Color
93 InsideOut::get_color(Context context, const Point &p)const
94 {
95         Point pos(p-origin);
96         Real inv_mag=pos.inv_mag();
97         Point invpos(pos*inv_mag*inv_mag);
98         return context.get_color(invpos+origin);
99 }
100
101 class InsideOut_Trans : public Transform
102 {
103         etl::handle<const InsideOut> layer;
104 public:
105         InsideOut_Trans(const InsideOut* x):layer(x) { }
106         
107         synfig::Vector perform(const synfig::Vector& x)const
108         {
109                 Point pos(x-layer->origin);
110                 Real inv_mag=pos.inv_mag();
111                 if(!isnan(inv_mag))
112                         return (pos*(inv_mag*inv_mag)+layer->origin);
113                 return x;
114         }
115         
116         synfig::Vector unperform(const synfig::Vector& x)const
117         {
118                 Point pos(x-layer->origin);
119                 Real inv_mag=pos.inv_mag();
120                 if(!isnan(inv_mag))
121                         return (pos*(inv_mag*inv_mag)+layer->origin);
122                 return x;
123         }
124 };
125 etl::handle<Transform>
126 InsideOut::get_transform()const
127 {
128         return new InsideOut_Trans(this);
129 }
130
131 Layer::Vocab
132 InsideOut::get_param_vocab()const
133 {
134         Layer::Vocab ret;
135         
136         ret.push_back(ParamDesc("origin")
137                 .set_local_name(_("Origin"))
138                 .set_description(_("Defines the where the center will be"))
139         );
140         
141         return ret;
142 }