Merge branch 'genete_static_values'
[synfig.git] / synfig-core / src / modules / lyr_std / stroboscope.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file stroboscope.cpp
3 **      \brief Implementation of the "Stroboscope" layer
4 **
5 **      $Id$
6 **
7 **      \legal
8 **      Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 **      Copyright (c) 2007, 2008 Chris Moore
10 **      Copyright (c) 2009 Ray Frederikson
11 **
12 **      This package is free software; you can redistribute it and/or
13 **      modify it under the terms of the GNU General Public License as
14 **      published by the Free Software Foundation; either version 2 of
15 **      the License, or (at your option) any later version.
16 **
17 **      This package is distributed in the hope that it will be useful,
18 **      but WITHOUT ANY WARRANTY; without even the implied warranty of
19 **      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 **      General Public License for more details.
21 **      \endlegal
22 **
23 ** === N O T E S ===========================================================
24 **
25 ** ========================================================================= */
26
27 /* === H E A D E R S ======================================================= */
28
29 #ifdef USING_PCH
30 #       include "pch.h"
31 #else
32 #ifdef HAVE_CONFIG_H
33 #       include <config.h>
34 #endif
35
36 #include "stroboscope.h"
37 #include <synfig/valuenode.h>
38 #include <synfig/valuenode_const.h>
39 #include <synfig/valuenode_subtract.h>
40 #include <synfig/time.h>
41 #include <synfig/context.h>
42 #include <synfig/paramdesc.h>
43 #include <synfig/renddesc.h>
44 #include <synfig/value.h>
45 #include <synfig/canvas.h>
46
47 #endif
48
49 using namespace synfig;
50 using namespace std;
51 using namespace etl;
52
53 /* === M A C R O S ========================================================= */
54
55 /* === G L O B A L S ======================================================= */
56
57 SYNFIG_LAYER_INIT(Layer_Stroboscope);
58 SYNFIG_LAYER_SET_NAME(Layer_Stroboscope,"stroboscope");
59 SYNFIG_LAYER_SET_LOCAL_NAME(Layer_Stroboscope,N_("Stroboscope"));
60 SYNFIG_LAYER_SET_CATEGORY(Layer_Stroboscope,N_("Other"));
61 SYNFIG_LAYER_SET_VERSION(Layer_Stroboscope,"0.1");
62 SYNFIG_LAYER_SET_CVS_ID(Layer_Stroboscope,"$Id$");
63
64 /* === P R O C E D U R E S ================================================= */
65
66 /* === M E T H O D S ======================================================= */
67
68 Layer_Stroboscope::Layer_Stroboscope()
69 {
70         frequency=2.0;
71 }
72
73 Layer_Stroboscope::~Layer_Stroboscope()
74 {
75 }
76
77 bool
78 Layer_Stroboscope::set_param(const String & param, const ValueBase &value)
79 {
80         IMPORT(frequency);
81
82         return Layer::set_param(param,value);
83 }
84
85 ValueBase
86 Layer_Stroboscope::get_param(const String & param)const
87 {
88         EXPORT(frequency);
89         EXPORT_NAME();
90         EXPORT_VERSION();
91
92         return Layer::get_param(param);
93 }
94
95 Layer::Vocab
96 Layer_Stroboscope::get_param_vocab()const
97 {
98         Layer::Vocab ret(Layer::get_param_vocab());
99
100         ret.push_back(ParamDesc("frequency")
101                 .set_local_name(_("Frequency"))
102                 .set_description(_("Frequency of the Strobe in times per second"))
103         );
104
105         return ret;
106 }
107
108 void
109 Layer_Stroboscope::set_time(Context context, Time t)const
110 {
111         Time ret_time=Time::begin();
112         if(frequency > 0.0)
113                 ret_time = Time(1.0)/frequency*floor(t*frequency);
114
115         context.set_time(ret_time);
116 }
117
118 Color
119 Layer_Stroboscope::get_color(Context context, const Point &pos)const
120 {
121         return context.get_color(pos);
122 }
123
124 bool
125 Layer_Stroboscope::accelerated_render(Context context,Surface *surface,int quality, const RendDesc &renddesc, ProgressCallback *cb)const
126 {
127         return context.accelerated_render(surface,quality,renddesc,cb);
128 }