1 /* === S Y N F I G ========================================================= */
2 /*! \file duckmatic.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) 2009 Nikita Kitaev
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 ======================================================= */
37 #include <ETL/hermite>
39 #include "duckmatic.h"
40 #include <synfigapp/value_desc.h>
41 #include <synfigapp/canvasinterface.h>
42 #include <synfig/general.h>
43 #include <synfig/paramdesc.h>
44 #include <synfig/valuenode_timedswap.h>
45 #include <synfig/valuenode_animated.h>
46 #include <synfig/valuenode_composite.h>
47 #include <synfig/valuenode_range.h>
48 #include <synfig/valuenode_scale.h>
49 #include <synfig/valuenode_bline.h>
50 #include <synfig/valuenode_blinecalctangent.h>
51 #include <synfig/valuenode_blinecalcvertex.h>
52 #include <synfig/valuenode_blinecalcwidth.h>
54 #include <synfig/curve_helper.h>
56 #include <sigc++/retype_return.h>
57 #include <sigc++/retype.h>
58 #include <sigc++/hide.h>
59 #include <sigc++/bind.h>
61 #include "canvasview.h"
63 #include "onemoment.h"
69 /* === U S I N G =========================================================== */
73 using namespace synfig;
74 using namespace studio;
76 /* === M A C R O S ========================================================= */
78 /* 0.33333333333333333 makes for nice short tangent handles,
79 1.0 makes them draw as their real length */
80 #define TANGENT_HANDLE_SCALE 0.33333333333333333
82 /* leave this alone or the bezier won't lie on top of the bline */
83 #define TANGENT_BEZIER_SCALE 0.33333333333333333
85 /* === G L O B A L S ======================================================= */
87 /* === P R O C E D U R E S ================================================= */
89 /* === M E T H O D S ======================================================= */
91 /* === E N T R Y P O I N T ================================================= */
93 Duckmatic::Duckmatic(etl::loose_handle<synfigapp::CanvasInterface> canvas_interface):
94 canvas_interface(canvas_interface),
95 type_mask(Duck::TYPE_ALL-Duck::TYPE_WIDTH),
98 grid_size(1.0/4.0,1.0/4.0),
99 show_persistent_strokes(true)
102 drag_offset_=Point(0,0);
103 clear_duck_dragger();
106 Duckmatic::~Duckmatic()
110 if (Duck::duck_count)
111 synfig::error("%d ducks not yet deleted!", Duck::duck_count);
113 if (getenv("SYNFIG_DEBUG_DESTRUCTORS"))
114 synfig::info("Duckmatic::~Duckmatic(): Deleted");
118 Duckmatic::clear_ducks()
120 duck_data_share_map.clear();
123 //duck_list_.clear();
124 bezier_list_.clear();
125 stroke_list_.clear();
127 if(show_persistent_strokes)
128 stroke_list_=persistent_stroke_list_;
133 Duckmatic::duck_is_selected(const etl::handle<Duck> &duck)const
135 return duck && selected_ducks.count(duck->get_guid());
139 Duckmatic::set_grid_size(const synfig::Vector &s)
144 signal_grid_changed();
149 Duckmatic::set_grid_snap(bool x)
154 signal_grid_changed();
159 Duckmatic::set_guide_snap(bool x)
164 signal_grid_changed();
168 Duckmatic::GuideList::iterator
169 Duckmatic::find_guide_x(synfig::Point pos, float radius)
171 GuideList::iterator iter,best(guide_list_x_.end());
173 for(iter=guide_list_x_.begin();iter!=guide_list_x_.end();++iter)
175 float amount(abs(*iter-pos[0]));
185 Duckmatic::GuideList::iterator
186 Duckmatic::find_guide_y(synfig::Point pos, float radius)
188 GuideList::iterator iter,best(guide_list_y_.end());
190 for(iter=guide_list_y_.begin();iter!=guide_list_y_.end();++iter)
192 float amount(abs(*iter-pos[1]));
203 Duckmatic::clear_selected_ducks()
205 selected_ducks.clear();
206 signal_duck_selection_changed_();
209 etl::handle<Duckmatic::Duck>
210 Duckmatic::get_selected_duck()const
212 if(selected_ducks.empty() || duck_map.empty())
214 return duck_map.find(*selected_ducks.begin())->second;
218 Duckmatic::refresh_selected_ducks()
221 std::set<etl::handle<Duck> >::iterator iter;
222 std::set<etl::handle<Duck> > new_set;
223 if(duck_list().empty())
225 selected_duck_list.clear();
226 signal_duck_selection_changed_();
230 for(iter=selected_duck_list.begin();iter!=selected_duck_list.end();++iter)
232 etl::handle<Duck> similar(find_similar_duck(*iter));
235 new_set.insert(similar);
238 selected_duck_list=new_set;
240 GUIDSet old_set(selected_ducks);
241 GUIDSet::const_iterator iter;
243 for(iter=old_set.begin();iter!=old_set.end();++iter)
245 if(duck_map.count(*iter)==0)
246 selected_ducks.erase(*iter);
249 signal_duck_selection_changed_();
253 Duckmatic::is_duck_group_selectable(const etl::handle<Duck>& x)const
255 const Type type(get_type_mask());
257 if (((x->get_type() && (!(type & x->get_type()))) ||
261 synfigapp::ValueDesc value_desc(x->get_value_desc());
262 if(value_desc.parent_is_layer_param() && type & Duck::TYPE_POSITION)
264 Layer::Handle layer(value_desc.get_layer());
265 String layer_name(layer->get_name());
267 if (layer_name == "outline" || layer_name == "region" || layer_name == "plant" ||
268 layer_name == "polygon" || layer_name == "curve_gradient")
271 if((layer_name=="PasteCanvas"|| layer_name=="paste_canvas") &&
272 !layer->get_param("children_lock").get(bool()))
275 else if (value_desc.parent_is_value_node())
277 if (ValueNode_BLineCalcVertex::Handle::cast_dynamic(value_desc.get_value_node()))
279 if (value_desc.parent_is_linkable_value_node())
281 LinkableValueNode::Handle parent_value_node(value_desc.get_parent_value_node());
282 if (ValueNode_Composite::Handle::cast_dynamic(parent_value_node))
284 if (parent_value_node->get_type() == ValueBase::TYPE_BLINEPOINT &&
285 ValueNode_BLineCalcVertex::Handle::cast_dynamic(
286 parent_value_node->get_link("point")))
289 else if (ValueNode_BLine::Handle::cast_dynamic(parent_value_node))
291 ValueNode_Composite::Handle composite(ValueNode_Composite::Handle::cast_dynamic(
292 value_desc.get_value_node()));
294 ValueNode_BLineCalcVertex::Handle::cast_dynamic(composite->get_link("point")))
303 Duckmatic::select_all_ducks()
305 DuckMap::const_iterator iter;
306 for(iter=duck_map.begin();iter!=duck_map.end();++iter)
307 if(is_duck_group_selectable(iter->second))
308 select_duck(iter->second);
310 unselect_duck(iter->second);
314 Duckmatic::unselect_all_ducks()
316 DuckMap::const_iterator iter;
317 for(iter=duck_map.begin();iter!=duck_map.end();++iter)
318 unselect_duck(iter->second);
322 Duckmatic::toggle_select_ducks_in_box(const synfig::Vector& tl,const synfig::Vector& br)
325 vmin[0]=std::min(tl[0],br[0]);
326 vmin[1]=std::min(tl[1],br[1]);
327 vmax[0]=std::max(tl[0],br[0]);
328 vmax[1]=std::max(tl[1],br[1]);
330 DuckMap::const_iterator iter;
331 for(iter=duck_map.begin();iter!=duck_map.end();++iter)
333 Point p(iter->second->get_trans_point());
334 if(p[0]<=vmax[0] && p[0]>=vmin[0] && p[1]<=vmax[1] && p[1]>=vmin[1] &&
335 is_duck_group_selectable(iter->second))
336 toggle_select_duck(iter->second);
341 Duckmatic::select_ducks_in_box(const synfig::Vector& tl,const synfig::Vector& br)
344 vmin[0]=std::min(tl[0],br[0]);
345 vmin[1]=std::min(tl[1],br[1]);
346 vmax[0]=std::max(tl[0],br[0]);
347 vmax[1]=std::max(tl[1],br[1]);
349 // Type type(get_type_mask());
351 DuckMap::const_iterator iter;
352 for(iter=duck_map.begin();iter!=duck_map.end();++iter)
354 Point p(iter->second->get_trans_point());
355 if(p[0]<=vmax[0] && p[0]>=vmin[0] && p[1]<=vmax[1] && p[1]>=vmin[1])
357 if(is_duck_group_selectable(iter->second))
358 select_duck(iter->second);
364 Duckmatic::count_selected_ducks()const
366 return selected_ducks.size();
370 Duckmatic::select_duck(const etl::handle<Duck> &duck)
374 selected_ducks.insert(duck->get_guid());
375 signal_duck_selection_changed_();
380 Duckmatic::get_selected_ducks()const
383 GUIDSet::const_iterator iter;
384 const Type type(get_type_mask());
386 for(iter=selected_ducks.begin();iter!=selected_ducks.end();++iter)
388 const DuckMap::const_iterator d_iter(duck_map.find(*iter));
390 if(d_iter==duck_map.end())
393 if(( d_iter->second->get_type() && (!(type & d_iter->second->get_type())) ) )
396 ret.push_back(d_iter->second);
402 Duckmatic::get_duck_list()const
405 DuckMap::const_iterator iter;
406 for(iter=duck_map.begin();iter!=duck_map.end();++iter) if (iter->second->get_type()&Duck::TYPE_POSITION) ret.push_back(iter->second);
407 for(iter=duck_map.begin();iter!=duck_map.end();++iter) if (iter->second->get_type()&Duck::TYPE_VERTEX ) ret.push_back(iter->second);
408 for(iter=duck_map.begin();iter!=duck_map.end();++iter) if (iter->second->get_type()&Duck::TYPE_TANGENT ) ret.push_back(iter->second);
409 for(iter=duck_map.begin();iter!=duck_map.end();++iter)
410 if (!(iter->second->get_type()&Duck::TYPE_POSITION) &&
411 !(iter->second->get_type()&Duck::TYPE_VERTEX) &&
412 !(iter->second->get_type()&Duck::TYPE_TANGENT))
413 ret.push_back(iter->second);
418 Duckmatic::unselect_duck(const etl::handle<Duck> &duck)
420 if(duck && selected_ducks.count(duck->get_guid()))
422 selected_ducks.erase(duck->get_guid());
423 signal_duck_selection_changed_();
428 Duckmatic::toggle_select_duck(const etl::handle<Duck> &duck)
430 if(duck_is_selected(duck))
437 Duckmatic::translate_selected_ducks(const synfig::Vector& vector)
440 duck_dragger_->duck_drag(this,vector);
444 Duckmatic::start_duck_drag(const synfig::Vector& offset)
447 duck_dragger_->begin_duck_drag(this,offset);
449 //drag_offset_=offset;
450 drag_offset_=find_duck(offset)->get_trans_point();
454 Duckmatic::update_ducks()
456 Time time(get_time());
457 DuckList duck_list(get_duck_list());
458 const DuckList selected_ducks(get_selected_ducks());
459 DuckList::const_iterator iter;
460 for (iter=selected_ducks.begin(); iter!=selected_ducks.end(); ++iter)
462 etl::handle<Duck> duck(*iter);
463 if (duck->get_type() == Duck::TYPE_VERTEX || duck->get_type() == Duck::TYPE_POSITION)
465 ValueNode_BLineCalcVertex::Handle bline_vertex;
466 ValueNode_Composite::Handle composite;
468 if ((bline_vertex = ValueNode_BLineCalcVertex::Handle::cast_dynamic(duck->get_value_desc().get_value_node())) ||
469 ((composite = ValueNode_Composite::Handle::cast_dynamic(duck->get_value_desc().get_value_node())) &&
470 composite->get_type() == ValueBase::TYPE_BLINEPOINT &&
471 (bline_vertex = ValueNode_BLineCalcVertex::Handle::cast_dynamic(composite->get_link("point")))))
473 DuckList::iterator iter;
474 for (iter=duck_list.begin(); iter!=duck_list.end(); iter++)
475 if ( (*iter)->get_origin_duck()==duck /*&& !duck_is_selected(*iter)*/ )
477 synfig::Real radius = 0.0;
478 ValueNode_BLine::Handle bline(ValueNode_BLine::Handle::cast_dynamic(bline_vertex->get_link(bline_vertex->get_link_index_from_name("bline"))));
479 Real amount = synfig::find_closest_point((*bline)(time), duck->get_point(), radius, bline->get_loop());
481 int vertex_amount_index(bline_vertex->get_link_index_from_name("amount"));
482 ValueNode::Handle vertex_amount_value_node(bline_vertex->get_link(vertex_amount_index));
485 ValueNode::Handle duck_value_node((*iter)->get_value_desc().get_value_node());
486 if (ValueNode_BLineCalcTangent::Handle bline_tangent = ValueNode_BLineCalcTangent::Handle::cast_dynamic(duck_value_node))
488 if (bline_tangent->get_link(bline_tangent->get_link_index_from_name("amount")) == vertex_amount_value_node)
490 switch (bline_tangent->get_type())
492 case ValueBase::TYPE_ANGLE:
494 Angle angle((*bline_tangent)(time, amount).get(Angle()));
495 (*iter)->set_point(Point(Angle::cos(angle).get(), Angle::sin(angle).get()));
496 (*iter)->set_rotations(Angle::deg(0)); //hack: rotations are a relative value
499 case ValueBase::TYPE_REAL:
500 (*iter)->set_point(Point((*bline_tangent)(time, amount).get(Real()), 0));
502 case ValueBase::TYPE_VECTOR:
503 (*iter)->set_point((*bline_tangent)(time, amount).get(Vector()));
510 else if (ValueNode_BLineCalcWidth::Handle bline_width = ValueNode_BLineCalcWidth::Handle::cast_dynamic(duck_value_node))
512 if (bline_width->get_link(bline_width->get_link_index_from_name("amount")) == vertex_amount_value_node)
513 (*iter)->set_point(Point((*bline_width)(time, amount).get(Real()), 0));
523 Duckmatic::end_duck_drag()
526 return duck_dragger_->end_duck_drag(this);
531 Duckmatic::snap_point_to_grid(const synfig::Point& x, float radius)const
535 GuideList::const_iterator guide_x,guide_y;
536 bool has_guide_x(false), has_guide_y(false);
538 guide_x=find_guide_x(ret,radius);
539 if(guide_x!=guide_list_x_.end())
542 guide_y=find_guide_y(ret,radius);
543 if(guide_y!=guide_list_y_.end())
549 floor(ret[0]/get_grid_size()[0]+0.5)*get_grid_size()[0],
550 floor(ret[1]/get_grid_size()[1]+0.5)*get_grid_size()[1]);
552 if(abs(snap[0]-ret[0])<=radius && (!has_guide_x || abs(snap[0]-ret[0])<=abs(*guide_x-ret[0])))
553 ret[0]=snap[0],has_guide_x=false;
554 if(abs(snap[1]-ret[1])<=radius && (!has_guide_y || abs(snap[1]-ret[1])<=abs(*guide_y-ret[1])))
555 ret[1]=snap[1],has_guide_y=false;
569 if(abs(ret[0])<abs(ret[1]))
580 DuckDrag_Translate::begin_duck_drag(Duckmatic* duckmatic, const synfig::Vector& offset)
582 last_translate_=Vector(0,0);
584 drag_offset_=duckmatic->find_duck(offset)->get_trans_point();
589 const DuckList selected_ducks(duckmatic->get_selected_ducks());
590 DuckList::const_iterator iter;
593 for(iter=selected_ducks.begin();iter!=selected_ducks.end();++iter)
595 Point p((*iter)->get_trans_point());
596 positions.push_back(p);
601 DuckDrag_Translate::end_duck_drag(Duckmatic* duckmatic)
603 if(last_translate_.mag()>0.0001)
605 duckmatic->signal_edited_selected_ducks();
610 duckmatic->signal_user_click_selected_ducks(0);
616 DuckDrag_Translate::duck_drag(Duckmatic* duckmatic, const synfig::Vector& vector)
618 const DuckList selected_ducks(duckmatic->get_selected_ducks());
619 DuckList::const_iterator iter;
621 synfig::Vector vect(duckmatic->snap_point_to_grid(vector)-drag_offset_);
623 Time time(duckmatic->get_time());
625 // drag the vertex and position ducks first
626 for (i=0,iter=selected_ducks.begin(); iter!=selected_ducks.end(); ++iter,i++)
627 if((*iter)->get_type() == Duck::TYPE_VERTEX || (*iter)->get_type() == Duck::TYPE_POSITION)
628 (*iter)->set_trans_point(positions[i]+vect, time);
630 // then drag the others
631 for (i=0,iter=selected_ducks.begin(); iter!=selected_ducks.end(); ++iter,i++)
632 if ((*iter)->get_type() != Duck::TYPE_VERTEX && (*iter)->get_type() != Duck::TYPE_POSITION)
633 (*iter)->set_trans_point(positions[i]+vect, time);
635 // then patch up the tangents for the vertices we've moved
636 duckmatic->update_ducks();
638 last_translate_=vect;
643 Duckmatic::signal_user_click_selected_ducks(int button)
645 const DuckList ducks(get_selected_ducks());
646 DuckList::const_iterator iter;
648 for(iter=ducks.begin();iter!=ducks.end();++iter)
650 (*iter)->signal_user_click(button)();
656 Duckmatic::signal_edited_selected_ducks()
658 const DuckList ducks(get_selected_ducks());
659 DuckList::const_iterator iter;
661 synfig::GUIDSet old_set(selected_ducks);
663 // If we have more than 20 things to move, then display
664 // something to explain that it may take a moment
665 smart_ptr<OneMoment> wait; if(ducks.size()>20)wait.spawn();
667 // Go ahead and call everyone's signals
668 for(iter=ducks.begin();iter!=ducks.end();++iter)
670 if ((*iter)->get_type() == Duck::TYPE_ANGLE)
672 if(!(*iter)->signal_edited_angle()((*iter)->get_rotations()))
674 selected_ducks=old_set;
675 throw String("Bad edit");
678 else if (App::restrict_radius_ducks &&
679 (*iter)->is_radius())
681 Point point((*iter)->get_point());
682 bool changed = false;
695 if (changed) (*iter)->set_point(point);
697 if(!(*iter)->signal_edited()(point))
699 selected_ducks=old_set;
700 throw String("Bad edit");
705 if(!(*iter)->signal_edited()((*iter)->get_point()))
707 selected_ducks=old_set;
708 throw String("Bad edit");
712 selected_ducks=old_set;
717 Duckmatic::on_duck_changed(const synfig::Point &value,const synfigapp::ValueDesc& value_desc)
719 if (ValueNode_BLineCalcWidth::Handle bline_width = ValueNode_BLineCalcWidth::Handle::cast_dynamic(value_desc.get_value_node()))
721 Real old_width((*bline_width)(get_time()).get(Real()));
722 Real new_width(value.mag());
723 int scale_index(bline_width->get_link_index_from_name("scale"));
724 Real scale((*(bline_width->get_link(scale_index)))(get_time()).get(Real()));
725 return canvas_interface->change_value(synfigapp::ValueDesc(bline_width,scale_index), new_width * scale / old_width);
728 if (ValueNode_BLineCalcVertex::Handle bline_vertex = ValueNode_BLineCalcVertex::Handle::cast_dynamic(value_desc.get_value_node()))
730 ValueNode_BLine::Handle bline = ValueNode_BLine::Handle::cast_dynamic(bline_vertex->get_link("bline"));
732 if (((*(bline_vertex->get_link("loop")))(get_time()).get(bool()))){
733 Real amount_old((*(bline_vertex->get_link("amount")))(get_time()).get(Real()));
734 Real amount_new = synfig::find_closest_point((*bline)(get_time()), value, radius, bline->get_loop());
735 Real difference = fmod( fmod(amount_new - amount_old, 1.0) + 1.0 , 1.0);
736 //fmod is called twice to avoid negative values
737 if (difference > 0.5) difference=difference-1.0;
738 return canvas_interface->change_value(synfigapp::ValueDesc(bline_vertex,bline_vertex->get_link_index_from_name("amount")), amount_old+difference);
741 Real amount = synfig::find_closest_point((*bline)(get_time()), value, radius, bline->get_loop());
742 return canvas_interface->change_value(synfigapp::ValueDesc(bline_vertex,bline_vertex->get_link_index_from_name("amount")), amount);
746 if (ValueNode_BLineCalcTangent::Handle bline_tangent = ValueNode_BLineCalcTangent::Handle::cast_dynamic(value_desc.get_value_node()))
748 switch(value_desc.get_value_type())
750 case ValueBase::TYPE_REAL:
752 Real old_length = (*bline_tangent)(get_time()).get(Real());
753 Real new_length = value.mag();
754 int scale_index(bline_tangent->get_link_index_from_name("scale"));
755 int fixed_length_index(bline_tangent->get_link_index_from_name("fixed_length"));
756 Real scale((*(bline_tangent->get_link(scale_index)))(get_time()).get(Real()));
757 bool fixed_length((*(bline_tangent->get_link(fixed_length_index)))(get_time()).get(bool()));
759 return canvas_interface->change_value(synfigapp::ValueDesc(bline_tangent,scale_index), new_length);
762 return canvas_interface->change_value(synfigapp::ValueDesc(bline_tangent,scale_index), new_length * scale / old_length);
765 case ValueBase::TYPE_ANGLE:
766 assert(0); // doesn't happen?
769 case ValueBase::TYPE_VECTOR:
771 Vector old_tangent = (*bline_tangent)(get_time()).get(Vector());
772 Angle old_angle = old_tangent.angle();
773 Real old_length = old_tangent.mag();
774 Angle new_angle = value.angle();
775 Real new_length = value.mag();
776 int offset_index(bline_tangent->get_link_index_from_name("offset"));
777 int scale_index(bline_tangent->get_link_index_from_name("scale"));
778 int fixed_length_index(bline_tangent->get_link_index_from_name("fixed_length"));
779 Angle old_offset((*(bline_tangent->get_link(offset_index)))(get_time()).get(Angle()));
780 Real scale((*(bline_tangent->get_link(scale_index)))(get_time()).get(Real()));
781 bool fixed_length((*(bline_tangent->get_link(fixed_length_index)))(get_time()).get(bool()));
784 if (!(canvas_interface->change_value(synfigapp::ValueDesc(bline_tangent,scale_index), new_length)))
787 else if (old_length != 0 && !(canvas_interface->change_value(synfigapp::ValueDesc(bline_tangent,scale_index), new_length * scale / old_length)))
789 return canvas_interface->change_value(synfigapp::ValueDesc(bline_tangent,offset_index), old_offset + new_angle - old_angle);
796 if (ValueNode_Scale::Handle scale_value_node = ValueNode_Scale::Handle::cast_dynamic(value_desc.get_value_node()))
798 int link_index(scale_value_node->get_link_index_from_name("link"));
799 if(scale_value_node->is_invertible(get_time()))
800 return canvas_interface->change_value(
801 synfigapp::ValueDesc(scale_value_node,link_index),
802 scale_value_node->get_inverse(get_time(), value)
808 if (ValueNode_Range::Handle range_value_node = ValueNode_Range::Handle::cast_dynamic(value_desc.get_value_node()))
810 int link_index(range_value_node->get_link_index_from_name("link"));
811 return canvas_interface->change_value(
812 synfigapp::ValueDesc(range_value_node,link_index),
813 range_value_node->get_inverse(get_time(), value)
817 switch(value_desc.get_value_type())
819 case ValueBase::TYPE_REAL:
820 return canvas_interface->change_value(value_desc,value.mag());
821 case ValueBase::TYPE_ANGLE:
822 return canvas_interface->change_value(value_desc,Angle::tan(value[1],value[0]));
824 return canvas_interface->change_value(value_desc,value);
829 Duckmatic::on_duck_angle_changed(const synfig::Angle &rotation,const synfigapp::ValueDesc& value_desc)
831 if (ValueNode_BLineCalcTangent::Handle bline_tangent = ValueNode_BLineCalcTangent::Handle::cast_dynamic(value_desc.get_value_node()))
833 int offset_index(bline_tangent->get_link_index_from_name("offset"));
834 Angle old_offset((*(bline_tangent->get_link(offset_index)))(get_time()).get(Angle()));
835 return canvas_interface->change_value(synfigapp::ValueDesc(bline_tangent,offset_index), old_offset + rotation);
838 if (ValueNode_Scale::Handle scale_value_node = ValueNode_Scale::Handle::cast_dynamic(value_desc.get_value_node()))
840 int link_index(scale_value_node->get_link_index_from_name("link"));
841 if(scale_value_node->is_invertible(get_time()))
842 return canvas_interface->change_value(
843 synfigapp::ValueDesc(scale_value_node,link_index),
844 scale_value_node->get_inverse(get_time(), rotation)
850 if (ValueNode_Range::Handle range_value_node = ValueNode_Range::Handle::cast_dynamic(value_desc.get_value_node()))
852 int link_index(range_value_node->get_link_index_from_name("link"));
853 return canvas_interface->change_value(
854 synfigapp::ValueDesc(range_value_node,link_index),
855 range_value_node->get_inverse(get_time(), rotation)
858 // \todo will this really always be the case?
859 assert(value_desc.get_value_type() == ValueBase::TYPE_ANGLE);
860 return canvas_interface->change_value(value_desc, value_desc.get_value(get_time()).get(Angle()) + rotation);
864 Duckmatic::add_duck(const etl::handle<Duck> &duck)
866 //if(!duck_map.count(duck->get_guid()))
868 if(duck_data_share_map.count(duck->get_data_guid()))
870 duck->set_shared_point(duck_data_share_map[duck->get_data_guid()]);
874 etl::smart_ptr<synfig::Point> point(new Point(duck->get_point()));
875 duck->set_shared_point(point);
876 duck_data_share_map[duck->get_data_guid()]=point;
879 duck_map.insert(duck);
882 last_duck_guid=duck->get_guid();
886 Duckmatic::add_bezier(const etl::handle<Bezier> &bezier)
888 bezier_list_.push_back(bezier);
892 Duckmatic::add_stroke(etl::smart_ptr<std::list<synfig::Point> > stroke_point_list, const synfig::Color& color)
894 assert(stroke_point_list);
896 std::list<etl::handle<Stroke> >::iterator iter;
898 for(iter=stroke_list_.begin();iter!=stroke_list_.end();++iter)
900 if((*iter)->stroke_data==stroke_point_list)
904 etl::handle<Stroke> stroke(new Stroke());
906 stroke->stroke_data=stroke_point_list;
909 stroke_list_.push_back(stroke);
913 Duckmatic::add_persistent_stroke(etl::smart_ptr<std::list<synfig::Point> > stroke_point_list, const synfig::Color& color)
915 add_stroke(stroke_point_list,color);
916 persistent_stroke_list_.push_back(stroke_list_.back());
920 Duckmatic::clear_persistent_strokes()
922 persistent_stroke_list_.clear();
926 Duckmatic::set_show_persistent_strokes(bool x)
928 if(x!=show_persistent_strokes)
930 show_persistent_strokes=x;
932 stroke_list_=persistent_stroke_list_;
934 stroke_list_.clear();
939 Duckmatic::erase_duck(const etl::handle<Duck> &duck)
941 duck_map.erase(duck->get_guid());
944 etl::handle<Duckmatic::Duck>
945 Duckmatic::find_similar_duck(etl::handle<Duck> duck)
947 DuckMap::const_iterator iter(duck_map.find(duck->get_guid()));
948 if(iter!=duck_map.end())
952 /* std::list<handle<Duck> >::reverse_iterator iter;
954 for(iter=duck_list_.rbegin();iter!=duck_list_.rend();++iter)
956 if(*iter!=duck && **iter==*duck)
958 //synfig::info("Found similar duck! (iter:%08x vs. duck:%08x)",iter->get(), duck.get());
966 etl::handle<Duckmatic::Duck>
967 Duckmatic::add_similar_duck(etl::handle<Duck> duck)
969 etl::handle<Duck> similar(find_similar_duck(duck));
979 Duckmatic::erase_bezier(const etl::handle<Bezier> &bezier)
981 std::list<handle<Bezier> >::iterator iter;
983 for(iter=bezier_list_.begin();iter!=bezier_list_.end();++iter)
987 bezier_list_.erase(iter);
991 synfig::warning("Unable to find bezier to erase!");
994 etl::handle<Duckmatic::Duck>
995 Duckmatic::last_duck()const
997 DuckMap::const_iterator iter(duck_map.find(last_duck_guid));
998 if(iter!=duck_map.end())
1003 etl::handle<Duckmatic::Bezier>
1004 Duckmatic::last_bezier()const
1006 return bezier_list_.back();
1009 etl::handle<Duckmatic::Duck>
1010 Duckmatic::find_duck(synfig::Point point, synfig::Real radius, Duck::Type type)
1012 if(radius==0)radius=10000000;
1014 if(type==Duck::TYPE_DEFAULT)
1015 type=get_type_mask();
1017 Real closest(10000000);
1018 etl::handle<Duck> ret;
1020 DuckMap::const_iterator iter;
1022 for(iter=duck_map.begin();iter!=duck_map.end();++iter)
1024 const Duck::Handle& duck(iter->second);
1026 if(duck->get_ignore() ||
1027 (duck->get_type() && !(type & duck->get_type())))
1030 Real dist((duck->get_trans_point()-point).mag_squared());
1032 if(duck->get_type()&Duck::TYPE_VERTEX)
1034 else if(duck->get_type()&Duck::TYPE_TANGENT && duck->get_scalar()>0)
1036 else if(duck->get_type()&Duck::TYPE_RADIUS)
1046 if(radius==0 || closest<radius*radius)
1052 etl::handle<Duckmatic::Bezier>
1053 Duckmatic::find_bezier(synfig::Point point, synfig::Real radius,float* location)
1055 return find_bezier(point,radius,radius,location);
1058 etl::handle<Duckmatic::Bezier>
1059 Duckmatic::find_bezier(synfig::Point pos, synfig::Real scale, synfig::Real radius, float* location)
1061 if(radius==0)radius=10000000;
1062 Real closest(10000000);
1063 etl::handle<Bezier> ret;
1065 bezier<Point> curve;
1069 float best_time = 0;
1071 for(std::list<handle<Bezier> >::const_iterator iter=bezier_list().begin();iter!=bezier_list().end();++iter)
1073 curve[0] = (*iter)->p1->get_trans_point();
1074 curve[1] = (*iter)->c1->get_trans_point();
1075 curve[2] = (*iter)->c2->get_trans_point();
1076 curve[3] = (*iter)->p2->get_trans_point();
1080 // I don't know why this doesn't work
1081 time=curve.find_closest(pos,6);
1082 d=((curve(time)-pos).mag_squared());
1085 //set the step size based on the size of the picture
1086 d = (curve[1] - curve[0]).mag() + (curve[2]-curve[1]).mag() + (curve[3]-curve[2]).mag();
1088 step = d/(2*scale); //want to make the distance between lines happy
1090 step = max(step,0.01); //100 samples should be plenty
1091 step = min(step,0.1); //10 is minimum
1093 d = find_closest(curve,pos,step,&closest,&time);
1104 if(closest < radius*radius)
1107 *location = best_time; // We need to square-root this because we were dealing with squared distances
1116 Duckmatic::save_sketch(const synfig::String& filename)const
1118 ChangeLocale change_locale(LC_NUMERIC, "C");
1119 std::ofstream file(filename.c_str());
1121 if(!file)return false;
1123 file<<"SKETCH"<<endl;
1125 std::list<etl::handle<Stroke> >::const_iterator iter;
1127 for(iter=persistent_stroke_list_.begin();iter!=persistent_stroke_list_.end();++iter)
1130 <<(*iter)->color.get_r()<<' '
1131 <<(*iter)->color.get_g()<<' '
1132 <<(*iter)->color.get_b()
1134 std::list<synfig::Point>::const_iterator viter;
1135 for(viter=(*iter)->stroke_data->begin();viter!=(*iter)->stroke_data->end();++viter)
1143 if(!file)return false;
1144 sketch_filename_=filename;
1145 signal_sketch_saved_();
1150 Duckmatic::load_sketch(const synfig::String& filename)
1152 ChangeLocale change_locale(LC_NUMERIC, "C");
1153 std::ifstream file(filename.c_str());
1163 synfig::error("Not a sketch");
1167 etl::smart_ptr<std::list<synfig::Point> > stroke_data;
1181 stroke_data.spawn();
1183 if(!strscanf(line,"C %f %f %f",&r, &g, &b))
1185 synfig::warning("Bad color line \"%s\"",line.c_str());
1188 add_persistent_stroke(stroke_data, synfig::Color(r,g,b));
1195 stroke_data.spawn();
1196 add_persistent_stroke(stroke_data, synfig::Color(0,0,0));
1199 if(!strscanf(line,"V %f %f",&x, &y))
1200 synfig::warning("Bad vertex \"%s\"",line.c_str());
1202 stroke_data->push_back(synfig::Vector(x,y));
1205 synfig::warning("Unexpected sketch token '%c'",line[0]);
1210 sketch_filename_=filename;
1214 Duckmatic::Push::Push(Duckmatic *duckmatic_):
1215 duckmatic_(duckmatic_)
1217 duck_map=duckmatic_->duck_map;
1218 bezier_list_=duckmatic_->bezier_list_;
1219 duck_data_share_map=duckmatic_->duck_data_share_map;
1220 stroke_list_=duckmatic_->stroke_list_;
1221 duck_dragger_=duckmatic_->duck_dragger_;
1225 Duckmatic::Push::~Push()
1232 Duckmatic::Push::restore()
1234 duckmatic_->duck_map=duck_map;
1235 duckmatic_->bezier_list_=bezier_list_;
1236 duckmatic_->duck_data_share_map=duck_data_share_map;
1237 duckmatic_->stroke_list_=stroke_list_;
1238 duckmatic_->duck_dragger_=duck_dragger_;
1239 needs_restore=false;
1242 inline String guid_string(const synfigapp::ValueDesc& x)
1244 if(x.parent_is_layer_param())
1245 return strprintf("%s",x.get_layer()->get_guid().get_string().c_str())+x.get_param_name();
1246 //if(x.is_value_node())
1247 return strprintf("%s",x.get_value_node()->get_guid().get_string().c_str());
1250 inline synfig::GUID calc_duck_guid(const synfigapp::ValueDesc& x,const synfig::TransformStack& transform_stack)
1252 synfig::GUID ret(0);
1254 if(x.parent_is_layer_param())
1256 ret=x.get_layer()->get_guid()^synfig::GUID::hasher(x.get_param_name());
1260 ret=x.get_value_node()->get_guid();
1263 ret^=transform_stack.get_guid();
1269 Duckmatic::create_duck_from(const synfigapp::ValueDesc& value_desc,etl::handle<CanvasView> canvas_view, const synfig::TransformStack& transform_stack, int modifier, synfig::ParamDesc *param_desc)
1271 synfig::GUID duck_guid(calc_duck_guid(value_desc,transform_stack)^synfig::GUID::hasher(modifier));
1272 etl::handle<Duck> duck=new Duck();
1279 Duckmatic::add_to_ducks(const synfigapp::ValueDesc& value_desc,etl::handle<CanvasView> canvas_view, const synfig::TransformStack& transform_stack, synfig::ParamDesc *param_desc, int multiple)
1281 ValueBase::Type type=value_desc.get_value_type();
1282 #define REAL_COOKIE reinterpret_cast<synfig::ParamDesc*>(28)
1285 case ValueBase::TYPE_REAL:
1287 if(!param_desc || param_desc==REAL_COOKIE || !param_desc->get_origin().empty())
1289 etl::handle<Duck> duck=new Duck();
1290 duck->set_transform_stack(transform_stack);
1291 duck->set_radius(true);
1292 duck->set_type(Duck::TYPE_RADIUS);
1294 // put the duck on the right hand side of the center
1295 duck->set_point(Point(value_desc.get_value(get_time()).get(Real()), 0));
1296 duck->set_name(guid_string(value_desc));
1297 if(value_desc.is_value_node())
1299 // If the ValueNode can be directly manipulated,
1300 // then set it as so.
1301 duck->set_editable(synfigapp::is_editable(value_desc.get_value_node()));
1305 duck->set_editable(true);
1308 if(param_desc && param_desc!=REAL_COOKIE)
1310 if(!param_desc->get_origin().empty())
1312 synfigapp::ValueDesc value_desc_origin(value_desc.get_layer(),param_desc->get_origin());
1314 duck->set_origin(value_desc_origin.get_value(get_time()).get(synfig::Point()));
1316 add_to_ducks(value_desc_origin,canvas_view, transform_stack);
1317 duck->set_origin(last_duck());
1319 duck->set_scalar(param_desc->get_scalar());
1322 duck->signal_edited().clear(); // value_desc.get_value_type() == ValueBase::TYPE_REAL:
1323 duck->signal_edited().connect(
1327 &studio::Duckmatic::on_duck_changed),
1329 duck->set_value_desc(value_desc);
1331 duck->signal_user_click(2).connect(
1337 &studio::CanvasView::popup_param_menu),
1342 duck->set_guid(calc_duck_guid(value_desc,transform_stack)^synfig::GUID::hasher(multiple));
1350 case ValueBase::TYPE_ANGLE:
1352 if(!param_desc || param_desc==REAL_COOKIE || !param_desc->get_origin().empty())
1354 etl::handle<Duck> duck=new Duck();
1355 duck->set_type(Duck::TYPE_ANGLE);
1356 duck->set_transform_stack(transform_stack);
1357 synfig::Angle angle;
1359 angle=value_desc.get_value(get_time()).get(Angle());
1360 duck->set_point(Point(Angle::cos(angle).get(),Angle::sin(angle).get()));
1361 duck->set_name(guid_string(value_desc));
1362 if(value_desc.is_value_node())
1364 ValueNode::Handle value_node=value_desc.get_value_node();
1365 //duck->set_name(strprintf("%x",value_node.get()));
1367 // If the ValueNode can be directly manipulated,
1368 // then set it as so.
1369 duck->set_editable(synfigapp::is_editable(value_desc.get_value_node()));
1373 //angle=(value_desc.get_value().get(Angle()));
1374 //duck->set_point(Point(Angle::cos(angle).get(),Angle::sin(angle).get()));
1375 //duck->set_name(strprintf("%x",value_desc.get_layer().get())+value_desc.get_param_name());
1376 duck->set_editable(true);
1379 if(param_desc && param_desc!=REAL_COOKIE)
1381 if(!param_desc->get_origin().empty())
1383 synfigapp::ValueDesc value_desc_origin(value_desc.get_layer(),param_desc->get_origin());
1385 duck->set_origin(value_desc_origin.get_value(get_time()).get(synfig::Point()));
1387 add_to_ducks(value_desc_origin,canvas_view, transform_stack);
1388 duck->set_origin(last_duck());
1390 duck->set_scalar(param_desc->get_scalar());
1393 duck->signal_edited().clear(); // value_desc.get_value_type() == ValueBase::TYPE_ANGLE:
1394 duck->signal_edited_angle().clear();
1395 duck->signal_edited_angle().connect(
1399 &studio::Duckmatic::on_duck_angle_changed),
1401 duck->set_value_desc(value_desc);
1403 duck->signal_user_click(2).connect(
1409 &studio::CanvasView::popup_param_menu),
1413 duck->set_guid(calc_duck_guid(value_desc,transform_stack)^synfig::GUID::hasher(multiple));
1421 case ValueBase::TYPE_VECTOR:
1423 etl::handle<Duck> duck=new Duck();
1424 duck->set_transform_stack(transform_stack);
1426 duck->set_point(value_desc.get_value(get_time()).get(Point()));
1427 duck->set_name(guid_string(value_desc));
1428 if(value_desc.is_value_node())
1430 //duck->set_name(strprintf("%x",value_desc.get_value_node().get()));
1432 // If the ValueNode can be directly manipulated,
1433 // then set it as so.
1434 duck->set_editable(synfigapp::is_editable(value_desc.get_value_node()));
1438 //duck->set_point(value_desc.get_value().get(Point()));
1439 //duck->set_name(strprintf("%x",value_desc.get_layer().get())+value_desc.get_param_name());
1440 duck->set_editable(true);
1443 // If we were passed a parameter description
1446 if(!param_desc->get_connect().empty())
1448 synfigapp::ValueDesc value_desc_origin(value_desc.get_layer(),param_desc->get_connect());
1449 Duck::Handle connect_duck;
1450 if(duck_map.find(calc_duck_guid(value_desc_origin,transform_stack)^synfig::GUID::hasher(0))!=duck_map.end())
1452 connect_duck=duck_map[calc_duck_guid(value_desc_origin,transform_stack)^synfig::GUID::hasher(0)];
1456 add_to_ducks(value_desc_origin,canvas_view, transform_stack);
1457 connect_duck=last_duck();
1459 duck->set_connect_duck(connect_duck);
1461 if(!param_desc->get_box().empty())
1463 synfigapp::ValueDesc value_desc_origin(value_desc.get_layer(),param_desc->get_box());
1464 add_to_ducks(value_desc_origin,canvas_view, transform_stack);
1465 duck->set_box_duck(last_duck());
1468 // If we have an origin
1469 if(!param_desc->get_origin().empty())
1471 synfigapp::ValueDesc value_desc_origin(value_desc.get_layer(),param_desc->get_origin());
1473 duck->set_origin(value_desc_origin.get_value(get_time()).get(synfig::Point()));
1475 add_to_ducks(value_desc_origin,canvas_view, transform_stack);
1476 duck->set_origin(last_duck());
1477 duck->set_type(Duck::TYPE_VERTEX);
1480 duck->set_type(Duck::TYPE_POSITION);
1482 duck->set_scalar(param_desc->get_scalar());
1485 duck->set_type(Duck::TYPE_POSITION);
1487 duck->signal_edited().clear(); // value_desc.get_value_type() == ValueBase::TYPE_VECTOR:
1488 duck->signal_edited().connect(
1492 &studio::Duckmatic::on_duck_changed),
1494 duck->set_value_desc(value_desc);
1496 duck->signal_user_click(2).connect(
1502 &studio::CanvasView::popup_param_menu),
1506 duck->set_guid(calc_duck_guid(value_desc,transform_stack)^synfig::GUID::hasher(multiple));
1512 case ValueBase::TYPE_SEGMENT:
1514 etl::handle<Bezier> bezier(new Bezier());
1515 ValueNode_Composite::Handle value_node;
1517 if(value_desc.is_value_node() &&
1518 (value_node=ValueNode_Composite::Handle::cast_dynamic(value_desc.get_value_node())))
1520 if(!add_to_ducks(synfigapp::ValueDesc(value_node,0),canvas_view,transform_stack))
1522 bezier->p1=last_duck();
1523 bezier->p1->set_type(Duck::TYPE_VERTEX);
1524 if(!add_to_ducks(synfigapp::ValueDesc(value_node,1),canvas_view,transform_stack))
1526 bezier->c1=last_duck();
1527 bezier->c1->set_type(Duck::TYPE_TANGENT);
1528 bezier->c1->set_origin(bezier->p1);
1529 bezier->c1->set_scalar(TANGENT_BEZIER_SCALE);
1530 bezier->c1->set_tangent(true);
1532 if(!add_to_ducks(synfigapp::ValueDesc(value_node,2),canvas_view,transform_stack))
1534 bezier->p2=last_duck();
1535 bezier->p2->set_type(Duck::TYPE_VERTEX);
1536 if(!add_to_ducks(synfigapp::ValueDesc(value_node,3),canvas_view,transform_stack))
1538 bezier->c2=last_duck();
1539 bezier->c2->set_type(Duck::TYPE_TANGENT);
1540 bezier->c2->set_origin(bezier->p2);
1541 bezier->c2->set_scalar(-TANGENT_BEZIER_SCALE);
1542 bezier->c2->set_tangent(true);
1544 bezier->signal_user_click(2).connect(
1548 &studio::CanvasView::popup_param_menu_bezier),
1553 else if(value_desc.get_value().is_valid())
1555 Segment segment=value_desc.get_value();
1556 etl::handle<Duck> duck_p,duck_c;
1557 synfig::String name;
1560 name=param_desc->get_local_name();
1564 name=guid_string(value_desc);
1567 duck_p=new Duck(segment.p1);
1568 duck_p->set_name(name+".P1");
1569 duck_p->set_type(Duck::TYPE_VERTEX);
1572 duck_c=new Duck(segment.t1);
1573 duck_c->set_name(name+".T1");
1574 duck_c->set_type(Duck::TYPE_TANGENT);
1576 duck_c->set_origin(duck_p);
1577 duck_c->set_scalar(TANGENT_HANDLE_SCALE);
1578 duck_c->set_tangent(true);
1583 duck_p=new Duck(segment.p2);
1584 duck_p->set_name(name+".P2");
1585 duck_p->set_type(Duck::TYPE_VERTEX);
1588 duck_c=new Duck(segment.t2);
1589 duck_c->set_type(Duck::TYPE_TANGENT);
1590 duck_c->set_name(name+".T2");
1592 duck_c->set_origin(duck_p);
1593 duck_c->set_scalar(-TANGENT_HANDLE_SCALE);
1594 duck_c->set_tangent(true);
1604 case ValueBase::TYPE_BLINEPOINT:
1607 if(value_desc.is_value_node() &&
1608 ValueNode_Composite::Handle::cast_dynamic(value_desc.get_value_node()))
1610 ValueNode_Composite::Handle value_node;
1611 value_node=ValueNode_Composite::Handle::cast_dynamic(value_desc.get_value_node());
1613 if(!add_to_ducks(synfigapp::ValueDesc(value_node,0),canvas_view,transform_stack))
1615 etl::handle<Duck> vertex_duck(last_duck());
1616 vertex_duck->set_type(Duck::TYPE_VERTEX);
1617 if(!add_to_ducks(synfigapp::ValueDesc(value_node,4),canvas_view,transform_stack))
1619 etl::handle<Duck> t1_duck(last_duck());
1621 t1_duck->set_origin(vertex_duck);
1622 t1_duck->set_scalar(-TANGENT_HANDLE_SCALE);
1623 t1_duck->set_tangent(true);
1625 etl::handle<Duck> t2_duck;
1627 // If the tangents are split
1628 if((*value_node->get_link("split"))(get_time()).get(bool()))
1630 if(!add_to_ducks(synfigapp::ValueDesc(value_node,5),canvas_view,transform_stack))
1632 t2_duck=last_duck();
1633 t2_duck->set_origin(vertex_duck);
1634 t2_duck->set_scalar(TANGENT_HANDLE_SCALE);
1635 t2_duck->set_tangent(true);
1639 if(!add_to_ducks(synfigapp::ValueDesc(value_node,4),canvas_view,transform_stack))
1641 t2_duck=last_duck();
1642 t2_duck->set_origin(vertex_duck);
1643 t2_duck->set_scalar(TANGENT_HANDLE_SCALE);
1644 t2_duck->set_tangent(true);
1651 case ValueBase::TYPE_LIST:
1654 if (value_desc.is_value_node() &&
1655 ValueNode_BLine::Handle::cast_dynamic(value_desc.get_value_node()))
1657 ValueNode_BLine::Handle value_node;
1658 value_node=ValueNode_BLine::Handle::cast_dynamic(value_desc.get_value_node());
1662 etl::handle<Bezier> bezier;
1663 etl::handle<Duck> first_duck;
1664 etl::handle<Duck> duck, tduck;
1666 for (i = 0; i < value_node->link_count(); i++)
1668 float amount(value_node->list[i].amount_at_time(get_time()));
1670 // skip vertices that aren't fully on
1671 if (amount < 0.9999f)
1674 // remember the index of the first vertex we didn't skip
1678 BLinePoint bline_point((*value_node->get_link(i))(get_time()));
1680 // try casting the vertex to Composite - this tells us whether it is composite or not
1681 ValueNode_Composite::Handle composite_vertex_value_node(
1682 ValueNode_Composite::Handle::cast_dynamic(value_node->get_link(i)));
1684 // add the vertex duck - it's a composite
1685 if(composite_vertex_value_node)
1687 if (add_to_ducks(synfigapp::ValueDesc(composite_vertex_value_node,0),canvas_view,transform_stack))
1692 duck->set_type(Duck::TYPE_VERTEX);
1694 duck->signal_user_click(2).clear();
1695 duck->signal_user_click(2).connect(
1701 &studio::CanvasView::popup_param_menu),
1704 synfigapp::ValueDesc(value_node,i)));
1705 duck->set_value_desc(synfigapp::ValueDesc(value_node,i));
1709 if(!param_desc->get_origin().empty())
1711 synfigapp::ValueDesc value_desc_origin(value_desc.get_layer(),param_desc->get_origin());
1712 add_to_ducks(value_desc_origin,canvas_view, transform_stack);
1713 duck->set_origin(last_duck());
1715 ValueBase value(synfigapp::ValueDesc(value_desc.get_layer(),param_desc->get_origin()).get_value(get_time()));
1716 if(value.same_type_as(synfig::Point()))
1717 duck->set_origin(value.get(synfig::Point()));
1725 // else it's not a composite
1728 duck=new Duck(bline_point.get_vertex());
1731 duck->set_transform_stack(transform_stack);
1732 duck->set_editable(false);
1733 //duck->set_name(strprintf("%x-vertex",value_node->get_link(i).get()));
1734 duck->set_name(guid_string(synfigapp::ValueDesc(value_node,i))+".v");
1736 duck->set_type(Duck::TYPE_VERTEX);
1739 if(!param_desc->get_origin().empty())
1741 synfigapp::ValueDesc value_desc_origin(value_desc.get_layer(),param_desc->get_origin());
1742 add_to_ducks(value_desc_origin,canvas_view, transform_stack);
1743 duck->set_origin(last_duck());
1745 ValueBase value(synfigapp::ValueDesc(value_desc.get_layer(),param_desc->get_origin()).get_value(get_time()));
1746 if(value.same_type_as(synfig::Point()))
1747 duck->set_origin(value.get(synfig::Point()));
1751 duck->set_guid(calc_duck_guid(synfigapp::ValueDesc(value_node,i),transform_stack)^synfig::GUID::hasher(".v"));
1752 duck=add_similar_duck(duck);
1756 // Add the width duck if it is a parameter with a hint (ie. "width") or if it isn't a parameter
1757 if ((param_desc && !param_desc->get_hint().empty()) ||
1760 etl::handle<Duck> width;
1761 if (add_to_ducks(synfigapp::ValueDesc(composite_vertex_value_node,1),canvas_view,transform_stack,REAL_COOKIE))
1764 width->set_origin(duck);
1765 width->set_type(Duck::TYPE_WIDTH);
1766 width->set_name(guid_string(synfigapp::ValueDesc(value_node,i))+".w");
1768 // if the bline is a layer's parameter, scale the width duck by the layer's "width" parameter
1771 ValueBase value(synfigapp::ValueDesc(value_desc.get_layer(),param_desc->get_hint()).get_value(get_time()));
1772 if(value.same_type_as(synfig::Real()))
1773 width->set_scalar(value.get(synfig::Real())*0.5f);
1774 // if it doesn't have a "width" parameter, scale by 0.5f instead
1776 width->set_scalar(0.5f);
1778 // otherwise just present the raw unscaled width
1780 width->set_scalar(0.5f);
1783 synfig::error("Unable to add width duck!");
1786 // each bezier uses t2 of one point and t1 of the next
1787 // the first time through this loop we won't have the t2 duck from the previous vertex
1788 // and so we don't make a bezier. instead we skip on to t2 for this point
1791 // Add the tangent1 duck
1792 if(composite_vertex_value_node)
1794 if(!add_to_ducks(synfigapp::ValueDesc(composite_vertex_value_node,4),canvas_view,transform_stack))
1800 tduck=new Duck(bline_point.get_tangent1());
1801 tduck->set_transform_stack(transform_stack);
1802 tduck->set_editable(false);
1803 tduck->set_name(guid_string(synfigapp::ValueDesc(value_node,i))+".t1");
1804 // tduck->set_name(strprintf("%x-tangent1",value_node->get_link(i).get()));
1805 tduck->set_guid(calc_duck_guid(synfigapp::ValueDesc(value_node,i),transform_stack)^synfig::GUID::hasher(".t1"));
1806 tduck=add_similar_duck(tduck);
1810 tduck->set_origin(duck);
1811 tduck->set_scalar(-TANGENT_BEZIER_SCALE);
1812 tduck->set_tangent(true);
1817 bezier->signal_user_click(2).connect(
1821 &studio::CanvasView::popup_param_menu_bezier),
1822 synfigapp::ValueDesc(value_node,i)));
1824 duck->signal_user_click(2).clear();
1825 duck->signal_user_click(2).connect(
1831 &studio::CanvasView::popup_param_menu),
1834 synfigapp::ValueDesc(value_node,i)));
1835 duck->set_value_desc(synfigapp::ValueDesc(value_node,i));
1841 // don't start a new bezier for the last point in the line if we're not looped
1842 if(i+1>=value_node->link_count() && !value_node->get_loop())
1845 bezier=new Bezier();
1847 // Add the tangent2 duck
1848 if(composite_vertex_value_node)
1850 int i=bline_point.get_split_tangent_flag()?5:4;
1851 if(!add_to_ducks(synfigapp::ValueDesc(composite_vertex_value_node,i),canvas_view,transform_stack,0,2))
1857 if(bline_point.get_split_tangent_flag())
1858 tduck=new Duck(bline_point.get_tangent2());
1860 tduck=new Duck(bline_point.get_tangent1());
1862 tduck->set_transform_stack(transform_stack);
1863 tduck->set_name(guid_string(synfigapp::ValueDesc(value_node,i))+".t2");
1864 tduck->set_guid(calc_duck_guid(synfigapp::ValueDesc(value_node,i),transform_stack)^synfig::GUID::hasher(".t2"));
1865 tduck->set_editable(false);
1866 tduck=add_similar_duck(tduck);
1870 synfigapp::ValueDesc value_desc_origin(value_desc.get_layer(),param_desc->get_origin());
1871 add_to_ducks(value_desc_origin,canvas_view, transform_stack);
1872 duck->set_origin(last_duck());
1874 ValueBase value(synfigapp::ValueDesc(value_desc.get_layer(),param_desc->get_origin()).get_value(get_time()));
1875 if(value.same_type_as(synfig::Point()))
1876 duck->set_origin(value.get(synfig::Point()));
1878 // if(!param_desc->get_origin().empty())
1879 // duck->set_origin(synfigapp::ValueDesc(value_desc.get_layer(),param_desc->get_origin()).get_value(get_time()).get(synfig::Point()));
1881 duck->signal_user_click(2).clear();
1882 duck->signal_user_click(2).connect(
1888 &studio::CanvasView::popup_param_menu),
1891 synfigapp::ValueDesc(value_node,i)));
1892 duck->set_value_desc(synfigapp::ValueDesc(value_node,i));
1896 tduck->set_origin(duck);
1897 tduck->set_scalar(TANGENT_BEZIER_SCALE);
1898 tduck->set_tangent(true);
1904 // Loop if necessary
1905 if(bezier && value_node->get_loop())
1907 BLinePoint bline_point((*value_node->get_link(first))(get_time()));
1909 ValueNode_Composite::Handle composite_vertex_value_node(
1910 ValueNode_Composite::Handle::cast_dynamic(
1911 value_node->get_link(first)));
1913 // Add the vertex duck
1916 // Add the tangent1 duck
1917 if(composite_vertex_value_node)
1919 if(!add_to_ducks(synfigapp::ValueDesc(composite_vertex_value_node,4),canvas_view,transform_stack))
1925 tduck=new Duck(bline_point.get_tangent1());
1926 tduck->set_transform_stack(transform_stack);
1927 tduck->set_editable(false);
1928 tduck->set_name(guid_string(synfigapp::ValueDesc(value_node,first))+".t1");
1929 //tduck->set_name(strprintf("%x-tangent1",value_node->get_link(first).get()));
1930 tduck=add_similar_duck(tduck);
1931 tduck->set_guid(calc_duck_guid(synfigapp::ValueDesc(value_node,first),transform_stack)^synfig::GUID::hasher(".t1"));
1935 tduck->set_origin(duck);
1936 tduck->set_scalar(-TANGENT_BEZIER_SCALE);
1937 tduck->set_tangent(true);
1942 bezier->signal_user_click(2).connect(
1946 &studio::CanvasView::popup_param_menu_bezier),
1947 synfigapp::ValueDesc(value_node,first)));
1949 duck->signal_user_click(2).clear();
1950 duck->signal_user_click(2).connect(
1956 &studio::CanvasView::popup_param_menu),
1959 synfigapp::ValueDesc(value_node,first)));
1960 duck->set_value_desc(synfigapp::ValueDesc(value_node,first));
1967 else // Check for DynamicList
1968 if(value_desc.is_value_node() &&
1969 ValueNode_DynamicList::Handle::cast_dynamic(value_desc.get_value_node()))
1971 ValueNode_DynamicList::Handle value_node;
1972 value_node=ValueNode_DynamicList::Handle::cast_dynamic(value_desc.get_value_node());
1975 if(value_node->get_contained_type()==ValueBase::TYPE_VECTOR)
1978 etl::handle<Duck> first_duck, duck;
1980 for(i=0;i<value_node->link_count();i++)
1982 if(!value_node->list[i].status_at_time(get_time()))
1984 if(!add_to_ducks(synfigapp::ValueDesc(value_node,i),canvas_view,transform_stack))
1988 // remember the index of the first vertex we didn't skip
1995 if(param_desc && !param_desc->get_origin().empty())
1997 synfigapp::ValueDesc value_desc_origin(value_desc.get_layer(),param_desc->get_origin());
1998 add_to_ducks(value_desc_origin,canvas_view, transform_stack);
1999 duck->set_origin(last_duck());
2001 ValueBase value(synfigapp::ValueDesc(value_desc.get_layer(),param_desc->get_origin()).get_value(get_time()));
2002 if(value.same_type_as(synfig::Point()))
2003 duck->set_origin(value.get(synfig::Point()));
2005 // if(!param_desc->get_origin().empty())
2006 // last_duck()->set_origin(synfigapp::ValueDesc(value_desc.get_layer(),param_desc->get_origin()).get_value(get_time()).get(synfig::Point()));
2008 duck->set_type(Duck::TYPE_VERTEX);
2009 bezier.p1=bezier.p2;bezier.c1=bezier.c2;
2010 bezier.p2=bezier.c2=duck;
2014 handle<Bezier> bezier_(new Bezier());
2015 bezier_->p1=bezier.p1;
2016 bezier_->c1=bezier.c1;
2017 bezier_->p2=bezier.p2;
2018 bezier_->c2=bezier.c2;
2019 add_bezier(bezier_);
2020 last_bezier()->signal_user_click(2).connect(
2024 &studio::CanvasView::popup_param_menu_bezier),
2025 synfigapp::ValueDesc(value_node,i)));
2029 if (value_node->get_loop() && first != -1 && first_duck != duck)
2033 bezier.p1=bezier.p2;bezier.c1=bezier.c2;
2034 bezier.p2=bezier.c2=duck;
2036 handle<Bezier> bezier_(new Bezier());
2037 bezier_->p1=bezier.p1;
2038 bezier_->c1=bezier.c1;
2039 bezier_->p2=bezier.p2;
2040 bezier_->c2=bezier.c2;
2041 add_bezier(bezier_);
2042 last_bezier()->signal_user_click(2).connect(
2046 &studio::CanvasView::popup_param_menu_bezier),
2047 synfigapp::ValueDesc(value_node,first)));
2050 else if(value_node->get_contained_type()==ValueBase::TYPE_SEGMENT)
2052 for(i=0;i<value_node->link_count();i++)
2054 if(!value_node->list[i].status_at_time(get_time()))
2056 if(!add_to_ducks(synfigapp::ValueDesc(value_node,i),canvas_view,transform_stack))