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
11 ** This package is free software; you can redistribute it and/or
12 ** modify it under the terms of the GNU General Public License as
13 ** published by the Free Software Foundation; either version 2 of
14 ** the License, or (at your option) any later version.
16 ** This package is distributed in the hope that it will be useful,
17 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 ** General Public License for more details.
22 /* ========================================================================= */
24 /* === H E A D E R S ======================================================= */
33 #include "renderer_ducks.h"
35 #include "duckmatic.h"
38 #include "widget_color.h"
39 #include <synfig/distance.h>
46 /* === U S I N G =========================================================== */
50 using namespace synfig;
51 using namespace studio;
53 /* === M A C R O S ========================================================= */
55 /* === G L O B A L S ======================================================= */
57 /* === P R O C E D U R E S ================================================= */
59 /* === M E T H O D S ======================================================= */
61 Renderer_Ducks::~Renderer_Ducks()
67 Renderer_Ducks::get_enabled_vfunc()const
69 return get_work_area()->grid_status();
81 ScreenDuck():width(0) { }
85 Renderer_Ducks::render_vfunc(
86 const Glib::RefPtr<Gdk::Drawable>& drawable,
87 const Gdk::Rectangle& /*expose_area*/
90 assert(get_work_area());
94 const synfig::Vector focus_point(get_work_area()->get_focus_point());
97 int drawable_w,drawable_h;
98 drawable->get_size(drawable_w,drawable_h);
100 Glib::RefPtr<Gdk::GC> gc(Gdk::GC::create(drawable));
103 const synfig::Vector::value_type window_startx(get_work_area()->get_window_tl()[0]);
104 const synfig::Vector::value_type window_starty(get_work_area()->get_window_tl()[1]);
106 const float pw(get_pw()),ph(get_ph());
108 const std::list<etl::handle<Duckmatic::Bezier> >& bezier_list(get_work_area()->bezier_list());
109 const bool solid_lines(get_work_area()->solid_lines);
111 const std::list<handle<Duckmatic::Stroke> >& stroke_list(get_work_area()->stroke_list());
113 Glib::RefPtr<Pango::Layout> layout(Pango::Layout::create(get_work_area()->get_pango_context()));
115 // Render the strokes
116 for(std::list<handle<Duckmatic::Stroke> >::const_iterator iter=stroke_list.begin();iter!=stroke_list.end();++iter)
118 Point window_start(window_startx,window_starty);
119 vector<Gdk::Point> points;
120 std::list<synfig::Point>::iterator iter2;
123 for(iter2=(*iter)->stroke_data->begin();iter2!=(*iter)->stroke_data->end();++iter2)
125 holder=*iter2-window_start;
126 holder[0]/=pw;holder[1]/=ph;
127 points.push_back(Gdk::Point(round_to_int(holder[0]),round_to_int(holder[1])));
130 gc->set_rgb_fg_color(colorconv_synfig2gdk((*iter)->color));
131 gc->set_function(Gdk::COPY);
132 gc->set_line_attributes(1,Gdk::LINE_SOLID,Gdk::CAP_BUTT,Gdk::JOIN_MITER);
135 drawable->draw_lines(gc, Glib::ArrayHandle<Gdk::Point>(points));
140 // Render the beziers
141 for(std::list<handle<Duckmatic::Bezier> >::const_iterator iter=bezier_list.begin();iter!=bezier_list.end();++iter)
143 Point window_start(window_startx,window_starty);
144 Point p1((*iter)->p1->get_trans_point()-window_start);
145 Point p2((*iter)->p2->get_trans_point()-window_start);
146 Point c1((*iter)->c1->get_trans_point()-window_start);
147 Point c2((*iter)->c2->get_trans_point()-window_start);
152 bezier<Point> curve(p1,c1,c2,p2);
153 vector<Gdk::Point> points;
157 for(f=0;f<1.0;f+=1.0/17.0)
160 points.push_back(Gdk::Point(round_to_int(pt[0]),round_to_int(pt[1])));
162 points.push_back(Gdk::Point(round_to_int(p2[0]),round_to_int(p2[1])));
167 gc->set_rgb_fg_color(DUCK_COLOR_BEZIER_1);
168 gc->set_function(Gdk::COPY);
169 gc->set_line_attributes(3,Gdk::LINE_SOLID,Gdk::CAP_BUTT,Gdk::JOIN_MITER);
170 drawable->draw_lines(gc, Glib::ArrayHandle<Gdk::Point>(points));
171 gc->set_rgb_fg_color(DUCK_COLOR_BEZIER_2);
172 gc->set_line_attributes(1,Gdk::LINE_SOLID,Gdk::CAP_BUTT,Gdk::JOIN_MITER);
173 drawable->draw_lines(gc, Glib::ArrayHandle<Gdk::Point>(points));
178 // gc->set_rgb_fg_color(Gdk::Color("#ffffff"));
179 // gc->set_function(Gdk::INVERT);
180 // gc->set_line_attributes(1,Gdk::LINE_SOLID,Gdk::CAP_BUTT,Gdk::JOIN_MITER);
181 // drawable->draw_lines(gc, Glib::ArrayHandle<Gdk::Point>(points));
182 gc->set_rgb_fg_color(DUCK_COLOR_BEZIER_1);
183 gc->set_function(Gdk::COPY);
184 gc->set_line_attributes(1,Gdk::LINE_SOLID,Gdk::CAP_BUTT,Gdk::JOIN_MITER);
185 drawable->draw_lines(gc, Glib::ArrayHandle<Gdk::Point>(points));
186 gc->set_rgb_fg_color(DUCK_COLOR_BEZIER_2);
187 gc->set_line_attributes(1,Gdk::LINE_ON_OFF_DASH,Gdk::CAP_BUTT,Gdk::JOIN_MITER);
188 drawable->draw_lines(gc, Glib::ArrayHandle<Gdk::Point>(points));
194 const DuckList duck_list(get_work_area()->get_duck_list());
195 //Gtk::StateType state = Gtk::STATE_ACTIVE;
196 Gtk::ShadowType shadow=Gtk::SHADOW_OUT;
197 std::list<ScreenDuck> screen_duck_list;
198 const float radius((abs(pw)+abs(ph))*4);
200 etl::handle<Duck> hover_duck(get_work_area()->find_duck(get_work_area()->get_cursor_pos(),radius, get_work_area()->get_type_mask()));
203 for(std::list<handle<Duck> >::const_iterator iter=duck_list.begin();iter!=duck_list.end();++iter)
206 // If this type of duck has been masked, then skip it
207 if((*iter)->get_type() && (!(get_work_area()->get_type_mask() & (*iter)->get_type())))
211 // Gdk::Rectangle area;
212 Point sub_trans_point((*iter)->get_sub_trans_point());
213 Point sub_trans_origin((*iter)->get_sub_trans_origin());
215 if (App::restrict_radius_ducks &&
216 (*iter)->is_radius())
218 if (sub_trans_point[0] < sub_trans_origin[0])
219 sub_trans_point[0] = sub_trans_origin[0];
220 if (sub_trans_point[1] < sub_trans_origin[1])
221 sub_trans_point[1] = sub_trans_origin[1];
224 Point point((*iter)->get_transform_stack().perform(sub_trans_point));
225 Point origin((*iter)->get_transform_stack().perform(sub_trans_origin));
227 point[0]=(point[0]-window_startx)/pw;
228 point[1]=(point[1]-window_starty)/ph;
230 bool has_connect(false);
231 if((*iter)->get_tangent() || (*iter)->get_type()&Duck::TYPE_ANGLE)
235 if((*iter)->get_connect_duck())
238 origin=(*iter)->get_connect_duck()->get_trans_point();
241 origin[0]=(origin[0]-window_startx)/pw;
242 origin[1]=(origin[1]-window_starty)/ph;
244 bool selected(get_work_area()->duck_is_selected(*iter));
245 bool hover(*iter==hover_duck || (*iter)->get_hover());
247 shadow = selected?Gtk::SHADOW_IN:Gtk::SHADOW_OUT;
249 if(get_work_area()->get_selected_value_node())
251 synfigapp::ValueDesc value_desc((*iter)->get_value_desc());
252 if (value_desc.is_valid() &&
253 ((value_desc.is_value_node() && get_work_area()->get_selected_value_node() == value_desc.get_value_node()) ||
254 (value_desc.parent_is_value_node() && get_work_area()->get_selected_value_node() == value_desc.get_parent_value_node())))
256 gc->set_function(Gdk::COPY);
257 gc->set_rgb_fg_color(DUCK_COLOR_SELECTED);
258 //gc->set_line_attributes(1,Gdk::LINE_ON_OFF_DASH,Gdk::CAP_BUTT,Gdk::JOIN_MITER);
259 gc->set_line_attributes(2,Gdk::LINE_SOLID,Gdk::CAP_BUTT,Gdk::JOIN_MITER);
261 drawable->draw_rectangle(gc,false,
262 round_to_int(point[0]-5),
263 round_to_int(point[1]-5),
271 if((*iter)->get_box_duck())
273 Point boxpoint((*iter)->get_box_duck()->get_trans_point());
274 boxpoint[0]=(boxpoint[0]-window_startx)/pw;
275 boxpoint[1]=(boxpoint[1]-window_starty)/ph;
276 Point tl(min(point[0],boxpoint[0]),min(point[1],boxpoint[1]));
278 gc->set_function(Gdk::COPY);
279 gc->set_rgb_fg_color(DUCK_COLOR_BOX_1);
280 gc->set_line_attributes(1,Gdk::LINE_SOLID,Gdk::CAP_BUTT,Gdk::JOIN_MITER);
281 drawable->draw_rectangle(gc,false,
284 round_to_int(abs(boxpoint[0]-point[0])),
285 round_to_int(abs(boxpoint[1]-point[1]))
287 gc->set_function(Gdk::COPY);
288 gc->set_rgb_fg_color(DUCK_COLOR_BOX_2);
289 gc->set_line_attributes(1,Gdk::LINE_ON_OFF_DASH,Gdk::CAP_BUTT,Gdk::JOIN_MITER);
290 drawable->draw_rectangle(gc,false,
293 round_to_int(abs(boxpoint[0]-point[0])),
294 round_to_int(abs(boxpoint[1]-point[1]))
298 ScreenDuck screen_duck;
299 screen_duck.pos=point;
300 screen_duck.selected=selected;
301 screen_duck.hover=hover;
303 if(!(*iter)->get_editable())
304 screen_duck.color=(DUCK_COLOR_NOT_EDITABLE);
305 else if((*iter)->get_tangent())
306 screen_duck.color=((*iter)->get_scalar()<0 ? DUCK_COLOR_TANGENT_1 : DUCK_COLOR_TANGENT_2);
307 else if((*iter)->get_type()&Duck::TYPE_VERTEX)
308 screen_duck.color=DUCK_COLOR_VERTEX;
309 else if((*iter)->get_type()&Duck::TYPE_RADIUS)
310 screen_duck.color=DUCK_COLOR_RADIUS;
311 else if((*iter)->get_type()&Duck::TYPE_WIDTH)
312 screen_duck.color=DUCK_COLOR_WIDTH;
313 else if((*iter)->get_type()&Duck::TYPE_ANGLE)
314 screen_duck.color=(DUCK_COLOR_ANGLE);
316 screen_duck.color=DUCK_COLOR_OTHER;
318 screen_duck_list.push_front(screen_duck);
324 gc->set_line_attributes(3,Gdk::LINE_SOLID,Gdk::CAP_BUTT,Gdk::JOIN_MITER);
325 gc->set_rgb_fg_color(DUCK_COLOR_CONNECT_OUTSIDE);
326 gc->set_function(Gdk::COPY);
327 drawable->draw_line(gc, (int)origin[0],(int)origin[1],(int)(point[0]),(int)(point[1]));
328 gc->set_line_attributes(1,Gdk::LINE_SOLID,Gdk::CAP_BUTT,Gdk::JOIN_MITER);
329 gc->set_rgb_fg_color(DUCK_COLOR_CONNECT_INSIDE);
330 drawable->draw_line(gc, (int)origin[0],(int)origin[1],(int)(point[0]),(int)(point[1]));
334 // gc->set_rgb_fg_color(Gdk::Color("#ffffff"));
335 // gc->set_function(Gdk::INVERT);
336 // drawable->draw_line(gc, (int)origin[0],(int)origin[1],(int)(point[0]),(int)(point[1]));
337 gc->set_line_attributes(1,Gdk::LINE_SOLID,Gdk::CAP_BUTT,Gdk::JOIN_MITER);
338 gc->set_rgb_fg_color(DUCK_COLOR_CONNECT_OUTSIDE);
339 gc->set_function(Gdk::COPY);
340 drawable->draw_line(gc, (int)origin[0],(int)origin[1],(int)(point[0]),(int)(point[1]));
341 gc->set_line_attributes(1,Gdk::LINE_ON_OFF_DASH,Gdk::CAP_BUTT,Gdk::JOIN_MITER);
342 gc->set_rgb_fg_color(DUCK_COLOR_CONNECT_INSIDE);
343 drawable->draw_line(gc, (int)origin[0],(int)origin[1],(int)(point[0]),(int)(point[1]));
347 if((*iter)->is_radius())
349 const Real mag((point-origin).mag());
350 const int d(round_to_int(mag*2));
351 const int x(round_to_int(origin[0]-mag));
352 const int y(round_to_int(origin[1]-mag));
356 gc->set_rgb_fg_color(Gdk::Color("#000000"));
357 gc->set_function(Gdk::COPY);
358 gc->set_line_attributes(3,Gdk::LINE_SOLID,Gdk::CAP_BUTT,Gdk::JOIN_MITER);
369 gc->set_rgb_fg_color(Gdk::Color("#afafaf"));
373 gc->set_rgb_fg_color(Gdk::Color("#ffffff"));
374 gc->set_function(Gdk::INVERT);
376 gc->set_line_attributes(1,Gdk::LINE_SOLID,Gdk::CAP_BUTT,Gdk::JOIN_MITER);
392 if (App::restrict_radius_ducks)
394 Point sub_trans_point((*iter)->get_sub_trans_point());
395 Point sub_trans_origin((*iter)->get_sub_trans_origin());
397 if (sub_trans_point[0] < sub_trans_origin[0])
398 sub_trans_point[0] = sub_trans_origin[0];
399 if (sub_trans_point[1] < sub_trans_origin[1])
400 sub_trans_point[1] = sub_trans_origin[1];
402 Point point((*iter)->get_transform_stack().perform(sub_trans_point));
403 Point origin((*iter)->get_transform_stack().perform(sub_trans_origin));
405 mag = (point-origin).mag();
408 mag = ((*iter)->get_trans_point()-(*iter)->get_trans_origin()).mag();
410 Distance real_mag(mag, Distance::SYSTEM_UNITS);
411 real_mag.convert(App::distance_system,get_work_area()->get_rend_desc());
412 layout->set_text(real_mag.get_string());
414 gc->set_rgb_fg_color(DUCK_COLOR_WIDTH_TEXT_1);
415 drawable->draw_layout(
417 round_to_int(point[0])+1+6,
418 round_to_int(point[1])+1-8,
421 gc->set_rgb_fg_color(DUCK_COLOR_WIDTH_TEXT_2);
422 drawable->draw_layout(
424 round_to_int(point[0])+6,
425 round_to_int(point[1])-8,
435 for(;screen_duck_list.size();screen_duck_list.pop_front())
439 Gdk::Color color(screen_duck_list.front().color);
441 if(!screen_duck_list.front().selected)
443 color.set_red(color.get_red()*2/3);
444 color.set_green(color.get_green()*2/3);
445 color.set_blue(color.get_blue()*2/3);
448 if(screen_duck_list.front().hover && !screen_duck_list.back().hover && screen_duck_list.size()>1)
450 screen_duck_list.push_back(screen_duck_list.front());
454 if(screen_duck_list.front().hover)
460 gc->set_function(Gdk::COPY);
461 gc->set_line_attributes(1,Gdk::LINE_SOLID,Gdk::CAP_BUTT,Gdk::JOIN_MITER);
462 gc->set_rgb_fg_color(DUCK_COLOR_OUTLINE);
466 round_to_int(screen_duck_list.front().pos[0]-radius),
467 round_to_int(screen_duck_list.front().pos[1]-radius),
475 gc->set_rgb_fg_color(color);
480 round_to_int(screen_duck_list.front().pos[0]-radius+outline),
481 round_to_int(screen_duck_list.front().pos[1]-radius+outline),