1 /* === S Y N F I G ========================================================= */
2 /*! \file state_rectangle.cpp
3 ** \brief Template File
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 ** Copyright (c) 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_rectangle.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 "docks/dialog_tooloptions.h"
51 #include <gtkmm/optionmenu.h>
53 #include <synfigapp/main.h>
59 /* === U S I N G =========================================================== */
63 using namespace synfig;
64 using namespace studio;
66 /* === M A C R O S ========================================================= */
68 /* === G L O B A L S ======================================================= */
70 StateRectangle studio::state_rectangle;
72 /* === C L A S S E S & S T R U C T S ======================================= */
74 class studio::StateRectangle_Context : public sigc::trackable
76 etl::handle<CanvasView> canvas_view_;
77 CanvasView::IsWorking is_working;
79 Duckmatic::Push duckmatic_push;
83 etl::handle<Duck> point2_duck;
87 bool prev_workarea_layer_status_;
90 synfigapp::Settings& settings;
93 Gtk::Table options_table;
95 Gtk::Entry entry_id; //what to name the layer
97 Gtk::Adjustment adj_expand;
98 Gtk::Adjustment adj_feather;
99 Gtk::SpinButton spin_expand;
100 Gtk::SpinButton spin_feather;
102 Gtk::CheckButton checkbutton_invert;
103 Gtk::CheckButton checkbutton_layer_rectangle;
104 Gtk::CheckButton checkbutton_layer_region;
105 Gtk::CheckButton checkbutton_layer_outline;
106 Gtk::CheckButton checkbutton_layer_curve_gradient;
107 Gtk::CheckButton checkbutton_layer_plant;
108 Gtk::CheckButton checkbutton_layer_link_origins;
112 // this only counts the layers which use blines - they're the only
113 // ones we link the origins for
114 int layers_to_create()const
117 get_layer_region_flag() +
118 get_layer_outline_flag() +
119 get_layer_curve_gradient_flag() +
120 get_layer_plant_flag();
123 synfig::String get_id()const { return entry_id.get_text(); }
124 void set_id(const synfig::String& x) { return entry_id.set_text(x); }
126 Real get_expand()const { return adj_expand.get_value(); }
127 void set_expand(Real f) { adj_expand.set_value(f); }
129 Real get_feather()const { return adj_feather.get_value(); }
130 void set_feather(Real f) { adj_feather.set_value(f); }
132 bool get_invert()const { return checkbutton_invert.get_active(); }
133 void set_invert(bool i) { checkbutton_invert.set_active(i); }
135 bool get_layer_rectangle_flag()const { return checkbutton_layer_rectangle.get_active(); }
136 void set_layer_rectangle_flag(bool x) { return checkbutton_layer_rectangle.set_active(x); }
138 bool get_layer_region_flag()const { return checkbutton_layer_region.get_active(); }
139 void set_layer_region_flag(bool x) { return checkbutton_layer_region.set_active(x); }
141 bool get_layer_outline_flag()const { return checkbutton_layer_outline.get_active(); }
142 void set_layer_outline_flag(bool x) { return checkbutton_layer_outline.set_active(x); }
144 bool get_layer_curve_gradient_flag()const { return checkbutton_layer_curve_gradient.get_active(); }
145 void set_layer_curve_gradient_flag(bool x) { return checkbutton_layer_curve_gradient.set_active(x); }
147 bool get_layer_plant_flag()const { return checkbutton_layer_plant.get_active(); }
148 void set_layer_plant_flag(bool x) { return checkbutton_layer_plant.set_active(x); }
150 bool get_layer_link_origins_flag()const { return checkbutton_layer_link_origins.get_active(); }
151 void set_layer_link_origins_flag(bool x) { return checkbutton_layer_link_origins.set_active(x); }
153 void refresh_tool_options(); //to refresh the toolbox
156 Smach::event_result event_stop_handler(const Smach::event& x);
157 Smach::event_result event_refresh_handler(const Smach::event& x);
158 Smach::event_result event_mouse_click_handler(const Smach::event& x);
159 Smach::event_result event_refresh_tool_options(const Smach::event& x);
161 //constructor destructor
162 StateRectangle_Context(CanvasView* canvas_view);
163 ~StateRectangle_Context();
166 const etl::handle<CanvasView>& get_canvas_view()const{return canvas_view_;}
167 etl::handle<synfigapp::CanvasInterface> get_canvas_interface()const{return canvas_view_->canvas_interface();}
168 synfig::Canvas::Handle get_canvas()const{return canvas_view_->get_canvas();}
169 WorkArea * get_work_area()const{return canvas_view_->get_work_area();}
171 //Modifying settings etc.
172 void load_settings();
173 void save_settings();
176 bool egress_on_selection_change;
177 Smach::event_result event_layer_selection_changed_handler(const Smach::event& /*x*/)
179 if(egress_on_selection_change)
180 throw &state_normal; //throw Smach::egress_exception();
181 return Smach::RESULT_OK;
184 void make_rectangle(const Point& p1, const Point& p2);
186 }; // END of class StateGradient_Context
188 /* === M E T H O D S ======================================================= */
190 StateRectangle::StateRectangle():
191 Smach::state<StateRectangle_Context>("rectangle")
193 insert(event_def(EVENT_STOP,&StateRectangle_Context::event_stop_handler));
194 insert(event_def(EVENT_LAYER_SELECTION_CHANGED,&StateRectangle_Context::event_layer_selection_changed_handler));
195 insert(event_def(EVENT_REFRESH,&StateRectangle_Context::event_refresh_handler));
196 insert(event_def(EVENT_REFRESH_DUCKS,&StateRectangle_Context::event_refresh_handler));
197 insert(event_def(EVENT_WORKAREA_MOUSE_BUTTON_DOWN,&StateRectangle_Context::event_mouse_click_handler));
198 insert(event_def(EVENT_WORKAREA_MOUSE_BUTTON_DRAG,&StateRectangle_Context::event_mouse_click_handler));
199 insert(event_def(EVENT_WORKAREA_MOUSE_BUTTON_UP,&StateRectangle_Context::event_mouse_click_handler));
200 insert(event_def(EVENT_REFRESH_TOOL_OPTIONS,&StateRectangle_Context::event_refresh_tool_options));
203 StateRectangle::~StateRectangle()
208 StateRectangle_Context::load_settings()
212 //parse the arguments yargh!
213 if(settings.get_value("rectangle.id",value))
218 if(settings.get_value("rectangle.expand",value))
219 set_expand(atof(value.c_str()));
223 if(settings.get_value("rectangle.feather",value))
224 set_feather(atof(value.c_str()));
228 if(settings.get_value("rectangle.invert",value) && value != "0")
233 if(settings.get_value("rectangle.layer_rectangle",value) && value=="0")
234 set_layer_rectangle_flag(false);
236 set_layer_rectangle_flag(true);
238 if(settings.get_value("rectangle.layer_region",value) && value=="1")
239 set_layer_region_flag(true);
241 set_layer_region_flag(false);
243 if(settings.get_value("rectangle.layer_outline",value) && value=="1")
244 set_layer_outline_flag(true);
246 set_layer_outline_flag(false);
248 if(settings.get_value("rectangle.layer_curve_gradient",value) && value=="1")
249 set_layer_curve_gradient_flag(true);
251 set_layer_curve_gradient_flag(false);
253 if(settings.get_value("rectangle.layer_plant",value) && value=="1")
254 set_layer_plant_flag(true);
256 set_layer_plant_flag(false);
258 if(settings.get_value("rectangle.layer_link_origins",value) && value=="0")
259 set_layer_link_origins_flag(false);
261 set_layer_link_origins_flag(true);
265 StateRectangle_Context::save_settings()
267 settings.set_value("rectangle.id",get_id().c_str());
268 settings.set_value("rectangle.expand",strprintf("%f",get_expand()));
269 settings.set_value("rectangle.feather",strprintf("%f",(float)get_feather()));
270 settings.set_value("rectangle.invert",get_invert()?"1":"0");
271 settings.set_value("rectangle.layer_rectangle",get_layer_rectangle_flag()?"1":"0");
272 settings.set_value("rectangle.layer_outline",get_layer_outline_flag()?"1":"0");
273 settings.set_value("rectangle.layer_region",get_layer_region_flag()?"1":"0");
274 settings.set_value("rectangle.layer_curve_gradient",get_layer_curve_gradient_flag()?"1":"0");
275 settings.set_value("rectangle.layer_plant",get_layer_plant_flag()?"1":"0");
276 settings.set_value("rectangle.layer_link_origins",get_layer_link_origins_flag()?"1":"0");
280 StateRectangle_Context::reset()
286 StateRectangle_Context::increment_id()
295 // If there is a number
296 // already at the end of the
297 // id, then remove it.
298 if(id[id.size()-1]<='9' && id[id.size()-1]>='0')
300 // figure out how many digits it is
302 (int)id.size()-1 >= digits && id[id.size()-1-digits] <= '9' && id[id.size()-1-digits] >= '0';
307 str_number=String(id,id.size()-digits,id.size());
308 id=String(id,0,id.size()-digits);
310 number=atoi(str_number.c_str());
320 // Add the number back onto the id
322 const String format(strprintf("%%0%dd",digits));
323 id+=strprintf(format.c_str(),number);
330 StateRectangle_Context::StateRectangle_Context(CanvasView* canvas_view):
331 canvas_view_(canvas_view),
332 is_working(*canvas_view),
333 duckmatic_push(get_work_area()),
334 prev_workarea_layer_status_(get_work_area()->get_allow_layer_clicks()),
335 settings(synfigapp::Main::get_selected_input_device()->settings()),
337 adj_expand(0,0,1,0.01,0.1),
338 adj_feather(0,0,1,0.01,0.1),
339 spin_expand(adj_expand,0.1,3),
340 spin_feather(adj_feather,0.1,3),
341 checkbutton_invert(_("Invert")),
342 checkbutton_layer_rectangle(_("Create Rectangle Layer")),
343 checkbutton_layer_region(_("Create Region BLine")),
344 checkbutton_layer_outline(_("Create Outline BLine")),
345 checkbutton_layer_curve_gradient(_("Create Curve Gradient BLine")),
346 checkbutton_layer_plant(_("Create Plant BLine")),
347 checkbutton_layer_link_origins(_("Link BLine Origins"))
349 egress_on_selection_change=true;
352 // Set up the tool options dialog
353 options_table.attach(*manage(new Gtk::Label(_("Rectangle Tool"))), 0, 2, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
354 options_table.attach(entry_id, 0, 2, 1, 2, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
356 options_table.attach(checkbutton_layer_rectangle, 0, 2, 2, 3, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
357 options_table.attach(checkbutton_layer_outline, 0, 2, 3, 4, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
358 options_table.attach(checkbutton_layer_region, 0, 2, 4, 5, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
359 options_table.attach(checkbutton_layer_plant, 0, 2, 5, 6, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
360 options_table.attach(checkbutton_layer_curve_gradient, 0, 2, 6, 7, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
361 options_table.attach(checkbutton_layer_link_origins, 0, 2, 7, 8, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
364 options_table.attach(checkbutton_invert, 0, 2, 8, 9, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
367 options_table.attach(*manage(new Gtk::Label(_("Expansion:"))), 0, 1, 9, 10, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
368 options_table.attach(spin_expand, 1, 2, 9, 10, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
371 options_table.attach(*manage(new Gtk::Label(_("Feather:"))), 0, 1, 10, 11, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
372 options_table.attach(spin_feather, 1, 2, 10, 11, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
374 options_table.show_all();
376 //App::dialog_tool_options->set_widget(options_table);
377 refresh_tool_options();
378 App::dialog_tool_options->present();
380 // Turn off layer clicking
381 get_work_area()->set_allow_layer_clicks(false);
383 // clear out the ducks
384 get_work_area()->clear_ducks();
386 // Refresh the work area
387 get_work_area()->queue_draw();
389 get_work_area()->set_cursor(Gdk::DOTBOX);
391 // Hide the tables if they are showing
392 //prev_table_status=get_canvas_view()->tables_are_visible();
393 //if(prev_table_status)get_canvas_view()->hide_tables();
395 // Disable the time bar
396 //get_canvas_view()->set_sensitive_timebar(false);
399 //get_work_area()->signal_user_click().connect(sigc::mem_fun(*this,&studio::StateRectangle_Context::on_user_click));
401 App::toolbox->refresh();
405 StateRectangle_Context::refresh_tool_options()
407 App::dialog_tool_options->clear();
408 App::dialog_tool_options->set_widget(options_table);
409 App::dialog_tool_options->set_local_name(_("Rectangle Tool"));
410 App::dialog_tool_options->set_name("rectangle");
414 StateRectangle_Context::event_refresh_tool_options(const Smach::event& /*x*/)
416 refresh_tool_options();
417 return Smach::RESULT_ACCEPT;
420 StateRectangle_Context::~StateRectangle_Context()
424 // Restore layer clicking
425 get_work_area()->set_allow_layer_clicks(prev_workarea_layer_status_);
427 get_work_area()->reset_cursor();
429 App::dialog_tool_options->clear();
431 // Enable the time bar
432 //get_canvas_view()->set_sensitive_timebar(true);
434 // Bring back the tables if they were out before
435 //if(prev_table_status)get_canvas_view()->show_tables();
437 // Refresh the work area
438 get_work_area()->queue_draw();
440 get_canvas_view()->queue_rebuild_ducks();
442 App::toolbox->refresh();
446 StateRectangle_Context::event_stop_handler(const Smach::event& /*x*/)
448 //throw Smach::egress_exception();
450 return Smach::RESULT_OK;
454 StateRectangle_Context::event_refresh_handler(const Smach::event& /*x*/)
457 return Smach::RESULT_ACCEPT;
461 StateRectangle_Context::make_rectangle(const Point& _p1, const Point& _p2)
463 synfigapp::Action::PassiveGrouper group(get_canvas_interface()->get_instance().get(),_("New Rectangle"));
464 synfigapp::PushMode push_mode(get_canvas_interface(),synfigapp::MODE_NORMAL);
468 Canvas::Handle canvas;
471 // we are temporarily using the layer to hold something
472 layer=get_canvas_view()->get_selection_manager()->get_selected_layer();
475 depth=layer->get_depth();
476 canvas=layer->get_canvas();
479 synfigapp::SelectionManager::LayerList layer_selection;
480 if (!getenv("SYNFIG_TOOLS_CLEAR_SELECTION"))
481 layer_selection = get_canvas_view()->get_selection_manager()->get_selected_layers();
483 const synfig::TransformStack& transform(get_canvas_view()->get_curr_transform_stack());
484 const Point p1(transform.unperform(_p1));
485 const Point p2(transform.unperform(_p2));
486 Real x_min, x_max, y_min, y_max;
487 if (p1[0] < p2[0]) { x_min = p1[0]; x_max = p2[0]; } else { x_min = p2[0]; x_max = p1[0]; }
488 if (p1[1] < p2[1]) { y_min = p1[1]; y_max = p2[1]; } else { y_min = p2[1]; y_max = p1[1]; }
489 x_min -= get_expand(); x_max += get_expand(); y_min -= get_expand(); y_max += get_expand();
491 std::vector<BLinePoint> new_list;
492 for (int i = 0; i < 4; i++)
494 new_list.push_back(*(new BLinePoint));
495 new_list[i].set_width(1);
496 new_list[i].set_vertex(Point((i==0||i==3)?x_min:x_max,
497 (i==0||i==1)?y_min:y_max));
498 new_list[i].set_tangent(Point(0,0));
501 ValueNode_BLine::Handle value_node_bline(ValueNode_BLine::create(new_list));
502 assert(value_node_bline);
504 ValueNode_Const::Handle value_node_origin(ValueNode_Const::create(Vector()));
505 assert(value_node_origin);
507 // Set the looping flag
508 value_node_bline->set_loop(true);
511 canvas=get_canvas_view()->get_canvas();
513 value_node_bline->set_member_canvas(canvas);
515 // count how many layers we're going to be creating
516 int layers_to_create = this->layers_to_create();
518 ///////////////////////////////////////////////////////////////////////////
520 ///////////////////////////////////////////////////////////////////////////
522 if (get_layer_rectangle_flag())
524 layer=get_canvas_interface()->add_layer_to("rectangle",canvas,depth);
527 get_canvas_view()->get_ui_interface()->error(_("Unable to create layer"));
531 layer_selection.push_back(layer);
533 layer->set_param("point1",p1);
534 get_canvas_interface()->signal_layer_param_changed()(layer,"point1");
536 layer->set_param("point2",p2);
537 get_canvas_interface()->signal_layer_param_changed()(layer,"point2");
539 layer->set_param("expand",get_expand());
540 get_canvas_interface()->signal_layer_param_changed()(layer,"expand");
542 layer->set_param("invert",get_invert());
543 get_canvas_interface()->signal_layer_param_changed()(layer,"invert");
545 layer->set_description(get_id());
546 get_canvas_interface()->signal_layer_new_description()(layer,layer->get_description());
549 ///////////////////////////////////////////////////////////////////////////
550 // C U R V E G R A D I E N T
551 ///////////////////////////////////////////////////////////////////////////
553 if(get_layer_curve_gradient_flag())
555 synfigapp::PushMode push_mode(get_canvas_interface(),synfigapp::MODE_NORMAL);
557 Layer::Handle layer(get_canvas_interface()->add_layer_to("curve_gradient",canvas,depth));
560 get_canvas_view()->get_ui_interface()->error(_("Unable to create layer"));
564 layer_selection.push_back(layer);
565 layer->set_description(get_id()+_(" Gradient"));
566 get_canvas_interface()->signal_layer_new_description()(layer,layer->get_description());
569 synfigapp::Action::Handle action(synfigapp::Action::create("LayerParamConnect"));
572 action->set_param("canvas",get_canvas());
573 action->set_param("canvas_interface",get_canvas_interface());
574 action->set_param("layer",layer);
575 if(!action->set_param("param",String("bline")))
576 synfig::error("LayerParamConnect didn't like \"param\"");
577 if(!action->set_param("value_node",ValueNode::Handle(value_node_bline)))
578 synfig::error("LayerParamConnect didn't like \"value_node\"");
580 if(!get_canvas_interface()->get_instance()->perform_action(action))
582 //get_canvas_view()->get_ui_interface()->error(_("Unable to create BLine layer"));
584 throw String(_("Unable to create Gradient layer"));
589 // only link the curve gradient's origin parameter if the option is selected and we're creating more than one layer
590 if (get_layer_link_origins_flag() && layers_to_create > 1)
592 synfigapp::Action::Handle action(synfigapp::Action::create("LayerParamConnect"));
595 action->set_param("canvas",get_canvas());
596 action->set_param("canvas_interface",get_canvas_interface());
597 action->set_param("layer",layer);
598 if(!action->set_param("param",String("origin")))
599 synfig::error("LayerParamConnect didn't like \"param\"");
600 if(!action->set_param("value_node",ValueNode::Handle(value_node_origin)))
601 synfig::error("LayerParamConnect didn't like \"value_node\"");
603 if(!get_canvas_interface()->get_instance()->perform_action(action))
605 //get_canvas_view()->get_ui_interface()->error(_("Unable to create BLine layer"));
607 throw String(_("Unable to create Gradient layer"));
613 ///////////////////////////////////////////////////////////////////////////
615 ///////////////////////////////////////////////////////////////////////////
617 if(get_layer_plant_flag())
619 synfigapp::PushMode push_mode(get_canvas_interface(),synfigapp::MODE_NORMAL);
621 Layer::Handle layer(get_canvas_interface()->add_layer_to("plant",canvas,depth));
624 get_canvas_view()->get_ui_interface()->error(_("Unable to create layer"));
628 layer_selection.push_back(layer);
629 layer->set_description(get_id()+_(" Plant"));
630 get_canvas_interface()->signal_layer_new_description()(layer,layer->get_description());
633 synfigapp::Action::Handle action(synfigapp::Action::create("LayerParamConnect"));
636 action->set_param("canvas",get_canvas());
637 action->set_param("canvas_interface",get_canvas_interface());
638 action->set_param("layer",layer);
639 if(!action->set_param("param",String("bline")))
640 synfig::error("LayerParamConnect didn't like \"param\"");
641 if(!action->set_param("value_node",ValueNode::Handle(value_node_bline)))
642 synfig::error("LayerParamConnect didn't like \"value_node\"");
644 if(!get_canvas_interface()->get_instance()->perform_action(action))
646 //get_canvas_view()->get_ui_interface()->error(_("Unable to create BLine layer"));
648 throw String(_("Unable to create Plant layer"));
653 // only link the plant's origin parameter if the option is selected and we're creating more than one layer
654 if (get_layer_link_origins_flag() && layers_to_create > 1)
656 synfigapp::Action::Handle action(synfigapp::Action::create("LayerParamConnect"));
659 action->set_param("canvas",get_canvas());
660 action->set_param("canvas_interface",get_canvas_interface());
661 action->set_param("layer",layer);
662 if(!action->set_param("param",String("origin")))
663 synfig::error("LayerParamConnect didn't like \"param\"");
664 if(!action->set_param("value_node",ValueNode::Handle(value_node_origin)))
665 synfig::error("LayerParamConnect didn't like \"value_node\"");
667 if(!get_canvas_interface()->get_instance()->perform_action(action))
669 //get_canvas_view()->get_ui_interface()->error(_("Unable to create BLine layer"));
671 throw String(_("Unable to create Plant layer"));
677 ///////////////////////////////////////////////////////////////////////////
679 ///////////////////////////////////////////////////////////////////////////
681 if(get_layer_region_flag())
683 synfigapp::PushMode push_mode(get_canvas_interface(),synfigapp::MODE_NORMAL);
685 Layer::Handle layer(get_canvas_interface()->add_layer_to("region",canvas,depth));
688 get_canvas_view()->get_ui_interface()->error(_("Unable to create layer"));
692 layer_selection.push_back(layer);
693 layer->set_description(get_id()+_(" Region"));
694 get_canvas_interface()->signal_layer_new_description()(layer,layer->get_description());
696 layer->set_param("feather",get_feather());
697 get_canvas_interface()->signal_layer_param_changed()(layer,"feather");
699 layer->set_param("invert",get_invert());
700 get_canvas_interface()->signal_layer_param_changed()(layer,"invert");
702 // I don't know if it's safe to reuse the same LayerParamConnect action, so I'm
703 // using 2 separate ones.
705 synfigapp::Action::Handle action(synfigapp::Action::create("LayerParamConnect"));
708 action->set_param("canvas",get_canvas());
709 action->set_param("canvas_interface",get_canvas_interface());
710 action->set_param("layer",layer);
711 if(!action->set_param("param",String("bline")))
712 synfig::error("LayerParamConnect didn't like \"param\"");
713 if(!action->set_param("value_node",ValueNode::Handle(value_node_bline)))
714 synfig::error("LayerParamConnect didn't like \"value_node\"");
716 if(!get_canvas_interface()->get_instance()->perform_action(action))
718 //get_canvas_view()->get_ui_interface()->error(_("Unable to create Region layer"));
720 throw String(_("Unable to create Region layer"));
725 // only link the region's origin parameter if the option is selected and we're creating more than one layer
726 if (get_layer_link_origins_flag() && layers_to_create > 1)
728 synfigapp::Action::Handle action(synfigapp::Action::create("LayerParamConnect"));
731 action->set_param("canvas",get_canvas());
732 action->set_param("canvas_interface",get_canvas_interface());
733 action->set_param("layer",layer);
734 if(!action->set_param("param",String("origin")))
735 synfig::error("LayerParamConnect didn't like \"param\"");
736 if(!action->set_param("value_node",ValueNode::Handle(value_node_origin)))
737 synfig::error("LayerParamConnect didn't like \"value_node\"");
739 if(!get_canvas_interface()->get_instance()->perform_action(action))
741 //get_canvas_view()->get_ui_interface()->error(_("Unable to create Region layer"));
743 throw String(_("Unable to create Region layer"));
749 ///////////////////////////////////////////////////////////////////////////
751 ///////////////////////////////////////////////////////////////////////////
753 if (get_layer_outline_flag())
755 Layer::Handle layer(get_canvas_interface()->add_layer_to("outline",canvas,depth));
758 get_canvas_view()->get_ui_interface()->error(_("Unable to create layer"));
762 layer_selection.push_back(layer);
763 layer->set_description(get_id()+_(" Outline"));
764 get_canvas_interface()->signal_layer_new_description()(layer,layer->get_description());
766 layer->set_param("feather",get_feather());
767 get_canvas_interface()->signal_layer_param_changed()(layer,"feather");
769 layer->set_param("invert",get_invert());
770 get_canvas_interface()->signal_layer_param_changed()(layer,"invert");
773 synfigapp::Action::Handle action(synfigapp::Action::create("LayerParamConnect"));
776 action->set_param("canvas",get_canvas());
777 action->set_param("canvas_interface",get_canvas_interface());
778 action->set_param("layer",layer);
779 if(!action->set_param("param",String("bline")))
780 synfig::error("LayerParamConnect didn't like \"param\"");
781 if(!action->set_param("value_node",ValueNode::Handle(value_node_bline)))
782 synfig::error("LayerParamConnect didn't like \"value_node\"");
784 if(!get_canvas_interface()->get_instance()->perform_action(action))
786 //get_canvas_view()->get_ui_interface()->error(_("Unable to create BLine layer"));
788 throw String(_("Unable to create Outline layer"));
793 // only link the outline's origin parameter if the option is selected and we're creating more than one layer
794 if (get_layer_link_origins_flag() && layers_to_create > 1)
796 synfigapp::Action::Handle action(synfigapp::Action::create("LayerParamConnect"));
799 action->set_param("canvas",get_canvas());
800 action->set_param("canvas_interface",get_canvas_interface());
801 action->set_param("layer",layer);
802 if(!action->set_param("param",String("origin")))
803 synfig::error("LayerParamConnect didn't like \"param\"");
804 if(!action->set_param("value_node",ValueNode::Handle(value_node_origin)))
805 synfig::error("LayerParamConnect didn't like \"value_node\"");
807 if(!get_canvas_interface()->get_instance()->perform_action(action))
809 //get_canvas_view()->get_ui_interface()->error(_("Unable to create BLine layer"));
811 throw String(_("Unable to create Outline layer"));
817 egress_on_selection_change=false;
818 get_canvas_interface()->get_selection_manager()->clear_selected_layers();
819 get_canvas_interface()->get_selection_manager()->set_selected_layers(layer_selection);
820 egress_on_selection_change=true;
822 //post clean up stuff...
828 StateRectangle_Context::event_mouse_click_handler(const Smach::event& x)
830 const EventMouse& event(*reinterpret_cast<const EventMouse*>(&x));
832 if(event.key==EVENT_WORKAREA_MOUSE_BUTTON_DOWN && event.button==BUTTON_LEFT)
834 point_holder=get_work_area()->snap_point_to_grid(event.pos);
835 etl::handle<Duck> duck=new Duck();
836 duck->set_point(point_holder);
837 duck->set_name("p1");
838 duck->set_type(Duck::TYPE_POSITION);
839 get_work_area()->add_duck(duck);
841 point2_duck=new Duck();
842 point2_duck->set_point(point_holder);
843 point2_duck->set_name("p2");
844 point2_duck->set_type(Duck::TYPE_POSITION);
845 point2_duck->set_box_duck(duck);
846 get_work_area()->add_duck(point2_duck);
848 return Smach::RESULT_ACCEPT;
851 if(event.key==EVENT_WORKAREA_MOUSE_BUTTON_DRAG && event.button==BUTTON_LEFT)
853 if (!point2_duck) return Smach::RESULT_OK;
854 point2_duck->set_point(get_work_area()->snap_point_to_grid(event.pos));
855 get_work_area()->queue_draw();
856 return Smach::RESULT_ACCEPT;
859 if(event.key==EVENT_WORKAREA_MOUSE_BUTTON_UP && event.button==BUTTON_LEFT)
861 make_rectangle(point_holder, get_work_area()->snap_point_to_grid(event.pos));
862 get_work_area()->clear_ducks();
863 return Smach::RESULT_ACCEPT;
866 return Smach::RESULT_OK;
871 StateRectangle_Context::refresh_ducks()
873 get_work_area()->clear_ducks();
874 get_work_area()->queue_draw();