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;
106 //Duckmatic::Push duckmatic_push;
108 std::list< etl::smart_ptr<std::list<synfig::Point> > > stroke_list;
110 void refresh_ducks();
112 Duckmatic::Type old_duckmask;
114 void fill_last_stroke();
116 Smach::event_result new_bline(std::list<synfig::BLinePoint> bline,bool loop_bline_flag,float radius);
118 Smach::event_result new_region(std::list<synfig::BLinePoint> bline,synfig::Real radius);
120 Smach::event_result extend_bline_from_begin(ValueNode_BLine::Handle value_node,std::list<synfig::BLinePoint> bline,bool complete_loop);
121 Smach::event_result extend_bline_from_end(ValueNode_BLine::Handle value_node,std::list<synfig::BLinePoint> bline,bool complete_loop);
122 void reverse_bline(std::list<synfig::BLinePoint> &bline);
124 synfigapp::Settings& settings;
126 Gtk::Table options_table;
128 Gtk::CheckButton checkbutton_pressure_width;
129 Gtk::CheckButton checkbutton_round_ends;
130 Gtk::CheckButton checkbutton_auto_loop; // whether to loop new strokes which start and end in the same place
131 Gtk::CheckButton checkbutton_auto_extend; // whether to extend existing lines
132 Gtk::CheckButton checkbutton_auto_link; // whether to link new ducks to existing ducks
133 Gtk::CheckButton checkbutton_region_only;
134 Gtk::CheckButton checkbutton_auto_export;
135 Gtk::Button button_fill_last_stroke;
137 //pressure spinner and such
138 Gtk::Adjustment adj_min_pressure;
139 Gtk::SpinButton spin_min_pressure;
140 Gtk::CheckButton check_min_pressure;
142 Gtk::Adjustment adj_feather;
143 Gtk::SpinButton spin_feather;
145 Gtk::Adjustment adj_globalthres;
146 Gtk::SpinButton spin_globalthres;
148 Gtk::Adjustment adj_localthres;
149 Gtk::CheckButton check_localerror;
150 void UpdateErrorBox(); //switches the stuff if need be :)
152 //Added by Adrian - data drive HOOOOO
153 synfigapp::BLineConverter blineconv;
156 synfig::String get_id()const { return entry_id.get_text(); }
157 void set_id(const synfig::String& x) { return entry_id.set_text(x); }
159 bool get_pressure_width_flag()const { return checkbutton_pressure_width.get_active(); }
160 void set_pressure_width_flag(bool x) { return checkbutton_pressure_width.set_active(x); }
162 bool get_auto_loop_flag()const { return checkbutton_auto_loop.get_active(); }
163 void set_auto_loop_flag(bool x) { return checkbutton_auto_loop.set_active(x); }
165 bool get_auto_extend_flag()const { return checkbutton_auto_extend.get_active(); }
166 void set_auto_extend_flag(bool x) { return checkbutton_auto_extend.set_active(x); }
168 bool get_auto_link_flag()const { return checkbutton_auto_link.get_active(); }
169 void set_auto_link_flag(bool x) { return checkbutton_auto_link.set_active(x); }
171 bool get_region_only_flag()const { return checkbutton_region_only.get_active(); }
172 void set_region_only_flag(bool x) { return checkbutton_region_only.set_active(x); }
174 bool get_auto_export_flag()const { return checkbutton_auto_export.get_active(); }
175 void set_auto_export_flag(bool x) { return checkbutton_auto_export.set_active(x); }
177 Real get_min_pressure() const { return adj_min_pressure.get_value(); }
178 void set_min_pressure(Real x) { return adj_min_pressure.set_value(x); }
180 Real get_feather() const { return adj_feather.get_value(); }
181 void set_feather(Real x) { return adj_feather.set_value(x); }
183 Real get_gthres() const { return adj_globalthres.get_value(); }
184 void set_gthres(Real x) { return adj_globalthres.set_value(x); }
186 Real get_lthres() const { return adj_localthres.get_value(); }
187 void set_lthres(Real x) { return adj_localthres.set_value(x); }
189 bool get_local_error_flag() const { return check_localerror.get_active(); }
190 void set_local_error_flag(bool x) { check_localerror.set_active(x); }
192 bool get_min_pressure_flag()const { return check_min_pressure.get_active(); }
193 void set_min_pressure_flag(bool x) { check_min_pressure.set_active(x); }
195 void load_settings();
196 void save_settings();
199 Smach::event_result event_stop_handler(const Smach::event& x);
201 Smach::event_result event_refresh_handler(const Smach::event& x);
203 Smach::event_result event_mouse_down_handler(const Smach::event& x);
205 Smach::event_result event_stroke(const Smach::event& x);
206 Smach::event_result event_refresh_tool_options(const Smach::event& x);
207 void refresh_tool_options();
209 Smach::event_result process_stroke(StrokeData stroke_data, WidthData width_data, bool region_flag=false);
211 bool process_queue();
214 StateDraw_Context(CanvasView* canvas_view);
216 ~StateDraw_Context();
218 const etl::handle<CanvasView>& get_canvas_view()const{return canvas_view_;}
219 etl::handle<synfigapp::CanvasInterface> get_canvas_interface()const{return canvas_view_->canvas_interface();}
220 synfig::Time get_time()const { return get_canvas_interface()->get_time(); }
221 synfig::Canvas::Handle get_canvas()const{return canvas_view_->get_canvas();}
222 WorkArea * get_work_area()const{return canvas_view_->get_work_area();}
224 //void on_user_click(synfig::Point point);
227 }; // END of class StateDraw_Context
230 /* === M E T H O D S ======================================================= */
232 StateDraw::StateDraw():
233 Smach::state<StateDraw_Context>("draw")
235 insert(event_def(EVENT_STOP,&StateDraw_Context::event_stop_handler));
236 insert(event_def(EVENT_REFRESH,&StateDraw_Context::event_refresh_handler));
237 insert(event_def(EVENT_WORKAREA_MOUSE_BUTTON_DOWN,&StateDraw_Context::event_mouse_down_handler));
238 insert(event_def(EVENT_WORKAREA_STROKE,&StateDraw_Context::event_stroke));
239 insert(event_def(EVENT_REFRESH_TOOL_OPTIONS,&StateDraw_Context::event_refresh_tool_options));
242 StateDraw::~StateDraw()
248 StateDraw_Context::load_settings()
252 if(settings.get_value("draw.id",value))
255 set_id("NewDrawing");
257 if(settings.get_value("draw.pressure_width",value) && value=="0")
258 set_pressure_width_flag(false);
260 set_pressure_width_flag(true);
262 if(settings.get_value("draw.auto_loop",value) && value=="0")
263 set_auto_loop_flag(false);
265 set_auto_loop_flag(true);
267 if(settings.get_value("draw.auto_extend",value) && value=="0")
268 set_auto_extend_flag(false);
270 set_auto_extend_flag(true);
272 if(settings.get_value("draw.auto_link",value) && value=="0")
273 set_auto_link_flag(false);
275 set_auto_link_flag(true);
277 if(settings.get_value("draw.region_only",value) && value=="1")
278 set_region_only_flag(true);
280 set_region_only_flag(false);
282 if(settings.get_value("draw.auto_export",value) && value=="1")
283 set_auto_export_flag(true);
285 set_auto_export_flag(false);
287 if(settings.get_value("draw.min_pressure_on",value) && value=="0")
288 set_min_pressure_flag(false);
290 set_min_pressure_flag(true);
292 if(settings.get_value("draw.min_pressure",value))
294 Real n = atof(value.c_str());
299 if(settings.get_value("draw.feather",value))
301 Real n = atof(value.c_str());
306 if(settings.get_value("draw.gthreshold",value))
308 Real n = atof(value.c_str());
312 if(settings.get_value("draw.lthreshold",value))
314 Real n = atof(value.c_str());
318 if(settings.get_value("draw.localize",value) && value == "1")
319 set_local_error_flag(true);
321 set_local_error_flag(false);
325 StateDraw_Context::save_settings()
327 settings.set_value("draw.id",get_id().c_str());
328 settings.set_value("draw.pressure_width",get_pressure_width_flag()?"1":"0");
329 settings.set_value("draw.auto_loop",get_auto_loop_flag()?"1":"0");
330 settings.set_value("draw.auto_extend",get_auto_extend_flag()?"1":"0");
331 settings.set_value("draw.auto_link",get_auto_link_flag()?"1":"0");
332 settings.set_value("draw.region_only",get_region_only_flag()?"1":"0");
333 settings.set_value("draw.auto_export",get_auto_export_flag()?"1":"0");
334 settings.set_value("draw.min_pressure",strprintf("%f",get_min_pressure()));
335 settings.set_value("draw.feather",strprintf("%f",get_feather()));
336 settings.set_value("draw.min_pressure_on",get_min_pressure_flag()?"1":"0");
337 settings.set_value("draw.gthreshold",strprintf("%f",get_gthres()));
338 settings.set_value("draw.lthreshold",strprintf("%f",get_lthres()));
339 settings.set_value("draw.localize",get_local_error_flag()?"1":"0");
343 StateDraw_Context::increment_id()
352 // If there is a number
353 // already at the end of the
354 // id, then remove it.
355 if(id[id.size()-1]<='9' && id[id.size()-1]>='0')
357 // figure out how many digits it is
358 for(digits=0;(int)id.size()-1>=digits && id[id.size()-1-digits]<='9' && id[id.size()-1-digits]>='0';digits++)while(false);
361 str_number=String(id,id.size()-digits,id.size());
362 id=String(id,0,id.size()-digits);
363 synfig::info("---------------- \"%s\"",str_number.c_str());
365 number=atoi(str_number.c_str());
375 // Add the number back onto the id
377 const String format(strprintf("%%0%dd",digits));
378 id+=strprintf(format.c_str(),number);
385 StateDraw_Context::StateDraw_Context(CanvasView* canvas_view):
386 canvas_view_(canvas_view),
387 is_working(*canvas_view),
389 prev_workarea_layer_status_(get_work_area()->allow_layer_clicks),
390 settings(synfigapp::Main::get_selected_input_device()->settings()),
392 checkbutton_pressure_width(_("Pressure Width")),
393 checkbutton_auto_loop(_("Auto Loop")),
394 checkbutton_auto_extend(_("Auto Extend")),
395 checkbutton_auto_link(_("Auto Link")),
396 checkbutton_region_only(_("Create Region Only")),
397 checkbutton_auto_export(_("Auto Export")),
398 button_fill_last_stroke(_("Fill Last Stroke")),
399 adj_min_pressure(0,0,1,0.01,0.1),
400 spin_min_pressure(adj_min_pressure,0.1,3),
401 check_min_pressure(_("Min Pressure")),
402 adj_feather(0,0,10000,0.01,0.1),
403 spin_feather(adj_feather,0.01,4),
404 adj_globalthres(.70f,0.01,10000,0.01,0.1),
405 spin_globalthres(adj_globalthres,0.01,3),
406 adj_localthres(20,1,100000,0.1,1),
407 check_localerror(_("LocalError"))
410 synfig::info("STATE SKETCH: entering state");
417 //options_table.attach(*manage(new Gtk::Label(_("Draw Tool"))), 0, 2, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
418 options_table.attach(entry_id, 0, 2, 1, 2, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
419 options_table.attach(checkbutton_pressure_width,0, 2, 2, 3, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
420 options_table.attach(checkbutton_auto_loop, 0, 2, 3, 4, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
421 options_table.attach(checkbutton_auto_extend, 0, 2, 4, 5, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
422 options_table.attach(checkbutton_auto_link, 0, 2, 5, 6, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
423 options_table.attach(checkbutton_region_only, 0, 2, 6, 7, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
424 options_table.attach(checkbutton_auto_export, 0, 2, 7, 8, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
426 options_table.attach(check_min_pressure, 0, 2, 8, 9, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
427 options_table.attach(spin_min_pressure, 0, 2, 9, 10, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
429 options_table.attach(*manage(new Gtk::Label(_("Feather"))), 0, 1, 10, 11, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
430 options_table.attach(spin_feather, 1, 2, 10, 11, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
432 options_table.attach(check_localerror, 0, 2, 11, 12, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
433 options_table.attach(*manage(new Gtk::Label(_("Smooth"))), 0, 1, 12, 13, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
434 options_table.attach(spin_globalthres, 1, 2, 12, 13, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
436 //options_table.attach(button_fill_last_stroke, 0, 2, 13, 14, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
438 button_fill_last_stroke.signal_pressed().connect(sigc::mem_fun(*this,&StateDraw_Context::fill_last_stroke));
439 check_localerror.signal_toggled().connect(sigc::mem_fun(*this,&StateDraw_Context::UpdateErrorBox));
441 options_table.show_all();
442 refresh_tool_options();
443 //App::dialog_tool_options->set_widget(options_table);
444 App::dialog_tool_options->present();
447 old_duckmask=get_work_area()->get_type_mask();
448 get_work_area()->set_type_mask(Duck::TYPE_ALL-Duck::TYPE_TANGENT-Duck::TYPE_WIDTH);
450 // Turn off layer clicking
451 get_work_area()->allow_layer_clicks=false;
453 // Turn off duck clicking
454 get_work_area()->allow_duck_clicks=false;
456 // clear out the ducks
457 //get_work_area()->clear_ducks();
459 // Refresh the work area
460 //get_work_area()->queue_draw();
462 // Hide the tables if they are showing
463 prev_table_status=get_canvas_view()->tables_are_visible();
464 //if(prev_table_status)get_canvas_view()->hide_tables();
466 // Disable the time bar
467 get_canvas_view()->set_sensitive_timebar(false);
470 //get_work_area()->signal_user_click().connect(sigc::mem_fun(*this,&studio::StateDraw_Context::on_user_click));
472 get_canvas_view()->work_area->set_cursor(Gdk::PENCIL);
474 App::toolbox->refresh();
480 void StateDraw_Context::UpdateErrorBox()
482 if(get_local_error_flag())
484 spin_globalthres.set_adjustment(adj_localthres);
485 spin_globalthres.set_value(adj_localthres.get_value());
486 spin_globalthres.set_increments(0.1,1);
489 spin_globalthres.set_adjustment(adj_globalthres);
490 spin_globalthres.set_value(adj_globalthres.get_value());
491 spin_globalthres.set_increments(0.01,.1);
494 spin_globalthres.update();
498 StateDraw_Context::refresh_tool_options()
500 App::dialog_tool_options->clear();
501 App::dialog_tool_options->set_widget(options_table);
502 App::dialog_tool_options->set_local_name(_("Draw Tool"));
503 App::dialog_tool_options->set_name("draw");
505 App::dialog_tool_options->add_button(
506 Gtk::StockID("synfig-fill"),
507 _("Fill Last Stroke")
508 )->signal_clicked().connect(
511 &StateDraw_Context::fill_last_stroke
518 StateDraw_Context::event_refresh_tool_options(const Smach::event& x)
520 refresh_tool_options();
521 return Smach::RESULT_ACCEPT;
524 StateDraw_Context::~StateDraw_Context()
528 App::dialog_tool_options->clear();
530 get_work_area()->set_type_mask(old_duckmask);
532 get_canvas_view()->work_area->reset_cursor();
534 // Restore layer clicking
535 get_work_area()->allow_layer_clicks=prev_workarea_layer_status_;
537 // Restore duck clicking
538 get_work_area()->allow_duck_clicks=true;
540 // Enable the time bar
541 get_canvas_view()->set_sensitive_timebar(true);
543 // Bring back the tables if they were out before
544 if(prev_table_status)get_canvas_view()->show_tables();
546 // Refresh the work area
547 get_work_area()->queue_draw();
549 App::toolbox->refresh();
553 StateDraw_Context::event_stop_handler(const Smach::event& x)
555 throw Smach::egress_exception();
559 StateDraw_Context::event_refresh_handler(const Smach::event& x)
562 return Smach::RESULT_ACCEPT;
566 StateDraw_Context::event_mouse_down_handler(const Smach::event& x)
568 const EventMouse& event(*reinterpret_cast<const EventMouse*>(&x));
573 // Enter the stroke state to get the stroke
574 get_canvas_view()->get_smach().push_state(&state_stroke);
575 return Smach::RESULT_ACCEPT;
578 case BUTTON_RIGHT: // Intercept the right-button click to short-circut the pop-up menu
579 return Smach::RESULT_ACCEPT;
582 return Smach::RESULT_OK;
586 #define SIMILAR_TANGENT_THRESHOLD (0.2)
591 debugclass(const synfig::String &x):x(x)
593 // synfig::warning(">>>>>>>>>>>>>>>>>>> "+x);
597 // synfig::warning("<<<<<<<<<<<<<<<<<<< "+x);
604 DepthCounter(int &i):i(i) { i++; }
605 ~DepthCounter() { i--; }
609 StateDraw_Context::event_stroke(const Smach::event& x)
611 // debugclass debugger("StateDraw_Context::event_stroke(const Smach::event& x)");
613 const EventStroke& event(*reinterpret_cast<const EventStroke*>(&x));
615 assert(event.stroke_data);
617 get_work_area()->add_stroke(event.stroke_data,synfigapp::Main::get_foreground_color());
621 DirtyTrap dirty_trap(get_work_area());
622 Smach::event_result result;
623 result=process_stroke(event.stroke_data,event.width_data,event.modifier&Gdk::CONTROL_MASK || event.modifier&Gdk::BUTTON2_MASK);
628 stroke_queue.push_back(pair<StrokeData,WidthData>(event.stroke_data,event.width_data));
630 return Smach::RESULT_ACCEPT;
634 StateDraw_Context::process_queue()
636 // debugclass debugger("StateDraw_Context::process_queue()");
639 DepthCounter depth_counter(nested);
640 while(!stroke_queue.empty())
642 pair<StrokeData,WidthData> front(stroke_queue.front());
643 process_stroke(front.first,front.second);
644 stroke_queue.pop_front();
650 StateDraw_Context::process_stroke(StrokeData stroke_data, WidthData width_data, bool region_flag)
652 // debugclass debugger("StateDraw_Context::process_stroke");
653 DepthCounter depth_counter(nested);
655 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);
658 // If we aren't using pressure width,
659 // then set all the width to 1
660 if(!get_pressure_width_flag())
662 std::list<synfig::Real>::iterator iter;
663 for(iter=width_data->begin();iter!=width_data->end();++iter)
669 //get_work_area()->add_stroke(event.stroke_data,synfigapp::Main::get_foreground_color());
670 //stroke_list.push_back(event.stroke_data);
673 std::list<synfig::BLinePoint> bline;
674 bool loop_bline_flag(false);
676 //Changed by Adrian - use resident class :)
677 //synfigapp::convert_stroke_to_bline(bline, *event.stroke_data,*event.width_data, synfigapp::Main::get_bline_width());
678 blineconv.width = synfigapp::Main::get_bline_width().units(get_canvas()->rend_desc());
680 if(get_local_error_flag())
682 float pw = get_work_area()->get_pw();
683 float ph = get_work_area()->get_ph();
685 blineconv.pixelwidth = sqrt(pw*pw+ph*ph);
686 blineconv.smoothness = get_lthres();
689 blineconv.pixelwidth = 1;
690 blineconv.smoothness = get_gthres();
693 blineconv(bline,*stroke_data,*width_data);
695 //Postprocess to require minimum pressure
696 if(get_min_pressure_flag())
698 synfigapp::BLineConverter::EnforceMinWidth(bline,get_min_pressure());
701 // If the start and end points are similar, then make them the same point
702 if(get_auto_loop_flag() &&
703 bline.size()>2&&(bline.front().get_vertex()-bline.back().get_vertex()).mag()<=radius)
705 loop_bline_flag=true;
709 while(bline.size()>2&&(bline.front().get_vertex()-bline.back().get_vertex()).mag()<=radius)
711 tangent=bline.back().get_tangent1();
712 width=bline.back().get_width();
716 if(abs(bline.front().get_tangent1().norm()*tangent.norm().perp())>SIMILAR_TANGENT_THRESHOLD)
718 // If the tangents are not similar, then
719 // split the tangents
720 bline.front().set_split_tangent_flag(true);
721 bline.front().set_tangent1(tangent);
725 // If the tangents are similar, then set the tangent
726 // to the average of the two
727 bline.front().set_tangent((tangent+bline.front().get_tangent1())*0.5f);
730 // Add the widths of the two points
732 Real tmp_width(bline.front().get_width()+width);
733 tmp_width=tmp_width<=1?tmp_width:1;
734 bline.front().set_width(tmp_width);
738 // If the bline only has one blinepoint, then there is nothing to do.
740 return Smach::RESULT_OK;
743 return new_region(bline,radius);
745 return new_bline(bline,loop_bline_flag,radius);
749 StateDraw_Context::new_bline(std::list<synfig::BLinePoint> bline,bool loop_bline_flag,float radius)
751 // Create the action group
752 synfigapp::Action::PassiveGrouper group(get_canvas_interface()->get_instance().get(),_("Sketch BLine"));
754 bool shift_offset = false;
755 Vector shift_offset_vector;
756 bool join_start_no_extend=false,join_finish_no_extend=false;
757 synfigapp::ValueDesc start_duck_value_desc,finish_duck_value_desc;
758 bool extend_start=false,extend_finish=false,complete_loop=false;
759 bool extend_start_join_same=false,extend_start_join_different=false;
760 bool extend_finish_join_same=false,extend_finish_join_different=false;
761 int start_duck_index,finish_duck_index;
762 ValueNode_BLine::Handle start_duck_value_node_bline=NULL,finish_duck_value_node_bline=NULL;
764 // Find any ducks at the start or end that we might attach to
765 // (this used to only run if we aren't a loop - ie. !loop_bline_flag
766 // but having loops auto-connect can be useful as well)
767 if(get_auto_extend_flag() || get_auto_link_flag())
769 etl::handle<Duck> start_duck(get_work_area()->find_duck(bline.front().get_vertex(),radius,Duck::TYPE_VERTEX));
770 etl::handle<Duck> finish_duck(get_work_area()->find_duck(bline.back().get_vertex(),radius,Duck::TYPE_VERTEX));
772 // check whether the start of the new line extends an
773 // existing line. this is only the case if the new
774 // line isn't a self-contained loop, and if the new
775 // line starts at one of the ends of an existing line
778 if(!(start_duck_value_desc=start_duck->get_value_desc()))break;
779 if(loop_bline_flag)break;
780 if(!start_duck_value_desc.parent_is_value_node())break;
781 start_duck_index=start_duck_value_desc.get_index();
782 start_duck_value_node_bline=ValueNode_BLine::Handle::cast_dynamic(start_duck_value_desc.get_parent_value_node());
783 if(!get_auto_extend_flag())break;
785 // don't extend looped blines
786 if(start_duck_value_node_bline&&!start_duck_value_node_bline->get_loop()&&
787 (start_duck_index==0||start_duck_index==start_duck_value_node_bline->link_count()-1))
791 shift_offset_vector=start_duck->get_origin();
795 // check whether the end of the new line extends an
796 // existing line. this is only the case if the new
797 // line isn't a self-contained loop, and if the new
798 // line ends at one of the ends of an existing line
801 if(!(finish_duck_value_desc=finish_duck->get_value_desc()))break;
802 if(loop_bline_flag)break;
803 if(!finish_duck_value_desc.parent_is_value_node())break;
804 finish_duck_index=finish_duck_value_desc.get_index();
805 finish_duck_value_node_bline=ValueNode_BLine::Handle::cast_dynamic(finish_duck_value_desc.get_parent_value_node());
806 if(!get_auto_extend_flag())break;
808 // don't extend looped blines
809 if(finish_duck_value_node_bline&&!finish_duck_value_node_bline->get_loop()&&
810 (finish_duck_index==0||finish_duck_index==finish_duck_value_node_bline->link_count()-1))
813 // we've started and finished drawing at the end of a bline. we can't
814 // extend both blines, so unless we started and finished at the 2 ends
815 // of the same bline, only extend the one we started on
816 if(start_duck_value_node_bline==finish_duck_value_node_bline)
817 complete_loop=extend_finish=true;
821 shift_offset_vector=finish_duck->get_origin();
825 // if the new line's start didn't extend an existing line,
826 // check whether it needs to be linked to an existing duck
827 if(!extend_start&&get_auto_link_flag()&&start_duck&&start_duck_value_desc)
828 switch(start_duck_value_desc.get_value_type())
830 case synfig::ValueBase::TYPE_BLINEPOINT:
831 start_duck_value_desc=synfigapp::ValueDesc(LinkableValueNode::Handle::cast_dynamic(start_duck_value_desc.get_value_node()),0);
833 case synfig::ValueBase::TYPE_VECTOR:
834 if (shift_offset && shift_offset_vector != start_duck->get_origin())
837 shift_offset_vector = start_duck->get_origin();
838 get_canvas_interface()->auto_export(start_duck_value_desc);
840 if(start_duck_value_node_bline&&start_duck_value_node_bline==finish_duck_value_node_bline)
841 extend_finish_join_same=true;
843 extend_finish_join_different=true;
845 join_start_no_extend=true;
850 // if the new line's end didn't extend an existing line,
851 // check whether it needs to be linked to an existing duck
852 if(!extend_finish&&get_auto_link_flag()&&finish_duck&&finish_duck_value_desc)
853 switch(finish_duck_value_desc.get_value_type())
855 case synfig::ValueBase::TYPE_BLINEPOINT:
856 finish_duck_value_desc=synfigapp::ValueDesc(LinkableValueNode::Handle::cast_dynamic(finish_duck_value_desc.get_value_node()),0);
858 case synfig::ValueBase::TYPE_VECTOR:
859 if (shift_offset && shift_offset_vector != finish_duck->get_origin())
862 shift_offset_vector = finish_duck->get_origin();
863 get_canvas_interface()->auto_export(finish_duck_value_desc);
865 if(finish_duck_value_node_bline&&start_duck_value_node_bline==finish_duck_value_node_bline)
866 extend_start_join_same=true;
868 extend_start_join_different=true;
870 join_finish_no_extend=true;
876 ValueNode_BLine::Handle value_node;
877 std::list<synfig::BLinePoint> trans_bline;
880 std::list<synfig::BLinePoint>::iterator iter;
881 const synfig::TransformStack& transform(get_canvas_view()->get_curr_transform_stack());
883 for(iter=bline.begin();iter!=bline.end();++iter)
885 BLinePoint bline_point(*iter);
886 Point new_vertex(transform.unperform(bline_point.get_vertex()));
888 bline_point.set_tangent1(
890 bline_point.get_tangent1()+bline_point.get_vertex()
894 bline_point.set_tangent2(
896 bline_point.get_tangent2()+bline_point.get_vertex()
901 new_vertex=new_vertex-shift_offset_vector;
903 bline_point.set_vertex(new_vertex);
905 trans_bline.push_back(bline_point);
907 value_node=ValueNode_BLine::create(synfig::ValueBase(trans_bline,loop_bline_flag));
910 Smach::event_result result;
911 synfig::ValueNode_DynamicList::ListEntry source;
914 // the new line's start extends an existing line
917 if(complete_loop)trans_bline.pop_back();
918 trans_bline.pop_front();
919 if(start_duck_index==0)
920 { // We need to reverse the BLine first.
921 reverse_bline(trans_bline);
922 result=extend_bline_from_begin(start_duck_value_node_bline,trans_bline,complete_loop);
923 source=start_duck_value_node_bline->list.front();
924 target_index=trans_bline.size()+finish_duck_index;
928 result=extend_bline_from_end(start_duck_value_node_bline,trans_bline,complete_loop);
929 source=start_duck_value_node_bline->list.back();
930 target_index=finish_duck_index;
933 if(extend_start_join_different)
934 LinkableValueNode::Handle::cast_dynamic(source.value_node)->
935 set_link(0,finish_duck_value_desc.get_value_node());
936 else if(extend_start_join_same)
937 LinkableValueNode::Handle::cast_dynamic(source.value_node)->
938 set_link(0,synfigapp::ValueDesc(LinkableValueNode::Handle::cast_dynamic(start_duck_value_node_bline->
939 list[target_index].value_node),0).get_value_node());
943 // the new line's end extends an existing line
945 { // SPECIAL CASE -- EXTENSION
946 trans_bline.pop_back();
947 if(finish_duck_index==0)
949 result=extend_bline_from_begin(finish_duck_value_node_bline,trans_bline,false);
950 source=finish_duck_value_node_bline->list.front();
951 target_index=trans_bline.size()+start_duck_index;
954 { // We need to reverse the BLine first.
955 reverse_bline(trans_bline);
956 result=extend_bline_from_end(finish_duck_value_node_bline,trans_bline,false);
957 source=finish_duck_value_node_bline->list.back();
958 target_index=start_duck_index;
961 if(extend_finish_join_different)
962 LinkableValueNode::Handle::cast_dynamic(source.value_node)->
963 set_link(0,start_duck_value_desc.get_value_node());
964 else if(extend_finish_join_same)
965 LinkableValueNode::Handle::cast_dynamic(source.value_node)->
966 set_link(0,synfigapp::ValueDesc(LinkableValueNode::Handle::cast_dynamic(finish_duck_value_node_bline->
967 list[target_index].value_node),0).get_value_node());
971 if (join_start_no_extend)
972 LinkableValueNode::Handle::cast_dynamic(value_node->list.front().value_node)->
973 set_link(0,start_duck_value_desc.get_value_node());
975 if (join_finish_no_extend)
976 LinkableValueNode::Handle::cast_dynamic(value_node->list.back().value_node)->
977 set_link(0,finish_duck_value_desc.get_value_node());
979 if(get_auto_export_flag()) {
980 printf("this is where we would export the new line\n");
981 if (!get_canvas_interface()->add_value_node(value_node,get_id()))
983 /* it's no big deal, is it? let's keep the shape anyway */
984 // get_canvas_view()->get_ui_interface()->error(_("Unable to add value node"));
987 // return Smach::RESULT_ERROR;
994 Canvas::Handle canvas(get_canvas_view()->get_canvas());
997 // we are temporarily using the layer to hold something
998 layer=get_canvas_view()->get_selection_manager()->get_selected_layer();
1001 depth=layer->get_depth();
1002 canvas=layer->get_canvas();
1005 //int number(synfig::UniqueID().get_uid());
1007 synfigapp::PushMode push_mode(get_canvas_interface(),synfigapp::MODE_NORMAL);
1009 if(get_region_only_flag())
1011 layer=get_canvas_interface()->add_layer_to("region",canvas,depth);
1012 layer->set_description(get_id()+_(" Region"));
1016 layer=get_canvas_interface()->add_layer_to("outline",canvas,depth);
1017 layer->set_description(get_id()+_(" Outline"));
1022 layer->set_param("feather",get_feather());
1023 get_canvas_interface()->signal_layer_param_changed()(layer,"feather");
1026 //layer->set_description(strprintf("Stroke %d",number));
1027 //get_canvas_interface()->signal_layer_new_description()(layer,layer->get_description());
1030 get_canvas_interface()->
1031 change_value(synfigapp::ValueDesc(layer,"offset"),shift_offset_vector);
1033 synfigapp::Action::Handle action(synfigapp::Action::create("layer_param_connect"));
1037 action->set_param("canvas",get_canvas());
1038 action->set_param("canvas_interface",get_canvas_interface());
1039 action->set_param("layer",layer);
1040 if(!action->set_param("param",String("bline")))
1041 synfig::error("LayerParamConnect didn't like \"param\"");
1042 if(!action->set_param("value_node",ValueNode::Handle(value_node)))
1043 synfig::error("LayerParamConnect didn't like \"value_node\"");
1045 if(!get_canvas_interface()->get_instance()->perform_action(action))
1047 get_canvas_view()->get_ui_interface()->error(_("Unable to create layer"));
1051 return Smach::RESULT_ERROR;
1053 get_canvas_view()->get_selection_manager()->set_selected_layer(layer);
1058 last_stroke=value_node;
1059 return Smach::RESULT_ACCEPT;
1063 StateDraw_Context::new_region(std::list<synfig::BLinePoint> bline, synfig::Real radius)
1065 // Create the action group
1066 synfigapp::Action::PassiveGrouper group(get_canvas_interface()->get_instance().get(),_("Define Region"));
1068 std::list<synfigapp::ValueDesc> vertex_list;
1070 // First we need to come up with a rough list of
1071 // BLinePoints that we are going to be using to
1072 // define our region.
1074 std::list<synfig::BLinePoint>::iterator iter;
1075 for(iter=bline.begin();iter!=bline.end();++iter)
1077 etl::handle<Duck> duck(get_work_area()->find_duck(iter->get_vertex(),0,Duck::TYPE_VERTEX));
1081 synfig::info(__FILE__":%d: Nothing to enclose!",__LINE__);
1082 return Smach::RESULT_OK;
1086 assert(duck->get_type()==Duck::TYPE_VERTEX);
1088 synfigapp::ValueDesc value_desc(duck->get_value_desc());
1092 synfig::info(__FILE__":%d: Got a hit, but no ValueDesc on this duck",__LINE__);
1096 switch(value_desc.get_value_type())
1098 case synfig::ValueBase::TYPE_BLINEPOINT:
1099 //if(vertex_list.empty() || value_desc!=vertex_list.back())
1100 vertex_list.push_back(value_desc);
1101 assert(vertex_list.back().is_valid());
1110 if(vertex_list.size()<=2)
1112 synfig::info(__FILE__":%d: Vertex list too small to make region.",__LINE__);
1113 return Smach::RESULT_OK;
1116 assert(vertex_list.back().is_valid());
1118 // Remove any duplicates
1122 // Now we need to clean the list of vertices up
1123 // a bit. This includes inserting missing vertices
1124 // and removing extraneous ones.
1125 // We can do this in multiple passes.
1127 for(bool done=false;!done && i<30;i++)
1129 // Set done to "true" for now. If
1130 // any updates are performed, we will
1131 // change it back to false.
1134 std::list<synfigapp::ValueDesc>::iterator prev,iter,next;
1135 prev=vertex_list.end();prev--; // Set prev to the last ValueDesc
1136 next=vertex_list.begin();
1137 iter=next++; // Set iter to the first value desc, and next to the second
1139 for(;iter!=vertex_list.end();prev=iter,iter=next++)
1141 synfigapp::ValueDesc value_prev(*prev);
1142 synfigapp::ValueDesc value_desc(*iter);
1143 synfigapp::ValueDesc value_next((next==vertex_list.end())?vertex_list.front():*next);
1145 assert(value_desc.is_valid());
1146 assert(value_next.is_valid());
1147 assert(value_prev.is_valid());
1149 //synfig::info("-------");
1150 //synfig::info(__FILE__":%d: value_prev 0x%08X:%d",__LINE__,value_prev.get_parent_value_node().get(),value_prev.get_index());
1151 //synfig::info(__FILE__":%d: value_desc 0x%08X:%d",__LINE__,value_desc.get_parent_value_node().get(),value_desc.get_index());
1152 //synfig::info(__FILE__":%d: value_next 0x%08X:%d",__LINE__,value_next.get_parent_value_node().get(),value_next.get_index());
1155 if(value_prev.parent_is_value_node() && value_desc.parent_is_value_node() && value_next.parent_is_value_node())
1157 // Remove random extraneous vertices
1158 if(value_prev.get_parent_value_node()==value_next.get_parent_value_node() &&
1159 value_prev.get_parent_value_node()!=value_desc.get_parent_value_node())
1162 vertex_list.erase(iter);
1169 // Remove duplicate vertices
1170 if(value_prev.get_value_node()==value_desc.get_value_node()
1171 || value_desc.get_value_node()==value_next.get_value_node())
1174 vertex_list.erase(iter);
1178 if(value_prev.get_value_node()==value_next.get_value_node())
1181 vertex_list.erase(prev);
1186 if(value_desc.parent_is_value_node() && value_next.parent_is_value_node())
1187 if(value_desc.get_parent_value_node()==value_next.get_parent_value_node() && (next!=vertex_list.end()))
1189 // Fill in missing vertices
1190 if(value_desc.get_index()<value_next.get_index()-1)
1193 vertex_list.insert(next,synfigapp::ValueDesc(value_desc.get_parent_value_node(),value_desc.get_index()+1));
1197 if(value_next.get_index()<value_desc.get_index()-1)
1200 vertex_list.insert(next,synfigapp::ValueDesc(value_desc.get_parent_value_node(),value_next.get_index()+1));
1206 // Ensure that connections
1207 // between blines are properly
1209 if(value_desc.parent_is_value_node() && value_next.parent_is_value_node())
1210 if(value_desc.get_parent_value_node()!=value_next.get_parent_value_node() &&
1211 value_desc.get_value_node()!=value_next.get_value_node())
1213 BLinePoint vertex(value_desc.get_value(get_time()).get(BLinePoint()));
1214 BLinePoint vertex_next(value_next.get_value(get_time()).get(BLinePoint()));
1216 //synfig::info("--------");
1217 //synfig::info(__FILE__":%d: vertex: [%f, %f]",__LINE__,vertex.get_vertex()[0],vertex.get_vertex()[1]);
1218 //synfig::info(__FILE__":%d: vertex_next: [%f, %f]",__LINE__,vertex_next.get_vertex()[0],vertex_next.get_vertex()[1]);
1220 if((vertex.get_vertex()-vertex_next.get_vertex()).mag_squared()<radius*radius)
1223 ValueNode_Composite::Handle value_node;
1224 ValueNode_Composite::Handle value_node_next;
1225 value_node=ValueNode_Composite::Handle::cast_dynamic(value_desc.get_value_node().clone());
1226 value_node_next=ValueNode_Composite::Handle::cast_dynamic(value_next.get_value_node().clone());
1227 if(!value_node || !value_node_next)
1229 synfig::info(__FILE__":%d: Unable to properly connect blines.",__LINE__);
1233 value_node->set_link(5,value_node_next->get_link(5));
1234 value_node->set_link(3,ValueNode_Const::create(true));
1236 get_canvas_interface()->auto_export(value_node);
1237 assert(value_node->is_exported());
1238 *iter=synfigapp::ValueDesc(get_canvas(),value_node->get_id());
1239 vertex_list.erase(next);
1246 bool positive_trend(value_desc.get_index()>value_prev.get_index());
1248 if(!positive_trend && value_desc.get_index()>0)
1251 vertex_list.insert(next,synfigapp::ValueDesc(value_desc.get_parent_value_node(),value_desc.get_index()-1));
1255 if(positive_trend && value_desc.get_index()<LinkableValueNode::Handle::cast_static(value_desc.get_value_node())->link_count()-1)
1258 vertex_list.insert(next,synfigapp::ValueDesc(value_desc.get_parent_value_node(),value_desc.get_index()+1));
1268 if(vertex_list.size()<=2)
1270 synfig::info(__FILE__":%d: Vertex list too small to make region.",__LINE__);
1271 return Smach::RESULT_OK;
1274 ValueNode_BLine::Handle value_node_bline;
1276 // Now we need to test for the trivial case,
1277 // which is where all of the vertices
1278 // come from one BLine.
1279 if(vertex_list.front().parent_is_linkable_value_node())
1281 bool trivial_case(true);
1282 ValueNode::Handle trivial_case_value_node;
1284 trivial_case_value_node=vertex_list.front().get_parent_value_node();
1286 std::list<synfigapp::ValueDesc>::iterator iter;
1287 for(iter=vertex_list.begin();iter!=vertex_list.end();++iter)
1289 if(trivial_case_value_node!=iter->get_parent_value_node())
1296 value_node_bline=ValueNode_BLine::Handle::cast_dynamic(trivial_case_value_node);
1299 // If we aren't the trivial case,
1300 // then go ahead and create the new
1302 if(!value_node_bline)
1304 value_node_bline=ValueNode_BLine::create();
1306 std::list<synfigapp::ValueDesc>::iterator iter;
1307 for(iter=vertex_list.begin();iter!=vertex_list.end();++iter)
1309 // Ensure that the vertex is exported.
1310 get_canvas_interface()->auto_export(*iter);
1312 value_node_bline->add(iter->get_value_node());
1313 //value_node_bline->add(ValueNode_BLine::ListEntry(iter->get_value_node()));
1316 value_node_bline->set_loop(true);
1319 get_canvas_interface()->auto_export(value_node_bline);
1321 // Now we create the region layer
1324 Layer::Handle layer;
1325 Canvas::Handle canvas(get_canvas_view()->get_canvas());
1328 // we are temporarily using the layer to hold something
1329 layer=get_canvas_view()->get_selection_manager()->get_selected_layer();
1332 depth=layer->get_depth();
1333 canvas=layer->get_canvas();
1336 synfigapp::PushMode push_mode(get_canvas_interface(),synfigapp::MODE_NORMAL);
1338 layer=get_canvas_interface()->add_layer_to("region",canvas,depth);
1340 layer->set_param("color",synfigapp::Main::get_background_color());
1343 layer->set_param("feather",get_feather());
1344 get_canvas_interface()->signal_layer_param_changed()(layer,"feather");
1346 get_canvas_interface()->signal_layer_param_changed()(layer,"color");
1348 synfigapp::Action::Handle action(synfigapp::Action::create("layer_param_connect"));
1352 action->set_param("canvas",get_canvas());
1353 action->set_param("canvas_interface",get_canvas_interface());
1354 action->set_param("layer",layer);
1355 if(!action->set_param("param",String("bline")))
1356 synfig::error("LayerParamConnect didn't like \"param\"");
1357 if(!action->set_param("value_node",ValueNode::Handle(value_node_bline)))
1358 synfig::error("LayerParamConnect didn't like \"value_node\"");
1360 if(!get_canvas_interface()->get_instance()->perform_action(action))
1362 get_canvas_view()->get_ui_interface()->error(_("Unable to create Region layer"));
1364 return Smach::RESULT_ERROR;
1366 get_canvas_view()->get_selection_manager()->set_selected_layer(layer);
1369 return Smach::RESULT_ACCEPT;
1373 StateDraw_Context::refresh_ducks()
1375 get_canvas_view()->queue_rebuild_ducks();
1377 get_work_area()->clear_ducks();
1380 std::list< etl::smart_ptr<std::list<synfig::Point> > >::iterator iter;
1382 for(iter=stroke_list.begin();iter!=stroke_list.end();++iter)
1384 get_work_area()->add_stroke(*iter);
1387 get_work_area()->queue_draw();
1393 StateDraw_Context::extend_bline_from_begin(ValueNode_BLine::Handle value_node,std::list<synfig::BLinePoint> bline,bool complete_loop)
1395 // Create the action group
1396 synfigapp::Action::PassiveGrouper group(get_canvas_interface()->get_instance().get(),_("Extend BLine"));
1400 synfigapp::Action::Handle action(synfigapp::Action::create("value_node_dynamic_list_loop"));
1403 action->set_param("canvas",get_canvas());
1404 action->set_param("canvas_interface",get_canvas_interface());
1405 action->set_param("value_node",ValueNode::Handle(value_node));
1407 if(!get_canvas_interface()->get_instance()->perform_action(action))
1409 get_canvas_view()->get_ui_interface()->error(_("Unable to set loop for bline"));
1411 return Smach::RESULT_ERROR;
1415 std::list<synfig::BLinePoint>::reverse_iterator iter;
1416 for(iter=bline.rbegin();!(iter==bline.rend());++iter)
1418 ValueNode_Composite::Handle composite(ValueNode_Composite::create(*iter));
1420 synfigapp::Action::Handle action(synfigapp::Action::create("value_node_dynamic_list_insert"));
1423 synfigapp::ValueDesc value_desc(value_node,0);
1425 action->set_param("canvas",get_canvas());
1426 action->set_param("canvas_interface",get_canvas_interface());
1427 action->set_param("value_desc",value_desc);
1428 if(!action->set_param("item",ValueNode::Handle(composite)))
1429 synfig::error("ACTION didn't like \"item\"");
1431 if(!get_canvas_interface()->get_instance()->perform_action(action))
1433 get_canvas_view()->get_ui_interface()->error(_("Unable to insert item"));
1436 return Smach::RESULT_ERROR;
1439 last_stroke=value_node;
1440 return Smach::RESULT_ACCEPT;
1444 StateDraw_Context::extend_bline_from_end(ValueNode_BLine::Handle value_node,std::list<synfig::BLinePoint> bline,bool complete_loop)
1446 // Create the action group
1447 synfigapp::Action::PassiveGrouper group(get_canvas_interface()->get_instance().get(),_("Extend BLine"));
1451 synfigapp::Action::Handle action(synfigapp::Action::create("value_node_dynamic_list_loop"));
1454 action->set_param("canvas",get_canvas());
1455 action->set_param("canvas_interface",get_canvas_interface());
1456 action->set_param("value_node",ValueNode::Handle(value_node));
1458 if(!get_canvas_interface()->get_instance()->perform_action(action))
1460 get_canvas_view()->get_ui_interface()->error(_("Unable to set loop for bline"));
1462 return Smach::RESULT_ERROR;
1466 std::list<synfig::BLinePoint>::iterator iter;
1467 for(iter=bline.begin();iter!=bline.end();++iter)
1469 ValueNode_Composite::Handle composite(ValueNode_Composite::create(*iter));
1471 synfigapp::Action::Handle action(synfigapp::Action::create("value_node_dynamic_list_insert"));
1474 synfigapp::ValueDesc value_desc(value_node,value_node->link_count());
1476 action->set_param("canvas",get_canvas());
1477 action->set_param("canvas_interface",get_canvas_interface());
1478 action->set_param("value_desc",value_desc);
1479 if(!action->set_param("item",ValueNode::Handle(composite)))
1480 synfig::error("ACTION didn't like \"item\"");
1482 if(!get_canvas_interface()->get_instance()->perform_action(action))
1484 get_canvas_view()->get_ui_interface()->error(_("Unable to insert item"));
1487 return Smach::RESULT_ERROR;
1490 last_stroke=value_node;
1491 return Smach::RESULT_ACCEPT;
1495 StateDraw_Context::reverse_bline(std::list<synfig::BLinePoint> &bline)
1499 std::list<synfig::BLinePoint>::iterator iter,eiter;
1503 for(i=0;i<(int)bline.size()/2;++iter,--eiter,i++)
1505 iter_swap(iter,eiter);
1512 StateDraw_Context::fill_last_stroke()
1517 synfigapp::Action::PassiveGrouper group(get_canvas_interface()->get_instance().get(),_("Fill Stroke"));
1519 Layer::Handle layer;
1521 get_canvas_interface()->auto_export(last_stroke);
1523 synfigapp::PushMode push_mode(get_canvas_interface(),synfigapp::MODE_NORMAL);
1525 layer=get_canvas_interface()->add_layer("region");
1527 layer->set_param("color",synfigapp::Main::get_background_color());
1529 synfigapp::Action::Handle action(synfigapp::Action::create("layer_param_connect"));
1533 action->set_param("canvas",get_canvas());
1534 action->set_param("canvas_interface",get_canvas_interface());
1535 action->set_param("layer",layer);
1536 if(!action->set_param("param",String("segment_list")))
1537 synfig::error("LayerParamConnect didn't like \"param\"");
1538 if(!action->set_param("value_node",ValueNode::Handle(last_stroke)))
1539 synfig::error("LayerParamConnect didn't like \"value_node\"");
1541 if(!get_canvas_interface()->get_instance()->perform_action(action))
1543 get_canvas_view()->get_ui_interface()->error(_("Unable to create Region layer"));
1547 get_canvas_view()->get_selection_manager()->set_selected_layer(layer);