more updates
[synfig.git] / synfig-core / trunk / src / synfig / target.h
1 /* === S I N F 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 Robert B. Quattlebaum Jr.
9 **
10 **      This software and associated documentation
11 **      are CONFIDENTIAL and PROPRIETARY property of
12 **      the above-mentioned copyright holder.
13 **
14 **      You may not copy, print, publish, or in any
15 **      other way distribute this software without
16 **      a prior written agreement with
17 **      the copyright holder.
18 **      \endlegal
19 */
20 /* ========================================================================= */
21
22 /* === S T A R T =========================================================== */
23
24 #ifndef __SINFG_TARGET_H
25 #define __SINFG_TARGET_H
26
27 /* === H E A D E R S ======================================================= */
28
29 #include "string_decl.h"
30 #include <utility>
31 //#include <list>
32 #include <map>
33 #include <ETL/handle>
34 #include "renddesc.h"
35 //#include "general.h"
36 #include "color.h"
37 #include "canvas.h"
38
39 /* === M A C R O S ========================================================= */
40
41 //! \writeme
42 #define SINFG_TARGET_MODULE_EXT public: static const char name__[], version__[], ext__[],cvs_id__[]; static Target *create(const char *filename);
43
44 //! Sets the name of the target
45 #define SINFG_TARGET_SET_NAME(class,x) const char class::name__[]=x
46
47 //! \writeme
48 #define SINFG_TARGET_SET_EXT(class,x) const char class::ext__[]=x
49
50 //! Sets the version of the target
51 #define SINFG_TARGET_SET_VERSION(class,x) const char class::version__[]=x
52
53 //! Sets the CVS ID of the target
54 #define SINFG_TARGET_SET_CVS_ID(class,x) const char class::cvs_id__[]=x
55
56 //! \writeme
57 #define SINFG_TARGET_INIT(class) sinfg::Target* class::create(const char *filename) { return new class(filename); }
58
59 /* === T Y P E D E F S ===================================================== */
60
61 /* === C L A S S E S & S T R U C T S ======================================= */
62
63 namespace sinfg {
64
65 class Surface;
66 class RendDesc;
67 class Canvas;
68 class ProgressCallback;
69
70 /*!     \class Target
71 **      \brief Render-target
72 **      \todo writeme
73 */
74 class Target : public etl::shared_object
75 {
76 public:
77         typedef etl::handle<Target> Handle;
78         typedef etl::loose_handle<Target> LooseHandle;
79         typedef etl::handle<const Target> ConstHandle;
80
81         typedef Target* (*Factory)(const char *filename);
82
83         //! A type for a map of targets, indexed by the name of the Target
84         typedef std::map<String,std::pair<Factory,String> > Book;
85
86         typedef std::map<String,String> ExtBook;
87
88         //! Target Book, indexed by the target's name
89         static Book* book_;
90
91         //! Map of target names indexed by associated file extension
92         static ExtBook* ext_book_;
93         
94         static Book& book();
95         static ExtBook& ext_book();
96
97         static bool subsys_init();
98         static bool subsys_stop();
99         
100         //! Adjusted Render description set by set_rend_desc()
101         RendDesc desc;
102
103         etl::handle<Canvas> canvas;
104
105         int quality_;
106         Gamma gamma_;
107
108         bool remove_alpha;
109         
110         bool avoid_time_sync_;
111         
112 protected:
113
114         Target();
115
116 public:
117         virtual ~Target() { }
118
119         int get_quality()const { return quality_; }
120         
121         void set_quality(int q) { quality_=q; }
122         
123         void set_avoid_time_sync(bool x=true) { avoid_time_sync_=x; }
124
125         bool get_avoid_time_sync()const { return avoid_time_sync_; }
126         
127         bool get_remove_alpha()const { return remove_alpha; }
128
129         void set_remove_alpha(bool x=true) { remove_alpha=x; }
130         
131         Gamma &gamma() { return gamma_; }
132
133         const Gamma &gamma()const { return gamma_; }
134
135         virtual void set_canvas(etl::handle<Canvas> c);
136
137         const etl::handle<Canvas> &get_canvas()const { return canvas; }
138
139         RendDesc &rend_desc() { return desc; }
140         const RendDesc &rend_desc()const { return desc; }
141         
142         //! Renders the canvas to the target
143         virtual bool render(ProgressCallback *cb=NULL)=0;
144
145         //! Sets the RendDesc for the Target to \a desc.
146         /*!     If there are any parts of \a desc that the render target
147         **      is not capable of doing, the render target will adjust
148         **      \a desc to fit it's needs.
149         */
150         virtual bool set_rend_desc(RendDesc *d) { desc=*d; return true; }
151
152         virtual bool init() { return true; }
153
154         //! Creates a new Target described by \a type, outputing to a file described by \a filename.
155         static Handle create(const String &type, const String &filename);
156 }; // END of class Target
157
158 }; // END of namespace sinfg
159
160 /* === E N D =============================================================== */
161
162 #include "canvas.h"
163 #endif