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
11 ** This package is free software; you can redistribute it and/or
12 ** modify it under the terms of the GNU General Public License as
13 ** published by the Free Software Foundation; either version 2 of
14 ** the License, or (at your option) any later version.
16 ** This package is distributed in the hope that it will be useful,
17 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 ** General Public License for more details.
22 /* ========================================================================= */
24 /* === H E A D E R S ======================================================= */
36 #include <ETL/hermite>
38 #include "duckmatic.h"
39 #include <synfigapp/value_desc.h>
40 #include <synfig/general.h>
41 #include <synfig/paramdesc.h>
42 #include <synfig/valuenode_timedswap.h>
43 #include <synfig/valuenode_animated.h>
44 #include <synfig/valuenode_composite.h>
45 #include <synfig/valuenode_scale.h>
46 #include <synfig/valuenode_bline.h>
47 #include <synfig/valuenode_blinecalctangent.h>
48 #include <synfig/valuenode_blinecalcvertex.h>
49 #include <synfig/valuenode_blinecalcwidth.h>
51 #include <synfig/curve_helper.h>
53 #include <sigc++/retype_return.h>
54 #include <sigc++/retype.h>
55 #include <sigc++/hide.h>
56 #include <sigc++/bind.h>
58 #include "canvasview.h"
60 #include "onemoment.h"
66 /* === U S I N G =========================================================== */
70 using namespace synfig;
71 using namespace studio;
73 /* === M A C R O S ========================================================= */
75 /* 0.33333333333333333 makes for nice short tangent handles,
76 1.0 makes them draw as their real length */
77 #define TANGENT_HANDLE_SCALE 0.33333333333333333
79 /* leave this alone or the bezier won't lie on top of the bline */
80 #define TANGENT_BEZIER_SCALE 0.33333333333333333
82 /* === G L O B A L S ======================================================= */
84 /* === P R O C E D U R E S ================================================= */
86 /* === M E T H O D S ======================================================= */
88 /* === E N T R Y P O I N T ================================================= */
90 Duckmatic::Duckmatic():
91 type_mask(Duck::TYPE_ALL-Duck::TYPE_WIDTH),
94 grid_size(1.0/4.0,1.0/4.0),
95 show_persistent_strokes(true)
98 drag_offset_=Point(0,0);
102 Duckmatic::~Duckmatic()
106 if (Duck::duck_count)
107 synfig::error("%d ducks not yet deleted!", Duck::duck_count);
109 if (getenv("SYNFIG_DEBUG_DESTRUCTORS"))
110 synfig::info("Duckmatic::~Duckmatic(): Deleted");
114 Duckmatic::clear_ducks()
116 duck_data_share_map.clear();
119 //duck_list_.clear();
120 bezier_list_.clear();
121 stroke_list_.clear();
123 if(show_persistent_strokes)
124 stroke_list_=persistent_stroke_list_;
127 //! Returns \a true if the given duck is currently selected
129 Duckmatic::duck_is_selected(const etl::handle<Duck> &duck)const
131 return duck && selected_ducks.count(duck->get_guid());
135 Duckmatic::set_grid_size(const synfig::Vector &s)
140 signal_grid_changed();
145 Duckmatic::set_grid_snap(bool x)
150 signal_grid_changed();
155 Duckmatic::set_guide_snap(bool x)
160 signal_grid_changed();
164 Duckmatic::GuideList::iterator
165 Duckmatic::find_guide_x(synfig::Point pos, float radius)
167 GuideList::iterator iter,best(guide_list_x_.end());
169 for(iter=guide_list_x_.begin();iter!=guide_list_x_.end();++iter)
171 float amount(abs(*iter-pos[0]));
181 Duckmatic::GuideList::iterator
182 Duckmatic::find_guide_y(synfig::Point pos, float radius)
184 GuideList::iterator iter,best(guide_list_y_.end());
186 for(iter=guide_list_y_.begin();iter!=guide_list_y_.end();++iter)
188 float amount(abs(*iter-pos[1]));
199 Duckmatic::clear_selected_ducks()
201 selected_ducks.clear();
202 signal_duck_selection_changed_();
205 etl::handle<Duckmatic::Duck>
206 Duckmatic::get_selected_duck()const
208 if(selected_ducks.empty() || duck_map.empty())
210 return duck_map.find(*selected_ducks.begin())->second;
214 Duckmatic::refresh_selected_ducks()
217 std::set<etl::handle<Duck> >::iterator iter;
218 std::set<etl::handle<Duck> > new_set;
219 if(duck_list().empty())
221 selected_duck_list.clear();
222 signal_duck_selection_changed_();
226 for(iter=selected_duck_list.begin();iter!=selected_duck_list.end();++iter)
228 etl::handle<Duck> similar(find_similar_duck(*iter));
231 new_set.insert(similar);
234 selected_duck_list=new_set;
236 GUIDSet old_set(selected_ducks);
237 GUIDSet::const_iterator iter;
239 for(iter=old_set.begin();iter!=old_set.end();++iter)
241 if(duck_map.count(*iter)==0)
242 selected_ducks.erase(*iter);
245 signal_duck_selection_changed_();
249 Duckmatic::is_duck_group_selectable(const etl::handle<Duck>& x)const
251 const Type type(get_type_mask());
253 if (((x->get_type() && (!(type & x->get_type()))) ||
257 synfigapp::ValueDesc value_desc(x->get_value_desc());
258 if(value_desc.parent_is_layer_param() && type & Duck::TYPE_POSITION)
260 Layer::Handle layer(value_desc.get_layer());
261 String layer_name(layer->get_name());
263 if (layer_name == "outline" || layer_name == "region" || layer_name == "plant" ||
264 layer_name == "polygon" || layer_name == "curve_gradient")
267 if((layer_name=="PasteCanvas"|| layer_name=="paste_canvas") &&
268 !layer->get_param("children_lock").get(bool()))
271 else if (value_desc.parent_is_value_node())
273 if (ValueNode_BLineCalcVertex::Handle::cast_dynamic(value_desc.get_value_node()))
275 if (value_desc.parent_is_linkable_value_node())
277 LinkableValueNode::Handle parent_value_node(value_desc.get_parent_value_node());
278 if (ValueNode_Composite::Handle::cast_dynamic(parent_value_node))
280 if (parent_value_node->get_type() == ValueBase::TYPE_BLINEPOINT &&
281 ValueNode_BLineCalcVertex::Handle::cast_dynamic(
282 parent_value_node->get_link("point")))
285 else if (ValueNode_BLine::Handle::cast_dynamic(parent_value_node))
287 ValueNode_Composite::Handle composite(ValueNode_Composite::Handle::cast_dynamic(
288 value_desc.get_value_node()));
290 ValueNode_BLineCalcVertex::Handle::cast_dynamic(composite->get_link("point")))
299 Duckmatic::select_all_ducks()
301 DuckMap::const_iterator iter;
302 for(iter=duck_map.begin();iter!=duck_map.end();++iter)
303 if(is_duck_group_selectable(iter->second))
304 select_duck(iter->second);
306 unselect_duck(iter->second);
310 Duckmatic::unselect_all_ducks()
312 DuckMap::const_iterator iter;
313 for(iter=duck_map.begin();iter!=duck_map.end();++iter)
314 unselect_duck(iter->second);
318 Duckmatic::toggle_select_ducks_in_box(const synfig::Vector& tl,const synfig::Vector& br)
321 vmin[0]=std::min(tl[0],br[0]);
322 vmin[1]=std::min(tl[1],br[1]);
323 vmax[0]=std::max(tl[0],br[0]);
324 vmax[1]=std::max(tl[1],br[1]);
326 DuckMap::const_iterator iter;
327 for(iter=duck_map.begin();iter!=duck_map.end();++iter)
329 Point p(iter->second->get_trans_point());
330 if(p[0]<=vmax[0] && p[0]>=vmin[0] && p[1]<=vmax[1] && p[1]>=vmin[1] &&
331 is_duck_group_selectable(iter->second))
332 toggle_select_duck(iter->second);
337 Duckmatic::select_ducks_in_box(const synfig::Vector& tl,const synfig::Vector& br)
340 vmin[0]=std::min(tl[0],br[0]);
341 vmin[1]=std::min(tl[1],br[1]);
342 vmax[0]=std::max(tl[0],br[0]);
343 vmax[1]=std::max(tl[1],br[1]);
345 // Type type(get_type_mask());
347 DuckMap::const_iterator iter;
348 for(iter=duck_map.begin();iter!=duck_map.end();++iter)
350 Point p(iter->second->get_trans_point());
351 if(p[0]<=vmax[0] && p[0]>=vmin[0] && p[1]<=vmax[1] && p[1]>=vmin[1])
353 if(is_duck_group_selectable(iter->second))
354 select_duck(iter->second);
360 Duckmatic::count_selected_ducks()const
362 return selected_ducks.size();
366 Duckmatic::select_duck(const etl::handle<Duck> &duck)
370 selected_ducks.insert(duck->get_guid());
371 signal_duck_selection_changed_();
376 Duckmatic::get_selected_ducks()const
379 GUIDSet::const_iterator iter;
380 const Type type(get_type_mask());
382 for(iter=selected_ducks.begin();iter!=selected_ducks.end();++iter)
384 const DuckMap::const_iterator d_iter(duck_map.find(*iter));
386 if(d_iter==duck_map.end())
389 if(( d_iter->second->get_type() && (!(type & d_iter->second->get_type())) ) )
392 ret.push_back(d_iter->second);
398 Duckmatic::get_duck_list()const
401 DuckMap::const_iterator iter;
402 for(iter=duck_map.begin();iter!=duck_map.end();++iter)
403 ret.push_back(iter->second);
408 Duckmatic::unselect_duck(const etl::handle<Duck> &duck)
410 if(duck && selected_ducks.count(duck->get_guid()))
412 selected_ducks.erase(duck->get_guid());
413 signal_duck_selection_changed_();
418 Duckmatic::toggle_select_duck(const etl::handle<Duck> &duck)
420 if(duck_is_selected(duck))
427 Duckmatic::translate_selected_ducks(const synfig::Vector& vector)
430 duck_dragger_->duck_drag(this,vector);
434 Duckmatic::start_duck_drag(const synfig::Vector& offset)
437 duck_dragger_->begin_duck_drag(this,offset);
439 //drag_offset_=offset;
440 drag_offset_=find_duck(offset)->get_trans_point();
444 Duckmatic::end_duck_drag()
447 return duck_dragger_->end_duck_drag(this);
452 Duckmatic::snap_point_to_grid(const synfig::Point& x, float radius)const
456 GuideList::const_iterator guide_x,guide_y;
457 bool has_guide_x(false), has_guide_y(false);
459 guide_x=find_guide_x(ret,radius);
460 if(guide_x!=guide_list_x_.end())
463 guide_y=find_guide_y(ret,radius);
464 if(guide_y!=guide_list_y_.end())
470 floor(ret[0]/get_grid_size()[0]+0.5)*get_grid_size()[0],
471 floor(ret[1]/get_grid_size()[1]+0.5)*get_grid_size()[1]);
473 if(abs(snap[0]-ret[0])<=radius && (!has_guide_x || abs(snap[0]-ret[0])<=abs(*guide_x-ret[0])))
474 ret[0]=snap[0],has_guide_x=false;
475 if(abs(snap[1]-ret[1])<=radius && (!has_guide_y || abs(snap[1]-ret[1])<=abs(*guide_y-ret[1])))
476 ret[1]=snap[1],has_guide_y=false;
490 if(abs(ret[0])<abs(ret[1]))
501 DuckDrag_Translate::begin_duck_drag(Duckmatic* duckmatic, const synfig::Vector& offset)
503 last_translate_=Vector(0,0);
505 drag_offset_=duckmatic->find_duck(offset)->get_trans_point();
510 const DuckList selected_ducks(duckmatic->get_selected_ducks());
511 DuckList::const_iterator iter;
514 for(iter=selected_ducks.begin();iter!=selected_ducks.end();++iter)
516 Point p((*iter)->get_trans_point());
517 positions.push_back(p);
522 DuckDrag_Translate::end_duck_drag(Duckmatic* duckmatic)
524 if(last_translate_.mag()>0.0001)
526 duckmatic->signal_edited_selected_ducks();
531 duckmatic->signal_user_click_selected_ducks(0);
537 DuckDrag_Translate::duck_drag(Duckmatic* duckmatic, const synfig::Vector& vector)
539 const DuckList selected_ducks(duckmatic->get_selected_ducks());
540 DuckList::const_iterator iter;
542 synfig::Vector vect(duckmatic->snap_point_to_grid(vector)-drag_offset_);
544 Time time(duckmatic->get_time());
546 // drag the vertex and position ducks first
547 for (i=0,iter=selected_ducks.begin(); iter!=selected_ducks.end(); ++iter,i++)
549 etl::handle<Duck> duck(*iter);
550 if(duck->get_type() == Duck::TYPE_VERTEX || duck->get_type() == Duck::TYPE_POSITION)
552 duck->set_trans_point(positions[i]+vect);
554 ValueNode_BLineCalcVertex::Handle bline_vertex;
555 ValueNode_Composite::Handle composite;
557 if ((bline_vertex = ValueNode_BLineCalcVertex::Handle::cast_dynamic(duck->get_value_desc().get_value_node())) ||
558 ((composite = ValueNode_Composite::Handle::cast_dynamic(duck->get_value_desc().get_value_node())) &&
559 composite->get_type() == ValueBase::TYPE_BLINEPOINT &&
560 (bline_vertex = ValueNode_BLineCalcVertex::Handle::cast_dynamic(composite->get_link("point")))))
562 synfig::Point closest_point = duck->get_point();
563 synfig::Real radius = 0.0;
564 ValueNode_BLine::Handle bline = ValueNode_BLine::Handle::cast_dynamic(bline_vertex->get_link(bline_vertex->get_link_index_from_name("bline")));
565 synfig::find_closest_point(
571 duck->set_point(closest_point);
576 // then drag the others
577 for (i=0,iter=selected_ducks.begin(); iter!=selected_ducks.end(); ++iter,i++)
578 if ((*iter)->get_type() != Duck::TYPE_VERTEX && (*iter)->get_type() != Duck::TYPE_POSITION)
579 (*iter)->set_trans_point(positions[i]+vect);
581 // then patch up the tangents for the vertices we've moved
582 DuckList duck_list(duckmatic->get_duck_list());
583 for (iter=selected_ducks.begin(); iter!=selected_ducks.end(); ++iter)
585 etl::handle<Duck> duck(*iter);
586 if (duck->get_type() == Duck::TYPE_VERTEX || duck->get_type() == Duck::TYPE_POSITION)
588 ValueNode_BLineCalcVertex::Handle bline_vertex;
589 ValueNode_Composite::Handle composite;
591 if ((bline_vertex = ValueNode_BLineCalcVertex::Handle::cast_dynamic(duck->get_value_desc().get_value_node())) ||
592 ((composite = ValueNode_Composite::Handle::cast_dynamic(duck->get_value_desc().get_value_node())) &&
593 composite->get_type() == ValueBase::TYPE_BLINEPOINT &&
594 (bline_vertex = ValueNode_BLineCalcVertex::Handle::cast_dynamic(composite->get_link("point")))))
596 synfig::Real radius = 0.0;
597 ValueNode_BLine::Handle bline(ValueNode_BLine::Handle::cast_dynamic(bline_vertex->get_link(bline_vertex->get_link_index_from_name("bline"))));
598 Real amount = synfig::find_closest_point((*bline)(time), duck->get_point(), radius, bline->get_loop());
600 int vertex_amount_index(bline_vertex->get_link_index_from_name("amount"));
601 ValueNode::Handle vertex_amount_value_node(bline_vertex->get_link(vertex_amount_index));
603 DuckList::iterator iter;
604 for (iter=duck_list.begin(); iter!=duck_list.end(); iter++)
606 ValueNode::Handle duck_value_node((*iter)->get_value_desc().get_value_node());
607 if (ValueNode_BLineCalcTangent::Handle bline_tangent = ValueNode_BLineCalcTangent::Handle::cast_dynamic(duck_value_node))
609 if (bline_tangent->get_link(bline_tangent->get_link_index_from_name("amount")) == vertex_amount_value_node)
611 switch (bline_tangent->get_type())
613 case ValueBase::TYPE_ANGLE:
615 Angle angle((*bline_tangent)(time, amount).get(Angle()));
616 (*iter)->set_point(Point(Angle::cos(angle).get(), Angle::sin(angle).get()));
619 case ValueBase::TYPE_REAL:
620 (*iter)->set_point(Point((*bline_tangent)(time, amount).get(Real()), 0));
622 case ValueBase::TYPE_VECTOR:
623 (*iter)->set_point((*bline_tangent)(time, amount).get(Vector()));
630 else if (ValueNode_BLineCalcWidth::Handle bline_width = ValueNode_BLineCalcWidth::Handle::cast_dynamic(duck_value_node))
632 if (bline_width->get_link(bline_width->get_link_index_from_name("amount")) == vertex_amount_value_node)
633 (*iter)->set_point(Point((*bline_width)(time, amount).get(Real()), 0));
640 last_translate_=vect;
644 Duckmatic::signal_edited_selected_ducks()
646 const DuckList ducks(get_selected_ducks());
647 DuckList::const_iterator iter;
649 synfig::GUIDSet old_set(selected_ducks);
651 // If we have more than 20 things to move, then display
652 // something to explain that it may take a moment
653 smart_ptr<OneMoment> wait; if(ducks.size()>20)wait.spawn();
655 // Go ahead and call everyone's signals
656 for(iter=ducks.begin();iter!=ducks.end();++iter)
658 if ((*iter)->get_type() == Duck::TYPE_ANGLE)
660 if(!(*iter)->signal_edited_angle()((*iter)->get_rotations()))
662 selected_ducks=old_set;
663 throw String("Bad edit");
666 else if (App::restrict_radius_ducks &&
667 (*iter)->is_radius())
669 Point point((*iter)->get_point());
670 bool changed = false;
683 if (changed) (*iter)->set_point(point);
685 if(!(*iter)->signal_edited()(point))
687 selected_ducks=old_set;
688 throw String("Bad edit");
693 if(!(*iter)->signal_edited()((*iter)->get_point()))
695 selected_ducks=old_set;
696 throw String("Bad edit");
700 selected_ducks=old_set;
704 Duckmatic::signal_user_click_selected_ducks(int button)
706 const DuckList ducks(get_selected_ducks());
707 DuckList::const_iterator iter;
709 for(iter=ducks.begin();iter!=ducks.end();++iter)
711 (*iter)->signal_user_click(button)();
716 Duckmatic::add_duck(const etl::handle<Duck> &duck)
718 //if(!duck_map.count(duck->get_guid()))
720 if(duck_data_share_map.count(duck->get_data_guid()))
722 duck->set_shared_point(duck_data_share_map[duck->get_data_guid()]);
726 etl::smart_ptr<synfig::Point> point(new Point(duck->get_point()));
727 duck->set_shared_point(point);
728 duck_data_share_map[duck->get_data_guid()]=point;
731 duck_map.insert(duck);
734 last_duck_guid=duck->get_guid();
738 Duckmatic::add_bezier(const etl::handle<Bezier> &bezier)
740 bezier_list_.push_back(bezier);
744 Duckmatic::add_stroke(etl::smart_ptr<std::list<synfig::Point> > stroke_point_list, const synfig::Color& color)
746 assert(stroke_point_list);
748 std::list<etl::handle<Stroke> >::iterator iter;
750 for(iter=stroke_list_.begin();iter!=stroke_list_.end();++iter)
752 if((*iter)->stroke_data==stroke_point_list)
756 etl::handle<Stroke> stroke(new Stroke());
758 stroke->stroke_data=stroke_point_list;
761 stroke_list_.push_back(stroke);
765 Duckmatic::add_persistent_stroke(etl::smart_ptr<std::list<synfig::Point> > stroke_point_list, const synfig::Color& color)
767 add_stroke(stroke_point_list,color);
768 persistent_stroke_list_.push_back(stroke_list_.back());
772 Duckmatic::clear_persistent_strokes()
774 persistent_stroke_list_.clear();
778 Duckmatic::set_show_persistent_strokes(bool x)
780 if(x!=show_persistent_strokes)
782 show_persistent_strokes=x;
784 stroke_list_=persistent_stroke_list_;
786 stroke_list_.clear();
791 Duckmatic::erase_duck(const etl::handle<Duck> &duck)
793 duck_map.erase(duck->get_guid());
796 etl::handle<Duckmatic::Duck>
797 Duckmatic::find_similar_duck(etl::handle<Duck> duck)
799 DuckMap::const_iterator iter(duck_map.find(duck->get_guid()));
800 if(iter!=duck_map.end())
804 /* std::list<handle<Duck> >::reverse_iterator iter;
806 for(iter=duck_list_.rbegin();iter!=duck_list_.rend();++iter)
808 if(*iter!=duck && **iter==*duck)
810 //synfig::info("Found similar duck! (iter:%08x vs. duck:%08x)",iter->get(), duck.get());
818 etl::handle<Duckmatic::Duck>
819 Duckmatic::add_similar_duck(etl::handle<Duck> duck)
821 etl::handle<Duck> similar(find_similar_duck(duck));
831 Duckmatic::erase_bezier(const etl::handle<Bezier> &bezier)
833 std::list<handle<Bezier> >::iterator iter;
835 for(iter=bezier_list_.begin();iter!=bezier_list_.end();++iter)
839 bezier_list_.erase(iter);
843 synfig::warning("Unable to find bezier to erase!");
846 etl::handle<Duckmatic::Duck>
847 Duckmatic::last_duck()const
849 DuckMap::const_iterator iter(duck_map.find(last_duck_guid));
850 if(iter!=duck_map.end())
855 etl::handle<Duckmatic::Bezier>
856 Duckmatic::last_bezier()const
858 return bezier_list_.back();
861 etl::handle<Duckmatic::Duck>
862 Duckmatic::find_duck(synfig::Point point, synfig::Real radius, Duck::Type type)
864 if(radius==0)radius=10000000;
866 if(type==Duck::TYPE_DEFAULT)
867 type=get_type_mask();
869 Real closest(10000000);
870 etl::handle<Duck> ret;
872 DuckMap::const_iterator iter;
874 for(iter=duck_map.begin();iter!=duck_map.end();++iter)
876 const Duck::Handle& duck(iter->second);
878 if(duck->get_ignore())
880 Real dist((duck->get_trans_point()-point).mag_squared());
882 if(duck->get_type()&Duck::TYPE_VERTEX)
884 else if(duck->get_type()&Duck::TYPE_RADIUS)
887 if(dist<=closest && !( duck->get_type() && (!(type & duck->get_type())) ) )
896 if(radius==0 || closest<radius*radius)
902 etl::handle<Duckmatic::Bezier>
903 Duckmatic::find_bezier(synfig::Point point, synfig::Real radius,float* location)
905 return find_bezier(point,radius,radius,location);
908 etl::handle<Duckmatic::Bezier>
909 Duckmatic::find_bezier(synfig::Point pos, synfig::Real scale, synfig::Real radius, float* location)
911 if(radius==0)radius=10000000;
912 Real closest(10000000);
913 etl::handle<Bezier> ret;
921 for(std::list<handle<Bezier> >::const_iterator iter=bezier_list().begin();iter!=bezier_list().end();++iter)
923 curve[0] = (*iter)->p1->get_trans_point();
924 curve[1] = (*iter)->c1->get_trans_point();
925 curve[2] = (*iter)->c2->get_trans_point();
926 curve[3] = (*iter)->p2->get_trans_point();
930 // I don't know why this doesn't work
931 time=curve.find_closest(pos,6);
932 d=((curve(time)-pos).mag_squared());
935 //set the step size based on the size of the picture
936 d = (curve[1] - curve[0]).mag() + (curve[2]-curve[1]).mag() + (curve[3]-curve[2]).mag();
938 step = d/(2*scale); //want to make the distance between lines happy
940 step = max(step,0.01); //100 samples should be plenty
941 step = min(step,0.1); //10 is minimum
943 d = find_closest(curve,pos,step,&closest,&time);
954 if(closest < radius*radius)
957 *location = best_time; // We need to square-root this because we were dealing with squared distances
966 Duckmatic::save_sketch(const synfig::String& filename)const
968 ChangeLocale change_locale(LC_NUMERIC, "C");
969 std::ofstream file(filename.c_str());
971 if(!file)return false;
973 file<<"SKETCH"<<endl;
975 std::list<etl::handle<Stroke> >::const_iterator iter;
977 for(iter=persistent_stroke_list_.begin();iter!=persistent_stroke_list_.end();++iter)
980 <<(*iter)->color.get_r()<<' '
981 <<(*iter)->color.get_g()<<' '
982 <<(*iter)->color.get_b()
984 std::list<synfig::Point>::const_iterator viter;
985 for(viter=(*iter)->stroke_data->begin();viter!=(*iter)->stroke_data->end();++viter)
993 if(!file)return false;
994 sketch_filename_=filename;
995 signal_sketch_saved_();
1000 Duckmatic::load_sketch(const synfig::String& filename)
1002 ChangeLocale change_locale(LC_NUMERIC, "C");
1003 std::ifstream file(filename.c_str());
1013 synfig::error("Not a sketch");
1017 etl::smart_ptr<std::list<synfig::Point> > stroke_data;
1031 stroke_data.spawn();
1033 if(!strscanf(line,"C %f %f %f",&r, &g, &b))
1035 synfig::warning("Bad color line \"%s\"",line.c_str());
1038 add_persistent_stroke(stroke_data, synfig::Color(r,g,b));
1045 stroke_data.spawn();
1046 add_persistent_stroke(stroke_data, synfig::Color(0,0,0));
1049 if(!strscanf(line,"V %f %f",&x, &y))
1050 synfig::warning("Bad vertex \"%s\"",line.c_str());
1052 stroke_data->push_back(synfig::Vector(x,y));
1055 synfig::warning("Unexpected sketch token '%c'",line[0]);
1060 sketch_filename_=filename;
1064 Duckmatic::Push::Push(Duckmatic *duckmatic_):
1065 duckmatic_(duckmatic_)
1067 duck_map=duckmatic_->duck_map;
1068 bezier_list_=duckmatic_->bezier_list_;
1069 duck_data_share_map=duckmatic_->duck_data_share_map;
1070 stroke_list_=duckmatic_->stroke_list_;
1071 duck_dragger_=duckmatic_->duck_dragger_;
1075 Duckmatic::Push::~Push()
1082 Duckmatic::Push::restore()
1084 duckmatic_->duck_map=duck_map;
1085 duckmatic_->bezier_list_=bezier_list_;
1086 duckmatic_->duck_data_share_map=duck_data_share_map;
1087 duckmatic_->stroke_list_=stroke_list_;
1088 duckmatic_->duck_dragger_=duck_dragger_;
1089 needs_restore=false;
1092 inline String guid_string(const synfigapp::ValueDesc& x)
1094 if(x.parent_is_layer_param())
1095 return strprintf("%s",x.get_layer()->get_guid().get_string().c_str())+x.get_param_name();
1096 //if(x.is_value_node())
1097 return strprintf("%s",x.get_value_node()->get_guid().get_string().c_str());
1100 inline synfig::GUID calc_duck_guid(const synfigapp::ValueDesc& x,const synfig::TransformStack& transform_stack)
1102 synfig::GUID ret(0);
1104 if(x.parent_is_layer_param())
1106 ret=x.get_layer()->get_guid()^synfig::GUID::hasher(x.get_param_name());
1110 ret=x.get_value_node()->get_guid();
1113 ret^=transform_stack.get_guid();
1119 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)
1121 synfig::GUID duck_guid(calc_duck_guid(value_desc,transform_stack)^synfig::GUID::hasher(modifier));
1122 etl::handle<Duck> duck=new Duck();
1129 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)
1131 ValueBase::Type type=value_desc.get_value_type();
1132 #define REAL_COOKIE reinterpret_cast<synfig::ParamDesc*>(28)
1135 case ValueBase::TYPE_REAL:
1137 if(!param_desc || param_desc==REAL_COOKIE || !param_desc->get_origin().empty())
1139 etl::handle<Duck> duck=new Duck();
1140 duck->set_transform_stack(transform_stack);
1141 duck->set_radius(true);
1142 duck->set_type(Duck::TYPE_RADIUS);
1144 // put the duck on the right hand side of the center
1145 duck->set_point(Point(value_desc.get_value(get_time()).get(Real()), 0));
1146 duck->set_name(guid_string(value_desc));
1147 if(value_desc.is_value_node())
1149 // If the ValueNode can be directly manipulated,
1150 // then set it as so.
1151 duck->set_editable(synfigapp::is_editable(value_desc.get_value_node()));
1155 duck->set_editable(true);
1158 if(param_desc && param_desc!=REAL_COOKIE)
1160 if(!param_desc->get_origin().empty())
1162 synfigapp::ValueDesc value_desc_origin(value_desc.get_layer(),param_desc->get_origin());
1164 duck->set_origin(value_desc_origin.get_value(get_time()).get(synfig::Point()));
1166 add_to_ducks(value_desc_origin,canvas_view, transform_stack);
1167 duck->set_origin(last_duck());
1169 duck->set_scalar(param_desc->get_scalar());
1172 duck->signal_edited().clear(); // value_desc.get_value_type() == ValueBase::TYPE_REAL:
1173 duck->signal_edited().connect(
1177 &studio::CanvasView::on_duck_changed),
1179 duck->set_value_desc(value_desc);
1181 duck->signal_user_click(2).connect(
1187 &studio::CanvasView::popup_param_menu),
1192 duck->set_guid(calc_duck_guid(value_desc,transform_stack)^synfig::GUID::hasher(multiple));
1200 case ValueBase::TYPE_ANGLE:
1202 if(!param_desc || param_desc==REAL_COOKIE || !param_desc->get_origin().empty())
1204 etl::handle<Duck> duck=new Duck();
1205 duck->set_type(Duck::TYPE_ANGLE);
1206 duck->set_transform_stack(transform_stack);
1207 synfig::Angle angle;
1209 angle=value_desc.get_value(get_time()).get(Angle());
1210 duck->set_point(Point(Angle::cos(angle).get(),Angle::sin(angle).get()));
1211 duck->set_name(guid_string(value_desc));
1212 if(value_desc.is_value_node())
1214 ValueNode::Handle value_node=value_desc.get_value_node();
1215 //duck->set_name(strprintf("%x",value_node.get()));
1217 // If the ValueNode can be directly manipulated,
1218 // then set it as so.
1219 duck->set_editable(synfigapp::is_editable(value_desc.get_value_node()));
1223 //angle=(value_desc.get_value().get(Angle()));
1224 //duck->set_point(Point(Angle::cos(angle).get(),Angle::sin(angle).get()));
1225 //duck->set_name(strprintf("%x",value_desc.get_layer().get())+value_desc.get_param_name());
1226 duck->set_editable(true);
1229 if(param_desc && param_desc!=REAL_COOKIE)
1231 if(!param_desc->get_origin().empty())
1233 synfigapp::ValueDesc value_desc_origin(value_desc.get_layer(),param_desc->get_origin());
1235 duck->set_origin(value_desc_origin.get_value(get_time()).get(synfig::Point()));
1237 add_to_ducks(value_desc_origin,canvas_view, transform_stack);
1238 duck->set_origin(last_duck());
1240 duck->set_scalar(param_desc->get_scalar());
1243 duck->signal_edited().clear(); // value_desc.get_value_type() == ValueBase::TYPE_ANGLE:
1244 duck->signal_edited_angle().clear();
1245 duck->signal_edited_angle().connect(
1249 &studio::CanvasView::on_duck_angle_changed),
1251 duck->set_value_desc(value_desc);
1253 duck->signal_user_click(2).connect(
1259 &studio::CanvasView::popup_param_menu),
1263 duck->set_guid(calc_duck_guid(value_desc,transform_stack)^synfig::GUID::hasher(multiple));
1271 case ValueBase::TYPE_VECTOR:
1273 etl::handle<Duck> duck=new Duck();
1274 duck->set_transform_stack(transform_stack);
1276 duck->set_point(value_desc.get_value(get_time()).get(Point()));
1277 duck->set_name(guid_string(value_desc));
1278 if(value_desc.is_value_node())
1280 //duck->set_name(strprintf("%x",value_desc.get_value_node().get()));
1282 // If the ValueNode can be directly manipulated,
1283 // then set it as so.
1284 duck->set_editable(synfigapp::is_editable(value_desc.get_value_node()));
1288 //duck->set_point(value_desc.get_value().get(Point()));
1289 //duck->set_name(strprintf("%x",value_desc.get_layer().get())+value_desc.get_param_name());
1290 duck->set_editable(true);
1293 // If we were passed a parameter description
1296 if(!param_desc->get_connect().empty())
1298 synfigapp::ValueDesc value_desc_origin(value_desc.get_layer(),param_desc->get_connect());
1299 Duck::Handle connect_duck;
1300 if(duck_map.find(calc_duck_guid(value_desc_origin,transform_stack)^synfig::GUID::hasher(0))!=duck_map.end())
1302 connect_duck=duck_map[calc_duck_guid(value_desc_origin,transform_stack)^synfig::GUID::hasher(0)];
1306 add_to_ducks(value_desc_origin,canvas_view, transform_stack);
1307 connect_duck=last_duck();
1309 duck->set_connect_duck(connect_duck);
1311 if(!param_desc->get_box().empty())
1313 synfigapp::ValueDesc value_desc_origin(value_desc.get_layer(),param_desc->get_box());
1314 add_to_ducks(value_desc_origin,canvas_view, transform_stack);
1315 duck->set_box_duck(last_duck());
1318 // If we have an origin
1319 if(!param_desc->get_origin().empty())
1321 synfigapp::ValueDesc value_desc_origin(value_desc.get_layer(),param_desc->get_origin());
1323 duck->set_origin(value_desc_origin.get_value(get_time()).get(synfig::Point()));
1325 add_to_ducks(value_desc_origin,canvas_view, transform_stack);
1326 duck->set_origin(last_duck());
1327 duck->set_type(Duck::TYPE_VERTEX);
1330 duck->set_type(Duck::TYPE_POSITION);
1332 duck->set_scalar(param_desc->get_scalar());
1335 duck->set_type(Duck::TYPE_POSITION);
1337 duck->signal_edited().clear(); // value_desc.get_value_type() == ValueBase::TYPE_VECTOR:
1338 duck->signal_edited().connect(
1342 &studio::CanvasView::on_duck_changed),
1344 duck->set_value_desc(value_desc);
1346 duck->signal_user_click(2).connect(
1352 &studio::CanvasView::popup_param_menu),
1356 duck->set_guid(calc_duck_guid(value_desc,transform_stack)^synfig::GUID::hasher(multiple));
1362 case ValueBase::TYPE_SEGMENT:
1364 etl::handle<Bezier> bezier(new Bezier());
1365 ValueNode_Composite::Handle value_node;
1367 if(value_desc.is_value_node() &&
1368 (value_node=ValueNode_Composite::Handle::cast_dynamic(value_desc.get_value_node())))
1370 if(!add_to_ducks(synfigapp::ValueDesc(value_node,0),canvas_view,transform_stack))
1372 bezier->p1=last_duck();
1373 bezier->p1->set_type(Duck::TYPE_VERTEX);
1374 if(!add_to_ducks(synfigapp::ValueDesc(value_node,1),canvas_view,transform_stack))
1376 bezier->c1=last_duck();
1377 bezier->c1->set_type(Duck::TYPE_TANGENT);
1378 bezier->c1->set_origin(bezier->p1);
1379 bezier->c1->set_scalar(TANGENT_BEZIER_SCALE);
1380 bezier->c1->set_tangent(true);
1382 if(!add_to_ducks(synfigapp::ValueDesc(value_node,2),canvas_view,transform_stack))
1384 bezier->p2=last_duck();
1385 bezier->p2->set_type(Duck::TYPE_VERTEX);
1386 if(!add_to_ducks(synfigapp::ValueDesc(value_node,3),canvas_view,transform_stack))
1388 bezier->c2=last_duck();
1389 bezier->c2->set_type(Duck::TYPE_TANGENT);
1390 bezier->c2->set_origin(bezier->p2);
1391 bezier->c2->set_scalar(-TANGENT_BEZIER_SCALE);
1392 bezier->c2->set_tangent(true);
1394 bezier->signal_user_click(2).connect(
1398 &studio::CanvasView::popup_param_menu_bezier),
1403 else if(value_desc.get_value().is_valid())
1405 Segment segment=value_desc.get_value();
1406 etl::handle<Duck> duck_p,duck_c;
1407 synfig::String name;
1410 name=param_desc->get_local_name();
1414 name=guid_string(value_desc);
1417 duck_p=new Duck(segment.p1);
1418 duck_p->set_name(name+".P1");
1419 duck_p->set_type(Duck::TYPE_VERTEX);
1422 duck_c=new Duck(segment.t1);
1423 duck_c->set_name(name+".T1");
1424 duck_c->set_type(Duck::TYPE_TANGENT);
1426 duck_c->set_origin(duck_p);
1427 duck_c->set_scalar(TANGENT_HANDLE_SCALE);
1428 duck_c->set_tangent(true);
1433 duck_p=new Duck(segment.p2);
1434 duck_p->set_name(name+".P2");
1435 duck_p->set_type(Duck::TYPE_VERTEX);
1438 duck_c=new Duck(segment.t2);
1439 duck_c->set_type(Duck::TYPE_TANGENT);
1440 duck_c->set_name(name+".T2");
1442 duck_c->set_origin(duck_p);
1443 duck_c->set_scalar(-TANGENT_HANDLE_SCALE);
1444 duck_c->set_tangent(true);
1454 case ValueBase::TYPE_BLINEPOINT:
1457 if(value_desc.is_value_node() &&
1458 ValueNode_Composite::Handle::cast_dynamic(value_desc.get_value_node()))
1460 ValueNode_Composite::Handle value_node;
1461 value_node=ValueNode_Composite::Handle::cast_dynamic(value_desc.get_value_node());
1463 if(!add_to_ducks(synfigapp::ValueDesc(value_node,0),canvas_view,transform_stack))
1465 etl::handle<Duck> vertex_duck(last_duck());
1466 vertex_duck->set_type(Duck::TYPE_VERTEX);
1467 if(!add_to_ducks(synfigapp::ValueDesc(value_node,4),canvas_view,transform_stack))
1469 etl::handle<Duck> t1_duck(last_duck());
1471 t1_duck->set_origin(vertex_duck);
1472 t1_duck->set_scalar(-TANGENT_HANDLE_SCALE);
1473 t1_duck->set_tangent(true);
1475 etl::handle<Duck> t2_duck;
1477 // If the tangents are split
1478 if((*value_node->get_link("split"))(get_time()).get(bool()))
1480 if(!add_to_ducks(synfigapp::ValueDesc(value_node,5),canvas_view,transform_stack))
1482 t2_duck=last_duck();
1483 t2_duck->set_origin(vertex_duck);
1484 t2_duck->set_scalar(TANGENT_HANDLE_SCALE);
1485 t2_duck->set_tangent(true);
1489 if(!add_to_ducks(synfigapp::ValueDesc(value_node,4),canvas_view,transform_stack))
1491 t2_duck=last_duck();
1492 t2_duck->set_origin(vertex_duck);
1493 t2_duck->set_scalar(TANGENT_HANDLE_SCALE);
1494 t2_duck->set_tangent(true);
1501 case ValueBase::TYPE_LIST:
1504 if (value_desc.is_value_node() &&
1505 ValueNode_BLine::Handle::cast_dynamic(value_desc.get_value_node()))
1507 ValueNode_BLine::Handle value_node;
1508 value_node=ValueNode_BLine::Handle::cast_dynamic(value_desc.get_value_node());
1512 etl::handle<Bezier> bezier;
1513 etl::handle<Duck> first_duck;
1514 etl::handle<Duck> duck, tduck;
1516 for (i = 0; i < value_node->link_count(); i++)
1518 float amount(value_node->list[i].amount_at_time(get_time()));
1520 // skip vertices that aren't fully on
1521 if (amount < 0.9999f)
1524 // remember the index of the first vertex we didn't skip
1528 BLinePoint bline_point((*value_node->get_link(i))(get_time()));
1530 // try casting the vertex to Composite - this tells us whether it is composite or not
1531 ValueNode_Composite::Handle composite_vertex_value_node(
1532 ValueNode_Composite::Handle::cast_dynamic(value_node->get_link(i)));
1534 // add the vertex duck - it's a composite
1535 if(composite_vertex_value_node)
1537 if (add_to_ducks(synfigapp::ValueDesc(composite_vertex_value_node,0),canvas_view,transform_stack))
1542 duck->set_type(Duck::TYPE_VERTEX);
1544 duck->signal_user_click(2).clear();
1545 duck->signal_user_click(2).connect(
1551 &studio::CanvasView::popup_param_menu),
1554 synfigapp::ValueDesc(value_node,i)));
1555 duck->set_value_desc(synfigapp::ValueDesc(value_node,i));
1559 if(!param_desc->get_origin().empty())
1561 synfigapp::ValueDesc value_desc_origin(value_desc.get_layer(),param_desc->get_origin());
1562 add_to_ducks(value_desc_origin,canvas_view, transform_stack);
1563 duck->set_origin(last_duck());
1565 ValueBase value(synfigapp::ValueDesc(value_desc.get_layer(),param_desc->get_origin()).get_value(get_time()));
1566 if(value.same_type_as(synfig::Point()))
1567 duck->set_origin(value.get(synfig::Point()));
1575 // else it's not a composite
1578 duck=new Duck(bline_point.get_vertex());
1581 duck->set_transform_stack(transform_stack);
1582 duck->set_editable(false);
1583 //duck->set_name(strprintf("%x-vertex",value_node->get_link(i).get()));
1584 duck->set_name(guid_string(synfigapp::ValueDesc(value_node,i))+".v");
1586 duck->set_type(Duck::TYPE_VERTEX);
1589 if(!param_desc->get_origin().empty())
1591 synfigapp::ValueDesc value_desc_origin(value_desc.get_layer(),param_desc->get_origin());
1592 add_to_ducks(value_desc_origin,canvas_view, transform_stack);
1593 duck->set_origin(last_duck());
1595 ValueBase value(synfigapp::ValueDesc(value_desc.get_layer(),param_desc->get_origin()).get_value(get_time()));
1596 if(value.same_type_as(synfig::Point()))
1597 duck->set_origin(value.get(synfig::Point()));
1601 duck->set_guid(calc_duck_guid(synfigapp::ValueDesc(value_node,i),transform_stack)^synfig::GUID::hasher(".v"));
1602 duck=add_similar_duck(duck);
1606 // Add the width duck if it is a parameter with a hint (ie. "width") or if it isn't a parameter
1607 if ((param_desc && !param_desc->get_hint().empty()) ||
1610 etl::handle<Duck> width;
1611 if (add_to_ducks(synfigapp::ValueDesc(composite_vertex_value_node,1),canvas_view,transform_stack,REAL_COOKIE))
1614 width->set_origin(duck);
1615 width->set_type(Duck::TYPE_WIDTH);
1616 width->set_name(guid_string(synfigapp::ValueDesc(value_node,i))+".w");
1618 // if the bline is a layer's parameter, scale the width duck by the layer's "width" parameter
1621 ValueBase value(synfigapp::ValueDesc(value_desc.get_layer(),param_desc->get_hint()).get_value(get_time()));
1622 if(value.same_type_as(synfig::Real()))
1623 width->set_scalar(value.get(synfig::Real())*0.5f);
1624 // if it doesn't have a "width" parameter, scale by 0.5f instead
1626 width->set_scalar(0.5f);
1628 // otherwise just present the raw unscaled width
1630 width->set_scalar(0.5f);
1633 synfig::error("Unable to add width duck!");
1636 // each bezier uses t2 of one point and t1 of the next
1637 // the first time through this loop we won't have the t2 duck from the previous vertex
1638 // and so we don't make a bezier. instead we skip on to t2 for this point
1641 // Add the tangent1 duck
1642 if(composite_vertex_value_node)
1644 if(!add_to_ducks(synfigapp::ValueDesc(composite_vertex_value_node,4),canvas_view,transform_stack))
1650 tduck=new Duck(bline_point.get_tangent1());
1651 tduck->set_transform_stack(transform_stack);
1652 tduck->set_editable(false);
1653 tduck->set_name(guid_string(synfigapp::ValueDesc(value_node,i))+".t1");
1654 // tduck->set_name(strprintf("%x-tangent1",value_node->get_link(i).get()));
1655 tduck->set_guid(calc_duck_guid(synfigapp::ValueDesc(value_node,i),transform_stack)^synfig::GUID::hasher(".t1"));
1656 tduck=add_similar_duck(tduck);
1660 tduck->set_origin(duck);
1661 tduck->set_scalar(-TANGENT_BEZIER_SCALE);
1662 tduck->set_tangent(true);
1667 bezier->signal_user_click(2).connect(
1671 &studio::CanvasView::popup_param_menu_bezier),
1672 synfigapp::ValueDesc(value_node,i)));
1674 duck->signal_user_click(2).clear();
1675 duck->signal_user_click(2).connect(
1681 &studio::CanvasView::popup_param_menu),
1684 synfigapp::ValueDesc(value_node,i)));
1685 duck->set_value_desc(synfigapp::ValueDesc(value_node,i));
1691 // don't start a new bezier for the last point in the line if we're not looped
1692 if(i+1>=value_node->link_count() && !value_node->get_loop())
1695 bezier=new Bezier();
1697 // Add the tangent2 duck
1698 if(composite_vertex_value_node)
1700 int i=bline_point.get_split_tangent_flag()?5:4;
1701 if(!add_to_ducks(synfigapp::ValueDesc(composite_vertex_value_node,i),canvas_view,transform_stack,0,2))
1707 if(bline_point.get_split_tangent_flag())
1708 tduck=new Duck(bline_point.get_tangent2());
1710 tduck=new Duck(bline_point.get_tangent1());
1712 tduck->set_transform_stack(transform_stack);
1713 tduck->set_name(guid_string(synfigapp::ValueDesc(value_node,i))+".t2");
1714 tduck->set_guid(calc_duck_guid(synfigapp::ValueDesc(value_node,i),transform_stack)^synfig::GUID::hasher(".t2"));
1715 tduck->set_editable(false);
1716 tduck=add_similar_duck(tduck);
1720 synfigapp::ValueDesc value_desc_origin(value_desc.get_layer(),param_desc->get_origin());
1721 add_to_ducks(value_desc_origin,canvas_view, transform_stack);
1722 duck->set_origin(last_duck());
1724 ValueBase value(synfigapp::ValueDesc(value_desc.get_layer(),param_desc->get_origin()).get_value(get_time()));
1725 if(value.same_type_as(synfig::Point()))
1726 duck->set_origin(value.get(synfig::Point()));
1728 // if(!param_desc->get_origin().empty())
1729 // duck->set_origin(synfigapp::ValueDesc(value_desc.get_layer(),param_desc->get_origin()).get_value(get_time()).get(synfig::Point()));
1731 duck->signal_user_click(2).clear();
1732 duck->signal_user_click(2).connect(
1738 &studio::CanvasView::popup_param_menu),
1741 synfigapp::ValueDesc(value_node,i)));
1742 duck->set_value_desc(synfigapp::ValueDesc(value_node,i));
1746 tduck->set_origin(duck);
1747 tduck->set_scalar(TANGENT_BEZIER_SCALE);
1748 tduck->set_tangent(true);
1754 // Loop if necessary
1755 if(bezier && value_node->get_loop())
1757 BLinePoint bline_point((*value_node->get_link(first))(get_time()));
1759 ValueNode_Composite::Handle composite_vertex_value_node(
1760 ValueNode_Composite::Handle::cast_dynamic(
1761 value_node->get_link(first)));
1763 // Add the vertex duck
1766 // Add the tangent1 duck
1767 if(composite_vertex_value_node)
1769 if(!add_to_ducks(synfigapp::ValueDesc(composite_vertex_value_node,4),canvas_view,transform_stack))
1775 tduck=new Duck(bline_point.get_tangent1());
1776 tduck->set_transform_stack(transform_stack);
1777 tduck->set_editable(false);
1778 tduck->set_name(guid_string(synfigapp::ValueDesc(value_node,first))+".t1");
1779 //tduck->set_name(strprintf("%x-tangent1",value_node->get_link(first).get()));
1780 tduck=add_similar_duck(tduck);
1781 tduck->set_guid(calc_duck_guid(synfigapp::ValueDesc(value_node,first),transform_stack)^synfig::GUID::hasher(".t1"));
1785 tduck->set_origin(duck);
1786 tduck->set_scalar(-TANGENT_BEZIER_SCALE);
1787 tduck->set_tangent(true);
1792 bezier->signal_user_click(2).connect(
1796 &studio::CanvasView::popup_param_menu_bezier),
1797 synfigapp::ValueDesc(value_node,first)));
1799 duck->signal_user_click(2).clear();
1800 duck->signal_user_click(2).connect(
1806 &studio::CanvasView::popup_param_menu),
1809 synfigapp::ValueDesc(value_node,first)));
1810 duck->set_value_desc(synfigapp::ValueDesc(value_node,first));
1817 else // Check for DynamicList
1818 if(value_desc.is_value_node() &&
1819 ValueNode_DynamicList::Handle::cast_dynamic(value_desc.get_value_node()))
1821 ValueNode_DynamicList::Handle value_node;
1822 value_node=ValueNode_DynamicList::Handle::cast_dynamic(value_desc.get_value_node());
1825 if(value_node->get_contained_type()==ValueBase::TYPE_VECTOR)
1828 etl::handle<Duck> first_duck, duck;
1830 for(i=0;i<value_node->link_count();i++)
1832 if(!value_node->list[i].status_at_time(get_time()))
1834 if(!add_to_ducks(synfigapp::ValueDesc(value_node,i),canvas_view,transform_stack))
1838 // remember the index of the first vertex we didn't skip
1847 synfigapp::ValueDesc value_desc_origin(value_desc.get_layer(),param_desc->get_origin());
1848 add_to_ducks(value_desc_origin,canvas_view, transform_stack);
1849 duck->set_origin(last_duck());
1851 ValueBase value(synfigapp::ValueDesc(value_desc.get_layer(),param_desc->get_origin()).get_value(get_time()));
1852 if(value.same_type_as(synfig::Point()))
1853 duck->set_origin(value.get(synfig::Point()));
1855 // if(!param_desc->get_origin().empty())
1856 // last_duck()->set_origin(synfigapp::ValueDesc(value_desc.get_layer(),param_desc->get_origin()).get_value(get_time()).get(synfig::Point()));
1858 duck->set_type(Duck::TYPE_VERTEX);
1859 bezier.p1=bezier.p2;bezier.c1=bezier.c2;
1860 bezier.p2=bezier.c2=duck;
1864 handle<Bezier> bezier_(new Bezier());
1865 bezier_->p1=bezier.p1;
1866 bezier_->c1=bezier.c1;
1867 bezier_->p2=bezier.p2;
1868 bezier_->c2=bezier.c2;
1869 add_bezier(bezier_);
1870 last_bezier()->signal_user_click(2).connect(
1874 &studio::CanvasView::popup_param_menu_bezier),
1875 synfigapp::ValueDesc(value_node,i)));
1879 if (value_node->get_loop() && first != -1 && first_duck != duck)
1883 bezier.p1=bezier.p2;bezier.c1=bezier.c2;
1884 bezier.p2=bezier.c2=duck;
1886 handle<Bezier> bezier_(new Bezier());
1887 bezier_->p1=bezier.p1;
1888 bezier_->c1=bezier.c1;
1889 bezier_->p2=bezier.p2;
1890 bezier_->c2=bezier.c2;
1891 add_bezier(bezier_);
1892 last_bezier()->signal_user_click(2).connect(
1896 &studio::CanvasView::popup_param_menu_bezier),
1897 synfigapp::ValueDesc(value_node,first)));
1900 else if(value_node->get_contained_type()==ValueBase::TYPE_SEGMENT)
1902 for(i=0;i<value_node->link_count();i++)
1904 if(!value_node->list[i].status_at_time(get_time()))
1906 if(!add_to_ducks(synfigapp::ValueDesc(value_node,i),canvas_view,transform_stack))