moreupdates
[synfig.git] / synfig-core / trunk / src / synfig / renddesc.h
1 /* === S Y N F I G ========================================================= */
2 /*!     \file renddesc.h
3 **      \brief Template Header
4 **
5 **      $Id: renddesc.h,v 1.1.1.1 2005/01/04 01:23:14 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 __SYNFIG_RENDERDESC_H
25 #define __SYNFIG_RENDERDESC_H
26
27 /* === H E A D E R S ======================================================= */
28
29 #include "vector.h"
30 #include "color.h"
31 #include "types.h"
32 #include <cmath>
33 #include "rect.h"
34
35 /* === M A C R O S ========================================================= */
36
37 #ifndef DPM2DPI
38 #define DPM2DPI(x)      (float(x)/39.3700787402f)
39 #define DPI2DPM(x)      (float(x)*39.3700787402f)
40 #endif
41
42 /* === T Y P E D E F S ===================================================== */
43
44 /* === C L A S S E S & S T R U C T S ======================================= */
45
46 namespace synfig {
47
48 /*!     \class RendDesc
49 **      \todo writeme
50 */
51 class RendDesc
52 {
53 public:
54         enum Lock
55         {
56                 PX_ASPECT=(1<<0),
57                 PX_AREA=(1<<1),
58                 PX_W=(1<<2),
59                 PX_H=(1<<3),
60                 
61                 IM_ASPECT=(1<<4),
62                 IM_SPAN=(1<<5),
63                 IM_W=(1<<6),
64                 IM_H=(1<<7),
65                 IM_ZOOMIN=(1<<8),
66                 IM_ZOOMOUT=(1<<9),
67                                 
68                 LINK_PX_ASPECT=(1<<10),
69                 LINK_PX_AREA=(1<<11),
70                 LINK_IM_ASPECT=(1<<12),
71                 LINK_IM_SPAN=(1<<13),
72                 LINK_IM_CENTER=(1<<14)
73         };
74         
75 private:
76         int w_,h_;
77         Real x_res;
78         Real y_res;
79         Point tl_, br_;
80         Point focus;
81         int a;
82         //Gamma gamma;
83         Color background;
84         int flags;
85         bool interlaced;
86         bool clamp;
87
88         float frame_rate;
89         Time time_begin, time_end;
90                 
91 public:
92
93         enum
94         {
95                 ANTIALIAS_UNIFORM,
96                 ANTIALIAS_MONTE_CARLO,
97                 ANTIALIAS_JITTERED,
98                 ANTIALIAS_ADAPTIVE,
99                 ANTIALIAS_QUINTCUNX
100         } AntialiasFilter;
101
102         //! Default Constructor
103         RendDesc():
104                 w_                      (480),
105                 h_                      (270),
106                 x_res           (DPI2DPM(72.0f)),
107                 y_res           (DPI2DPM(72.0f)),
108                 tl_                     (-4,2.25),
109                 br_                     (4,-2.25),
110                 focus           (0,0),
111                 a                       (2),
112                 background      (Color::gray()),
113                 flags           (0),
114                 interlaced      (false),
115                 clamp           (false),
116                 frame_rate      (24),
117                 time_begin      (0),
118                 time_end        (0)
119         { }
120         
121         //! \writeme
122         RendDesc &apply(const RendDesc &x);
123         
124         //! \writeme
125         const Color &get_bg_color()const;
126
127         //! \writeme
128         RendDesc &set_bg_color(const Color &bg);
129
130         //! Return the width of the composition in pixels
131         int get_w()const;
132
133         //! Set the width of the composition in pixels.
134         /*! The other parameters are adjusted according to the
135         **      constraints placed on the flags.
136         */
137         RendDesc &set_w(int x);
138
139         //! Return the height of the composition in pixels
140         int     get_h()const;
141
142         //! Set the height of the composition in pixels.
143         /*! The other parameters are adjusted according to the
144         **      constraints placed on the flags.
145         */
146         RendDesc &set_h(int y);
147
148         //!     Sets the width and height of the composition in pixels
149         RendDesc &set_wh(int x, int y);
150
151     //! Returns the horizontal resolution (in dots per meter)
152         Real get_x_res()const;
153
154         //! Sets the horizontal resolution (in dots per meter)
155         RendDesc &set_x_res(Real x);
156         
157     //! Returns the vertical resolution (in dots per meter)
158         Real get_y_res()const;
159
160         //! Sets the vertical resolution (in dots per meter)
161         RendDesc &set_y_res(Real y);
162
163
164         //! Return the physical width of the composition in meters
165         Real get_physical_w()const;
166
167         //! Return the physical height of the composition in meters
168         Real get_physical_h()const;
169
170         //! Set the physical width of the composition in meters
171         RendDesc &set_physical_w(Real w);
172
173         //! Set the physical height of the composition in meters
174         RendDesc &set_physical_h(Real h);
175
176
177         //!     Return the index of the first frame
178         int get_frame_start()const;
179
180         //! Set the index of the first frame
181         RendDesc &set_frame_start(int x);
182         
183         //!     Return the index of the last frame
184         int get_frame_end()const;
185         
186         //! Set the index of the last frame
187         RendDesc &set_frame_end(int x);
188
189         //!     Return the starting time of the animation
190         const Time get_time_start()const;
191         
192         //!     Set the time that the animation will start
193         RendDesc &set_time_start(Time x);
194
195         //! Return the end time of the animation
196         const Time get_time_end()const;
197         
198         //!     Set the time that the animation will end
199         RendDesc &set_time_end(Time x);
200
201         //!     Setup for one frame at the given time
202         RendDesc &set_time(Time x);
203
204         //!     Setup for one frame
205         RendDesc &set_frame(int x);
206
207         //!     Return the frame rate (frames-per-second)
208         const float &get_frame_rate()const;
209         
210         //! Set the frame rate (frames-per-second)
211         RendDesc &set_frame_rate(float x);
212
213         //! Return the status of the interlaced flag
214         const bool &get_interlaced()const;
215         
216         //! Set the interlace flag
217         RendDesc &set_interlaced(bool x);
218
219         //! Return the status of the clamp flag
220         const bool &get_clamp()const;
221         
222         //! Set the clamp flag
223         RendDesc &set_clamp(bool x);
224
225         //! Set constraint flags
226         RendDesc &set_flags(const int &x);
227         
228         //! Clear constraint flags
229         RendDesc &clear_flags();
230
231         //! Get constraint flags
232         int get_flags()const;
233
234         //!     Return the aspect ratio of a single pixel
235         Point::value_type get_pixel_aspect()const;
236
237         //!     Return the aspect ratio of the entire image
238         Point::value_type get_image_aspect()const;
239         
240         //! Return the antialias amount
241         const int &get_antialias()const;
242
243         //! Set the antilaias amount
244         RendDesc &set_antialias(const int &x);
245
246         //! Return the distance from the bottom-right to the top-left
247         Real get_span()const;
248
249         //! Set the span distance
250         RendDesc& set_span(const Real &x);
251
252         //const Gamma &get_gamma()const;
253
254         //RendDesc &set_gamma(const Gamma &x);
255
256         const Point &get_focus()const;
257
258         RendDesc &set_focus(const Point &x);
259
260         const Point &get_tl()const;
261         
262         RendDesc &set_tl(const Point &x);
263
264         const Point &get_br()const;
265         
266         RendDesc &set_br(const Point &x);
267         
268         Rect get_rect()const { return Rect(get_tl(),get_br()); }
269
270         RendDesc &set_viewport(const Point &__tl, const Point &__br);
271         
272         RendDesc &set_viewport(Vector::value_type a,Vector::value_type b,Vector::value_type c,Vector::value_type d);
273
274         //! Returns the width of one pixel
275         Real get_pw()const;
276
277         //! Returns the height of one pixel
278         Real get_ph()const;
279
280         //! Sets viewport to represent the screen at the give pixel coordinates
281         RendDesc &set_subwindow(int x, int y, int w, int h);
282 };      // END of class RendDesc
283
284 //! This operator allows the combining of RendDesc::Lock flags using the '|' operator
285 /*!     \see RendDesc::Lock, RendDesc */
286 inline RendDesc::Lock operator|(RendDesc::Lock lhs, RendDesc::Lock rhs)
287 {
288         return static_cast<RendDesc::Lock>((int)lhs|(int)rhs);
289 }
290
291 //! This operator allows the masking of RendDesc::Lock flags using the '&' operator
292 /*!     \see RendDesc::Lock, RendDesc */
293 inline RendDesc::Lock operator&(RendDesc::Lock lhs, RendDesc::Lock rhs)
294 {
295         return static_cast<RendDesc::Lock>((int)lhs&(int)rhs);
296 }
297
298 //! This operator allows the inverting of RendDesc::Lock flags using the '~' operator
299 /*!     \see RendDesc::Lock, RendDesc */
300 inline RendDesc::Lock operator~(RendDesc::Lock rhs)
301 {
302         return static_cast<RendDesc::Lock>(~(int)rhs);
303 }
304
305 //! This operator is for checking RendDesc::Lock flags.
306 /*! Don't think of it as "less then or equal to", but think of it
307 **      like an arrow. Is \a rhs inside of \a lhs ?
308 **      \see RendDesc::Lock, RendDesc */
309 inline bool operator<=(RendDesc::Lock lhs, RendDesc::Lock rhs)
310 {
311         return static_cast<int>(lhs) & static_cast<int>(rhs)==static_cast<int>(rhs);
312 }
313
314
315 }; /* end namespace synfig */
316
317 /* === E N D =============================================================== */
318
319 #endif