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 "state_normal.h"
42 #include "canvasview.h"
46 #include <synfigapp/action.h>
47 #include "event_mouse.h"
48 #include "event_layerclick.h"
50 #include "dialog_tooloptions.h"
51 #include <gtkmm/optionmenu.h>
53 #include "widget_enum.h"
54 #include <synfigapp/main.h>
60 /* === U S I N G =========================================================== */
64 using namespace synfig;
65 using namespace studio;
67 /* === M A C R O S ========================================================= */
71 CIRCLE_INTERPOLATION_LINEAR =1,
78 /* === G L O B A L S ======================================================= */
80 StateCircle studio::state_circle;
82 /* === C L A S S E S & S T R U C T S ======================================= */
84 class studio::StateCircle_Context : public sigc::trackable
86 etl::handle<CanvasView> canvas_view_;
87 CanvasView::IsWorking is_working;
89 Duckmatic::Push duckmatic_push;
93 etl::handle<Duck> point2_duck;
97 bool prev_workarea_layer_status_;
100 synfigapp::Settings& settings;
103 Gtk::Table options_table;
105 Gtk::Entry entry_id; //what to name the layer
107 Widget_Enum enum_falloff;
108 #ifdef BLEND_METHOD_IN_TOOL_OPTIONS
109 Widget_Enum enum_blend;
110 #endif // BLEND_METHOD_IN_TOOL_OPTIONS
112 Gtk::Adjustment adj_feather;
113 Gtk::Adjustment adj_number_of_bline_points;
114 Gtk::Adjustment adj_bline_point_angle_offset;
115 Gtk::SpinButton spin_feather;
116 Gtk::SpinButton spin_number_of_bline_points;
117 Gtk::SpinButton spin_bline_point_angle_offset;
119 Gtk::CheckButton checkbutton_invert;
120 Gtk::CheckButton checkbutton_layer_circle;
121 Gtk::CheckButton checkbutton_layer_region;
122 Gtk::CheckButton checkbutton_layer_outline;
123 Gtk::CheckButton checkbutton_layer_curve_gradient;
124 Gtk::CheckButton checkbutton_layer_plant;
125 Gtk::CheckButton checkbutton_layer_link_origins;
126 Gtk::CheckButton checkbutton_layer_origins_at_center;
130 // this only counts the layers which will have their origins linked
131 int layers_to_create()const
134 (get_layer_circle_flag() && get_layer_origins_at_center_flag()) +
135 get_layer_region_flag() +
136 get_layer_outline_flag() +
137 get_layer_curve_gradient_flag() +
138 get_layer_plant_flag();
141 synfig::String get_id()const { return entry_id.get_text(); }
142 void set_id(const synfig::String& x) { return entry_id.set_text(x); }
144 int get_falloff()const { return enum_falloff.get_value(); }
145 void set_falloff(int x) { return enum_falloff.set_value(x); }
147 #ifdef BLEND_METHOD_IN_TOOL_OPTIONS
148 int get_blend()const { return enum_blend.get_value(); }
149 void set_blend(int x) { return enum_blend.set_value(x); }
150 #endif // BLEND_METHOD_IN_TOOL_OPTIONS
152 Real get_feather()const { return adj_feather.get_value(); }
153 void set_feather(Real f) { adj_feather.set_value(f); }
155 Real get_number_of_bline_points()const { return adj_number_of_bline_points.get_value(); }
156 void set_number_of_bline_points(Real f) { adj_number_of_bline_points.set_value(f); }
158 Real get_bline_point_angle_offset()const { return adj_bline_point_angle_offset.get_value(); }
159 void set_bline_point_angle_offset(Real f) { adj_bline_point_angle_offset.set_value(f); }
161 bool get_invert()const { return checkbutton_invert.get_active(); }
162 void set_invert(bool i) { checkbutton_invert.set_active(i); }
164 bool get_layer_circle_flag()const { return checkbutton_layer_circle.get_active(); }
165 void set_layer_circle_flag(bool x) { return checkbutton_layer_circle.set_active(x); }
167 bool get_layer_region_flag()const { return checkbutton_layer_region.get_active(); }
168 void set_layer_region_flag(bool x) { return checkbutton_layer_region.set_active(x); }
170 bool get_layer_outline_flag()const { return checkbutton_layer_outline.get_active(); }
171 void set_layer_outline_flag(bool x) { return checkbutton_layer_outline.set_active(x); }
173 bool get_layer_curve_gradient_flag()const { return checkbutton_layer_curve_gradient.get_active(); }
174 void set_layer_curve_gradient_flag(bool x) { return checkbutton_layer_curve_gradient.set_active(x); }
176 bool get_layer_plant_flag()const { return checkbutton_layer_plant.get_active(); }
177 void set_layer_plant_flag(bool x) { return checkbutton_layer_plant.set_active(x); }
179 bool get_layer_link_origins_flag()const { return checkbutton_layer_link_origins.get_active(); }
180 void set_layer_link_origins_flag(bool x) { return checkbutton_layer_link_origins.set_active(x); }
182 bool get_layer_origins_at_center_flag()const { return checkbutton_layer_origins_at_center.get_active(); }
183 void set_layer_origins_at_center_flag(bool x) { return checkbutton_layer_origins_at_center.set_active(x); }
185 void refresh_tool_options(); //to refresh the toolbox
188 Smach::event_result event_stop_handler(const Smach::event& x);
189 Smach::event_result event_refresh_handler(const Smach::event& x);
190 Smach::event_result event_mouse_click_handler(const Smach::event& x);
191 Smach::event_result event_refresh_tool_options(const Smach::event& x);
193 //constructor destructor
194 StateCircle_Context(CanvasView* canvas_view);
195 ~StateCircle_Context();
198 const etl::handle<CanvasView>& get_canvas_view()const{return canvas_view_;}
199 etl::handle<synfigapp::CanvasInterface> get_canvas_interface()const{return canvas_view_->canvas_interface();}
200 synfig::Canvas::Handle get_canvas()const{return canvas_view_->get_canvas();}
201 WorkArea * get_work_area()const{return canvas_view_->get_work_area();}
203 //Modifying settings etc.
204 void load_settings();
205 void save_settings();
208 bool egress_on_selection_change;
209 Smach::event_result event_layer_selection_changed_handler(const Smach::event& /*x*/)
211 if(egress_on_selection_change)
212 throw &state_normal; //throw Smach::egress_exception();
213 return Smach::RESULT_OK;
216 void make_circle(const Point& p1, const Point& p2);
218 }; // END of class StateCircle_Context
220 /* === M E T H O D S ======================================================= */
222 StateCircle::StateCircle():
223 Smach::state<StateCircle_Context>("circle")
225 insert(event_def(EVENT_LAYER_SELECTION_CHANGED,&StateCircle_Context::event_layer_selection_changed_handler));
226 insert(event_def(EVENT_STOP,&StateCircle_Context::event_stop_handler));
227 insert(event_def(EVENT_REFRESH,&StateCircle_Context::event_refresh_handler));
228 insert(event_def(EVENT_REFRESH_DUCKS,&StateCircle_Context::event_refresh_handler));
229 insert(event_def(EVENT_WORKAREA_MOUSE_BUTTON_DOWN,&StateCircle_Context::event_mouse_click_handler));
230 insert(event_def(EVENT_WORKAREA_MOUSE_BUTTON_DRAG,&StateCircle_Context::event_mouse_click_handler));
231 insert(event_def(EVENT_WORKAREA_MOUSE_BUTTON_UP,&StateCircle_Context::event_mouse_click_handler));
232 insert(event_def(EVENT_REFRESH_TOOL_OPTIONS,&StateCircle_Context::event_refresh_tool_options));
235 StateCircle::~StateCircle()
240 StateCircle_Context::load_settings()
244 //parse the arguments yargh!
245 if(settings.get_value("circle.id",value))
250 if(settings.get_value("circle.fallofftype",value) && value != "")
251 set_falloff(atoi(value.c_str()));
255 #ifdef BLEND_METHOD_IN_TOOL_OPTIONS
256 if(settings.get_value("circle.blend",value) && value != "")
257 set_blend(atoi(value.c_str()));
259 set_blend(0);//(int)Color::BLEND_COMPOSITE); //0 should be blend composites value
260 #endif // BLEND_METHOD_IN_TOOL_OPTIONS
262 if(settings.get_value("circle.feather",value))
263 set_feather(atof(value.c_str()));
267 if(settings.get_value("circle.number_of_bline_points",value))
268 set_number_of_bline_points(atof(value.c_str()));
270 set_number_of_bline_points(4);
272 if(settings.get_value("circle.bline_point_angle_offset",value))
273 set_bline_point_angle_offset(atof(value.c_str()));
275 set_bline_point_angle_offset(0);
277 if(settings.get_value("circle.invert",value) && value != "0")
282 if(settings.get_value("circle.layer_circle",value) && value=="0")
283 set_layer_circle_flag(false);
285 set_layer_circle_flag(true);
287 if(settings.get_value("circle.layer_region",value) && value=="1")
288 set_layer_region_flag(true);
290 set_layer_region_flag(false);
292 if(settings.get_value("circle.layer_outline",value) && value=="1")
293 set_layer_outline_flag(true);
295 set_layer_outline_flag(false);
297 if(settings.get_value("circle.layer_curve_gradient",value) && value=="1")
298 set_layer_curve_gradient_flag(true);
300 set_layer_curve_gradient_flag(false);
302 if(settings.get_value("circle.layer_plant",value) && value=="1")
303 set_layer_plant_flag(true);
305 set_layer_plant_flag(false);
307 if(settings.get_value("circle.layer_link_origins",value) && value=="0")
308 set_layer_link_origins_flag(false);
310 set_layer_link_origins_flag(true);
312 if(settings.get_value("circle.layer_origins_at_center",value) && value=="0")
313 set_layer_origins_at_center_flag(false);
315 set_layer_origins_at_center_flag(true);
319 StateCircle_Context::save_settings()
321 settings.set_value("circle.id",get_id());
322 settings.set_value("circle.fallofftype",strprintf("%d",get_falloff()));
323 #ifdef BLEND_METHOD_IN_TOOL_OPTIONS
324 settings.set_value("circle.blend",strprintf("%d",get_blend()));
325 #endif // BLEND_METHOD_IN_TOOL_OPTIONS
326 settings.set_value("circle.feather",strprintf("%f",(float)get_feather()));
327 settings.set_value("circle.number_of_bline_points",strprintf("%d",(int)(get_number_of_bline_points() + 0.5)));
328 settings.set_value("circle.bline_point_angle_offset",strprintf("%f",(float)get_bline_point_angle_offset()));
329 settings.set_value("circle.invert",get_invert()?"1":"0");
330 settings.set_value("circle.layer_circle",get_layer_circle_flag()?"1":"0");
331 settings.set_value("circle.layer_outline",get_layer_outline_flag()?"1":"0");
332 settings.set_value("circle.layer_region",get_layer_region_flag()?"1":"0");
333 settings.set_value("circle.layer_curve_gradient",get_layer_curve_gradient_flag()?"1":"0");
334 settings.set_value("circle.layer_plant",get_layer_plant_flag()?"1":"0");
335 settings.set_value("circle.layer_link_origins",get_layer_link_origins_flag()?"1":"0");
336 settings.set_value("circle.layer_origins_at_center",get_layer_origins_at_center_flag()?"1":"0");
340 StateCircle_Context::reset()
346 StateCircle_Context::increment_id()
355 // If there is a number
356 // already at the end of the
357 // id, then remove it.
358 if(id[id.size()-1]<='9' && id[id.size()-1]>='0')
360 // figure out how many digits it is
362 (int)id.size()-1 >= digits && id[id.size()-1-digits] <= '9' && id[id.size()-1-digits] >= '0';
367 str_number=String(id,id.size()-digits,id.size());
368 id=String(id,0,id.size()-digits);
370 number=atoi(str_number.c_str());
380 // Add the number back onto the id
382 const String format(strprintf("%%0%dd",digits));
383 id+=strprintf(format.c_str(),number);
390 StateCircle_Context::StateCircle_Context(CanvasView* canvas_view):
391 canvas_view_(canvas_view),
392 is_working(*canvas_view),
393 duckmatic_push(get_work_area()),
394 prev_workarea_layer_status_(get_work_area()->get_allow_layer_clicks()),
395 settings(synfigapp::Main::get_selected_input_device()->settings()),
396 entry_id(), // value lower upper step page
397 adj_feather( 0, 0, 1, 0.01, 0.1),
398 adj_number_of_bline_points( 0, 2, 120, 1 , 1 ),
399 adj_bline_point_angle_offset( 0, -360, 360, 0.1 , 1 ),
400 spin_feather(adj_feather,0.1,3),
401 spin_number_of_bline_points(adj_number_of_bline_points,1,0),
402 spin_bline_point_angle_offset(adj_bline_point_angle_offset,1,1),
403 checkbutton_invert(_("Invert")),
404 checkbutton_layer_circle(_("Create Circle Layer")),
405 checkbutton_layer_region(_("Create Region BLine")),
406 checkbutton_layer_outline(_("Create Outline BLine")),
407 checkbutton_layer_curve_gradient(_("Create Curve Gradient BLine")),
408 checkbutton_layer_plant(_("Create Plant BLine")),
409 checkbutton_layer_link_origins(_("Link Origins")),
410 checkbutton_layer_origins_at_center(_("BLine Origins at Center"))
412 egress_on_selection_change=true;
414 // Set up the tool options dialog
415 enum_falloff.set_param_desc(ParamDesc("falloff")
416 .set_local_name(_("Falloff"))
417 .set_description(_("Determines the falloff function for the feather"))
419 .add_enum_value(CIRCLE_INTERPOLATION_LINEAR,"linear",_("Linear"))
420 .add_enum_value(CIRCLE_SQUARED,"squared",_("Squared"))
421 .add_enum_value(CIRCLE_SQRT,"sqrt",_("Square Root"))
422 .add_enum_value(CIRCLE_SIGMOND,"sigmond",_("Sigmond"))
423 .add_enum_value(CIRCLE_COSINE,"cosine",_("Cosine")));
425 #ifdef BLEND_METHOD_IN_TOOL_OPTIONS
426 enum_blend.set_param_desc(ParamDesc(Color::BLEND_COMPOSITE,"blend_method")
427 .set_local_name(_("Blend Method"))
428 .set_description(_("Defines the blend method to be used for circles")));
429 #endif // BLEND_METHOD_IN_TOOL_OPTIONS
433 options_table.attach(*manage(new Gtk::Label(_("Circle Tool"))), 0, 2, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
434 options_table.attach(entry_id, 0, 2, 1, 2, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
436 options_table.attach(checkbutton_layer_circle, 0, 2, 2, 3, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
437 options_table.attach(checkbutton_layer_outline, 0, 2, 3, 4, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
438 options_table.attach(checkbutton_layer_region, 0, 2, 4, 5, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
439 options_table.attach(checkbutton_layer_plant, 0, 2, 5, 6, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
440 options_table.attach(checkbutton_layer_curve_gradient, 0, 2, 6, 7, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
441 options_table.attach(checkbutton_layer_link_origins, 0, 2, 7, 8, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
442 options_table.attach(checkbutton_layer_origins_at_center, 0, 2, 8, 9, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
445 options_table.attach(checkbutton_invert, 0, 2, 9, 10, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
447 options_table.attach(*manage(new Gtk::Label(_("Falloff:"))), 0, 1, 10, 11, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
448 options_table.attach(enum_falloff, 1, 2, 10, 11, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
451 options_table.attach(*manage(new Gtk::Label(_("Feather:"))), 0, 1, 11, 12, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
452 options_table.attach(spin_feather, 1, 2, 11, 12, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
454 #ifdef BLEND_METHOD_IN_TOOL_OPTIONS
455 options_table.attach(enum_blend, 0, 2, 12, 13, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
456 #endif // BLEND_METHOD_IN_TOOL_OPTIONS
458 options_table.attach(*manage(new Gtk::Label(_("BLine Points:"))), 0, 1, 13, 14, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
459 options_table.attach(spin_number_of_bline_points, 1, 2, 13, 14, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
461 options_table.attach(*manage(new Gtk::Label(_("Point Angle Offset:"))), 0, 1, 14, 15, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
462 options_table.attach(spin_bline_point_angle_offset, 1, 2, 14, 15, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
464 options_table.show_all();
466 refresh_tool_options();
467 App::dialog_tool_options->present();
469 // Turn off layer clicking
470 get_work_area()->set_allow_layer_clicks(false);
472 // clear out the ducks
473 get_work_area()->clear_ducks();
475 // Refresh the work area
476 get_work_area()->queue_draw();
478 // Hide the tables if they are showing
479 //prev_table_status=get_canvas_view()->tables_are_visible();
480 //if(prev_table_status)get_canvas_view()->hide_tables();
482 // Disable the time bar
483 //get_canvas_view()->set_sensitive_timebar(false);
486 //get_work_area()->signal_user_click().connect(sigc::mem_fun(*this,&studio::StateCircle_Context::on_user_click));
487 get_work_area()->set_cursor(Gdk::CROSSHAIR);
489 App::toolbox->refresh();
493 StateCircle_Context::refresh_tool_options()
495 App::dialog_tool_options->clear();
496 App::dialog_tool_options->set_widget(options_table);
497 App::dialog_tool_options->set_local_name(_("Circle Tool"));
498 App::dialog_tool_options->set_name("circle");
502 StateCircle_Context::event_refresh_tool_options(const Smach::event& /*x*/)
504 refresh_tool_options();
505 return Smach::RESULT_ACCEPT;
508 StateCircle_Context::~StateCircle_Context()
512 // Restore layer clicking
513 get_work_area()->set_allow_layer_clicks(prev_workarea_layer_status_);
514 get_work_area()->reset_cursor();
516 App::dialog_tool_options->clear();
518 // Enable the time bar
519 //get_canvas_view()->set_sensitive_timebar(true);
521 // Bring back the tables if they were out before
522 //if(prev_table_status)get_canvas_view()->show_tables();
524 // Refresh the work area
525 get_work_area()->queue_draw();
527 get_canvas_view()->queue_rebuild_ducks();
529 App::toolbox->refresh();
533 StateCircle_Context::event_stop_handler(const Smach::event& /*x*/)
535 //throw Smach::egress_exception();
537 return Smach::RESULT_OK;
541 StateCircle_Context::event_refresh_handler(const Smach::event& /*x*/)
544 return Smach::RESULT_ACCEPT;
548 StateCircle_Context::make_circle(const Point& _p1, const Point& _p2)
550 synfigapp::Action::PassiveGrouper group(get_canvas_interface()->get_instance().get(),_("New Circle"));
551 synfigapp::PushMode push_mode(get_canvas_interface(),synfigapp::MODE_NORMAL);
555 Canvas::Handle canvas;
558 // we are temporarily using the layer to hold something
559 layer=get_canvas_view()->get_selection_manager()->get_selected_layer();
562 depth=layer->get_depth();
563 canvas=layer->get_canvas();
566 synfigapp::SelectionManager::LayerList layer_selection;
567 if (!getenv("SYNFIG_TOOLS_CLEAR_SELECTION"))
568 layer_selection = get_canvas_view()->get_selection_manager()->get_selected_layers();
570 const synfig::TransformStack& transform(get_canvas_view()->get_curr_transform_stack());
571 const Point p1(transform.unperform(_p1));
572 const Point p2(transform.unperform(_p2));
574 Real radius((p2-p1).mag());
575 int points = get_number_of_bline_points();
576 Angle::deg offset(get_bline_point_angle_offset());
577 Angle::deg angle(360.0/points);
578 Real tangent(4 * ((points == 2)
580 : ((2 * Angle::cos(angle/2).get() - Angle::cos(angle).get() - 1) / Angle::sin(angle).get())));
584 if (get_layer_origins_at_center_flag())
595 std::vector<BLinePoint> new_list;
596 for (int i = 0; i < points; i++)
598 new_list.push_back(*(new BLinePoint));
599 new_list[i].set_width(1);
600 new_list[i].set_vertex(Point(radius*Angle::cos(angle*i + offset).get() + x,
601 radius*Angle::sin(angle*i + offset).get() + y));
602 new_list[i].set_tangent(Point(-radius*tangent*Angle::sin(angle*i + offset).get(),
603 radius*tangent*Angle::cos(angle*i + offset).get()));
606 ValueNode_BLine::Handle value_node_bline(ValueNode_BLine::create(new_list));
607 assert(value_node_bline);
609 ValueNode_Const::Handle value_node_origin(ValueNode_Const::create(origin));
610 assert(value_node_origin);
612 // Set the looping flag
613 value_node_bline->set_loop(true);
616 canvas=get_canvas_view()->get_canvas();
618 value_node_bline->set_member_canvas(canvas);
620 // count how many layers we're going to be creating
621 int layers_to_create = this->layers_to_create();
623 ///////////////////////////////////////////////////////////////////////////
625 ///////////////////////////////////////////////////////////////////////////
627 if (get_layer_circle_flag() &&
628 get_falloff() >= 0 && get_falloff() < CIRCLE_NUM_FALLOFF)
630 layer=get_canvas_interface()->add_layer_to("circle",canvas,depth);
633 get_canvas_view()->get_ui_interface()->error(_("Unable to create layer"));
637 layer_selection.push_back(layer);
639 layer->set_param("radius",(p2-p1).mag());
640 get_canvas_interface()->signal_layer_param_changed()(layer,"radius");
642 layer->set_param("falloff",get_falloff());
643 get_canvas_interface()->signal_layer_param_changed()(layer,"falloff");
645 layer->set_param("feather",get_feather());
646 get_canvas_interface()->signal_layer_param_changed()(layer,"feather");
648 layer->set_param("invert",get_invert());
649 get_canvas_interface()->signal_layer_param_changed()(layer,"invert");
651 #ifdef BLEND_METHOD_IN_TOOL_OPTIONS
652 layer->set_param("blend_method",get_blend());
653 get_canvas_interface()->signal_layer_param_changed()(layer,"blend_method");
654 #endif // BLEND_METHOD_IN_TOOL_OPTIONS
656 layer->set_description(get_id());
657 get_canvas_interface()->signal_layer_new_description()(layer,layer->get_description());
659 // only link the circle's origin parameter if the option is selected, we're putting bline
660 // origins at their centers, and we're creating more than one layer
661 if (get_layer_link_origins_flag() && get_layer_origins_at_center_flag() && layers_to_create > 1)
663 synfigapp::Action::Handle action(synfigapp::Action::create("LayerParamConnect"));
666 action->set_param("canvas",get_canvas());
667 action->set_param("canvas_interface",get_canvas_interface());
668 action->set_param("layer",layer);
669 if(!action->set_param("param",String("origin")))
670 synfig::error("LayerParamConnect didn't like \"param\"");
671 if(!action->set_param("value_node",ValueNode::Handle(value_node_origin)))
672 synfig::error("LayerParamConnect didn't like \"value_node\"");
674 if(!get_canvas_interface()->get_instance()->perform_action(action))
676 //get_canvas_view()->get_ui_interface()->error(_("Unable to create Circle layer"));
678 throw String(_("Unable to create Circle layer"));
684 layer->set_param("origin",p1);
685 get_canvas_interface()->signal_layer_param_changed()(layer,"origin");
689 ///////////////////////////////////////////////////////////////////////////
690 // C U R V E G R A D I E N T
691 ///////////////////////////////////////////////////////////////////////////
693 if(get_layer_curve_gradient_flag())
695 synfigapp::PushMode push_mode(get_canvas_interface(),synfigapp::MODE_NORMAL);
697 Layer::Handle layer(get_canvas_interface()->add_layer_to("curve_gradient",canvas,depth));
700 get_canvas_view()->get_ui_interface()->error(_("Unable to create layer"));
704 layer_selection.push_back(layer);
705 layer->set_description(get_id()+_(" Gradient"));
706 get_canvas_interface()->signal_layer_new_description()(layer,layer->get_description());
708 #ifdef BLEND_METHOD_IN_TOOL_OPTIONS
709 layer->set_param("blend_method",get_blend());
710 get_canvas_interface()->signal_layer_param_changed()(layer,"blend_method");
711 #endif // BLEND_METHOD_IN_TOOL_OPTIONS
714 synfigapp::Action::Handle action(synfigapp::Action::create("LayerParamConnect"));
717 action->set_param("canvas",get_canvas());
718 action->set_param("canvas_interface",get_canvas_interface());
719 action->set_param("layer",layer);
720 if(!action->set_param("param",String("bline")))
721 synfig::error("LayerParamConnect didn't like \"param\"");
722 if(!action->set_param("value_node",ValueNode::Handle(value_node_bline)))
723 synfig::error("LayerParamConnect didn't like \"value_node\"");
725 if(!get_canvas_interface()->get_instance()->perform_action(action))
727 //get_canvas_view()->get_ui_interface()->error(_("Unable to create BLine layer"));
729 throw String(_("Unable to create Gradient layer"));
734 // only link the curve gradient's origin parameter if the option is selected and we're creating more than one layer
735 if (get_layer_link_origins_flag() && layers_to_create > 1)
737 synfigapp::Action::Handle action(synfigapp::Action::create("LayerParamConnect"));
740 action->set_param("canvas",get_canvas());
741 action->set_param("canvas_interface",get_canvas_interface());
742 action->set_param("layer",layer);
743 if(!action->set_param("param",String("origin")))
744 synfig::error("LayerParamConnect didn't like \"param\"");
745 if(!action->set_param("value_node",ValueNode::Handle(value_node_origin)))
746 synfig::error("LayerParamConnect didn't like \"value_node\"");
748 if(!get_canvas_interface()->get_instance()->perform_action(action))
750 //get_canvas_view()->get_ui_interface()->error(_("Unable to create BLine layer"));
752 throw String(_("Unable to create Gradient layer"));
758 layer->set_param("origin",origin);
759 get_canvas_interface()->signal_layer_param_changed()(layer,"origin");
763 ///////////////////////////////////////////////////////////////////////////
765 ///////////////////////////////////////////////////////////////////////////
767 if(get_layer_plant_flag())
769 synfigapp::PushMode push_mode(get_canvas_interface(),synfigapp::MODE_NORMAL);
771 Layer::Handle layer(get_canvas_interface()->add_layer_to("plant",canvas,depth));
774 get_canvas_view()->get_ui_interface()->error(_("Unable to create layer"));
778 layer_selection.push_back(layer);
779 layer->set_description(get_id()+_(" Plant"));
780 get_canvas_interface()->signal_layer_new_description()(layer,layer->get_description());
782 #ifdef BLEND_METHOD_IN_TOOL_OPTIONS
783 layer->set_param("blend_method",get_blend());
784 get_canvas_interface()->signal_layer_param_changed()(layer,"blend_method");
785 #endif // BLEND_METHOD_IN_TOOL_OPTIONS
788 synfigapp::Action::Handle action(synfigapp::Action::create("LayerParamConnect"));
791 action->set_param("canvas",get_canvas());
792 action->set_param("canvas_interface",get_canvas_interface());
793 action->set_param("layer",layer);
794 if(!action->set_param("param",String("bline")))
795 synfig::error("LayerParamConnect didn't like \"param\"");
796 if(!action->set_param("value_node",ValueNode::Handle(value_node_bline)))
797 synfig::error("LayerParamConnect didn't like \"value_node\"");
799 if(!get_canvas_interface()->get_instance()->perform_action(action))
801 //get_canvas_view()->get_ui_interface()->error(_("Unable to create BLine layer"));
803 throw String(_("Unable to create Plant layer"));
808 // only link the plant's origin parameter if the option is selected and we're creating more than one layer
809 if (get_layer_link_origins_flag() && layers_to_create > 1)
811 synfigapp::Action::Handle action(synfigapp::Action::create("LayerParamConnect"));
814 action->set_param("canvas",get_canvas());
815 action->set_param("canvas_interface",get_canvas_interface());
816 action->set_param("layer",layer);
817 if(!action->set_param("param",String("origin")))
818 synfig::error("LayerParamConnect didn't like \"param\"");
819 if(!action->set_param("value_node",ValueNode::Handle(value_node_origin)))
820 synfig::error("LayerParamConnect didn't like \"value_node\"");
822 if(!get_canvas_interface()->get_instance()->perform_action(action))
824 //get_canvas_view()->get_ui_interface()->error(_("Unable to create BLine layer"));
826 throw String(_("Unable to create Plant layer"));
832 layer->set_param("origin",origin);
833 get_canvas_interface()->signal_layer_param_changed()(layer,"origin");
837 ///////////////////////////////////////////////////////////////////////////
839 ///////////////////////////////////////////////////////////////////////////
841 if(get_layer_region_flag())
843 synfigapp::PushMode push_mode(get_canvas_interface(),synfigapp::MODE_NORMAL);
845 Layer::Handle layer(get_canvas_interface()->add_layer_to("region",canvas,depth));
848 get_canvas_view()->get_ui_interface()->error(_("Unable to create layer"));
852 layer_selection.push_back(layer);
853 layer->set_description(get_id()+_(" Region"));
854 get_canvas_interface()->signal_layer_new_description()(layer,layer->get_description());
856 #ifdef BLEND_METHOD_IN_TOOL_OPTIONS
857 layer->set_param("blend_method",get_blend());
858 get_canvas_interface()->signal_layer_param_changed()(layer,"blend_method");
859 #endif // BLEND_METHOD_IN_TOOL_OPTIONS
861 layer->set_param("feather",get_feather());
862 get_canvas_interface()->signal_layer_param_changed()(layer,"feather");
864 layer->set_param("invert",get_invert());
865 get_canvas_interface()->signal_layer_param_changed()(layer,"invert");
867 // I don't know if it's safe to reuse the same LayerParamConnect action, so I'm
868 // using 2 separate ones.
870 synfigapp::Action::Handle action(synfigapp::Action::create("LayerParamConnect"));
873 action->set_param("canvas",get_canvas());
874 action->set_param("canvas_interface",get_canvas_interface());
875 action->set_param("layer",layer);
876 if(!action->set_param("param",String("bline")))
877 synfig::error("LayerParamConnect didn't like \"param\"");
878 if(!action->set_param("value_node",ValueNode::Handle(value_node_bline)))
879 synfig::error("LayerParamConnect didn't like \"value_node\"");
881 if(!get_canvas_interface()->get_instance()->perform_action(action))
883 //get_canvas_view()->get_ui_interface()->error(_("Unable to create Region layer"));
885 throw String(_("Unable to create Region layer"));
890 // only link the region's origin parameter if the option is selected and we're creating more than one layer
891 if (get_layer_link_origins_flag() && layers_to_create > 1)
893 synfigapp::Action::Handle action(synfigapp::Action::create("LayerParamConnect"));
896 action->set_param("canvas",get_canvas());
897 action->set_param("canvas_interface",get_canvas_interface());
898 action->set_param("layer",layer);
899 if(!action->set_param("param",String("origin")))
900 synfig::error("LayerParamConnect didn't like \"param\"");
901 if(!action->set_param("value_node",ValueNode::Handle(value_node_origin)))
902 synfig::error("LayerParamConnect didn't like \"value_node\"");
904 if(!get_canvas_interface()->get_instance()->perform_action(action))
906 //get_canvas_view()->get_ui_interface()->error(_("Unable to create Region layer"));
908 throw String(_("Unable to create Region layer"));
914 layer->set_param("origin",origin);
915 get_canvas_interface()->signal_layer_param_changed()(layer,"origin");
919 ///////////////////////////////////////////////////////////////////////////
921 ///////////////////////////////////////////////////////////////////////////
923 if (get_layer_outline_flag())
925 Layer::Handle layer(get_canvas_interface()->add_layer_to("outline",canvas,depth));
928 get_canvas_view()->get_ui_interface()->error(_("Unable to create layer"));
932 layer_selection.push_back(layer);
933 layer->set_description(get_id()+_(" Outline"));
934 get_canvas_interface()->signal_layer_new_description()(layer,layer->get_description());
936 #ifdef BLEND_METHOD_IN_TOOL_OPTIONS
937 layer->set_param("blend_method",get_blend());
938 get_canvas_interface()->signal_layer_param_changed()(layer,"blend_method");
939 #endif // BLEND_METHOD_IN_TOOL_OPTIONS
941 layer->set_param("feather",get_feather());
942 get_canvas_interface()->signal_layer_param_changed()(layer,"feather");
944 layer->set_param("invert",get_invert());
945 get_canvas_interface()->signal_layer_param_changed()(layer,"invert");
948 synfigapp::Action::Handle action(synfigapp::Action::create("LayerParamConnect"));
951 action->set_param("canvas",get_canvas());
952 action->set_param("canvas_interface",get_canvas_interface());
953 action->set_param("layer",layer);
954 if(!action->set_param("param",String("bline")))
955 synfig::error("LayerParamConnect didn't like \"param\"");
956 if(!action->set_param("value_node",ValueNode::Handle(value_node_bline)))
957 synfig::error("LayerParamConnect didn't like \"value_node\"");
959 if(!get_canvas_interface()->get_instance()->perform_action(action))
961 //get_canvas_view()->get_ui_interface()->error(_("Unable to create BLine layer"));
963 throw String(_("Unable to create Outline layer"));
968 // only link the outline's origin parameter if the option is selected and we're creating more than one layer
969 if (get_layer_link_origins_flag() && layers_to_create > 1)
971 synfigapp::Action::Handle action(synfigapp::Action::create("LayerParamConnect"));
974 action->set_param("canvas",get_canvas());
975 action->set_param("canvas_interface",get_canvas_interface());
976 action->set_param("layer",layer);
977 if(!action->set_param("param",String("origin")))
978 synfig::error("LayerParamConnect didn't like \"param\"");
979 if(!action->set_param("value_node",ValueNode::Handle(value_node_origin)))
980 synfig::error("LayerParamConnect didn't like \"value_node\"");
982 if(!get_canvas_interface()->get_instance()->perform_action(action))
984 //get_canvas_view()->get_ui_interface()->error(_("Unable to create BLine layer"));
986 throw String(_("Unable to create Outline layer"));
992 layer->set_param("origin",origin);
993 get_canvas_interface()->signal_layer_param_changed()(layer,"origin");
997 egress_on_selection_change=false;
998 get_canvas_interface()->get_selection_manager()->clear_selected_layers();
999 get_canvas_interface()->get_selection_manager()->set_selected_layers(layer_selection);
1000 egress_on_selection_change=true;
1007 StateCircle_Context::event_mouse_click_handler(const Smach::event& x)
1009 const EventMouse& event(*reinterpret_cast<const EventMouse*>(&x));
1011 if(event.key==EVENT_WORKAREA_MOUSE_BUTTON_DOWN && event.button==BUTTON_LEFT)
1013 point_holder=get_work_area()->snap_point_to_grid(event.pos);
1014 etl::handle<Duck> duck=new Duck();
1015 duck->set_point(point_holder);
1016 duck->set_name("p1");
1017 duck->set_type(Duck::TYPE_POSITION);
1018 duck->set_editable(false);
1019 get_work_area()->add_duck(duck);
1021 point2_duck=new Duck();
1022 point2_duck->set_point(Vector(0,0));
1023 point2_duck->set_name("radius");
1024 point2_duck->set_origin(duck);
1025 point2_duck->set_radius(true);
1026 point2_duck->set_scalar(-1);
1027 point2_duck->set_type(Duck::TYPE_RADIUS);
1028 point2_duck->set_hover(true);
1029 get_work_area()->add_duck(point2_duck);
1031 return Smach::RESULT_ACCEPT;
1034 if(event.key==EVENT_WORKAREA_MOUSE_BUTTON_DRAG && event.button==BUTTON_LEFT)
1036 if (!point2_duck) return Smach::RESULT_OK;
1037 point2_duck->set_point(point_holder-get_work_area()->snap_point_to_grid(event.pos));
1038 get_work_area()->queue_draw();
1039 return Smach::RESULT_ACCEPT;
1042 if(event.key==EVENT_WORKAREA_MOUSE_BUTTON_UP && event.button==BUTTON_LEFT)
1044 Point point(get_work_area()->snap_point_to_grid(event.pos));
1046 if (App::restrict_radius_ducks)
1048 if ((point[0] - point_holder[0]) < 0) point[0] = point_holder[0];
1049 if ((point[1] - point_holder[1]) < 0) point[1] = point_holder[1];
1052 make_circle(point_holder, point);
1053 get_work_area()->clear_ducks();
1054 return Smach::RESULT_ACCEPT;
1057 return Smach::RESULT_OK;
1062 StateCircle_Context::refresh_ducks()
1064 get_work_area()->clear_ducks();
1065 get_work_area()->queue_draw();