1 /* === S Y N F I G ========================================================= */
2 /*! \file synfig/renddesc.cpp
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
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.
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.
21 /* ========================================================================= */
23 /* === H E A D E R S ======================================================= */
37 /* === U S I N G =========================================================== */
41 using namespace synfig;
43 /* === M A C R O S ========================================================= */
45 /* === G L O B A L S ======================================================= */
47 /* === M E T H O D S ======================================================= */
50 RendDesc::apply(const RendDesc &x)
57 RendDesc::get_bg_color()const
63 RendDesc::set_bg_color(const Color &bg)
65 background=bg; return *this;
69 RendDesc::get_physical_w()const
71 return (Real)get_w()/get_x_res();
75 RendDesc::get_physical_h()const
77 return (Real)get_h()/get_y_res();
81 RendDesc::set_physical_w(Real w)
83 set_w(round_to_int(w*get_x_res()));
88 RendDesc::set_physical_h(Real h)
90 set_h(round_to_int(h*get_y_res()));
95 RendDesc::get_w()const
101 RendDesc::set_w(int x)
103 if(FLAGS(flags,LINK_PX_ASPECT))
108 else if(FLAGS(flags,LINK_PX_AREA))
113 else if(FLAGS(flags,PX_ASPECT))
116 float old_span=get_span();
118 // If we should preserve image width
119 if( FLAGS(flags,IM_W)
120 || (FLAGS(flags,IM_ZOOMIN) && d[1]>d[1]/x*w_)
121 || (FLAGS(flags,IM_ZOOMOUT) && d[1]<d[1]/x*w_))
141 if(FLAGS(flags,IM_SPAN))
144 else if(FLAGS(flags,PX_AREA))
156 RendDesc::get_h()const
162 RendDesc::set_h(int y)
164 if(FLAGS(flags,LINK_PX_ASPECT))
169 else if(FLAGS(flags,LINK_PX_AREA))
174 else if(FLAGS(flags,PX_ASPECT))
177 float old_span=get_span();
179 // If we should preserve image width
180 if( FLAGS(flags,IM_W)
181 || (FLAGS(flags,IM_ZOOMIN) && d[0]>d[0]/y*h_)
182 || (FLAGS(flags,IM_ZOOMOUT) && d[0]<d[0]/y*h_))
202 if(FLAGS(flags,IM_SPAN))
205 else if(FLAGS(flags,PX_AREA))
217 RendDesc::set_wh(int x, int y)
219 // FIXME: This is a working hack...
227 RendDesc::get_x_res()const
233 RendDesc::set_x_res(Real x)
235 x_res=x; return *this;
239 RendDesc::get_y_res()const
245 RendDesc::set_y_res(Real y)
247 y_res=y; return *this;
251 RendDesc::get_frame_start()const
253 return time_begin*frame_rate;
257 RendDesc::set_frame_start(int x)
259 return set_time_start(Time(x)/frame_rate);
263 RendDesc::get_frame_end()const
265 return time_end*frame_rate;
269 RendDesc::set_frame_end(int x)
271 return set_time_end(Time(x)/frame_rate);
276 RendDesc::get_time_start()const
282 RendDesc::set_time_start(Time x)
285 time_begin=time_end=x;
293 RendDesc::get_time_end()const
299 RendDesc::set_time_end(Time x)
302 time_end=time_begin=x;
309 RendDesc::set_time(Time x)
311 time_end=time_begin=x;
316 RendDesc::set_frame(int x)
318 return set_time(Time(x)/frame_rate);
322 RendDesc::get_frame_rate()const
328 RendDesc::set_frame_rate(float x)
335 RendDesc::get_interlaced()const
341 RendDesc::set_interlaced(bool x)
342 { interlaced=x; return *this; }
344 //! Return the status of the clamp flag
346 RendDesc::get_clamp()const
349 //! Set the clamp flag
351 RendDesc::set_clamp(bool x)
352 { clamp=x; return *this; }
354 //! Set constraint flags
356 RendDesc::set_flags(const int &x)
357 { flags=x; return *this; }
359 //! Clear constraint flags
361 RendDesc::clear_flags()
362 { flags=0; return *this; }
365 RendDesc::get_flags()const
369 //! Return the aspect ratio of a single pixel
371 RendDesc::get_pixel_aspect()const
382 //! Return the aspect ratio of the entire image
384 RendDesc::get_image_aspect()const
394 //! Return the antialias amount
396 RendDesc::get_antialias()const
399 //! Set the antilaias amount
401 RendDesc::set_antialias(const int &x)
402 { a=x; return *this; }
405 //! Return the distance from the bottom-right to the top-left
407 RendDesc::get_span()const
409 return (br_-tl_).mag();
412 //! Set the span distance
414 RendDesc::set_span(const Real &x)
416 Vector::value_type ratio=x/get_span();
418 if(!FLAGS(flags,IM_W|IM_H) || FLAGS(flags,IM_ASPECT))
427 else if(FLAGS(flags,IM_W))
429 //! \writeme or fix me
438 //! \writeme or fix me
453 RendDesc::get_gamma()const
457 RendDesc::set_gamma(const Gamma &x)
458 { gamma=x; return *this; }
462 RendDesc::get_focus()const
466 RendDesc::set_focus(const Point &x)
467 { focus=x; return *this; }
471 RendDesc::get_tl()const
475 RendDesc::get_br()const
479 RendDesc::set_tl(const Point &x)
481 if(FLAGS(flags,PX_ASPECT))
483 Vector new_size(x-br_);
484 new_size[0]=abs(new_size[0]);
485 new_size[1]=abs(new_size[1]);
487 Vector old_size(tl_-br_);
488 old_size[0]=abs(old_size[0]);
489 old_size[1]=abs(old_size[1]);
491 if(new_size[0]!=old_size[0])
492 w_=round_to_int(new_size[0]*w_/old_size[0]);
494 if(new_size[1]!=old_size[1])
495 h_=round_to_int(new_size[1]*h_/old_size[1]);
502 RendDesc::set_br(const Point &x)
504 if(FLAGS(flags,PX_ASPECT))
506 Vector new_size(x-tl_);
507 new_size[0]=abs(new_size[0]);
508 new_size[1]=abs(new_size[1]);
510 Vector old_size(tl_-br_);
511 old_size[0]=abs(old_size[0]);
512 old_size[1]=abs(old_size[1]);
514 if(new_size[0]!=old_size[0])
515 w_=round_to_int(new_size[0]*w_/old_size[0]);
517 if(new_size[1]!=old_size[1])
518 h_=round_to_int(new_size[1]*h_/old_size[1]);
524 RendDesc::set_viewport(const Point &__tl, const Point &__br)
525 { tl_=__tl; br_=__br; return *this; }
528 RendDesc::set_viewport(Real a,Real b,Real c,Real d)
529 { tl_=Point(a,b); br_=Point(c,d); return *this; }
532 RendDesc::get_pw()const
534 return (br_[0] - tl_[0]) / w_;
538 RendDesc::get_ph()const
540 return (br_[1] - tl_[1]) / h_;
544 RendDesc::set_subwindow(int x, int y, int w, int h)
546 const Real pw(get_pw());
547 const Real ph(get_ph());
552 br_[0]-=pw*(w_-(x+w));
553 br_[1]-=ph*(h_-(y+h));