1 /* === S Y N F I G ========================================================= */
2 /*! \file renderer_guides.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_guides.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_Guides::Renderer_Guides():
59 Renderer_Guides::~Renderer_Guides()
64 Renderer_Guides::get_enabled_vfunc()const
66 return get_work_area()->get_show_guides();
70 Renderer_Guides::get_guide_list_x()
72 return get_work_area()->get_guide_list_x();
76 Renderer_Guides::get_guide_list_y()
78 return get_work_area()->get_guide_list_y();
82 Renderer_Guides::event_vfunc(GdkEvent* event)
84 synfig::Point mouse_pos;
85 // float bezier_click_pos;
86 // const float radius((abs(get_pw())+abs(get_ph()))*4);
87 int button_pressed(0);
90 Gdk::ModifierType modifier(Gdk::ModifierType(0));
94 event->any.type==GDK_MOTION_NOTIFY ||
95 event->any.type==GDK_BUTTON_PRESS ||
96 event->any.type==GDK_2BUTTON_PRESS ||
97 event->any.type==GDK_3BUTTON_PRESS ||
98 event->any.type==GDK_BUTTON_RELEASE
102 if(event->any.type==GDK_MOTION_NOTIFY)
104 device=event->motion.device;
105 modifier=Gdk::ModifierType(event->motion.state);
109 device=event->button.device;
110 modifier=Gdk::ModifierType(event->button.state);
113 // Make sure we recognise the device
114 /*if(curr_input_device)
116 if(curr_input_device!=device)
119 curr_input_device=device;
120 signal_input_device_changed()(curr_input_device);
125 //curr_input_device=device;
126 //signal_input_device_changed()(curr_input_device);
129 //assert(curr_input_device);
131 // Calculate the position of the
132 // input device in canvas coordinates
134 if(!event->button.axes)
136 mouse_pos=synfig::Point(screen_to_comp_coords(synfig::Point(event->button.x,event->button.y)));
137 button_pressed=event->button.button;
140 if(isnan(event->button.x) || isnan(event->button.y))
145 double x(event->button.axes[0]);
146 double y(event->button.axes[1]);
147 if(isnan(x) || isnan(y))
150 pressure=event->button.axes[2];
151 //synfig::info("pressure=%f",pressure);
153 pressure/=1.0f-0.04f;
156 assert(!isnan(pressure));
158 mouse_pos=synfig::Point(screen_to_comp_coords(synfig::Point(x,y)));
160 button_pressed=event->button.button;
162 if(button_pressed==1 && pressure<0 && (event->any.type!=GDK_BUTTON_RELEASE && event->any.type!=GDK_BUTTON_PRESS))
167 //if(event->any.type==GDK_BUTTON_PRESS && button_pressed)
168 // synfig::info("Button pressed on input device = %d",event->button.button);
170 //if(event->button.axes[2]>0.1)
178 case GDK_BUTTON_PRESS:
180 case GDK_MOTION_NOTIFY:
182 case GDK_BUTTON_RELEASE:
192 Renderer_Guides::render_vfunc(
193 const Glib::RefPtr<Gdk::Drawable>& drawable,
194 const Gdk::Rectangle& expose_area
197 assert(get_work_area());
201 // const synfig::RendDesc &rend_desc(get_work_area()->get_canvas()->rend_desc());
203 const synfig::Vector focus_point(get_work_area()->get_focus_point());
205 //std::vector< std::pair<Glib::RefPtr<Gdk::Pixbuf>,int> >& tile_book(get_tile_book());
207 int drawable_w,drawable_h;
208 drawable->get_size(drawable_w,drawable_h);
210 // Calculate the window coordinates of the top-left
211 // corner of the canvas.
212 // const synfig::Vector::value_type
213 // x(focus_point[0]/get_pw()+drawable_w/2-get_w()/2),
214 // y(focus_point[1]/get_ph()+drawable_h/2-get_h()/2);
216 /*const synfig::Vector::value_type window_startx(window_tl[0]);
217 const synfig::Vector::value_type window_endx(window_br[0]);
218 const synfig::Vector::value_type window_starty(window_tl[1]);
219 const synfig::Vector::value_type window_endy(window_br[1]);
222 // tile_w(get_work_area()->get_tile_w()),
223 // tile_h(get_work_area()->get_tile_h());
229 Glib::RefPtr<Gdk::GC> gc(Gdk::GC::create(drawable));
231 //const synfig::Vector grid_size(get_grid_size());
233 const synfig::Vector::value_type window_startx(get_work_area()->get_window_tl()[0]);
234 // const synfig::Vector::value_type window_endx(get_work_area()->get_window_br()[0]);
235 const synfig::Vector::value_type window_starty(get_work_area()->get_window_tl()[1]);
236 // const synfig::Vector::value_type window_endy(get_work_area()->get_window_br()[1]);
237 const float pw(get_pw()),ph(get_ph());
239 // Draw out the guides
241 gc->set_function(Gdk::COPY);
242 gc->set_rgb_fg_color(Gdk::Color("#9f9fff"));
243 gc->set_line_attributes(1,Gdk::LINE_ON_OFF_DASH,Gdk::CAP_BUTT,Gdk::JOIN_MITER);
245 Duckmatic::GuideList::const_iterator iter;
248 for(iter=get_guide_list_x().begin();iter!=get_guide_list_x().end();++iter)
250 const float x((*iter-window_startx)/pw);
252 if(iter==get_work_area()->curr_guide)
253 gc->set_rgb_fg_color(Gdk::Color("#ff6f6f"));
255 gc->set_rgb_fg_color(Gdk::Color("#6f6fff"));
257 drawable->draw_line(gc,
265 for(iter=get_guide_list_y().begin();iter!=get_guide_list_y().end();++iter)
267 const float y((*iter-window_starty)/ph);
269 if(iter==get_work_area()->curr_guide)
270 gc->set_rgb_fg_color(Gdk::Color("#ff6f6f"));
272 gc->set_rgb_fg_color(Gdk::Color("#6f6fff"));
274 drawable->draw_line(gc,