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"
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_Guides::Renderer_Guides():
61 Renderer_Guides::~Renderer_Guides()
66 Renderer_Guides::get_enabled_vfunc()const
68 return get_work_area()->get_show_guides();
72 Renderer_Guides::get_guide_list_x()
74 return get_work_area()->get_guide_list_x();
78 Renderer_Guides::get_guide_list_y()
80 return get_work_area()->get_guide_list_y();
84 Renderer_Guides::event_vfunc(GdkEvent* event)
86 synfig::Point mouse_pos;
87 // float bezier_click_pos;
88 // const float radius((abs(get_pw())+abs(get_ph()))*4);
89 int button_pressed(0);
92 Gdk::ModifierType modifier(Gdk::ModifierType(0));
96 event->any.type==GDK_MOTION_NOTIFY ||
97 event->any.type==GDK_BUTTON_PRESS ||
98 event->any.type==GDK_2BUTTON_PRESS ||
99 event->any.type==GDK_3BUTTON_PRESS ||
100 event->any.type==GDK_BUTTON_RELEASE
104 if(event->any.type==GDK_MOTION_NOTIFY)
106 device=event->motion.device;
107 modifier=Gdk::ModifierType(event->motion.state);
111 device=event->button.device;
112 modifier=Gdk::ModifierType(event->button.state);
115 // Make sure we recognize the device
116 /*if(curr_input_device)
118 if(curr_input_device!=device)
121 curr_input_device=device;
122 signal_input_device_changed()(curr_input_device);
127 //curr_input_device=device;
128 //signal_input_device_changed()(curr_input_device);
131 //assert(curr_input_device);
133 // Calculate the position of the
134 // input device in canvas coordinates
136 if(!event->button.axes)
138 mouse_pos=synfig::Point(screen_to_comp_coords(synfig::Point(event->button.x,event->button.y)));
139 button_pressed=event->button.button;
142 if(isnan(event->button.x) || isnan(event->button.y))
147 double x(event->button.axes[0]);
148 double y(event->button.axes[1]);
149 if(isnan(x) || isnan(y))
152 pressure=event->button.axes[2];
153 //synfig::info("pressure=%f",pressure);
155 pressure/=1.0f-0.04f;
158 assert(!isnan(pressure));
160 mouse_pos=synfig::Point(screen_to_comp_coords(synfig::Point(x,y)));
162 button_pressed=event->button.button;
164 if(button_pressed==1 && pressure<0 && (event->any.type!=GDK_BUTTON_RELEASE && event->any.type!=GDK_BUTTON_PRESS))
169 //if(event->any.type==GDK_BUTTON_PRESS && button_pressed)
170 // synfig::info("Button pressed on input device = %d",event->button.button);
172 //if(event->button.axes[2]>0.1)
180 case GDK_BUTTON_PRESS:
182 case GDK_MOTION_NOTIFY:
184 case GDK_BUTTON_RELEASE:
194 Renderer_Guides::render_vfunc(
195 const Glib::RefPtr<Gdk::Drawable>& drawable,
196 const Gdk::Rectangle& /*expose_area*/
199 assert(get_work_area());
203 // const synfig::RendDesc &rend_desc(get_work_area()->get_canvas()->rend_desc());
205 const synfig::Vector focus_point(get_work_area()->get_focus_point());
207 //std::vector< std::pair<Glib::RefPtr<Gdk::Pixbuf>,int> >& tile_book(get_tile_book());
209 int drawable_w,drawable_h;
210 drawable->get_size(drawable_w,drawable_h);
212 // Calculate the window coordinates of the top-left
213 // corner of the canvas.
214 // const synfig::Vector::value_type
215 // x(focus_point[0]/get_pw()+drawable_w/2-get_w()/2),
216 // y(focus_point[1]/get_ph()+drawable_h/2-get_h()/2);
218 /*const synfig::Vector::value_type window_startx(window_tl[0]);
219 const synfig::Vector::value_type window_endx(window_br[0]);
220 const synfig::Vector::value_type window_starty(window_tl[1]);
221 const synfig::Vector::value_type window_endy(window_br[1]);
224 // tile_w(get_work_area()->get_tile_w()),
225 // tile_h(get_work_area()->get_tile_h());
231 Glib::RefPtr<Gdk::GC> gc(Gdk::GC::create(drawable));
233 //const synfig::Vector grid_size(get_grid_size());
235 const synfig::Vector::value_type window_startx(get_work_area()->get_window_tl()[0]);
236 // const synfig::Vector::value_type window_endx(get_work_area()->get_window_br()[0]);
237 const synfig::Vector::value_type window_starty(get_work_area()->get_window_tl()[1]);
238 // const synfig::Vector::value_type window_endy(get_work_area()->get_window_br()[1]);
239 const float pw(get_pw()),ph(get_ph());
241 // Draw out the guides
243 gc->set_function(Gdk::COPY);
244 gc->set_rgb_fg_color(Gdk::Color("#9f9fff"));
245 gc->set_line_attributes(1,Gdk::LINE_ON_OFF_DASH,Gdk::CAP_BUTT,Gdk::JOIN_MITER);
247 Duckmatic::GuideList::const_iterator iter;
250 for(iter=get_guide_list_x().begin();iter!=get_guide_list_x().end();++iter)
252 const float x((*iter-window_startx)/pw);
254 if(iter==get_work_area()->curr_guide)
255 gc->set_rgb_fg_color(Gdk::Color("#ff6f6f"));
257 gc->set_rgb_fg_color(Gdk::Color("#6f6fff"));
259 drawable->draw_line(gc,
267 for(iter=get_guide_list_y().begin();iter!=get_guide_list_y().end();++iter)
269 const float y((*iter-window_starty)/ph);
271 if(iter==get_work_area()->curr_guide)
272 gc->set_rgb_fg_color(Gdk::Color("#ff6f6f"));
274 gc->set_rgb_fg_color(Gdk::Color("#6f6fff"));
276 drawable->draw_line(gc,