1 /* === S Y N F I G ========================================================= */
2 /*! \file renderer_canvas.cpp
3 ** \brief Template File
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 ** Copyright (c) 2007, 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 ======================================================= */
33 #include "renderer_canvas.h"
41 /* === U S I N G =========================================================== */
45 using namespace synfig;
46 using namespace studio;
48 /* === M A C R O S ========================================================= */
50 /* === G L O B A L S ======================================================= */
52 /* === P R O C E D U R E S ================================================= */
54 /* === M E T H O D S ======================================================= */
56 Renderer_Canvas::~Renderer_Canvas()
59 std::vector< std::pair<Glib::RefPtr<Gdk::Pixbuf>,int> >&
60 Renderer_Canvas::get_tile_book()
62 return get_work_area()->get_tile_book();
66 Renderer_Canvas::get_full_frame()const
68 return get_work_area()->get_full_frame();
71 int Renderer_Canvas::get_refreshes()const
73 return get_work_area()->get_refreshes();
77 Renderer_Canvas::get_canceled()const
79 return get_work_area()->get_canceled();
83 Renderer_Canvas::get_queued()const
85 return get_work_area()->get_queued();
89 Renderer_Canvas::get_rendering()const
91 return get_work_area()->get_rendering();
95 Renderer_Canvas::render_vfunc(
96 const Glib::RefPtr<Gdk::Drawable>& drawable,
97 const Gdk::Rectangle& /*expose_area*/
100 assert(get_work_area());
104 // const synfig::RendDesc &rend_desc(get_work_area()->get_canvas()->rend_desc());
106 const synfig::Vector focus_point(get_work_area()->get_focus_point());
108 std::vector< std::pair<Glib::RefPtr<Gdk::Pixbuf>,int> >& tile_book(get_tile_book());
110 int drawable_w,drawable_h;
111 drawable->get_size(drawable_w,drawable_h);
113 // Calculate the window coordinates of the top-left
114 // corner of the canvas.
115 const synfig::Vector::value_type
116 x(focus_point[0]/get_pw()+drawable_w/2-get_w()/2),
117 y(focus_point[1]/get_ph()+drawable_h/2-get_h()/2);
119 /*const synfig::Vector::value_type window_startx(window_tl[0]);
120 const synfig::Vector::value_type window_endx(window_br[0]);
121 const synfig::Vector::value_type window_starty(window_tl[1]);
122 const synfig::Vector::value_type window_endy(window_br[1]);
125 tile_w(get_work_area()->get_tile_w()),
126 tile_h(get_work_area()->get_tile_h());
132 Glib::RefPtr<Gdk::GC> gc(Gdk::GC::create(drawable));
134 if(!tile_book.empty())
138 if(tile_book[0].first)
140 drawable->draw_pixbuf(
142 tile_book[0].first, //pixbuf
143 0, 0, // Source X and Y
144 round_to_int(x),round_to_int(y), // Dest X and Y
145 -1,-1, // Width and Height
146 Gdk::RGB_DITHER_MAX, // RgbDither
147 2, 2 // Dither offset X and Y
150 if(tile_book[0].second!=get_refreshes() && get_canceled()==false && get_rendering()==false && get_queued()==false)
151 get_work_area()->async_update_preview();
155 int div = get_work_area()->get_low_res_pixel_size();
156 const int width_in_tiles(w/tile_w+(((get_work_area()->get_low_resolution_flag())?((w/div)%(tile_w/div)):(w%tile_w))?1:0));
157 const int height_in_tiles(h/tile_h+(h%tile_h?1:0));
160 int u1(0),v1(0),u2(width_in_tiles), v2(height_in_tiles);
162 bool needs_refresh(false);
166 u2=int((-x+drawable_w)/tile_w+1);
167 v2=int((-y+drawable_h)/tile_h+1);
168 if(u2>width_in_tiles)u2=width_in_tiles;
169 if(v2>height_in_tiles)v2=height_in_tiles;
177 int index=v*width_in_tiles+u;
178 if(int(tile_book.size())>index && tile_book[index].first)
183 drawable->draw_pixbuf(
185 tile_book[index].first, //pixbuf
186 0, 0, // Source X and Y
187 round_to_int(x)+tx,round_to_int(y)+ty, // Dest X and Y
188 -1,-1, // Width and Height
189 Gdk::RGB_DITHER_MAX, // RgbDither
190 2, 2 // Dither offset X and Y
193 if(tile_book[index].second!=get_refreshes())
197 if(needs_refresh==true && get_canceled()==false && get_rendering()==false && get_queued()==false)
199 //queue_render_preview();
200 get_work_area()->async_update_preview();
208 // Draw the border around the rendered region
210 gc->set_rgb_fg_color(Gdk::Color("#000000"));
211 gc->set_line_attributes(1,Gdk::LINE_SOLID,Gdk::CAP_BUTT,Gdk::JOIN_MITER);
212 drawable->draw_rectangle(
215 round_to_int(x),round_to_int(y), // x,y