1 /* === S Y N F I G ========================================================= */
2 /*! \file state_draw.cpp
3 ** \brief Template File
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 ** Copyright (c) 2007 Chris Moore
11 ** This package is free software; you can redistribute it and/or
12 ** modify it under the terms of the GNU General Public License as
13 ** published by the Free Software Foundation; either version 2 of
14 ** the License, or (at your option) any later version.
16 ** This package is distributed in the hope that it will be useful,
17 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 ** General Public License for more details.
22 /* ========================================================================= */
24 /* === H E A D E R S ======================================================= */
33 #include <gtkmm/dialog.h>
34 #include <gtkmm/entry.h>
36 #include <synfig/valuenode_dynamiclist.h>
38 #include "state_draw.h"
39 #include "state_stroke.h"
40 #include "canvasview.h"
43 #include <synfig/valuenode_bline.h>
44 #include <synfig/valuenode_composite.h>
45 #include <ETL/hermite>
46 #include <ETL/calculus>
48 #include "event_mouse.h"
49 #include "event_layerclick.h"
52 #include <synfigapp/blineconvert.h>
53 #include <synfigapp/main.h>
55 #include <ETL/gaussian>
56 #include "dialog_tooloptions.h"
58 #include <gtkmm/table.h>
59 #include <gtkmm/label.h>
60 #include <gtkmm/button.h>
61 #include <gtkmm/checkbutton.h>
62 #include <gtkmm/scale.h>
63 #include <sigc++/connection.h>
67 /* === U S I N G =========================================================== */
71 using namespace synfig;
72 using namespace studio;
74 /* === M A C R O S ========================================================= */
76 /* === G L O B A L S ======================================================= */
78 StateDraw studio::state_draw;
80 /* === C L A S S E S & S T R U C T S ======================================= */
82 class studio::StateDraw_Context : public sigc::trackable
84 typedef etl::smart_ptr<std::list<synfig::Point> > StrokeData;
85 typedef etl::smart_ptr<std::list<synfig::Real> > WidthData;
87 typedef list< pair<StrokeData,WidthData> > StrokeQueue;
89 StrokeQueue stroke_queue;
92 etl::handle<CanvasView> canvas_view_;
93 CanvasView::IsWorking is_working;
95 bool prev_table_status;
97 bool prev_workarea_layer_status_;
100 SigC::Connection process_queue_connection;
102 ValueNode_BLine::Handle last_stroke;
103 synfig::String last_stroke_id;
107 //Duckmatic::Push duckmatic_push;
109 std::list< etl::smart_ptr<std::list<synfig::Point> > > stroke_list;
111 void refresh_ducks();
113 Duckmatic::Type old_duckmask;
115 void fill_last_stroke();
117 Smach::event_result new_bline(std::list<synfig::BLinePoint> bline,bool loop_bline_flag,float radius);
119 Smach::event_result new_region(std::list<synfig::BLinePoint> bline,synfig::Real radius);
121 Smach::event_result extend_bline_from_begin(ValueNode_BLine::Handle value_node,std::list<synfig::BLinePoint> bline,bool complete_loop);
122 Smach::event_result extend_bline_from_end(ValueNode_BLine::Handle value_node,std::list<synfig::BLinePoint> bline,bool complete_loop);
123 void reverse_bline(std::list<synfig::BLinePoint> &bline);
125 synfigapp::Settings& settings;
127 Gtk::Table options_table;
129 Gtk::CheckButton checkbutton_pressure_width;
130 Gtk::CheckButton checkbutton_round_ends;
131 Gtk::CheckButton checkbutton_auto_loop; // whether to loop new strokes which start and end in the same place
132 Gtk::CheckButton checkbutton_auto_extend; // whether to extend existing lines
133 Gtk::CheckButton checkbutton_auto_link; // whether to link new ducks to existing ducks
134 Gtk::CheckButton checkbutton_region; // whether to create regions
135 Gtk::CheckButton checkbutton_outline; // whether to create outlines
136 Gtk::CheckButton checkbutton_auto_export;
137 Gtk::Button button_fill_last_stroke;
139 //pressure spinner and such
140 Gtk::Adjustment adj_min_pressure;
141 Gtk::SpinButton spin_min_pressure;
142 Gtk::CheckButton check_min_pressure;
144 Gtk::Adjustment adj_feather;
145 Gtk::SpinButton spin_feather;
147 Gtk::Adjustment adj_globalthres;
148 Gtk::SpinButton spin_globalthres;
150 Gtk::Adjustment adj_localthres;
151 Gtk::CheckButton check_localerror;
152 void UpdateErrorBox(); //switches the stuff if need be :)
154 //Added by Adrian - data drive HOOOOO
155 synfigapp::BLineConverter blineconv;
158 synfig::String get_id()const { return entry_id.get_text(); }
159 void set_id(const synfig::String& x) { return entry_id.set_text(x); }
161 bool get_pressure_width_flag()const { return checkbutton_pressure_width.get_active(); }
162 void set_pressure_width_flag(bool x) { return checkbutton_pressure_width.set_active(x); }
164 bool get_auto_loop_flag()const { return checkbutton_auto_loop.get_active(); }
165 void set_auto_loop_flag(bool x) { return checkbutton_auto_loop.set_active(x); }
167 bool get_auto_extend_flag()const { return checkbutton_auto_extend.get_active(); }
168 void set_auto_extend_flag(bool x) { return checkbutton_auto_extend.set_active(x); }
170 bool get_auto_link_flag()const { return checkbutton_auto_link.get_active(); }
171 void set_auto_link_flag(bool x) { return checkbutton_auto_link.set_active(x); }
173 bool get_region_flag()const { return checkbutton_region.get_active(); }
174 void set_region_flag(bool x) { return checkbutton_region.set_active(x); }
176 bool get_outline_flag()const { return checkbutton_outline.get_active(); }
177 void set_outline_flag(bool x) { return checkbutton_outline.set_active(x); }
179 bool get_auto_export_flag()const { return checkbutton_auto_export.get_active(); }
180 void set_auto_export_flag(bool x) { return checkbutton_auto_export.set_active(x); }
182 Real get_min_pressure() const { return adj_min_pressure.get_value(); }
183 void set_min_pressure(Real x) { return adj_min_pressure.set_value(x); }
185 Real get_feather() const { return adj_feather.get_value(); }
186 void set_feather(Real x) { return adj_feather.set_value(x); }
188 Real get_gthres() const { return adj_globalthres.get_value(); }
189 void set_gthres(Real x) { return adj_globalthres.set_value(x); }
191 Real get_lthres() const { return adj_localthres.get_value(); }
192 void set_lthres(Real x) { return adj_localthres.set_value(x); }
194 bool get_local_error_flag() const { return check_localerror.get_active(); }
195 void set_local_error_flag(bool x) { check_localerror.set_active(x); }
197 bool get_min_pressure_flag()const { return check_min_pressure.get_active(); }
198 void set_min_pressure_flag(bool x) { check_min_pressure.set_active(x); }
200 void load_settings();
201 void save_settings();
204 Smach::event_result event_stop_handler(const Smach::event& x);
206 Smach::event_result event_refresh_handler(const Smach::event& x);
208 Smach::event_result event_mouse_down_handler(const Smach::event& x);
210 Smach::event_result event_stroke(const Smach::event& x);
211 Smach::event_result event_refresh_tool_options(const Smach::event& x);
212 void refresh_tool_options();
214 Smach::event_result process_stroke(StrokeData stroke_data, WidthData width_data, bool region_flag=false);
216 bool process_queue();
219 StateDraw_Context(CanvasView* canvas_view);
221 ~StateDraw_Context();
223 const etl::handle<CanvasView>& get_canvas_view()const{return canvas_view_;}
224 etl::handle<synfigapp::CanvasInterface> get_canvas_interface()const{return canvas_view_->canvas_interface();}
225 synfig::Time get_time()const { return get_canvas_interface()->get_time(); }
226 synfig::Canvas::Handle get_canvas()const{return canvas_view_->get_canvas();}
227 WorkArea * get_work_area()const{return canvas_view_->get_work_area();}
229 //void on_user_click(synfig::Point point);
232 }; // END of class StateDraw_Context
235 /* === M E T H O D S ======================================================= */
237 StateDraw::StateDraw():
238 Smach::state<StateDraw_Context>("draw")
240 insert(event_def(EVENT_STOP,&StateDraw_Context::event_stop_handler));
241 insert(event_def(EVENT_REFRESH,&StateDraw_Context::event_refresh_handler));
242 insert(event_def(EVENT_WORKAREA_MOUSE_BUTTON_DOWN,&StateDraw_Context::event_mouse_down_handler));
243 insert(event_def(EVENT_WORKAREA_STROKE,&StateDraw_Context::event_stroke));
244 insert(event_def(EVENT_REFRESH_TOOL_OPTIONS,&StateDraw_Context::event_refresh_tool_options));
247 StateDraw::~StateDraw()
253 StateDraw_Context::load_settings()
257 if(settings.get_value("draw.id",value))
260 set_id("NewDrawing");
262 if(settings.get_value("draw.pressure_width",value) && value=="0")
263 set_pressure_width_flag(false);
265 set_pressure_width_flag(true);
267 if(settings.get_value("draw.auto_loop",value) && value=="0")
268 set_auto_loop_flag(false);
270 set_auto_loop_flag(true);
272 if(settings.get_value("draw.auto_extend",value) && value=="0")
273 set_auto_extend_flag(false);
275 set_auto_extend_flag(true);
277 if(settings.get_value("draw.auto_link",value) && value=="0")
278 set_auto_link_flag(false);
280 set_auto_link_flag(true);
282 if(settings.get_value("draw.region",value) && value=="0")
283 set_region_flag(false);
285 set_region_flag(true);
287 if(settings.get_value("draw.outline",value) && value=="0")
288 set_outline_flag(false);
290 set_outline_flag(true);
292 if(settings.get_value("draw.auto_export",value) && value=="1")
293 set_auto_export_flag(true);
295 set_auto_export_flag(false);
297 if(settings.get_value("draw.min_pressure_on",value) && value=="0")
298 set_min_pressure_flag(false);
300 set_min_pressure_flag(true);
302 if(settings.get_value("draw.min_pressure",value))
304 Real n = atof(value.c_str());
309 if(settings.get_value("draw.feather",value))
311 Real n = atof(value.c_str());
316 if(settings.get_value("draw.gthreshold",value))
318 Real n = atof(value.c_str());
322 if(settings.get_value("draw.lthreshold",value))
324 Real n = atof(value.c_str());
328 if(settings.get_value("draw.localize",value) && value == "1")
329 set_local_error_flag(true);
331 set_local_error_flag(false);
335 StateDraw_Context::save_settings()
337 settings.set_value("draw.id",get_id().c_str());
338 settings.set_value("draw.pressure_width",get_pressure_width_flag()?"1":"0");
339 settings.set_value("draw.auto_loop",get_auto_loop_flag()?"1":"0");
340 settings.set_value("draw.auto_extend",get_auto_extend_flag()?"1":"0");
341 settings.set_value("draw.auto_link",get_auto_link_flag()?"1":"0");
342 settings.set_value("draw.region",get_region_flag()?"1":"0");
343 settings.set_value("draw.outline",get_outline_flag()?"1":"0");
344 settings.set_value("draw.auto_export",get_auto_export_flag()?"1":"0");
345 settings.set_value("draw.min_pressure",strprintf("%f",get_min_pressure()));
346 settings.set_value("draw.feather",strprintf("%f",get_feather()));
347 settings.set_value("draw.min_pressure_on",get_min_pressure_flag()?"1":"0");
348 settings.set_value("draw.gthreshold",strprintf("%f",get_gthres()));
349 settings.set_value("draw.lthreshold",strprintf("%f",get_lthres()));
350 settings.set_value("draw.localize",get_local_error_flag()?"1":"0");
354 StateDraw_Context::increment_id()
363 // If there is a number
364 // already at the end of the
365 // id, then remove it.
366 if(id[id.size()-1]<='9' && id[id.size()-1]>='0')
368 // figure out how many digits it is
369 for(digits=0;(int)id.size()-1>=digits && id[id.size()-1-digits]<='9' && id[id.size()-1-digits]>='0';digits++)while(false);
372 str_number=String(id,id.size()-digits,id.size());
373 id=String(id,0,id.size()-digits);
374 synfig::info("---------------- \"%s\"",str_number.c_str());
376 number=atoi(str_number.c_str());
386 // Add the number back onto the id
388 const String format(strprintf("%%0%dd",digits));
389 id+=strprintf(format.c_str(),number);
396 StateDraw_Context::StateDraw_Context(CanvasView* canvas_view):
397 canvas_view_(canvas_view),
398 is_working(*canvas_view),
400 prev_workarea_layer_status_(get_work_area()->get_allow_layer_clicks()),
401 settings(synfigapp::Main::get_selected_input_device()->settings()),
403 checkbutton_pressure_width(_("Pressure Width")),
404 checkbutton_auto_loop(_("Auto Loop")),
405 checkbutton_auto_extend(_("Auto Extend")),
406 checkbutton_auto_link(_("Auto Link")),
407 checkbutton_region(_("Create Region")),
408 checkbutton_outline(_("Create Outline")),
409 checkbutton_auto_export(_("Auto Export")),
410 button_fill_last_stroke(_("Fill Last Stroke")),
411 adj_min_pressure(0,0,1,0.01,0.1),
412 spin_min_pressure(adj_min_pressure,0.1,3),
413 check_min_pressure(_("Min Pressure")),
414 adj_feather(0,0,10000,0.01,0.1),
415 spin_feather(adj_feather,0.01,4),
416 adj_globalthres(.70f,0.01,10000,0.01,0.1),
417 spin_globalthres(adj_globalthres,0.01,3),
418 adj_localthres(20,1,100000,0.1,1),
419 check_localerror(_("LocalError"))
422 synfig::info("STATE SKETCH: entering state");
429 //options_table.attach(*manage(new Gtk::Label(_("Draw Tool"))), 0, 2, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
430 options_table.attach(entry_id, 0, 2, 1, 2, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
431 options_table.attach(checkbutton_region, 0, 2, 2, 3, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
432 options_table.attach(checkbutton_outline, 0, 2, 3, 4, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
433 options_table.attach(checkbutton_auto_loop, 0, 2, 4, 5, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
434 options_table.attach(checkbutton_auto_extend, 0, 2, 5, 6, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
435 options_table.attach(checkbutton_auto_link, 0, 2, 6, 7, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
436 options_table.attach(checkbutton_auto_export, 0, 2, 7, 8, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
437 options_table.attach(checkbutton_pressure_width, 0, 2, 8, 9, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
438 options_table.attach(check_localerror, 0, 2, 9, 10, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
440 options_table.attach(check_min_pressure, 0, 1, 10, 11, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
441 options_table.attach(spin_min_pressure, 1, 2, 10, 11, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
443 options_table.attach(*manage(new Gtk::Label(_("Smooth"))), 0, 1, 11, 12, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
444 options_table.attach(spin_globalthres, 1, 2, 11, 12, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
446 options_table.attach(*manage(new Gtk::Label(_("Feather"))), 0, 1, 12, 13, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
447 options_table.attach(spin_feather, 1, 2, 12, 13, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
449 //options_table.attach(button_fill_last_stroke, 0, 2, 13, 14, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
451 button_fill_last_stroke.signal_pressed().connect(sigc::mem_fun(*this,&StateDraw_Context::fill_last_stroke));
452 check_localerror.signal_toggled().connect(sigc::mem_fun(*this,&StateDraw_Context::UpdateErrorBox));
454 options_table.show_all();
455 refresh_tool_options();
456 //App::dialog_tool_options->set_widget(options_table);
457 App::dialog_tool_options->present();
460 old_duckmask=get_work_area()->get_type_mask();
461 get_work_area()->set_type_mask(Duck::TYPE_ALL-Duck::TYPE_TANGENT-Duck::TYPE_WIDTH);
463 // Turn off layer clicking
464 get_work_area()->set_allow_layer_clicks(false);
466 // Turn off duck clicking
467 get_work_area()->set_allow_duck_clicks(false);
469 // clear out the ducks
470 //get_work_area()->clear_ducks();
472 // Refresh the work area
473 //get_work_area()->queue_draw();
475 // Hide the tables if they are showing
476 prev_table_status=get_canvas_view()->tables_are_visible();
477 //if(prev_table_status)get_canvas_view()->hide_tables();
479 // Disable the time bar
480 get_canvas_view()->set_sensitive_timebar(false);
483 //get_work_area()->signal_user_click().connect(sigc::mem_fun(*this,&studio::StateDraw_Context::on_user_click));
485 get_canvas_view()->work_area->set_cursor(Gdk::PENCIL);
487 App::toolbox->refresh();
493 void StateDraw_Context::UpdateErrorBox()
495 if(get_local_error_flag())
497 spin_globalthres.set_adjustment(adj_localthres);
498 spin_globalthres.set_value(adj_localthres.get_value());
499 spin_globalthres.set_increments(0.1,1);
502 spin_globalthres.set_adjustment(adj_globalthres);
503 spin_globalthres.set_value(adj_globalthres.get_value());
504 spin_globalthres.set_increments(0.01,.1);
507 spin_globalthres.update();
511 StateDraw_Context::refresh_tool_options()
513 App::dialog_tool_options->clear();
514 App::dialog_tool_options->set_widget(options_table);
515 App::dialog_tool_options->set_local_name(_("Draw Tool"));
516 App::dialog_tool_options->set_name("draw");
518 App::dialog_tool_options->add_button(
519 Gtk::StockID("synfig-fill"),
520 _("Fill Last Stroke")
521 )->signal_clicked().connect(
524 &StateDraw_Context::fill_last_stroke
531 StateDraw_Context::event_refresh_tool_options(const Smach::event& /*x*/)
533 refresh_tool_options();
534 return Smach::RESULT_ACCEPT;
537 StateDraw_Context::~StateDraw_Context()
541 App::dialog_tool_options->clear();
543 get_work_area()->set_type_mask(old_duckmask);
545 get_canvas_view()->work_area->reset_cursor();
547 // Restore layer clicking
548 get_work_area()->set_allow_layer_clicks(prev_workarea_layer_status_);
550 // Restore duck clicking
551 get_work_area()->set_allow_duck_clicks(true);
553 // Enable the time bar
554 get_canvas_view()->set_sensitive_timebar(true);
556 // Bring back the tables if they were out before
557 if(prev_table_status)get_canvas_view()->show_tables();
559 // Refresh the work area
560 get_work_area()->queue_draw();
562 App::toolbox->refresh();
566 StateDraw_Context::event_stop_handler(const Smach::event& /*x*/)
568 throw Smach::egress_exception();
572 StateDraw_Context::event_refresh_handler(const Smach::event& /*x*/)
575 return Smach::RESULT_ACCEPT;
579 StateDraw_Context::event_mouse_down_handler(const Smach::event& x)
581 const EventMouse& event(*reinterpret_cast<const EventMouse*>(&x));
586 // Enter the stroke state to get the stroke
587 get_canvas_view()->get_smach().push_state(&state_stroke);
588 return Smach::RESULT_ACCEPT;
591 case BUTTON_RIGHT: // Intercept the right-button click to short-circuit the pop-up menu
592 return Smach::RESULT_ACCEPT;
595 return Smach::RESULT_OK;
599 #define SIMILAR_TANGENT_THRESHOLD (0.2)
604 debugclass(const synfig::String &x):x(x)
606 // synfig::warning(">>>>>>>>>>>>>>>>>>> "+x);
610 // synfig::warning("<<<<<<<<<<<<<<<<<<< "+x);
617 DepthCounter(int &i):i(i) { i++; }
618 ~DepthCounter() { i--; }
622 StateDraw_Context::event_stroke(const Smach::event& x)
624 // debugclass debugger("StateDraw_Context::event_stroke(const Smach::event& x)");
626 const EventStroke& event(*reinterpret_cast<const EventStroke*>(&x));
628 assert(event.stroke_data);
630 get_work_area()->add_stroke(event.stroke_data,synfigapp::Main::get_foreground_color());
634 DirtyTrap dirty_trap(get_work_area());
635 Smach::event_result result;
636 result=process_stroke(event.stroke_data,event.width_data,event.modifier&Gdk::CONTROL_MASK || event.modifier&Gdk::BUTTON2_MASK);
641 stroke_queue.push_back(pair<StrokeData,WidthData>(event.stroke_data,event.width_data));
643 return Smach::RESULT_ACCEPT;
647 StateDraw_Context::process_queue()
649 // debugclass debugger("StateDraw_Context::process_queue()");
652 DepthCounter depth_counter(nested);
653 while(!stroke_queue.empty())
655 pair<StrokeData,WidthData> front(stroke_queue.front());
656 process_stroke(front.first,front.second);
657 stroke_queue.pop_front();
663 StateDraw_Context::process_stroke(StrokeData stroke_data, WidthData width_data, bool region_flag)
665 // debugclass debugger("StateDraw_Context::process_stroke");
666 DepthCounter depth_counter(nested);
668 const float radius(synfigapp::Main::get_bline_width().units(get_canvas()->rend_desc())+(abs(get_work_area()->get_pw())+abs(get_work_area()->get_ph()))*5);
671 // If we aren't using pressure width,
672 // then set all the width to 1
673 if(!get_pressure_width_flag())
675 std::list<synfig::Real>::iterator iter;
676 for(iter=width_data->begin();iter!=width_data->end();++iter)
682 //get_work_area()->add_stroke(event.stroke_data,synfigapp::Main::get_foreground_color());
683 //stroke_list.push_back(event.stroke_data);
686 std::list<synfig::BLinePoint> bline;
687 bool loop_bline_flag(false);
689 //Changed by Adrian - use resident class :)
690 //synfigapp::convert_stroke_to_bline(bline, *event.stroke_data,*event.width_data, synfigapp::Main::get_bline_width());
691 blineconv.width = synfigapp::Main::get_bline_width().units(get_canvas()->rend_desc());
693 if(get_local_error_flag())
695 float pw = get_work_area()->get_pw();
696 float ph = get_work_area()->get_ph();
698 blineconv.pixelwidth = sqrt(pw*pw+ph*ph);
699 blineconv.smoothness = get_lthres();
702 blineconv.pixelwidth = 1;
703 blineconv.smoothness = get_gthres();
706 blineconv(bline,*stroke_data,*width_data);
708 //Postprocess to require minimum pressure
709 if(get_min_pressure_flag())
711 synfigapp::BLineConverter::EnforceMinWidth(bline,get_min_pressure());
714 // If the start and end points are similar, then make them the same point
715 if(get_auto_loop_flag() &&
716 bline.size()>2&&(bline.front().get_vertex()-bline.back().get_vertex()).mag()<=radius)
718 loop_bline_flag=true;
722 while(bline.size()>2&&(bline.front().get_vertex()-bline.back().get_vertex()).mag()<=radius)
724 tangent=bline.back().get_tangent1();
725 width=bline.back().get_width();
729 if(abs(bline.front().get_tangent1().norm()*tangent.norm().perp())>SIMILAR_TANGENT_THRESHOLD)
731 // If the tangents are not similar, then
732 // split the tangents
733 bline.front().set_split_tangent_flag(true);
734 bline.front().set_tangent1(tangent);
738 // If the tangents are similar, then set the tangent
739 // to the average of the two
740 bline.front().set_tangent((tangent+bline.front().get_tangent1())*0.5f);
743 // Add the widths of the two points
745 Real tmp_width(bline.front().get_width()+width);
746 tmp_width=tmp_width<=1?tmp_width:1;
747 bline.front().set_width(tmp_width);
751 // If the bline only has one blinepoint, then there is nothing to do.
753 return Smach::RESULT_OK;
756 return new_region(bline,radius);
758 return new_bline(bline,loop_bline_flag,radius);
762 StateDraw_Context::new_bline(std::list<synfig::BLinePoint> bline,bool loop_bline_flag,float radius)
764 // Create the action group
765 synfigapp::Action::PassiveGrouper group(get_canvas_interface()->get_instance().get(),_("Sketch BLine"));
767 bool shift_offset = false;
768 Vector shift_offset_vector;
769 bool join_start_no_extend=false,join_finish_no_extend=false;
770 synfigapp::ValueDesc start_duck_value_desc,finish_duck_value_desc;
771 bool extend_start=false,extend_finish=false,complete_loop=false;
772 bool extend_start_join_same=false,extend_start_join_different=false;
773 bool extend_finish_join_same=false,extend_finish_join_different=false;
774 int start_duck_index = 0,finish_duck_index = 0; // initialized to keep the compiler happy; shouldn't be needed though
775 ValueNode_BLine::Handle start_duck_value_node_bline=NULL,finish_duck_value_node_bline=NULL;
777 // Find any ducks at the start or end that we might attach to
778 // (this used to only run if we didn't just draw a loop - ie. !loop_bline_flag
779 // but having loops auto-connect can be useful as well)
780 if(get_auto_extend_flag() || get_auto_link_flag())
782 etl::handle<Duck> start_duck(get_work_area()->find_duck(bline.front().get_vertex(),radius,Duck::TYPE_VERTEX));
783 etl::handle<Duck> finish_duck(get_work_area()->find_duck(bline.back().get_vertex(),radius,Duck::TYPE_VERTEX));
785 // check whether the start of the new line extends an
786 // existing line. this is only the case if the new
787 // line isn't a self-contained loop, and if the new
788 // line starts at one of the ends of an existing line
791 if(!(start_duck_value_desc=start_duck->get_value_desc()))break;
792 if(loop_bline_flag)break; // loops don't extend anything
793 if(!start_duck_value_desc.parent_is_value_node())break;
794 start_duck_index=start_duck_value_desc.get_index(); // which point on the line did we start drawing at
795 start_duck_value_node_bline=ValueNode_BLine::Handle::cast_dynamic(start_duck_value_desc.get_parent_value_node());
796 if(!get_auto_extend_flag())break;
798 // don't extend looped blines
799 if(start_duck_value_node_bline&&!start_duck_value_node_bline->get_loop()&&
800 // did we start drawing at either end of the line?
801 (start_duck_index==0||start_duck_index==start_duck_value_node_bline->link_count()-1))
805 shift_offset_vector=start_duck->get_origin();
809 // check whether the end of the new line extends an
810 // existing line. this is only the case if the new
811 // line isn't a self-contained loop, and if the new
812 // line ends at one of the ends of an existing line
815 if(!(finish_duck_value_desc=finish_duck->get_value_desc()))break;
816 if(loop_bline_flag)break;
817 if(!finish_duck_value_desc.parent_is_value_node())break;
818 finish_duck_index=finish_duck_value_desc.get_index();
819 finish_duck_value_node_bline=ValueNode_BLine::Handle::cast_dynamic(finish_duck_value_desc.get_parent_value_node());
820 if(!get_auto_extend_flag())break;
822 // don't extend looped blines
823 if(finish_duck_value_node_bline&&!finish_duck_value_node_bline->get_loop()&&
824 (finish_duck_index==0||finish_duck_index==finish_duck_value_node_bline->link_count()-1))
827 // we've started and finished drawing at the end of a bline. we can't
828 // extend both blines, so unless we started and finished at the 2 ends
829 // of the same bline, only extend the one we started on
830 if(start_duck_value_node_bline==finish_duck_value_node_bline)
831 complete_loop=extend_finish=true;
835 shift_offset_vector=finish_duck->get_origin();
839 // if the new line's start didn't extend an existing line,
840 // check whether it needs to be linked to an existing duck
841 if(!extend_start&&get_auto_link_flag()&&start_duck&&start_duck_value_desc)
842 switch(start_duck_value_desc.get_value_type())
844 case synfig::ValueBase::TYPE_BLINEPOINT:
845 start_duck_value_desc=synfigapp::ValueDesc(LinkableValueNode::Handle::cast_dynamic(start_duck_value_desc.get_value_node()),0);
847 case synfig::ValueBase::TYPE_VECTOR:
848 if (shift_offset && shift_offset_vector != start_duck->get_origin())
851 shift_offset_vector = start_duck->get_origin();
852 get_canvas_interface()->auto_export(start_duck_value_desc);
854 if(start_duck_value_node_bline&&start_duck_value_node_bline==finish_duck_value_node_bline)
855 extend_finish_join_same=true;
857 extend_finish_join_different=true;
859 join_start_no_extend=true;
864 // if the new line's end didn't extend an existing line,
865 // check whether it needs to be linked to an existing duck
866 if(!extend_finish&&get_auto_link_flag()&&finish_duck&&finish_duck_value_desc)
867 switch(finish_duck_value_desc.get_value_type())
869 case synfig::ValueBase::TYPE_BLINEPOINT:
870 finish_duck_value_desc=synfigapp::ValueDesc(LinkableValueNode::Handle::cast_dynamic(finish_duck_value_desc.get_value_node()),0);
872 case synfig::ValueBase::TYPE_VECTOR:
873 if (shift_offset && shift_offset_vector != finish_duck->get_origin())
876 shift_offset_vector = finish_duck->get_origin();
877 get_canvas_interface()->auto_export(finish_duck_value_desc);
879 if(finish_duck_value_node_bline&&start_duck_value_node_bline==finish_duck_value_node_bline)
880 extend_start_join_same=true;
882 extend_start_join_different=true;
884 join_finish_no_extend=true;
890 ValueNode_BLine::Handle value_node;
891 std::list<synfig::BLinePoint> trans_bline;
894 std::list<synfig::BLinePoint>::iterator iter;
895 const synfig::TransformStack& transform(get_canvas_view()->get_curr_transform_stack());
897 for(iter=bline.begin();iter!=bline.end();++iter)
899 BLinePoint bline_point(*iter);
900 Point new_vertex(transform.unperform(bline_point.get_vertex()));
902 bline_point.set_tangent1(
904 bline_point.get_tangent1()+bline_point.get_vertex()
908 bline_point.set_tangent2(
910 bline_point.get_tangent2()+bline_point.get_vertex()
915 new_vertex=new_vertex-shift_offset_vector;
917 bline_point.set_vertex(new_vertex);
919 trans_bline.push_back(bline_point);
921 value_node=ValueNode_BLine::create(synfig::ValueBase(trans_bline,loop_bline_flag));
924 Smach::event_result result;
925 synfig::ValueNode_DynamicList::ListEntry source;
927 // the new line's start extends an existing line
930 int target_offset = 0;
931 if(complete_loop)trans_bline.pop_back();
932 trans_bline.pop_front();
933 if(start_duck_index==0)
934 { // We need to reverse the BLine first.
935 reverse_bline(trans_bline);
936 result=extend_bline_from_begin(start_duck_value_node_bline,trans_bline,complete_loop);
937 source=start_duck_value_node_bline->list.front();
938 target_offset=trans_bline.size();
942 result=extend_bline_from_end(start_duck_value_node_bline,trans_bline,complete_loop);
943 source=start_duck_value_node_bline->list.back();
946 if(extend_start_join_different)
947 LinkableValueNode::Handle::cast_dynamic(source.value_node)->
948 set_link(0,finish_duck_value_desc.get_value_node());
949 else if(extend_start_join_same)
950 LinkableValueNode::Handle::cast_dynamic(source.value_node)->
951 set_link(0,synfigapp::ValueDesc(LinkableValueNode::Handle::cast_dynamic(start_duck_value_node_bline->
952 list[target_offset+finish_duck_index].value_node),0).get_value_node());
956 // the new line's end extends an existing line
959 int target_offset = 0;
960 trans_bline.pop_back();
961 if(finish_duck_index==0)
963 result=extend_bline_from_begin(finish_duck_value_node_bline,trans_bline,false);
964 source=finish_duck_value_node_bline->list.front();
965 target_offset=trans_bline.size();
968 { // We need to reverse the BLine first.
969 reverse_bline(trans_bline);
970 result=extend_bline_from_end(finish_duck_value_node_bline,trans_bline,false);
971 source=finish_duck_value_node_bline->list.back();
974 if(extend_finish_join_different)
975 LinkableValueNode::Handle::cast_dynamic(source.value_node)->
976 set_link(0,start_duck_value_desc.get_value_node());
977 else if(extend_finish_join_same)
978 LinkableValueNode::Handle::cast_dynamic(source.value_node)->
979 set_link(0,synfigapp::ValueDesc(LinkableValueNode::Handle::cast_dynamic(finish_duck_value_node_bline->
980 list[target_offset+start_duck_index].value_node),0).get_value_node());
984 if (join_start_no_extend)
985 LinkableValueNode::Handle::cast_dynamic(value_node->list.front().value_node)->
986 set_link(0,start_duck_value_desc.get_value_node());
988 if (join_finish_no_extend)
989 LinkableValueNode::Handle::cast_dynamic(value_node->list.back().value_node)->
990 set_link(0,finish_duck_value_desc.get_value_node());
992 if(get_auto_export_flag()) {
993 printf("this is where we would export the new line\n");
994 if (!get_canvas_interface()->add_value_node(value_node,get_id()))
996 /* it's no big deal, is it? let's keep the shape anyway */
997 // get_canvas_view()->get_ui_interface()->error(_("Unable to add value node"));
1000 // return Smach::RESULT_ERROR;
1006 Layer::Handle layer;
1007 Canvas::Handle canvas(get_canvas_view()->get_canvas());
1010 // we are temporarily using the layer to hold something
1011 layer=get_canvas_view()->get_selection_manager()->get_selected_layer();
1014 depth=layer->get_depth();
1015 canvas=layer->get_canvas();
1018 //int number(synfig::UniqueID().get_uid());
1020 synfigapp::PushMode push_mode(get_canvas_interface(),synfigapp::MODE_NORMAL);
1022 // if they're both defined, we'll add the region later
1023 if(get_outline_flag())
1025 layer=get_canvas_interface()->add_layer_to("outline",canvas,depth);
1026 layer->set_description(get_id()+_(" Outline"));
1030 layer=get_canvas_interface()->add_layer_to("region",canvas,depth);
1031 layer->set_description(get_id()+_(" Region"));
1036 layer->set_param("feather",get_feather());
1037 get_canvas_interface()->signal_layer_param_changed()(layer,"feather");
1040 //layer->set_description(strprintf("Stroke %d",number));
1041 //get_canvas_interface()->signal_layer_new_description()(layer,layer->get_description());
1044 get_canvas_interface()->
1045 change_value(synfigapp::ValueDesc(layer,"offset"),shift_offset_vector);
1047 synfigapp::Action::Handle action(synfigapp::Action::create("layer_param_connect"));
1051 action->set_param("canvas",get_canvas());
1052 action->set_param("canvas_interface",get_canvas_interface());
1053 action->set_param("layer",layer);
1054 if(!action->set_param("param",String("bline")))
1055 synfig::error("LayerParamConnect didn't like \"param\"");
1056 if(!action->set_param("value_node",ValueNode::Handle(value_node)))
1057 synfig::error("LayerParamConnect didn't like \"value_node\"");
1059 if(!get_canvas_interface()->get_instance()->perform_action(action))
1061 get_canvas_view()->get_ui_interface()->error(_("Unable to create layer"));
1065 return Smach::RESULT_ERROR;
1067 get_canvas_view()->get_selection_manager()->set_selected_layer(layer);
1071 last_stroke=value_node;
1072 last_stroke_id=get_id();
1074 if(get_outline_flag() && get_region_flag())
1078 return Smach::RESULT_ACCEPT;
1082 StateDraw_Context::new_region(std::list<synfig::BLinePoint> bline, synfig::Real radius)
1084 // Create the action group
1085 synfigapp::Action::PassiveGrouper group(get_canvas_interface()->get_instance().get(),_("Define Region"));
1087 std::list<synfigapp::ValueDesc> vertex_list;
1089 // First we need to come up with a rough list of
1090 // BLinePoints that we are going to be using to
1091 // define our region.
1093 std::list<synfig::BLinePoint>::iterator iter;
1094 for(iter=bline.begin();iter!=bline.end();++iter)
1096 etl::handle<Duck> duck(get_work_area()->find_duck(iter->get_vertex(),0,Duck::TYPE_VERTEX));
1100 synfig::info(__FILE__":%d: Nothing to enclose!",__LINE__);
1101 return Smach::RESULT_OK;
1105 assert(duck->get_type()==Duck::TYPE_VERTEX);
1107 synfigapp::ValueDesc value_desc(duck->get_value_desc());
1111 synfig::info(__FILE__":%d: Got a hit, but no ValueDesc on this duck",__LINE__);
1115 switch(value_desc.get_value_type())
1117 case synfig::ValueBase::TYPE_BLINEPOINT:
1118 //if(vertex_list.empty() || value_desc!=vertex_list.back())
1119 vertex_list.push_back(value_desc);
1120 assert(vertex_list.back().is_valid());
1129 if(vertex_list.size()<=2)
1131 synfig::info(__FILE__":%d: Vertex list too small to make region.",__LINE__);
1132 return Smach::RESULT_OK;
1135 assert(vertex_list.back().is_valid());
1137 // Remove any duplicates
1141 // Now we need to clean the list of vertices up
1142 // a bit. This includes inserting missing vertices
1143 // and removing extraneous ones.
1144 // We can do this in multiple passes.
1146 for(bool done=false;!done && i<30;i++)
1148 // Set done to "true" for now. If
1149 // any updates are performed, we will
1150 // change it back to false.
1153 std::list<synfigapp::ValueDesc>::iterator prev,iter,next;
1154 prev=vertex_list.end();prev--; // Set prev to the last ValueDesc
1155 next=vertex_list.begin();
1156 iter=next++; // Set iter to the first value desc, and next to the second
1158 for(;iter!=vertex_list.end();prev=iter,iter=next++)
1160 synfigapp::ValueDesc value_prev(*prev);
1161 synfigapp::ValueDesc value_desc(*iter);
1162 synfigapp::ValueDesc value_next((next==vertex_list.end())?vertex_list.front():*next);
1164 assert(value_desc.is_valid());
1165 assert(value_next.is_valid());
1166 assert(value_prev.is_valid());
1168 //synfig::info("-------");
1169 //synfig::info(__FILE__":%d: value_prev 0x%08X:%d",__LINE__,value_prev.get_parent_value_node().get(),value_prev.get_index());
1170 //synfig::info(__FILE__":%d: value_desc 0x%08X:%d",__LINE__,value_desc.get_parent_value_node().get(),value_desc.get_index());
1171 //synfig::info(__FILE__":%d: value_next 0x%08X:%d",__LINE__,value_next.get_parent_value_node().get(),value_next.get_index());
1174 if(value_prev.parent_is_value_node() && value_desc.parent_is_value_node() && value_next.parent_is_value_node())
1176 // Remove random extraneous vertices
1177 if(value_prev.get_parent_value_node()==value_next.get_parent_value_node() &&
1178 value_prev.get_parent_value_node()!=value_desc.get_parent_value_node())
1181 vertex_list.erase(iter);
1188 // Remove duplicate vertices
1189 if(value_prev.get_value_node()==value_desc.get_value_node()
1190 || value_desc.get_value_node()==value_next.get_value_node())
1193 vertex_list.erase(iter);
1197 if(value_prev.get_value_node()==value_next.get_value_node())
1200 vertex_list.erase(prev);
1205 if(value_desc.parent_is_value_node() && value_next.parent_is_value_node())
1206 if(value_desc.get_parent_value_node()==value_next.get_parent_value_node() && (next!=vertex_list.end()))
1208 // Fill in missing vertices
1209 if(value_desc.get_index()<value_next.get_index()-1)
1212 vertex_list.insert(next,synfigapp::ValueDesc(value_desc.get_parent_value_node(),value_desc.get_index()+1));
1216 if(value_next.get_index()<value_desc.get_index()-1)
1219 vertex_list.insert(next,synfigapp::ValueDesc(value_desc.get_parent_value_node(),value_next.get_index()+1));
1225 // Ensure that connections
1226 // between blines are properly
1228 if(value_desc.parent_is_value_node() && value_next.parent_is_value_node() &&
1229 value_desc.get_parent_value_node()!=value_next.get_parent_value_node() &&
1230 value_desc.get_value_node()!=value_next.get_value_node())
1232 BLinePoint vertex(value_desc.get_value(get_time()).get(BLinePoint()));
1233 BLinePoint vertex_next(value_next.get_value(get_time()).get(BLinePoint()));
1235 //synfig::info("--------");
1236 //synfig::info(__FILE__":%d: vertex: [%f, %f]",__LINE__,vertex.get_vertex()[0],vertex.get_vertex()[1]);
1237 //synfig::info(__FILE__":%d: vertex_next: [%f, %f]",__LINE__,vertex_next.get_vertex()[0],vertex_next.get_vertex()[1]);
1239 if((vertex.get_vertex()-vertex_next.get_vertex()).mag_squared()<radius*radius)
1242 ValueNode_Composite::Handle value_node;
1243 ValueNode_Composite::Handle value_node_next;
1244 value_node=ValueNode_Composite::Handle::cast_dynamic(value_desc.get_value_node().clone());
1245 value_node_next=ValueNode_Composite::Handle::cast_dynamic(value_next.get_value_node().clone());
1246 if(!value_node || !value_node_next)
1248 synfig::info(__FILE__":%d: Unable to properly connect blines.",__LINE__);
1252 value_node->set_link(5,value_node_next->get_link(5));
1253 value_node->set_link(3,ValueNode_Const::create(true));
1255 get_canvas_interface()->auto_export(value_node);
1256 assert(value_node->is_exported());
1257 *iter=synfigapp::ValueDesc(get_canvas(),value_node->get_id());
1258 vertex_list.erase(next);
1265 bool positive_trend(value_desc.get_index()>value_prev.get_index());
1267 if(!positive_trend && value_desc.get_index()>0)
1270 vertex_list.insert(next,synfigapp::ValueDesc(value_desc.get_parent_value_node(),value_desc.get_index()-1));
1274 if(positive_trend && value_desc.get_index()<LinkableValueNode::Handle::cast_static(value_desc.get_value_node())->link_count()-1)
1277 vertex_list.insert(next,synfigapp::ValueDesc(value_desc.get_parent_value_node(),value_desc.get_index()+1));
1287 if(vertex_list.size()<=2)
1289 synfig::info(__FILE__":%d: Vertex list too small to make region.",__LINE__);
1290 return Smach::RESULT_OK;
1293 ValueNode_BLine::Handle value_node_bline;
1295 // Now we need to test for the trivial case,
1296 // which is where all of the vertices
1297 // come from one BLine.
1298 if(vertex_list.front().parent_is_linkable_value_node())
1300 bool trivial_case(true);
1301 ValueNode::Handle trivial_case_value_node;
1303 trivial_case_value_node=vertex_list.front().get_parent_value_node();
1305 std::list<synfigapp::ValueDesc>::iterator iter;
1306 for(iter=vertex_list.begin();iter!=vertex_list.end();++iter)
1308 if(trivial_case_value_node!=iter->get_parent_value_node())
1315 value_node_bline=ValueNode_BLine::Handle::cast_dynamic(trivial_case_value_node);
1318 // If we aren't the trivial case,
1319 // then go ahead and create the new
1321 if(!value_node_bline)
1323 value_node_bline=ValueNode_BLine::create();
1325 std::list<synfigapp::ValueDesc>::iterator iter;
1326 for(iter=vertex_list.begin();iter!=vertex_list.end();++iter)
1328 // Ensure that the vertex is exported.
1329 get_canvas_interface()->auto_export(*iter);
1331 value_node_bline->add(iter->get_value_node());
1332 //value_node_bline->add(ValueNode_BLine::ListEntry(iter->get_value_node()));
1335 value_node_bline->set_loop(true);
1338 get_canvas_interface()->auto_export(value_node_bline);
1340 // Now we create the region layer
1343 Layer::Handle layer;
1344 Canvas::Handle canvas(get_canvas_view()->get_canvas());
1347 // we are temporarily using the layer to hold something
1348 layer=get_canvas_view()->get_selection_manager()->get_selected_layer();
1351 depth=layer->get_depth();
1352 canvas=layer->get_canvas();
1355 synfigapp::PushMode push_mode(get_canvas_interface(),synfigapp::MODE_NORMAL);
1357 layer=get_canvas_interface()->add_layer_to("region",canvas,depth);
1359 layer->set_param("color",synfigapp::Main::get_background_color());
1362 layer->set_param("feather",get_feather());
1363 get_canvas_interface()->signal_layer_param_changed()(layer,"feather");
1365 get_canvas_interface()->signal_layer_param_changed()(layer,"color");
1367 synfigapp::Action::Handle action(synfigapp::Action::create("layer_param_connect"));
1371 action->set_param("canvas",get_canvas());
1372 action->set_param("canvas_interface",get_canvas_interface());
1373 action->set_param("layer",layer);
1374 if(!action->set_param("param",String("bline")))
1375 synfig::error("LayerParamConnect didn't like \"param\"");
1376 if(!action->set_param("value_node",ValueNode::Handle(value_node_bline)))
1377 synfig::error("LayerParamConnect didn't like \"value_node\"");
1379 if(!get_canvas_interface()->get_instance()->perform_action(action))
1381 get_canvas_view()->get_ui_interface()->error(_("Unable to create Region layer"));
1383 return Smach::RESULT_ERROR;
1385 get_canvas_view()->get_selection_manager()->set_selected_layer(layer);
1388 return Smach::RESULT_ACCEPT;
1392 StateDraw_Context::refresh_ducks()
1394 get_canvas_view()->queue_rebuild_ducks();
1396 get_work_area()->clear_ducks();
1399 std::list< etl::smart_ptr<std::list<synfig::Point> > >::iterator iter;
1401 for(iter=stroke_list.begin();iter!=stroke_list.end();++iter)
1403 get_work_area()->add_stroke(*iter);
1406 get_work_area()->queue_draw();
1412 StateDraw_Context::extend_bline_from_begin(ValueNode_BLine::Handle value_node,std::list<synfig::BLinePoint> bline,bool complete_loop)
1414 // Create the action group
1415 synfigapp::Action::PassiveGrouper group(get_canvas_interface()->get_instance().get(),_("Extend BLine"));
1419 synfigapp::Action::Handle action(synfigapp::Action::create("value_node_dynamic_list_loop"));
1422 action->set_param("canvas",get_canvas());
1423 action->set_param("canvas_interface",get_canvas_interface());
1424 action->set_param("value_node",ValueNode::Handle(value_node));
1426 if(!get_canvas_interface()->get_instance()->perform_action(action))
1428 get_canvas_view()->get_ui_interface()->error(_("Unable to set loop for bline"));
1430 return Smach::RESULT_ERROR;
1434 std::list<synfig::BLinePoint>::reverse_iterator iter;
1435 for(iter=bline.rbegin();!(iter==bline.rend());++iter)
1437 ValueNode_Composite::Handle composite(ValueNode_Composite::create(*iter));
1439 synfigapp::Action::Handle action(synfigapp::Action::create("value_node_dynamic_list_insert"));
1442 synfigapp::ValueDesc value_desc(value_node,0);
1444 action->set_param("canvas",get_canvas());
1445 action->set_param("canvas_interface",get_canvas_interface());
1446 action->set_param("value_desc",value_desc);
1447 if(!action->set_param("item",ValueNode::Handle(composite)))
1448 synfig::error("ACTION didn't like \"item\"");
1450 if(!get_canvas_interface()->get_instance()->perform_action(action))
1452 get_canvas_view()->get_ui_interface()->error(_("Unable to insert item"));
1455 return Smach::RESULT_ERROR;
1458 last_stroke=value_node;
1459 return Smach::RESULT_ACCEPT;
1463 StateDraw_Context::extend_bline_from_end(ValueNode_BLine::Handle value_node,std::list<synfig::BLinePoint> bline,bool complete_loop)
1465 // Create the action group
1466 synfigapp::Action::PassiveGrouper group(get_canvas_interface()->get_instance().get(),_("Extend BLine"));
1470 synfigapp::Action::Handle action(synfigapp::Action::create("value_node_dynamic_list_loop"));
1473 action->set_param("canvas",get_canvas());
1474 action->set_param("canvas_interface",get_canvas_interface());
1475 action->set_param("value_node",ValueNode::Handle(value_node));
1477 if(!get_canvas_interface()->get_instance()->perform_action(action))
1479 get_canvas_view()->get_ui_interface()->error(_("Unable to set loop for bline"));
1481 return Smach::RESULT_ERROR;
1485 std::list<synfig::BLinePoint>::iterator iter;
1486 for(iter=bline.begin();iter!=bline.end();++iter)
1488 ValueNode_Composite::Handle composite(ValueNode_Composite::create(*iter));
1490 synfigapp::Action::Handle action(synfigapp::Action::create("value_node_dynamic_list_insert"));
1493 synfigapp::ValueDesc value_desc(value_node,value_node->link_count());
1495 action->set_param("canvas",get_canvas());
1496 action->set_param("canvas_interface",get_canvas_interface());
1497 action->set_param("value_desc",value_desc);
1498 if(!action->set_param("item",ValueNode::Handle(composite)))
1499 synfig::error("ACTION didn't like \"item\"");
1501 if(!get_canvas_interface()->get_instance()->perform_action(action))
1503 get_canvas_view()->get_ui_interface()->error(_("Unable to insert item"));
1506 return Smach::RESULT_ERROR;
1509 last_stroke=value_node;
1510 return Smach::RESULT_ACCEPT;
1514 StateDraw_Context::reverse_bline(std::list<synfig::BLinePoint> &bline)
1518 std::list<synfig::BLinePoint>::iterator iter,eiter;
1522 for(i=0;i<(int)bline.size()/2;++iter,--eiter,i++)
1524 iter_swap(iter,eiter);
1531 StateDraw_Context::fill_last_stroke()
1536 synfigapp::Action::PassiveGrouper group(get_canvas_interface()->get_instance().get(),_("Fill Stroke"));
1538 Layer::Handle layer;
1540 get_canvas_interface()->auto_export(last_stroke);
1542 synfigapp::PushMode push_mode(get_canvas_interface(),synfigapp::MODE_NORMAL);
1544 layer=get_canvas_interface()->add_layer("region");
1546 layer->set_param("color",synfigapp::Main::get_background_color());
1547 layer->set_description(last_stroke_id + _(" Region"));
1549 synfigapp::Action::Handle action(synfigapp::Action::create("layer_param_connect"));
1553 action->set_param("canvas",get_canvas());
1554 action->set_param("canvas_interface",get_canvas_interface());
1555 action->set_param("layer",layer);
1556 if(!action->set_param("param",String("bline")))
1557 synfig::error("LayerParamConnect didn't like \"param\"");
1558 if(!action->set_param("value_node",ValueNode::Handle(last_stroke)))
1559 synfig::error("LayerParamConnect didn't like \"value_node\"");
1561 if(!get_canvas_interface()->get_instance()->perform_action(action))
1563 get_canvas_view()->get_ui_interface()->error(_("Unable to create Region layer"));
1567 get_canvas_view()->get_selection_manager()->set_selected_layer(layer);