1 /* === S Y N F I G ========================================================= */
3 ** \brief Target Class Implementation
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 ** Copyright (c) 2007 Chris Moore
10 ** Copyright (c) 2010 Diego Barrios Romero
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.
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.
23 /* ========================================================================= */
25 /* === S T A R T =========================================================== */
27 #ifndef __SYNFIG_TARGET_H
28 #define __SYNFIG_TARGET_H
30 /* === H E A D E R S ======================================================= */
32 #include <sigc++/signal.h>
33 #include "string_decl.h"
39 //#include "general.h"
42 #include "targetparam.h"
44 /* === M A C R O S ========================================================= */
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);
52 //! Sets the name of the target
53 #define SYNFIG_TARGET_SET_NAME(class,x) const char class::name__[]=x
56 #define SYNFIG_TARGET_SET_EXT(class,x) const char class::ext__[]=x
58 //! Sets the version of the target
59 #define SYNFIG_TARGET_SET_VERSION(class,x) const char class::version__[]=x
61 //! Sets the CVS ID of the target
62 #define SYNFIG_TARGET_SET_CVS_ID(class,x) const char class::cvs_id__[]=x
65 #define SYNFIG_TARGET_INIT(class) \
66 synfig::Target* class::create (const char *filename, \
67 synfig::TargetParam p) \
68 { return new class(filename, p); }
70 /* === T Y P E D E F S ===================================================== */
72 /* === C L A S S E S & S T R U C T S ======================================= */
79 class ProgressCallback;
83 ** \brief Render-target
86 class Target : public etl::shared_object
89 typedef etl::handle<Target> Handle;
90 typedef etl::loose_handle<Target> LooseHandle;
91 typedef etl::handle<const Target> ConstHandle;
94 -- ** -- S I G N A L S -------------------------------------------------------
99 sigc::signal<void> signal_progress_;
102 -- ** -- S I G N A L I N T E R F A C E -------------------------------------
107 sigc::signal<void>& signal_progress() { return signal_progress_; }
110 -- ** -- C O N S T R U C T O R S ---------------------------------------------
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).
118 typedef Target* (*Factory)(const char *filename, TargetParam p);
123 String filename; ///< Output filename including path
124 TargetParam target_param; ///< Target module parameters
127 //! Book of types of targets indexed by the name of the Target.
128 typedef std::map<String,BookEntry> Book;
130 typedef std::map<String,String> ExtBook;
132 //! Target Book, indexed by the target's name
135 //! Map of target names indexed by associated file extension
136 static ExtBook* ext_book_;
139 static ExtBook& ext_book();
141 static bool subsys_init();
142 static bool subsys_stop();
144 //! Adjusted Render description set by set_rend_desc()
147 etl::handle<Canvas> canvas;
154 bool avoid_time_sync_;
161 virtual ~Target() { }
163 int get_quality()const { return quality_; }
165 void set_quality(int q) { quality_=q; }
167 void set_avoid_time_sync(bool x=true) { avoid_time_sync_=x; }
169 bool get_avoid_time_sync()const { return avoid_time_sync_; }
171 bool get_remove_alpha()const { return remove_alpha; }
173 void set_remove_alpha(bool x=true) { remove_alpha=x; }
175 Gamma &gamma() { return gamma_; }
177 const Gamma &gamma()const { return gamma_; }
179 virtual void set_canvas(etl::handle<Canvas> c);
181 const etl::handle<Canvas> &get_canvas()const { return canvas; }
183 RendDesc &rend_desc() { return desc; }
184 const RendDesc &rend_desc()const { return desc; }
186 //! Renders the canvas to the target
187 virtual bool render(ProgressCallback *cb=NULL)=0;
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.
194 virtual bool set_rend_desc(RendDesc *d) { desc=*d; return true; }
196 virtual bool init() { return true; }
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
203 }; // END of namespace synfig
205 /* === E N D =============================================================== */