Fix 2458112: default transform GUIDs to random values, not zero. Initialise the...
[synfig.git] / synfig-core / trunk / src / modules / lyr_std / insideout.cpp
blob1ed9c2c77bcd08c9373475f48fd674b533a3535d
1 /* === S Y N F I G ========================================================= */
2 /*! \file insideout.cpp
3 ** \brief Implementation of the "Inside Out" layer
4 **
5 ** $Id$
6 **
7 ** \legal
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 ** Copyright (c) 2007 Chris Moore
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.
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
22 ** === N O T E S ===========================================================
24 ** ========================================================================= */
26 /* === H E A D E R S ======================================================= */
28 #ifdef USING_PCH
29 # include "pch.h"
30 #else
31 #ifdef HAVE_CONFIG_H
32 # include <config.h>
33 #endif
35 #include "insideout.h"
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>
47 #endif
49 /* === M A C R O S ========================================================= */
51 /* === G L O B A L S ======================================================= */
53 SYNFIG_LAYER_INIT(InsideOut);
54 SYNFIG_LAYER_SET_NAME(InsideOut,"inside_out");
55 SYNFIG_LAYER_SET_LOCAL_NAME(InsideOut,N_("Inside Out"));
56 SYNFIG_LAYER_SET_CATEGORY(InsideOut,N_("Distortions"));
57 SYNFIG_LAYER_SET_VERSION(InsideOut,"0.1");
58 SYNFIG_LAYER_SET_CVS_ID(InsideOut,"$Id$");
60 /* === P R O C E D U R E S ================================================= */
62 /* === M E T H O D S ======================================================= */
64 InsideOut::InsideOut():
65 origin(0,0)
69 bool
70 InsideOut::set_param(const String & param, const ValueBase &value)
72 IMPORT(origin);
73 return false;
76 ValueBase
77 InsideOut::get_param(const String & param)const
79 EXPORT(origin);
81 EXPORT_NAME();
82 EXPORT_VERSION();
84 return ValueBase();
87 synfig::Layer::Handle
88 InsideOut::hit_check(synfig::Context context, const synfig::Point &p)const
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);
96 Color
97 InsideOut::get_color(Context context, const Point &p)const
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);
105 class InsideOut_Trans : public Transform
107 etl::handle<const InsideOut> layer;
108 public:
109 InsideOut_Trans(const InsideOut* x):Transform(x->get_guid()),layer(x) { }
111 synfig::Vector perform(const synfig::Vector& x)const
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;
120 synfig::Vector unperform(const synfig::Vector& x)const
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;
129 etl::handle<Transform>
130 InsideOut::get_transform()const
132 return new InsideOut_Trans(this);
135 Layer::Vocab
136 InsideOut::get_param_vocab()const
138 Layer::Vocab ret;
140 ret.push_back(ParamDesc("origin")
141 .set_local_name(_("Origin"))
142 .set_description(_("Defines the where the center will be"))
145 return ret;