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