1 /* === S Y N F I G ========================================================= */
2 /*! \file state_circle.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_circle.h"
41 #include "canvasview.h"
45 #include <synfigapp/action.h>
46 #include "event_mouse.h"
47 #include "event_layerclick.h"
49 #include "dialog_tooloptions.h"
50 #include <gtkmm/optionmenu.h>
52 #include "widget_enum.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 ========================================================= */
70 CIRCLE_INTERPOLATION_LINEAR =1,
77 /* === G L O B A L S ======================================================= */
79 StateCircle studio::state_circle;
81 /* === C L A S S E S & S T R U C T S ======================================= */
83 class studio::StateCircle_Context : public sigc::trackable
85 etl::handle<CanvasView> canvas_view_;
86 CanvasView::IsWorking is_working;
88 Duckmatic::Push duckmatic_push;
92 etl::handle<Duck> point2_duck;
96 bool prev_workarea_layer_status_;
99 synfigapp::Settings& settings;
102 Gtk::Table options_table;
104 Gtk::Entry entry_id; //what to name the layer
106 Widget_Enum enum_falloff;
107 #ifdef BLEND_METHOD_IN_TOOL_OPTIONS
108 Widget_Enum enum_blend;
109 #endif // BLEND_METHOD_IN_TOOL_OPTIONS
111 Gtk::Adjustment adj_feather;
112 Gtk::Adjustment adj_number_of_bline_points;
113 Gtk::Adjustment adj_bline_point_angle_offset;
114 Gtk::SpinButton spin_feather;
115 Gtk::SpinButton spin_number_of_bline_points;
116 Gtk::SpinButton spin_bline_point_angle_offset;
118 Gtk::CheckButton checkbutton_invert;
119 Gtk::CheckButton checkbutton_layer_circle;
120 Gtk::CheckButton checkbutton_layer_region;
121 Gtk::CheckButton checkbutton_layer_outline;
122 Gtk::CheckButton checkbutton_layer_curve_gradient;
123 Gtk::CheckButton checkbutton_layer_plant;
124 Gtk::CheckButton checkbutton_layer_link_origins;
128 // this only counts the layers which use blines - they're the only
129 // ones we link the origins for
130 int layers_to_create()const
133 get_layer_region_flag() +
134 get_layer_outline_flag() +
135 get_layer_curve_gradient_flag() +
136 get_layer_plant_flag();
139 synfig::String get_id()const { return entry_id.get_text(); }
140 void set_id(const synfig::String& x) { return entry_id.set_text(x); }
142 int get_falloff()const { return enum_falloff.get_value(); }
143 void set_falloff(int x) { return enum_falloff.set_value(x); }
145 #ifdef BLEND_METHOD_IN_TOOL_OPTIONS
146 int get_blend()const { return enum_blend.get_value(); }
147 void set_blend(int x) { return enum_blend.set_value(x); }
148 #endif // BLEND_METHOD_IN_TOOL_OPTIONS
150 Real get_feather()const { return adj_feather.get_value(); }
151 void set_feather(Real f) { adj_feather.set_value(f); }
153 Real get_number_of_bline_points()const { return adj_number_of_bline_points.get_value(); }
154 void set_number_of_bline_points(Real f) { adj_number_of_bline_points.set_value(f); }
156 Real get_bline_point_angle_offset()const { return adj_bline_point_angle_offset.get_value(); }
157 void set_bline_point_angle_offset(Real f) { adj_bline_point_angle_offset.set_value(f); }
159 bool get_invert()const { return checkbutton_invert.get_active(); }
160 void set_invert(bool i) { checkbutton_invert.set_active(i); }
162 bool get_layer_circle_flag()const { return checkbutton_layer_circle.get_active(); }
163 void set_layer_circle_flag(bool x) { return checkbutton_layer_circle.set_active(x); }
165 bool get_layer_region_flag()const { return checkbutton_layer_region.get_active(); }
166 void set_layer_region_flag(bool x) { return checkbutton_layer_region.set_active(x); }
168 bool get_layer_outline_flag()const { return checkbutton_layer_outline.get_active(); }
169 void set_layer_outline_flag(bool x) { return checkbutton_layer_outline.set_active(x); }
171 bool get_layer_curve_gradient_flag()const { return checkbutton_layer_curve_gradient.get_active(); }
172 void set_layer_curve_gradient_flag(bool x) { return checkbutton_layer_curve_gradient.set_active(x); }
174 bool get_layer_plant_flag()const { return checkbutton_layer_plant.get_active(); }
175 void set_layer_plant_flag(bool x) { return checkbutton_layer_plant.set_active(x); }
177 bool get_layer_link_origins_flag()const { return checkbutton_layer_link_origins.get_active(); }
178 void set_layer_link_origins_flag(bool x) { return checkbutton_layer_link_origins.set_active(x); }
180 void refresh_tool_options(); //to refresh the toolbox
183 Smach::event_result event_stop_handler(const Smach::event& x);
184 Smach::event_result event_refresh_handler(const Smach::event& x);
185 Smach::event_result event_mouse_click_handler(const Smach::event& x);
186 Smach::event_result event_refresh_tool_options(const Smach::event& x);
188 //constructor destructor
189 StateCircle_Context(CanvasView* canvas_view);
190 ~StateCircle_Context();
193 const etl::handle<CanvasView>& get_canvas_view()const{return canvas_view_;}
194 etl::handle<synfigapp::CanvasInterface> get_canvas_interface()const{return canvas_view_->canvas_interface();}
195 synfig::Canvas::Handle get_canvas()const{return canvas_view_->get_canvas();}
196 WorkArea * get_work_area()const{return canvas_view_->get_work_area();}
198 //Modifying settings etc.
199 void load_settings();
200 void save_settings();
203 bool egress_on_selection_change;
204 Smach::event_result event_layer_selection_changed_handler(const Smach::event& /*x*/)
206 if(egress_on_selection_change)
207 throw Smach::egress_exception();
208 return Smach::RESULT_OK;
211 void make_circle(const Point& p1, const Point& p2);
213 }; // END of class StateCircle_Context
215 /* === M E T H O D S ======================================================= */
217 StateCircle::StateCircle():
218 Smach::state<StateCircle_Context>("circle")
220 insert(event_def(EVENT_LAYER_SELECTION_CHANGED,&StateCircle_Context::event_layer_selection_changed_handler));
221 insert(event_def(EVENT_STOP,&StateCircle_Context::event_stop_handler));
222 insert(event_def(EVENT_REFRESH,&StateCircle_Context::event_refresh_handler));
223 insert(event_def(EVENT_REFRESH_DUCKS,&StateCircle_Context::event_refresh_handler));
224 insert(event_def(EVENT_WORKAREA_MOUSE_BUTTON_DOWN,&StateCircle_Context::event_mouse_click_handler));
225 insert(event_def(EVENT_WORKAREA_MOUSE_BUTTON_DRAG,&StateCircle_Context::event_mouse_click_handler));
226 insert(event_def(EVENT_WORKAREA_MOUSE_BUTTON_UP,&StateCircle_Context::event_mouse_click_handler));
227 insert(event_def(EVENT_REFRESH_TOOL_OPTIONS,&StateCircle_Context::event_refresh_tool_options));
230 StateCircle::~StateCircle()
235 StateCircle_Context::load_settings()
239 //parse the arguments yargh!
240 if(settings.get_value("circle.id",value))
245 if(settings.get_value("circle.fallofftype",value) && value != "")
246 set_falloff(atoi(value.c_str()));
250 #ifdef BLEND_METHOD_IN_TOOL_OPTIONS
251 if(settings.get_value("circle.blend",value) && value != "")
252 set_blend(atoi(value.c_str()));
254 set_blend(0);//(int)Color::BLEND_COMPOSITE); //0 should be blend composites value
255 #endif // BLEND_METHOD_IN_TOOL_OPTIONS
257 if(settings.get_value("circle.feather",value))
258 set_feather(atof(value.c_str()));
262 if(settings.get_value("circle.number_of_bline_points",value))
263 set_number_of_bline_points(atof(value.c_str()));
265 set_number_of_bline_points(4);
267 if(settings.get_value("circle.bline_point_angle_offset",value))
268 set_bline_point_angle_offset(atof(value.c_str()));
270 set_bline_point_angle_offset(0);
272 if(settings.get_value("circle.invert",value) && value != "0")
277 if(settings.get_value("circle.layer_circle",value) && value=="0")
278 set_layer_circle_flag(false);
280 set_layer_circle_flag(true);
282 if(settings.get_value("circle.layer_region",value) && value=="1")
283 set_layer_region_flag(true);
285 set_layer_region_flag(false);
287 if(settings.get_value("circle.layer_outline",value) && value=="1")
288 set_layer_outline_flag(true);
290 set_layer_outline_flag(false);
292 if(settings.get_value("circle.layer_curve_gradient",value) && value=="1")
293 set_layer_curve_gradient_flag(true);
295 set_layer_curve_gradient_flag(false);
297 if(settings.get_value("circle.layer_plant",value) && value=="1")
298 set_layer_plant_flag(true);
300 set_layer_plant_flag(false);
302 if(settings.get_value("circle.layer_link_origins",value) && value=="0")
303 set_layer_link_origins_flag(false);
305 set_layer_link_origins_flag(true);
309 StateCircle_Context::save_settings()
311 settings.set_value("circle.id",get_id());
312 settings.set_value("circle.fallofftype",strprintf("%d",get_falloff()));
313 #ifdef BLEND_METHOD_IN_TOOL_OPTIONS
314 settings.set_value("circle.blend",strprintf("%d",get_blend()));
315 #endif // BLEND_METHOD_IN_TOOL_OPTIONS
316 settings.set_value("circle.feather",strprintf("%f",(float)get_feather()));
317 settings.set_value("circle.number_of_bline_points",strprintf("%d",(int)(get_number_of_bline_points() + 0.5)));
318 settings.set_value("circle.bline_point_angle_offset",strprintf("%f",(float)get_bline_point_angle_offset()));
319 settings.set_value("circle.invert",get_invert()?"1":"0");
320 settings.set_value("circle.layer_circle",get_layer_circle_flag()?"1":"0");
321 settings.set_value("circle.layer_outline",get_layer_outline_flag()?"1":"0");
322 settings.set_value("circle.layer_region",get_layer_region_flag()?"1":"0");
323 settings.set_value("circle.layer_curve_gradient",get_layer_curve_gradient_flag()?"1":"0");
324 settings.set_value("circle.layer_plant",get_layer_plant_flag()?"1":"0");
325 settings.set_value("circle.layer_link_origins",get_layer_link_origins_flag()?"1":"0");
329 StateCircle_Context::reset()
335 StateCircle_Context::increment_id()
344 // If there is a number
345 // already at the end of the
346 // id, then remove it.
347 if(id[id.size()-1]<='9' && id[id.size()-1]>='0')
349 // figure out how many digits it is
351 (int)id.size()-1 >= digits && id[id.size()-1-digits] <= '9' && id[id.size()-1-digits] >= '0';
356 str_number=String(id,id.size()-digits,id.size());
357 id=String(id,0,id.size()-digits);
359 number=atoi(str_number.c_str());
369 // Add the number back onto the id
371 const String format(strprintf("%%0%dd",digits));
372 id+=strprintf(format.c_str(),number);
379 StateCircle_Context::StateCircle_Context(CanvasView* canvas_view):
380 canvas_view_(canvas_view),
381 is_working(*canvas_view),
382 duckmatic_push(get_work_area()),
383 prev_workarea_layer_status_(get_work_area()->get_allow_layer_clicks()),
384 settings(synfigapp::Main::get_selected_input_device()->settings()),
385 entry_id(), // value lower upper step page
386 adj_feather( 0, 0, 1, 0.01, 0.1),
387 adj_number_of_bline_points( 0, 2, 120, 1 , 1 ),
388 adj_bline_point_angle_offset( 0, -360, 360, 0.1 , 1 ),
389 spin_feather(adj_feather,0.1,3),
390 spin_number_of_bline_points(adj_number_of_bline_points,1,0),
391 spin_bline_point_angle_offset(adj_bline_point_angle_offset,1,1),
392 checkbutton_invert(_("Invert")),
393 checkbutton_layer_circle(_("Create Circle Layer")),
394 checkbutton_layer_region(_("Create Region BLine")),
395 checkbutton_layer_outline(_("Create Outline BLine")),
396 checkbutton_layer_curve_gradient(_("Create Curve Gradient BLine")),
397 checkbutton_layer_plant(_("Create Plant BLine")),
398 checkbutton_layer_link_origins(_("Link BLine Origins"))
400 egress_on_selection_change=true;
401 // Set up the tool options dialog
402 options_table.attach(*manage(new Gtk::Label(_("Circle Tool"))), 0, 2, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
403 options_table.attach(entry_id, 0, 2, 1, 2, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
405 enum_falloff.set_param_desc(ParamDesc("falloff")
406 .set_local_name(_("Falloff"))
407 .set_description(_("Determines the falloff function for the feather"))
409 .add_enum_value(CIRCLE_INTERPOLATION_LINEAR,"linear",_("Linear"))
410 .add_enum_value(CIRCLE_SQUARED,"squared",_("Squared"))
411 .add_enum_value(CIRCLE_SQRT,"sqrt",_("Square Root"))
412 .add_enum_value(CIRCLE_SIGMOND,"sigmond",_("Sigmond"))
413 .add_enum_value(CIRCLE_COSINE,"cosine",_("Cosine")));
415 #ifdef BLEND_METHOD_IN_TOOL_OPTIONS
416 enum_blend.set_param_desc(ParamDesc(Color::BLEND_COMPOSITE,"blend_method")
417 .set_local_name(_("Blend Method"))
418 .set_description(_("Defines the blend method to be used for circles")));
419 #endif // BLEND_METHOD_IN_TOOL_OPTIONS
424 options_table.attach(*manage(new Gtk::Label(_("Feather:"))), 0, 1, 2, 3, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
425 options_table.attach(spin_feather, 1, 2, 2, 3, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
426 options_table.attach(enum_falloff, 0, 2, 4, 5, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
427 #ifdef BLEND_METHOD_IN_TOOL_OPTIONS
428 options_table.attach(enum_blend, 0, 2, 5, 6, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
429 #endif // BLEND_METHOD_IN_TOOL_OPTIONS
430 options_table.attach(checkbutton_invert, 0, 2, 6, 7, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
431 options_table.attach(checkbutton_layer_circle, 0, 2, 7, 8, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
432 options_table.attach(checkbutton_layer_outline, 0, 2, 8, 9, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
433 options_table.attach(checkbutton_layer_region, 0, 2, 9, 10, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
434 options_table.attach(checkbutton_layer_plant, 0, 2, 10, 11, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
435 options_table.attach(checkbutton_layer_curve_gradient, 0, 2, 11, 12, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
436 options_table.attach(checkbutton_layer_link_origins, 0, 2, 12, 13, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
437 options_table.attach(*manage(new Gtk::Label(_("BLine Points:"))), 0, 1, 13, 14, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
438 options_table.attach(spin_number_of_bline_points, 1, 2, 13, 14, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
439 options_table.attach(*manage(new Gtk::Label(_("Point Angle Offset:"))), 0, 1, 14, 15, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
440 options_table.attach(spin_bline_point_angle_offset, 1, 2, 14, 15, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
442 options_table.show_all();
444 refresh_tool_options();
445 App::dialog_tool_options->present();
447 // Turn off layer clicking
448 get_work_area()->set_allow_layer_clicks(false);
450 // clear out the ducks
451 get_work_area()->clear_ducks();
453 // Refresh the work area
454 get_work_area()->queue_draw();
456 // Hide the tables if they are showing
457 //prev_table_status=get_canvas_view()->tables_are_visible();
458 //if(prev_table_status)get_canvas_view()->hide_tables();
460 // Disable the time bar
461 //get_canvas_view()->set_sensitive_timebar(false);
464 //get_work_area()->signal_user_click().connect(sigc::mem_fun(*this,&studio::StateCircle_Context::on_user_click));
465 get_canvas_view()->work_area->set_cursor(Gdk::CROSSHAIR);
467 App::toolbox->refresh();
471 StateCircle_Context::refresh_tool_options()
473 App::dialog_tool_options->clear();
474 App::dialog_tool_options->set_widget(options_table);
475 App::dialog_tool_options->set_local_name(_("Circle Tool"));
476 App::dialog_tool_options->set_name("circle");
480 StateCircle_Context::event_refresh_tool_options(const Smach::event& /*x*/)
482 refresh_tool_options();
483 return Smach::RESULT_ACCEPT;
486 StateCircle_Context::~StateCircle_Context()
490 // Restore layer clicking
491 get_work_area()->set_allow_layer_clicks(prev_workarea_layer_status_);
492 get_canvas_view()->work_area->reset_cursor();
494 App::dialog_tool_options->clear();
496 // Enable the time bar
497 //get_canvas_view()->set_sensitive_timebar(true);
499 // Bring back the tables if they were out before
500 //if(prev_table_status)get_canvas_view()->show_tables();
502 // Refresh the work area
503 get_work_area()->queue_draw();
505 get_canvas_view()->queue_rebuild_ducks();
507 App::toolbox->refresh();
511 StateCircle_Context::event_stop_handler(const Smach::event& /*x*/)
513 throw Smach::egress_exception();
517 StateCircle_Context::event_refresh_handler(const Smach::event& /*x*/)
520 return Smach::RESULT_ACCEPT;
524 StateCircle_Context::make_circle(const Point& _p1, const Point& _p2)
526 synfigapp::Action::PassiveGrouper group(get_canvas_interface()->get_instance().get(),_("New Circle"));
527 synfigapp::PushMode push_mode(get_canvas_interface(),synfigapp::MODE_NORMAL);
531 Canvas::Handle canvas;
534 // we are temporarily using the layer to hold something
535 layer=get_canvas_view()->get_selection_manager()->get_selected_layer();
538 depth=layer->get_depth();
539 canvas=layer->get_canvas();
542 synfigapp::SelectionManager::LayerList layer_selection;
543 if (!getenv("SYNFIG_TOOLS_CLEAR_SELECTION"))
544 layer_selection = get_canvas_view()->get_selection_manager()->get_selected_layers();
546 const synfig::TransformStack& transform(get_canvas_view()->get_curr_transform_stack());
547 const Point p1(transform.unperform(_p1));
548 const Point p2(transform.unperform(_p2));
550 Real radius((p2-p1).mag());
551 int points = get_number_of_bline_points();
552 Angle::deg offset(get_bline_point_angle_offset());
553 Angle::deg angle(360.0/points);
554 Real tangent(4 * ((points == 2)
556 : ((2 * Angle::cos(angle/2).get() - Angle::cos(angle).get() - 1) / Angle::sin(angle).get())));
557 Real x(p1[0]), y(p1[1]);
559 std::vector<BLinePoint> new_list;
560 for (int i = 0; i < points; i++)
562 new_list.push_back(*(new BLinePoint));
563 new_list[i].set_width(1);
564 new_list[i].set_vertex(Point(radius*Angle::cos(angle*i + offset).get() + x,
565 radius*Angle::sin(angle*i + offset).get() + y));
566 new_list[i].set_tangent(Point(-radius*tangent*Angle::sin(angle*i + offset).get(),
567 radius*tangent*Angle::cos(angle*i + offset).get()));
570 ValueNode_BLine::Handle value_node_bline(ValueNode_BLine::create(new_list));
571 assert(value_node_bline);
573 ValueNode_Const::Handle value_node_origin(ValueNode_Const::create(Vector()));
574 assert(value_node_origin);
576 // Set the looping flag
577 value_node_bline->set_loop(true);
580 canvas=get_canvas_view()->get_canvas();
582 value_node_bline->set_member_canvas(canvas);
584 // count how many layers we're going to be creating
585 int layers_to_create = this->layers_to_create();
587 ///////////////////////////////////////////////////////////////////////////
589 ///////////////////////////////////////////////////////////////////////////
591 if (get_layer_circle_flag() &&
592 get_falloff() >= 0 && get_falloff() < CIRCLE_NUM_FALLOFF)
594 layer=get_canvas_interface()->add_layer_to("circle",canvas,depth);
595 layer_selection.push_back(layer);
597 layer->set_param("origin",p1);
598 get_canvas_interface()->signal_layer_param_changed()(layer,"origin");
600 layer->set_param("radius",(p2-p1).mag());
601 get_canvas_interface()->signal_layer_param_changed()(layer,"radius");
603 layer->set_param("falloff",get_falloff());
604 get_canvas_interface()->signal_layer_param_changed()(layer,"falloff");
606 layer->set_param("feather",get_feather());
607 get_canvas_interface()->signal_layer_param_changed()(layer,"feather");
609 layer->set_param("invert",get_invert());
610 get_canvas_interface()->signal_layer_param_changed()(layer,"invert");
612 #ifdef BLEND_METHOD_IN_TOOL_OPTIONS
613 layer->set_param("blend_method",get_blend());
614 get_canvas_interface()->signal_layer_param_changed()(layer,"blend_method");
615 #endif // BLEND_METHOD_IN_TOOL_OPTIONS
617 layer->set_description(get_id());
618 get_canvas_interface()->signal_layer_new_description()(layer,layer->get_description());
620 if(get_layer_outline_flag())
622 layer->set_param("color",synfigapp::Main::get_background_color());
623 get_canvas_interface()->signal_layer_param_changed()(layer,"color");
627 ///////////////////////////////////////////////////////////////////////////
628 // C U R V E G R A D I E N T
629 ///////////////////////////////////////////////////////////////////////////
631 if(get_layer_curve_gradient_flag())
633 synfigapp::PushMode push_mode(get_canvas_interface(),synfigapp::MODE_NORMAL);
635 Layer::Handle layer(get_canvas_interface()->add_layer_to("curve_gradient",canvas,depth));
637 layer_selection.push_back(layer);
638 layer->set_description(get_id()+_(" Gradient"));
639 get_canvas_interface()->signal_layer_new_description()(layer,layer->get_description());
641 #ifdef BLEND_METHOD_IN_TOOL_OPTIONS
642 layer->set_param("blend_method",get_blend());
643 get_canvas_interface()->signal_layer_param_changed()(layer,"blend_method");
644 #endif // BLEND_METHOD_IN_TOOL_OPTIONS
647 synfigapp::Action::Handle action(synfigapp::Action::create("layer_param_connect"));
650 action->set_param("canvas",get_canvas());
651 action->set_param("canvas_interface",get_canvas_interface());
652 action->set_param("layer",layer);
653 if(!action->set_param("param",String("bline")))
654 synfig::error("LayerParamConnect didn't like \"param\"");
655 if(!action->set_param("value_node",ValueNode::Handle(value_node_bline)))
656 synfig::error("LayerParamConnect didn't like \"value_node\"");
658 if(!get_canvas_interface()->get_instance()->perform_action(action))
660 //get_canvas_view()->get_ui_interface()->error(_("Unable to create BLine layer"));
662 throw String(_("Unable to create Gradient layer"));
667 // only link the curve gradient's origin parameter if the option is selected and we're creating more than one layer
668 if (get_layer_link_origins_flag() && layers_to_create > 1)
670 synfigapp::Action::Handle action(synfigapp::Action::create("layer_param_connect"));
673 action->set_param("canvas",get_canvas());
674 action->set_param("canvas_interface",get_canvas_interface());
675 action->set_param("layer",layer);
676 if(!action->set_param("param",String("origin")))
677 synfig::error("LayerParamConnect didn't like \"param\"");
678 if(!action->set_param("value_node",ValueNode::Handle(value_node_origin)))
679 synfig::error("LayerParamConnect didn't like \"value_node\"");
681 if(!get_canvas_interface()->get_instance()->perform_action(action))
683 //get_canvas_view()->get_ui_interface()->error(_("Unable to create BLine layer"));
685 throw String(_("Unable to create Gradient layer"));
691 ///////////////////////////////////////////////////////////////////////////
693 ///////////////////////////////////////////////////////////////////////////
695 if(get_layer_plant_flag())
697 synfigapp::PushMode push_mode(get_canvas_interface(),synfigapp::MODE_NORMAL);
699 Layer::Handle layer(get_canvas_interface()->add_layer_to("plant",canvas,depth));
701 layer_selection.push_back(layer);
702 layer->set_description(get_id()+_(" Plant"));
703 get_canvas_interface()->signal_layer_new_description()(layer,layer->get_description());
705 #ifdef BLEND_METHOD_IN_TOOL_OPTIONS
706 layer->set_param("blend_method",get_blend());
707 get_canvas_interface()->signal_layer_param_changed()(layer,"blend_method");
708 #endif // BLEND_METHOD_IN_TOOL_OPTIONS
711 synfigapp::Action::Handle action(synfigapp::Action::create("layer_param_connect"));
714 action->set_param("canvas",get_canvas());
715 action->set_param("canvas_interface",get_canvas_interface());
716 action->set_param("layer",layer);
717 if(!action->set_param("param",String("bline")))
718 synfig::error("LayerParamConnect didn't like \"param\"");
719 if(!action->set_param("value_node",ValueNode::Handle(value_node_bline)))
720 synfig::error("LayerParamConnect didn't like \"value_node\"");
722 if(!get_canvas_interface()->get_instance()->perform_action(action))
724 //get_canvas_view()->get_ui_interface()->error(_("Unable to create BLine layer"));
726 throw String(_("Unable to create Plant layer"));
731 // only link the plant's origin parameter if the option is selected and we're creating more than one layer
732 if (get_layer_link_origins_flag() && layers_to_create > 1)
734 synfigapp::Action::Handle action(synfigapp::Action::create("layer_param_connect"));
737 action->set_param("canvas",get_canvas());
738 action->set_param("canvas_interface",get_canvas_interface());
739 action->set_param("layer",layer);
740 if(!action->set_param("param",String("origin")))
741 synfig::error("LayerParamConnect didn't like \"param\"");
742 if(!action->set_param("value_node",ValueNode::Handle(value_node_origin)))
743 synfig::error("LayerParamConnect didn't like \"value_node\"");
745 if(!get_canvas_interface()->get_instance()->perform_action(action))
747 //get_canvas_view()->get_ui_interface()->error(_("Unable to create BLine layer"));
749 throw String(_("Unable to create Plant layer"));
755 ///////////////////////////////////////////////////////////////////////////
757 ///////////////////////////////////////////////////////////////////////////
759 if(get_layer_region_flag())
761 synfigapp::PushMode push_mode(get_canvas_interface(),synfigapp::MODE_NORMAL);
763 Layer::Handle layer(get_canvas_interface()->add_layer_to("region",canvas,depth));
765 layer_selection.push_back(layer);
766 layer->set_description(get_id()+_(" Region"));
767 get_canvas_interface()->signal_layer_new_description()(layer,layer->get_description());
769 #ifdef BLEND_METHOD_IN_TOOL_OPTIONS
770 layer->set_param("blend_method",get_blend());
771 get_canvas_interface()->signal_layer_param_changed()(layer,"blend_method");
772 #endif // BLEND_METHOD_IN_TOOL_OPTIONS
774 layer->set_param("feather",get_feather());
775 get_canvas_interface()->signal_layer_param_changed()(layer,"feather");
777 layer->set_param("invert",get_invert());
778 get_canvas_interface()->signal_layer_param_changed()(layer,"invert");
780 if(get_layer_outline_flag())
781 layer->set_param("color",synfigapp::Main::get_background_color());
783 // I don't know if it's safe to reuse the same layer_param_connect action, so I'm
784 // using 2 separate ones.
786 synfigapp::Action::Handle action(synfigapp::Action::create("layer_param_connect"));
789 action->set_param("canvas",get_canvas());
790 action->set_param("canvas_interface",get_canvas_interface());
791 action->set_param("layer",layer);
792 if(!action->set_param("param",String("bline")))
793 synfig::error("LayerParamConnect didn't like \"param\"");
794 if(!action->set_param("value_node",ValueNode::Handle(value_node_bline)))
795 synfig::error("LayerParamConnect didn't like \"value_node\"");
797 if(!get_canvas_interface()->get_instance()->perform_action(action))
799 //get_canvas_view()->get_ui_interface()->error(_("Unable to create Region layer"));
801 throw String(_("Unable to create Region layer"));
806 // only link the region's origin parameter if the option is selected and we're creating more than one layer
807 if (get_layer_link_origins_flag() && layers_to_create > 1)
809 synfigapp::Action::Handle action(synfigapp::Action::create("layer_param_connect"));
812 action->set_param("canvas",get_canvas());
813 action->set_param("canvas_interface",get_canvas_interface());
814 action->set_param("layer",layer);
815 if(!action->set_param("param",String("origin")))
816 synfig::error("LayerParamConnect didn't like \"param\"");
817 if(!action->set_param("value_node",ValueNode::Handle(value_node_origin)))
818 synfig::error("LayerParamConnect didn't like \"value_node\"");
820 if(!get_canvas_interface()->get_instance()->perform_action(action))
822 //get_canvas_view()->get_ui_interface()->error(_("Unable to create Region layer"));
824 throw String(_("Unable to create Region layer"));
830 ///////////////////////////////////////////////////////////////////////////
832 ///////////////////////////////////////////////////////////////////////////
834 if (get_layer_outline_flag())
836 Layer::Handle layer(get_canvas_interface()->add_layer_to("outline",canvas,depth));
838 layer_selection.push_back(layer);
839 layer->set_description(get_id()+_(" Outline"));
840 get_canvas_interface()->signal_layer_new_description()(layer,layer->get_description());
842 #ifdef BLEND_METHOD_IN_TOOL_OPTIONS
843 layer->set_param("blend_method",get_blend());
844 get_canvas_interface()->signal_layer_param_changed()(layer,"blend_method");
845 #endif // BLEND_METHOD_IN_TOOL_OPTIONS
847 layer->set_param("feather",get_feather());
848 get_canvas_interface()->signal_layer_param_changed()(layer,"feather");
850 layer->set_param("invert",get_invert());
851 get_canvas_interface()->signal_layer_param_changed()(layer,"invert");
854 synfigapp::Action::Handle action(synfigapp::Action::create("layer_param_connect"));
857 action->set_param("canvas",get_canvas());
858 action->set_param("canvas_interface",get_canvas_interface());
859 action->set_param("layer",layer);
860 if(!action->set_param("param",String("bline")))
861 synfig::error("LayerParamConnect didn't like \"param\"");
862 if(!action->set_param("value_node",ValueNode::Handle(value_node_bline)))
863 synfig::error("LayerParamConnect didn't like \"value_node\"");
865 if(!get_canvas_interface()->get_instance()->perform_action(action))
867 //get_canvas_view()->get_ui_interface()->error(_("Unable to create BLine layer"));
869 throw String(_("Unable to create Outline layer"));
874 // only link the outline's origin parameter if the option is selected and we're creating more than one layer
875 if (get_layer_link_origins_flag() && layers_to_create > 1)
877 synfigapp::Action::Handle action(synfigapp::Action::create("layer_param_connect"));
880 action->set_param("canvas",get_canvas());
881 action->set_param("canvas_interface",get_canvas_interface());
882 action->set_param("layer",layer);
883 if(!action->set_param("param",String("origin")))
884 synfig::error("LayerParamConnect didn't like \"param\"");
885 if(!action->set_param("value_node",ValueNode::Handle(value_node_origin)))
886 synfig::error("LayerParamConnect didn't like \"value_node\"");
888 if(!get_canvas_interface()->get_instance()->perform_action(action))
890 //get_canvas_view()->get_ui_interface()->error(_("Unable to create BLine layer"));
892 throw String(_("Unable to create Outline layer"));
898 egress_on_selection_change=false;
899 get_canvas_interface()->get_selection_manager()->clear_selected_layers();
900 get_canvas_interface()->get_selection_manager()->set_selected_layers(layer_selection);
901 egress_on_selection_change=true;
908 StateCircle_Context::event_mouse_click_handler(const Smach::event& x)
910 const EventMouse& event(*reinterpret_cast<const EventMouse*>(&x));
912 if(event.key==EVENT_WORKAREA_MOUSE_BUTTON_DOWN && event.button==BUTTON_LEFT)
914 point_holder=get_work_area()->snap_point_to_grid(event.pos);
915 etl::handle<Duck> duck=new Duck();
916 duck->set_point(point_holder);
917 duck->set_name("p1");
918 duck->set_type(Duck::TYPE_POSITION);
919 duck->set_editable(false);
920 get_work_area()->add_duck(duck);
922 point2_duck=new Duck();
923 point2_duck->set_point(Vector(0,0));
924 point2_duck->set_name("radius");
925 point2_duck->set_origin(duck);
926 point2_duck->set_radius(true);
927 point2_duck->set_scalar(-1);
928 point2_duck->set_type(Duck::TYPE_RADIUS);
929 point2_duck->set_hover(true);
930 get_work_area()->add_duck(point2_duck);
932 return Smach::RESULT_ACCEPT;
935 if(event.key==EVENT_WORKAREA_MOUSE_BUTTON_DRAG && event.button==BUTTON_LEFT)
937 if (!point2_duck) return Smach::RESULT_OK;
938 point2_duck->set_point(point_holder-get_work_area()->snap_point_to_grid(event.pos));
939 get_work_area()->queue_draw();
940 return Smach::RESULT_ACCEPT;
943 if(event.key==EVENT_WORKAREA_MOUSE_BUTTON_UP && event.button==BUTTON_LEFT)
945 Point point(get_work_area()->snap_point_to_grid(event.pos));
947 if (App::restrict_radius_ducks)
949 if ((point[0] - point_holder[0]) < 0) point[0] = point_holder[0];
950 if ((point[1] - point_holder[1]) < 0) point[1] = point_holder[1];
953 make_circle(point_holder, point);
954 get_work_area()->clear_ducks();
955 return Smach::RESULT_ACCEPT;
958 return Smach::RESULT_OK;
963 StateCircle_Context::refresh_ducks()
965 get_work_area()->clear_ducks();
966 get_work_area()->queue_draw();