1 /* === S Y N F I G ========================================================= */
2 /*! \file renderer_grid.cpp
3 ** \brief Template File
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_grid.h"
40 /* === U S I N G =========================================================== */
44 using namespace synfig;
45 using namespace studio;
47 /* === M A C R O S ========================================================= */
49 /* === G L O B A L S ======================================================= */
51 /* === P R O C E D U R E S ================================================= */
53 /* === M E T H O D S ======================================================= */
55 Renderer_Grid::~Renderer_Grid()
60 Renderer_Grid::get_enabled_vfunc()const
62 return get_work_area()->grid_status();
66 Renderer_Grid::get_grid_size()const
68 return get_work_area()->get_grid_size();
72 Renderer_Grid::render_vfunc(
73 const Glib::RefPtr<Gdk::Drawable>& drawable,
74 const Gdk::Rectangle& /*expose_area*/
77 assert(get_work_area());
81 // const synfig::RendDesc &rend_desc(get_work_area()->get_canvas()->rend_desc());
83 const synfig::Vector focus_point(get_work_area()->get_focus_point());
85 // std::vector< std::pair<Glib::RefPtr<Gdk::Pixbuf>,int> >& tile_book(get_tile_book());
87 int drawable_w,drawable_h;
88 drawable->get_size(drawable_w,drawable_h);
90 // Calculate the window coordinates of the top-left
91 // corner of the canvas.
92 // const synfig::Vector::value_type
93 // x(focus_point[0]/get_pw()+drawable_w/2-get_w()/2),
94 // y(focus_point[1]/get_ph()+drawable_h/2-get_h()/2);
96 /*const synfig::Vector::value_type window_startx(window_tl[0]);
97 const synfig::Vector::value_type window_endx(window_br[0]);
98 const synfig::Vector::value_type window_starty(window_tl[1]);
99 const synfig::Vector::value_type window_endy(window_br[1]);
102 // tile_w(get_work_area()->get_tile_w()),
103 // tile_h(get_work_area()->get_tile_h());
109 Glib::RefPtr<Gdk::GC> gc(Gdk::GC::create(drawable));
111 const synfig::Vector grid_size(get_grid_size());
113 const synfig::Vector::value_type window_startx(get_work_area()->get_window_tl()[0]);
114 const synfig::Vector::value_type window_endx(get_work_area()->get_window_br()[0]);
115 const synfig::Vector::value_type window_starty(get_work_area()->get_window_tl()[1]);
116 const synfig::Vector::value_type window_endy(get_work_area()->get_window_br()[1]);
117 const float pw(get_pw()),ph(get_ph());
120 if(grid_size[0]>pw*3.5 && grid_size[1]>ph*3.5)
122 synfig::Vector::value_type x,y;
124 x=floor(window_startx/grid_size[0])*grid_size[0];
125 y=floor(window_starty/grid_size[1])*grid_size[1];
127 gc->set_function(Gdk::COPY);
128 gc->set_rgb_fg_color(Gdk::Color("#9f9f9f"));
129 gc->set_line_attributes(1,Gdk::LINE_ON_OFF_DASH,Gdk::CAP_BUTT,Gdk::JOIN_MITER);
132 for(;x<window_endx;x+=grid_size[0])
134 drawable->draw_line(gc,
135 round_to_int((x-window_startx)/pw),
137 round_to_int((x-window_startx)/pw),
142 for(;x>window_endx;x-=grid_size[0])
144 drawable->draw_line(gc,
145 round_to_int((x-window_startx)/pw),
147 round_to_int((x-window_startx)/pw),
153 for(;y<window_endy;y+=grid_size[1])
155 drawable->draw_line(gc,
157 round_to_int((y-window_starty)/ph),
159 round_to_int((y-window_starty)/ph)
163 for(;y>window_endy;y-=grid_size[1])
165 drawable->draw_line(gc,
167 round_to_int((y-window_starty)/ph),
169 round_to_int((y-window_starty)/ph)