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 "state_normal.h"
42 #include "canvasview.h"
46 #include <synfigapp/action.h>
47 #include "event_mouse.h"
48 #include "event_layerclick.h"
50 #include "dialog_tooloptions.h"
51 #include <synfigapp/main.h>
57 /* === U S I N G =========================================================== */
61 using namespace synfig;
62 using namespace studio;
64 /* === M A C R O S ========================================================= */
66 /* === G L O B A L S ======================================================= */
68 StatePolygon studio::state_polygon;
70 /* === C L A S S E S & S T R U C T S ======================================= */
72 class studio::StatePolygon_Context : public sigc::trackable
74 etl::handle<CanvasView> canvas_view_;
75 CanvasView::IsWorking is_working;
77 bool prev_table_status;
78 bool prev_workarea_layer_status_;
82 Duckmatic::Push duckmatic_push;
84 std::list<synfig::Point> polygon_point_list;
85 synfigapp::Settings& settings;
88 bool on_polygon_duck_change(const synfig::Point &point, std::list<synfig::Point>::iterator iter);
91 void popup_handle_menu(synfigapp::ValueDesc value_desc);
96 Gtk::Table options_table;
98 Gtk::CheckButton checkbutton_invert;
99 Gtk::CheckButton checkbutton_layer_polygon;
100 Gtk::CheckButton checkbutton_layer_region;
101 Gtk::CheckButton checkbutton_layer_outline;
102 Gtk::CheckButton checkbutton_layer_curve_gradient;
103 Gtk::CheckButton checkbutton_layer_plant;
104 Gtk::CheckButton checkbutton_layer_link_origins;
105 Gtk::Button button_make;
106 Gtk::Adjustment adj_feather;
107 Gtk::SpinButton spin_feather;
111 // this counts the layers we create - they all have origins we can link
112 int layers_to_create()const
115 get_layer_polygon_flag() +
116 get_layer_region_flag() +
117 get_layer_outline_flag() +
118 get_layer_curve_gradient_flag() +
119 get_layer_plant_flag();
122 synfig::String get_id()const { return entry_id.get_text(); }
123 void set_id(const synfig::String& x) { return entry_id.set_text(x); }
125 bool get_invert()const { return checkbutton_invert.get_active(); }
126 void set_invert(bool i) { checkbutton_invert.set_active(i); }
128 bool get_layer_polygon_flag()const { return checkbutton_layer_polygon.get_active(); }
129 void set_layer_polygon_flag(bool x) { return checkbutton_layer_polygon.set_active(x); }
131 bool get_layer_region_flag()const { return checkbutton_layer_region.get_active(); }
132 void set_layer_region_flag(bool x) { return checkbutton_layer_region.set_active(x); }
134 bool get_layer_outline_flag()const { return checkbutton_layer_outline.get_active(); }
135 void set_layer_outline_flag(bool x) { return checkbutton_layer_outline.set_active(x); }
137 bool get_layer_curve_gradient_flag()const { return checkbutton_layer_curve_gradient.get_active(); }
138 void set_layer_curve_gradient_flag(bool x) { return checkbutton_layer_curve_gradient.set_active(x); }
140 bool get_layer_plant_flag()const { return checkbutton_layer_plant.get_active(); }
141 void set_layer_plant_flag(bool x) { return checkbutton_layer_plant.set_active(x); }
143 bool get_layer_link_origins_flag()const { return checkbutton_layer_link_origins.get_active(); }
144 void set_layer_link_origins_flag(bool x) { return checkbutton_layer_link_origins.set_active(x); }
146 Real get_feather() const { return adj_feather.get_value(); }
147 void set_feather(Real x) { return adj_feather.set_value(x); }
149 Smach::event_result event_stop_handler(const Smach::event& x);
151 Smach::event_result event_refresh_handler(const Smach::event& x);
153 Smach::event_result event_mouse_click_handler(const Smach::event& x);
154 Smach::event_result event_refresh_tool_options(const Smach::event& x);
155 void refresh_tool_options();
157 StatePolygon_Context(CanvasView* canvas_view);
159 ~StatePolygon_Context();
161 const etl::handle<CanvasView>& get_canvas_view()const{return canvas_view_;}
162 etl::handle<synfigapp::CanvasInterface> get_canvas_interface()const{return canvas_view_->canvas_interface();}
163 synfig::Canvas::Handle get_canvas()const{return canvas_view_->get_canvas();}
164 WorkArea * get_work_area()const{return canvas_view_->get_work_area();}
166 //void on_user_click(synfig::Point point);
167 void load_settings();
168 void save_settings();
171 bool egress_on_selection_change;
172 Smach::event_result event_layer_selection_changed_handler(const Smach::event& /*x*/)
174 if(egress_on_selection_change)
175 throw &state_normal; //throw Smach::egress_exception();
176 return Smach::RESULT_OK;
180 }; // END of class StatePolygon_Context
182 /* === M E T H O D S ======================================================= */
184 StatePolygon::StatePolygon():
185 Smach::state<StatePolygon_Context>("polygon")
187 insert(event_def(EVENT_LAYER_SELECTION_CHANGED,&StatePolygon_Context::event_layer_selection_changed_handler));
188 insert(event_def(EVENT_STOP,&StatePolygon_Context::event_stop_handler));
189 insert(event_def(EVENT_REFRESH,&StatePolygon_Context::event_refresh_handler));
190 insert(event_def(EVENT_REFRESH_DUCKS,&StatePolygon_Context::event_refresh_handler));
191 insert(event_def(EVENT_WORKAREA_MOUSE_BUTTON_DOWN,&StatePolygon_Context::event_mouse_click_handler));
192 insert(event_def(EVENT_REFRESH_TOOL_OPTIONS,&StatePolygon_Context::event_refresh_tool_options));
195 StatePolygon::~StatePolygon()
200 StatePolygon_Context::load_settings()
204 if(settings.get_value("polygon.id",value))
209 if(settings.get_value("polygon.invert",value) && value != "0")
214 if(settings.get_value("polygon.layer_polygon",value) && value=="0")
215 set_layer_polygon_flag(false);
217 set_layer_polygon_flag(true);
219 if(settings.get_value("polygon.layer_region",value) && value=="1")
220 set_layer_region_flag(true);
222 set_layer_region_flag(false);
224 if(settings.get_value("polygon.layer_outline",value) && value=="1")
225 set_layer_outline_flag(true);
227 set_layer_outline_flag(false);
229 if(settings.get_value("polygon.layer_curve_gradient",value) && value=="1")
230 set_layer_curve_gradient_flag(true);
232 set_layer_curve_gradient_flag(false);
234 if(settings.get_value("polygon.layer_plant",value) && value=="1")
235 set_layer_plant_flag(true);
237 set_layer_plant_flag(false);
239 if(settings.get_value("polygon.layer_link_origins",value) && value=="0")
240 set_layer_link_origins_flag(false);
242 set_layer_link_origins_flag(true);
244 if(settings.get_value("polygon.feather",value))
246 Real n = atof(value.c_str());
252 StatePolygon_Context::save_settings()
254 settings.set_value("polygon.id",get_id().c_str());
255 settings.set_value("polygon.invert",get_invert()?"1":"0");
256 settings.set_value("polygon.layer_polygon",get_layer_polygon_flag()?"1":"0");
257 settings.set_value("polygon.layer_outline",get_layer_outline_flag()?"1":"0");
258 settings.set_value("polygon.layer_region",get_layer_region_flag()?"1":"0");
259 settings.set_value("polygon.layer_curve_gradient",get_layer_curve_gradient_flag()?"1":"0");
260 settings.set_value("polygon.layer_plant",get_layer_plant_flag()?"1":"0");
261 settings.set_value("polygon.layer_link_origins",get_layer_link_origins_flag()?"1":"0");
262 settings.set_value("polygon.feather",strprintf("%f",get_feather()));
266 StatePolygon_Context::reset()
268 polygon_point_list.clear();
273 StatePolygon_Context::increment_id()
282 // If there is a number
283 // already at the end of the
284 // id, then remove it.
285 if(id[id.size()-1]<='9' && id[id.size()-1]>='0')
287 // figure out how many digits it is
289 (int)id.size()-1 >= digits && id[id.size()-1-digits] <= '9' && id[id.size()-1-digits] >= '0';
294 str_number=String(id,id.size()-digits,id.size());
295 id=String(id,0,id.size()-digits);
297 number=atoi(str_number.c_str());
307 // Add the number back onto the id
309 const String format(strprintf("%%0%dd",digits));
310 id+=strprintf(format.c_str(),number);
317 StatePolygon_Context::StatePolygon_Context(CanvasView* canvas_view):
318 canvas_view_(canvas_view),
319 is_working(*canvas_view),
320 prev_workarea_layer_status_(get_work_area()->get_allow_layer_clicks()),
321 duckmatic_push(get_work_area()),
322 settings(synfigapp::Main::get_selected_input_device()->settings()),
324 checkbutton_invert(_("Invert")),
325 checkbutton_layer_polygon(_("Create Polygon Layer")),
326 checkbutton_layer_region(_("Create Region BLine")),
327 checkbutton_layer_outline(_("Create Outline BLine")),
328 checkbutton_layer_curve_gradient(_("Create Curve Gradient BLine")),
329 checkbutton_layer_plant(_("Create Plant BLine")),
330 checkbutton_layer_link_origins(_("Link Origins")),
331 button_make(_("Make")),
332 adj_feather(0,0,10000,0.01,0.1),
333 spin_feather(adj_feather,0.01,4)
335 egress_on_selection_change=true;
338 // Set up the tool options dialog
339 options_table.attach(*manage(new Gtk::Label(_("Polygon Tool"))), 0, 2, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
340 options_table.attach(entry_id, 0, 2, 1, 2, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
342 options_table.attach(checkbutton_layer_polygon, 0, 2, 2, 3, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
343 options_table.attach(checkbutton_layer_outline, 0, 2, 3, 4, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
344 options_table.attach(checkbutton_layer_region, 0, 2, 4, 5, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
345 options_table.attach(checkbutton_layer_plant, 0, 2, 5, 6, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
346 options_table.attach(checkbutton_layer_curve_gradient, 0, 2, 6, 7, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
347 options_table.attach(checkbutton_layer_link_origins, 0, 2, 7, 8, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
350 options_table.attach(checkbutton_invert, 0, 2, 8, 9, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
353 options_table.attach(*manage(new Gtk::Label(_("Feather"))), 0, 1, 9, 10, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
354 options_table.attach(spin_feather, 1, 2, 9, 10, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
356 //options_table.attach(button_make, 0, 2, 4, 5, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
357 button_make.signal_pressed().connect(sigc::mem_fun(*this,&StatePolygon_Context::run));
358 options_table.show_all();
359 refresh_tool_options();
360 App::dialog_tool_options->present();
363 // Turn off layer clicking
364 get_work_area()->set_allow_layer_clicks(false);
366 // clear out the ducks
367 get_work_area()->clear_ducks();
369 // Refresh the work area
370 get_work_area()->queue_draw();
372 get_work_area()->set_cursor(Gdk::CROSSHAIR);
374 // Hide the tables if they are showing
375 prev_table_status=get_canvas_view()->tables_are_visible();
376 if(prev_table_status)get_canvas_view()->hide_tables();
378 // Disable the time bar
379 get_canvas_view()->set_sensitive_timebar(false);
382 //get_work_area()->signal_user_click().connect(sigc::mem_fun(*this,&studio::StatePolygon_Context::on_user_click));
384 App::toolbox->refresh();
388 StatePolygon_Context::refresh_tool_options()
390 App::dialog_tool_options->clear();
391 App::dialog_tool_options->set_widget(options_table);
393 App::dialog_tool_options->set_local_name(_("Polygon Tool"));
394 App::dialog_tool_options->set_name("polygon");
396 App::dialog_tool_options->add_button(
397 Gtk::StockID("gtk-execute"),
399 )->signal_clicked().connect(
402 &StatePolygon_Context::run
406 App::dialog_tool_options->add_button(
407 Gtk::StockID("gtk-clear"),
408 _("Clear current Polygon")
409 )->signal_clicked().connect(
412 &StatePolygon_Context::reset
418 StatePolygon_Context::event_refresh_tool_options(const Smach::event& /*x*/)
420 refresh_tool_options();
421 return Smach::RESULT_ACCEPT;
424 StatePolygon_Context::~StatePolygon_Context()
429 // Restore layer clicking
430 get_work_area()->set_allow_layer_clicks(prev_workarea_layer_status_);
432 App::dialog_tool_options->clear();
434 get_work_area()->reset_cursor();
436 // Enable the time bar
437 get_canvas_view()->set_sensitive_timebar(true);
439 // Bring back the tables if they were out before
440 if(prev_table_status)get_canvas_view()->show_tables();
442 // Refresh the work area
443 get_work_area()->queue_draw();
445 App::toolbox->refresh();
449 StatePolygon_Context::event_stop_handler(const Smach::event& /*x*/)
451 synfig::info("STATE RotoPolygon: Received Stop Event");
452 //throw Smach::egress_exception();
454 return Smach::RESULT_ACCEPT;
459 StatePolygon_Context::event_refresh_handler(const Smach::event& /*x*/)
461 synfig::info("STATE RotoPolygon: Received Refresh Event");
463 return Smach::RESULT_ACCEPT;
467 StatePolygon_Context::run()
469 if(polygon_point_list.empty())
472 if(polygon_point_list.size()<3)
474 get_canvas_view()->get_ui_interface()->error("You need at least 3 points to create a polygon");
478 synfigapp::Action::PassiveGrouper group(get_canvas_interface()->get_instance().get(),_("New Polygon"));
482 Canvas::Handle canvas;
485 // we are temporarily using the layer to hold something
486 layer=get_canvas_view()->get_selection_manager()->get_selected_layer();
489 depth=layer->get_depth();
490 canvas=layer->get_canvas();
493 synfigapp::SelectionManager::LayerList layer_selection;
494 if (!getenv("SYNFIG_TOOLS_CLEAR_SELECTION"))
495 layer_selection = get_canvas_view()->get_selection_manager()->get_selected_layers();
497 const synfig::TransformStack& transform(get_canvas_view()->get_curr_transform_stack());
499 std::vector<BLinePoint> new_list;
500 std::list<synfig::Point>::iterator iter;
502 for(i=0,iter=polygon_point_list.begin();iter!=polygon_point_list.end();++iter,++i)
504 *iter = transform.unperform(*iter);
505 new_list.push_back(*(new BLinePoint));
506 new_list[i].set_width(1);
507 new_list[i].set_vertex(*iter);
508 new_list[i].set_tangent(Point(0,0));
511 ValueNode_BLine::Handle value_node_bline(ValueNode_BLine::create(new_list));
512 assert(value_node_bline);
514 ValueNode_Const::Handle value_node_origin(ValueNode_Const::create(Vector()));
515 assert(value_node_origin);
517 // Set the looping flag
518 value_node_bline->set_loop(true);
521 canvas=get_canvas_view()->get_canvas();
523 value_node_bline->set_member_canvas(canvas);
525 // count how many layers we're going to be creating
526 int layers_to_create = this->layers_to_create();
528 ///////////////////////////////////////////////////////////////////////////
530 ///////////////////////////////////////////////////////////////////////////
532 if (get_layer_polygon_flag())
534 layer=get_canvas_interface()->add_layer_to("polygon",canvas,depth);
537 get_canvas_view()->get_ui_interface()->error(_("Unable to create layer"));
541 layer_selection.push_back(layer);
543 layer->set_param("invert",get_invert());
544 get_canvas_interface()->signal_layer_param_changed()(layer,"invert");
548 layer->set_param("feather",get_feather());
549 get_canvas_interface()->signal_layer_param_changed()(layer,"feather");
552 layer->set_description(get_id());
553 get_canvas_interface()->signal_layer_new_description()(layer,layer->get_description());
555 layer->disconnect_dynamic_param("vector_list");
556 if(!layer->set_param("vector_list",polygon_point_list))
559 get_canvas_view()->get_ui_interface()->error("Unable to set layer parameter");
564 synfigapp::Action::Handle action(synfigapp::Action::create("ValueDescConvert"));
565 synfigapp::ValueDesc value_desc(layer,"vector_list");
566 action->set_param("canvas",get_canvas());
567 action->set_param("canvas_interface",get_canvas_interface());
568 action->set_param("value_desc",value_desc);
569 action->set_param("type","dynamic_list");
570 action->set_param("time",get_canvas_interface()->get_time());
571 if(!get_canvas_interface()->get_instance()->perform_action(action))
574 get_canvas_view()->get_ui_interface()->error("Unable to execute action \"ValueDescConvert\"");
579 // only link the polygon's origin parameter if the option is selected and we're creating more than one layer
580 if (get_layer_link_origins_flag() && layers_to_create > 1)
582 synfigapp::Action::Handle action(synfigapp::Action::create("LayerParamConnect"));
585 action->set_param("canvas",get_canvas());
586 action->set_param("canvas_interface",get_canvas_interface());
587 action->set_param("layer",layer);
588 if(!action->set_param("param",String("origin")))
589 synfig::error("LayerParamConnect didn't like \"param\"");
590 if(!action->set_param("value_node",ValueNode::Handle(value_node_origin)))
591 synfig::error("LayerParamConnect didn't like \"value_node\"");
593 if(!get_canvas_interface()->get_instance()->perform_action(action))
595 get_canvas_view()->get_ui_interface()->error(_("Unable to create Polygon layer"));
597 throw String(_("Unable to create Polygon layer"));
603 ///////////////////////////////////////////////////////////////////////////
604 // C U R V E G R A D I E N T
605 ///////////////////////////////////////////////////////////////////////////
607 if(get_layer_curve_gradient_flag())
609 synfigapp::PushMode push_mode(get_canvas_interface(),synfigapp::MODE_NORMAL);
611 Layer::Handle layer(get_canvas_interface()->add_layer_to("curve_gradient",canvas,depth));
614 get_canvas_view()->get_ui_interface()->error(_("Unable to create layer"));
618 layer_selection.push_back(layer);
619 layer->set_description(get_id()+_(" Gradient"));
620 get_canvas_interface()->signal_layer_new_description()(layer,layer->get_description());
623 synfigapp::Action::Handle action(synfigapp::Action::create("LayerParamConnect"));
626 action->set_param("canvas",get_canvas());
627 action->set_param("canvas_interface",get_canvas_interface());
628 action->set_param("layer",layer);
629 if(!action->set_param("param",String("bline")))
630 synfig::error("LayerParamConnect didn't like \"param\"");
631 if(!action->set_param("value_node",ValueNode::Handle(value_node_bline)))
632 synfig::error("LayerParamConnect didn't like \"value_node\"");
634 if(!get_canvas_interface()->get_instance()->perform_action(action))
636 //get_canvas_view()->get_ui_interface()->error(_("Unable to create BLine layer"));
638 throw String(_("Unable to create Gradient layer"));
643 // only link the curve gradient's origin parameter if the option is selected and we're creating more than one layer
644 if (get_layer_link_origins_flag() && layers_to_create > 1)
646 synfigapp::Action::Handle action(synfigapp::Action::create("LayerParamConnect"));
649 action->set_param("canvas",get_canvas());
650 action->set_param("canvas_interface",get_canvas_interface());
651 action->set_param("layer",layer);
652 if(!action->set_param("param",String("origin")))
653 synfig::error("LayerParamConnect didn't like \"param\"");
654 if(!action->set_param("value_node",ValueNode::Handle(value_node_origin)))
655 synfig::error("LayerParamConnect didn't like \"value_node\"");
657 if(!get_canvas_interface()->get_instance()->perform_action(action))
659 //get_canvas_view()->get_ui_interface()->error(_("Unable to create BLine layer"));
661 throw String(_("Unable to create Gradient layer"));
667 ///////////////////////////////////////////////////////////////////////////
669 ///////////////////////////////////////////////////////////////////////////
671 if(get_layer_plant_flag())
673 synfigapp::PushMode push_mode(get_canvas_interface(),synfigapp::MODE_NORMAL);
675 Layer::Handle layer(get_canvas_interface()->add_layer_to("plant",canvas,depth));
678 get_canvas_view()->get_ui_interface()->error(_("Unable to create layer"));
682 layer_selection.push_back(layer);
683 layer->set_description(get_id()+_(" Plant"));
684 get_canvas_interface()->signal_layer_new_description()(layer,layer->get_description());
687 synfigapp::Action::Handle action(synfigapp::Action::create("LayerParamConnect"));
690 action->set_param("canvas",get_canvas());
691 action->set_param("canvas_interface",get_canvas_interface());
692 action->set_param("layer",layer);
693 if(!action->set_param("param",String("bline")))
694 synfig::error("LayerParamConnect didn't like \"param\"");
695 if(!action->set_param("value_node",ValueNode::Handle(value_node_bline)))
696 synfig::error("LayerParamConnect didn't like \"value_node\"");
698 if(!get_canvas_interface()->get_instance()->perform_action(action))
700 //get_canvas_view()->get_ui_interface()->error(_("Unable to create BLine layer"));
702 throw String(_("Unable to create Plant layer"));
707 // only link the plant's origin parameter if the option is selected and we're creating more than one layer
708 if (get_layer_link_origins_flag() && layers_to_create > 1)
710 synfigapp::Action::Handle action(synfigapp::Action::create("LayerParamConnect"));
713 action->set_param("canvas",get_canvas());
714 action->set_param("canvas_interface",get_canvas_interface());
715 action->set_param("layer",layer);
716 if(!action->set_param("param",String("origin")))
717 synfig::error("LayerParamConnect didn't like \"param\"");
718 if(!action->set_param("value_node",ValueNode::Handle(value_node_origin)))
719 synfig::error("LayerParamConnect didn't like \"value_node\"");
721 if(!get_canvas_interface()->get_instance()->perform_action(action))
723 //get_canvas_view()->get_ui_interface()->error(_("Unable to create BLine layer"));
725 throw String(_("Unable to create Plant layer"));
731 ///////////////////////////////////////////////////////////////////////////
733 ///////////////////////////////////////////////////////////////////////////
735 if(get_layer_region_flag())
737 synfigapp::PushMode push_mode(get_canvas_interface(),synfigapp::MODE_NORMAL);
739 Layer::Handle layer(get_canvas_interface()->add_layer_to("region",canvas,depth));
742 get_canvas_view()->get_ui_interface()->error(_("Unable to create layer"));
746 layer_selection.push_back(layer);
747 layer->set_description(get_id()+_(" Region"));
748 get_canvas_interface()->signal_layer_new_description()(layer,layer->get_description());
750 layer->set_param("feather",get_feather());
751 get_canvas_interface()->signal_layer_param_changed()(layer,"feather");
753 layer->set_param("invert",get_invert());
754 get_canvas_interface()->signal_layer_param_changed()(layer,"invert");
756 // I don't know if it's safe to reuse the same LayerParamConnect action, so I'm
757 // using 2 separate ones.
759 synfigapp::Action::Handle action(synfigapp::Action::create("LayerParamConnect"));
762 action->set_param("canvas",get_canvas());
763 action->set_param("canvas_interface",get_canvas_interface());
764 action->set_param("layer",layer);
765 if(!action->set_param("param",String("bline")))
766 synfig::error("LayerParamConnect didn't like \"param\"");
767 if(!action->set_param("value_node",ValueNode::Handle(value_node_bline)))
768 synfig::error("LayerParamConnect didn't like \"value_node\"");
770 if(!get_canvas_interface()->get_instance()->perform_action(action))
772 //get_canvas_view()->get_ui_interface()->error(_("Unable to create Region layer"));
774 throw String(_("Unable to create Region layer"));
779 // only link the region's origin parameter if the option is selected and we're creating more than one layer
780 if (get_layer_link_origins_flag() && layers_to_create > 1)
782 synfigapp::Action::Handle action(synfigapp::Action::create("LayerParamConnect"));
785 action->set_param("canvas",get_canvas());
786 action->set_param("canvas_interface",get_canvas_interface());
787 action->set_param("layer",layer);
788 if(!action->set_param("param",String("origin")))
789 synfig::error("LayerParamConnect didn't like \"param\"");
790 if(!action->set_param("value_node",ValueNode::Handle(value_node_origin)))
791 synfig::error("LayerParamConnect didn't like \"value_node\"");
793 if(!get_canvas_interface()->get_instance()->perform_action(action))
795 //get_canvas_view()->get_ui_interface()->error(_("Unable to create Region layer"));
797 throw String(_("Unable to create Region layer"));
803 ///////////////////////////////////////////////////////////////////////////
805 ///////////////////////////////////////////////////////////////////////////
807 if (get_layer_outline_flag())
809 Layer::Handle layer(get_canvas_interface()->add_layer_to("outline",canvas,depth));
812 get_canvas_view()->get_ui_interface()->error(_("Unable to create layer"));
816 layer_selection.push_back(layer);
817 layer->set_description(get_id()+_(" Outline"));
818 get_canvas_interface()->signal_layer_new_description()(layer,layer->get_description());
820 layer->set_param("feather",get_feather());
821 get_canvas_interface()->signal_layer_param_changed()(layer,"feather");
823 layer->set_param("invert",get_invert());
824 get_canvas_interface()->signal_layer_param_changed()(layer,"invert");
827 synfigapp::Action::Handle action(synfigapp::Action::create("LayerParamConnect"));
830 action->set_param("canvas",get_canvas());
831 action->set_param("canvas_interface",get_canvas_interface());
832 action->set_param("layer",layer);
833 if(!action->set_param("param",String("bline")))
834 synfig::error("LayerParamConnect didn't like \"param\"");
835 if(!action->set_param("value_node",ValueNode::Handle(value_node_bline)))
836 synfig::error("LayerParamConnect didn't like \"value_node\"");
838 if(!get_canvas_interface()->get_instance()->perform_action(action))
840 //get_canvas_view()->get_ui_interface()->error(_("Unable to create BLine layer"));
842 throw String(_("Unable to create Outline layer"));
847 // only link the outline's origin parameter if the option is selected and we're creating more than one layer
848 if (get_layer_link_origins_flag() && layers_to_create > 1)
850 synfigapp::Action::Handle action(synfigapp::Action::create("LayerParamConnect"));
853 action->set_param("canvas",get_canvas());
854 action->set_param("canvas_interface",get_canvas_interface());
855 action->set_param("layer",layer);
856 if(!action->set_param("param",String("origin")))
857 synfig::error("LayerParamConnect didn't like \"param\"");
858 if(!action->set_param("value_node",ValueNode::Handle(value_node_origin)))
859 synfig::error("LayerParamConnect didn't like \"value_node\"");
861 if(!get_canvas_interface()->get_instance()->perform_action(action))
863 //get_canvas_view()->get_ui_interface()->error(_("Unable to create BLine layer"));
865 throw String(_("Unable to create Outline layer"));
871 egress_on_selection_change=false;
872 get_canvas_interface()->get_selection_manager()->clear_selected_layers();
873 get_canvas_interface()->get_selection_manager()->set_selected_layers(layer_selection);
874 egress_on_selection_change=true;
876 //post clean up stuff...
882 StatePolygon_Context::event_mouse_click_handler(const Smach::event& x)
884 synfig::info("STATE ROTOPOLYGON: Received mouse button down Event");
885 const EventMouse& event(*reinterpret_cast<const EventMouse*>(&x));
889 polygon_point_list.push_back(get_work_area()->snap_point_to_grid(event.pos));
891 return Smach::RESULT_ACCEPT;
894 return Smach::RESULT_OK;
900 StatePolygon_Context::refresh_ducks()
902 get_work_area()->clear_ducks();
903 get_work_area()->queue_draw();
905 if(polygon_point_list.empty()) return;
907 std::list<synfig::Point>::iterator iter=polygon_point_list.begin();
909 etl::handle<WorkArea::Duck> duck;
910 duck=new WorkArea::Duck(*iter);
911 duck->set_editable(true);
912 duck->signal_edited().connect(
913 sigc::bind(sigc::mem_fun(*this,&studio::StatePolygon_Context::on_polygon_duck_change),iter)
915 duck->signal_user_click(0).connect(sigc::mem_fun(*this,&StatePolygon_Context::run));
917 get_work_area()->add_duck(duck);
919 for(++iter;iter!=polygon_point_list.end();++iter)
921 etl::handle<WorkArea::Bezier> bezier(new WorkArea::Bezier());
922 bezier->p1=bezier->c1=duck;
924 duck=new WorkArea::Duck(*iter);
925 duck->set_editable(true);
926 duck->set_name(strprintf("%x",&*iter));
927 duck->signal_edited().connect(
928 sigc::bind(sigc::mem_fun(*this,&studio::StatePolygon_Context::on_polygon_duck_change),iter)
931 get_work_area()->add_duck(duck);
933 bezier->p2=bezier->c2=duck;
934 get_work_area()->add_bezier(bezier);
936 get_work_area()->queue_draw();
941 StatePolygon_Context::on_polygon_duck_change(const synfig::Point &point, std::list<synfig::Point>::iterator iter)