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;
125 Gtk::CheckButton checkbutton_layer_origins_at_center;
129 // this only counts the layers which will have their origins linked
130 int layers_to_create()const
133 (get_layer_circle_flag() && get_layer_origins_at_center_flag()) +
134 get_layer_region_flag() +
135 get_layer_outline_flag() +
136 get_layer_curve_gradient_flag() +
137 get_layer_plant_flag();
140 synfig::String get_id()const { return entry_id.get_text(); }
141 void set_id(const synfig::String& x) { return entry_id.set_text(x); }
143 int get_falloff()const { return enum_falloff.get_value(); }
144 void set_falloff(int x) { return enum_falloff.set_value(x); }
146 #ifdef BLEND_METHOD_IN_TOOL_OPTIONS
147 int get_blend()const { return enum_blend.get_value(); }
148 void set_blend(int x) { return enum_blend.set_value(x); }
149 #endif // BLEND_METHOD_IN_TOOL_OPTIONS
151 Real get_feather()const { return adj_feather.get_value(); }
152 void set_feather(Real f) { adj_feather.set_value(f); }
154 Real get_number_of_bline_points()const { return adj_number_of_bline_points.get_value(); }
155 void set_number_of_bline_points(Real f) { adj_number_of_bline_points.set_value(f); }
157 Real get_bline_point_angle_offset()const { return adj_bline_point_angle_offset.get_value(); }
158 void set_bline_point_angle_offset(Real f) { adj_bline_point_angle_offset.set_value(f); }
160 bool get_invert()const { return checkbutton_invert.get_active(); }
161 void set_invert(bool i) { checkbutton_invert.set_active(i); }
163 bool get_layer_circle_flag()const { return checkbutton_layer_circle.get_active(); }
164 void set_layer_circle_flag(bool x) { return checkbutton_layer_circle.set_active(x); }
166 bool get_layer_region_flag()const { return checkbutton_layer_region.get_active(); }
167 void set_layer_region_flag(bool x) { return checkbutton_layer_region.set_active(x); }
169 bool get_layer_outline_flag()const { return checkbutton_layer_outline.get_active(); }
170 void set_layer_outline_flag(bool x) { return checkbutton_layer_outline.set_active(x); }
172 bool get_layer_curve_gradient_flag()const { return checkbutton_layer_curve_gradient.get_active(); }
173 void set_layer_curve_gradient_flag(bool x) { return checkbutton_layer_curve_gradient.set_active(x); }
175 bool get_layer_plant_flag()const { return checkbutton_layer_plant.get_active(); }
176 void set_layer_plant_flag(bool x) { return checkbutton_layer_plant.set_active(x); }
178 bool get_layer_link_origins_flag()const { return checkbutton_layer_link_origins.get_active(); }
179 void set_layer_link_origins_flag(bool x) { return checkbutton_layer_link_origins.set_active(x); }
181 bool get_layer_origins_at_center_flag()const { return checkbutton_layer_origins_at_center.get_active(); }
182 void set_layer_origins_at_center_flag(bool x) { return checkbutton_layer_origins_at_center.set_active(x); }
184 void refresh_tool_options(); //to refresh the toolbox
187 Smach::event_result event_stop_handler(const Smach::event& x);
188 Smach::event_result event_refresh_handler(const Smach::event& x);
189 Smach::event_result event_mouse_click_handler(const Smach::event& x);
190 Smach::event_result event_refresh_tool_options(const Smach::event& x);
192 //constructor destructor
193 StateCircle_Context(CanvasView* canvas_view);
194 ~StateCircle_Context();
197 const etl::handle<CanvasView>& get_canvas_view()const{return canvas_view_;}
198 etl::handle<synfigapp::CanvasInterface> get_canvas_interface()const{return canvas_view_->canvas_interface();}
199 synfig::Canvas::Handle get_canvas()const{return canvas_view_->get_canvas();}
200 WorkArea * get_work_area()const{return canvas_view_->get_work_area();}
202 //Modifying settings etc.
203 void load_settings();
204 void save_settings();
207 bool egress_on_selection_change;
208 Smach::event_result event_layer_selection_changed_handler(const Smach::event& /*x*/)
210 if(egress_on_selection_change)
211 throw Smach::egress_exception();
212 return Smach::RESULT_OK;
215 void make_circle(const Point& p1, const Point& p2);
217 }; // END of class StateCircle_Context
219 /* === M E T H O D S ======================================================= */
221 StateCircle::StateCircle():
222 Smach::state<StateCircle_Context>("circle")
224 insert(event_def(EVENT_LAYER_SELECTION_CHANGED,&StateCircle_Context::event_layer_selection_changed_handler));
225 insert(event_def(EVENT_STOP,&StateCircle_Context::event_stop_handler));
226 insert(event_def(EVENT_REFRESH,&StateCircle_Context::event_refresh_handler));
227 insert(event_def(EVENT_REFRESH_DUCKS,&StateCircle_Context::event_refresh_handler));
228 insert(event_def(EVENT_WORKAREA_MOUSE_BUTTON_DOWN,&StateCircle_Context::event_mouse_click_handler));
229 insert(event_def(EVENT_WORKAREA_MOUSE_BUTTON_DRAG,&StateCircle_Context::event_mouse_click_handler));
230 insert(event_def(EVENT_WORKAREA_MOUSE_BUTTON_UP,&StateCircle_Context::event_mouse_click_handler));
231 insert(event_def(EVENT_REFRESH_TOOL_OPTIONS,&StateCircle_Context::event_refresh_tool_options));
234 StateCircle::~StateCircle()
239 StateCircle_Context::load_settings()
243 //parse the arguments yargh!
244 if(settings.get_value("circle.id",value))
249 if(settings.get_value("circle.fallofftype",value) && value != "")
250 set_falloff(atoi(value.c_str()));
254 #ifdef BLEND_METHOD_IN_TOOL_OPTIONS
255 if(settings.get_value("circle.blend",value) && value != "")
256 set_blend(atoi(value.c_str()));
258 set_blend(0);//(int)Color::BLEND_COMPOSITE); //0 should be blend composites value
259 #endif // BLEND_METHOD_IN_TOOL_OPTIONS
261 if(settings.get_value("circle.feather",value))
262 set_feather(atof(value.c_str()));
266 if(settings.get_value("circle.number_of_bline_points",value))
267 set_number_of_bline_points(atof(value.c_str()));
269 set_number_of_bline_points(4);
271 if(settings.get_value("circle.bline_point_angle_offset",value))
272 set_bline_point_angle_offset(atof(value.c_str()));
274 set_bline_point_angle_offset(0);
276 if(settings.get_value("circle.invert",value) && value != "0")
281 if(settings.get_value("circle.layer_circle",value) && value=="0")
282 set_layer_circle_flag(false);
284 set_layer_circle_flag(true);
286 if(settings.get_value("circle.layer_region",value) && value=="1")
287 set_layer_region_flag(true);
289 set_layer_region_flag(false);
291 if(settings.get_value("circle.layer_outline",value) && value=="1")
292 set_layer_outline_flag(true);
294 set_layer_outline_flag(false);
296 if(settings.get_value("circle.layer_curve_gradient",value) && value=="1")
297 set_layer_curve_gradient_flag(true);
299 set_layer_curve_gradient_flag(false);
301 if(settings.get_value("circle.layer_plant",value) && value=="1")
302 set_layer_plant_flag(true);
304 set_layer_plant_flag(false);
306 if(settings.get_value("circle.layer_link_origins",value) && value=="0")
307 set_layer_link_origins_flag(false);
309 set_layer_link_origins_flag(true);
311 if(settings.get_value("circle.layer_origins_at_center",value) && value=="0")
312 set_layer_origins_at_center_flag(false);
314 set_layer_origins_at_center_flag(true);
318 StateCircle_Context::save_settings()
320 settings.set_value("circle.id",get_id());
321 settings.set_value("circle.fallofftype",strprintf("%d",get_falloff()));
322 #ifdef BLEND_METHOD_IN_TOOL_OPTIONS
323 settings.set_value("circle.blend",strprintf("%d",get_blend()));
324 #endif // BLEND_METHOD_IN_TOOL_OPTIONS
325 settings.set_value("circle.feather",strprintf("%f",(float)get_feather()));
326 settings.set_value("circle.number_of_bline_points",strprintf("%d",(int)(get_number_of_bline_points() + 0.5)));
327 settings.set_value("circle.bline_point_angle_offset",strprintf("%f",(float)get_bline_point_angle_offset()));
328 settings.set_value("circle.invert",get_invert()?"1":"0");
329 settings.set_value("circle.layer_circle",get_layer_circle_flag()?"1":"0");
330 settings.set_value("circle.layer_outline",get_layer_outline_flag()?"1":"0");
331 settings.set_value("circle.layer_region",get_layer_region_flag()?"1":"0");
332 settings.set_value("circle.layer_curve_gradient",get_layer_curve_gradient_flag()?"1":"0");
333 settings.set_value("circle.layer_plant",get_layer_plant_flag()?"1":"0");
334 settings.set_value("circle.layer_link_origins",get_layer_link_origins_flag()?"1":"0");
335 settings.set_value("circle.layer_origins_at_center",get_layer_origins_at_center_flag()?"1":"0");
339 StateCircle_Context::reset()
345 StateCircle_Context::increment_id()
354 // If there is a number
355 // already at the end of the
356 // id, then remove it.
357 if(id[id.size()-1]<='9' && id[id.size()-1]>='0')
359 // figure out how many digits it is
361 (int)id.size()-1 >= digits && id[id.size()-1-digits] <= '9' && id[id.size()-1-digits] >= '0';
366 str_number=String(id,id.size()-digits,id.size());
367 id=String(id,0,id.size()-digits);
369 number=atoi(str_number.c_str());
379 // Add the number back onto the id
381 const String format(strprintf("%%0%dd",digits));
382 id+=strprintf(format.c_str(),number);
389 StateCircle_Context::StateCircle_Context(CanvasView* canvas_view):
390 canvas_view_(canvas_view),
391 is_working(*canvas_view),
392 duckmatic_push(get_work_area()),
393 prev_workarea_layer_status_(get_work_area()->get_allow_layer_clicks()),
394 settings(synfigapp::Main::get_selected_input_device()->settings()),
395 entry_id(), // value lower upper step page
396 adj_feather( 0, 0, 1, 0.01, 0.1),
397 adj_number_of_bline_points( 0, 2, 120, 1 , 1 ),
398 adj_bline_point_angle_offset( 0, -360, 360, 0.1 , 1 ),
399 spin_feather(adj_feather,0.1,3),
400 spin_number_of_bline_points(adj_number_of_bline_points,1,0),
401 spin_bline_point_angle_offset(adj_bline_point_angle_offset,1,1),
402 checkbutton_invert(_("Invert")),
403 checkbutton_layer_circle(_("Create Circle Layer")),
404 checkbutton_layer_region(_("Create Region BLine")),
405 checkbutton_layer_outline(_("Create Outline BLine")),
406 checkbutton_layer_curve_gradient(_("Create Curve Gradient BLine")),
407 checkbutton_layer_plant(_("Create Plant BLine")),
408 checkbutton_layer_link_origins(_("Link Origins")),
409 checkbutton_layer_origins_at_center(_("BLine Origins at Center"))
411 egress_on_selection_change=true;
413 // Set up the tool options dialog
414 enum_falloff.set_param_desc(ParamDesc("falloff")
415 .set_local_name(_("Falloff"))
416 .set_description(_("Determines the falloff function for the feather"))
418 .add_enum_value(CIRCLE_INTERPOLATION_LINEAR,"linear",_("Linear"))
419 .add_enum_value(CIRCLE_SQUARED,"squared",_("Squared"))
420 .add_enum_value(CIRCLE_SQRT,"sqrt",_("Square Root"))
421 .add_enum_value(CIRCLE_SIGMOND,"sigmond",_("Sigmond"))
422 .add_enum_value(CIRCLE_COSINE,"cosine",_("Cosine")));
424 #ifdef BLEND_METHOD_IN_TOOL_OPTIONS
425 enum_blend.set_param_desc(ParamDesc(Color::BLEND_COMPOSITE,"blend_method")
426 .set_local_name(_("Blend Method"))
427 .set_description(_("Defines the blend method to be used for circles")));
428 #endif // BLEND_METHOD_IN_TOOL_OPTIONS
432 options_table.attach(*manage(new Gtk::Label(_("Circle Tool"))), 0, 2, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
433 options_table.attach(entry_id, 0, 2, 1, 2, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
435 options_table.attach(checkbutton_layer_circle, 0, 2, 2, 3, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
436 options_table.attach(checkbutton_layer_outline, 0, 2, 3, 4, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
437 options_table.attach(checkbutton_layer_region, 0, 2, 4, 5, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
438 options_table.attach(checkbutton_layer_plant, 0, 2, 5, 6, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
439 options_table.attach(checkbutton_layer_curve_gradient, 0, 2, 6, 7, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
440 options_table.attach(checkbutton_layer_link_origins, 0, 2, 7, 8, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
441 options_table.attach(checkbutton_layer_origins_at_center, 0, 2, 8, 9, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
444 options_table.attach(checkbutton_invert, 0, 2, 9, 10, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
446 options_table.attach(*manage(new Gtk::Label(_("Falloff:"))), 0, 1, 10, 11, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
447 options_table.attach(enum_falloff, 1, 2, 10, 11, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
450 options_table.attach(*manage(new Gtk::Label(_("Feather:"))), 0, 1, 11, 12, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
451 options_table.attach(spin_feather, 1, 2, 11, 12, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
453 #ifdef BLEND_METHOD_IN_TOOL_OPTIONS
454 options_table.attach(enum_blend, 0, 2, 12, 13, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
455 #endif // BLEND_METHOD_IN_TOOL_OPTIONS
457 options_table.attach(*manage(new Gtk::Label(_("BLine Points:"))), 0, 1, 13, 14, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
458 options_table.attach(spin_number_of_bline_points, 1, 2, 13, 14, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
460 options_table.attach(*manage(new Gtk::Label(_("Point Angle Offset:"))), 0, 1, 14, 15, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
461 options_table.attach(spin_bline_point_angle_offset, 1, 2, 14, 15, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
463 options_table.show_all();
465 refresh_tool_options();
466 App::dialog_tool_options->present();
468 // Turn off layer clicking
469 get_work_area()->set_allow_layer_clicks(false);
471 // clear out the ducks
472 get_work_area()->clear_ducks();
474 // Refresh the work area
475 get_work_area()->queue_draw();
477 // Hide the tables if they are showing
478 //prev_table_status=get_canvas_view()->tables_are_visible();
479 //if(prev_table_status)get_canvas_view()->hide_tables();
481 // Disable the time bar
482 //get_canvas_view()->set_sensitive_timebar(false);
485 //get_work_area()->signal_user_click().connect(sigc::mem_fun(*this,&studio::StateCircle_Context::on_user_click));
486 get_canvas_view()->work_area->set_cursor(Gdk::CROSSHAIR);
488 App::toolbox->refresh();
492 StateCircle_Context::refresh_tool_options()
494 App::dialog_tool_options->clear();
495 App::dialog_tool_options->set_widget(options_table);
496 App::dialog_tool_options->set_local_name(_("Circle Tool"));
497 App::dialog_tool_options->set_name("circle");
501 StateCircle_Context::event_refresh_tool_options(const Smach::event& /*x*/)
503 refresh_tool_options();
504 return Smach::RESULT_ACCEPT;
507 StateCircle_Context::~StateCircle_Context()
511 // Restore layer clicking
512 get_work_area()->set_allow_layer_clicks(prev_workarea_layer_status_);
513 get_canvas_view()->work_area->reset_cursor();
515 App::dialog_tool_options->clear();
517 // Enable the time bar
518 //get_canvas_view()->set_sensitive_timebar(true);
520 // Bring back the tables if they were out before
521 //if(prev_table_status)get_canvas_view()->show_tables();
523 // Refresh the work area
524 get_work_area()->queue_draw();
526 get_canvas_view()->queue_rebuild_ducks();
528 App::toolbox->refresh();
532 StateCircle_Context::event_stop_handler(const Smach::event& /*x*/)
534 throw Smach::egress_exception();
538 StateCircle_Context::event_refresh_handler(const Smach::event& /*x*/)
541 return Smach::RESULT_ACCEPT;
545 StateCircle_Context::make_circle(const Point& _p1, const Point& _p2)
547 synfigapp::Action::PassiveGrouper group(get_canvas_interface()->get_instance().get(),_("New Circle"));
548 synfigapp::PushMode push_mode(get_canvas_interface(),synfigapp::MODE_NORMAL);
552 Canvas::Handle canvas;
555 // we are temporarily using the layer to hold something
556 layer=get_canvas_view()->get_selection_manager()->get_selected_layer();
559 depth=layer->get_depth();
560 canvas=layer->get_canvas();
563 synfigapp::SelectionManager::LayerList layer_selection;
564 if (!getenv("SYNFIG_TOOLS_CLEAR_SELECTION"))
565 layer_selection = get_canvas_view()->get_selection_manager()->get_selected_layers();
567 const synfig::TransformStack& transform(get_canvas_view()->get_curr_transform_stack());
568 const Point p1(transform.unperform(_p1));
569 const Point p2(transform.unperform(_p2));
571 Real radius((p2-p1).mag());
572 int points = get_number_of_bline_points();
573 Angle::deg offset(get_bline_point_angle_offset());
574 Angle::deg angle(360.0/points);
575 Real tangent(4 * ((points == 2)
577 : ((2 * Angle::cos(angle/2).get() - Angle::cos(angle).get() - 1) / Angle::sin(angle).get())));
581 if (get_layer_origins_at_center_flag())
592 std::vector<BLinePoint> new_list;
593 for (int i = 0; i < points; i++)
595 new_list.push_back(*(new BLinePoint));
596 new_list[i].set_width(1);
597 new_list[i].set_vertex(Point(radius*Angle::cos(angle*i + offset).get() + x,
598 radius*Angle::sin(angle*i + offset).get() + y));
599 new_list[i].set_tangent(Point(-radius*tangent*Angle::sin(angle*i + offset).get(),
600 radius*tangent*Angle::cos(angle*i + offset).get()));
603 ValueNode_BLine::Handle value_node_bline(ValueNode_BLine::create(new_list));
604 assert(value_node_bline);
606 ValueNode_Const::Handle value_node_origin(ValueNode_Const::create(origin));
607 assert(value_node_origin);
609 // Set the looping flag
610 value_node_bline->set_loop(true);
613 canvas=get_canvas_view()->get_canvas();
615 value_node_bline->set_member_canvas(canvas);
617 // count how many layers we're going to be creating
618 int layers_to_create = this->layers_to_create();
620 ///////////////////////////////////////////////////////////////////////////
622 ///////////////////////////////////////////////////////////////////////////
624 if (get_layer_circle_flag() &&
625 get_falloff() >= 0 && get_falloff() < CIRCLE_NUM_FALLOFF)
627 layer=get_canvas_interface()->add_layer_to("circle",canvas,depth);
630 get_canvas_view()->get_ui_interface()->error(_("Unable to create layer"));
634 layer_selection.push_back(layer);
636 layer->set_param("radius",(p2-p1).mag());
637 get_canvas_interface()->signal_layer_param_changed()(layer,"radius");
639 layer->set_param("falloff",get_falloff());
640 get_canvas_interface()->signal_layer_param_changed()(layer,"falloff");
642 layer->set_param("feather",get_feather());
643 get_canvas_interface()->signal_layer_param_changed()(layer,"feather");
645 layer->set_param("invert",get_invert());
646 get_canvas_interface()->signal_layer_param_changed()(layer,"invert");
648 #ifdef BLEND_METHOD_IN_TOOL_OPTIONS
649 layer->set_param("blend_method",get_blend());
650 get_canvas_interface()->signal_layer_param_changed()(layer,"blend_method");
651 #endif // BLEND_METHOD_IN_TOOL_OPTIONS
653 layer->set_description(get_id());
654 get_canvas_interface()->signal_layer_new_description()(layer,layer->get_description());
656 // only link the circle's origin parameter if the option is selected, we're putting bline
657 // origins at their centers, and we're creating more than one layer
658 if (get_layer_link_origins_flag() && get_layer_origins_at_center_flag() && layers_to_create > 1)
660 synfigapp::Action::Handle action(synfigapp::Action::create("LayerParamConnect"));
663 action->set_param("canvas",get_canvas());
664 action->set_param("canvas_interface",get_canvas_interface());
665 action->set_param("layer",layer);
666 if(!action->set_param("param",String("origin")))
667 synfig::error("LayerParamConnect didn't like \"param\"");
668 if(!action->set_param("value_node",ValueNode::Handle(value_node_origin)))
669 synfig::error("LayerParamConnect didn't like \"value_node\"");
671 if(!get_canvas_interface()->get_instance()->perform_action(action))
673 //get_canvas_view()->get_ui_interface()->error(_("Unable to create Circle layer"));
675 throw String(_("Unable to create Circle layer"));
681 layer->set_param("origin",p1);
682 get_canvas_interface()->signal_layer_param_changed()(layer,"origin");
686 ///////////////////////////////////////////////////////////////////////////
687 // C U R V E G R A D I E N T
688 ///////////////////////////////////////////////////////////////////////////
690 if(get_layer_curve_gradient_flag())
692 synfigapp::PushMode push_mode(get_canvas_interface(),synfigapp::MODE_NORMAL);
694 Layer::Handle layer(get_canvas_interface()->add_layer_to("curve_gradient",canvas,depth));
697 get_canvas_view()->get_ui_interface()->error(_("Unable to create layer"));
701 layer_selection.push_back(layer);
702 layer->set_description(get_id()+_(" Gradient"));
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("LayerParamConnect"));
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 Gradient layer"));
731 // only link the curve gradient'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("LayerParamConnect"));
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 Gradient layer"));
755 layer->set_param("origin",origin);
756 get_canvas_interface()->signal_layer_param_changed()(layer,"origin");
760 ///////////////////////////////////////////////////////////////////////////
762 ///////////////////////////////////////////////////////////////////////////
764 if(get_layer_plant_flag())
766 synfigapp::PushMode push_mode(get_canvas_interface(),synfigapp::MODE_NORMAL);
768 Layer::Handle layer(get_canvas_interface()->add_layer_to("plant",canvas,depth));
771 get_canvas_view()->get_ui_interface()->error(_("Unable to create layer"));
775 layer_selection.push_back(layer);
776 layer->set_description(get_id()+_(" Plant"));
777 get_canvas_interface()->signal_layer_new_description()(layer,layer->get_description());
779 #ifdef BLEND_METHOD_IN_TOOL_OPTIONS
780 layer->set_param("blend_method",get_blend());
781 get_canvas_interface()->signal_layer_param_changed()(layer,"blend_method");
782 #endif // BLEND_METHOD_IN_TOOL_OPTIONS
785 synfigapp::Action::Handle action(synfigapp::Action::create("LayerParamConnect"));
788 action->set_param("canvas",get_canvas());
789 action->set_param("canvas_interface",get_canvas_interface());
790 action->set_param("layer",layer);
791 if(!action->set_param("param",String("bline")))
792 synfig::error("LayerParamConnect didn't like \"param\"");
793 if(!action->set_param("value_node",ValueNode::Handle(value_node_bline)))
794 synfig::error("LayerParamConnect didn't like \"value_node\"");
796 if(!get_canvas_interface()->get_instance()->perform_action(action))
798 //get_canvas_view()->get_ui_interface()->error(_("Unable to create BLine layer"));
800 throw String(_("Unable to create Plant layer"));
805 // only link the plant's origin parameter if the option is selected and we're creating more than one layer
806 if (get_layer_link_origins_flag() && layers_to_create > 1)
808 synfigapp::Action::Handle action(synfigapp::Action::create("LayerParamConnect"));
811 action->set_param("canvas",get_canvas());
812 action->set_param("canvas_interface",get_canvas_interface());
813 action->set_param("layer",layer);
814 if(!action->set_param("param",String("origin")))
815 synfig::error("LayerParamConnect didn't like \"param\"");
816 if(!action->set_param("value_node",ValueNode::Handle(value_node_origin)))
817 synfig::error("LayerParamConnect didn't like \"value_node\"");
819 if(!get_canvas_interface()->get_instance()->perform_action(action))
821 //get_canvas_view()->get_ui_interface()->error(_("Unable to create BLine layer"));
823 throw String(_("Unable to create Plant layer"));
829 layer->set_param("origin",origin);
830 get_canvas_interface()->signal_layer_param_changed()(layer,"origin");
834 ///////////////////////////////////////////////////////////////////////////
836 ///////////////////////////////////////////////////////////////////////////
838 if(get_layer_region_flag())
840 synfigapp::PushMode push_mode(get_canvas_interface(),synfigapp::MODE_NORMAL);
842 Layer::Handle layer(get_canvas_interface()->add_layer_to("region",canvas,depth));
845 get_canvas_view()->get_ui_interface()->error(_("Unable to create layer"));
849 layer_selection.push_back(layer);
850 layer->set_description(get_id()+_(" Region"));
851 get_canvas_interface()->signal_layer_new_description()(layer,layer->get_description());
853 #ifdef BLEND_METHOD_IN_TOOL_OPTIONS
854 layer->set_param("blend_method",get_blend());
855 get_canvas_interface()->signal_layer_param_changed()(layer,"blend_method");
856 #endif // BLEND_METHOD_IN_TOOL_OPTIONS
858 layer->set_param("feather",get_feather());
859 get_canvas_interface()->signal_layer_param_changed()(layer,"feather");
861 layer->set_param("invert",get_invert());
862 get_canvas_interface()->signal_layer_param_changed()(layer,"invert");
864 // I don't know if it's safe to reuse the same LayerParamConnect action, so I'm
865 // using 2 separate ones.
867 synfigapp::Action::Handle action(synfigapp::Action::create("LayerParamConnect"));
870 action->set_param("canvas",get_canvas());
871 action->set_param("canvas_interface",get_canvas_interface());
872 action->set_param("layer",layer);
873 if(!action->set_param("param",String("bline")))
874 synfig::error("LayerParamConnect didn't like \"param\"");
875 if(!action->set_param("value_node",ValueNode::Handle(value_node_bline)))
876 synfig::error("LayerParamConnect didn't like \"value_node\"");
878 if(!get_canvas_interface()->get_instance()->perform_action(action))
880 //get_canvas_view()->get_ui_interface()->error(_("Unable to create Region layer"));
882 throw String(_("Unable to create Region layer"));
887 // only link the region's origin parameter if the option is selected and we're creating more than one layer
888 if (get_layer_link_origins_flag() && layers_to_create > 1)
890 synfigapp::Action::Handle action(synfigapp::Action::create("LayerParamConnect"));
893 action->set_param("canvas",get_canvas());
894 action->set_param("canvas_interface",get_canvas_interface());
895 action->set_param("layer",layer);
896 if(!action->set_param("param",String("origin")))
897 synfig::error("LayerParamConnect didn't like \"param\"");
898 if(!action->set_param("value_node",ValueNode::Handle(value_node_origin)))
899 synfig::error("LayerParamConnect didn't like \"value_node\"");
901 if(!get_canvas_interface()->get_instance()->perform_action(action))
903 //get_canvas_view()->get_ui_interface()->error(_("Unable to create Region layer"));
905 throw String(_("Unable to create Region layer"));
911 layer->set_param("origin",origin);
912 get_canvas_interface()->signal_layer_param_changed()(layer,"origin");
916 ///////////////////////////////////////////////////////////////////////////
918 ///////////////////////////////////////////////////////////////////////////
920 if (get_layer_outline_flag())
922 Layer::Handle layer(get_canvas_interface()->add_layer_to("outline",canvas,depth));
925 get_canvas_view()->get_ui_interface()->error(_("Unable to create layer"));
929 layer_selection.push_back(layer);
930 layer->set_description(get_id()+_(" Outline"));
931 get_canvas_interface()->signal_layer_new_description()(layer,layer->get_description());
933 #ifdef BLEND_METHOD_IN_TOOL_OPTIONS
934 layer->set_param("blend_method",get_blend());
935 get_canvas_interface()->signal_layer_param_changed()(layer,"blend_method");
936 #endif // BLEND_METHOD_IN_TOOL_OPTIONS
938 layer->set_param("feather",get_feather());
939 get_canvas_interface()->signal_layer_param_changed()(layer,"feather");
941 layer->set_param("invert",get_invert());
942 get_canvas_interface()->signal_layer_param_changed()(layer,"invert");
945 synfigapp::Action::Handle action(synfigapp::Action::create("LayerParamConnect"));
948 action->set_param("canvas",get_canvas());
949 action->set_param("canvas_interface",get_canvas_interface());
950 action->set_param("layer",layer);
951 if(!action->set_param("param",String("bline")))
952 synfig::error("LayerParamConnect didn't like \"param\"");
953 if(!action->set_param("value_node",ValueNode::Handle(value_node_bline)))
954 synfig::error("LayerParamConnect didn't like \"value_node\"");
956 if(!get_canvas_interface()->get_instance()->perform_action(action))
958 //get_canvas_view()->get_ui_interface()->error(_("Unable to create BLine layer"));
960 throw String(_("Unable to create Outline layer"));
965 // only link the outline's origin parameter if the option is selected and we're creating more than one layer
966 if (get_layer_link_origins_flag() && layers_to_create > 1)
968 synfigapp::Action::Handle action(synfigapp::Action::create("LayerParamConnect"));
971 action->set_param("canvas",get_canvas());
972 action->set_param("canvas_interface",get_canvas_interface());
973 action->set_param("layer",layer);
974 if(!action->set_param("param",String("origin")))
975 synfig::error("LayerParamConnect didn't like \"param\"");
976 if(!action->set_param("value_node",ValueNode::Handle(value_node_origin)))
977 synfig::error("LayerParamConnect didn't like \"value_node\"");
979 if(!get_canvas_interface()->get_instance()->perform_action(action))
981 //get_canvas_view()->get_ui_interface()->error(_("Unable to create BLine layer"));
983 throw String(_("Unable to create Outline layer"));
989 layer->set_param("origin",origin);
990 get_canvas_interface()->signal_layer_param_changed()(layer,"origin");
994 egress_on_selection_change=false;
995 get_canvas_interface()->get_selection_manager()->clear_selected_layers();
996 get_canvas_interface()->get_selection_manager()->set_selected_layers(layer_selection);
997 egress_on_selection_change=true;
1004 StateCircle_Context::event_mouse_click_handler(const Smach::event& x)
1006 const EventMouse& event(*reinterpret_cast<const EventMouse*>(&x));
1008 if(event.key==EVENT_WORKAREA_MOUSE_BUTTON_DOWN && event.button==BUTTON_LEFT)
1010 point_holder=get_work_area()->snap_point_to_grid(event.pos);
1011 etl::handle<Duck> duck=new Duck();
1012 duck->set_point(point_holder);
1013 duck->set_name("p1");
1014 duck->set_type(Duck::TYPE_POSITION);
1015 duck->set_editable(false);
1016 get_work_area()->add_duck(duck);
1018 point2_duck=new Duck();
1019 point2_duck->set_point(Vector(0,0));
1020 point2_duck->set_name("radius");
1021 point2_duck->set_origin(duck);
1022 point2_duck->set_radius(true);
1023 point2_duck->set_scalar(-1);
1024 point2_duck->set_type(Duck::TYPE_RADIUS);
1025 point2_duck->set_hover(true);
1026 get_work_area()->add_duck(point2_duck);
1028 return Smach::RESULT_ACCEPT;
1031 if(event.key==EVENT_WORKAREA_MOUSE_BUTTON_DRAG && event.button==BUTTON_LEFT)
1033 if (!point2_duck) return Smach::RESULT_OK;
1034 point2_duck->set_point(point_holder-get_work_area()->snap_point_to_grid(event.pos));
1035 get_work_area()->queue_draw();
1036 return Smach::RESULT_ACCEPT;
1039 if(event.key==EVENT_WORKAREA_MOUSE_BUTTON_UP && event.button==BUTTON_LEFT)
1041 Point point(get_work_area()->snap_point_to_grid(event.pos));
1043 if (App::restrict_radius_ducks)
1045 if ((point[0] - point_holder[0]) < 0) point[0] = point_holder[0];
1046 if ((point[1] - point_holder[1]) < 0) point[1] = point_holder[1];
1049 make_circle(point_holder, point);
1050 get_work_area()->clear_ducks();
1051 return Smach::RESULT_ACCEPT;
1054 return Smach::RESULT_OK;
1059 StateCircle_Context::refresh_ducks()
1061 get_work_area()->clear_ducks();
1062 get_work_area()->queue_draw();