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 <synfig/general.h>
42 #include <synfig/paramdesc.h>
43 #include <synfig/valuenode_timedswap.h>
44 #include <synfig/valuenode_animated.h>
45 #include <synfig/valuenode_composite.h>
46 #include <synfig/valuenode_scale.h>
47 #include <synfig/valuenode_bline.h>
48 #include <synfig/valuenode_blinecalctangent.h>
49 #include <synfig/valuenode_blinecalcvertex.h>
50 #include <synfig/valuenode_blinecalcwidth.h>
52 #include <synfig/curve_helper.h>
54 #include <sigc++/retype_return.h>
55 #include <sigc++/retype.h>
56 #include <sigc++/hide.h>
57 #include <sigc++/bind.h>
59 #include "canvasview.h"
61 #include "onemoment.h"
67 /* === U S I N G =========================================================== */
71 using namespace synfig;
72 using namespace studio;
74 /* === M A C R O S ========================================================= */
76 /* 0.33333333333333333 makes for nice short tangent handles,
77 1.0 makes them draw as their real length */
78 #define TANGENT_HANDLE_SCALE 0.33333333333333333
80 /* leave this alone or the bezier won't lie on top of the bline */
81 #define TANGENT_BEZIER_SCALE 0.33333333333333333
83 /* === G L O B A L S ======================================================= */
85 /* === P R O C E D U R E S ================================================= */
87 /* === M E T H O D S ======================================================= */
89 /* === E N T R Y P O I N T ================================================= */
91 Duckmatic::Duckmatic():
92 type_mask(Duck::TYPE_ALL-Duck::TYPE_WIDTH),
95 grid_size(1.0/4.0,1.0/4.0),
96 show_persistent_strokes(true)
99 drag_offset_=Point(0,0);
100 clear_duck_dragger();
103 Duckmatic::~Duckmatic()
107 if (Duck::duck_count)
108 synfig::error("%d ducks not yet deleted!", Duck::duck_count);
110 if (getenv("SYNFIG_DEBUG_DESTRUCTORS"))
111 synfig::info("Duckmatic::~Duckmatic(): Deleted");
115 Duckmatic::clear_ducks()
117 duck_data_share_map.clear();
120 //duck_list_.clear();
121 bezier_list_.clear();
122 stroke_list_.clear();
124 if(show_persistent_strokes)
125 stroke_list_=persistent_stroke_list_;
128 //! Returns \a true if the given duck is currently selected
130 Duckmatic::duck_is_selected(const etl::handle<Duck> &duck)const
132 return duck && selected_ducks.count(duck->get_guid());
136 Duckmatic::set_grid_size(const synfig::Vector &s)
141 signal_grid_changed();
146 Duckmatic::set_grid_snap(bool x)
151 signal_grid_changed();
156 Duckmatic::set_guide_snap(bool x)
161 signal_grid_changed();
165 Duckmatic::GuideList::iterator
166 Duckmatic::find_guide_x(synfig::Point pos, float radius)
168 GuideList::iterator iter,best(guide_list_x_.end());
170 for(iter=guide_list_x_.begin();iter!=guide_list_x_.end();++iter)
172 float amount(abs(*iter-pos[0]));
182 Duckmatic::GuideList::iterator
183 Duckmatic::find_guide_y(synfig::Point pos, float radius)
185 GuideList::iterator iter,best(guide_list_y_.end());
187 for(iter=guide_list_y_.begin();iter!=guide_list_y_.end();++iter)
189 float amount(abs(*iter-pos[1]));
200 Duckmatic::clear_selected_ducks()
202 selected_ducks.clear();
203 signal_duck_selection_changed_();
206 etl::handle<Duckmatic::Duck>
207 Duckmatic::get_selected_duck()const
209 if(selected_ducks.empty() || duck_map.empty())
211 return duck_map.find(*selected_ducks.begin())->second;
215 Duckmatic::refresh_selected_ducks()
218 std::set<etl::handle<Duck> >::iterator iter;
219 std::set<etl::handle<Duck> > new_set;
220 if(duck_list().empty())
222 selected_duck_list.clear();
223 signal_duck_selection_changed_();
227 for(iter=selected_duck_list.begin();iter!=selected_duck_list.end();++iter)
229 etl::handle<Duck> similar(find_similar_duck(*iter));
232 new_set.insert(similar);
235 selected_duck_list=new_set;
237 GUIDSet old_set(selected_ducks);
238 GUIDSet::const_iterator iter;
240 for(iter=old_set.begin();iter!=old_set.end();++iter)
242 if(duck_map.count(*iter)==0)
243 selected_ducks.erase(*iter);
246 signal_duck_selection_changed_();
250 Duckmatic::is_duck_group_selectable(const etl::handle<Duck>& x)const
252 const Type type(get_type_mask());
254 if (((x->get_type() && (!(type & x->get_type()))) ||
258 synfigapp::ValueDesc value_desc(x->get_value_desc());
259 if(value_desc.parent_is_layer_param() && type & Duck::TYPE_POSITION)
261 Layer::Handle layer(value_desc.get_layer());
262 String layer_name(layer->get_name());
264 if (layer_name == "outline" || layer_name == "region" || layer_name == "plant" ||
265 layer_name == "polygon" || layer_name == "curve_gradient")
268 if((layer_name=="PasteCanvas"|| layer_name=="paste_canvas") &&
269 !layer->get_param("children_lock").get(bool()))
272 else if (value_desc.parent_is_value_node())
274 if (ValueNode_BLineCalcVertex::Handle::cast_dynamic(value_desc.get_value_node()))
276 if (value_desc.parent_is_linkable_value_node())
278 LinkableValueNode::Handle parent_value_node(value_desc.get_parent_value_node());
279 if (ValueNode_Composite::Handle::cast_dynamic(parent_value_node))
281 if (parent_value_node->get_type() == ValueBase::TYPE_BLINEPOINT &&
282 ValueNode_BLineCalcVertex::Handle::cast_dynamic(
283 parent_value_node->get_link("point")))
286 else if (ValueNode_BLine::Handle::cast_dynamic(parent_value_node))
288 ValueNode_Composite::Handle composite(ValueNode_Composite::Handle::cast_dynamic(
289 value_desc.get_value_node()));
291 ValueNode_BLineCalcVertex::Handle::cast_dynamic(composite->get_link("point")))
300 Duckmatic::select_all_ducks()
302 DuckMap::const_iterator iter;
303 for(iter=duck_map.begin();iter!=duck_map.end();++iter)
304 if(is_duck_group_selectable(iter->second))
305 select_duck(iter->second);
307 unselect_duck(iter->second);
311 Duckmatic::unselect_all_ducks()
313 DuckMap::const_iterator iter;
314 for(iter=duck_map.begin();iter!=duck_map.end();++iter)
315 unselect_duck(iter->second);
319 Duckmatic::toggle_select_ducks_in_box(const synfig::Vector& tl,const synfig::Vector& br)
322 vmin[0]=std::min(tl[0],br[0]);
323 vmin[1]=std::min(tl[1],br[1]);
324 vmax[0]=std::max(tl[0],br[0]);
325 vmax[1]=std::max(tl[1],br[1]);
327 DuckMap::const_iterator iter;
328 for(iter=duck_map.begin();iter!=duck_map.end();++iter)
330 Point p(iter->second->get_trans_point());
331 if(p[0]<=vmax[0] && p[0]>=vmin[0] && p[1]<=vmax[1] && p[1]>=vmin[1] &&
332 is_duck_group_selectable(iter->second))
333 toggle_select_duck(iter->second);
338 Duckmatic::select_ducks_in_box(const synfig::Vector& tl,const synfig::Vector& br)
341 vmin[0]=std::min(tl[0],br[0]);
342 vmin[1]=std::min(tl[1],br[1]);
343 vmax[0]=std::max(tl[0],br[0]);
344 vmax[1]=std::max(tl[1],br[1]);
346 // Type type(get_type_mask());
348 DuckMap::const_iterator iter;
349 for(iter=duck_map.begin();iter!=duck_map.end();++iter)
351 Point p(iter->second->get_trans_point());
352 if(p[0]<=vmax[0] && p[0]>=vmin[0] && p[1]<=vmax[1] && p[1]>=vmin[1])
354 if(is_duck_group_selectable(iter->second))
355 select_duck(iter->second);
361 Duckmatic::count_selected_ducks()const
363 return selected_ducks.size();
367 Duckmatic::select_duck(const etl::handle<Duck> &duck)
371 selected_ducks.insert(duck->get_guid());
372 signal_duck_selection_changed_();
377 Duckmatic::get_selected_ducks()const
380 GUIDSet::const_iterator iter;
381 const Type type(get_type_mask());
383 for(iter=selected_ducks.begin();iter!=selected_ducks.end();++iter)
385 const DuckMap::const_iterator d_iter(duck_map.find(*iter));
387 if(d_iter==duck_map.end())
390 if(( d_iter->second->get_type() && (!(type & d_iter->second->get_type())) ) )
393 ret.push_back(d_iter->second);
399 Duckmatic::get_duck_list()const
402 DuckMap::const_iterator iter;
403 for(iter=duck_map.begin();iter!=duck_map.end();++iter) if (iter->second->get_type()&Duck::TYPE_POSITION) ret.push_back(iter->second);
404 for(iter=duck_map.begin();iter!=duck_map.end();++iter) if (iter->second->get_type()&Duck::TYPE_VERTEX ) ret.push_back(iter->second);
405 for(iter=duck_map.begin();iter!=duck_map.end();++iter) if (iter->second->get_type()&Duck::TYPE_TANGENT ) ret.push_back(iter->second);
406 for(iter=duck_map.begin();iter!=duck_map.end();++iter)
407 if (!(iter->second->get_type()&Duck::TYPE_POSITION) &&
408 !(iter->second->get_type()&Duck::TYPE_VERTEX) &&
409 !(iter->second->get_type()&Duck::TYPE_TANGENT))
410 ret.push_back(iter->second);
415 Duckmatic::unselect_duck(const etl::handle<Duck> &duck)
417 if(duck && selected_ducks.count(duck->get_guid()))
419 selected_ducks.erase(duck->get_guid());
420 signal_duck_selection_changed_();
425 Duckmatic::toggle_select_duck(const etl::handle<Duck> &duck)
427 if(duck_is_selected(duck))
434 Duckmatic::translate_selected_ducks(const synfig::Vector& vector)
437 duck_dragger_->duck_drag(this,vector);
441 Duckmatic::start_duck_drag(const synfig::Vector& offset)
444 duck_dragger_->begin_duck_drag(this,offset);
446 //drag_offset_=offset;
447 drag_offset_=find_duck(offset)->get_trans_point();
451 Duckmatic::update_ducks()
453 Time time(get_time());
454 DuckList duck_list(get_duck_list());
455 const DuckList selected_ducks(get_selected_ducks());
456 DuckList::const_iterator iter;
457 for (iter=selected_ducks.begin(); iter!=selected_ducks.end(); ++iter)
459 etl::handle<Duck> duck(*iter);
460 if (duck->get_type() == Duck::TYPE_VERTEX || duck->get_type() == Duck::TYPE_POSITION)
462 ValueNode_BLineCalcVertex::Handle bline_vertex;
463 ValueNode_Composite::Handle composite;
465 if ((bline_vertex = ValueNode_BLineCalcVertex::Handle::cast_dynamic(duck->get_value_desc().get_value_node())) ||
466 ((composite = ValueNode_Composite::Handle::cast_dynamic(duck->get_value_desc().get_value_node())) &&
467 composite->get_type() == ValueBase::TYPE_BLINEPOINT &&
468 (bline_vertex = ValueNode_BLineCalcVertex::Handle::cast_dynamic(composite->get_link("point")))))
470 DuckList::iterator iter;
471 for (iter=duck_list.begin(); iter!=duck_list.end(); iter++)
472 if ( (*iter)->get_origin_duck()==duck /*&& !duck_is_selected(*iter)*/ )
474 synfig::Real radius = 0.0;
475 ValueNode_BLine::Handle bline(ValueNode_BLine::Handle::cast_dynamic(bline_vertex->get_link(bline_vertex->get_link_index_from_name("bline"))));
476 Real amount = synfig::find_closest_point((*bline)(time), duck->get_point(), radius, bline->get_loop());
478 int vertex_amount_index(bline_vertex->get_link_index_from_name("amount"));
479 ValueNode::Handle vertex_amount_value_node(bline_vertex->get_link(vertex_amount_index));
482 ValueNode::Handle duck_value_node((*iter)->get_value_desc().get_value_node());
483 if (ValueNode_BLineCalcTangent::Handle bline_tangent = ValueNode_BLineCalcTangent::Handle::cast_dynamic(duck_value_node))
485 if (bline_tangent->get_link(bline_tangent->get_link_index_from_name("amount")) == vertex_amount_value_node)
487 switch (bline_tangent->get_type())
489 case ValueBase::TYPE_ANGLE:
491 Angle angle((*bline_tangent)(time, amount).get(Angle()));
492 (*iter)->set_point(Point(Angle::cos(angle).get(), Angle::sin(angle).get()));
493 (*iter)->set_rotations(Angle::deg(0)); //hack: rotations are a relative value
496 case ValueBase::TYPE_REAL:
497 (*iter)->set_point(Point((*bline_tangent)(time, amount).get(Real()), 0));
499 case ValueBase::TYPE_VECTOR:
500 (*iter)->set_point((*bline_tangent)(time, amount).get(Vector()));
507 else if (ValueNode_BLineCalcWidth::Handle bline_width = ValueNode_BLineCalcWidth::Handle::cast_dynamic(duck_value_node))
509 if (bline_width->get_link(bline_width->get_link_index_from_name("amount")) == vertex_amount_value_node)
510 (*iter)->set_point(Point((*bline_width)(time, amount).get(Real()), 0));
520 Duckmatic::end_duck_drag()
523 return duck_dragger_->end_duck_drag(this);
528 Duckmatic::snap_point_to_grid(const synfig::Point& x, float radius)const
532 GuideList::const_iterator guide_x,guide_y;
533 bool has_guide_x(false), has_guide_y(false);
535 guide_x=find_guide_x(ret,radius);
536 if(guide_x!=guide_list_x_.end())
539 guide_y=find_guide_y(ret,radius);
540 if(guide_y!=guide_list_y_.end())
546 floor(ret[0]/get_grid_size()[0]+0.5)*get_grid_size()[0],
547 floor(ret[1]/get_grid_size()[1]+0.5)*get_grid_size()[1]);
549 if(abs(snap[0]-ret[0])<=radius && (!has_guide_x || abs(snap[0]-ret[0])<=abs(*guide_x-ret[0])))
550 ret[0]=snap[0],has_guide_x=false;
551 if(abs(snap[1]-ret[1])<=radius && (!has_guide_y || abs(snap[1]-ret[1])<=abs(*guide_y-ret[1])))
552 ret[1]=snap[1],has_guide_y=false;
566 if(abs(ret[0])<abs(ret[1]))
577 DuckDrag_Translate::begin_duck_drag(Duckmatic* duckmatic, const synfig::Vector& offset)
579 last_translate_=Vector(0,0);
581 drag_offset_=duckmatic->find_duck(offset)->get_trans_point();
586 const DuckList selected_ducks(duckmatic->get_selected_ducks());
587 DuckList::const_iterator iter;
590 for(iter=selected_ducks.begin();iter!=selected_ducks.end();++iter)
592 Point p((*iter)->get_trans_point());
593 positions.push_back(p);
598 DuckDrag_Translate::end_duck_drag(Duckmatic* duckmatic)
600 if(last_translate_.mag()>0.0001)
602 duckmatic->signal_edited_selected_ducks();
607 duckmatic->signal_user_click_selected_ducks(0);
613 DuckDrag_Translate::duck_drag(Duckmatic* duckmatic, const synfig::Vector& vector)
615 const DuckList selected_ducks(duckmatic->get_selected_ducks());
616 DuckList::const_iterator iter;
618 synfig::Vector vect(duckmatic->snap_point_to_grid(vector)-drag_offset_);
620 Time time(duckmatic->get_time());
622 // drag the vertex and position ducks first
623 for (i=0,iter=selected_ducks.begin(); iter!=selected_ducks.end(); ++iter,i++)
624 if((*iter)->get_type() == Duck::TYPE_VERTEX || (*iter)->get_type() == Duck::TYPE_POSITION)
625 (*iter)->set_trans_point(positions[i]+vect, time);
627 // then drag the others
628 for (i=0,iter=selected_ducks.begin(); iter!=selected_ducks.end(); ++iter,i++)
629 if ((*iter)->get_type() != Duck::TYPE_VERTEX && (*iter)->get_type() != Duck::TYPE_POSITION)
630 (*iter)->set_trans_point(positions[i]+vect, time);
632 // then patch up the tangents for the vertices we've moved
633 duckmatic->update_ducks();
635 last_translate_=vect;
639 Duckmatic::signal_edited_selected_ducks()
641 const DuckList ducks(get_selected_ducks());
642 DuckList::const_iterator iter;
644 synfig::GUIDSet old_set(selected_ducks);
646 // If we have more than 20 things to move, then display
647 // something to explain that it may take a moment
648 smart_ptr<OneMoment> wait; if(ducks.size()>20)wait.spawn();
650 // Go ahead and call everyone's signals
651 for(iter=ducks.begin();iter!=ducks.end();++iter)
653 if ((*iter)->get_type() == Duck::TYPE_ANGLE)
655 if(!(*iter)->signal_edited_angle()((*iter)->get_rotations()))
657 selected_ducks=old_set;
658 throw String("Bad edit");
661 else if (App::restrict_radius_ducks &&
662 (*iter)->is_radius())
664 Point point((*iter)->get_point());
665 bool changed = false;
678 if (changed) (*iter)->set_point(point);
680 if(!(*iter)->signal_edited()(point))
682 selected_ducks=old_set;
683 throw String("Bad edit");
688 if(!(*iter)->signal_edited()((*iter)->get_point()))
690 selected_ducks=old_set;
691 throw String("Bad edit");
695 selected_ducks=old_set;
699 Duckmatic::signal_user_click_selected_ducks(int button)
701 const DuckList ducks(get_selected_ducks());
702 DuckList::const_iterator iter;
704 for(iter=ducks.begin();iter!=ducks.end();++iter)
706 (*iter)->signal_user_click(button)();
711 Duckmatic::add_duck(const etl::handle<Duck> &duck)
713 //if(!duck_map.count(duck->get_guid()))
715 if(duck_data_share_map.count(duck->get_data_guid()))
717 duck->set_shared_point(duck_data_share_map[duck->get_data_guid()]);
721 etl::smart_ptr<synfig::Point> point(new Point(duck->get_point()));
722 duck->set_shared_point(point);
723 duck_data_share_map[duck->get_data_guid()]=point;
726 duck_map.insert(duck);
729 last_duck_guid=duck->get_guid();
733 Duckmatic::add_bezier(const etl::handle<Bezier> &bezier)
735 bezier_list_.push_back(bezier);
739 Duckmatic::add_stroke(etl::smart_ptr<std::list<synfig::Point> > stroke_point_list, const synfig::Color& color)
741 assert(stroke_point_list);
743 std::list<etl::handle<Stroke> >::iterator iter;
745 for(iter=stroke_list_.begin();iter!=stroke_list_.end();++iter)
747 if((*iter)->stroke_data==stroke_point_list)
751 etl::handle<Stroke> stroke(new Stroke());
753 stroke->stroke_data=stroke_point_list;
756 stroke_list_.push_back(stroke);
760 Duckmatic::add_persistent_stroke(etl::smart_ptr<std::list<synfig::Point> > stroke_point_list, const synfig::Color& color)
762 add_stroke(stroke_point_list,color);
763 persistent_stroke_list_.push_back(stroke_list_.back());
767 Duckmatic::clear_persistent_strokes()
769 persistent_stroke_list_.clear();
773 Duckmatic::set_show_persistent_strokes(bool x)
775 if(x!=show_persistent_strokes)
777 show_persistent_strokes=x;
779 stroke_list_=persistent_stroke_list_;
781 stroke_list_.clear();
786 Duckmatic::erase_duck(const etl::handle<Duck> &duck)
788 duck_map.erase(duck->get_guid());
791 etl::handle<Duckmatic::Duck>
792 Duckmatic::find_similar_duck(etl::handle<Duck> duck)
794 DuckMap::const_iterator iter(duck_map.find(duck->get_guid()));
795 if(iter!=duck_map.end())
799 /* std::list<handle<Duck> >::reverse_iterator iter;
801 for(iter=duck_list_.rbegin();iter!=duck_list_.rend();++iter)
803 if(*iter!=duck && **iter==*duck)
805 //synfig::info("Found similar duck! (iter:%08x vs. duck:%08x)",iter->get(), duck.get());
813 etl::handle<Duckmatic::Duck>
814 Duckmatic::add_similar_duck(etl::handle<Duck> duck)
816 etl::handle<Duck> similar(find_similar_duck(duck));
826 Duckmatic::erase_bezier(const etl::handle<Bezier> &bezier)
828 std::list<handle<Bezier> >::iterator iter;
830 for(iter=bezier_list_.begin();iter!=bezier_list_.end();++iter)
834 bezier_list_.erase(iter);
838 synfig::warning("Unable to find bezier to erase!");
841 etl::handle<Duckmatic::Duck>
842 Duckmatic::last_duck()const
844 DuckMap::const_iterator iter(duck_map.find(last_duck_guid));
845 if(iter!=duck_map.end())
850 etl::handle<Duckmatic::Bezier>
851 Duckmatic::last_bezier()const
853 return bezier_list_.back();
856 etl::handle<Duckmatic::Duck>
857 Duckmatic::find_duck(synfig::Point point, synfig::Real radius, Duck::Type type)
859 if(radius==0)radius=10000000;
861 if(type==Duck::TYPE_DEFAULT)
862 type=get_type_mask();
864 Real closest(10000000);
865 etl::handle<Duck> ret;
867 DuckMap::const_iterator iter;
869 for(iter=duck_map.begin();iter!=duck_map.end();++iter)
871 const Duck::Handle& duck(iter->second);
873 if(duck->get_ignore() ||
874 (duck->get_type() && !(type & duck->get_type())))
877 Real dist((duck->get_trans_point()-point).mag_squared());
879 if(duck->get_type()&Duck::TYPE_VERTEX)
881 else if(duck->get_type()&Duck::TYPE_TANGENT && duck->get_scalar()>0)
883 else if(duck->get_type()&Duck::TYPE_RADIUS)
893 if(radius==0 || closest<radius*radius)
899 etl::handle<Duckmatic::Bezier>
900 Duckmatic::find_bezier(synfig::Point point, synfig::Real radius,float* location)
902 return find_bezier(point,radius,radius,location);
905 etl::handle<Duckmatic::Bezier>
906 Duckmatic::find_bezier(synfig::Point pos, synfig::Real scale, synfig::Real radius, float* location)
908 if(radius==0)radius=10000000;
909 Real closest(10000000);
910 etl::handle<Bezier> ret;
918 for(std::list<handle<Bezier> >::const_iterator iter=bezier_list().begin();iter!=bezier_list().end();++iter)
920 curve[0] = (*iter)->p1->get_trans_point();
921 curve[1] = (*iter)->c1->get_trans_point();
922 curve[2] = (*iter)->c2->get_trans_point();
923 curve[3] = (*iter)->p2->get_trans_point();
927 // I don't know why this doesn't work
928 time=curve.find_closest(pos,6);
929 d=((curve(time)-pos).mag_squared());
932 //set the step size based on the size of the picture
933 d = (curve[1] - curve[0]).mag() + (curve[2]-curve[1]).mag() + (curve[3]-curve[2]).mag();
935 step = d/(2*scale); //want to make the distance between lines happy
937 step = max(step,0.01); //100 samples should be plenty
938 step = min(step,0.1); //10 is minimum
940 d = find_closest(curve,pos,step,&closest,&time);
951 if(closest < radius*radius)
954 *location = best_time; // We need to square-root this because we were dealing with squared distances
963 Duckmatic::save_sketch(const synfig::String& filename)const
965 ChangeLocale change_locale(LC_NUMERIC, "C");
966 std::ofstream file(filename.c_str());
968 if(!file)return false;
970 file<<"SKETCH"<<endl;
972 std::list<etl::handle<Stroke> >::const_iterator iter;
974 for(iter=persistent_stroke_list_.begin();iter!=persistent_stroke_list_.end();++iter)
977 <<(*iter)->color.get_r()<<' '
978 <<(*iter)->color.get_g()<<' '
979 <<(*iter)->color.get_b()
981 std::list<synfig::Point>::const_iterator viter;
982 for(viter=(*iter)->stroke_data->begin();viter!=(*iter)->stroke_data->end();++viter)
990 if(!file)return false;
991 sketch_filename_=filename;
992 signal_sketch_saved_();
997 Duckmatic::load_sketch(const synfig::String& filename)
999 ChangeLocale change_locale(LC_NUMERIC, "C");
1000 std::ifstream file(filename.c_str());
1010 synfig::error("Not a sketch");
1014 etl::smart_ptr<std::list<synfig::Point> > stroke_data;
1028 stroke_data.spawn();
1030 if(!strscanf(line,"C %f %f %f",&r, &g, &b))
1032 synfig::warning("Bad color line \"%s\"",line.c_str());
1035 add_persistent_stroke(stroke_data, synfig::Color(r,g,b));
1042 stroke_data.spawn();
1043 add_persistent_stroke(stroke_data, synfig::Color(0,0,0));
1046 if(!strscanf(line,"V %f %f",&x, &y))
1047 synfig::warning("Bad vertex \"%s\"",line.c_str());
1049 stroke_data->push_back(synfig::Vector(x,y));
1052 synfig::warning("Unexpected sketch token '%c'",line[0]);
1057 sketch_filename_=filename;
1061 Duckmatic::Push::Push(Duckmatic *duckmatic_):
1062 duckmatic_(duckmatic_)
1064 duck_map=duckmatic_->duck_map;
1065 bezier_list_=duckmatic_->bezier_list_;
1066 duck_data_share_map=duckmatic_->duck_data_share_map;
1067 stroke_list_=duckmatic_->stroke_list_;
1068 duck_dragger_=duckmatic_->duck_dragger_;
1072 Duckmatic::Push::~Push()
1079 Duckmatic::Push::restore()
1081 duckmatic_->duck_map=duck_map;
1082 duckmatic_->bezier_list_=bezier_list_;
1083 duckmatic_->duck_data_share_map=duck_data_share_map;
1084 duckmatic_->stroke_list_=stroke_list_;
1085 duckmatic_->duck_dragger_=duck_dragger_;
1086 needs_restore=false;
1089 inline String guid_string(const synfigapp::ValueDesc& x)
1091 if(x.parent_is_layer_param())
1092 return strprintf("%s",x.get_layer()->get_guid().get_string().c_str())+x.get_param_name();
1093 //if(x.is_value_node())
1094 return strprintf("%s",x.get_value_node()->get_guid().get_string().c_str());
1097 inline synfig::GUID calc_duck_guid(const synfigapp::ValueDesc& x,const synfig::TransformStack& transform_stack)
1099 synfig::GUID ret(0);
1101 if(x.parent_is_layer_param())
1103 ret=x.get_layer()->get_guid()^synfig::GUID::hasher(x.get_param_name());
1107 ret=x.get_value_node()->get_guid();
1110 ret^=transform_stack.get_guid();
1116 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)
1118 synfig::GUID duck_guid(calc_duck_guid(value_desc,transform_stack)^synfig::GUID::hasher(modifier));
1119 etl::handle<Duck> duck=new Duck();
1126 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)
1128 ValueBase::Type type=value_desc.get_value_type();
1129 #define REAL_COOKIE reinterpret_cast<synfig::ParamDesc*>(28)
1132 case ValueBase::TYPE_REAL:
1134 if(!param_desc || param_desc==REAL_COOKIE || !param_desc->get_origin().empty())
1136 etl::handle<Duck> duck=new Duck();
1137 duck->set_transform_stack(transform_stack);
1138 duck->set_radius(true);
1139 duck->set_type(Duck::TYPE_RADIUS);
1141 // put the duck on the right hand side of the center
1142 duck->set_point(Point(value_desc.get_value(get_time()).get(Real()), 0));
1143 duck->set_name(guid_string(value_desc));
1144 if(value_desc.is_value_node())
1146 // If the ValueNode can be directly manipulated,
1147 // then set it as so.
1148 duck->set_editable(synfigapp::is_editable(value_desc.get_value_node()));
1152 duck->set_editable(true);
1155 if(param_desc && param_desc!=REAL_COOKIE)
1157 if(!param_desc->get_origin().empty())
1159 synfigapp::ValueDesc value_desc_origin(value_desc.get_layer(),param_desc->get_origin());
1161 duck->set_origin(value_desc_origin.get_value(get_time()).get(synfig::Point()));
1163 add_to_ducks(value_desc_origin,canvas_view, transform_stack);
1164 duck->set_origin(last_duck());
1166 duck->set_scalar(param_desc->get_scalar());
1169 duck->signal_edited().clear(); // value_desc.get_value_type() == ValueBase::TYPE_REAL:
1170 duck->signal_edited().connect(
1174 &studio::CanvasView::on_duck_changed),
1176 duck->set_value_desc(value_desc);
1178 duck->signal_user_click(2).connect(
1184 &studio::CanvasView::popup_param_menu),
1189 duck->set_guid(calc_duck_guid(value_desc,transform_stack)^synfig::GUID::hasher(multiple));
1197 case ValueBase::TYPE_ANGLE:
1199 if(!param_desc || param_desc==REAL_COOKIE || !param_desc->get_origin().empty())
1201 etl::handle<Duck> duck=new Duck();
1202 duck->set_type(Duck::TYPE_ANGLE);
1203 duck->set_transform_stack(transform_stack);
1204 synfig::Angle angle;
1206 angle=value_desc.get_value(get_time()).get(Angle());
1207 duck->set_point(Point(Angle::cos(angle).get(),Angle::sin(angle).get()));
1208 duck->set_name(guid_string(value_desc));
1209 if(value_desc.is_value_node())
1211 ValueNode::Handle value_node=value_desc.get_value_node();
1212 //duck->set_name(strprintf("%x",value_node.get()));
1214 // If the ValueNode can be directly manipulated,
1215 // then set it as so.
1216 duck->set_editable(synfigapp::is_editable(value_desc.get_value_node()));
1220 //angle=(value_desc.get_value().get(Angle()));
1221 //duck->set_point(Point(Angle::cos(angle).get(),Angle::sin(angle).get()));
1222 //duck->set_name(strprintf("%x",value_desc.get_layer().get())+value_desc.get_param_name());
1223 duck->set_editable(true);
1226 if(param_desc && param_desc!=REAL_COOKIE)
1228 if(!param_desc->get_origin().empty())
1230 synfigapp::ValueDesc value_desc_origin(value_desc.get_layer(),param_desc->get_origin());
1232 duck->set_origin(value_desc_origin.get_value(get_time()).get(synfig::Point()));
1234 add_to_ducks(value_desc_origin,canvas_view, transform_stack);
1235 duck->set_origin(last_duck());
1237 duck->set_scalar(param_desc->get_scalar());
1240 duck->signal_edited().clear(); // value_desc.get_value_type() == ValueBase::TYPE_ANGLE:
1241 duck->signal_edited_angle().clear();
1242 duck->signal_edited_angle().connect(
1246 &studio::CanvasView::on_duck_angle_changed),
1248 duck->set_value_desc(value_desc);
1250 duck->signal_user_click(2).connect(
1256 &studio::CanvasView::popup_param_menu),
1260 duck->set_guid(calc_duck_guid(value_desc,transform_stack)^synfig::GUID::hasher(multiple));
1268 case ValueBase::TYPE_VECTOR:
1270 etl::handle<Duck> duck=new Duck();
1271 duck->set_transform_stack(transform_stack);
1273 duck->set_point(value_desc.get_value(get_time()).get(Point()));
1274 duck->set_name(guid_string(value_desc));
1275 if(value_desc.is_value_node())
1277 //duck->set_name(strprintf("%x",value_desc.get_value_node().get()));
1279 // If the ValueNode can be directly manipulated,
1280 // then set it as so.
1281 duck->set_editable(synfigapp::is_editable(value_desc.get_value_node()));
1285 //duck->set_point(value_desc.get_value().get(Point()));
1286 //duck->set_name(strprintf("%x",value_desc.get_layer().get())+value_desc.get_param_name());
1287 duck->set_editable(true);
1290 // If we were passed a parameter description
1293 if(!param_desc->get_connect().empty())
1295 synfigapp::ValueDesc value_desc_origin(value_desc.get_layer(),param_desc->get_connect());
1296 Duck::Handle connect_duck;
1297 if(duck_map.find(calc_duck_guid(value_desc_origin,transform_stack)^synfig::GUID::hasher(0))!=duck_map.end())
1299 connect_duck=duck_map[calc_duck_guid(value_desc_origin,transform_stack)^synfig::GUID::hasher(0)];
1303 add_to_ducks(value_desc_origin,canvas_view, transform_stack);
1304 connect_duck=last_duck();
1306 duck->set_connect_duck(connect_duck);
1308 if(!param_desc->get_box().empty())
1310 synfigapp::ValueDesc value_desc_origin(value_desc.get_layer(),param_desc->get_box());
1311 add_to_ducks(value_desc_origin,canvas_view, transform_stack);
1312 duck->set_box_duck(last_duck());
1315 // If we have an origin
1316 if(!param_desc->get_origin().empty())
1318 synfigapp::ValueDesc value_desc_origin(value_desc.get_layer(),param_desc->get_origin());
1320 duck->set_origin(value_desc_origin.get_value(get_time()).get(synfig::Point()));
1322 add_to_ducks(value_desc_origin,canvas_view, transform_stack);
1323 duck->set_origin(last_duck());
1324 duck->set_type(Duck::TYPE_VERTEX);
1327 duck->set_type(Duck::TYPE_POSITION);
1329 duck->set_scalar(param_desc->get_scalar());
1332 duck->set_type(Duck::TYPE_POSITION);
1334 duck->signal_edited().clear(); // value_desc.get_value_type() == ValueBase::TYPE_VECTOR:
1335 duck->signal_edited().connect(
1339 &studio::CanvasView::on_duck_changed),
1341 duck->set_value_desc(value_desc);
1343 duck->signal_user_click(2).connect(
1349 &studio::CanvasView::popup_param_menu),
1353 duck->set_guid(calc_duck_guid(value_desc,transform_stack)^synfig::GUID::hasher(multiple));
1359 case ValueBase::TYPE_SEGMENT:
1361 etl::handle<Bezier> bezier(new Bezier());
1362 ValueNode_Composite::Handle value_node;
1364 if(value_desc.is_value_node() &&
1365 (value_node=ValueNode_Composite::Handle::cast_dynamic(value_desc.get_value_node())))
1367 if(!add_to_ducks(synfigapp::ValueDesc(value_node,0),canvas_view,transform_stack))
1369 bezier->p1=last_duck();
1370 bezier->p1->set_type(Duck::TYPE_VERTEX);
1371 if(!add_to_ducks(synfigapp::ValueDesc(value_node,1),canvas_view,transform_stack))
1373 bezier->c1=last_duck();
1374 bezier->c1->set_type(Duck::TYPE_TANGENT);
1375 bezier->c1->set_origin(bezier->p1);
1376 bezier->c1->set_scalar(TANGENT_BEZIER_SCALE);
1377 bezier->c1->set_tangent(true);
1379 if(!add_to_ducks(synfigapp::ValueDesc(value_node,2),canvas_view,transform_stack))
1381 bezier->p2=last_duck();
1382 bezier->p2->set_type(Duck::TYPE_VERTEX);
1383 if(!add_to_ducks(synfigapp::ValueDesc(value_node,3),canvas_view,transform_stack))
1385 bezier->c2=last_duck();
1386 bezier->c2->set_type(Duck::TYPE_TANGENT);
1387 bezier->c2->set_origin(bezier->p2);
1388 bezier->c2->set_scalar(-TANGENT_BEZIER_SCALE);
1389 bezier->c2->set_tangent(true);
1391 bezier->signal_user_click(2).connect(
1395 &studio::CanvasView::popup_param_menu_bezier),
1400 else if(value_desc.get_value().is_valid())
1402 Segment segment=value_desc.get_value();
1403 etl::handle<Duck> duck_p,duck_c;
1404 synfig::String name;
1407 name=param_desc->get_local_name();
1411 name=guid_string(value_desc);
1414 duck_p=new Duck(segment.p1);
1415 duck_p->set_name(name+".P1");
1416 duck_p->set_type(Duck::TYPE_VERTEX);
1419 duck_c=new Duck(segment.t1);
1420 duck_c->set_name(name+".T1");
1421 duck_c->set_type(Duck::TYPE_TANGENT);
1423 duck_c->set_origin(duck_p);
1424 duck_c->set_scalar(TANGENT_HANDLE_SCALE);
1425 duck_c->set_tangent(true);
1430 duck_p=new Duck(segment.p2);
1431 duck_p->set_name(name+".P2");
1432 duck_p->set_type(Duck::TYPE_VERTEX);
1435 duck_c=new Duck(segment.t2);
1436 duck_c->set_type(Duck::TYPE_TANGENT);
1437 duck_c->set_name(name+".T2");
1439 duck_c->set_origin(duck_p);
1440 duck_c->set_scalar(-TANGENT_HANDLE_SCALE);
1441 duck_c->set_tangent(true);
1451 case ValueBase::TYPE_BLINEPOINT:
1454 if(value_desc.is_value_node() &&
1455 ValueNode_Composite::Handle::cast_dynamic(value_desc.get_value_node()))
1457 ValueNode_Composite::Handle value_node;
1458 value_node=ValueNode_Composite::Handle::cast_dynamic(value_desc.get_value_node());
1460 if(!add_to_ducks(synfigapp::ValueDesc(value_node,0),canvas_view,transform_stack))
1462 etl::handle<Duck> vertex_duck(last_duck());
1463 vertex_duck->set_type(Duck::TYPE_VERTEX);
1464 if(!add_to_ducks(synfigapp::ValueDesc(value_node,4),canvas_view,transform_stack))
1466 etl::handle<Duck> t1_duck(last_duck());
1468 t1_duck->set_origin(vertex_duck);
1469 t1_duck->set_scalar(-TANGENT_HANDLE_SCALE);
1470 t1_duck->set_tangent(true);
1472 etl::handle<Duck> t2_duck;
1474 // If the tangents are split
1475 if((*value_node->get_link("split"))(get_time()).get(bool()))
1477 if(!add_to_ducks(synfigapp::ValueDesc(value_node,5),canvas_view,transform_stack))
1479 t2_duck=last_duck();
1480 t2_duck->set_origin(vertex_duck);
1481 t2_duck->set_scalar(TANGENT_HANDLE_SCALE);
1482 t2_duck->set_tangent(true);
1486 if(!add_to_ducks(synfigapp::ValueDesc(value_node,4),canvas_view,transform_stack))
1488 t2_duck=last_duck();
1489 t2_duck->set_origin(vertex_duck);
1490 t2_duck->set_scalar(TANGENT_HANDLE_SCALE);
1491 t2_duck->set_tangent(true);
1498 case ValueBase::TYPE_LIST:
1501 if (value_desc.is_value_node() &&
1502 ValueNode_BLine::Handle::cast_dynamic(value_desc.get_value_node()))
1504 ValueNode_BLine::Handle value_node;
1505 value_node=ValueNode_BLine::Handle::cast_dynamic(value_desc.get_value_node());
1509 etl::handle<Bezier> bezier;
1510 etl::handle<Duck> first_duck;
1511 etl::handle<Duck> duck, tduck;
1513 for (i = 0; i < value_node->link_count(); i++)
1515 float amount(value_node->list[i].amount_at_time(get_time()));
1517 // skip vertices that aren't fully on
1518 if (amount < 0.9999f)
1521 // remember the index of the first vertex we didn't skip
1525 BLinePoint bline_point((*value_node->get_link(i))(get_time()));
1527 // try casting the vertex to Composite - this tells us whether it is composite or not
1528 ValueNode_Composite::Handle composite_vertex_value_node(
1529 ValueNode_Composite::Handle::cast_dynamic(value_node->get_link(i)));
1531 // add the vertex duck - it's a composite
1532 if(composite_vertex_value_node)
1534 if (add_to_ducks(synfigapp::ValueDesc(composite_vertex_value_node,0),canvas_view,transform_stack))
1539 duck->set_type(Duck::TYPE_VERTEX);
1541 duck->signal_user_click(2).clear();
1542 duck->signal_user_click(2).connect(
1548 &studio::CanvasView::popup_param_menu),
1551 synfigapp::ValueDesc(value_node,i)));
1552 duck->set_value_desc(synfigapp::ValueDesc(value_node,i));
1556 if(!param_desc->get_origin().empty())
1558 synfigapp::ValueDesc value_desc_origin(value_desc.get_layer(),param_desc->get_origin());
1559 add_to_ducks(value_desc_origin,canvas_view, transform_stack);
1560 duck->set_origin(last_duck());
1562 ValueBase value(synfigapp::ValueDesc(value_desc.get_layer(),param_desc->get_origin()).get_value(get_time()));
1563 if(value.same_type_as(synfig::Point()))
1564 duck->set_origin(value.get(synfig::Point()));
1572 // else it's not a composite
1575 duck=new Duck(bline_point.get_vertex());
1578 duck->set_transform_stack(transform_stack);
1579 duck->set_editable(false);
1580 //duck->set_name(strprintf("%x-vertex",value_node->get_link(i).get()));
1581 duck->set_name(guid_string(synfigapp::ValueDesc(value_node,i))+".v");
1583 duck->set_type(Duck::TYPE_VERTEX);
1586 if(!param_desc->get_origin().empty())
1588 synfigapp::ValueDesc value_desc_origin(value_desc.get_layer(),param_desc->get_origin());
1589 add_to_ducks(value_desc_origin,canvas_view, transform_stack);
1590 duck->set_origin(last_duck());
1592 ValueBase value(synfigapp::ValueDesc(value_desc.get_layer(),param_desc->get_origin()).get_value(get_time()));
1593 if(value.same_type_as(synfig::Point()))
1594 duck->set_origin(value.get(synfig::Point()));
1598 duck->set_guid(calc_duck_guid(synfigapp::ValueDesc(value_node,i),transform_stack)^synfig::GUID::hasher(".v"));
1599 duck=add_similar_duck(duck);
1603 // Add the width duck if it is a parameter with a hint (ie. "width") or if it isn't a parameter
1604 if ((param_desc && !param_desc->get_hint().empty()) ||
1607 etl::handle<Duck> width;
1608 if (add_to_ducks(synfigapp::ValueDesc(composite_vertex_value_node,1),canvas_view,transform_stack,REAL_COOKIE))
1611 width->set_origin(duck);
1612 width->set_type(Duck::TYPE_WIDTH);
1613 width->set_name(guid_string(synfigapp::ValueDesc(value_node,i))+".w");
1615 // if the bline is a layer's parameter, scale the width duck by the layer's "width" parameter
1618 ValueBase value(synfigapp::ValueDesc(value_desc.get_layer(),param_desc->get_hint()).get_value(get_time()));
1619 if(value.same_type_as(synfig::Real()))
1620 width->set_scalar(value.get(synfig::Real())*0.5f);
1621 // if it doesn't have a "width" parameter, scale by 0.5f instead
1623 width->set_scalar(0.5f);
1625 // otherwise just present the raw unscaled width
1627 width->set_scalar(0.5f);
1630 synfig::error("Unable to add width duck!");
1633 // each bezier uses t2 of one point and t1 of the next
1634 // the first time through this loop we won't have the t2 duck from the previous vertex
1635 // and so we don't make a bezier. instead we skip on to t2 for this point
1638 // Add the tangent1 duck
1639 if(composite_vertex_value_node)
1641 if(!add_to_ducks(synfigapp::ValueDesc(composite_vertex_value_node,4),canvas_view,transform_stack))
1647 tduck=new Duck(bline_point.get_tangent1());
1648 tduck->set_transform_stack(transform_stack);
1649 tduck->set_editable(false);
1650 tduck->set_name(guid_string(synfigapp::ValueDesc(value_node,i))+".t1");
1651 // tduck->set_name(strprintf("%x-tangent1",value_node->get_link(i).get()));
1652 tduck->set_guid(calc_duck_guid(synfigapp::ValueDesc(value_node,i),transform_stack)^synfig::GUID::hasher(".t1"));
1653 tduck=add_similar_duck(tduck);
1657 tduck->set_origin(duck);
1658 tduck->set_scalar(-TANGENT_BEZIER_SCALE);
1659 tduck->set_tangent(true);
1664 bezier->signal_user_click(2).connect(
1668 &studio::CanvasView::popup_param_menu_bezier),
1669 synfigapp::ValueDesc(value_node,i)));
1671 duck->signal_user_click(2).clear();
1672 duck->signal_user_click(2).connect(
1678 &studio::CanvasView::popup_param_menu),
1681 synfigapp::ValueDesc(value_node,i)));
1682 duck->set_value_desc(synfigapp::ValueDesc(value_node,i));
1688 // don't start a new bezier for the last point in the line if we're not looped
1689 if(i+1>=value_node->link_count() && !value_node->get_loop())
1692 bezier=new Bezier();
1694 // Add the tangent2 duck
1695 if(composite_vertex_value_node)
1697 int i=bline_point.get_split_tangent_flag()?5:4;
1698 if(!add_to_ducks(synfigapp::ValueDesc(composite_vertex_value_node,i),canvas_view,transform_stack,0,2))
1704 if(bline_point.get_split_tangent_flag())
1705 tduck=new Duck(bline_point.get_tangent2());
1707 tduck=new Duck(bline_point.get_tangent1());
1709 tduck->set_transform_stack(transform_stack);
1710 tduck->set_name(guid_string(synfigapp::ValueDesc(value_node,i))+".t2");
1711 tduck->set_guid(calc_duck_guid(synfigapp::ValueDesc(value_node,i),transform_stack)^synfig::GUID::hasher(".t2"));
1712 tduck->set_editable(false);
1713 tduck=add_similar_duck(tduck);
1717 synfigapp::ValueDesc value_desc_origin(value_desc.get_layer(),param_desc->get_origin());
1718 add_to_ducks(value_desc_origin,canvas_view, transform_stack);
1719 duck->set_origin(last_duck());
1721 ValueBase value(synfigapp::ValueDesc(value_desc.get_layer(),param_desc->get_origin()).get_value(get_time()));
1722 if(value.same_type_as(synfig::Point()))
1723 duck->set_origin(value.get(synfig::Point()));
1725 // if(!param_desc->get_origin().empty())
1726 // duck->set_origin(synfigapp::ValueDesc(value_desc.get_layer(),param_desc->get_origin()).get_value(get_time()).get(synfig::Point()));
1728 duck->signal_user_click(2).clear();
1729 duck->signal_user_click(2).connect(
1735 &studio::CanvasView::popup_param_menu),
1738 synfigapp::ValueDesc(value_node,i)));
1739 duck->set_value_desc(synfigapp::ValueDesc(value_node,i));
1743 tduck->set_origin(duck);
1744 tduck->set_scalar(TANGENT_BEZIER_SCALE);
1745 tduck->set_tangent(true);
1751 // Loop if necessary
1752 if(bezier && value_node->get_loop())
1754 BLinePoint bline_point((*value_node->get_link(first))(get_time()));
1756 ValueNode_Composite::Handle composite_vertex_value_node(
1757 ValueNode_Composite::Handle::cast_dynamic(
1758 value_node->get_link(first)));
1760 // Add the vertex duck
1763 // Add the tangent1 duck
1764 if(composite_vertex_value_node)
1766 if(!add_to_ducks(synfigapp::ValueDesc(composite_vertex_value_node,4),canvas_view,transform_stack))
1772 tduck=new Duck(bline_point.get_tangent1());
1773 tduck->set_transform_stack(transform_stack);
1774 tduck->set_editable(false);
1775 tduck->set_name(guid_string(synfigapp::ValueDesc(value_node,first))+".t1");
1776 //tduck->set_name(strprintf("%x-tangent1",value_node->get_link(first).get()));
1777 tduck=add_similar_duck(tduck);
1778 tduck->set_guid(calc_duck_guid(synfigapp::ValueDesc(value_node,first),transform_stack)^synfig::GUID::hasher(".t1"));
1782 tduck->set_origin(duck);
1783 tduck->set_scalar(-TANGENT_BEZIER_SCALE);
1784 tduck->set_tangent(true);
1789 bezier->signal_user_click(2).connect(
1793 &studio::CanvasView::popup_param_menu_bezier),
1794 synfigapp::ValueDesc(value_node,first)));
1796 duck->signal_user_click(2).clear();
1797 duck->signal_user_click(2).connect(
1803 &studio::CanvasView::popup_param_menu),
1806 synfigapp::ValueDesc(value_node,first)));
1807 duck->set_value_desc(synfigapp::ValueDesc(value_node,first));
1814 else // Check for DynamicList
1815 if(value_desc.is_value_node() &&
1816 ValueNode_DynamicList::Handle::cast_dynamic(value_desc.get_value_node()))
1818 ValueNode_DynamicList::Handle value_node;
1819 value_node=ValueNode_DynamicList::Handle::cast_dynamic(value_desc.get_value_node());
1822 if(value_node->get_contained_type()==ValueBase::TYPE_VECTOR)
1825 etl::handle<Duck> first_duck, duck;
1827 for(i=0;i<value_node->link_count();i++)
1829 if(!value_node->list[i].status_at_time(get_time()))
1831 if(!add_to_ducks(synfigapp::ValueDesc(value_node,i),canvas_view,transform_stack))
1835 // remember the index of the first vertex we didn't skip
1842 if(param_desc && !param_desc->get_origin().empty())
1844 synfigapp::ValueDesc value_desc_origin(value_desc.get_layer(),param_desc->get_origin());
1845 add_to_ducks(value_desc_origin,canvas_view, transform_stack);
1846 duck->set_origin(last_duck());
1848 ValueBase value(synfigapp::ValueDesc(value_desc.get_layer(),param_desc->get_origin()).get_value(get_time()));
1849 if(value.same_type_as(synfig::Point()))
1850 duck->set_origin(value.get(synfig::Point()));
1852 // if(!param_desc->get_origin().empty())
1853 // last_duck()->set_origin(synfigapp::ValueDesc(value_desc.get_layer(),param_desc->get_origin()).get_value(get_time()).get(synfig::Point()));
1855 duck->set_type(Duck::TYPE_VERTEX);
1856 bezier.p1=bezier.p2;bezier.c1=bezier.c2;
1857 bezier.p2=bezier.c2=duck;
1861 handle<Bezier> bezier_(new Bezier());
1862 bezier_->p1=bezier.p1;
1863 bezier_->c1=bezier.c1;
1864 bezier_->p2=bezier.p2;
1865 bezier_->c2=bezier.c2;
1866 add_bezier(bezier_);
1867 last_bezier()->signal_user_click(2).connect(
1871 &studio::CanvasView::popup_param_menu_bezier),
1872 synfigapp::ValueDesc(value_node,i)));
1876 if (value_node->get_loop() && first != -1 && first_duck != duck)
1880 bezier.p1=bezier.p2;bezier.c1=bezier.c2;
1881 bezier.p2=bezier.c2=duck;
1883 handle<Bezier> bezier_(new Bezier());
1884 bezier_->p1=bezier.p1;
1885 bezier_->c1=bezier.c1;
1886 bezier_->p2=bezier.p2;
1887 bezier_->c2=bezier.c2;
1888 add_bezier(bezier_);
1889 last_bezier()->signal_user_click(2).connect(
1893 &studio::CanvasView::popup_param_menu_bezier),
1894 synfigapp::ValueDesc(value_node,first)));
1897 else if(value_node->get_contained_type()==ValueBase::TYPE_SEGMENT)
1899 for(i=0;i<value_node->link_count();i++)
1901 if(!value_node->list[i].status_at_time(get_time()))
1903 if(!add_to_ducks(synfigapp::ValueDesc(value_node,i),canvas_view,transform_stack))