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
10 ** This package is free software; you can redistribute it and/or
11 ** modify it under the terms of the GNU General Public License as
12 ** published by the Free Software Foundation; either version 2 of
13 ** the License, or (at your option) any later version.
15 ** This package is distributed in the hope that it will be useful,
16 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 ** General Public License for more details.
21 /* ========================================================================= */
23 /* === H E A D E R S ======================================================= */
32 #include <gtkmm/dialog.h>
33 #include <gtkmm/entry.h>
35 #include <synfig/valuenode_dynamiclist.h>
36 #include <synfigapp/action_system.h>
37 #include <synfig/valuenode_bline.h>
39 #include "state_rectangle.h"
40 #include "canvasview.h"
44 #include <synfigapp/action.h>
45 #include "event_mouse.h"
46 #include "event_layerclick.h"
48 #include "dialog_tooloptions.h"
49 #include <gtkmm/optionmenu.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 StateRectangle studio::state_rectangle;
70 /* === C L A S S E S & S T R U C T S ======================================= */
72 class studio::StateRectangle_Context : public sigc::trackable
74 etl::handle<CanvasView> canvas_view_;
75 CanvasView::IsWorking is_working;
77 Duckmatic::Push duckmatic_push;
81 etl::handle<Duck> point2_duck;
85 bool prev_workarea_layer_status_;
88 synfigapp::Settings& settings;
91 Gtk::Table options_table;
93 Gtk::Entry entry_id; //what to name the layer
95 Gtk::Adjustment adj_expand;
96 Gtk::Adjustment adj_feather;
97 Gtk::SpinButton spin_expand;
98 Gtk::SpinButton spin_feather;
100 Gtk::CheckButton checkbutton_invert;
101 Gtk::CheckButton checkbutton_layer_rectangle;
102 Gtk::CheckButton checkbutton_layer_region;
103 Gtk::CheckButton checkbutton_layer_outline;
104 Gtk::CheckButton checkbutton_layer_curve_gradient;
105 Gtk::CheckButton checkbutton_layer_plant;
106 Gtk::CheckButton checkbutton_layer_link_origins;
110 // this only counts the layers which use blines - they're the only
111 // ones we link the origins for
112 int layers_to_create()const
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 Real get_expand()const { return adj_expand.get_value(); }
125 void set_expand(Real f) { adj_expand.set_value(f); }
127 Real get_feather()const { return adj_feather.get_value(); }
128 void set_feather(Real f) { adj_feather.set_value(f); }
130 bool get_invert()const { return checkbutton_invert.get_active(); }
131 void set_invert(bool i) { checkbutton_invert.set_active(i); }
133 bool get_layer_rectangle_flag()const { return checkbutton_layer_rectangle.get_active(); }
134 void set_layer_rectangle_flag(bool x) { return checkbutton_layer_rectangle.set_active(x); }
136 bool get_layer_region_flag()const { return checkbutton_layer_region.get_active(); }
137 void set_layer_region_flag(bool x) { return checkbutton_layer_region.set_active(x); }
139 bool get_layer_outline_flag()const { return checkbutton_layer_outline.get_active(); }
140 void set_layer_outline_flag(bool x) { return checkbutton_layer_outline.set_active(x); }
142 bool get_layer_curve_gradient_flag()const { return checkbutton_layer_curve_gradient.get_active(); }
143 void set_layer_curve_gradient_flag(bool x) { return checkbutton_layer_curve_gradient.set_active(x); }
145 bool get_layer_plant_flag()const { return checkbutton_layer_plant.get_active(); }
146 void set_layer_plant_flag(bool x) { return checkbutton_layer_plant.set_active(x); }
148 bool get_layer_link_origins_flag()const { return checkbutton_layer_link_origins.get_active(); }
149 void set_layer_link_origins_flag(bool x) { return checkbutton_layer_link_origins.set_active(x); }
151 void refresh_tool_options(); //to refresh the toolbox
154 Smach::event_result event_stop_handler(const Smach::event& x);
155 Smach::event_result event_refresh_handler(const Smach::event& x);
156 Smach::event_result event_mouse_click_handler(const Smach::event& x);
157 Smach::event_result event_refresh_tool_options(const Smach::event& x);
159 //constructor destructor
160 StateRectangle_Context(CanvasView* canvas_view);
161 ~StateRectangle_Context();
164 const etl::handle<CanvasView>& get_canvas_view()const{return canvas_view_;}
165 etl::handle<synfigapp::CanvasInterface> get_canvas_interface()const{return canvas_view_->canvas_interface();}
166 synfig::Canvas::Handle get_canvas()const{return canvas_view_->get_canvas();}
167 WorkArea * get_work_area()const{return canvas_view_->get_work_area();}
169 //Modifying settings etc.
170 void load_settings();
171 void save_settings();
174 bool egress_on_selection_change;
175 Smach::event_result event_layer_selection_changed_handler(const Smach::event& /*x*/)
177 if(egress_on_selection_change)
178 throw Smach::egress_exception();
179 return Smach::RESULT_OK;
182 void make_rectangle(const Point& p1, const Point& p2);
184 }; // END of class StateGradient_Context
186 /* === M E T H O D S ======================================================= */
188 StateRectangle::StateRectangle():
189 Smach::state<StateRectangle_Context>("rectangle")
191 insert(event_def(EVENT_STOP,&StateRectangle_Context::event_stop_handler));
192 insert(event_def(EVENT_LAYER_SELECTION_CHANGED,&StateRectangle_Context::event_layer_selection_changed_handler));
193 insert(event_def(EVENT_REFRESH,&StateRectangle_Context::event_refresh_handler));
194 insert(event_def(EVENT_REFRESH_DUCKS,&StateRectangle_Context::event_refresh_handler));
195 insert(event_def(EVENT_WORKAREA_MOUSE_BUTTON_DOWN,&StateRectangle_Context::event_mouse_click_handler));
196 insert(event_def(EVENT_WORKAREA_MOUSE_BUTTON_DRAG,&StateRectangle_Context::event_mouse_click_handler));
197 insert(event_def(EVENT_WORKAREA_MOUSE_BUTTON_UP,&StateRectangle_Context::event_mouse_click_handler));
198 insert(event_def(EVENT_REFRESH_TOOL_OPTIONS,&StateRectangle_Context::event_refresh_tool_options));
201 StateRectangle::~StateRectangle()
206 StateRectangle_Context::load_settings()
210 //parse the arguments yargh!
211 if(settings.get_value("rectangle.id",value))
216 if(settings.get_value("rectangle.expand",value))
217 set_expand(atof(value.c_str()));
221 if(settings.get_value("rectangle.feather",value))
222 set_feather(atof(value.c_str()));
226 if(settings.get_value("rectangle.invert",value) && value != "0")
231 if(settings.get_value("rectangle.layer_rectangle",value) && value=="0")
232 set_layer_rectangle_flag(false);
234 set_layer_rectangle_flag(true);
236 if(settings.get_value("rectangle.layer_region",value) && value=="1")
237 set_layer_region_flag(true);
239 set_layer_region_flag(false);
241 if(settings.get_value("rectangle.layer_outline",value) && value=="1")
242 set_layer_outline_flag(true);
244 set_layer_outline_flag(false);
246 if(settings.get_value("rectangle.layer_curve_gradient",value) && value=="1")
247 set_layer_curve_gradient_flag(true);
249 set_layer_curve_gradient_flag(false);
251 if(settings.get_value("rectangle.layer_plant",value) && value=="1")
252 set_layer_plant_flag(true);
254 set_layer_plant_flag(false);
256 if(settings.get_value("rectangle.layer_link_origins",value) && value=="0")
257 set_layer_link_origins_flag(false);
259 set_layer_link_origins_flag(true);
263 StateRectangle_Context::save_settings()
265 settings.set_value("rectangle.id",get_id().c_str());
266 settings.set_value("rectangle.expand",strprintf("%f",get_expand()));
267 settings.set_value("rectangle.feather",strprintf("%f",(float)get_feather()));
268 settings.set_value("rectangle.invert",get_invert()?"1":"0");
269 settings.set_value("rectangle.layer_rectangle",get_layer_rectangle_flag()?"1":"0");
270 settings.set_value("rectangle.layer_outline",get_layer_outline_flag()?"1":"0");
271 settings.set_value("rectangle.layer_region",get_layer_region_flag()?"1":"0");
272 settings.set_value("rectangle.layer_curve_gradient",get_layer_curve_gradient_flag()?"1":"0");
273 settings.set_value("rectangle.layer_plant",get_layer_plant_flag()?"1":"0");
274 settings.set_value("rectangle.layer_link_origins",get_layer_link_origins_flag()?"1":"0");
278 StateRectangle_Context::reset()
284 StateRectangle_Context::increment_id()
293 // If there is a number
294 // already at the end of the
295 // id, then remove it.
296 if(id[id.size()-1]<='9' && id[id.size()-1]>='0')
298 // figure out how many digits it is
300 (int)id.size()-1 >= digits && id[id.size()-1-digits] <= '9' && id[id.size()-1-digits] >= '0';
305 str_number=String(id,id.size()-digits,id.size());
306 id=String(id,0,id.size()-digits);
308 number=atoi(str_number.c_str());
318 // Add the number back onto the id
320 const String format(strprintf("%%0%dd",digits));
321 id+=strprintf(format.c_str(),number);
328 StateRectangle_Context::StateRectangle_Context(CanvasView* canvas_view):
329 canvas_view_(canvas_view),
330 is_working(*canvas_view),
331 duckmatic_push(get_work_area()),
332 prev_workarea_layer_status_(get_work_area()->get_allow_layer_clicks()),
333 settings(synfigapp::Main::get_selected_input_device()->settings()),
335 adj_expand(0,0,1,0.01,0.1),
336 adj_feather(0,0,1,0.01,0.1),
337 spin_expand(adj_expand,0.1,3),
338 spin_feather(adj_feather,0.1,3),
339 checkbutton_invert(_("Invert")),
340 checkbutton_layer_rectangle(_("Create Rectangle Layer")),
341 checkbutton_layer_region(_("Create Region BLine")),
342 checkbutton_layer_outline(_("Create Outline BLine")),
343 checkbutton_layer_curve_gradient(_("Create Curve Gradient BLine")),
344 checkbutton_layer_plant(_("Create Plant BLine")),
345 checkbutton_layer_link_origins(_("Link BLine Origins"))
347 egress_on_selection_change=true;
350 // Set up the tool options dialog
351 options_table.attach(*manage(new Gtk::Label(_("Rectangle Tool"))), 0, 2, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
352 options_table.attach(entry_id, 0, 2, 1, 2, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
355 options_table.attach(*manage(new Gtk::Label(_("Expansion:"))), 0, 1, 2, 3, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
356 options_table.attach(spin_expand, 1, 2, 2, 3, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
359 options_table.attach(*manage(new Gtk::Label(_("Feather:"))), 0, 1, 3, 4, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
360 options_table.attach(spin_feather, 1, 2, 3, 4, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
363 options_table.attach(checkbutton_invert, 1, 2, 4 , 5, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
365 options_table.attach(checkbutton_layer_rectangle, 0, 2, 7, 8, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
366 options_table.attach(checkbutton_layer_outline, 0, 2, 8, 9, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
367 options_table.attach(checkbutton_layer_region, 0, 2, 9, 10, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
368 options_table.attach(checkbutton_layer_plant, 0, 2, 10, 11, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
369 options_table.attach(checkbutton_layer_curve_gradient, 0, 2, 11, 12, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
370 options_table.attach(checkbutton_layer_link_origins, 0, 2, 12, 13, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
372 options_table.show_all();
374 //App::dialog_tool_options->set_widget(options_table);
375 refresh_tool_options();
376 App::dialog_tool_options->present();
378 // Turn off layer clicking
379 get_work_area()->set_allow_layer_clicks(false);
381 // clear out the ducks
382 get_work_area()->clear_ducks();
384 // Refresh the work area
385 get_work_area()->queue_draw();
387 get_canvas_view()->work_area->set_cursor(Gdk::CROSSHAIR);
389 // Hide the tables if they are showing
390 //prev_table_status=get_canvas_view()->tables_are_visible();
391 //if(prev_table_status)get_canvas_view()->hide_tables();
393 // Disable the time bar
394 //get_canvas_view()->set_sensitive_timebar(false);
397 //get_work_area()->signal_user_click().connect(sigc::mem_fun(*this,&studio::StateRectangle_Context::on_user_click));
399 App::toolbox->refresh();
403 StateRectangle_Context::refresh_tool_options()
405 App::dialog_tool_options->clear();
406 App::dialog_tool_options->set_widget(options_table);
407 App::dialog_tool_options->set_local_name(_("Rectangle Tool"));
408 App::dialog_tool_options->set_name("rectangle");
412 StateRectangle_Context::event_refresh_tool_options(const Smach::event& /*x*/)
414 refresh_tool_options();
415 return Smach::RESULT_ACCEPT;
418 StateRectangle_Context::~StateRectangle_Context()
422 // Restore layer clicking
423 get_work_area()->set_allow_layer_clicks(prev_workarea_layer_status_);
425 get_canvas_view()->work_area->reset_cursor();
427 App::dialog_tool_options->clear();
429 // Enable the time bar
430 //get_canvas_view()->set_sensitive_timebar(true);
432 // Bring back the tables if they were out before
433 //if(prev_table_status)get_canvas_view()->show_tables();
435 // Refresh the work area
436 get_work_area()->queue_draw();
438 get_canvas_view()->queue_rebuild_ducks();
440 App::toolbox->refresh();
444 StateRectangle_Context::event_stop_handler(const Smach::event& /*x*/)
446 throw Smach::egress_exception();
450 StateRectangle_Context::event_refresh_handler(const Smach::event& /*x*/)
453 return Smach::RESULT_ACCEPT;
457 StateRectangle_Context::make_rectangle(const Point& _p1, const Point& _p2)
459 synfigapp::Action::PassiveGrouper group(get_canvas_interface()->get_instance().get(),_("New Rectangle"));
460 synfigapp::PushMode push_mode(get_canvas_interface(),synfigapp::MODE_NORMAL);
464 Canvas::Handle canvas;
467 // we are temporarily using the layer to hold something
468 layer=get_canvas_view()->get_selection_manager()->get_selected_layer();
471 depth=layer->get_depth();
472 canvas=layer->get_canvas();
475 synfigapp::SelectionManager::LayerList layer_selection;
476 if (!getenv("SYNFIG_TOOLS_CLEAR_SELECTION"))
477 layer_selection = get_canvas_view()->get_selection_manager()->get_selected_layers();
479 const synfig::TransformStack& transform(get_canvas_view()->get_curr_transform_stack());
480 const Point p1(transform.unperform(_p1));
481 const Point p2(transform.unperform(_p2));
482 Real x_min, x_max, y_min, y_max;
483 if (p1[0] < p2[0]) { x_min = p1[0]; x_max = p2[0]; } else { x_min = p2[0]; x_max = p1[0]; }
484 if (p1[1] < p2[1]) { y_min = p1[1]; y_max = p2[1]; } else { y_min = p2[1]; y_max = p1[1]; }
485 x_min -= get_expand(); x_max += get_expand(); y_min -= get_expand(); y_max += get_expand();
487 std::vector<BLinePoint> new_list;
488 for (int i = 0; i < 4; i++)
490 new_list.push_back(*(new BLinePoint));
491 new_list[i].set_width(1);
492 new_list[i].set_vertex(Point((i==0||i==1)?x_min:x_max,
493 (i==0||i==3)?y_min:y_max));
494 new_list[i].set_tangent(Point(0,0));
497 ValueNode_BLine::Handle value_node_bline(ValueNode_BLine::create(new_list));
498 assert(value_node_bline);
500 ValueNode_Const::Handle value_node_origin(ValueNode_Const::create(Vector()));
501 assert(value_node_origin);
503 // Set the looping flag
504 value_node_bline->set_loop(true);
507 canvas=get_canvas_view()->get_canvas();
509 value_node_bline->set_member_canvas(canvas);
511 // count how many layers we're going to be creating
512 int layers_to_create = this->layers_to_create();
514 ///////////////////////////////////////////////////////////////////////////
516 ///////////////////////////////////////////////////////////////////////////
518 if (get_layer_rectangle_flag())
520 layer=get_canvas_interface()->add_layer_to("rectangle",canvas,depth);
521 layer_selection.push_back(layer);
523 layer->set_param("point1",p1);
524 get_canvas_interface()->signal_layer_param_changed()(layer,"point1");
526 layer->set_param("point2",p2);
527 get_canvas_interface()->signal_layer_param_changed()(layer,"point2");
529 layer->set_param("expand",get_expand());
530 get_canvas_interface()->signal_layer_param_changed()(layer,"expand");
532 layer->set_param("invert",get_invert());
533 get_canvas_interface()->signal_layer_param_changed()(layer,"invert");
535 layer->set_description(get_id());
536 get_canvas_interface()->signal_layer_new_description()(layer,layer->get_description());
538 if(get_layer_outline_flag())
540 layer->set_param("color",synfigapp::Main::get_background_color());
541 get_canvas_interface()->signal_layer_param_changed()(layer,"color");
545 ///////////////////////////////////////////////////////////////////////////
546 // C U R V E G R A D I E N T
547 ///////////////////////////////////////////////////////////////////////////
549 if(get_layer_curve_gradient_flag())
551 synfigapp::PushMode push_mode(get_canvas_interface(),synfigapp::MODE_NORMAL);
553 Layer::Handle layer(get_canvas_interface()->add_layer_to("curve_gradient",canvas,depth));
555 layer_selection.push_back(layer);
556 layer->set_description(get_id()+_(" Gradient"));
557 get_canvas_interface()->signal_layer_new_description()(layer,layer->get_description());
560 synfigapp::Action::Handle action(synfigapp::Action::create("layer_param_connect"));
563 action->set_param("canvas",get_canvas());
564 action->set_param("canvas_interface",get_canvas_interface());
565 action->set_param("layer",layer);
566 if(!action->set_param("param",String("bline")))
567 synfig::error("LayerParamConnect didn't like \"param\"");
568 if(!action->set_param("value_node",ValueNode::Handle(value_node_bline)))
569 synfig::error("LayerParamConnect didn't like \"value_node\"");
571 if(!get_canvas_interface()->get_instance()->perform_action(action))
573 //get_canvas_view()->get_ui_interface()->error(_("Unable to create BLine layer"));
575 throw String(_("Unable to create Gradient layer"));
580 // only link the curve gradient's origin parameter if the option is selected and we're creating more than one layer
581 if (get_layer_link_origins_flag() && layers_to_create > 1)
583 synfigapp::Action::Handle action(synfigapp::Action::create("layer_param_connect"));
586 action->set_param("canvas",get_canvas());
587 action->set_param("canvas_interface",get_canvas_interface());
588 action->set_param("layer",layer);
589 if(!action->set_param("param",String("origin")))
590 synfig::error("LayerParamConnect didn't like \"param\"");
591 if(!action->set_param("value_node",ValueNode::Handle(value_node_origin)))
592 synfig::error("LayerParamConnect didn't like \"value_node\"");
594 if(!get_canvas_interface()->get_instance()->perform_action(action))
596 //get_canvas_view()->get_ui_interface()->error(_("Unable to create BLine layer"));
598 throw String(_("Unable to create Gradient layer"));
604 ///////////////////////////////////////////////////////////////////////////
606 ///////////////////////////////////////////////////////////////////////////
608 if(get_layer_plant_flag())
610 synfigapp::PushMode push_mode(get_canvas_interface(),synfigapp::MODE_NORMAL);
612 Layer::Handle layer(get_canvas_interface()->add_layer_to("plant",canvas,depth));
614 layer_selection.push_back(layer);
615 layer->set_description(get_id()+_(" Plant"));
616 get_canvas_interface()->signal_layer_new_description()(layer,layer->get_description());
619 synfigapp::Action::Handle action(synfigapp::Action::create("layer_param_connect"));
622 action->set_param("canvas",get_canvas());
623 action->set_param("canvas_interface",get_canvas_interface());
624 action->set_param("layer",layer);
625 if(!action->set_param("param",String("bline")))
626 synfig::error("LayerParamConnect didn't like \"param\"");
627 if(!action->set_param("value_node",ValueNode::Handle(value_node_bline)))
628 synfig::error("LayerParamConnect didn't like \"value_node\"");
630 if(!get_canvas_interface()->get_instance()->perform_action(action))
632 //get_canvas_view()->get_ui_interface()->error(_("Unable to create BLine layer"));
634 throw String(_("Unable to create Plant layer"));
639 // only link the plant's origin parameter if the option is selected and we're creating more than one layer
640 if (get_layer_link_origins_flag() && layers_to_create > 1)
642 synfigapp::Action::Handle action(synfigapp::Action::create("layer_param_connect"));
645 action->set_param("canvas",get_canvas());
646 action->set_param("canvas_interface",get_canvas_interface());
647 action->set_param("layer",layer);
648 if(!action->set_param("param",String("origin")))
649 synfig::error("LayerParamConnect didn't like \"param\"");
650 if(!action->set_param("value_node",ValueNode::Handle(value_node_origin)))
651 synfig::error("LayerParamConnect didn't like \"value_node\"");
653 if(!get_canvas_interface()->get_instance()->perform_action(action))
655 //get_canvas_view()->get_ui_interface()->error(_("Unable to create BLine layer"));
657 throw String(_("Unable to create Plant layer"));
663 ///////////////////////////////////////////////////////////////////////////
665 ///////////////////////////////////////////////////////////////////////////
667 if(get_layer_region_flag())
669 synfigapp::PushMode push_mode(get_canvas_interface(),synfigapp::MODE_NORMAL);
671 Layer::Handle layer(get_canvas_interface()->add_layer_to("region",canvas,depth));
673 layer_selection.push_back(layer);
674 layer->set_description(get_id()+_(" Region"));
675 get_canvas_interface()->signal_layer_new_description()(layer,layer->get_description());
677 layer->set_param("feather",get_feather());
678 get_canvas_interface()->signal_layer_param_changed()(layer,"feather");
680 layer->set_param("invert",get_invert());
681 get_canvas_interface()->signal_layer_param_changed()(layer,"invert");
683 if(get_layer_outline_flag())
684 layer->set_param("color",synfigapp::Main::get_background_color());
686 // I don't know if it's safe to reuse the same layer_param_connect action, so I'm
687 // using 2 separate ones.
689 synfigapp::Action::Handle action(synfigapp::Action::create("layer_param_connect"));
692 action->set_param("canvas",get_canvas());
693 action->set_param("canvas_interface",get_canvas_interface());
694 action->set_param("layer",layer);
695 if(!action->set_param("param",String("bline")))
696 synfig::error("LayerParamConnect didn't like \"param\"");
697 if(!action->set_param("value_node",ValueNode::Handle(value_node_bline)))
698 synfig::error("LayerParamConnect didn't like \"value_node\"");
700 if(!get_canvas_interface()->get_instance()->perform_action(action))
702 //get_canvas_view()->get_ui_interface()->error(_("Unable to create Region layer"));
704 throw String(_("Unable to create Region layer"));
709 // only link the region's origin parameter if the option is selected and we're creating more than one layer
710 if (get_layer_link_origins_flag() && layers_to_create > 1)
712 synfigapp::Action::Handle action(synfigapp::Action::create("layer_param_connect"));
715 action->set_param("canvas",get_canvas());
716 action->set_param("canvas_interface",get_canvas_interface());
717 action->set_param("layer",layer);
718 if(!action->set_param("param",String("origin")))
719 synfig::error("LayerParamConnect didn't like \"param\"");
720 if(!action->set_param("value_node",ValueNode::Handle(value_node_origin)))
721 synfig::error("LayerParamConnect didn't like \"value_node\"");
723 if(!get_canvas_interface()->get_instance()->perform_action(action))
725 //get_canvas_view()->get_ui_interface()->error(_("Unable to create Region layer"));
727 throw String(_("Unable to create Region layer"));
733 ///////////////////////////////////////////////////////////////////////////
735 ///////////////////////////////////////////////////////////////////////////
737 if (get_layer_outline_flag())
739 Layer::Handle layer(get_canvas_interface()->add_layer_to("outline",canvas,depth));
741 layer_selection.push_back(layer);
742 layer->set_description(get_id()+_(" Outline"));
743 get_canvas_interface()->signal_layer_new_description()(layer,layer->get_description());
745 layer->set_param("feather",get_feather());
746 get_canvas_interface()->signal_layer_param_changed()(layer,"feather");
748 layer->set_param("invert",get_invert());
749 get_canvas_interface()->signal_layer_param_changed()(layer,"invert");
752 synfigapp::Action::Handle action(synfigapp::Action::create("layer_param_connect"));
755 action->set_param("canvas",get_canvas());
756 action->set_param("canvas_interface",get_canvas_interface());
757 action->set_param("layer",layer);
758 if(!action->set_param("param",String("bline")))
759 synfig::error("LayerParamConnect didn't like \"param\"");
760 if(!action->set_param("value_node",ValueNode::Handle(value_node_bline)))
761 synfig::error("LayerParamConnect didn't like \"value_node\"");
763 if(!get_canvas_interface()->get_instance()->perform_action(action))
765 //get_canvas_view()->get_ui_interface()->error(_("Unable to create BLine layer"));
767 throw String(_("Unable to create Outline layer"));
772 // only link the outline's origin parameter if the option is selected and we're creating more than one layer
773 if (get_layer_link_origins_flag() && layers_to_create > 1)
775 synfigapp::Action::Handle action(synfigapp::Action::create("layer_param_connect"));
778 action->set_param("canvas",get_canvas());
779 action->set_param("canvas_interface",get_canvas_interface());
780 action->set_param("layer",layer);
781 if(!action->set_param("param",String("origin")))
782 synfig::error("LayerParamConnect didn't like \"param\"");
783 if(!action->set_param("value_node",ValueNode::Handle(value_node_origin)))
784 synfig::error("LayerParamConnect didn't like \"value_node\"");
786 if(!get_canvas_interface()->get_instance()->perform_action(action))
788 //get_canvas_view()->get_ui_interface()->error(_("Unable to create BLine layer"));
790 throw String(_("Unable to create Outline layer"));
796 egress_on_selection_change=false;
797 get_canvas_interface()->get_selection_manager()->clear_selected_layers();
798 get_canvas_interface()->get_selection_manager()->set_selected_layers(layer_selection);
799 egress_on_selection_change=true;
801 //post clean up stuff...
807 StateRectangle_Context::event_mouse_click_handler(const Smach::event& x)
809 const EventMouse& event(*reinterpret_cast<const EventMouse*>(&x));
811 if(event.key==EVENT_WORKAREA_MOUSE_BUTTON_DOWN && event.button==BUTTON_LEFT)
813 point_holder=get_work_area()->snap_point_to_grid(event.pos);
814 etl::handle<Duck> duck=new Duck();
815 duck->set_point(point_holder);
816 duck->set_name("p1");
817 duck->set_type(Duck::TYPE_POSITION);
818 get_work_area()->add_duck(duck);
820 point2_duck=new Duck();
821 point2_duck->set_point(point_holder);
822 point2_duck->set_name("p2");
823 point2_duck->set_type(Duck::TYPE_POSITION);
824 point2_duck->set_box_duck(duck);
825 get_work_area()->add_duck(point2_duck);
827 return Smach::RESULT_ACCEPT;
830 if(event.key==EVENT_WORKAREA_MOUSE_BUTTON_DRAG && event.button==BUTTON_LEFT)
832 point2_duck->set_point(get_work_area()->snap_point_to_grid(event.pos));
833 get_work_area()->queue_draw();
834 return Smach::RESULT_ACCEPT;
837 if(event.key==EVENT_WORKAREA_MOUSE_BUTTON_UP && event.button==BUTTON_LEFT)
839 make_rectangle(point_holder, get_work_area()->snap_point_to_grid(event.pos));
840 get_work_area()->clear_ducks();
841 return Smach::RESULT_ACCEPT;
844 return Smach::RESULT_OK;
849 StateRectangle_Context::refresh_ducks()
851 get_work_area()->clear_ducks();
852 get_work_area()->queue_draw();