moreupdates
[synfig.git] / synfig-core / trunk / 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 Robert B. Quattlebaum Jr.
7 **
8 ** This software and associated documentation
9 ** are CONFIDENTIAL and PROPRIETARY property of
10 ** the above-mentioned copyright holder.
11 **
12 ** You may not copy, print, publish, or in any
13 ** other way distribute this software without
14 ** a prior written agreement with
15 ** the copyright holder.
16 **
17 ** === N O T E S ===========================================================
18 **
19 ** ========================================================================= */
20
21 /* === H E A D E R S ======================================================= */
22
23 #ifdef USING_PCH
24 #       include "pch.h"
25 #else
26 #ifdef HAVE_CONFIG_H
27 #       include <config.h>
28 #endif
29
30 #include "insideout.h"
31
32 #include <synfig/string.h>
33 #include <synfig/time.h>
34 #include <synfig/context.h>
35 #include <synfig/paramdesc.h>
36 #include <synfig/renddesc.h>
37 #include <synfig/surface.h>
38 #include <synfig/value.h>
39 #include <synfig/valuenode.h>
40 #include <synfig/transform.h>
41
42 #endif
43
44 /* === M A C R O S ========================================================= */
45
46 /* === G L O B A L S ======================================================= */
47
48 SYNFIG_LAYER_INIT(InsideOut);
49 SYNFIG_LAYER_SET_NAME(InsideOut,"inside_out");
50 SYNFIG_LAYER_SET_LOCAL_NAME(InsideOut,_("InsideOut"));
51 SYNFIG_LAYER_SET_CATEGORY(InsideOut,_("Distortions"));
52 SYNFIG_LAYER_SET_VERSION(InsideOut,"0.1");
53 SYNFIG_LAYER_SET_CVS_ID(InsideOut,"$Id: insideout.cpp,v 1.1.1.1 2005/01/04 01:23:10 darco Exp $");
54
55 /* === P R O C E D U R E S ================================================= */
56
57 /* === M E T H O D S ======================================================= */
58
59 InsideOut::InsideOut():
60         origin(0,0)
61 {
62 }
63         
64 bool
65 InsideOut::set_param(const String & param, const ValueBase &value)
66 {
67         IMPORT(origin);
68         return false;
69 }
70
71 ValueBase
72 InsideOut::get_param(const String & param)const
73 {
74         EXPORT(origin);
75         
76         EXPORT_NAME();
77         EXPORT_VERSION();
78                 
79         return ValueBase();     
80 }
81
82 synfig::Layer::Handle
83 InsideOut::hit_check(synfig::Context context, const synfig::Point &p)const
84 {
85         Point pos(p-origin);
86         Real inv_mag=pos.inv_mag();
87         Point invpos(pos*inv_mag*inv_mag);
88         return context.hit_check(invpos+origin);
89 }
90
91 Color
92 InsideOut::get_color(Context context, const Point &p)const
93 {
94         Point pos(p-origin);
95         Real inv_mag=pos.inv_mag();
96         Point invpos(pos*inv_mag*inv_mag);
97         return context.get_color(invpos+origin);
98 }
99
100 class InsideOut_Trans : public Transform
101 {
102         etl::handle<const InsideOut> layer;
103 public:
104         InsideOut_Trans(const InsideOut* x):layer(x) { }
105         
106         synfig::Vector perform(const synfig::Vector& x)const
107         {
108                 Point pos(x-layer->origin);
109                 Real inv_mag=pos.inv_mag();
110                 if(!isnan(inv_mag))
111                         return (pos*(inv_mag*inv_mag)+layer->origin);
112                 return x;
113         }
114         
115         synfig::Vector unperform(const synfig::Vector& x)const
116         {
117                 Point pos(x-layer->origin);
118                 Real inv_mag=pos.inv_mag();
119                 if(!isnan(inv_mag))
120                         return (pos*(inv_mag*inv_mag)+layer->origin);
121                 return x;
122         }
123 };
124 etl::handle<Transform>
125 InsideOut::get_transform()const
126 {
127         return new InsideOut_Trans(this);
128 }
129
130 Layer::Vocab
131 InsideOut::get_param_vocab()const
132 {
133         Layer::Vocab ret;
134         
135         ret.push_back(ParamDesc("origin")
136                 .set_local_name(_("Origin"))
137                 .set_description(_("Defines the where the center will be"))
138         );
139         
140         return ret;
141 }