1 /* === S Y N F I G ========================================================= */
3 ** \brief Template File
5 ** $Id: renderer_canvas.cpp,v 1.1.1.1 2005/01/07 03:34:36 darco Exp $
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 ======================================================= */
32 #include "renderer_canvas.h"
38 /* === U S I N G =========================================================== */
42 using namespace synfig;
43 using namespace studio;
45 /* === M A C R O S ========================================================= */
47 /* === G L O B A L S ======================================================= */
49 /* === P R O C E D U R E S ================================================= */
51 /* === M E T H O D S ======================================================= */
53 Renderer_Canvas::~Renderer_Canvas()
56 std::vector< std::pair<Glib::RefPtr<Gdk::Pixbuf>,int> >&
57 Renderer_Canvas::get_tile_book()
59 return get_work_area()->get_tile_book();
63 Renderer_Canvas::get_full_frame()const
65 return get_work_area()->get_full_frame();
68 int Renderer_Canvas::get_refreshes()const
70 return get_work_area()->get_refreshes();
74 Renderer_Canvas::get_canceled()const
76 return get_work_area()->get_canceled();
80 Renderer_Canvas::get_queued()const
82 return get_work_area()->get_queued();
86 Renderer_Canvas::get_rendering()const
88 return get_work_area()->get_rendering();
92 Renderer_Canvas::render_vfunc(
93 const Glib::RefPtr<Gdk::Drawable>& drawable,
94 const Gdk::Rectangle& expose_area
97 assert(get_work_area());
101 // const synfig::RendDesc &rend_desc(get_work_area()->get_canvas()->rend_desc());
103 const synfig::Vector focus_point(get_work_area()->get_focus_point());
105 std::vector< std::pair<Glib::RefPtr<Gdk::Pixbuf>,int> >& tile_book(get_tile_book());
107 int drawable_w,drawable_h;
108 drawable->get_size(drawable_w,drawable_h);
110 // Calculate the window coordinates of the top-left
111 // corner of the canvas.
112 const synfig::Vector::value_type
113 x(focus_point[0]/get_pw()+drawable_w/2-get_w()/2),
114 y(focus_point[1]/get_ph()+drawable_h/2-get_h()/2);
116 /*const synfig::Vector::value_type window_startx(window_tl[0]);
117 const synfig::Vector::value_type window_endx(window_br[0]);
118 const synfig::Vector::value_type window_starty(window_tl[1]);
119 const synfig::Vector::value_type window_endy(window_br[1]);
122 tile_w(get_work_area()->get_tile_w()),
123 tile_h(get_work_area()->get_tile_h());
129 Glib::RefPtr<Gdk::GC> gc(Gdk::GC::create(drawable));
131 if(!tile_book.empty())
134 if(tile_book[0].first)
136 drawable->draw_pixbuf(
138 tile_book[0].first, //pixbuf
139 0, 0, // Source X and Y
140 round_to_int(x),round_to_int(y), // Dest X and Y
141 -1,-1, // Width and Height
142 Gdk::RGB_DITHER_MAX, // RgbDither
143 2, 2 // Dither offset X and Y
146 if(tile_book[0].second!=get_refreshes() && get_canceled()==false && get_rendering()==false && get_queued()==false)
147 get_work_area()->async_update_preview();
151 const int width_in_tiles(w/tile_w+(w%tile_w?1:0));
152 const int height_in_tiles(h/tile_h+(h%tile_h?1:0));
155 int u1(0),v1(0),u2(width_in_tiles), v2(height_in_tiles);
157 bool needs_refresh(false);
161 u2=int((-x+drawable_w)/tile_w+1);
162 v2=int((-y+drawable_h)/tile_h+1);
163 if(u2>width_in_tiles)u2=width_in_tiles;
164 if(v2>height_in_tiles)v2=height_in_tiles;
172 int index=v*width_in_tiles+u;
173 if(tile_book.size()>index && tile_book[index].first)
178 drawable->draw_pixbuf(
180 tile_book[index].first, //pixbuf
181 0, 0, // Source X and Y
182 round_to_int(x)+tx,round_to_int(y)+ty, // Dest X and Y
183 -1,-1, // Width and Height
184 Gdk::RGB_DITHER_MAX, // RgbDither
185 2, 2 // Dither offset X and Y
188 if(tile_book[index].second!=get_refreshes())
192 if(needs_refresh==true && get_canceled()==false && get_rendering()==false && get_queued()==false)
194 //queue_render_preview();
195 get_work_area()->async_update_preview();
202 // Draw the border around the rendered region
204 gc->set_rgb_fg_color(Gdk::Color("#000000"));
205 gc->set_line_attributes(1,Gdk::LINE_SOLID,Gdk::CAP_BUTT,Gdk::JOIN_MITER);
206 drawable->draw_rectangle(
209 round_to_int(x),round_to_int(y), // x,y