5fcaaeb45418524c0338d8551ca05350d21dc3a3
[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 <list>
36 #include <map>
37 #include <ETL/handle>
38 #include "renddesc.h"
39 //#include "general.h"
40 #include "color.h"
41 #include "canvas.h"
42 #include "targetparam.h"
43
44 /* === M A C R O S ========================================================= */
45
46 //! \writeme
47 #define SYNFIG_TARGET_MODULE_EXT public: static const char name__[],    \
48                 version__[], ext__[], cvs_id__[];                                                               \
49         static Target* create (const char *filename,                                            \
50                                                    synfig::TargetParam p);
51
52 //! Sets the name of the target
53 #define SYNFIG_TARGET_SET_NAME(class,x) const char class::name__[]=x
54
55 //! \writeme
56 #define SYNFIG_TARGET_SET_EXT(class,x) const char class::ext__[]=x
57
58 //! Sets the version of the target
59 #define SYNFIG_TARGET_SET_VERSION(class,x) const char class::version__[]=x
60
61 //! Sets the CVS ID of the target
62 #define SYNFIG_TARGET_SET_CVS_ID(class,x) const char class::cvs_id__[]=x
63
64 //! \writeme
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 Render-target
84 **      \todo writeme
85 */
86 class Target : public etl::shared_object
87 {
88 public:
89         typedef etl::handle<Target> Handle;
90         typedef etl::loose_handle<Target> LooseHandle;
91         typedef etl::handle<const Target> ConstHandle;
92
93         /*
94  -- ** -- S I G N A L S -------------------------------------------------------
95         */
96
97 private:
98
99         sigc::signal<void> signal_progress_;
100
101         /*
102  -- ** -- S I G N A L   I N T E R F A C E -------------------------------------
103         */
104
105 public:
106
107         sigc::signal<void>& signal_progress() { return signal_progress_; }
108
109         /*
110  --     ** -- C O N S T R U C T O R S ---------------------------------------------
111         */
112
113 public:
114         //! Type that represents a pointer to a Target's constructor.
115         /*! As a pointer to the constructor, it represents a "factory" of targets.
116         **  Receives the output filename (including path).
117         */
118         typedef Target* (*Factory)(const char *filename, TargetParam p);
119
120         struct BookEntry
121         {
122                 Factory factory;
123                 String filename; ///< Output filename including path
124                 TargetParam target_param; ///< Target module parameters
125         };
126
127         //! Book of types of targets indexed by the name of the Target.
128         typedef std::map<String,BookEntry> Book;
129
130         typedef std::map<String,String> ExtBook;
131
132         //! Target Book, indexed by the target's name
133         static Book* book_;
134
135         //! Map of target names indexed by associated file extension
136         static ExtBook* ext_book_;
137
138         static Book& book();
139         static ExtBook& ext_book();
140
141         static bool subsys_init();
142         static bool subsys_stop();
143
144         //! Adjusted Render description set by set_rend_desc()
145         RendDesc desc;
146
147         etl::handle<Canvas> canvas;
148
149         int quality_;
150         Gamma gamma_;
151
152         bool remove_alpha;
153
154         bool avoid_time_sync_;
155
156 protected:
157
158         Target();
159
160 public:
161         virtual ~Target() { }
162
163         int get_quality()const { return quality_; }
164
165         void set_quality(int q) { quality_=q; }
166
167         void set_avoid_time_sync(bool x=true) { avoid_time_sync_=x; }
168
169         bool get_avoid_time_sync()const { return avoid_time_sync_; }
170
171         bool get_remove_alpha()const { return remove_alpha; }
172
173         void set_remove_alpha(bool x=true) { remove_alpha=x; }
174
175         Gamma &gamma() { return gamma_; }
176
177         const Gamma &gamma()const { return gamma_; }
178
179         virtual void set_canvas(etl::handle<Canvas> c);
180
181         const etl::handle<Canvas> &get_canvas()const { return canvas; }
182
183         RendDesc &rend_desc() { return desc; }
184         const RendDesc &rend_desc()const { return desc; }
185
186         //! Renders the canvas to the target
187         virtual bool render(ProgressCallback *cb=NULL)=0;
188
189         //! Sets the RendDesc for the Target to \a desc.
190         /*!     If there are any parts of \a desc that the render target
191         **      is not capable of doing, the render target will adjust
192         **      \a desc to fit its needs.
193         */
194         virtual bool set_rend_desc(RendDesc *d) { desc=*d; return true; }
195
196         virtual bool init() { return true; }
197
198         //! Creates a new Target described by \a type, outputting to a file described by \a filename.
199         static Handle create(const String &type, const String &filename,
200                                                  synfig::TargetParam params);
201 }; // END of class Target
202
203 }; // END of namespace synfig
204
205 /* === E N D =============================================================== */
206
207 #include "canvas.h"
208 #endif