Fix bugs in previous commit that caused FTBFS in synfig and ETL FTBFS with older...
[synfig.git] / synfig-core / tags / synfig_0_61_05 / 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: target.h,v 1.1.1.1 2005/01/04 01:23:15 darco Exp $
6 **
7 **      \legal
8 **      Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 **
10 **      This package is free software; you can redistribute it and/or
11 **      modify it under the terms of the GNU General Public License as
12 **      published by the Free Software Foundation; either version 2 of
13 **      the License, or (at your option) any later version.
14 **
15 **      This package is distributed in the hope that it will be useful,
16 **      but WITHOUT ANY WARRANTY; without even the implied warranty of
17 **      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 **      General Public License for more details.
19 **      \endlegal
20 */
21 /* ========================================================================= */
22
23 /* === S T A R T =========================================================== */
24
25 #ifndef __SYNFIG_TARGET_H
26 #define __SYNFIG_TARGET_H
27
28 /* === H E A D E R S ======================================================= */
29
30 #include "string_decl.h"
31 #include <utility>
32 //#include <list>
33 #include <map>
34 #include <ETL/handle>
35 #include "renddesc.h"
36 //#include "general.h"
37 #include "color.h"
38 #include "canvas.h"
39
40 /* === M A C R O S ========================================================= */
41
42 //! \writeme
43 #define SYNFIG_TARGET_MODULE_EXT public: static const char name__[], version__[], ext__[],cvs_id__[]; static Target *create(const char *filename);
44
45 //! Sets the name of the target
46 #define SYNFIG_TARGET_SET_NAME(class,x) const char class::name__[]=x
47
48 //! \writeme
49 #define SYNFIG_TARGET_SET_EXT(class,x) const char class::ext__[]=x
50
51 //! Sets the version of the target
52 #define SYNFIG_TARGET_SET_VERSION(class,x) const char class::version__[]=x
53
54 //! Sets the CVS ID of the target
55 #define SYNFIG_TARGET_SET_CVS_ID(class,x) const char class::cvs_id__[]=x
56
57 //! \writeme
58 #define SYNFIG_TARGET_INIT(class) synfig::Target* class::create(const char *filename) { return new class(filename); }
59
60 /* === T Y P E D E F S ===================================================== */
61
62 /* === C L A S S E S & S T R U C T S ======================================= */
63
64 namespace synfig {
65
66 class Surface;
67 class RendDesc;
68 class Canvas;
69 class ProgressCallback;
70
71 /*!     \class Target
72 **      \brief Render-target
73 **      \todo writeme
74 */
75 class Target : public etl::shared_object
76 {
77 public:
78         typedef etl::handle<Target> Handle;
79         typedef etl::loose_handle<Target> LooseHandle;
80         typedef etl::handle<const Target> ConstHandle;
81
82         typedef Target* (*Factory)(const char *filename);
83
84         //! A type for a map of targets, indexed by the name of the Target
85         typedef std::map<String,std::pair<Factory,String> > Book;
86
87         typedef std::map<String,String> ExtBook;
88
89         //! Target Book, indexed by the target's name
90         static Book* book_;
91
92         //! Map of target names indexed by associated file extension
93         static ExtBook* ext_book_;
94         
95         static Book& book();
96         static ExtBook& ext_book();
97
98         static bool subsys_init();
99         static bool subsys_stop();
100         
101         //! Adjusted Render description set by set_rend_desc()
102         RendDesc desc;
103
104         etl::handle<Canvas> canvas;
105
106         int quality_;
107         Gamma gamma_;
108
109         bool remove_alpha;
110         
111         bool avoid_time_sync_;
112         
113 protected:
114
115         Target();
116
117 public:
118         virtual ~Target() { }
119
120         int get_quality()const { return quality_; }
121         
122         void set_quality(int q) { quality_=q; }
123         
124         void set_avoid_time_sync(bool x=true) { avoid_time_sync_=x; }
125
126         bool get_avoid_time_sync()const { return avoid_time_sync_; }
127         
128         bool get_remove_alpha()const { return remove_alpha; }
129
130         void set_remove_alpha(bool x=true) { remove_alpha=x; }
131         
132         Gamma &gamma() { return gamma_; }
133
134         const Gamma &gamma()const { return gamma_; }
135
136         virtual void set_canvas(etl::handle<Canvas> c);
137
138         const etl::handle<Canvas> &get_canvas()const { return canvas; }
139
140         RendDesc &rend_desc() { return desc; }
141         const RendDesc &rend_desc()const { return desc; }
142         
143         //! Renders the canvas to the target
144         virtual bool render(ProgressCallback *cb=NULL)=0;
145
146         //! Sets the RendDesc for the Target to \a desc.
147         /*!     If there are any parts of \a desc that the render target
148         **      is not capable of doing, the render target will adjust
149         **      \a desc to fit it's needs.
150         */
151         virtual bool set_rend_desc(RendDesc *d) { desc=*d; return true; }
152
153         virtual bool init() { return true; }
154
155         //! Creates a new Target described by \a type, outputing to a file described by \a filename.
156         static Handle create(const String &type, const String &filename);
157 }; // END of class Target
158
159 }; // END of namespace synfig
160
161 /* === E N D =============================================================== */
162
163 #include "canvas.h"
164 #endif