1 /* === S Y N F I G ========================================================= */
2 /*! \file state_star.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_star.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 ========================================================= */
68 /* === G L O B A L S ======================================================= */
70 StateStar studio::state_star;
72 /* === C L A S S E S & S T R U C T S ======================================= */
74 class studio::StateStar_Context : public sigc::trackable
76 etl::handle<CanvasView> canvas_view_;
77 CanvasView::IsWorking is_working;
79 Duckmatic::Push duckmatic_push;
83 etl::handle<Duck> point2_duck;
87 bool prev_workarea_layer_status_;
90 synfigapp::Settings& settings;
93 Gtk::Table options_table;
95 Gtk::Entry entry_id; //what to name the layer
97 Gtk::Adjustment adj_feather;
98 Gtk::Adjustment adj_number_of_points;
99 Gtk::Adjustment adj_inner_tangent;
100 Gtk::Adjustment adj_outer_tangent;
101 Gtk::Adjustment adj_inner_width;
102 Gtk::Adjustment adj_outer_width;
103 Gtk::Adjustment adj_radius_ratio;
104 Gtk::Adjustment adj_angle_offset;
105 Gtk::SpinButton spin_feather;
106 Gtk::SpinButton spin_number_of_points;
107 Gtk::SpinButton spin_inner_tangent;
108 Gtk::SpinButton spin_outer_tangent;
109 Gtk::SpinButton spin_inner_width;
110 Gtk::SpinButton spin_outer_width;
111 Gtk::SpinButton spin_radius_ratio;
112 Gtk::SpinButton spin_angle_offset;
114 Gtk::CheckButton checkbutton_invert;
115 Gtk::CheckButton checkbutton_regular_polygon;
116 Gtk::CheckButton checkbutton_layer_star;
117 Gtk::CheckButton checkbutton_layer_region;
118 Gtk::CheckButton checkbutton_layer_outline;
119 Gtk::CheckButton checkbutton_layer_curve_gradient;
120 Gtk::CheckButton checkbutton_layer_plant;
121 Gtk::CheckButton checkbutton_layer_link_origins;
125 // this only counts the layers which use blines - they're the only
126 // ones we link the origins for
127 int layers_to_create()const
130 get_layer_star_flag() +
131 get_layer_region_flag() +
132 get_layer_outline_flag() +
133 get_layer_curve_gradient_flag() +
134 get_layer_plant_flag();
137 synfig::String get_id()const { return entry_id.get_text(); }
138 void set_id(const synfig::String& x) { return entry_id.set_text(x); }
140 Real get_feather()const { return adj_feather.get_value(); }
141 void set_feather(Real f) { adj_feather.set_value(f); }
143 Real get_number_of_points()const { return adj_number_of_points.get_value(); }
144 void set_number_of_points(Real f) { adj_number_of_points.set_value(f); }
146 Real get_inner_tangent()const { return adj_inner_tangent.get_value(); }
147 void set_inner_tangent(Real f) { adj_inner_tangent.set_value(f); }
149 Real get_outer_tangent()const { return adj_outer_tangent.get_value(); }
150 void set_outer_tangent(Real f) { adj_outer_tangent.set_value(f); }
152 Real get_inner_width()const { return adj_inner_width.get_value(); }
153 void set_inner_width(Real f) { adj_inner_width.set_value(f); }
155 Real get_outer_width()const { return adj_outer_width.get_value(); }
156 void set_outer_width(Real f) { adj_outer_width.set_value(f); }
158 Real get_radius_ratio()const { return adj_radius_ratio.get_value(); }
159 void set_radius_ratio(Real f) { adj_radius_ratio.set_value(f); }
161 Real get_angle_offset()const { return adj_angle_offset.get_value(); }
162 void set_angle_offset(Real f) { adj_angle_offset.set_value(f); }
164 bool get_invert()const { return checkbutton_invert.get_active(); }
165 void set_invert(bool i) { checkbutton_invert.set_active(i); }
167 bool get_regular_polygon()const { return checkbutton_regular_polygon.get_active(); }
168 void set_regular_polygon(bool i) { checkbutton_regular_polygon.set_active(i); }
170 bool get_layer_star_flag()const { return checkbutton_layer_star.get_active(); }
171 void set_layer_star_flag(bool x) { return checkbutton_layer_star.set_active(x); }
173 bool get_layer_region_flag()const { return checkbutton_layer_region.get_active(); }
174 void set_layer_region_flag(bool x) { return checkbutton_layer_region.set_active(x); }
176 bool get_layer_outline_flag()const { return checkbutton_layer_outline.get_active(); }
177 void set_layer_outline_flag(bool x) { return checkbutton_layer_outline.set_active(x); }
179 bool get_layer_curve_gradient_flag()const { return checkbutton_layer_curve_gradient.get_active(); }
180 void set_layer_curve_gradient_flag(bool x) { return checkbutton_layer_curve_gradient.set_active(x); }
182 bool get_layer_plant_flag()const { return checkbutton_layer_plant.get_active(); }
183 void set_layer_plant_flag(bool x) { return checkbutton_layer_plant.set_active(x); }
185 bool get_layer_link_origins_flag()const { return checkbutton_layer_link_origins.get_active(); }
186 void set_layer_link_origins_flag(bool x) { return checkbutton_layer_link_origins.set_active(x); }
188 void refresh_tool_options(); //to refresh the toolbox
191 Smach::event_result event_stop_handler(const Smach::event& x);
192 Smach::event_result event_refresh_handler(const Smach::event& x);
193 Smach::event_result event_mouse_click_handler(const Smach::event& x);
194 Smach::event_result event_refresh_tool_options(const Smach::event& x);
196 //constructor destructor
197 StateStar_Context(CanvasView* canvas_view);
198 ~StateStar_Context();
201 const etl::handle<CanvasView>& get_canvas_view()const{return canvas_view_;}
202 etl::handle<synfigapp::CanvasInterface> get_canvas_interface()const{return canvas_view_->canvas_interface();}
203 synfig::Canvas::Handle get_canvas()const{return canvas_view_->get_canvas();}
204 WorkArea * get_work_area()const{return canvas_view_->get_work_area();}
206 //Modifying settings etc.
207 void load_settings();
208 void save_settings();
211 bool egress_on_selection_change;
212 Smach::event_result event_layer_selection_changed_handler(const Smach::event& /*x*/)
214 if(egress_on_selection_change)
215 throw Smach::egress_exception();
216 return Smach::RESULT_OK;
219 void make_star(const Point& p1, const Point& p2);
221 }; // END of class StateStar_Context
223 /* === M E T H O D S ======================================================= */
225 StateStar::StateStar():
226 Smach::state<StateStar_Context>("star")
228 insert(event_def(EVENT_LAYER_SELECTION_CHANGED,&StateStar_Context::event_layer_selection_changed_handler));
229 insert(event_def(EVENT_STOP,&StateStar_Context::event_stop_handler));
230 insert(event_def(EVENT_REFRESH,&StateStar_Context::event_refresh_handler));
231 insert(event_def(EVENT_REFRESH_DUCKS,&StateStar_Context::event_refresh_handler));
232 insert(event_def(EVENT_WORKAREA_MOUSE_BUTTON_DOWN,&StateStar_Context::event_mouse_click_handler));
233 insert(event_def(EVENT_WORKAREA_MOUSE_BUTTON_DRAG,&StateStar_Context::event_mouse_click_handler));
234 insert(event_def(EVENT_WORKAREA_MOUSE_BUTTON_UP,&StateStar_Context::event_mouse_click_handler));
235 insert(event_def(EVENT_REFRESH_TOOL_OPTIONS,&StateStar_Context::event_refresh_tool_options));
238 StateStar::~StateStar()
243 StateStar_Context::load_settings()
247 //parse the arguments yargh!
248 if(settings.get_value("star.id",value))
253 if(settings.get_value("star.feather",value))
254 set_feather(atof(value.c_str()));
258 if(settings.get_value("star.number_of_points",value))
259 set_number_of_points(atof(value.c_str()));
261 set_number_of_points(5);
263 if(settings.get_value("star.inner_tangent",value))
264 set_inner_tangent(atof(value.c_str()));
266 set_inner_tangent(0);
268 if(settings.get_value("star.outer_tangent",value))
269 set_outer_tangent(atof(value.c_str()));
271 set_outer_tangent(0);
273 if(settings.get_value("star.inner_width",value))
274 set_inner_width(atof(value.c_str()));
278 if(settings.get_value("star.outer_width",value))
279 set_outer_width(atof(value.c_str()));
283 if(settings.get_value("star.radius_ratio",value))
284 set_radius_ratio(atof(value.c_str()));
286 set_radius_ratio(0.5);
288 if(settings.get_value("star.angle_offset",value))
289 set_angle_offset(atof(value.c_str()));
293 if(settings.get_value("star.invert",value) && value != "0")
298 if(settings.get_value("star.regular_polygon",value) && value != "0")
299 set_regular_polygon(true);
301 set_regular_polygon(false);
303 if(settings.get_value("star.layer_star",value) && value=="0")
304 set_layer_star_flag(false);
306 set_layer_star_flag(true);
308 if(settings.get_value("star.layer_region",value) && value=="1")
309 set_layer_region_flag(true);
311 set_layer_region_flag(false);
313 if(settings.get_value("star.layer_outline",value) && value=="1")
314 set_layer_outline_flag(true);
316 set_layer_outline_flag(false);
318 if(settings.get_value("star.layer_curve_gradient",value) && value=="1")
319 set_layer_curve_gradient_flag(true);
321 set_layer_curve_gradient_flag(false);
323 if(settings.get_value("star.layer_plant",value) && value=="1")
324 set_layer_plant_flag(true);
326 set_layer_plant_flag(false);
328 if(settings.get_value("star.layer_link_origins",value) && value=="0")
329 set_layer_link_origins_flag(false);
331 set_layer_link_origins_flag(true);
335 StateStar_Context::save_settings()
337 settings.set_value("star.id",get_id());
338 settings.set_value("star.feather",strprintf("%f",(float)get_feather()));
339 settings.set_value("star.number_of_points",strprintf("%d",(int)(get_number_of_points() + 0.5)));
340 settings.set_value("star.inner_tangent",strprintf("%f",(float)get_inner_tangent()));
341 settings.set_value("star.outer_tangent",strprintf("%f",(float)get_outer_tangent()));
342 settings.set_value("star.inner_width",strprintf("%f",(float)get_inner_width()));
343 settings.set_value("star.outer_width",strprintf("%f",(float)get_outer_width()));
344 settings.set_value("star.radius_ratio",strprintf("%f",(float)get_radius_ratio()));
345 settings.set_value("star.angle_offset",strprintf("%f",(float)get_angle_offset()));
346 settings.set_value("star.invert",get_invert()?"1":"0");
347 settings.set_value("star.regular_polygon",get_regular_polygon()?"1":"0");
348 settings.set_value("star.layer_star",get_layer_star_flag()?"1":"0");
349 settings.set_value("star.layer_outline",get_layer_outline_flag()?"1":"0");
350 settings.set_value("star.layer_region",get_layer_region_flag()?"1":"0");
351 settings.set_value("star.layer_curve_gradient",get_layer_curve_gradient_flag()?"1":"0");
352 settings.set_value("star.layer_plant",get_layer_plant_flag()?"1":"0");
353 settings.set_value("star.layer_link_origins",get_layer_link_origins_flag()?"1":"0");
357 StateStar_Context::reset()
363 StateStar_Context::increment_id()
372 // If there is a number
373 // already at the end of the
374 // id, then remove it.
375 if(id[id.size()-1]<='9' && id[id.size()-1]>='0')
377 // figure out how many digits it is
379 (int)id.size()-1 >= digits && id[id.size()-1-digits] <= '9' && id[id.size()-1-digits] >= '0';
384 str_number=String(id,id.size()-digits,id.size());
385 id=String(id,0,id.size()-digits);
387 number=atoi(str_number.c_str());
397 // Add the number back onto the id
399 const String format(strprintf("%%0%dd",digits));
400 id+=strprintf(format.c_str(),number);
407 StateStar_Context::StateStar_Context(CanvasView* canvas_view):
408 canvas_view_(canvas_view),
409 is_working(*canvas_view),
410 duckmatic_push(get_work_area()),
411 prev_workarea_layer_status_(get_work_area()->get_allow_layer_clicks()),
412 settings(synfigapp::Main::get_selected_input_device()->settings()),
413 entry_id(), // value lower upper step page
414 adj_feather( 0, 0, 1, 0.01, 0.1),
415 adj_number_of_points( 0, 2, 120, 1 , 1 ),
416 adj_inner_tangent( 0, -10, 10, 0.01, 0.1),
417 adj_outer_tangent( 0, -10, 10, 0.01, 0.1),
418 adj_inner_width( 0, -10, 10, 0.01, 0.1),
419 adj_outer_width( 0, -10, 10, 0.01, 0.1),
420 adj_radius_ratio( 0, -10, 10, 0.01, 0.1),
421 adj_angle_offset( 0, -360, 360, 0.1 , 1 ),
422 spin_feather(adj_feather,0.1,3),
423 spin_number_of_points(adj_number_of_points,1,0),
424 spin_inner_tangent(adj_inner_tangent,1,2),
425 spin_outer_tangent(adj_outer_tangent,1,2),
426 spin_inner_width(adj_inner_width,1,2),
427 spin_outer_width(adj_outer_width,1,2),
428 spin_radius_ratio(adj_radius_ratio,1,2),
429 spin_angle_offset(adj_angle_offset,1,1),
430 checkbutton_invert(_("Invert")),
431 checkbutton_regular_polygon(_("Regular Polygon")),
432 checkbutton_layer_star(_("Create Star Layer")),
433 checkbutton_layer_region(_("Create Region BLine")),
434 checkbutton_layer_outline(_("Create Outline BLine")),
435 checkbutton_layer_curve_gradient(_("Create Curve Gradient BLine")),
436 checkbutton_layer_plant(_("Create Plant BLine")),
437 checkbutton_layer_link_origins(_("Link Origins"))
439 egress_on_selection_change=true;
443 // Set up the tool options dialog
444 options_table.attach(*manage(new Gtk::Label(_("Star Tool"))), 0, 2, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
445 options_table.attach(entry_id, 0, 2, 1, 2, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
446 options_table.attach(checkbutton_layer_star, 0, 2, 2, 3, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
447 options_table.attach(checkbutton_layer_outline, 0, 2, 3, 4, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
448 options_table.attach(checkbutton_layer_region, 0, 2, 4, 5, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
449 options_table.attach(checkbutton_layer_plant, 0, 2, 5, 6, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
450 options_table.attach(checkbutton_layer_curve_gradient, 0, 2, 6, 7, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
451 options_table.attach(checkbutton_layer_link_origins, 0, 2, 7, 8, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
452 options_table.attach(checkbutton_invert, 0, 2, 8, 9, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
453 options_table.attach(checkbutton_regular_polygon, 0, 2, 9, 10, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
454 options_table.attach(*manage(new Gtk::Label(_("Feather:"))), 0, 1, 10, 11, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
455 options_table.attach(spin_feather, 1, 2, 10, 11, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
456 options_table.attach(*manage(new Gtk::Label(_("Number of Points:"))), 0, 1, 11, 12, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
457 options_table.attach(spin_number_of_points, 1, 2, 11, 12, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
458 options_table.attach(*manage(new Gtk::Label(_("Inner Tangent:"))), 0, 1, 12, 13, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
459 options_table.attach(spin_inner_tangent, 1, 2, 12, 13, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
460 options_table.attach(*manage(new Gtk::Label(_("Outer Tangent:"))), 0, 1, 13, 14, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
461 options_table.attach(spin_outer_tangent, 1, 2, 13, 14, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
462 options_table.attach(*manage(new Gtk::Label(_("Inner Width:"))), 0, 1, 14, 15, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
463 options_table.attach(spin_inner_width, 1, 2, 14, 15, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
464 options_table.attach(*manage(new Gtk::Label(_("Outer Width:"))), 0, 1, 15, 16, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
465 options_table.attach(spin_outer_width, 1, 2, 15, 16, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
466 options_table.attach(*manage(new Gtk::Label(_("Radius Ratio:"))), 0, 1, 16, 17, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
467 options_table.attach(spin_radius_ratio, 1, 2, 16, 17, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
468 options_table.attach(*manage(new Gtk::Label(_("Angle Offset:"))), 0, 1, 17, 18, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
469 options_table.attach(spin_angle_offset, 1, 2, 17, 18, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
471 options_table.show_all();
473 refresh_tool_options();
474 App::dialog_tool_options->present();
476 // Turn off layer clicking
477 get_work_area()->set_allow_layer_clicks(false);
479 // clear out the ducks
480 get_work_area()->clear_ducks();
482 // Refresh the work area
483 get_work_area()->queue_draw();
485 // Hide the tables if they are showing
486 //prev_table_status=get_canvas_view()->tables_are_visible();
487 //if(prev_table_status)get_canvas_view()->hide_tables();
489 // Disable the time bar
490 //get_canvas_view()->set_sensitive_timebar(false);
493 //get_work_area()->signal_user_click().connect(sigc::mem_fun(*this,&studio::StateStar_Context::on_user_click));
494 get_canvas_view()->work_area->set_cursor(Gdk::CROSSHAIR);
496 App::toolbox->refresh();
500 StateStar_Context::refresh_tool_options()
502 App::dialog_tool_options->clear();
503 App::dialog_tool_options->set_widget(options_table);
504 App::dialog_tool_options->set_local_name(_("Star Tool"));
505 App::dialog_tool_options->set_name("star");
509 StateStar_Context::event_refresh_tool_options(const Smach::event& /*x*/)
511 refresh_tool_options();
512 return Smach::RESULT_ACCEPT;
515 StateStar_Context::~StateStar_Context()
519 // Restore layer clicking
520 get_work_area()->set_allow_layer_clicks(prev_workarea_layer_status_);
521 get_canvas_view()->work_area->reset_cursor();
523 App::dialog_tool_options->clear();
525 // Enable the time bar
526 //get_canvas_view()->set_sensitive_timebar(true);
528 // Bring back the tables if they were out before
529 //if(prev_table_status)get_canvas_view()->show_tables();
531 // Refresh the work area
532 get_work_area()->queue_draw();
534 get_canvas_view()->queue_rebuild_ducks();
536 App::toolbox->refresh();
540 StateStar_Context::event_stop_handler(const Smach::event& /*x*/)
542 throw Smach::egress_exception();
546 StateStar_Context::event_refresh_handler(const Smach::event& /*x*/)
549 return Smach::RESULT_ACCEPT;
553 StateStar_Context::make_star(const Point& _p1, const Point& _p2)
555 synfigapp::Action::PassiveGrouper group(get_canvas_interface()->get_instance().get(),_("New Star"));
556 synfigapp::PushMode push_mode(get_canvas_interface(),synfigapp::MODE_NORMAL);
560 Canvas::Handle canvas;
563 // we are temporarily using the layer to hold something
564 layer=get_canvas_view()->get_selection_manager()->get_selected_layer();
567 depth=layer->get_depth();
568 canvas=layer->get_canvas();
571 synfigapp::SelectionManager::LayerList layer_selection;
572 if (!getenv("SYNFIG_TOOLS_CLEAR_SELECTION"))
573 layer_selection = get_canvas_view()->get_selection_manager()->get_selected_layers();
575 const synfig::TransformStack& transform(get_canvas_view()->get_curr_transform_stack());
576 const Point p1(transform.unperform(_p1));
577 const Point p2(transform.unperform(_p2));
579 Real radius_ratio(get_radius_ratio());
580 Real radius1((p2-p1).mag());
581 Real radius2(radius1 * radius_ratio);
582 int points = get_number_of_points();
583 Real inner_tangent = get_inner_tangent() * radius1;
584 Real outer_tangent = get_outer_tangent() * radius2;
585 Real inner_width = get_inner_width();
586 Real outer_width = get_outer_width();
587 Angle::deg offset(get_angle_offset());
588 bool regular(get_regular_polygon());
589 Angle::deg angle(360.0/points);
591 std::vector<BLinePoint> new_list;
593 for (int i = 0; i < points; i++)
595 new_list.push_back(*(new BLinePoint));
596 new_list[point].set_width(outer_width);
597 new_list[point].set_vertex(Point(radius1*Angle::cos(angle*i + offset).get(),
598 radius1*Angle::sin(angle*i + offset).get()));
599 new_list[point++].set_tangent(Point(-Angle::sin(angle*i + offset).get(),
600 Angle::cos(angle*i + offset).get()) * outer_tangent);
604 new_list.push_back(*(new BLinePoint));
605 new_list[point].set_width(inner_width);
606 new_list[point].set_vertex(Point(radius2*Angle::cos(angle*i + angle/2 + offset).get(),
607 radius2*Angle::sin(angle*i + angle/2 + offset).get()));
608 new_list[point++].set_tangent(Point(-Angle::sin(angle*i + angle/2 + offset).get(),
609 Angle::cos(angle*i + angle/2 + offset).get()) * inner_tangent);
613 ValueNode_BLine::Handle value_node_bline(ValueNode_BLine::create(new_list));
614 assert(value_node_bline);
616 ValueNode_Const::Handle value_node_origin(ValueNode_Const::create(p1));
617 assert(value_node_origin);
619 // Set the looping flag
620 value_node_bline->set_loop(true);
623 canvas=get_canvas_view()->get_canvas();
625 value_node_bline->set_member_canvas(canvas);
627 // count how many layers we're going to be creating
628 int layers_to_create = this->layers_to_create();
630 ///////////////////////////////////////////////////////////////////////////
632 ///////////////////////////////////////////////////////////////////////////
634 if (get_layer_star_flag())
636 layer=get_canvas_interface()->add_layer_to("star",canvas,depth);
639 get_canvas_view()->get_ui_interface()->error(_("Unable to create layer"));
643 layer_selection.push_back(layer);
645 layer->set_param("origin",p1);
646 get_canvas_interface()->signal_layer_param_changed()(layer,"origin");
648 layer->set_param("radius1",radius1);
649 get_canvas_interface()->signal_layer_param_changed()(layer,"radius1");
651 layer->set_param("radius2",radius2);
652 get_canvas_interface()->signal_layer_param_changed()(layer,"radius2");
654 layer->set_param("angle",offset);
655 get_canvas_interface()->signal_layer_param_changed()(layer,"angle");
657 layer->set_param("points",points);
658 get_canvas_interface()->signal_layer_param_changed()(layer,"points");
660 layer->set_param("regular_polygon",regular);
661 get_canvas_interface()->signal_layer_param_changed()(layer,"regular_polygon");
663 layer->set_param("feather",get_feather());
664 get_canvas_interface()->signal_layer_param_changed()(layer,"feather");
666 layer->set_param("invert",get_invert());
667 get_canvas_interface()->signal_layer_param_changed()(layer,"invert");
669 layer->set_description(get_id());
670 get_canvas_interface()->signal_layer_new_description()(layer,layer->get_description());
672 if(get_layer_outline_flag())
674 layer->set_param("color",synfigapp::Main::get_background_color());
675 get_canvas_interface()->signal_layer_param_changed()(layer,"color");
678 // only link the star's origin parameter if the option is selected and we're creating more than one layer
679 if (get_layer_link_origins_flag() && layers_to_create > 1)
681 synfigapp::Action::Handle action(synfigapp::Action::create("layer_param_connect"));
684 action->set_param("canvas",get_canvas());
685 action->set_param("canvas_interface",get_canvas_interface());
686 action->set_param("layer",layer);
687 if(!action->set_param("param",String("origin")))
688 synfig::error("LayerParamConnect didn't like \"param\"");
689 if(!action->set_param("value_node",ValueNode::Handle(value_node_origin)))
690 synfig::error("LayerParamConnect didn't like \"value_node\"");
692 if(!get_canvas_interface()->get_instance()->perform_action(action))
694 //get_canvas_view()->get_ui_interface()->error(_("Unable to create Star layer"));
696 throw String(_("Unable to create Star layer"));
702 layer->set_param("origin",p1);
703 get_canvas_interface()->signal_layer_param_changed()(layer,"origin");
707 ///////////////////////////////////////////////////////////////////////////
708 // C U R V E G R A D I E N T
709 ///////////////////////////////////////////////////////////////////////////
711 if(get_layer_curve_gradient_flag())
713 synfigapp::PushMode push_mode(get_canvas_interface(),synfigapp::MODE_NORMAL);
715 Layer::Handle layer(get_canvas_interface()->add_layer_to("curve_gradient",canvas,depth));
718 get_canvas_view()->get_ui_interface()->error(_("Unable to create layer"));
722 layer_selection.push_back(layer);
723 layer->set_description(get_id()+_(" Gradient"));
724 get_canvas_interface()->signal_layer_new_description()(layer,layer->get_description());
727 synfigapp::Action::Handle action(synfigapp::Action::create("layer_param_connect"));
730 action->set_param("canvas",get_canvas());
731 action->set_param("canvas_interface",get_canvas_interface());
732 action->set_param("layer",layer);
733 if(!action->set_param("param",String("bline")))
734 synfig::error("LayerParamConnect didn't like \"param\"");
735 if(!action->set_param("value_node",ValueNode::Handle(value_node_bline)))
736 synfig::error("LayerParamConnect didn't like \"value_node\"");
738 if(!get_canvas_interface()->get_instance()->perform_action(action))
740 //get_canvas_view()->get_ui_interface()->error(_("Unable to create BLine layer"));
742 throw String(_("Unable to create Gradient layer"));
747 // only link the curve gradient's origin parameter if the option is selected and we're creating more than one layer
748 if (get_layer_link_origins_flag() && layers_to_create > 1)
750 synfigapp::Action::Handle action(synfigapp::Action::create("layer_param_connect"));
753 action->set_param("canvas",get_canvas());
754 action->set_param("canvas_interface",get_canvas_interface());
755 action->set_param("layer",layer);
756 if(!action->set_param("param",String("origin")))
757 synfig::error("LayerParamConnect didn't like \"param\"");
758 if(!action->set_param("value_node",ValueNode::Handle(value_node_origin)))
759 synfig::error("LayerParamConnect didn't like \"value_node\"");
761 if(!get_canvas_interface()->get_instance()->perform_action(action))
763 //get_canvas_view()->get_ui_interface()->error(_("Unable to create BLine layer"));
765 throw String(_("Unable to create Gradient layer"));
771 layer->set_param("origin",p1);
772 get_canvas_interface()->signal_layer_param_changed()(layer,"origin");
776 ///////////////////////////////////////////////////////////////////////////
778 ///////////////////////////////////////////////////////////////////////////
780 if(get_layer_plant_flag())
782 synfigapp::PushMode push_mode(get_canvas_interface(),synfigapp::MODE_NORMAL);
784 Layer::Handle layer(get_canvas_interface()->add_layer_to("plant",canvas,depth));
787 get_canvas_view()->get_ui_interface()->error(_("Unable to create layer"));
791 layer_selection.push_back(layer);
792 layer->set_description(get_id()+_(" Plant"));
793 get_canvas_interface()->signal_layer_new_description()(layer,layer->get_description());
796 synfigapp::Action::Handle action(synfigapp::Action::create("layer_param_connect"));
799 action->set_param("canvas",get_canvas());
800 action->set_param("canvas_interface",get_canvas_interface());
801 action->set_param("layer",layer);
802 if(!action->set_param("param",String("bline")))
803 synfig::error("LayerParamConnect didn't like \"param\"");
804 if(!action->set_param("value_node",ValueNode::Handle(value_node_bline)))
805 synfig::error("LayerParamConnect didn't like \"value_node\"");
807 if(!get_canvas_interface()->get_instance()->perform_action(action))
809 //get_canvas_view()->get_ui_interface()->error(_("Unable to create BLine layer"));
811 throw String(_("Unable to create Plant layer"));
816 // only link the plant's origin parameter if the option is selected and we're creating more than one layer
817 if (get_layer_link_origins_flag() && layers_to_create > 1)
819 synfigapp::Action::Handle action(synfigapp::Action::create("layer_param_connect"));
822 action->set_param("canvas",get_canvas());
823 action->set_param("canvas_interface",get_canvas_interface());
824 action->set_param("layer",layer);
825 if(!action->set_param("param",String("origin")))
826 synfig::error("LayerParamConnect didn't like \"param\"");
827 if(!action->set_param("value_node",ValueNode::Handle(value_node_origin)))
828 synfig::error("LayerParamConnect didn't like \"value_node\"");
830 if(!get_canvas_interface()->get_instance()->perform_action(action))
832 //get_canvas_view()->get_ui_interface()->error(_("Unable to create BLine layer"));
834 throw String(_("Unable to create Plant layer"));
840 layer->set_param("origin",p1);
841 get_canvas_interface()->signal_layer_param_changed()(layer,"origin");
845 ///////////////////////////////////////////////////////////////////////////
847 ///////////////////////////////////////////////////////////////////////////
849 if(get_layer_region_flag())
851 synfigapp::PushMode push_mode(get_canvas_interface(),synfigapp::MODE_NORMAL);
853 Layer::Handle layer(get_canvas_interface()->add_layer_to("region",canvas,depth));
856 get_canvas_view()->get_ui_interface()->error(_("Unable to create layer"));
860 layer_selection.push_back(layer);
861 layer->set_description(get_id()+_(" Region"));
862 get_canvas_interface()->signal_layer_new_description()(layer,layer->get_description());
864 layer->set_param("feather",get_feather());
865 get_canvas_interface()->signal_layer_param_changed()(layer,"feather");
867 layer->set_param("invert",get_invert());
868 get_canvas_interface()->signal_layer_param_changed()(layer,"invert");
870 if(get_layer_outline_flag())
871 layer->set_param("color",synfigapp::Main::get_background_color());
873 // I don't know if it's safe to reuse the same layer_param_connect action, so I'm
874 // using 2 separate ones.
876 synfigapp::Action::Handle action(synfigapp::Action::create("layer_param_connect"));
879 action->set_param("canvas",get_canvas());
880 action->set_param("canvas_interface",get_canvas_interface());
881 action->set_param("layer",layer);
882 if(!action->set_param("param",String("bline")))
883 synfig::error("LayerParamConnect didn't like \"param\"");
884 if(!action->set_param("value_node",ValueNode::Handle(value_node_bline)))
885 synfig::error("LayerParamConnect didn't like \"value_node\"");
887 if(!get_canvas_interface()->get_instance()->perform_action(action))
889 //get_canvas_view()->get_ui_interface()->error(_("Unable to create Region layer"));
891 throw String(_("Unable to create Region layer"));
896 // only link the region's origin parameter if the option is selected and we're creating more than one layer
897 if (get_layer_link_origins_flag() && layers_to_create > 1)
899 synfigapp::Action::Handle action(synfigapp::Action::create("layer_param_connect"));
902 action->set_param("canvas",get_canvas());
903 action->set_param("canvas_interface",get_canvas_interface());
904 action->set_param("layer",layer);
905 if(!action->set_param("param",String("origin")))
906 synfig::error("LayerParamConnect didn't like \"param\"");
907 if(!action->set_param("value_node",ValueNode::Handle(value_node_origin)))
908 synfig::error("LayerParamConnect didn't like \"value_node\"");
910 if(!get_canvas_interface()->get_instance()->perform_action(action))
912 //get_canvas_view()->get_ui_interface()->error(_("Unable to create Region layer"));
914 throw String(_("Unable to create Region layer"));
920 layer->set_param("origin",p1);
921 get_canvas_interface()->signal_layer_param_changed()(layer,"origin");
925 ///////////////////////////////////////////////////////////////////////////
927 ///////////////////////////////////////////////////////////////////////////
929 if (get_layer_outline_flag())
931 Layer::Handle layer(get_canvas_interface()->add_layer_to("outline",canvas,depth));
934 get_canvas_view()->get_ui_interface()->error(_("Unable to create layer"));
938 layer_selection.push_back(layer);
939 layer->set_description(get_id()+_(" Outline"));
940 get_canvas_interface()->signal_layer_new_description()(layer,layer->get_description());
942 layer->set_param("feather",get_feather());
943 get_canvas_interface()->signal_layer_param_changed()(layer,"feather");
945 layer->set_param("invert",get_invert());
946 get_canvas_interface()->signal_layer_param_changed()(layer,"invert");
949 synfigapp::Action::Handle action(synfigapp::Action::create("layer_param_connect"));
952 action->set_param("canvas",get_canvas());
953 action->set_param("canvas_interface",get_canvas_interface());
954 action->set_param("layer",layer);
955 if(!action->set_param("param",String("bline")))
956 synfig::error("LayerParamConnect didn't like \"param\"");
957 if(!action->set_param("value_node",ValueNode::Handle(value_node_bline)))
958 synfig::error("LayerParamConnect didn't like \"value_node\"");
960 if(!get_canvas_interface()->get_instance()->perform_action(action))
962 //get_canvas_view()->get_ui_interface()->error(_("Unable to create BLine layer"));
964 throw String(_("Unable to create Outline layer"));
969 // only link the outline's origin parameter if the option is selected and we're creating more than one layer
970 if (get_layer_link_origins_flag() && layers_to_create > 1)
972 synfigapp::Action::Handle action(synfigapp::Action::create("layer_param_connect"));
975 action->set_param("canvas",get_canvas());
976 action->set_param("canvas_interface",get_canvas_interface());
977 action->set_param("layer",layer);
978 if(!action->set_param("param",String("origin")))
979 synfig::error("LayerParamConnect didn't like \"param\"");
980 if(!action->set_param("value_node",ValueNode::Handle(value_node_origin)))
981 synfig::error("LayerParamConnect didn't like \"value_node\"");
983 if(!get_canvas_interface()->get_instance()->perform_action(action))
985 //get_canvas_view()->get_ui_interface()->error(_("Unable to create BLine layer"));
987 throw String(_("Unable to create Outline layer"));
993 layer->set_param("origin",p1);
994 get_canvas_interface()->signal_layer_param_changed()(layer,"origin");
998 egress_on_selection_change=false;
999 get_canvas_interface()->get_selection_manager()->clear_selected_layers();
1000 get_canvas_interface()->get_selection_manager()->set_selected_layers(layer_selection);
1001 egress_on_selection_change=true;
1008 StateStar_Context::event_mouse_click_handler(const Smach::event& x)
1010 const EventMouse& event(*reinterpret_cast<const EventMouse*>(&x));
1012 if(event.key==EVENT_WORKAREA_MOUSE_BUTTON_DOWN && event.button==BUTTON_LEFT)
1014 point_holder=get_work_area()->snap_point_to_grid(event.pos);
1015 etl::handle<Duck> duck=new Duck();
1016 duck->set_point(point_holder);
1017 duck->set_name("p1");
1018 duck->set_type(Duck::TYPE_POSITION);
1019 duck->set_editable(false);
1020 get_work_area()->add_duck(duck);
1022 point2_duck=new Duck();
1023 point2_duck->set_point(Vector(0,0));
1024 point2_duck->set_name("radius");
1025 point2_duck->set_origin(duck);
1026 point2_duck->set_radius(true);
1027 point2_duck->set_scalar(-1);
1028 point2_duck->set_type(Duck::TYPE_RADIUS);
1029 point2_duck->set_hover(true);
1030 get_work_area()->add_duck(point2_duck);
1032 return Smach::RESULT_ACCEPT;
1035 if(event.key==EVENT_WORKAREA_MOUSE_BUTTON_DRAG && event.button==BUTTON_LEFT)
1037 if (!point2_duck) return Smach::RESULT_OK;
1038 point2_duck->set_point(point_holder-get_work_area()->snap_point_to_grid(event.pos));
1039 get_work_area()->queue_draw();
1040 return Smach::RESULT_ACCEPT;
1043 if(event.key==EVENT_WORKAREA_MOUSE_BUTTON_UP && event.button==BUTTON_LEFT)
1045 Point point(get_work_area()->snap_point_to_grid(event.pos));
1047 if (App::restrict_radius_ducks)
1049 if ((point[0] - point_holder[0]) < 0) point[0] = point_holder[0];
1050 if ((point[1] - point_holder[1]) < 0) point[1] = point_holder[1];
1053 make_star(point_holder, point);
1054 get_work_area()->clear_ducks();
1055 return Smach::RESULT_ACCEPT;
1058 return Smach::RESULT_OK;
1063 StateStar_Context::refresh_ducks()
1065 get_work_area()->clear_ducks();
1066 get_work_area()->queue_draw();