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