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