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 SETTINGS_LOCALE_SAFE_AND_BACKUP
215 //parse the arguments yargh!
216 if(settings.get_value("rectangle.id",value))
221 if(settings.get_value("rectangle.expand",value))
222 set_expand(atof(value.c_str()));
226 if(settings.get_value("rectangle.feather",value))
227 set_feather(atof(value.c_str()));
231 if(settings.get_value("rectangle.invert",value) && value != "0")
236 if(settings.get_value("rectangle.layer_rectangle",value) && value=="0")
237 set_layer_rectangle_flag(false);
239 set_layer_rectangle_flag(true);
241 if(settings.get_value("rectangle.layer_region",value) && value=="1")
242 set_layer_region_flag(true);
244 set_layer_region_flag(false);
246 if(settings.get_value("rectangle.layer_outline",value) && value=="1")
247 set_layer_outline_flag(true);
249 set_layer_outline_flag(false);
251 if(settings.get_value("rectangle.layer_curve_gradient",value) && value=="1")
252 set_layer_curve_gradient_flag(true);
254 set_layer_curve_gradient_flag(false);
256 if(settings.get_value("rectangle.layer_plant",value) && value=="1")
257 set_layer_plant_flag(true);
259 set_layer_plant_flag(false);
261 if(settings.get_value("rectangle.layer_link_origins",value) && value=="0")
262 set_layer_link_origins_flag(false);
264 set_layer_link_origins_flag(true);
265 SETTINGS_LOCALE_RESTORE
269 synfig::warning("State Rectangle: Caught exception when attempting to load settings.");
274 StateRectangle_Context::save_settings()
278 SETTINGS_LOCALE_SAFE_AND_BACKUP
279 settings.set_value("rectangle.id",get_id().c_str());
280 settings.set_value("rectangle.expand",strprintf("%f",get_expand()));
281 settings.set_value("rectangle.feather",strprintf("%f",(float)get_feather()));
282 settings.set_value("rectangle.invert",get_invert()?"1":"0");
283 settings.set_value("rectangle.layer_rectangle",get_layer_rectangle_flag()?"1":"0");
284 settings.set_value("rectangle.layer_outline",get_layer_outline_flag()?"1":"0");
285 settings.set_value("rectangle.layer_region",get_layer_region_flag()?"1":"0");
286 settings.set_value("rectangle.layer_curve_gradient",get_layer_curve_gradient_flag()?"1":"0");
287 settings.set_value("rectangle.layer_plant",get_layer_plant_flag()?"1":"0");
288 settings.set_value("rectangle.layer_link_origins",get_layer_link_origins_flag()?"1":"0");
289 SETTINGS_LOCALE_RESTORE
293 synfig::warning("State Rectangle: Caught exception when attempting to save settings.");
298 StateRectangle_Context::reset()
304 StateRectangle_Context::increment_id()
313 // If there is a number
314 // already at the end of the
315 // id, then remove it.
316 if(id[id.size()-1]<='9' && id[id.size()-1]>='0')
318 // figure out how many digits it is
320 (int)id.size()-1 >= digits && id[id.size()-1-digits] <= '9' && id[id.size()-1-digits] >= '0';
325 str_number=String(id,id.size()-digits,id.size());
326 id=String(id,0,id.size()-digits);
328 number=atoi(str_number.c_str());
338 // Add the number back onto the id
340 const String format(strprintf("%%0%dd",digits));
341 id+=strprintf(format.c_str(),number);
348 StateRectangle_Context::StateRectangle_Context(CanvasView* canvas_view):
349 canvas_view_(canvas_view),
350 is_working(*canvas_view),
351 duckmatic_push(get_work_area()),
352 prev_workarea_layer_status_(get_work_area()->get_allow_layer_clicks()),
353 settings(synfigapp::Main::get_selected_input_device()->settings()),
355 adj_expand(0,0,1,0.01,0.1),
356 adj_feather(0,0,1,0.01,0.1),
357 spin_expand(adj_expand,0.1,3),
358 spin_feather(adj_feather,0.1,3),
359 checkbutton_invert(_("Invert")),
360 checkbutton_layer_rectangle(_("Create Rectangle Layer")),
361 checkbutton_layer_region(_("Create Region BLine")),
362 checkbutton_layer_outline(_("Create Outline BLine")),
363 checkbutton_layer_curve_gradient(_("Create Curve Gradient BLine")),
364 checkbutton_layer_plant(_("Create Plant BLine")),
365 checkbutton_layer_link_origins(_("Link BLine Origins"))
367 egress_on_selection_change=true;
370 // Set up the tool options dialog
371 options_table.attach(*manage(new Gtk::Label(_("Rectangle Tool"))), 0, 2, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
372 options_table.attach(entry_id, 0, 2, 1, 2, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
374 options_table.attach(checkbutton_layer_rectangle, 0, 2, 2, 3, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
375 options_table.attach(checkbutton_layer_outline, 0, 2, 3, 4, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
376 options_table.attach(checkbutton_layer_region, 0, 2, 4, 5, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
377 options_table.attach(checkbutton_layer_plant, 0, 2, 5, 6, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
378 options_table.attach(checkbutton_layer_curve_gradient, 0, 2, 6, 7, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
379 options_table.attach(checkbutton_layer_link_origins, 0, 2, 7, 8, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
382 options_table.attach(checkbutton_invert, 0, 2, 8, 9, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
385 options_table.attach(*manage(new Gtk::Label(_("Expansion:"))), 0, 1, 9, 10, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
386 options_table.attach(spin_expand, 1, 2, 9, 10, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
389 options_table.attach(*manage(new Gtk::Label(_("Feather:"))), 0, 1, 10, 11, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
390 options_table.attach(spin_feather, 1, 2, 10, 11, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
392 options_table.show_all();
394 //App::dialog_tool_options->set_widget(options_table);
395 refresh_tool_options();
396 App::dialog_tool_options->present();
398 // Turn off layer clicking
399 get_work_area()->set_allow_layer_clicks(false);
401 // clear out the ducks
402 get_work_area()->clear_ducks();
404 // Refresh the work area
405 get_work_area()->queue_draw();
407 get_work_area()->set_cursor(Gdk::DOTBOX);
409 // Hide the tables if they are showing
410 //prev_table_status=get_canvas_view()->tables_are_visible();
411 //if(prev_table_status)get_canvas_view()->hide_tables();
413 // Disable the time bar
414 //get_canvas_view()->set_sensitive_timebar(false);
417 //get_work_area()->signal_user_click().connect(sigc::mem_fun(*this,&studio::StateRectangle_Context::on_user_click));
419 App::toolbox->refresh();
423 StateRectangle_Context::refresh_tool_options()
425 App::dialog_tool_options->clear();
426 App::dialog_tool_options->set_widget(options_table);
427 App::dialog_tool_options->set_local_name(_("Rectangle Tool"));
428 App::dialog_tool_options->set_name("rectangle");
432 StateRectangle_Context::event_refresh_tool_options(const Smach::event& /*x*/)
434 refresh_tool_options();
435 return Smach::RESULT_ACCEPT;
438 StateRectangle_Context::~StateRectangle_Context()
442 // Restore layer clicking
443 get_work_area()->set_allow_layer_clicks(prev_workarea_layer_status_);
445 get_work_area()->reset_cursor();
447 App::dialog_tool_options->clear();
449 // Enable the time bar
450 //get_canvas_view()->set_sensitive_timebar(true);
452 // Bring back the tables if they were out before
453 //if(prev_table_status)get_canvas_view()->show_tables();
455 // Refresh the work area
456 get_work_area()->queue_draw();
458 get_canvas_view()->queue_rebuild_ducks();
460 App::toolbox->refresh();
464 StateRectangle_Context::event_stop_handler(const Smach::event& /*x*/)
466 //throw Smach::egress_exception();
468 return Smach::RESULT_OK;
472 StateRectangle_Context::event_refresh_handler(const Smach::event& /*x*/)
475 return Smach::RESULT_ACCEPT;
479 StateRectangle_Context::make_rectangle(const Point& _p1, const Point& _p2)
481 synfigapp::Action::PassiveGrouper group(get_canvas_interface()->get_instance().get(),_("New Rectangle"));
482 synfigapp::PushMode push_mode(get_canvas_interface(),synfigapp::MODE_NORMAL);
486 Canvas::Handle canvas;
489 // we are temporarily using the layer to hold something
490 layer=get_canvas_view()->get_selection_manager()->get_selected_layer();
493 depth=layer->get_depth();
494 canvas=layer->get_canvas();
497 synfigapp::SelectionManager::LayerList layer_selection;
498 if (!getenv("SYNFIG_TOOLS_CLEAR_SELECTION"))
499 layer_selection = get_canvas_view()->get_selection_manager()->get_selected_layers();
501 const synfig::TransformStack& transform(get_canvas_view()->get_curr_transform_stack());
502 const Point p1(transform.unperform(_p1));
503 const Point p2(transform.unperform(_p2));
504 Real x_min, x_max, y_min, y_max;
505 if (p1[0] < p2[0]) { x_min = p1[0]; x_max = p2[0]; } else { x_min = p2[0]; x_max = p1[0]; }
506 if (p1[1] < p2[1]) { y_min = p1[1]; y_max = p2[1]; } else { y_min = p2[1]; y_max = p1[1]; }
507 x_min -= get_expand(); x_max += get_expand(); y_min -= get_expand(); y_max += get_expand();
509 std::vector<BLinePoint> new_list;
510 for (int i = 0; i < 4; i++)
512 new_list.push_back(*(new BLinePoint));
513 new_list[i].set_width(1);
514 new_list[i].set_vertex(Point((i==0||i==3)?x_min:x_max,
515 (i==0||i==1)?y_min:y_max));
516 new_list[i].set_tangent(Point(0,0));
519 ValueNode_BLine::Handle value_node_bline(ValueNode_BLine::create(new_list));
520 assert(value_node_bline);
522 ValueNode_Const::Handle value_node_origin(ValueNode_Const::create(Vector()));
523 assert(value_node_origin);
525 // Set the looping flag
526 value_node_bline->set_loop(true);
529 canvas=get_canvas_view()->get_canvas();
531 value_node_bline->set_member_canvas(canvas);
533 // count how many layers we're going to be creating
534 int layers_to_create = this->layers_to_create();
536 ///////////////////////////////////////////////////////////////////////////
538 ///////////////////////////////////////////////////////////////////////////
540 if (get_layer_rectangle_flag())
542 layer=get_canvas_interface()->add_layer_to("rectangle",canvas,depth);
545 get_canvas_view()->get_ui_interface()->error(_("Unable to create layer"));
549 layer_selection.push_back(layer);
551 layer->set_param("point1",p1);
552 get_canvas_interface()->signal_layer_param_changed()(layer,"point1");
554 layer->set_param("point2",p2);
555 get_canvas_interface()->signal_layer_param_changed()(layer,"point2");
557 layer->set_param("expand",get_expand());
558 get_canvas_interface()->signal_layer_param_changed()(layer,"expand");
560 layer->set_param("invert",get_invert());
561 get_canvas_interface()->signal_layer_param_changed()(layer,"invert");
563 layer->set_description(get_id());
564 get_canvas_interface()->signal_layer_new_description()(layer,layer->get_description());
567 ///////////////////////////////////////////////////////////////////////////
568 // C U R V E G R A D I E N T
569 ///////////////////////////////////////////////////////////////////////////
571 if(get_layer_curve_gradient_flag())
573 synfigapp::PushMode push_mode(get_canvas_interface(),synfigapp::MODE_NORMAL);
575 Layer::Handle layer(get_canvas_interface()->add_layer_to("curve_gradient",canvas,depth));
578 get_canvas_view()->get_ui_interface()->error(_("Unable to create layer"));
582 layer_selection.push_back(layer);
583 layer->set_description(get_id()+_(" Gradient"));
584 get_canvas_interface()->signal_layer_new_description()(layer,layer->get_description());
587 synfigapp::Action::Handle action(synfigapp::Action::create("LayerParamConnect"));
590 action->set_param("canvas",get_canvas());
591 action->set_param("canvas_interface",get_canvas_interface());
592 action->set_param("layer",layer);
593 if(!action->set_param("param",String("bline")))
594 synfig::error("LayerParamConnect didn't like \"param\"");
595 if(!action->set_param("value_node",ValueNode::Handle(value_node_bline)))
596 synfig::error("LayerParamConnect didn't like \"value_node\"");
598 if(!get_canvas_interface()->get_instance()->perform_action(action))
600 //get_canvas_view()->get_ui_interface()->error(_("Unable to create BLine layer"));
602 throw String(_("Unable to create Gradient layer"));
607 // only link the curve gradient's origin parameter if the option is selected and we're creating more than one layer
608 if (get_layer_link_origins_flag() && layers_to_create > 1)
610 synfigapp::Action::Handle action(synfigapp::Action::create("LayerParamConnect"));
613 action->set_param("canvas",get_canvas());
614 action->set_param("canvas_interface",get_canvas_interface());
615 action->set_param("layer",layer);
616 if(!action->set_param("param",String("origin")))
617 synfig::error("LayerParamConnect didn't like \"param\"");
618 if(!action->set_param("value_node",ValueNode::Handle(value_node_origin)))
619 synfig::error("LayerParamConnect didn't like \"value_node\"");
621 if(!get_canvas_interface()->get_instance()->perform_action(action))
623 //get_canvas_view()->get_ui_interface()->error(_("Unable to create BLine layer"));
625 throw String(_("Unable to create Gradient layer"));
631 ///////////////////////////////////////////////////////////////////////////
633 ///////////////////////////////////////////////////////////////////////////
635 if(get_layer_plant_flag())
637 synfigapp::PushMode push_mode(get_canvas_interface(),synfigapp::MODE_NORMAL);
639 Layer::Handle layer(get_canvas_interface()->add_layer_to("plant",canvas,depth));
642 get_canvas_view()->get_ui_interface()->error(_("Unable to create layer"));
646 layer_selection.push_back(layer);
647 layer->set_description(get_id()+_(" Plant"));
648 get_canvas_interface()->signal_layer_new_description()(layer,layer->get_description());
651 synfigapp::Action::Handle action(synfigapp::Action::create("LayerParamConnect"));
654 action->set_param("canvas",get_canvas());
655 action->set_param("canvas_interface",get_canvas_interface());
656 action->set_param("layer",layer);
657 if(!action->set_param("param",String("bline")))
658 synfig::error("LayerParamConnect didn't like \"param\"");
659 if(!action->set_param("value_node",ValueNode::Handle(value_node_bline)))
660 synfig::error("LayerParamConnect didn't like \"value_node\"");
662 if(!get_canvas_interface()->get_instance()->perform_action(action))
664 //get_canvas_view()->get_ui_interface()->error(_("Unable to create BLine layer"));
666 throw String(_("Unable to create Plant layer"));
671 // only link the plant's origin parameter if the option is selected and we're creating more than one layer
672 if (get_layer_link_origins_flag() && layers_to_create > 1)
674 synfigapp::Action::Handle action(synfigapp::Action::create("LayerParamConnect"));
677 action->set_param("canvas",get_canvas());
678 action->set_param("canvas_interface",get_canvas_interface());
679 action->set_param("layer",layer);
680 if(!action->set_param("param",String("origin")))
681 synfig::error("LayerParamConnect didn't like \"param\"");
682 if(!action->set_param("value_node",ValueNode::Handle(value_node_origin)))
683 synfig::error("LayerParamConnect didn't like \"value_node\"");
685 if(!get_canvas_interface()->get_instance()->perform_action(action))
687 //get_canvas_view()->get_ui_interface()->error(_("Unable to create BLine layer"));
689 throw String(_("Unable to create Plant layer"));
695 ///////////////////////////////////////////////////////////////////////////
697 ///////////////////////////////////////////////////////////////////////////
699 if(get_layer_region_flag())
701 synfigapp::PushMode push_mode(get_canvas_interface(),synfigapp::MODE_NORMAL);
703 Layer::Handle layer(get_canvas_interface()->add_layer_to("region",canvas,depth));
706 get_canvas_view()->get_ui_interface()->error(_("Unable to create layer"));
710 layer_selection.push_back(layer);
711 layer->set_description(get_id()+_(" Region"));
712 get_canvas_interface()->signal_layer_new_description()(layer,layer->get_description());
714 layer->set_param("feather",get_feather());
715 get_canvas_interface()->signal_layer_param_changed()(layer,"feather");
717 layer->set_param("invert",get_invert());
718 get_canvas_interface()->signal_layer_param_changed()(layer,"invert");
720 // I don't know if it's safe to reuse the same LayerParamConnect action, so I'm
721 // using 2 separate ones.
723 synfigapp::Action::Handle action(synfigapp::Action::create("LayerParamConnect"));
726 action->set_param("canvas",get_canvas());
727 action->set_param("canvas_interface",get_canvas_interface());
728 action->set_param("layer",layer);
729 if(!action->set_param("param",String("bline")))
730 synfig::error("LayerParamConnect didn't like \"param\"");
731 if(!action->set_param("value_node",ValueNode::Handle(value_node_bline)))
732 synfig::error("LayerParamConnect didn't like \"value_node\"");
734 if(!get_canvas_interface()->get_instance()->perform_action(action))
736 //get_canvas_view()->get_ui_interface()->error(_("Unable to create Region layer"));
738 throw String(_("Unable to create Region layer"));
743 // only link the region's origin parameter if the option is selected and we're creating more than one layer
744 if (get_layer_link_origins_flag() && layers_to_create > 1)
746 synfigapp::Action::Handle action(synfigapp::Action::create("LayerParamConnect"));
749 action->set_param("canvas",get_canvas());
750 action->set_param("canvas_interface",get_canvas_interface());
751 action->set_param("layer",layer);
752 if(!action->set_param("param",String("origin")))
753 synfig::error("LayerParamConnect didn't like \"param\"");
754 if(!action->set_param("value_node",ValueNode::Handle(value_node_origin)))
755 synfig::error("LayerParamConnect didn't like \"value_node\"");
757 if(!get_canvas_interface()->get_instance()->perform_action(action))
759 //get_canvas_view()->get_ui_interface()->error(_("Unable to create Region layer"));
761 throw String(_("Unable to create Region layer"));
767 ///////////////////////////////////////////////////////////////////////////
769 ///////////////////////////////////////////////////////////////////////////
771 if (get_layer_outline_flag())
773 Layer::Handle layer(get_canvas_interface()->add_layer_to("outline",canvas,depth));
776 get_canvas_view()->get_ui_interface()->error(_("Unable to create layer"));
780 layer_selection.push_back(layer);
781 layer->set_description(get_id()+_(" Outline"));
782 get_canvas_interface()->signal_layer_new_description()(layer,layer->get_description());
784 layer->set_param("feather",get_feather());
785 get_canvas_interface()->signal_layer_param_changed()(layer,"feather");
787 layer->set_param("invert",get_invert());
788 get_canvas_interface()->signal_layer_param_changed()(layer,"invert");
791 synfigapp::Action::Handle action(synfigapp::Action::create("LayerParamConnect"));
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("bline")))
798 synfig::error("LayerParamConnect didn't like \"param\"");
799 if(!action->set_param("value_node",ValueNode::Handle(value_node_bline)))
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 BLine layer"));
806 throw String(_("Unable to create Outline layer"));
811 // only link the outline's origin parameter if the option is selected and we're creating more than one layer
812 if (get_layer_link_origins_flag() && layers_to_create > 1)
814 synfigapp::Action::Handle action(synfigapp::Action::create("LayerParamConnect"));
817 action->set_param("canvas",get_canvas());
818 action->set_param("canvas_interface",get_canvas_interface());
819 action->set_param("layer",layer);
820 if(!action->set_param("param",String("origin")))
821 synfig::error("LayerParamConnect didn't like \"param\"");
822 if(!action->set_param("value_node",ValueNode::Handle(value_node_origin)))
823 synfig::error("LayerParamConnect didn't like \"value_node\"");
825 if(!get_canvas_interface()->get_instance()->perform_action(action))
827 //get_canvas_view()->get_ui_interface()->error(_("Unable to create BLine layer"));
829 throw String(_("Unable to create Outline layer"));
835 egress_on_selection_change=false;
836 get_canvas_interface()->get_selection_manager()->clear_selected_layers();
837 get_canvas_interface()->get_selection_manager()->set_selected_layers(layer_selection);
838 egress_on_selection_change=true;
840 //post clean up stuff...
846 StateRectangle_Context::event_mouse_click_handler(const Smach::event& x)
848 const EventMouse& event(*reinterpret_cast<const EventMouse*>(&x));
850 if(event.key==EVENT_WORKAREA_MOUSE_BUTTON_DOWN && event.button==BUTTON_LEFT)
852 point_holder=get_work_area()->snap_point_to_grid(event.pos);
853 etl::handle<Duck> duck=new Duck();
854 duck->set_point(point_holder);
855 duck->set_name("p1");
856 duck->set_type(Duck::TYPE_POSITION);
857 get_work_area()->add_duck(duck);
859 point2_duck=new Duck();
860 point2_duck->set_point(point_holder);
861 point2_duck->set_name("p2");
862 point2_duck->set_type(Duck::TYPE_POSITION);
863 point2_duck->set_box_duck(duck);
864 get_work_area()->add_duck(point2_duck);
866 return Smach::RESULT_ACCEPT;
869 if(event.key==EVENT_WORKAREA_MOUSE_BUTTON_DRAG && event.button==BUTTON_LEFT)
871 if (!point2_duck) return Smach::RESULT_OK;
872 point2_duck->set_point(get_work_area()->snap_point_to_grid(event.pos));
873 get_work_area()->queue_draw();
874 return Smach::RESULT_ACCEPT;
877 if(event.key==EVENT_WORKAREA_MOUSE_BUTTON_UP && event.button==BUTTON_LEFT)
879 make_rectangle(point_holder, get_work_area()->snap_point_to_grid(event.pos));
880 get_work_area()->clear_ducks();
881 return Smach::RESULT_ACCEPT;
884 return Smach::RESULT_OK;
889 StateRectangle_Context::refresh_ducks()
891 get_work_area()->clear_ducks();
892 get_work_area()->queue_draw();