1 /* === S Y N F I G ========================================================= */
2 /*! \file renderer_ducks.cpp
3 ** \brief Template File
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 ** Copyright (c) 2007, 2008 Chris Moore
10 ** Copyright (c) 2008 Gerald Young
12 ** This package is free software; you can redistribute it and/or
13 ** modify it under the terms of the GNU General Public License as
14 ** published by the Free Software Foundation; either version 2 of
15 ** the License, or (at your option) any later version.
17 ** This package is distributed in the hope that it will be useful,
18 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 ** General Public License for more details.
23 /* ========================================================================= */
25 /* === H E A D E R S ======================================================= */
34 #include "renderer_ducks.h"
36 #include "duckmatic.h"
39 #include "widget_color.h"
40 #include <synfig/distance.h>
47 /* === U S I N G =========================================================== */
51 using namespace synfig;
52 using namespace studio;
54 /* === M A C R O S ========================================================= */
56 /* === G L O B A L S ======================================================= */
58 /* === P R O C E D U R E S ================================================= */
60 /* === M E T H O D S ======================================================= */
62 Renderer_Ducks::~Renderer_Ducks()
68 Renderer_Ducks::get_enabled_vfunc()const
70 return get_work_area()->grid_status();
82 ScreenDuck():width(0) { }
86 Renderer_Ducks::render_vfunc(
87 const Glib::RefPtr<Gdk::Drawable>& drawable,
88 const Gdk::Rectangle& /*expose_area*/
91 assert(get_work_area());
95 const synfig::Vector focus_point(get_work_area()->get_focus_point());
98 int drawable_w,drawable_h;
99 drawable->get_size(drawable_w,drawable_h);
101 Glib::RefPtr<Gdk::GC> gc(Gdk::GC::create(drawable));
104 const synfig::Vector::value_type window_startx(get_work_area()->get_window_tl()[0]);
105 const synfig::Vector::value_type window_starty(get_work_area()->get_window_tl()[1]);
107 const float pw(get_pw()),ph(get_ph());
109 const std::list<etl::handle<Duckmatic::Bezier> >& bezier_list(get_work_area()->bezier_list());
110 const bool solid_lines(get_work_area()->solid_lines);
112 const std::list<handle<Duckmatic::Stroke> >& stroke_list(get_work_area()->stroke_list());
114 Glib::RefPtr<Pango::Layout> layout(Pango::Layout::create(get_work_area()->get_pango_context()));
116 // Render the strokes
117 for(std::list<handle<Duckmatic::Stroke> >::const_iterator iter=stroke_list.begin();iter!=stroke_list.end();++iter)
119 Point window_start(window_startx,window_starty);
120 vector<Gdk::Point> points;
121 std::list<synfig::Point>::iterator iter2;
124 for(iter2=(*iter)->stroke_data->begin();iter2!=(*iter)->stroke_data->end();++iter2)
126 holder=*iter2-window_start;
127 holder[0]/=pw;holder[1]/=ph;
128 points.push_back(Gdk::Point(round_to_int(holder[0]),round_to_int(holder[1])));
131 gc->set_rgb_fg_color(colorconv_synfig2gdk((*iter)->color));
132 gc->set_function(Gdk::COPY);
133 gc->set_line_attributes(1,Gdk::LINE_SOLID,Gdk::CAP_BUTT,Gdk::JOIN_MITER);
136 drawable->draw_lines(gc, Glib::ArrayHandle<Gdk::Point>(points));
141 // Render the beziers
142 for(std::list<handle<Duckmatic::Bezier> >::const_iterator iter=bezier_list.begin();iter!=bezier_list.end();++iter)
144 Point window_start(window_startx,window_starty);
145 Point p1((*iter)->p1->get_trans_point()-window_start);
146 Point p2((*iter)->p2->get_trans_point()-window_start);
147 Point c1((*iter)->c1->get_trans_point()-window_start);
148 Point c2((*iter)->c2->get_trans_point()-window_start);
153 bezier<Point> curve(p1,c1,c2,p2);
154 vector<Gdk::Point> points;
158 for(f=0;f<1.0;f+=1.0/17.0)
161 points.push_back(Gdk::Point(round_to_int(pt[0]),round_to_int(pt[1])));
163 points.push_back(Gdk::Point(round_to_int(p2[0]),round_to_int(p2[1])));
168 gc->set_rgb_fg_color(DUCK_COLOR_BEZIER_1);
169 gc->set_function(Gdk::COPY);
170 gc->set_line_attributes(3,Gdk::LINE_SOLID,Gdk::CAP_BUTT,Gdk::JOIN_MITER);
171 drawable->draw_lines(gc, Glib::ArrayHandle<Gdk::Point>(points));
172 gc->set_rgb_fg_color(DUCK_COLOR_BEZIER_2);
173 gc->set_line_attributes(1,Gdk::LINE_SOLID,Gdk::CAP_BUTT,Gdk::JOIN_MITER);
174 drawable->draw_lines(gc, Glib::ArrayHandle<Gdk::Point>(points));
179 // gc->set_rgb_fg_color(Gdk::Color("#ffffff"));
180 // gc->set_function(Gdk::INVERT);
181 // gc->set_line_attributes(1,Gdk::LINE_SOLID,Gdk::CAP_BUTT,Gdk::JOIN_MITER);
182 // drawable->draw_lines(gc, Glib::ArrayHandle<Gdk::Point>(points));
183 gc->set_rgb_fg_color(DUCK_COLOR_BEZIER_1);
184 gc->set_function(Gdk::COPY);
185 gc->set_line_attributes(1,Gdk::LINE_SOLID,Gdk::CAP_BUTT,Gdk::JOIN_MITER);
186 drawable->draw_lines(gc, Glib::ArrayHandle<Gdk::Point>(points));
187 gc->set_rgb_fg_color(DUCK_COLOR_BEZIER_2);
188 gc->set_line_attributes(1,Gdk::LINE_ON_OFF_DASH,Gdk::CAP_BUTT,Gdk::JOIN_MITER);
189 drawable->draw_lines(gc, Glib::ArrayHandle<Gdk::Point>(points));
195 const DuckList duck_list(get_work_area()->get_duck_list());
196 //Gtk::StateType state = Gtk::STATE_ACTIVE;
197 Gtk::ShadowType shadow=Gtk::SHADOW_OUT;
198 std::list<ScreenDuck> screen_duck_list;
199 const float radius((abs(pw)+abs(ph))*4);
201 etl::handle<Duck> hover_duck(get_work_area()->find_duck(get_work_area()->get_cursor_pos(),radius, get_work_area()->get_type_mask()));
204 for(std::list<handle<Duck> >::const_iterator iter=duck_list.begin();iter!=duck_list.end();++iter)
207 // If this type of duck has been masked, then skip it
208 if((*iter)->get_type() && (!(get_work_area()->get_type_mask() & (*iter)->get_type())))
212 // Gdk::Rectangle area;
213 Point sub_trans_point((*iter)->get_sub_trans_point());
214 Point sub_trans_origin((*iter)->get_sub_trans_origin());
216 if (App::restrict_radius_ducks &&
217 (*iter)->is_radius())
219 if (sub_trans_point[0] < sub_trans_origin[0])
220 sub_trans_point[0] = sub_trans_origin[0];
221 if (sub_trans_point[1] < sub_trans_origin[1])
222 sub_trans_point[1] = sub_trans_origin[1];
225 Point point((*iter)->get_transform_stack().perform(sub_trans_point));
226 Point origin((*iter)->get_transform_stack().perform(sub_trans_origin));
228 point[0]=(point[0]-window_startx)/pw;
229 point[1]=(point[1]-window_starty)/ph;
231 bool has_connect(false);
232 if((*iter)->get_tangent() || (*iter)->get_type()&Duck::TYPE_ANGLE)
236 if((*iter)->get_connect_duck())
239 origin=(*iter)->get_connect_duck()->get_trans_point();
242 origin[0]=(origin[0]-window_startx)/pw;
243 origin[1]=(origin[1]-window_starty)/ph;
245 bool selected(get_work_area()->duck_is_selected(*iter));
246 bool hover(*iter==hover_duck || (*iter)->get_hover());
248 shadow = selected?Gtk::SHADOW_IN:Gtk::SHADOW_OUT;
250 if(get_work_area()->get_selected_value_node())
252 synfigapp::ValueDesc value_desc((*iter)->get_value_desc());
253 if (value_desc.is_valid() &&
254 ((value_desc.is_value_node() && get_work_area()->get_selected_value_node() == value_desc.get_value_node()) ||
255 (value_desc.parent_is_value_node() && get_work_area()->get_selected_value_node() == value_desc.get_parent_value_node())))
257 gc->set_function(Gdk::COPY);
258 gc->set_rgb_fg_color(DUCK_COLOR_SELECTED);
259 //gc->set_line_attributes(1,Gdk::LINE_ON_OFF_DASH,Gdk::CAP_BUTT,Gdk::JOIN_MITER);
260 gc->set_line_attributes(2,Gdk::LINE_SOLID,Gdk::CAP_BUTT,Gdk::JOIN_MITER);
262 drawable->draw_rectangle(gc,false,
263 round_to_int(point[0]-5),
264 round_to_int(point[1]-5),
272 if((*iter)->get_box_duck())
274 Point boxpoint((*iter)->get_box_duck()->get_trans_point());
275 boxpoint[0]=(boxpoint[0]-window_startx)/pw;
276 boxpoint[1]=(boxpoint[1]-window_starty)/ph;
277 Point tl(min(point[0],boxpoint[0]),min(point[1],boxpoint[1]));
279 gc->set_function(Gdk::COPY);
280 gc->set_rgb_fg_color(DUCK_COLOR_BOX_1);
281 gc->set_line_attributes(1,Gdk::LINE_SOLID,Gdk::CAP_BUTT,Gdk::JOIN_MITER);
282 drawable->draw_rectangle(gc,false,
285 round_to_int(abs(boxpoint[0]-point[0])),
286 round_to_int(abs(boxpoint[1]-point[1]))
288 gc->set_function(Gdk::COPY);
289 gc->set_rgb_fg_color(DUCK_COLOR_BOX_2);
290 gc->set_line_attributes(1,Gdk::LINE_ON_OFF_DASH,Gdk::CAP_BUTT,Gdk::JOIN_MITER);
291 drawable->draw_rectangle(gc,false,
294 round_to_int(abs(boxpoint[0]-point[0])),
295 round_to_int(abs(boxpoint[1]-point[1]))
299 ScreenDuck screen_duck;
300 screen_duck.pos=point;
301 screen_duck.selected=selected;
302 screen_duck.hover=hover;
304 if(!(*iter)->get_editable())
305 screen_duck.color=(DUCK_COLOR_NOT_EDITABLE);
306 else if((*iter)->get_tangent())
307 screen_duck.color=((*iter)->get_scalar()<0 ? DUCK_COLOR_TANGENT_1 : DUCK_COLOR_TANGENT_2);
308 else if((*iter)->get_type()&Duck::TYPE_VERTEX)
309 screen_duck.color=DUCK_COLOR_VERTEX;
310 else if((*iter)->get_type()&Duck::TYPE_RADIUS)
311 screen_duck.color=DUCK_COLOR_RADIUS;
312 else if((*iter)->get_type()&Duck::TYPE_WIDTH)
313 screen_duck.color=DUCK_COLOR_WIDTH;
314 else if((*iter)->get_type()&Duck::TYPE_ANGLE)
315 screen_duck.color=(DUCK_COLOR_ANGLE);
317 screen_duck.color=DUCK_COLOR_OTHER;
319 screen_duck_list.push_front(screen_duck);
325 gc->set_line_attributes(3,Gdk::LINE_SOLID,Gdk::CAP_BUTT,Gdk::JOIN_MITER);
326 gc->set_rgb_fg_color(DUCK_COLOR_CONNECT_OUTSIDE);
327 gc->set_function(Gdk::COPY);
328 drawable->draw_line(gc, (int)origin[0],(int)origin[1],(int)(point[0]),(int)(point[1]));
329 gc->set_line_attributes(1,Gdk::LINE_SOLID,Gdk::CAP_BUTT,Gdk::JOIN_MITER);
330 gc->set_rgb_fg_color(DUCK_COLOR_CONNECT_INSIDE);
331 drawable->draw_line(gc, (int)origin[0],(int)origin[1],(int)(point[0]),(int)(point[1]));
335 // gc->set_rgb_fg_color(Gdk::Color("#ffffff"));
336 // gc->set_function(Gdk::INVERT);
337 // drawable->draw_line(gc, (int)origin[0],(int)origin[1],(int)(point[0]),(int)(point[1]));
338 gc->set_line_attributes(1,Gdk::LINE_SOLID,Gdk::CAP_BUTT,Gdk::JOIN_MITER);
339 gc->set_rgb_fg_color(DUCK_COLOR_CONNECT_OUTSIDE);
340 gc->set_function(Gdk::COPY);
341 drawable->draw_line(gc, (int)origin[0],(int)origin[1],(int)(point[0]),(int)(point[1]));
342 gc->set_line_attributes(1,Gdk::LINE_ON_OFF_DASH,Gdk::CAP_BUTT,Gdk::JOIN_MITER);
343 gc->set_rgb_fg_color(DUCK_COLOR_CONNECT_INSIDE);
344 drawable->draw_line(gc, (int)origin[0],(int)origin[1],(int)(point[0]),(int)(point[1]));
348 if((*iter)->is_radius())
350 const Real mag((point-origin).mag());
351 const int d(round_to_int(mag*2));
352 const int x(round_to_int(origin[0]-mag));
353 const int y(round_to_int(origin[1]-mag));
357 gc->set_rgb_fg_color(Gdk::Color("#000000"));
358 gc->set_function(Gdk::COPY);
359 gc->set_line_attributes(3,Gdk::LINE_SOLID,Gdk::CAP_BUTT,Gdk::JOIN_MITER);
370 gc->set_rgb_fg_color(Gdk::Color("#afafaf"));
374 gc->set_rgb_fg_color(Gdk::Color("#ffffff"));
375 gc->set_function(Gdk::INVERT);
377 gc->set_line_attributes(1,Gdk::LINE_SOLID,Gdk::CAP_BUTT,Gdk::JOIN_MITER);
393 if (App::restrict_radius_ducks)
395 Point sub_trans_point((*iter)->get_sub_trans_point());
396 Point sub_trans_origin((*iter)->get_sub_trans_origin());
398 if (sub_trans_point[0] < sub_trans_origin[0])
399 sub_trans_point[0] = sub_trans_origin[0];
400 if (sub_trans_point[1] < sub_trans_origin[1])
401 sub_trans_point[1] = sub_trans_origin[1];
403 Point point((*iter)->get_transform_stack().perform(sub_trans_point));
404 Point origin((*iter)->get_transform_stack().perform(sub_trans_origin));
406 mag = (point-origin).mag();
409 mag = ((*iter)->get_trans_point()-(*iter)->get_trans_origin()).mag();
411 Distance real_mag(mag, Distance::SYSTEM_UNITS);
412 real_mag.convert(App::distance_system,get_work_area()->get_rend_desc());
413 layout->set_text(real_mag.get_string());
415 gc->set_rgb_fg_color(DUCK_COLOR_WIDTH_TEXT_1);
416 drawable->draw_layout(
418 round_to_int(point[0])+1+6,
419 round_to_int(point[1])+1-8,
422 gc->set_rgb_fg_color(DUCK_COLOR_WIDTH_TEXT_2);
423 drawable->draw_layout(
425 round_to_int(point[0])+6,
426 round_to_int(point[1])-8,
436 for(;screen_duck_list.size();screen_duck_list.pop_front())
440 Gdk::Color color(screen_duck_list.front().color);
442 if(!screen_duck_list.front().selected)
444 color.set_red(color.get_red()*2/3);
445 color.set_green(color.get_green()*2/3);
446 color.set_blue(color.get_blue()*2/3);
449 if(screen_duck_list.front().hover && !screen_duck_list.back().hover && screen_duck_list.size()>1)
451 screen_duck_list.push_back(screen_duck_list.front());
455 if(screen_duck_list.front().hover)
461 gc->set_function(Gdk::COPY);
462 gc->set_line_attributes(1,Gdk::LINE_SOLID,Gdk::CAP_BUTT,Gdk::JOIN_MITER);
463 gc->set_rgb_fg_color(DUCK_COLOR_OUTLINE);
467 round_to_int(screen_duck_list.front().pos[0]-radius),
468 round_to_int(screen_duck_list.front().pos[1]-radius),
476 gc->set_rgb_fg_color(color);
481 round_to_int(screen_duck_list.front().pos[0]-radius+outline),
482 round_to_int(screen_duck_list.front().pos[1]-radius+outline),