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_circle_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 void refresh_tool_options(); //to refresh the toolbox
184 Smach::event_result event_stop_handler(const Smach::event& x);
185 Smach::event_result event_refresh_handler(const Smach::event& x);
186 Smach::event_result event_mouse_click_handler(const Smach::event& x);
187 Smach::event_result event_refresh_tool_options(const Smach::event& x);
189 //constructor destructor
190 StateCircle_Context(CanvasView* canvas_view);
191 ~StateCircle_Context();
194 const etl::handle<CanvasView>& get_canvas_view()const{return canvas_view_;}
195 etl::handle<synfigapp::CanvasInterface> get_canvas_interface()const{return canvas_view_->canvas_interface();}
196 synfig::Canvas::Handle get_canvas()const{return canvas_view_->get_canvas();}
197 WorkArea * get_work_area()const{return canvas_view_->get_work_area();}
199 //Modifying settings etc.
200 void load_settings();
201 void save_settings();
204 bool egress_on_selection_change;
205 Smach::event_result event_layer_selection_changed_handler(const Smach::event& /*x*/)
207 if(egress_on_selection_change)
208 throw Smach::egress_exception();
209 return Smach::RESULT_OK;
212 void make_circle(const Point& p1, const Point& p2);
214 }; // END of class StateCircle_Context
216 /* === M E T H O D S ======================================================= */
218 StateCircle::StateCircle():
219 Smach::state<StateCircle_Context>("circle")
221 insert(event_def(EVENT_LAYER_SELECTION_CHANGED,&StateCircle_Context::event_layer_selection_changed_handler));
222 insert(event_def(EVENT_STOP,&StateCircle_Context::event_stop_handler));
223 insert(event_def(EVENT_REFRESH,&StateCircle_Context::event_refresh_handler));
224 insert(event_def(EVENT_REFRESH_DUCKS,&StateCircle_Context::event_refresh_handler));
225 insert(event_def(EVENT_WORKAREA_MOUSE_BUTTON_DOWN,&StateCircle_Context::event_mouse_click_handler));
226 insert(event_def(EVENT_WORKAREA_MOUSE_BUTTON_DRAG,&StateCircle_Context::event_mouse_click_handler));
227 insert(event_def(EVENT_WORKAREA_MOUSE_BUTTON_UP,&StateCircle_Context::event_mouse_click_handler));
228 insert(event_def(EVENT_REFRESH_TOOL_OPTIONS,&StateCircle_Context::event_refresh_tool_options));
231 StateCircle::~StateCircle()
236 StateCircle_Context::load_settings()
240 //parse the arguments yargh!
241 if(settings.get_value("circle.id",value))
246 if(settings.get_value("circle.fallofftype",value) && value != "")
247 set_falloff(atoi(value.c_str()));
251 #ifdef BLEND_METHOD_IN_TOOL_OPTIONS
252 if(settings.get_value("circle.blend",value) && value != "")
253 set_blend(atoi(value.c_str()));
255 set_blend(0);//(int)Color::BLEND_COMPOSITE); //0 should be blend composites value
256 #endif // BLEND_METHOD_IN_TOOL_OPTIONS
258 if(settings.get_value("circle.feather",value))
259 set_feather(atof(value.c_str()));
263 if(settings.get_value("circle.number_of_bline_points",value))
264 set_number_of_bline_points(atof(value.c_str()));
266 set_number_of_bline_points(4);
268 if(settings.get_value("circle.bline_point_angle_offset",value))
269 set_bline_point_angle_offset(atof(value.c_str()));
271 set_bline_point_angle_offset(0);
273 if(settings.get_value("circle.invert",value) && value != "0")
278 if(settings.get_value("circle.layer_circle",value) && value=="0")
279 set_layer_circle_flag(false);
281 set_layer_circle_flag(true);
283 if(settings.get_value("circle.layer_region",value) && value=="1")
284 set_layer_region_flag(true);
286 set_layer_region_flag(false);
288 if(settings.get_value("circle.layer_outline",value) && value=="1")
289 set_layer_outline_flag(true);
291 set_layer_outline_flag(false);
293 if(settings.get_value("circle.layer_curve_gradient",value) && value=="1")
294 set_layer_curve_gradient_flag(true);
296 set_layer_curve_gradient_flag(false);
298 if(settings.get_value("circle.layer_plant",value) && value=="1")
299 set_layer_plant_flag(true);
301 set_layer_plant_flag(false);
303 if(settings.get_value("circle.layer_link_origins",value) && value=="0")
304 set_layer_link_origins_flag(false);
306 set_layer_link_origins_flag(true);
310 StateCircle_Context::save_settings()
312 settings.set_value("circle.id",get_id());
313 settings.set_value("circle.fallofftype",strprintf("%d",get_falloff()));
314 #ifdef BLEND_METHOD_IN_TOOL_OPTIONS
315 settings.set_value("circle.blend",strprintf("%d",get_blend()));
316 #endif // BLEND_METHOD_IN_TOOL_OPTIONS
317 settings.set_value("circle.feather",strprintf("%f",(float)get_feather()));
318 settings.set_value("circle.number_of_bline_points",strprintf("%d",(int)(get_number_of_bline_points() + 0.5)));
319 settings.set_value("circle.bline_point_angle_offset",strprintf("%f",(float)get_bline_point_angle_offset()));
320 settings.set_value("circle.invert",get_invert()?"1":"0");
321 settings.set_value("circle.layer_circle",get_layer_circle_flag()?"1":"0");
322 settings.set_value("circle.layer_outline",get_layer_outline_flag()?"1":"0");
323 settings.set_value("circle.layer_region",get_layer_region_flag()?"1":"0");
324 settings.set_value("circle.layer_curve_gradient",get_layer_curve_gradient_flag()?"1":"0");
325 settings.set_value("circle.layer_plant",get_layer_plant_flag()?"1":"0");
326 settings.set_value("circle.layer_link_origins",get_layer_link_origins_flag()?"1":"0");
330 StateCircle_Context::reset()
336 StateCircle_Context::increment_id()
345 // If there is a number
346 // already at the end of the
347 // id, then remove it.
348 if(id[id.size()-1]<='9' && id[id.size()-1]>='0')
350 // figure out how many digits it is
352 (int)id.size()-1 >= digits && id[id.size()-1-digits] <= '9' && id[id.size()-1-digits] >= '0';
357 str_number=String(id,id.size()-digits,id.size());
358 id=String(id,0,id.size()-digits);
360 number=atoi(str_number.c_str());
370 // Add the number back onto the id
372 const String format(strprintf("%%0%dd",digits));
373 id+=strprintf(format.c_str(),number);
380 StateCircle_Context::StateCircle_Context(CanvasView* canvas_view):
381 canvas_view_(canvas_view),
382 is_working(*canvas_view),
383 duckmatic_push(get_work_area()),
384 prev_workarea_layer_status_(get_work_area()->get_allow_layer_clicks()),
385 settings(synfigapp::Main::get_selected_input_device()->settings()),
386 entry_id(), // value lower upper step page
387 adj_feather( 0, 0, 1, 0.01, 0.1),
388 adj_number_of_bline_points( 0, 2, 120, 1 , 1 ),
389 adj_bline_point_angle_offset( 0, -360, 360, 0.1 , 1 ),
390 spin_feather(adj_feather,0.1,3),
391 spin_number_of_bline_points(adj_number_of_bline_points,1,0),
392 spin_bline_point_angle_offset(adj_bline_point_angle_offset,1,1),
393 checkbutton_invert(_("Invert")),
394 checkbutton_layer_circle(_("Create Circle Layer")),
395 checkbutton_layer_region(_("Create Region BLine")),
396 checkbutton_layer_outline(_("Create Outline BLine")),
397 checkbutton_layer_curve_gradient(_("Create Curve Gradient BLine")),
398 checkbutton_layer_plant(_("Create Plant BLine")),
399 checkbutton_layer_link_origins(_("Link Origins"))
401 egress_on_selection_change=true;
403 // Set up the tool options dialog
404 enum_falloff.set_param_desc(ParamDesc("falloff")
405 .set_local_name(_("Falloff"))
406 .set_description(_("Determines the falloff function for the feather"))
408 .add_enum_value(CIRCLE_INTERPOLATION_LINEAR,"linear",_("Linear"))
409 .add_enum_value(CIRCLE_SQUARED,"squared",_("Squared"))
410 .add_enum_value(CIRCLE_SQRT,"sqrt",_("Square Root"))
411 .add_enum_value(CIRCLE_SIGMOND,"sigmond",_("Sigmond"))
412 .add_enum_value(CIRCLE_COSINE,"cosine",_("Cosine")));
414 #ifdef BLEND_METHOD_IN_TOOL_OPTIONS
415 enum_blend.set_param_desc(ParamDesc(Color::BLEND_COMPOSITE,"blend_method")
416 .set_local_name(_("Blend Method"))
417 .set_description(_("Defines the blend method to be used for circles")));
418 #endif // BLEND_METHOD_IN_TOOL_OPTIONS
422 options_table.attach(*manage(new Gtk::Label(_("Circle Tool"))), 0, 2, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
423 options_table.attach(entry_id, 0, 2, 1, 2, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
425 options_table.attach(checkbutton_layer_circle, 0, 2, 2, 3, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
426 options_table.attach(checkbutton_layer_outline, 0, 2, 3, 4, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
427 options_table.attach(checkbutton_layer_region, 0, 2, 4, 5, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
428 options_table.attach(checkbutton_layer_plant, 0, 2, 5, 6, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
429 options_table.attach(checkbutton_layer_curve_gradient, 0, 2, 6, 7, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
430 options_table.attach(checkbutton_layer_link_origins, 0, 2, 7, 8, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
433 options_table.attach(checkbutton_invert, 0, 2, 8, 9, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
435 options_table.attach(*manage(new Gtk::Label(_("Falloff:"))), 0, 1, 9, 10, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
436 options_table.attach(enum_falloff, 1, 2, 9, 10, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
439 options_table.attach(*manage(new Gtk::Label(_("Feather:"))), 0, 1, 10, 11, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
440 options_table.attach(spin_feather, 1, 2, 10, 11, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
442 #ifdef BLEND_METHOD_IN_TOOL_OPTIONS
443 options_table.attach(enum_blend, 0, 2, 11, 12, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
444 #endif // BLEND_METHOD_IN_TOOL_OPTIONS
446 options_table.attach(*manage(new Gtk::Label(_("BLine Points:"))), 0, 1, 12, 13, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
447 options_table.attach(spin_number_of_bline_points, 1, 2, 12, 13, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
449 options_table.attach(*manage(new Gtk::Label(_("Point Angle Offset:"))), 0, 1, 13, 14, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
450 options_table.attach(spin_bline_point_angle_offset, 1, 2, 13, 14, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
452 options_table.show_all();
454 refresh_tool_options();
455 App::dialog_tool_options->present();
457 // Turn off layer clicking
458 get_work_area()->set_allow_layer_clicks(false);
460 // clear out the ducks
461 get_work_area()->clear_ducks();
463 // Refresh the work area
464 get_work_area()->queue_draw();
466 // Hide the tables if they are showing
467 //prev_table_status=get_canvas_view()->tables_are_visible();
468 //if(prev_table_status)get_canvas_view()->hide_tables();
470 // Disable the time bar
471 //get_canvas_view()->set_sensitive_timebar(false);
474 //get_work_area()->signal_user_click().connect(sigc::mem_fun(*this,&studio::StateCircle_Context::on_user_click));
475 get_canvas_view()->work_area->set_cursor(Gdk::CROSSHAIR);
477 App::toolbox->refresh();
481 StateCircle_Context::refresh_tool_options()
483 App::dialog_tool_options->clear();
484 App::dialog_tool_options->set_widget(options_table);
485 App::dialog_tool_options->set_local_name(_("Circle Tool"));
486 App::dialog_tool_options->set_name("circle");
490 StateCircle_Context::event_refresh_tool_options(const Smach::event& /*x*/)
492 refresh_tool_options();
493 return Smach::RESULT_ACCEPT;
496 StateCircle_Context::~StateCircle_Context()
500 // Restore layer clicking
501 get_work_area()->set_allow_layer_clicks(prev_workarea_layer_status_);
502 get_canvas_view()->work_area->reset_cursor();
504 App::dialog_tool_options->clear();
506 // Enable the time bar
507 //get_canvas_view()->set_sensitive_timebar(true);
509 // Bring back the tables if they were out before
510 //if(prev_table_status)get_canvas_view()->show_tables();
512 // Refresh the work area
513 get_work_area()->queue_draw();
515 get_canvas_view()->queue_rebuild_ducks();
517 App::toolbox->refresh();
521 StateCircle_Context::event_stop_handler(const Smach::event& /*x*/)
523 throw Smach::egress_exception();
527 StateCircle_Context::event_refresh_handler(const Smach::event& /*x*/)
530 return Smach::RESULT_ACCEPT;
534 StateCircle_Context::make_circle(const Point& _p1, const Point& _p2)
536 synfigapp::Action::PassiveGrouper group(get_canvas_interface()->get_instance().get(),_("New Circle"));
537 synfigapp::PushMode push_mode(get_canvas_interface(),synfigapp::MODE_NORMAL);
541 Canvas::Handle canvas;
544 // we are temporarily using the layer to hold something
545 layer=get_canvas_view()->get_selection_manager()->get_selected_layer();
548 depth=layer->get_depth();
549 canvas=layer->get_canvas();
552 synfigapp::SelectionManager::LayerList layer_selection;
553 if (!getenv("SYNFIG_TOOLS_CLEAR_SELECTION"))
554 layer_selection = get_canvas_view()->get_selection_manager()->get_selected_layers();
556 const synfig::TransformStack& transform(get_canvas_view()->get_curr_transform_stack());
557 const Point p1(transform.unperform(_p1));
558 const Point p2(transform.unperform(_p2));
560 Real radius((p2-p1).mag());
561 int points = get_number_of_bline_points();
562 Angle::deg offset(get_bline_point_angle_offset());
563 Angle::deg angle(360.0/points);
564 Real tangent(4 * ((points == 2)
566 : ((2 * Angle::cos(angle/2).get() - Angle::cos(angle).get() - 1) / Angle::sin(angle).get())));
568 std::vector<BLinePoint> new_list;
569 for (int i = 0; i < points; i++)
571 new_list.push_back(*(new BLinePoint));
572 new_list[i].set_width(1);
573 new_list[i].set_vertex(Point(radius*Angle::cos(angle*i + offset).get(),
574 radius*Angle::sin(angle*i + offset).get()));
575 new_list[i].set_tangent(Point(-radius*tangent*Angle::sin(angle*i + offset).get(),
576 radius*tangent*Angle::cos(angle*i + offset).get()));
579 ValueNode_BLine::Handle value_node_bline(ValueNode_BLine::create(new_list));
580 assert(value_node_bline);
582 ValueNode_Const::Handle value_node_origin(ValueNode_Const::create(p1));
583 assert(value_node_origin);
585 // Set the looping flag
586 value_node_bline->set_loop(true);
589 canvas=get_canvas_view()->get_canvas();
591 value_node_bline->set_member_canvas(canvas);
593 // count how many layers we're going to be creating
594 int layers_to_create = this->layers_to_create();
596 ///////////////////////////////////////////////////////////////////////////
598 ///////////////////////////////////////////////////////////////////////////
600 if (get_layer_circle_flag() &&
601 get_falloff() >= 0 && get_falloff() < CIRCLE_NUM_FALLOFF)
603 layer=get_canvas_interface()->add_layer_to("circle",canvas,depth);
606 get_canvas_view()->get_ui_interface()->error(_("Unable to create layer"));
610 layer_selection.push_back(layer);
612 layer->set_param("origin",p1);
613 get_canvas_interface()->signal_layer_param_changed()(layer,"origin");
615 layer->set_param("radius",(p2-p1).mag());
616 get_canvas_interface()->signal_layer_param_changed()(layer,"radius");
618 layer->set_param("falloff",get_falloff());
619 get_canvas_interface()->signal_layer_param_changed()(layer,"falloff");
621 layer->set_param("feather",get_feather());
622 get_canvas_interface()->signal_layer_param_changed()(layer,"feather");
624 layer->set_param("invert",get_invert());
625 get_canvas_interface()->signal_layer_param_changed()(layer,"invert");
627 #ifdef BLEND_METHOD_IN_TOOL_OPTIONS
628 layer->set_param("blend_method",get_blend());
629 get_canvas_interface()->signal_layer_param_changed()(layer,"blend_method");
630 #endif // BLEND_METHOD_IN_TOOL_OPTIONS
632 layer->set_description(get_id());
633 get_canvas_interface()->signal_layer_new_description()(layer,layer->get_description());
635 if(get_layer_outline_flag())
637 layer->set_param("color",synfigapp::Main::get_background_color());
638 get_canvas_interface()->signal_layer_param_changed()(layer,"color");
641 // only link the circle's origin parameter if the option is selected and we're creating more than one layer
642 if (get_layer_link_origins_flag() && layers_to_create > 1)
644 synfigapp::Action::Handle action(synfigapp::Action::create("layer_param_connect"));
647 action->set_param("canvas",get_canvas());
648 action->set_param("canvas_interface",get_canvas_interface());
649 action->set_param("layer",layer);
650 if(!action->set_param("param",String("origin")))
651 synfig::error("LayerParamConnect didn't like \"param\"");
652 if(!action->set_param("value_node",ValueNode::Handle(value_node_origin)))
653 synfig::error("LayerParamConnect didn't like \"value_node\"");
655 if(!get_canvas_interface()->get_instance()->perform_action(action))
657 //get_canvas_view()->get_ui_interface()->error(_("Unable to create Circle layer"));
659 throw String(_("Unable to create Circle layer"));
665 layer->set_param("origin",p1);
666 get_canvas_interface()->signal_layer_param_changed()(layer,"origin");
670 ///////////////////////////////////////////////////////////////////////////
671 // C U R V E G R A D I E N T
672 ///////////////////////////////////////////////////////////////////////////
674 if(get_layer_curve_gradient_flag())
676 synfigapp::PushMode push_mode(get_canvas_interface(),synfigapp::MODE_NORMAL);
678 Layer::Handle layer(get_canvas_interface()->add_layer_to("curve_gradient",canvas,depth));
681 get_canvas_view()->get_ui_interface()->error(_("Unable to create layer"));
685 layer_selection.push_back(layer);
686 layer->set_description(get_id()+_(" Gradient"));
687 get_canvas_interface()->signal_layer_new_description()(layer,layer->get_description());
689 #ifdef BLEND_METHOD_IN_TOOL_OPTIONS
690 layer->set_param("blend_method",get_blend());
691 get_canvas_interface()->signal_layer_param_changed()(layer,"blend_method");
692 #endif // BLEND_METHOD_IN_TOOL_OPTIONS
695 synfigapp::Action::Handle action(synfigapp::Action::create("layer_param_connect"));
698 action->set_param("canvas",get_canvas());
699 action->set_param("canvas_interface",get_canvas_interface());
700 action->set_param("layer",layer);
701 if(!action->set_param("param",String("bline")))
702 synfig::error("LayerParamConnect didn't like \"param\"");
703 if(!action->set_param("value_node",ValueNode::Handle(value_node_bline)))
704 synfig::error("LayerParamConnect didn't like \"value_node\"");
706 if(!get_canvas_interface()->get_instance()->perform_action(action))
708 //get_canvas_view()->get_ui_interface()->error(_("Unable to create BLine layer"));
710 throw String(_("Unable to create Gradient layer"));
715 // only link the curve gradient's origin parameter if the option is selected and we're creating more than one layer
716 if (get_layer_link_origins_flag() && layers_to_create > 1)
718 synfigapp::Action::Handle action(synfigapp::Action::create("layer_param_connect"));
721 action->set_param("canvas",get_canvas());
722 action->set_param("canvas_interface",get_canvas_interface());
723 action->set_param("layer",layer);
724 if(!action->set_param("param",String("origin")))
725 synfig::error("LayerParamConnect didn't like \"param\"");
726 if(!action->set_param("value_node",ValueNode::Handle(value_node_origin)))
727 synfig::error("LayerParamConnect didn't like \"value_node\"");
729 if(!get_canvas_interface()->get_instance()->perform_action(action))
731 //get_canvas_view()->get_ui_interface()->error(_("Unable to create BLine layer"));
733 throw String(_("Unable to create Gradient layer"));
739 layer->set_param("origin",p1);
740 get_canvas_interface()->signal_layer_param_changed()(layer,"origin");
744 ///////////////////////////////////////////////////////////////////////////
746 ///////////////////////////////////////////////////////////////////////////
748 if(get_layer_plant_flag())
750 synfigapp::PushMode push_mode(get_canvas_interface(),synfigapp::MODE_NORMAL);
752 Layer::Handle layer(get_canvas_interface()->add_layer_to("plant",canvas,depth));
755 get_canvas_view()->get_ui_interface()->error(_("Unable to create layer"));
759 layer_selection.push_back(layer);
760 layer->set_description(get_id()+_(" Plant"));
761 get_canvas_interface()->signal_layer_new_description()(layer,layer->get_description());
763 #ifdef BLEND_METHOD_IN_TOOL_OPTIONS
764 layer->set_param("blend_method",get_blend());
765 get_canvas_interface()->signal_layer_param_changed()(layer,"blend_method");
766 #endif // BLEND_METHOD_IN_TOOL_OPTIONS
769 synfigapp::Action::Handle action(synfigapp::Action::create("layer_param_connect"));
772 action->set_param("canvas",get_canvas());
773 action->set_param("canvas_interface",get_canvas_interface());
774 action->set_param("layer",layer);
775 if(!action->set_param("param",String("bline")))
776 synfig::error("LayerParamConnect didn't like \"param\"");
777 if(!action->set_param("value_node",ValueNode::Handle(value_node_bline)))
778 synfig::error("LayerParamConnect didn't like \"value_node\"");
780 if(!get_canvas_interface()->get_instance()->perform_action(action))
782 //get_canvas_view()->get_ui_interface()->error(_("Unable to create BLine layer"));
784 throw String(_("Unable to create Plant layer"));
789 // only link the plant's origin parameter if the option is selected and we're creating more than one layer
790 if (get_layer_link_origins_flag() && layers_to_create > 1)
792 synfigapp::Action::Handle action(synfigapp::Action::create("layer_param_connect"));
795 action->set_param("canvas",get_canvas());
796 action->set_param("canvas_interface",get_canvas_interface());
797 action->set_param("layer",layer);
798 if(!action->set_param("param",String("origin")))
799 synfig::error("LayerParamConnect didn't like \"param\"");
800 if(!action->set_param("value_node",ValueNode::Handle(value_node_origin)))
801 synfig::error("LayerParamConnect didn't like \"value_node\"");
803 if(!get_canvas_interface()->get_instance()->perform_action(action))
805 //get_canvas_view()->get_ui_interface()->error(_("Unable to create BLine layer"));
807 throw String(_("Unable to create Plant layer"));
813 layer->set_param("origin",p1);
814 get_canvas_interface()->signal_layer_param_changed()(layer,"origin");
818 ///////////////////////////////////////////////////////////////////////////
820 ///////////////////////////////////////////////////////////////////////////
822 if(get_layer_region_flag())
824 synfigapp::PushMode push_mode(get_canvas_interface(),synfigapp::MODE_NORMAL);
826 Layer::Handle layer(get_canvas_interface()->add_layer_to("region",canvas,depth));
829 get_canvas_view()->get_ui_interface()->error(_("Unable to create layer"));
833 layer_selection.push_back(layer);
834 layer->set_description(get_id()+_(" Region"));
835 get_canvas_interface()->signal_layer_new_description()(layer,layer->get_description());
837 #ifdef BLEND_METHOD_IN_TOOL_OPTIONS
838 layer->set_param("blend_method",get_blend());
839 get_canvas_interface()->signal_layer_param_changed()(layer,"blend_method");
840 #endif // BLEND_METHOD_IN_TOOL_OPTIONS
842 layer->set_param("feather",get_feather());
843 get_canvas_interface()->signal_layer_param_changed()(layer,"feather");
845 layer->set_param("invert",get_invert());
846 get_canvas_interface()->signal_layer_param_changed()(layer,"invert");
848 if(get_layer_outline_flag())
849 layer->set_param("color",synfigapp::Main::get_background_color());
851 // I don't know if it's safe to reuse the same layer_param_connect action, so I'm
852 // using 2 separate ones.
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 Region layer"));
869 throw String(_("Unable to create Region layer"));
874 // only link the region'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 Region layer"));
892 throw String(_("Unable to create Region layer"));
898 layer->set_param("origin",p1);
899 get_canvas_interface()->signal_layer_param_changed()(layer,"origin");
903 ///////////////////////////////////////////////////////////////////////////
905 ///////////////////////////////////////////////////////////////////////////
907 if (get_layer_outline_flag())
909 Layer::Handle layer(get_canvas_interface()->add_layer_to("outline",canvas,depth));
912 get_canvas_view()->get_ui_interface()->error(_("Unable to create layer"));
916 layer_selection.push_back(layer);
917 layer->set_description(get_id()+_(" Outline"));
918 get_canvas_interface()->signal_layer_new_description()(layer,layer->get_description());
920 #ifdef BLEND_METHOD_IN_TOOL_OPTIONS
921 layer->set_param("blend_method",get_blend());
922 get_canvas_interface()->signal_layer_param_changed()(layer,"blend_method");
923 #endif // BLEND_METHOD_IN_TOOL_OPTIONS
925 layer->set_param("feather",get_feather());
926 get_canvas_interface()->signal_layer_param_changed()(layer,"feather");
928 layer->set_param("invert",get_invert());
929 get_canvas_interface()->signal_layer_param_changed()(layer,"invert");
932 synfigapp::Action::Handle action(synfigapp::Action::create("layer_param_connect"));
935 action->set_param("canvas",get_canvas());
936 action->set_param("canvas_interface",get_canvas_interface());
937 action->set_param("layer",layer);
938 if(!action->set_param("param",String("bline")))
939 synfig::error("LayerParamConnect didn't like \"param\"");
940 if(!action->set_param("value_node",ValueNode::Handle(value_node_bline)))
941 synfig::error("LayerParamConnect didn't like \"value_node\"");
943 if(!get_canvas_interface()->get_instance()->perform_action(action))
945 //get_canvas_view()->get_ui_interface()->error(_("Unable to create BLine layer"));
947 throw String(_("Unable to create Outline layer"));
952 // only link the outline's origin parameter if the option is selected and we're creating more than one layer
953 if (get_layer_link_origins_flag() && layers_to_create > 1)
955 synfigapp::Action::Handle action(synfigapp::Action::create("layer_param_connect"));
958 action->set_param("canvas",get_canvas());
959 action->set_param("canvas_interface",get_canvas_interface());
960 action->set_param("layer",layer);
961 if(!action->set_param("param",String("origin")))
962 synfig::error("LayerParamConnect didn't like \"param\"");
963 if(!action->set_param("value_node",ValueNode::Handle(value_node_origin)))
964 synfig::error("LayerParamConnect didn't like \"value_node\"");
966 if(!get_canvas_interface()->get_instance()->perform_action(action))
968 //get_canvas_view()->get_ui_interface()->error(_("Unable to create BLine layer"));
970 throw String(_("Unable to create Outline layer"));
976 layer->set_param("origin",p1);
977 get_canvas_interface()->signal_layer_param_changed()(layer,"origin");
981 egress_on_selection_change=false;
982 get_canvas_interface()->get_selection_manager()->clear_selected_layers();
983 get_canvas_interface()->get_selection_manager()->set_selected_layers(layer_selection);
984 egress_on_selection_change=true;
991 StateCircle_Context::event_mouse_click_handler(const Smach::event& x)
993 const EventMouse& event(*reinterpret_cast<const EventMouse*>(&x));
995 if(event.key==EVENT_WORKAREA_MOUSE_BUTTON_DOWN && event.button==BUTTON_LEFT)
997 point_holder=get_work_area()->snap_point_to_grid(event.pos);
998 etl::handle<Duck> duck=new Duck();
999 duck->set_point(point_holder);
1000 duck->set_name("p1");
1001 duck->set_type(Duck::TYPE_POSITION);
1002 duck->set_editable(false);
1003 get_work_area()->add_duck(duck);
1005 point2_duck=new Duck();
1006 point2_duck->set_point(Vector(0,0));
1007 point2_duck->set_name("radius");
1008 point2_duck->set_origin(duck);
1009 point2_duck->set_radius(true);
1010 point2_duck->set_scalar(-1);
1011 point2_duck->set_type(Duck::TYPE_RADIUS);
1012 point2_duck->set_hover(true);
1013 get_work_area()->add_duck(point2_duck);
1015 return Smach::RESULT_ACCEPT;
1018 if(event.key==EVENT_WORKAREA_MOUSE_BUTTON_DRAG && event.button==BUTTON_LEFT)
1020 if (!point2_duck) return Smach::RESULT_OK;
1021 point2_duck->set_point(point_holder-get_work_area()->snap_point_to_grid(event.pos));
1022 get_work_area()->queue_draw();
1023 return Smach::RESULT_ACCEPT;
1026 if(event.key==EVENT_WORKAREA_MOUSE_BUTTON_UP && event.button==BUTTON_LEFT)
1028 Point point(get_work_area()->snap_point_to_grid(event.pos));
1030 if (App::restrict_radius_ducks)
1032 if ((point[0] - point_holder[0]) < 0) point[0] = point_holder[0];
1033 if ((point[1] - point_holder[1]) < 0) point[1] = point_holder[1];
1036 make_circle(point_holder, point);
1037 get_work_area()->clear_ducks();
1038 return Smach::RESULT_ACCEPT;
1041 return Smach::RESULT_OK;
1046 StateCircle_Context::refresh_ducks()
1048 get_work_area()->clear_ducks();
1049 get_work_area()->queue_draw();