Fix bugs in previous commit that caused FTBFS in synfig and ETL FTBFS with older...
[synfig.git] / synfig-core / tags / stable / 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         typedef Target* (*Factory)(const char *filename);
106
107         //! A type for a map of targets, indexed by the name of the Target
108         typedef std::map<String,std::pair<Factory,String> > Book;
109
110         typedef std::map<String,String> ExtBook;
111
112         //! Target Book, indexed by the target's name
113         static Book* book_;
114
115         //! Map of target names indexed by associated file extension
116         static ExtBook* ext_book_;
117
118         static Book& book();
119         static ExtBook& ext_book();
120
121         static bool subsys_init();
122         static bool subsys_stop();
123
124         //! Adjusted Render description set by set_rend_desc()
125         RendDesc desc;
126
127         etl::handle<Canvas> canvas;
128
129         int quality_;
130         Gamma gamma_;
131
132         bool remove_alpha;
133
134         bool avoid_time_sync_;
135
136 protected:
137
138         Target();
139
140 public:
141         virtual ~Target() { }
142
143         int get_quality()const { return quality_; }
144
145         void set_quality(int q) { quality_=q; }
146
147         void set_avoid_time_sync(bool x=true) { avoid_time_sync_=x; }
148
149         bool get_avoid_time_sync()const { return avoid_time_sync_; }
150
151         bool get_remove_alpha()const { return remove_alpha; }
152
153         void set_remove_alpha(bool x=true) { remove_alpha=x; }
154
155         Gamma &gamma() { return gamma_; }
156
157         const Gamma &gamma()const { return gamma_; }
158
159         virtual void set_canvas(etl::handle<Canvas> c);
160
161         const etl::handle<Canvas> &get_canvas()const { return canvas; }
162
163         RendDesc &rend_desc() { return desc; }
164         const RendDesc &rend_desc()const { return desc; }
165
166         //! Renders the canvas to the target
167         virtual bool render(ProgressCallback *cb=NULL)=0;
168
169         //! Sets the RendDesc for the Target to \a desc.
170         /*!     If there are any parts of \a desc that the render target
171         **      is not capable of doing, the render target will adjust
172         **      \a desc to fit its needs.
173         */
174         virtual bool set_rend_desc(RendDesc *d) { desc=*d; return true; }
175
176         virtual bool init() { return true; }
177
178         //! Creates a new Target described by \a type, outputting to a file described by \a filename.
179         static Handle create(const String &type, const String &filename);
180 }; // END of class Target
181
182 }; // END of namespace synfig
183
184 /* === E N D =============================================================== */
185
186 #include "canvas.h"
187 #endif