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 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"
39 /* === U S I N G =========================================================== */
43 using namespace synfig;
44 using namespace studio;
46 /* === M A C R O S ========================================================= */
48 /* === G L O B A L S ======================================================= */
50 /* === P R O C E D U R E S ================================================= */
52 /* === M E T H O D S ======================================================= */
54 Renderer_Canvas::~Renderer_Canvas()
57 std::vector< std::pair<Glib::RefPtr<Gdk::Pixbuf>,int> >&
58 Renderer_Canvas::get_tile_book()
60 return get_work_area()->get_tile_book();
64 Renderer_Canvas::get_full_frame()const
66 return get_work_area()->get_full_frame();
69 int Renderer_Canvas::get_refreshes()const
71 return get_work_area()->get_refreshes();
75 Renderer_Canvas::get_canceled()const
77 return get_work_area()->get_canceled();
81 Renderer_Canvas::get_queued()const
83 return get_work_area()->get_queued();
87 Renderer_Canvas::get_rendering()const
89 return get_work_area()->get_rendering();
93 Renderer_Canvas::render_vfunc(
94 const Glib::RefPtr<Gdk::Drawable>& drawable,
95 const Gdk::Rectangle& /*expose_area*/
98 assert(get_work_area());
102 // const synfig::RendDesc &rend_desc(get_work_area()->get_canvas()->rend_desc());
104 const synfig::Vector focus_point(get_work_area()->get_focus_point());
106 std::vector< std::pair<Glib::RefPtr<Gdk::Pixbuf>,int> >& tile_book(get_tile_book());
108 int drawable_w,drawable_h;
109 drawable->get_size(drawable_w,drawable_h);
111 // Calculate the window coordinates of the top-left
112 // corner of the canvas.
113 const synfig::Vector::value_type
114 x(focus_point[0]/get_pw()+drawable_w/2-get_w()/2),
115 y(focus_point[1]/get_ph()+drawable_h/2-get_h()/2);
117 /*const synfig::Vector::value_type window_startx(window_tl[0]);
118 const synfig::Vector::value_type window_endx(window_br[0]);
119 const synfig::Vector::value_type window_starty(window_tl[1]);
120 const synfig::Vector::value_type window_endy(window_br[1]);
123 tile_w(get_work_area()->get_tile_w()),
124 tile_h(get_work_area()->get_tile_h());
130 Glib::RefPtr<Gdk::GC> gc(Gdk::GC::create(drawable));
132 if(!tile_book.empty())
135 if(tile_book[0].first)
137 drawable->draw_pixbuf(
139 tile_book[0].first, //pixbuf
140 0, 0, // Source X and Y
141 round_to_int(x),round_to_int(y), // Dest X and Y
142 -1,-1, // Width and Height
143 Gdk::RGB_DITHER_MAX, // RgbDither
144 2, 2 // Dither offset X and Y
147 if(tile_book[0].second!=get_refreshes() && get_canceled()==false && get_rendering()==false && get_queued()==false)
148 get_work_area()->async_update_preview();
152 const int width_in_tiles(w/tile_w+(w%tile_w?1:0));
153 const int height_in_tiles(h/tile_h+(h%tile_h?1:0));
156 int u1(0),v1(0),u2(width_in_tiles), v2(height_in_tiles);
158 bool needs_refresh(false);
162 u2=int((-x+drawable_w)/tile_w+1);
163 v2=int((-y+drawable_h)/tile_h+1);
164 if(u2>width_in_tiles)u2=width_in_tiles;
165 if(v2>height_in_tiles)v2=height_in_tiles;
173 int index=v*width_in_tiles+u;
174 if(int(tile_book.size())>index && tile_book[index].first)
179 drawable->draw_pixbuf(
181 tile_book[index].first, //pixbuf
182 0, 0, // Source X and Y
183 round_to_int(x)+tx,round_to_int(y)+ty, // Dest X and Y
184 -1,-1, // Width and Height
185 Gdk::RGB_DITHER_MAX, // RgbDither
186 2, 2 // Dither offset X and Y
189 if(tile_book[index].second!=get_refreshes())
193 if(needs_refresh==true && get_canceled()==false && get_rendering()==false && get_queued()==false)
195 //queue_render_preview();
196 get_work_area()->async_update_preview();
203 // Draw the border around the rendered region
205 gc->set_rgb_fg_color(Gdk::Color("#000000"));
206 gc->set_line_attributes(1,Gdk::LINE_SOLID,Gdk::CAP_BUTT,Gdk::JOIN_MITER);
207 drawable->draw_rectangle(
210 round_to_int(x),round_to_int(y), // x,y