1 /* === S Y N F I G ========================================================= */
2 /*! \file synfig/renddesc.cpp
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 ** Copyright (c) 2008 Chris Moore
11 ** This package is free software; you can redistribute it and/or
12 ** modify it under the terms of the GNU General Public License as
13 ** published by the Free Software Foundation; either version 2 of
14 ** the License, or (at your option) any later version.
16 ** This package is distributed in the hope that it will be useful,
17 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 ** General Public License for more details.
22 /* ========================================================================= */
24 /* === H E A D E R S ======================================================= */
38 /* === U S I N G =========================================================== */
42 using namespace synfig;
44 /* === M A C R O S ========================================================= */
46 /* === G L O B A L S ======================================================= */
48 /* === M E T H O D S ======================================================= */
51 RendDesc::apply(const RendDesc &x)
58 RendDesc::get_bg_color()const
64 RendDesc::set_bg_color(const Color &bg)
66 background=bg; return *this;
70 RendDesc::get_physical_w()const
72 return (Real)get_w()/get_x_res();
76 RendDesc::get_physical_h()const
78 return (Real)get_h()/get_y_res();
82 RendDesc::set_physical_w(Real w)
84 set_w(round_to_int(w*get_x_res()));
89 RendDesc::set_physical_h(Real h)
91 set_h(round_to_int(h*get_y_res()));
96 RendDesc::get_w()const
102 RendDesc::set_w(int x)
104 if(FLAGS(flags,LINK_PX_ASPECT))
109 else if(FLAGS(flags,LINK_PX_AREA))
114 else if(FLAGS(flags,PX_ASPECT))
117 float old_span=get_span();
119 // If we should preserve image width
120 if( FLAGS(flags,IM_W)
121 || (FLAGS(flags,IM_ZOOMIN) && d[1]>d[1]/x*w_)
122 || (FLAGS(flags,IM_ZOOMOUT) && d[1]<d[1]/x*w_))
142 if(FLAGS(flags,IM_SPAN))
145 else if(FLAGS(flags,PX_AREA))
157 RendDesc::get_h()const
163 RendDesc::set_h(int y)
165 if(FLAGS(flags,LINK_PX_ASPECT))
170 else if(FLAGS(flags,LINK_PX_AREA))
175 else if(FLAGS(flags,PX_ASPECT))
178 float old_span=get_span();
180 // If we should preserve image width
181 if( FLAGS(flags,IM_W)
182 || (FLAGS(flags,IM_ZOOMIN) && d[0]>d[0]/y*h_)
183 || (FLAGS(flags,IM_ZOOMOUT) && d[0]<d[0]/y*h_))
203 if(FLAGS(flags,IM_SPAN))
206 else if(FLAGS(flags,PX_AREA))
218 RendDesc::set_wh(int x, int y)
220 // FIXME: This is a working hack...
228 RendDesc::get_x_res()const
234 RendDesc::set_x_res(Real x)
236 x_res=x; return *this;
240 RendDesc::get_y_res()const
246 RendDesc::set_y_res(Real y)
248 y_res=y; return *this;
252 RendDesc::get_frame_start()const
254 return round_to_int(time_begin*frame_rate);
258 RendDesc::set_frame_start(int x)
260 return set_time_start(Time(x)/frame_rate);
264 RendDesc::get_frame_end()const
266 return round_to_int(time_end*frame_rate);
270 RendDesc::set_frame_end(int x)
272 return set_time_end(Time(x)/frame_rate);
277 RendDesc::get_time_start()const
283 RendDesc::set_time_start(Time x)
286 time_begin=time_end=x;
294 RendDesc::get_time_end()const
300 RendDesc::set_time_end(Time x)
303 time_end=time_begin=x;
310 RendDesc::set_time(Time x)
312 time_end=time_begin=x;
317 RendDesc::set_frame(int x)
319 return set_time(Time(x)/frame_rate);
323 RendDesc::get_frame_rate()const
329 RendDesc::set_frame_rate(float x)
336 RendDesc::get_interlaced()const
342 RendDesc::set_interlaced(bool x)
343 { interlaced=x; return *this; }
345 //! Return the status of the clamp flag
347 RendDesc::get_clamp()const
350 //! Set the clamp flag
352 RendDesc::set_clamp(bool x)
353 { clamp=x; return *this; }
355 //! Set constraint flags
357 RendDesc::set_flags(const int &x)
358 { flags=x; return *this; }
360 //! Clear constraint flags
362 RendDesc::clear_flags()
363 { flags=0; return *this; }
366 RendDesc::get_flags()const
370 //! Return the aspect ratio of a single pixel
372 RendDesc::get_pixel_aspect()const
383 //! Return the aspect ratio of the entire image
385 RendDesc::get_image_aspect()const
395 //! Return the antialias amount
397 RendDesc::get_antialias()const
400 //! Set the antialias amount
402 RendDesc::set_antialias(const int &x)
403 { a=x; return *this; }
406 //! Return the distance from the bottom-right to the top-left
408 RendDesc::get_span()const
410 return (br_-tl_).mag();
413 //! Set the span distance
415 RendDesc::set_span(const Real &x)
417 Vector::value_type ratio=x/get_span();
419 if(!FLAGS(flags,IM_W|IM_H) || FLAGS(flags,IM_ASPECT))
428 else if(FLAGS(flags,IM_W))
430 //! \writeme or fix me
439 //! \writeme or fix me
454 RendDesc::get_gamma()const
458 RendDesc::set_gamma(const Gamma &x)
459 { gamma=x; return *this; }
463 RendDesc::get_focus()const
467 RendDesc::set_focus(const Point &x)
468 { focus=x; return *this; }
472 RendDesc::get_tl()const
476 RendDesc::get_br()const
480 RendDesc::set_tl(const Point &x)
482 if(FLAGS(flags,PX_ASPECT))
484 Vector new_size(x-br_);
485 new_size[0]=abs(new_size[0]);
486 new_size[1]=abs(new_size[1]);
488 Vector old_size(tl_-br_);
489 old_size[0]=abs(old_size[0]);
490 old_size[1]=abs(old_size[1]);
492 if(new_size[0]!=old_size[0])
493 w_=round_to_int(new_size[0]*w_/old_size[0]);
495 if(new_size[1]!=old_size[1])
496 h_=round_to_int(new_size[1]*h_/old_size[1]);
503 RendDesc::set_br(const Point &x)
505 if(FLAGS(flags,PX_ASPECT))
507 Vector new_size(x-tl_);
508 new_size[0]=abs(new_size[0]);
509 new_size[1]=abs(new_size[1]);
511 Vector old_size(tl_-br_);
512 old_size[0]=abs(old_size[0]);
513 old_size[1]=abs(old_size[1]);
515 if(new_size[0]!=old_size[0])
516 w_=round_to_int(new_size[0]*w_/old_size[0]);
518 if(new_size[1]!=old_size[1])
519 h_=round_to_int(new_size[1]*h_/old_size[1]);
525 RendDesc::set_viewport(const Point &__tl, const Point &__br)
526 { tl_=__tl; br_=__br; return *this; }
529 RendDesc::set_viewport(Vector::value_type a, Vector::value_type b, Vector::value_type c, Vector::value_type d)
530 { tl_=Point(a,b); br_=Point(c,d); return *this; }
533 RendDesc::get_pw()const
535 return (br_[0] - tl_[0]) / w_;
539 RendDesc::get_ph()const
541 return (br_[1] - tl_[1]) / h_;
545 RendDesc::set_subwindow(int x, int y, int w, int h)
547 const Real pw(get_pw());
548 const Real ph(get_ph());
553 br_[0]-=pw*(w_-(x+w));
554 br_[1]-=ph*(h_-(y+h));