1 /* === S Y N F I G ========================================================= */
2 /*! \file state_polygon.cpp
3 ** \brief Template File
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 ** Copyright (c) 2007, 2008 Chris Moore
11 ** This package is free software; you can redistribute it and/or
12 ** modify it under the terms of the GNU General Public License as
13 ** published by the Free Software Foundation; either version 2 of
14 ** the License, or (at your option) any later version.
16 ** This package is distributed in the hope that it will be useful,
17 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 ** General Public License for more details.
22 /* ========================================================================= */
24 /* === H E A D E R S ======================================================= */
33 #include <gtkmm/dialog.h>
34 #include <gtkmm/entry.h>
36 #include <synfig/valuenode_dynamiclist.h>
37 #include <synfigapp/action_system.h>
38 #include <synfig/valuenode_bline.h>
40 #include "state_polygon.h"
41 #include "canvasview.h"
45 #include <synfigapp/action.h>
46 #include "event_mouse.h"
47 #include "event_layerclick.h"
49 #include "dialog_tooloptions.h"
50 #include <synfigapp/main.h>
56 /* === U S I N G =========================================================== */
60 using namespace synfig;
61 using namespace studio;
63 /* === M A C R O S ========================================================= */
65 /* === G L O B A L S ======================================================= */
67 StatePolygon studio::state_polygon;
69 /* === C L A S S E S & S T R U C T S ======================================= */
71 class studio::StatePolygon_Context : public sigc::trackable
73 etl::handle<CanvasView> canvas_view_;
74 CanvasView::IsWorking is_working;
76 bool prev_table_status;
77 bool prev_workarea_layer_status_;
81 Duckmatic::Push duckmatic_push;
83 std::list<synfig::Point> polygon_point_list;
84 synfigapp::Settings& settings;
87 bool on_polygon_duck_change(const synfig::Point &point, std::list<synfig::Point>::iterator iter);
90 void popup_handle_menu(synfigapp::ValueDesc value_desc);
95 Gtk::Table options_table;
97 Gtk::CheckButton checkbutton_invert;
98 Gtk::CheckButton checkbutton_layer_polygon;
99 Gtk::CheckButton checkbutton_layer_region;
100 Gtk::CheckButton checkbutton_layer_outline;
101 Gtk::CheckButton checkbutton_layer_curve_gradient;
102 Gtk::CheckButton checkbutton_layer_plant;
103 Gtk::CheckButton checkbutton_layer_link_origins;
104 Gtk::Button button_make;
105 Gtk::Adjustment adj_feather;
106 Gtk::SpinButton spin_feather;
110 // this counts the layers we create - they all have origins we can link
111 int layers_to_create()const
114 get_layer_polygon_flag() +
115 get_layer_region_flag() +
116 get_layer_outline_flag() +
117 get_layer_curve_gradient_flag() +
118 get_layer_plant_flag();
121 synfig::String get_id()const { return entry_id.get_text(); }
122 void set_id(const synfig::String& x) { return entry_id.set_text(x); }
124 bool get_invert()const { return checkbutton_invert.get_active(); }
125 void set_invert(bool i) { checkbutton_invert.set_active(i); }
127 bool get_layer_polygon_flag()const { return checkbutton_layer_polygon.get_active(); }
128 void set_layer_polygon_flag(bool x) { return checkbutton_layer_polygon.set_active(x); }
130 bool get_layer_region_flag()const { return checkbutton_layer_region.get_active(); }
131 void set_layer_region_flag(bool x) { return checkbutton_layer_region.set_active(x); }
133 bool get_layer_outline_flag()const { return checkbutton_layer_outline.get_active(); }
134 void set_layer_outline_flag(bool x) { return checkbutton_layer_outline.set_active(x); }
136 bool get_layer_curve_gradient_flag()const { return checkbutton_layer_curve_gradient.get_active(); }
137 void set_layer_curve_gradient_flag(bool x) { return checkbutton_layer_curve_gradient.set_active(x); }
139 bool get_layer_plant_flag()const { return checkbutton_layer_plant.get_active(); }
140 void set_layer_plant_flag(bool x) { return checkbutton_layer_plant.set_active(x); }
142 bool get_layer_link_origins_flag()const { return checkbutton_layer_link_origins.get_active(); }
143 void set_layer_link_origins_flag(bool x) { return checkbutton_layer_link_origins.set_active(x); }
145 Real get_feather() const { return adj_feather.get_value(); }
146 void set_feather(Real x) { return adj_feather.set_value(x); }
148 Smach::event_result event_stop_handler(const Smach::event& x);
150 Smach::event_result event_refresh_handler(const Smach::event& x);
152 Smach::event_result event_mouse_click_handler(const Smach::event& x);
153 Smach::event_result event_refresh_tool_options(const Smach::event& x);
154 void refresh_tool_options();
156 StatePolygon_Context(CanvasView* canvas_view);
158 ~StatePolygon_Context();
160 const etl::handle<CanvasView>& get_canvas_view()const{return canvas_view_;}
161 etl::handle<synfigapp::CanvasInterface> get_canvas_interface()const{return canvas_view_->canvas_interface();}
162 synfig::Canvas::Handle get_canvas()const{return canvas_view_->get_canvas();}
163 WorkArea * get_work_area()const{return canvas_view_->get_work_area();}
165 //void on_user_click(synfig::Point point);
166 void load_settings();
167 void save_settings();
170 bool egress_on_selection_change;
171 Smach::event_result event_layer_selection_changed_handler(const Smach::event& /*x*/)
173 if(egress_on_selection_change)
174 throw Smach::egress_exception();
175 return Smach::RESULT_OK;
179 }; // END of class StatePolygon_Context
181 /* === M E T H O D S ======================================================= */
183 StatePolygon::StatePolygon():
184 Smach::state<StatePolygon_Context>("polygon")
186 insert(event_def(EVENT_LAYER_SELECTION_CHANGED,&StatePolygon_Context::event_layer_selection_changed_handler));
187 insert(event_def(EVENT_STOP,&StatePolygon_Context::event_stop_handler));
188 insert(event_def(EVENT_REFRESH,&StatePolygon_Context::event_refresh_handler));
189 insert(event_def(EVENT_REFRESH_DUCKS,&StatePolygon_Context::event_refresh_handler));
190 insert(event_def(EVENT_WORKAREA_MOUSE_BUTTON_DOWN,&StatePolygon_Context::event_mouse_click_handler));
191 insert(event_def(EVENT_REFRESH_TOOL_OPTIONS,&StatePolygon_Context::event_refresh_tool_options));
194 StatePolygon::~StatePolygon()
199 StatePolygon_Context::load_settings()
203 if(settings.get_value("polygon.id",value))
208 if(settings.get_value("polygon.invert",value) && value != "0")
213 if(settings.get_value("polygon.layer_polygon",value) && value=="0")
214 set_layer_polygon_flag(false);
216 set_layer_polygon_flag(true);
218 if(settings.get_value("polygon.layer_region",value) && value=="1")
219 set_layer_region_flag(true);
221 set_layer_region_flag(false);
223 if(settings.get_value("polygon.layer_outline",value) && value=="1")
224 set_layer_outline_flag(true);
226 set_layer_outline_flag(false);
228 if(settings.get_value("polygon.layer_curve_gradient",value) && value=="1")
229 set_layer_curve_gradient_flag(true);
231 set_layer_curve_gradient_flag(false);
233 if(settings.get_value("polygon.layer_plant",value) && value=="1")
234 set_layer_plant_flag(true);
236 set_layer_plant_flag(false);
238 if(settings.get_value("polygon.layer_link_origins",value) && value=="0")
239 set_layer_link_origins_flag(false);
241 set_layer_link_origins_flag(true);
243 if(settings.get_value("polygon.feather",value))
245 Real n = atof(value.c_str());
251 StatePolygon_Context::save_settings()
253 settings.set_value("polygon.id",get_id().c_str());
254 settings.set_value("polygon.invert",get_invert()?"1":"0");
255 settings.set_value("polygon.layer_polygon",get_layer_polygon_flag()?"1":"0");
256 settings.set_value("polygon.layer_outline",get_layer_outline_flag()?"1":"0");
257 settings.set_value("polygon.layer_region",get_layer_region_flag()?"1":"0");
258 settings.set_value("polygon.layer_curve_gradient",get_layer_curve_gradient_flag()?"1":"0");
259 settings.set_value("polygon.layer_plant",get_layer_plant_flag()?"1":"0");
260 settings.set_value("polygon.layer_link_origins",get_layer_link_origins_flag()?"1":"0");
261 settings.set_value("polygon.feather",strprintf("%f",get_feather()));
265 StatePolygon_Context::reset()
267 polygon_point_list.clear();
272 StatePolygon_Context::increment_id()
281 // If there is a number
282 // already at the end of the
283 // id, then remove it.
284 if(id[id.size()-1]<='9' && id[id.size()-1]>='0')
286 // figure out how many digits it is
288 (int)id.size()-1 >= digits && id[id.size()-1-digits] <= '9' && id[id.size()-1-digits] >= '0';
293 str_number=String(id,id.size()-digits,id.size());
294 id=String(id,0,id.size()-digits);
296 number=atoi(str_number.c_str());
306 // Add the number back onto the id
308 const String format(strprintf("%%0%dd",digits));
309 id+=strprintf(format.c_str(),number);
316 StatePolygon_Context::StatePolygon_Context(CanvasView* canvas_view):
317 canvas_view_(canvas_view),
318 is_working(*canvas_view),
319 prev_workarea_layer_status_(get_work_area()->get_allow_layer_clicks()),
320 duckmatic_push(get_work_area()),
321 settings(synfigapp::Main::get_selected_input_device()->settings()),
323 checkbutton_invert(_("Invert")),
324 checkbutton_layer_polygon(_("Create Polygon Layer")),
325 checkbutton_layer_region(_("Create Region BLine")),
326 checkbutton_layer_outline(_("Create Outline BLine")),
327 checkbutton_layer_curve_gradient(_("Create Curve Gradient BLine")),
328 checkbutton_layer_plant(_("Create Plant BLine")),
329 checkbutton_layer_link_origins(_("Link Origins")),
330 button_make(_("Make")),
331 adj_feather(0,0,10000,0.01,0.1),
332 spin_feather(adj_feather,0.01,4)
334 egress_on_selection_change=true;
337 // Set up the tool options dialog
338 options_table.attach(*manage(new Gtk::Label(_("Polygon Tool"))), 0, 2, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
339 options_table.attach(entry_id, 0, 2, 1, 2, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
341 options_table.attach(checkbutton_layer_polygon, 0, 2, 2, 3, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
342 options_table.attach(checkbutton_layer_outline, 0, 2, 3, 4, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
343 options_table.attach(checkbutton_layer_region, 0, 2, 4, 5, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
344 options_table.attach(checkbutton_layer_plant, 0, 2, 5, 6, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
345 options_table.attach(checkbutton_layer_curve_gradient, 0, 2, 6, 7, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
346 options_table.attach(checkbutton_layer_link_origins, 0, 2, 7, 8, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
349 options_table.attach(checkbutton_invert, 0, 2, 8, 9, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
352 options_table.attach(*manage(new Gtk::Label(_("Feather"))), 0, 1, 9, 10, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
353 options_table.attach(spin_feather, 1, 2, 9, 10, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
355 //options_table.attach(button_make, 0, 2, 4, 5, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
356 button_make.signal_pressed().connect(sigc::mem_fun(*this,&StatePolygon_Context::run));
357 options_table.show_all();
358 refresh_tool_options();
359 App::dialog_tool_options->present();
362 // Turn off layer clicking
363 get_work_area()->set_allow_layer_clicks(false);
365 // clear out the ducks
366 get_work_area()->clear_ducks();
368 // Refresh the work area
369 get_work_area()->queue_draw();
371 get_canvas_view()->work_area->set_cursor(Gdk::CROSSHAIR);
373 // Hide the tables if they are showing
374 prev_table_status=get_canvas_view()->tables_are_visible();
375 if(prev_table_status)get_canvas_view()->hide_tables();
377 // Disable the time bar
378 get_canvas_view()->set_sensitive_timebar(false);
381 //get_work_area()->signal_user_click().connect(sigc::mem_fun(*this,&studio::StatePolygon_Context::on_user_click));
383 App::toolbox->refresh();
387 StatePolygon_Context::refresh_tool_options()
389 App::dialog_tool_options->clear();
390 App::dialog_tool_options->set_widget(options_table);
392 App::dialog_tool_options->set_local_name(_("Polygon Tool"));
393 App::dialog_tool_options->set_name("polygon");
395 App::dialog_tool_options->add_button(
396 Gtk::StockID("gtk-execute"),
398 )->signal_clicked().connect(
401 &StatePolygon_Context::run
405 App::dialog_tool_options->add_button(
406 Gtk::StockID("gtk-clear"),
407 _("Clear current Polygon")
408 )->signal_clicked().connect(
411 &StatePolygon_Context::reset
417 StatePolygon_Context::event_refresh_tool_options(const Smach::event& /*x*/)
419 refresh_tool_options();
420 return Smach::RESULT_ACCEPT;
423 StatePolygon_Context::~StatePolygon_Context()
428 // Restore layer clicking
429 get_work_area()->set_allow_layer_clicks(prev_workarea_layer_status_);
431 App::dialog_tool_options->clear();
433 get_canvas_view()->work_area->reset_cursor();
435 // Enable the time bar
436 get_canvas_view()->set_sensitive_timebar(true);
438 // Bring back the tables if they were out before
439 if(prev_table_status)get_canvas_view()->show_tables();
441 // Refresh the work area
442 get_work_area()->queue_draw();
444 App::toolbox->refresh();
448 StatePolygon_Context::event_stop_handler(const Smach::event& /*x*/)
450 synfig::info("STATE RotoPolygon: Received Stop Event");
451 //throw Smach::egress_exception();
453 return Smach::RESULT_ACCEPT;
458 StatePolygon_Context::event_refresh_handler(const Smach::event& /*x*/)
460 synfig::info("STATE RotoPolygon: Received Refresh Event");
462 return Smach::RESULT_ACCEPT;
466 StatePolygon_Context::run()
468 if(polygon_point_list.empty())
471 if(polygon_point_list.size()<3)
473 get_canvas_view()->get_ui_interface()->error("You need at least 3 points to create a polygon");
477 synfigapp::Action::PassiveGrouper group(get_canvas_interface()->get_instance().get(),_("New Polygon"));
481 Canvas::Handle canvas;
484 // we are temporarily using the layer to hold something
485 layer=get_canvas_view()->get_selection_manager()->get_selected_layer();
488 depth=layer->get_depth();
489 canvas=layer->get_canvas();
492 synfigapp::SelectionManager::LayerList layer_selection;
493 if (!getenv("SYNFIG_TOOLS_CLEAR_SELECTION"))
494 layer_selection = get_canvas_view()->get_selection_manager()->get_selected_layers();
496 const synfig::TransformStack& transform(get_canvas_view()->get_curr_transform_stack());
498 std::vector<BLinePoint> new_list;
499 std::list<synfig::Point>::iterator iter;
501 for(i=0,iter=polygon_point_list.begin();iter!=polygon_point_list.end();++iter,++i)
503 *iter = transform.unperform(*iter);
504 new_list.push_back(*(new BLinePoint));
505 new_list[i].set_width(1);
506 new_list[i].set_vertex(*iter);
507 new_list[i].set_tangent(Point(0,0));
510 ValueNode_BLine::Handle value_node_bline(ValueNode_BLine::create(new_list));
511 assert(value_node_bline);
513 ValueNode_Const::Handle value_node_origin(ValueNode_Const::create(Vector()));
514 assert(value_node_origin);
516 // Set the looping flag
517 value_node_bline->set_loop(true);
520 canvas=get_canvas_view()->get_canvas();
522 value_node_bline->set_member_canvas(canvas);
524 // count how many layers we're going to be creating
525 int layers_to_create = this->layers_to_create();
527 ///////////////////////////////////////////////////////////////////////////
529 ///////////////////////////////////////////////////////////////////////////
531 if (get_layer_polygon_flag())
533 layer=get_canvas_interface()->add_layer_to("polygon",canvas,depth);
536 get_canvas_view()->get_ui_interface()->error(_("Unable to create layer"));
540 layer_selection.push_back(layer);
542 layer->set_param("invert",get_invert());
543 get_canvas_interface()->signal_layer_param_changed()(layer,"invert");
547 layer->set_param("feather",get_feather());
548 get_canvas_interface()->signal_layer_param_changed()(layer,"feather");
551 layer->set_description(get_id());
552 get_canvas_interface()->signal_layer_new_description()(layer,layer->get_description());
554 layer->disconnect_dynamic_param("vector_list");
555 if(!layer->set_param("vector_list",polygon_point_list))
558 get_canvas_view()->get_ui_interface()->error("Unable to set layer parameter");
563 synfigapp::Action::Handle action(synfigapp::Action::create("ValueDescConvert"));
564 synfigapp::ValueDesc value_desc(layer,"vector_list");
565 action->set_param("canvas",get_canvas());
566 action->set_param("canvas_interface",get_canvas_interface());
567 action->set_param("value_desc",value_desc);
568 action->set_param("type","dynamic_list");
569 action->set_param("time",get_canvas_interface()->get_time());
570 if(!get_canvas_interface()->get_instance()->perform_action(action))
573 get_canvas_view()->get_ui_interface()->error("Unable to execute action \"ValueDescConvert\"");
578 // only link the polygon's origin parameter if the option is selected and we're creating more than one layer
579 if (get_layer_link_origins_flag() && layers_to_create > 1)
581 synfigapp::Action::Handle action(synfigapp::Action::create("LayerParamConnect"));
584 action->set_param("canvas",get_canvas());
585 action->set_param("canvas_interface",get_canvas_interface());
586 action->set_param("layer",layer);
587 if(!action->set_param("param",String("origin")))
588 synfig::error("LayerParamConnect didn't like \"param\"");
589 if(!action->set_param("value_node",ValueNode::Handle(value_node_origin)))
590 synfig::error("LayerParamConnect didn't like \"value_node\"");
592 if(!get_canvas_interface()->get_instance()->perform_action(action))
594 get_canvas_view()->get_ui_interface()->error(_("Unable to create Polygon layer"));
596 throw String(_("Unable to create Polygon layer"));
602 ///////////////////////////////////////////////////////////////////////////
603 // C U R V E G R A D I E N T
604 ///////////////////////////////////////////////////////////////////////////
606 if(get_layer_curve_gradient_flag())
608 synfigapp::PushMode push_mode(get_canvas_interface(),synfigapp::MODE_NORMAL);
610 Layer::Handle layer(get_canvas_interface()->add_layer_to("curve_gradient",canvas,depth));
613 get_canvas_view()->get_ui_interface()->error(_("Unable to create layer"));
617 layer_selection.push_back(layer);
618 layer->set_description(get_id()+_(" Gradient"));
619 get_canvas_interface()->signal_layer_new_description()(layer,layer->get_description());
622 synfigapp::Action::Handle action(synfigapp::Action::create("LayerParamConnect"));
625 action->set_param("canvas",get_canvas());
626 action->set_param("canvas_interface",get_canvas_interface());
627 action->set_param("layer",layer);
628 if(!action->set_param("param",String("bline")))
629 synfig::error("LayerParamConnect didn't like \"param\"");
630 if(!action->set_param("value_node",ValueNode::Handle(value_node_bline)))
631 synfig::error("LayerParamConnect didn't like \"value_node\"");
633 if(!get_canvas_interface()->get_instance()->perform_action(action))
635 //get_canvas_view()->get_ui_interface()->error(_("Unable to create BLine layer"));
637 throw String(_("Unable to create Gradient layer"));
642 // only link the curve gradient's origin parameter if the option is selected and we're creating more than one layer
643 if (get_layer_link_origins_flag() && layers_to_create > 1)
645 synfigapp::Action::Handle action(synfigapp::Action::create("LayerParamConnect"));
648 action->set_param("canvas",get_canvas());
649 action->set_param("canvas_interface",get_canvas_interface());
650 action->set_param("layer",layer);
651 if(!action->set_param("param",String("origin")))
652 synfig::error("LayerParamConnect didn't like \"param\"");
653 if(!action->set_param("value_node",ValueNode::Handle(value_node_origin)))
654 synfig::error("LayerParamConnect didn't like \"value_node\"");
656 if(!get_canvas_interface()->get_instance()->perform_action(action))
658 //get_canvas_view()->get_ui_interface()->error(_("Unable to create BLine layer"));
660 throw String(_("Unable to create Gradient layer"));
666 ///////////////////////////////////////////////////////////////////////////
668 ///////////////////////////////////////////////////////////////////////////
670 if(get_layer_plant_flag())
672 synfigapp::PushMode push_mode(get_canvas_interface(),synfigapp::MODE_NORMAL);
674 Layer::Handle layer(get_canvas_interface()->add_layer_to("plant",canvas,depth));
677 get_canvas_view()->get_ui_interface()->error(_("Unable to create layer"));
681 layer_selection.push_back(layer);
682 layer->set_description(get_id()+_(" Plant"));
683 get_canvas_interface()->signal_layer_new_description()(layer,layer->get_description());
686 synfigapp::Action::Handle action(synfigapp::Action::create("LayerParamConnect"));
689 action->set_param("canvas",get_canvas());
690 action->set_param("canvas_interface",get_canvas_interface());
691 action->set_param("layer",layer);
692 if(!action->set_param("param",String("bline")))
693 synfig::error("LayerParamConnect didn't like \"param\"");
694 if(!action->set_param("value_node",ValueNode::Handle(value_node_bline)))
695 synfig::error("LayerParamConnect didn't like \"value_node\"");
697 if(!get_canvas_interface()->get_instance()->perform_action(action))
699 //get_canvas_view()->get_ui_interface()->error(_("Unable to create BLine layer"));
701 throw String(_("Unable to create Plant layer"));
706 // only link the plant's origin parameter if the option is selected and we're creating more than one layer
707 if (get_layer_link_origins_flag() && layers_to_create > 1)
709 synfigapp::Action::Handle action(synfigapp::Action::create("LayerParamConnect"));
712 action->set_param("canvas",get_canvas());
713 action->set_param("canvas_interface",get_canvas_interface());
714 action->set_param("layer",layer);
715 if(!action->set_param("param",String("origin")))
716 synfig::error("LayerParamConnect didn't like \"param\"");
717 if(!action->set_param("value_node",ValueNode::Handle(value_node_origin)))
718 synfig::error("LayerParamConnect didn't like \"value_node\"");
720 if(!get_canvas_interface()->get_instance()->perform_action(action))
722 //get_canvas_view()->get_ui_interface()->error(_("Unable to create BLine layer"));
724 throw String(_("Unable to create Plant layer"));
730 ///////////////////////////////////////////////////////////////////////////
732 ///////////////////////////////////////////////////////////////////////////
734 if(get_layer_region_flag())
736 synfigapp::PushMode push_mode(get_canvas_interface(),synfigapp::MODE_NORMAL);
738 Layer::Handle layer(get_canvas_interface()->add_layer_to("region",canvas,depth));
741 get_canvas_view()->get_ui_interface()->error(_("Unable to create layer"));
745 layer_selection.push_back(layer);
746 layer->set_description(get_id()+_(" Region"));
747 get_canvas_interface()->signal_layer_new_description()(layer,layer->get_description());
749 layer->set_param("feather",get_feather());
750 get_canvas_interface()->signal_layer_param_changed()(layer,"feather");
752 layer->set_param("invert",get_invert());
753 get_canvas_interface()->signal_layer_param_changed()(layer,"invert");
755 // I don't know if it's safe to reuse the same LayerParamConnect action, so I'm
756 // using 2 separate ones.
758 synfigapp::Action::Handle action(synfigapp::Action::create("LayerParamConnect"));
761 action->set_param("canvas",get_canvas());
762 action->set_param("canvas_interface",get_canvas_interface());
763 action->set_param("layer",layer);
764 if(!action->set_param("param",String("bline")))
765 synfig::error("LayerParamConnect didn't like \"param\"");
766 if(!action->set_param("value_node",ValueNode::Handle(value_node_bline)))
767 synfig::error("LayerParamConnect didn't like \"value_node\"");
769 if(!get_canvas_interface()->get_instance()->perform_action(action))
771 //get_canvas_view()->get_ui_interface()->error(_("Unable to create Region layer"));
773 throw String(_("Unable to create Region layer"));
778 // only link the region's origin parameter if the option is selected and we're creating more than one layer
779 if (get_layer_link_origins_flag() && layers_to_create > 1)
781 synfigapp::Action::Handle action(synfigapp::Action::create("LayerParamConnect"));
784 action->set_param("canvas",get_canvas());
785 action->set_param("canvas_interface",get_canvas_interface());
786 action->set_param("layer",layer);
787 if(!action->set_param("param",String("origin")))
788 synfig::error("LayerParamConnect didn't like \"param\"");
789 if(!action->set_param("value_node",ValueNode::Handle(value_node_origin)))
790 synfig::error("LayerParamConnect didn't like \"value_node\"");
792 if(!get_canvas_interface()->get_instance()->perform_action(action))
794 //get_canvas_view()->get_ui_interface()->error(_("Unable to create Region layer"));
796 throw String(_("Unable to create Region layer"));
802 ///////////////////////////////////////////////////////////////////////////
804 ///////////////////////////////////////////////////////////////////////////
806 if (get_layer_outline_flag())
808 Layer::Handle layer(get_canvas_interface()->add_layer_to("outline",canvas,depth));
811 get_canvas_view()->get_ui_interface()->error(_("Unable to create layer"));
815 layer_selection.push_back(layer);
816 layer->set_description(get_id()+_(" Outline"));
817 get_canvas_interface()->signal_layer_new_description()(layer,layer->get_description());
819 layer->set_param("feather",get_feather());
820 get_canvas_interface()->signal_layer_param_changed()(layer,"feather");
822 layer->set_param("invert",get_invert());
823 get_canvas_interface()->signal_layer_param_changed()(layer,"invert");
826 synfigapp::Action::Handle action(synfigapp::Action::create("LayerParamConnect"));
829 action->set_param("canvas",get_canvas());
830 action->set_param("canvas_interface",get_canvas_interface());
831 action->set_param("layer",layer);
832 if(!action->set_param("param",String("bline")))
833 synfig::error("LayerParamConnect didn't like \"param\"");
834 if(!action->set_param("value_node",ValueNode::Handle(value_node_bline)))
835 synfig::error("LayerParamConnect didn't like \"value_node\"");
837 if(!get_canvas_interface()->get_instance()->perform_action(action))
839 //get_canvas_view()->get_ui_interface()->error(_("Unable to create BLine layer"));
841 throw String(_("Unable to create Outline layer"));
846 // only link the outline's origin parameter if the option is selected and we're creating more than one layer
847 if (get_layer_link_origins_flag() && layers_to_create > 1)
849 synfigapp::Action::Handle action(synfigapp::Action::create("LayerParamConnect"));
852 action->set_param("canvas",get_canvas());
853 action->set_param("canvas_interface",get_canvas_interface());
854 action->set_param("layer",layer);
855 if(!action->set_param("param",String("origin")))
856 synfig::error("LayerParamConnect didn't like \"param\"");
857 if(!action->set_param("value_node",ValueNode::Handle(value_node_origin)))
858 synfig::error("LayerParamConnect didn't like \"value_node\"");
860 if(!get_canvas_interface()->get_instance()->perform_action(action))
862 //get_canvas_view()->get_ui_interface()->error(_("Unable to create BLine layer"));
864 throw String(_("Unable to create Outline layer"));
870 egress_on_selection_change=false;
871 get_canvas_interface()->get_selection_manager()->clear_selected_layers();
872 get_canvas_interface()->get_selection_manager()->set_selected_layers(layer_selection);
873 egress_on_selection_change=true;
875 //post clean up stuff...
881 StatePolygon_Context::event_mouse_click_handler(const Smach::event& x)
883 synfig::info("STATE ROTOPOLYGON: Received mouse button down Event");
884 const EventMouse& event(*reinterpret_cast<const EventMouse*>(&x));
888 polygon_point_list.push_back(get_work_area()->snap_point_to_grid(event.pos));
890 return Smach::RESULT_ACCEPT;
893 return Smach::RESULT_OK;
899 StatePolygon_Context::refresh_ducks()
901 get_work_area()->clear_ducks();
903 if(polygon_point_list.empty()) return;
905 std::list<synfig::Point>::iterator iter=polygon_point_list.begin();
907 etl::handle<WorkArea::Duck> duck;
908 duck=new WorkArea::Duck(*iter);
909 duck->set_editable(true);
910 duck->signal_edited().connect(
911 sigc::bind(sigc::mem_fun(*this,&studio::StatePolygon_Context::on_polygon_duck_change),iter)
913 duck->signal_user_click(0).connect(sigc::mem_fun(*this,&StatePolygon_Context::run));
915 get_work_area()->add_duck(duck);
917 for(++iter;iter!=polygon_point_list.end();++iter)
919 etl::handle<WorkArea::Bezier> bezier(new WorkArea::Bezier());
920 bezier->p1=bezier->c1=duck;
922 duck=new WorkArea::Duck(*iter);
923 duck->set_editable(true);
924 duck->set_name(strprintf("%x",&*iter));
925 duck->signal_edited().connect(
926 sigc::bind(sigc::mem_fun(*this,&studio::StatePolygon_Context::on_polygon_duck_change),iter)
929 get_work_area()->add_duck(duck);
931 bezier->p2=bezier->c2=duck;
932 get_work_area()->add_bezier(bezier);
934 get_work_area()->queue_draw();
939 StatePolygon_Context::on_polygon_duck_change(const synfig::Point &point, std::list<synfig::Point>::iterator iter)