1 /* === S I N F G =========================================================== */
3 ** \brief Template File
5 ** $Id: renderer_guides.cpp,v 1.1.1.1 2005/01/07 03:34:36 darco Exp $
8 ** Copyright (c) 2002 Robert B. Quattlebaum Jr.
10 ** This software and associated documentation
11 ** are CONFIDENTIAL and PROPRIETARY property of
12 ** the above-mentioned copyright holder.
14 ** You may not copy, print, publish, or in any
15 ** other way distribute this software without
16 ** a prior written agreement with
17 ** the copyright holder.
20 /* ========================================================================= */
22 /* === H E A D E R S ======================================================= */
31 #include "renderer_guides.h"
37 /* === U S I N G =========================================================== */
41 using namespace sinfg;
42 using namespace studio;
44 /* === M A C R O S ========================================================= */
46 /* === G L O B A L S ======================================================= */
48 /* === P R O C E D U R E S ================================================= */
50 /* === M E T H O D S ======================================================= */
52 Renderer_Guides::Renderer_Guides():
58 Renderer_Guides::~Renderer_Guides()
63 Renderer_Guides::get_enabled_vfunc()const
65 return get_work_area()->get_show_guides();
69 Renderer_Guides::get_guide_list_x()
71 return get_work_area()->get_guide_list_x();
75 Renderer_Guides::get_guide_list_y()
77 return get_work_area()->get_guide_list_y();
81 Renderer_Guides::event_vfunc(GdkEvent* event)
83 sinfg::Point mouse_pos;
84 float bezier_click_pos;
85 const float radius((abs(get_pw())+abs(get_ph()))*4);
86 int button_pressed(0);
89 Gdk::ModifierType modifier(Gdk::ModifierType(0));
93 event->any.type==GDK_MOTION_NOTIFY ||
94 event->any.type==GDK_BUTTON_PRESS ||
95 event->any.type==GDK_2BUTTON_PRESS ||
96 event->any.type==GDK_3BUTTON_PRESS ||
97 event->any.type==GDK_BUTTON_RELEASE
101 if(event->any.type==GDK_MOTION_NOTIFY)
103 device=event->motion.device;
104 modifier=Gdk::ModifierType(event->motion.state);
108 device=event->button.device;
109 modifier=Gdk::ModifierType(event->button.state);
112 // Make sure we recognise the device
113 /*if(curr_input_device)
115 if(curr_input_device!=device)
118 curr_input_device=device;
119 signal_input_device_changed()(curr_input_device);
124 //curr_input_device=device;
125 //signal_input_device_changed()(curr_input_device);
128 //assert(curr_input_device);
130 // Calculate the position of the
131 // input device in canvas coordinates
133 if(!event->button.axes)
135 mouse_pos=sinfg::Point(screen_to_comp_coords(sinfg::Point(event->button.x,event->button.y)));
136 button_pressed=event->button.button;
139 if(isnan(event->button.x) || isnan(event->button.y))
144 double x(event->button.axes[0]);
145 double y(event->button.axes[1]);
146 if(isnan(x) || isnan(y))
149 pressure=event->button.axes[2];
150 //sinfg::info("pressure=%f",pressure);
152 pressure/=1.0f-0.04f;
155 assert(!isnan(pressure));
157 mouse_pos=sinfg::Point(screen_to_comp_coords(sinfg::Point(x,y)));
159 button_pressed=event->button.button;
161 if(button_pressed==1 && pressure<0 && (event->any.type!=GDK_BUTTON_RELEASE && event->any.type!=GDK_BUTTON_PRESS))
166 //if(event->any.type==GDK_BUTTON_PRESS && button_pressed)
167 // sinfg::info("Button pressed on input device = %d",event->button.button);
169 //if(event->button.axes[2]>0.1)
177 case GDK_BUTTON_PRESS:
179 case GDK_MOTION_NOTIFY:
181 case GDK_BUTTON_RELEASE:
191 Renderer_Guides::render_vfunc(
192 const Glib::RefPtr<Gdk::Drawable>& drawable,
193 const Gdk::Rectangle& expose_area
196 assert(get_work_area());
200 const sinfg::RendDesc &rend_desc(get_work_area()->get_canvas()->rend_desc());
202 const sinfg::Vector focus_point(get_work_area()->get_focus_point());
204 //std::vector< std::pair<Glib::RefPtr<Gdk::Pixbuf>,int> >& tile_book(get_tile_book());
206 int drawable_w,drawable_h;
207 drawable->get_size(drawable_w,drawable_h);
209 // Calculate the window coordinates of the top-left
210 // corner of the canvas.
211 const sinfg::Vector::value_type
212 x(focus_point[0]/get_pw()+drawable_w/2-get_w()/2),
213 y(focus_point[1]/get_ph()+drawable_h/2-get_h()/2);
215 /*const sinfg::Vector::value_type window_startx(window_tl[0]);
216 const sinfg::Vector::value_type window_endx(window_br[0]);
217 const sinfg::Vector::value_type window_starty(window_tl[1]);
218 const sinfg::Vector::value_type window_endy(window_br[1]);
221 tile_w(get_work_area()->get_tile_w()),
222 tile_h(get_work_area()->get_tile_h());
228 Glib::RefPtr<Gdk::GC> gc(Gdk::GC::create(drawable));
230 //const sinfg::Vector grid_size(get_grid_size());
232 const sinfg::Vector::value_type window_startx(get_work_area()->get_window_tl()[0]);
233 const sinfg::Vector::value_type window_endx(get_work_area()->get_window_br()[0]);
234 const sinfg::Vector::value_type window_starty(get_work_area()->get_window_tl()[1]);
235 const sinfg::Vector::value_type window_endy(get_work_area()->get_window_br()[1]);
236 const float pw(get_pw()),ph(get_ph());
238 // Draw out the guides
240 gc->set_function(Gdk::COPY);
241 gc->set_rgb_fg_color(Gdk::Color("#9f9fff"));
242 gc->set_line_attributes(1,Gdk::LINE_ON_OFF_DASH,Gdk::CAP_BUTT,Gdk::JOIN_MITER);
244 Duckmatic::GuideList::const_iterator iter;
247 for(iter=get_guide_list_x().begin();iter!=get_guide_list_x().end();++iter)
249 const float x((*iter-window_startx)/pw);
251 if(iter==get_work_area()->curr_guide)
252 gc->set_rgb_fg_color(Gdk::Color("#ff6f6f"));
254 gc->set_rgb_fg_color(Gdk::Color("#6f6fff"));
256 drawable->draw_line(gc,
264 for(iter=get_guide_list_y().begin();iter!=get_guide_list_y().end();++iter)
266 const float y((*iter-window_starty)/ph);
268 if(iter==get_work_area()->curr_guide)
269 gc->set_rgb_fg_color(Gdk::Color("#ff6f6f"));
271 gc->set_rgb_fg_color(Gdk::Color("#6f6fff"));
273 drawable->draw_line(gc,