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());
555 if(get_layer_outline_flag())
557 layer->set_param("color",synfigapp::Main::get_background_color());
558 get_canvas_interface()->signal_layer_param_changed()(layer,"color");
561 layer->disconnect_dynamic_param("vector_list");
562 if(!layer->set_param("vector_list",polygon_point_list))
565 get_canvas_view()->get_ui_interface()->error("Unable to set layer parameter");
570 synfigapp::Action::Handle action(synfigapp::Action::create("value_desc_convert"));
571 synfigapp::ValueDesc value_desc(layer,"vector_list");
572 action->set_param("canvas",get_canvas());
573 action->set_param("canvas_interface",get_canvas_interface());
574 action->set_param("value_desc",value_desc);
575 action->set_param("type","dynamic_list");
576 action->set_param("time",get_canvas_interface()->get_time());
577 if(!get_canvas_interface()->get_instance()->perform_action(action))
580 get_canvas_view()->get_ui_interface()->error("Unable to execute action \"value_desc_convert\"");
585 // only link the polygon's origin parameter if the option is selected and we're creating more than one layer
586 if (get_layer_link_origins_flag() && layers_to_create > 1)
588 synfigapp::Action::Handle action(synfigapp::Action::create("layer_param_connect"));
591 action->set_param("canvas",get_canvas());
592 action->set_param("canvas_interface",get_canvas_interface());
593 action->set_param("layer",layer);
594 if(!action->set_param("param",String("origin")))
595 synfig::error("LayerParamConnect didn't like \"param\"");
596 if(!action->set_param("value_node",ValueNode::Handle(value_node_origin)))
597 synfig::error("LayerParamConnect didn't like \"value_node\"");
599 if(!get_canvas_interface()->get_instance()->perform_action(action))
601 get_canvas_view()->get_ui_interface()->error(_("Unable to create Polygon layer"));
603 throw String(_("Unable to create Polygon layer"));
609 ///////////////////////////////////////////////////////////////////////////
610 // C U R V E G R A D I E N T
611 ///////////////////////////////////////////////////////////////////////////
613 if(get_layer_curve_gradient_flag())
615 synfigapp::PushMode push_mode(get_canvas_interface(),synfigapp::MODE_NORMAL);
617 Layer::Handle layer(get_canvas_interface()->add_layer_to("curve_gradient",canvas,depth));
620 get_canvas_view()->get_ui_interface()->error(_("Unable to create layer"));
624 layer_selection.push_back(layer);
625 layer->set_description(get_id()+_(" Gradient"));
626 get_canvas_interface()->signal_layer_new_description()(layer,layer->get_description());
629 synfigapp::Action::Handle action(synfigapp::Action::create("layer_param_connect"));
632 action->set_param("canvas",get_canvas());
633 action->set_param("canvas_interface",get_canvas_interface());
634 action->set_param("layer",layer);
635 if(!action->set_param("param",String("bline")))
636 synfig::error("LayerParamConnect didn't like \"param\"");
637 if(!action->set_param("value_node",ValueNode::Handle(value_node_bline)))
638 synfig::error("LayerParamConnect didn't like \"value_node\"");
640 if(!get_canvas_interface()->get_instance()->perform_action(action))
642 //get_canvas_view()->get_ui_interface()->error(_("Unable to create BLine layer"));
644 throw String(_("Unable to create Gradient layer"));
649 // only link the curve gradient's origin parameter if the option is selected and we're creating more than one layer
650 if (get_layer_link_origins_flag() && layers_to_create > 1)
652 synfigapp::Action::Handle action(synfigapp::Action::create("layer_param_connect"));
655 action->set_param("canvas",get_canvas());
656 action->set_param("canvas_interface",get_canvas_interface());
657 action->set_param("layer",layer);
658 if(!action->set_param("param",String("origin")))
659 synfig::error("LayerParamConnect didn't like \"param\"");
660 if(!action->set_param("value_node",ValueNode::Handle(value_node_origin)))
661 synfig::error("LayerParamConnect didn't like \"value_node\"");
663 if(!get_canvas_interface()->get_instance()->perform_action(action))
665 //get_canvas_view()->get_ui_interface()->error(_("Unable to create BLine layer"));
667 throw String(_("Unable to create Gradient layer"));
673 ///////////////////////////////////////////////////////////////////////////
675 ///////////////////////////////////////////////////////////////////////////
677 if(get_layer_plant_flag())
679 synfigapp::PushMode push_mode(get_canvas_interface(),synfigapp::MODE_NORMAL);
681 Layer::Handle layer(get_canvas_interface()->add_layer_to("plant",canvas,depth));
684 get_canvas_view()->get_ui_interface()->error(_("Unable to create layer"));
688 layer_selection.push_back(layer);
689 layer->set_description(get_id()+_(" Plant"));
690 get_canvas_interface()->signal_layer_new_description()(layer,layer->get_description());
693 synfigapp::Action::Handle action(synfigapp::Action::create("layer_param_connect"));
696 action->set_param("canvas",get_canvas());
697 action->set_param("canvas_interface",get_canvas_interface());
698 action->set_param("layer",layer);
699 if(!action->set_param("param",String("bline")))
700 synfig::error("LayerParamConnect didn't like \"param\"");
701 if(!action->set_param("value_node",ValueNode::Handle(value_node_bline)))
702 synfig::error("LayerParamConnect didn't like \"value_node\"");
704 if(!get_canvas_interface()->get_instance()->perform_action(action))
706 //get_canvas_view()->get_ui_interface()->error(_("Unable to create BLine layer"));
708 throw String(_("Unable to create Plant layer"));
713 // only link the plant's origin parameter if the option is selected and we're creating more than one layer
714 if (get_layer_link_origins_flag() && layers_to_create > 1)
716 synfigapp::Action::Handle action(synfigapp::Action::create("layer_param_connect"));
719 action->set_param("canvas",get_canvas());
720 action->set_param("canvas_interface",get_canvas_interface());
721 action->set_param("layer",layer);
722 if(!action->set_param("param",String("origin")))
723 synfig::error("LayerParamConnect didn't like \"param\"");
724 if(!action->set_param("value_node",ValueNode::Handle(value_node_origin)))
725 synfig::error("LayerParamConnect didn't like \"value_node\"");
727 if(!get_canvas_interface()->get_instance()->perform_action(action))
729 //get_canvas_view()->get_ui_interface()->error(_("Unable to create BLine layer"));
731 throw String(_("Unable to create Plant layer"));
737 ///////////////////////////////////////////////////////////////////////////
739 ///////////////////////////////////////////////////////////////////////////
741 if(get_layer_region_flag())
743 synfigapp::PushMode push_mode(get_canvas_interface(),synfigapp::MODE_NORMAL);
745 Layer::Handle layer(get_canvas_interface()->add_layer_to("region",canvas,depth));
748 get_canvas_view()->get_ui_interface()->error(_("Unable to create layer"));
752 layer_selection.push_back(layer);
753 layer->set_description(get_id()+_(" Region"));
754 get_canvas_interface()->signal_layer_new_description()(layer,layer->get_description());
756 layer->set_param("feather",get_feather());
757 get_canvas_interface()->signal_layer_param_changed()(layer,"feather");
759 layer->set_param("invert",get_invert());
760 get_canvas_interface()->signal_layer_param_changed()(layer,"invert");
762 if(get_layer_outline_flag())
763 layer->set_param("color",synfigapp::Main::get_background_color());
765 // I don't know if it's safe to reuse the same layer_param_connect action, so I'm
766 // using 2 separate ones.
768 synfigapp::Action::Handle action(synfigapp::Action::create("layer_param_connect"));
771 action->set_param("canvas",get_canvas());
772 action->set_param("canvas_interface",get_canvas_interface());
773 action->set_param("layer",layer);
774 if(!action->set_param("param",String("bline")))
775 synfig::error("LayerParamConnect didn't like \"param\"");
776 if(!action->set_param("value_node",ValueNode::Handle(value_node_bline)))
777 synfig::error("LayerParamConnect didn't like \"value_node\"");
779 if(!get_canvas_interface()->get_instance()->perform_action(action))
781 //get_canvas_view()->get_ui_interface()->error(_("Unable to create Region layer"));
783 throw String(_("Unable to create Region layer"));
788 // only link the region's origin parameter if the option is selected and we're creating more than one layer
789 if (get_layer_link_origins_flag() && layers_to_create > 1)
791 synfigapp::Action::Handle action(synfigapp::Action::create("layer_param_connect"));
794 action->set_param("canvas",get_canvas());
795 action->set_param("canvas_interface",get_canvas_interface());
796 action->set_param("layer",layer);
797 if(!action->set_param("param",String("origin")))
798 synfig::error("LayerParamConnect didn't like \"param\"");
799 if(!action->set_param("value_node",ValueNode::Handle(value_node_origin)))
800 synfig::error("LayerParamConnect didn't like \"value_node\"");
802 if(!get_canvas_interface()->get_instance()->perform_action(action))
804 //get_canvas_view()->get_ui_interface()->error(_("Unable to create Region layer"));
806 throw String(_("Unable to create Region layer"));
812 ///////////////////////////////////////////////////////////////////////////
814 ///////////////////////////////////////////////////////////////////////////
816 if (get_layer_outline_flag())
818 Layer::Handle layer(get_canvas_interface()->add_layer_to("outline",canvas,depth));
821 get_canvas_view()->get_ui_interface()->error(_("Unable to create layer"));
825 layer_selection.push_back(layer);
826 layer->set_description(get_id()+_(" Outline"));
827 get_canvas_interface()->signal_layer_new_description()(layer,layer->get_description());
829 layer->set_param("feather",get_feather());
830 get_canvas_interface()->signal_layer_param_changed()(layer,"feather");
832 layer->set_param("invert",get_invert());
833 get_canvas_interface()->signal_layer_param_changed()(layer,"invert");
836 synfigapp::Action::Handle action(synfigapp::Action::create("layer_param_connect"));
839 action->set_param("canvas",get_canvas());
840 action->set_param("canvas_interface",get_canvas_interface());
841 action->set_param("layer",layer);
842 if(!action->set_param("param",String("bline")))
843 synfig::error("LayerParamConnect didn't like \"param\"");
844 if(!action->set_param("value_node",ValueNode::Handle(value_node_bline)))
845 synfig::error("LayerParamConnect didn't like \"value_node\"");
847 if(!get_canvas_interface()->get_instance()->perform_action(action))
849 //get_canvas_view()->get_ui_interface()->error(_("Unable to create BLine layer"));
851 throw String(_("Unable to create Outline layer"));
856 // only link the outline's origin parameter if the option is selected and we're creating more than one layer
857 if (get_layer_link_origins_flag() && layers_to_create > 1)
859 synfigapp::Action::Handle action(synfigapp::Action::create("layer_param_connect"));
862 action->set_param("canvas",get_canvas());
863 action->set_param("canvas_interface",get_canvas_interface());
864 action->set_param("layer",layer);
865 if(!action->set_param("param",String("origin")))
866 synfig::error("LayerParamConnect didn't like \"param\"");
867 if(!action->set_param("value_node",ValueNode::Handle(value_node_origin)))
868 synfig::error("LayerParamConnect didn't like \"value_node\"");
870 if(!get_canvas_interface()->get_instance()->perform_action(action))
872 //get_canvas_view()->get_ui_interface()->error(_("Unable to create BLine layer"));
874 throw String(_("Unable to create Outline layer"));
880 egress_on_selection_change=false;
881 get_canvas_interface()->get_selection_manager()->clear_selected_layers();
882 get_canvas_interface()->get_selection_manager()->set_selected_layers(layer_selection);
883 egress_on_selection_change=true;
885 //post clean up stuff...
891 StatePolygon_Context::event_mouse_click_handler(const Smach::event& x)
893 synfig::info("STATE ROTOPOLYGON: Received mouse button down Event");
894 const EventMouse& event(*reinterpret_cast<const EventMouse*>(&x));
898 polygon_point_list.push_back(get_work_area()->snap_point_to_grid(event.pos));
900 return Smach::RESULT_ACCEPT;
903 return Smach::RESULT_OK;
909 StatePolygon_Context::refresh_ducks()
911 get_work_area()->clear_ducks();
913 if(polygon_point_list.empty()) return;
915 std::list<synfig::Point>::iterator iter=polygon_point_list.begin();
917 etl::handle<WorkArea::Duck> duck;
918 duck=new WorkArea::Duck(*iter);
919 duck->set_editable(true);
920 duck->signal_edited().connect(
921 sigc::bind(sigc::mem_fun(*this,&studio::StatePolygon_Context::on_polygon_duck_change),iter)
923 duck->signal_user_click(0).connect(sigc::mem_fun(*this,&StatePolygon_Context::run));
925 get_work_area()->add_duck(duck);
927 for(++iter;iter!=polygon_point_list.end();++iter)
929 etl::handle<WorkArea::Bezier> bezier(new WorkArea::Bezier());
930 bezier->p1=bezier->c1=duck;
932 duck=new WorkArea::Duck(*iter);
933 duck->set_editable(true);
934 duck->set_name(strprintf("%x",&*iter));
935 duck->signal_edited().connect(
936 sigc::bind(sigc::mem_fun(*this,&studio::StatePolygon_Context::on_polygon_duck_change),iter)
939 get_work_area()->add_duck(duck);
941 bezier->p2=bezier->c2=duck;
942 get_work_area()->add_bezier(bezier);
944 get_work_area()->queue_draw();
949 StatePolygon_Context::on_polygon_duck_change(const synfig::Point &point, std::list<synfig::Point>::iterator iter)