Documentation and clean of target.h and target.cpp
[synfig.git] / synfig-core / src / synfig / target.h
1 /* === S Y N F I G ========================================================= */
2 /*!     \file target.h
3 **      \brief Target Class Implementation
4 **
5 **      $Id$
6 **
7 **      \legal
8 **      Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 **      Copyright (c) 2007 Chris Moore
10 **      Copyright (c) 2010 Diego Barrios Romero
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 /* ========================================================================= */
24
25 /* === S T A R T =========================================================== */
26
27 #ifndef __SYNFIG_TARGET_H
28 #define __SYNFIG_TARGET_H
29
30 /* === H E A D E R S ======================================================= */
31
32 #include <sigc++/signal.h>
33 #include "string_decl.h"
34 #include <utility>
35 #include <map>
36 #include <ETL/handle>
37 #include "renddesc.h"
38 #include "color.h"
39 #include "canvas.h"
40 #include "targetparam.h"
41
42 /* === M A C R O S ========================================================= */
43
44 //! Defines various variables and the create method, common for all Targets.
45 //! To be used in the private part of the target class definition.
46 #define SYNFIG_TARGET_MODULE_EXT \
47                 public: static const char name__[], version__[], ext__[], cvs_id__[];\
48                 static Target* create (const char *filename, synfig::TargetParam p);
49
50 //! Sets the name of the target
51 #define SYNFIG_TARGET_SET_NAME(class,x) const char class::name__[]=x
52
53 //! Sets the primary file extension of the target
54 #define SYNFIG_TARGET_SET_EXT(class,x) const char class::ext__[]=x
55
56 //! Sets the version of the target
57 #define SYNFIG_TARGET_SET_VERSION(class,x) const char class::version__[]=x
58
59 //! Sets the CVS ID of the target
60 #define SYNFIG_TARGET_SET_CVS_ID(class,x) const char class::cvs_id__[]=x
61
62 //! Defines de implementation of the create method for the target
63 //! \param filename The file name to be created by the target.
64 //! |param p The parameters passed to the target (bit rate and vcodec)
65 #define SYNFIG_TARGET_INIT(class)                                                                               \
66         synfig::Target* class::create (const char *filename,                            \
67                                                                    synfig::TargetParam p)                               \
68         { return new class(filename, p); }
69
70 /* === T Y P E D E F S ===================================================== */
71
72 /* === C L A S S E S & S T R U C T S ======================================= */
73
74 namespace synfig {
75
76 class Surface;
77 class RendDesc;
78 class Canvas;
79 class ProgressCallback;
80 class TargetParam;
81
82 /*!     \class Target
83 **      \brief Used to produce rendered animations of the documents
84 **
85 *       It is the base class for all the target renderers. It defines the has a static Book
86 *       pointer class that is a map for the targets factory creators and the strings
87 *       of the extension that the renderer can understand. It allows to create the a
88 *       pointer to a particular renderer just by using the extension of the name of file
89 *       to import. Also it creates a virtual member render() that must be declared in
90 *       the inherited classes.
91 */
92 class Target : public etl::shared_object
93 {
94 public:
95         typedef etl::handle<Target> Handle;
96         typedef etl::loose_handle<Target> LooseHandle;
97         typedef etl::handle<const Target> ConstHandle;
98
99         /*
100  -- ** -- S I G N A L S -------------------------------------------------------
101         */
102
103 private:
104
105         sigc::signal<void> signal_progress_;
106
107         /*
108  -- ** -- S I G N A L   I N T E R F A C E -------------------------------------
109         */
110
111 public:
112
113         sigc::signal<void>& signal_progress() { return signal_progress_; }
114
115         /*
116  --     ** -- C O N S T R U C T O R S ---------------------------------------------
117         */
118
119 public:
120         //! Type that represents a pointer to a Target's constructor.
121         /*! As a pointer to the constructor, it represents a "factory" of targets.
122         **  Receives the output filename (including path) and the parameters of the target.
123         */
124         typedef Target* (*Factory)(const char *filename, TargetParam p);
125
126         struct BookEntry
127         {
128                 Factory factory;
129                 String filename; ///< Output filename including path
130                 TargetParam target_param; ///< Target module parameters
131         };
132
133         //! Book of types of targets indexed by the name of the Target.
134         typedef std::map<String,BookEntry> Book;
135
136         //! Book of types of targets indexed by the file extension
137         typedef std::map<String,String> ExtBook;
138
139         //! Target Book, indexed by the target's name
140         static Book* book_;
141
142         //! Map of target names indexed by associated file extension
143         static ExtBook* ext_book_;
144
145         static Book& book();
146         static ExtBook& ext_book();
147
148         //! Initializes the Target module by creating a book of targets names
149         //! and its creators
150         static bool subsys_init();
151         //! Stops the Target module by deleting the book and the extension book
152         static bool subsys_stop();
153
154         //! Adjusted Render description set by set_rend_desc()
155         RendDesc desc;
156
157         //! Canvas being rendered in this target module
158         //! \see set_canvas()
159         etl::handle<Canvas> canvas;
160
161         //! Render quality used for the render process of the target.
162         int quality_;
163         //! Gamma value used for the render process of the target
164         Gamma gamma_;
165
166         //! Used by non alpha supported targets to decide if the background
167         //! must be filled or not
168         bool remove_alpha;
169
170         //! When set to true, the target doesn't sync to canvas time.
171         bool avoid_time_sync_;
172
173 protected:
174         //! Default constructor
175         Target();
176
177 public:
178         virtual ~Target() { }
179         //! Gets the target quality
180         int get_quality()const { return quality_; }
181         //! Sets the target quality
182         void set_quality(int q) { quality_=q; }
183         //! Sets the target avoid time synchronization
184         void set_avoid_time_sync(bool x=true) { avoid_time_sync_=x; }
185         //! Gets the target avoid time synchronization
186         bool get_avoid_time_sync()const { return avoid_time_sync_; }
187         //! Gets the target remove alpha
188         bool get_remove_alpha()const { return remove_alpha; }
189         //! Sets the target remove alpha
190         void set_remove_alpha(bool x=true) { remove_alpha=x; }
191         //! Gets the target gamma
192         Gamma &gamma() { return gamma_; }
193         //! Sets the target gamma
194         const Gamma &gamma()const { return gamma_; }
195         //! Sets the target canvas. Must be defined by derived targets
196         virtual void set_canvas(etl::handle<Canvas> c);
197         //! Gets the target canvas.
198         const etl::handle<Canvas> &get_canvas()const { return canvas; }
199         //! Gets the target particular render description
200         RendDesc &rend_desc() { return desc; }
201         //! Gets the target particular render description
202         const RendDesc &rend_desc()const { return desc; }
203         //! Sets the RendDesc for the Target to \a desc.
204         /*!     If there are any parts of \a desc that the render target
205         **      is not capable of doing, the render target will adjust
206         **      \a desc to fit its needs.
207         */
208         virtual bool set_rend_desc(RendDesc *d) { desc=*d; return true; }
209         //! Renders the canvas to the target
210         virtual bool render(ProgressCallback *cb=NULL)=0;
211         //! Initialization tasks of the derived target.
212         //! @returns true if the initialization has no errors
213         virtual bool init() { return true; }
214
215         //! Creates a new Target described by \a type, outputting to a file described by \a filename.
216         static Handle create(const String &type, const String &filename,
217                                                  synfig::TargetParam params);
218 }; // END of class Target
219
220 }; // END of namespace synfig
221
222 /* === E N D =============================================================== */
223
224 #endif