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