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 "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 ========================================================= */
69 /* === G L O B A L S ======================================================= */
71 StateStar studio::state_star;
73 /* === C L A S S E S & S T R U C T S ======================================= */
75 class studio::StateStar_Context : public sigc::trackable
77 etl::handle<CanvasView> canvas_view_;
78 CanvasView::IsWorking is_working;
80 Duckmatic::Push duckmatic_push;
84 etl::handle<Duck> point2_duck;
88 bool prev_workarea_layer_status_;
91 synfigapp::Settings& settings;
94 Gtk::Table options_table;
96 Gtk::Entry entry_id; //what to name the layer
98 Gtk::Adjustment adj_feather;
99 Gtk::Adjustment adj_number_of_points;
100 Gtk::Adjustment adj_inner_tangent;
101 Gtk::Adjustment adj_outer_tangent;
102 Gtk::Adjustment adj_inner_width;
103 Gtk::Adjustment adj_outer_width;
104 Gtk::Adjustment adj_radius_ratio;
105 Gtk::Adjustment adj_angle_offset;
106 Gtk::SpinButton spin_feather;
107 Gtk::SpinButton spin_number_of_points;
108 Gtk::SpinButton spin_inner_tangent;
109 Gtk::SpinButton spin_outer_tangent;
110 Gtk::SpinButton spin_inner_width;
111 Gtk::SpinButton spin_outer_width;
112 Gtk::SpinButton spin_radius_ratio;
113 Gtk::SpinButton spin_angle_offset;
115 Gtk::CheckButton checkbutton_invert;
116 Gtk::CheckButton checkbutton_regular_polygon;
117 Gtk::CheckButton checkbutton_layer_star;
118 Gtk::CheckButton checkbutton_layer_region;
119 Gtk::CheckButton checkbutton_layer_outline;
120 Gtk::CheckButton checkbutton_layer_curve_gradient;
121 Gtk::CheckButton checkbutton_layer_plant;
122 Gtk::CheckButton checkbutton_layer_link_origins;
123 Gtk::CheckButton checkbutton_layer_origins_at_center;
127 // this only counts the layers which will have their origins linked
128 int layers_to_create()const
131 (get_layer_star_flag() && get_layer_origins_at_center_flag()) +
132 get_layer_region_flag() +
133 get_layer_outline_flag() +
134 get_layer_curve_gradient_flag() +
135 get_layer_plant_flag();
138 synfig::String get_id()const { return entry_id.get_text(); }
139 void set_id(const synfig::String& x) { return entry_id.set_text(x); }
141 Real get_feather()const { return adj_feather.get_value(); }
142 void set_feather(Real f) { adj_feather.set_value(f); }
144 Real get_number_of_points()const { return adj_number_of_points.get_value(); }
145 void set_number_of_points(Real f) { adj_number_of_points.set_value(f); }
147 Real get_inner_tangent()const { return adj_inner_tangent.get_value(); }
148 void set_inner_tangent(Real f) { adj_inner_tangent.set_value(f); }
150 Real get_outer_tangent()const { return adj_outer_tangent.get_value(); }
151 void set_outer_tangent(Real f) { adj_outer_tangent.set_value(f); }
153 Real get_inner_width()const { return adj_inner_width.get_value(); }
154 void set_inner_width(Real f) { adj_inner_width.set_value(f); }
156 Real get_outer_width()const { return adj_outer_width.get_value(); }
157 void set_outer_width(Real f) { adj_outer_width.set_value(f); }
159 Real get_radius_ratio()const { return adj_radius_ratio.get_value(); }
160 void set_radius_ratio(Real f) { adj_radius_ratio.set_value(f); }
162 Real get_angle_offset()const { return adj_angle_offset.get_value(); }
163 void set_angle_offset(Real f) { adj_angle_offset.set_value(f); }
165 bool get_invert()const { return checkbutton_invert.get_active(); }
166 void set_invert(bool i) { checkbutton_invert.set_active(i); }
168 bool get_regular_polygon()const { return checkbutton_regular_polygon.get_active(); }
169 void set_regular_polygon(bool i) { checkbutton_regular_polygon.set_active(i); }
171 bool get_layer_star_flag()const { return checkbutton_layer_star.get_active(); }
172 void set_layer_star_flag(bool x) { return checkbutton_layer_star.set_active(x); }
174 bool get_layer_region_flag()const { return checkbutton_layer_region.get_active(); }
175 void set_layer_region_flag(bool x) { return checkbutton_layer_region.set_active(x); }
177 bool get_layer_outline_flag()const { return checkbutton_layer_outline.get_active(); }
178 void set_layer_outline_flag(bool x) { return checkbutton_layer_outline.set_active(x); }
180 bool get_layer_curve_gradient_flag()const { return checkbutton_layer_curve_gradient.get_active(); }
181 void set_layer_curve_gradient_flag(bool x) { return checkbutton_layer_curve_gradient.set_active(x); }
183 bool get_layer_plant_flag()const { return checkbutton_layer_plant.get_active(); }
184 void set_layer_plant_flag(bool x) { return checkbutton_layer_plant.set_active(x); }
186 bool get_layer_link_origins_flag()const { return checkbutton_layer_link_origins.get_active(); }
187 void set_layer_link_origins_flag(bool x) { return checkbutton_layer_link_origins.set_active(x); }
189 bool get_layer_origins_at_center_flag()const { return checkbutton_layer_origins_at_center.get_active(); }
190 void set_layer_origins_at_center_flag(bool x) { return checkbutton_layer_origins_at_center.set_active(x); }
192 void refresh_tool_options(); //to refresh the toolbox
195 Smach::event_result event_stop_handler(const Smach::event& x);
196 Smach::event_result event_refresh_handler(const Smach::event& x);
197 Smach::event_result event_mouse_click_handler(const Smach::event& x);
198 Smach::event_result event_refresh_tool_options(const Smach::event& x);
200 //constructor destructor
201 StateStar_Context(CanvasView* canvas_view);
202 ~StateStar_Context();
205 const etl::handle<CanvasView>& get_canvas_view()const{return canvas_view_;}
206 etl::handle<synfigapp::CanvasInterface> get_canvas_interface()const{return canvas_view_->canvas_interface();}
207 synfig::Canvas::Handle get_canvas()const{return canvas_view_->get_canvas();}
208 WorkArea * get_work_area()const{return canvas_view_->get_work_area();}
210 //Modifying settings etc.
211 void load_settings();
212 void save_settings();
215 bool egress_on_selection_change;
216 Smach::event_result event_layer_selection_changed_handler(const Smach::event& /*x*/)
218 if(egress_on_selection_change)
219 throw &state_normal; //throw Smach::egress_exception();
220 return Smach::RESULT_OK;
223 void make_star(const Point& p1, const Point& p2);
225 }; // END of class StateStar_Context
227 /* === M E T H O D S ======================================================= */
229 StateStar::StateStar():
230 Smach::state<StateStar_Context>("star")
232 insert(event_def(EVENT_LAYER_SELECTION_CHANGED,&StateStar_Context::event_layer_selection_changed_handler));
233 insert(event_def(EVENT_STOP,&StateStar_Context::event_stop_handler));
234 insert(event_def(EVENT_REFRESH,&StateStar_Context::event_refresh_handler));
235 insert(event_def(EVENT_REFRESH_DUCKS,&StateStar_Context::event_refresh_handler));
236 insert(event_def(EVENT_WORKAREA_MOUSE_BUTTON_DOWN,&StateStar_Context::event_mouse_click_handler));
237 insert(event_def(EVENT_WORKAREA_MOUSE_BUTTON_DRAG,&StateStar_Context::event_mouse_click_handler));
238 insert(event_def(EVENT_WORKAREA_MOUSE_BUTTON_UP,&StateStar_Context::event_mouse_click_handler));
239 insert(event_def(EVENT_REFRESH_TOOL_OPTIONS,&StateStar_Context::event_refresh_tool_options));
242 StateStar::~StateStar()
247 StateStar_Context::load_settings()
251 //parse the arguments yargh!
252 if(settings.get_value("star.id",value))
257 if(settings.get_value("star.feather",value))
258 set_feather(atof(value.c_str()));
262 if(settings.get_value("star.number_of_points",value))
263 set_number_of_points(atof(value.c_str()));
265 set_number_of_points(5);
267 if(settings.get_value("star.inner_tangent",value))
268 set_inner_tangent(atof(value.c_str()));
270 set_inner_tangent(0);
272 if(settings.get_value("star.outer_tangent",value))
273 set_outer_tangent(atof(value.c_str()));
275 set_outer_tangent(0);
277 if(settings.get_value("star.inner_width",value))
278 set_inner_width(atof(value.c_str()));
282 if(settings.get_value("star.outer_width",value))
283 set_outer_width(atof(value.c_str()));
287 if(settings.get_value("star.radius_ratio",value))
288 set_radius_ratio(atof(value.c_str()));
290 set_radius_ratio(0.5);
292 if(settings.get_value("star.angle_offset",value))
293 set_angle_offset(atof(value.c_str()));
297 if(settings.get_value("star.invert",value) && value != "0")
302 if(settings.get_value("star.regular_polygon",value) && value != "0")
303 set_regular_polygon(true);
305 set_regular_polygon(false);
307 if(settings.get_value("star.layer_star",value) && value=="0")
308 set_layer_star_flag(false);
310 set_layer_star_flag(true);
312 if(settings.get_value("star.layer_region",value) && value=="1")
313 set_layer_region_flag(true);
315 set_layer_region_flag(false);
317 if(settings.get_value("star.layer_outline",value) && value=="1")
318 set_layer_outline_flag(true);
320 set_layer_outline_flag(false);
322 if(settings.get_value("star.layer_curve_gradient",value) && value=="1")
323 set_layer_curve_gradient_flag(true);
325 set_layer_curve_gradient_flag(false);
327 if(settings.get_value("star.layer_plant",value) && value=="1")
328 set_layer_plant_flag(true);
330 set_layer_plant_flag(false);
332 if(settings.get_value("star.layer_link_origins",value) && value=="0")
333 set_layer_link_origins_flag(false);
335 set_layer_link_origins_flag(true);
337 if(settings.get_value("star.layer_origins_at_center",value) && value=="0")
338 set_layer_origins_at_center_flag(false);
340 set_layer_origins_at_center_flag(true);
344 StateStar_Context::save_settings()
346 settings.set_value("star.id",get_id());
347 settings.set_value("star.feather",strprintf("%f",(float)get_feather()));
348 settings.set_value("star.number_of_points",strprintf("%d",(int)(get_number_of_points() + 0.5)));
349 settings.set_value("star.inner_tangent",strprintf("%f",(float)get_inner_tangent()));
350 settings.set_value("star.outer_tangent",strprintf("%f",(float)get_outer_tangent()));
351 settings.set_value("star.inner_width",strprintf("%f",(float)get_inner_width()));
352 settings.set_value("star.outer_width",strprintf("%f",(float)get_outer_width()));
353 settings.set_value("star.radius_ratio",strprintf("%f",(float)get_radius_ratio()));
354 settings.set_value("star.angle_offset",strprintf("%f",(float)get_angle_offset()));
355 settings.set_value("star.invert",get_invert()?"1":"0");
356 settings.set_value("star.regular_polygon",get_regular_polygon()?"1":"0");
357 settings.set_value("star.layer_star",get_layer_star_flag()?"1":"0");
358 settings.set_value("star.layer_outline",get_layer_outline_flag()?"1":"0");
359 settings.set_value("star.layer_region",get_layer_region_flag()?"1":"0");
360 settings.set_value("star.layer_curve_gradient",get_layer_curve_gradient_flag()?"1":"0");
361 settings.set_value("star.layer_plant",get_layer_plant_flag()?"1":"0");
362 settings.set_value("star.layer_link_origins",get_layer_link_origins_flag()?"1":"0");
363 settings.set_value("star.layer_origins_at_center",get_layer_origins_at_center_flag()?"1":"0");
367 StateStar_Context::reset()
373 StateStar_Context::increment_id()
382 // If there is a number
383 // already at the end of the
384 // id, then remove it.
385 if(id[id.size()-1]<='9' && id[id.size()-1]>='0')
387 // figure out how many digits it is
389 (int)id.size()-1 >= digits && id[id.size()-1-digits] <= '9' && id[id.size()-1-digits] >= '0';
394 str_number=String(id,id.size()-digits,id.size());
395 id=String(id,0,id.size()-digits);
397 number=atoi(str_number.c_str());
407 // Add the number back onto the id
409 const String format(strprintf("%%0%dd",digits));
410 id+=strprintf(format.c_str(),number);
417 StateStar_Context::StateStar_Context(CanvasView* canvas_view):
418 canvas_view_(canvas_view),
419 is_working(*canvas_view),
420 duckmatic_push(get_work_area()),
421 prev_workarea_layer_status_(get_work_area()->get_allow_layer_clicks()),
422 settings(synfigapp::Main::get_selected_input_device()->settings()),
423 entry_id(), // value lower upper step page
424 adj_feather( 0, 0, 1, 0.01, 0.1),
425 adj_number_of_points( 0, 2, 120, 1 , 1 ),
426 adj_inner_tangent( 0, -10, 10, 0.01, 0.1),
427 adj_outer_tangent( 0, -10, 10, 0.01, 0.1),
428 adj_inner_width( 0, -10, 10, 0.01, 0.1),
429 adj_outer_width( 0, -10, 10, 0.01, 0.1),
430 adj_radius_ratio( 0, -10, 10, 0.01, 0.1),
431 adj_angle_offset( 0, -360, 360, 0.1 , 1 ),
432 spin_feather(adj_feather,0.1,3),
433 spin_number_of_points(adj_number_of_points,1,0),
434 spin_inner_tangent(adj_inner_tangent,1,2),
435 spin_outer_tangent(adj_outer_tangent,1,2),
436 spin_inner_width(adj_inner_width,1,2),
437 spin_outer_width(adj_outer_width,1,2),
438 spin_radius_ratio(adj_radius_ratio,1,2),
439 spin_angle_offset(adj_angle_offset,1,1),
440 checkbutton_invert(_("Invert")),
441 checkbutton_regular_polygon(_("Regular Polygon")),
442 checkbutton_layer_star(_("Create Star Layer")),
443 checkbutton_layer_region(_("Create Region BLine")),
444 checkbutton_layer_outline(_("Create Outline BLine")),
445 checkbutton_layer_curve_gradient(_("Create Curve Gradient BLine")),
446 checkbutton_layer_plant(_("Create Plant BLine")),
447 checkbutton_layer_link_origins(_("Link Origins")),
448 checkbutton_layer_origins_at_center(_("BLine Origins at Center"))
450 egress_on_selection_change=true;
454 // Set up the tool options dialog
455 options_table.attach(*manage(new Gtk::Label(_("Star Tool"))), 0, 2, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
456 options_table.attach(entry_id, 0, 2, 1, 2, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
457 options_table.attach(checkbutton_layer_star, 0, 2, 2, 3, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
458 options_table.attach(checkbutton_layer_outline, 0, 2, 3, 4, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
459 options_table.attach(checkbutton_layer_region, 0, 2, 4, 5, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
460 options_table.attach(checkbutton_layer_plant, 0, 2, 5, 6, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
461 options_table.attach(checkbutton_layer_curve_gradient, 0, 2, 6, 7, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
462 options_table.attach(checkbutton_layer_link_origins, 0, 2, 7, 8, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
463 options_table.attach(checkbutton_layer_origins_at_center, 0, 2, 8, 9, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
464 options_table.attach(checkbutton_invert, 0, 2, 9, 10, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
465 options_table.attach(checkbutton_regular_polygon, 0, 2, 10, 11, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
467 options_table.attach(*manage(new Gtk::Label(_("Feather:"))), 0, 1, 11, 12, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
468 options_table.attach(spin_feather, 1, 2, 11, 12, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
470 options_table.attach(*manage(new Gtk::Label(_("Number of Points:"))), 0, 1, 12, 13, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
471 options_table.attach(spin_number_of_points, 1, 2, 12, 13, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
473 options_table.attach(*manage(new Gtk::Label(_("Inner Tangent:"))), 0, 1, 13, 14, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
474 options_table.attach(spin_inner_tangent, 1, 2, 13, 14, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
476 options_table.attach(*manage(new Gtk::Label(_("Outer Tangent:"))), 0, 1, 14, 15, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
477 options_table.attach(spin_outer_tangent, 1, 2, 14, 15, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
479 options_table.attach(*manage(new Gtk::Label(_("Inner Width:"))), 0, 1, 15, 16, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
480 options_table.attach(spin_inner_width, 1, 2, 15, 16, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
482 options_table.attach(*manage(new Gtk::Label(_("Outer Width:"))), 0, 1, 16, 17, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
483 options_table.attach(spin_outer_width, 1, 2, 16, 17, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
485 options_table.attach(*manage(new Gtk::Label(_("Radius Ratio:"))), 0, 1, 17, 18, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
486 options_table.attach(spin_radius_ratio, 1, 2, 17, 18, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
488 options_table.attach(*manage(new Gtk::Label(_("Angle Offset:"))), 0, 1, 18, 19, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
489 options_table.attach(spin_angle_offset, 1, 2, 18, 19, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
491 options_table.show_all();
493 refresh_tool_options();
494 App::dialog_tool_options->present();
496 // Turn off layer clicking
497 get_work_area()->set_allow_layer_clicks(false);
499 // clear out the ducks
500 get_work_area()->clear_ducks();
502 // Refresh the work area
503 get_work_area()->queue_draw();
505 // Hide the tables if they are showing
506 //prev_table_status=get_canvas_view()->tables_are_visible();
507 //if(prev_table_status)get_canvas_view()->hide_tables();
509 // Disable the time bar
510 //get_canvas_view()->set_sensitive_timebar(false);
513 //get_work_area()->signal_user_click().connect(sigc::mem_fun(*this,&studio::StateStar_Context::on_user_click));
514 get_work_area()->set_cursor(Gdk::STAR);
516 App::toolbox->refresh();
520 StateStar_Context::refresh_tool_options()
522 App::dialog_tool_options->clear();
523 App::dialog_tool_options->set_widget(options_table);
524 App::dialog_tool_options->set_local_name(_("Star Tool"));
525 App::dialog_tool_options->set_name("star");
529 StateStar_Context::event_refresh_tool_options(const Smach::event& /*x*/)
531 refresh_tool_options();
532 return Smach::RESULT_ACCEPT;
535 StateStar_Context::~StateStar_Context()
539 // Restore layer clicking
540 get_work_area()->set_allow_layer_clicks(prev_workarea_layer_status_);
541 get_work_area()->reset_cursor();
543 App::dialog_tool_options->clear();
545 // Enable the time bar
546 //get_canvas_view()->set_sensitive_timebar(true);
548 // Bring back the tables if they were out before
549 //if(prev_table_status)get_canvas_view()->show_tables();
551 // Refresh the work area
552 get_work_area()->queue_draw();
554 get_canvas_view()->queue_rebuild_ducks();
556 App::toolbox->refresh();
560 StateStar_Context::event_stop_handler(const Smach::event& /*x*/)
562 //throw Smach::egress_exception();
564 return Smach::RESULT_OK;
568 StateStar_Context::event_refresh_handler(const Smach::event& /*x*/)
571 return Smach::RESULT_ACCEPT;
575 StateStar_Context::make_star(const Point& _p1, const Point& _p2)
577 synfigapp::Action::PassiveGrouper group(get_canvas_interface()->get_instance().get(),_("New Star"));
578 synfigapp::PushMode push_mode(get_canvas_interface(),synfigapp::MODE_NORMAL);
582 Canvas::Handle canvas;
585 // we are temporarily using the layer to hold something
586 layer=get_canvas_view()->get_selection_manager()->get_selected_layer();
589 depth=layer->get_depth();
590 canvas=layer->get_canvas();
593 synfigapp::SelectionManager::LayerList layer_selection;
594 if (!getenv("SYNFIG_TOOLS_CLEAR_SELECTION"))
595 layer_selection = get_canvas_view()->get_selection_manager()->get_selected_layers();
597 const synfig::TransformStack& transform(get_canvas_view()->get_curr_transform_stack());
598 const Point p1(transform.unperform(_p1));
599 const Point p2(transform.unperform(_p2));
601 Real radius_ratio(get_radius_ratio());
602 Real radius1((p2-p1).mag());
603 Real radius2(radius1 * radius_ratio);
604 int points = get_number_of_points();
605 Real inner_tangent = get_inner_tangent() * radius1;
606 Real outer_tangent = get_outer_tangent() * radius2;
607 Real inner_width = get_inner_width();
608 Real outer_width = get_outer_width();
609 Angle::deg offset(get_angle_offset());
610 bool regular(get_regular_polygon());
611 Angle::deg angle(360.0/points);
615 if (get_layer_origins_at_center_flag())
626 std::vector<BLinePoint> new_list;
628 for (int i = 0; i < points; i++)
630 new_list.push_back(*(new BLinePoint));
631 new_list[point].set_width(outer_width);
632 new_list[point].set_vertex(Point(radius1*Angle::cos(angle*i + offset).get() + x,
633 radius1*Angle::sin(angle*i + offset).get() + y));
634 new_list[point++].set_tangent(Point(-Angle::sin(angle*i + offset).get(),
635 Angle::cos(angle*i + offset).get()) * outer_tangent);
639 new_list.push_back(*(new BLinePoint));
640 new_list[point].set_width(inner_width);
641 new_list[point].set_vertex(Point(radius2*Angle::cos(angle*i + angle/2 + offset).get() + x,
642 radius2*Angle::sin(angle*i + angle/2 + offset).get() + y));
643 new_list[point++].set_tangent(Point(-Angle::sin(angle*i + angle/2 + offset).get(),
644 Angle::cos(angle*i + angle/2 + offset).get()) * inner_tangent);
648 ValueNode_BLine::Handle value_node_bline(ValueNode_BLine::create(new_list));
649 assert(value_node_bline);
651 ValueNode_Const::Handle value_node_origin(ValueNode_Const::create(origin));
652 assert(value_node_origin);
654 // Set the looping flag
655 value_node_bline->set_loop(true);
658 canvas=get_canvas_view()->get_canvas();
660 value_node_bline->set_member_canvas(canvas);
662 // count how many layers we're going to be creating
663 int layers_to_create = this->layers_to_create();
665 ///////////////////////////////////////////////////////////////////////////
667 ///////////////////////////////////////////////////////////////////////////
669 if (get_layer_star_flag())
671 layer=get_canvas_interface()->add_layer_to("star",canvas,depth);
674 get_canvas_view()->get_ui_interface()->error(_("Unable to create layer"));
678 layer_selection.push_back(layer);
680 layer->set_param("radius1",radius1);
681 get_canvas_interface()->signal_layer_param_changed()(layer,"radius1");
683 layer->set_param("radius2",radius2);
684 get_canvas_interface()->signal_layer_param_changed()(layer,"radius2");
686 layer->set_param("angle",offset);
687 get_canvas_interface()->signal_layer_param_changed()(layer,"angle");
689 layer->set_param("points",points);
690 get_canvas_interface()->signal_layer_param_changed()(layer,"points");
692 layer->set_param("regular_polygon",regular);
693 get_canvas_interface()->signal_layer_param_changed()(layer,"regular_polygon");
695 layer->set_param("feather",get_feather());
696 get_canvas_interface()->signal_layer_param_changed()(layer,"feather");
698 layer->set_param("invert",get_invert());
699 get_canvas_interface()->signal_layer_param_changed()(layer,"invert");
701 layer->set_description(get_id());
702 get_canvas_interface()->signal_layer_new_description()(layer,layer->get_description());
704 // only link the star's origin parameter if the option is selected, we're putting bline
705 // origins at their centers, and we're creating more than one layer
706 if (get_layer_link_origins_flag() && get_layer_origins_at_center_flag() && layers_to_create > 1)
708 synfigapp::Action::Handle action(synfigapp::Action::create("LayerParamConnect"));
711 action->set_param("canvas",get_canvas());
712 action->set_param("canvas_interface",get_canvas_interface());
713 action->set_param("layer",layer);
714 if(!action->set_param("param",String("origin")))
715 synfig::error("LayerParamConnect didn't like \"param\"");
716 if(!action->set_param("value_node",ValueNode::Handle(value_node_origin)))
717 synfig::error("LayerParamConnect didn't like \"value_node\"");
719 if(!get_canvas_interface()->get_instance()->perform_action(action))
721 //get_canvas_view()->get_ui_interface()->error(_("Unable to create Star layer"));
723 throw String(_("Unable to create Star layer"));
729 layer->set_param("origin",p1);
730 get_canvas_interface()->signal_layer_param_changed()(layer,"origin");
734 ///////////////////////////////////////////////////////////////////////////
735 // C U R V E G R A D I E N T
736 ///////////////////////////////////////////////////////////////////////////
738 if(get_layer_curve_gradient_flag())
740 synfigapp::PushMode push_mode(get_canvas_interface(),synfigapp::MODE_NORMAL);
742 Layer::Handle layer(get_canvas_interface()->add_layer_to("curve_gradient",canvas,depth));
745 get_canvas_view()->get_ui_interface()->error(_("Unable to create layer"));
749 layer_selection.push_back(layer);
750 layer->set_description(get_id()+_(" Gradient"));
751 get_canvas_interface()->signal_layer_new_description()(layer,layer->get_description());
754 synfigapp::Action::Handle action(synfigapp::Action::create("LayerParamConnect"));
757 action->set_param("canvas",get_canvas());
758 action->set_param("canvas_interface",get_canvas_interface());
759 action->set_param("layer",layer);
760 if(!action->set_param("param",String("bline")))
761 synfig::error("LayerParamConnect didn't like \"param\"");
762 if(!action->set_param("value_node",ValueNode::Handle(value_node_bline)))
763 synfig::error("LayerParamConnect didn't like \"value_node\"");
765 if(!get_canvas_interface()->get_instance()->perform_action(action))
767 //get_canvas_view()->get_ui_interface()->error(_("Unable to create BLine layer"));
769 throw String(_("Unable to create Gradient layer"));
774 // only link the curve gradient's origin parameter if the option is selected and we're creating more than one layer
775 if (get_layer_link_origins_flag() && layers_to_create > 1)
777 synfigapp::Action::Handle action(synfigapp::Action::create("LayerParamConnect"));
780 action->set_param("canvas",get_canvas());
781 action->set_param("canvas_interface",get_canvas_interface());
782 action->set_param("layer",layer);
783 if(!action->set_param("param",String("origin")))
784 synfig::error("LayerParamConnect didn't like \"param\"");
785 if(!action->set_param("value_node",ValueNode::Handle(value_node_origin)))
786 synfig::error("LayerParamConnect didn't like \"value_node\"");
788 if(!get_canvas_interface()->get_instance()->perform_action(action))
790 //get_canvas_view()->get_ui_interface()->error(_("Unable to create BLine layer"));
792 throw String(_("Unable to create Gradient layer"));
798 layer->set_param("origin",origin);
799 get_canvas_interface()->signal_layer_param_changed()(layer,"origin");
803 ///////////////////////////////////////////////////////////////////////////
805 ///////////////////////////////////////////////////////////////////////////
807 if(get_layer_plant_flag())
809 synfigapp::PushMode push_mode(get_canvas_interface(),synfigapp::MODE_NORMAL);
811 Layer::Handle layer(get_canvas_interface()->add_layer_to("plant",canvas,depth));
814 get_canvas_view()->get_ui_interface()->error(_("Unable to create layer"));
818 layer_selection.push_back(layer);
819 layer->set_description(get_id()+_(" Plant"));
820 get_canvas_interface()->signal_layer_new_description()(layer,layer->get_description());
823 synfigapp::Action::Handle action(synfigapp::Action::create("LayerParamConnect"));
826 action->set_param("canvas",get_canvas());
827 action->set_param("canvas_interface",get_canvas_interface());
828 action->set_param("layer",layer);
829 if(!action->set_param("param",String("bline")))
830 synfig::error("LayerParamConnect didn't like \"param\"");
831 if(!action->set_param("value_node",ValueNode::Handle(value_node_bline)))
832 synfig::error("LayerParamConnect didn't like \"value_node\"");
834 if(!get_canvas_interface()->get_instance()->perform_action(action))
836 //get_canvas_view()->get_ui_interface()->error(_("Unable to create BLine layer"));
838 throw String(_("Unable to create Plant layer"));
843 // only link the plant's origin parameter if the option is selected and we're creating more than one layer
844 if (get_layer_link_origins_flag() && layers_to_create > 1)
846 synfigapp::Action::Handle action(synfigapp::Action::create("LayerParamConnect"));
849 action->set_param("canvas",get_canvas());
850 action->set_param("canvas_interface",get_canvas_interface());
851 action->set_param("layer",layer);
852 if(!action->set_param("param",String("origin")))
853 synfig::error("LayerParamConnect didn't like \"param\"");
854 if(!action->set_param("value_node",ValueNode::Handle(value_node_origin)))
855 synfig::error("LayerParamConnect didn't like \"value_node\"");
857 if(!get_canvas_interface()->get_instance()->perform_action(action))
859 //get_canvas_view()->get_ui_interface()->error(_("Unable to create BLine layer"));
861 throw String(_("Unable to create Plant layer"));
867 layer->set_param("origin",origin);
868 get_canvas_interface()->signal_layer_param_changed()(layer,"origin");
872 ///////////////////////////////////////////////////////////////////////////
874 ///////////////////////////////////////////////////////////////////////////
876 if(get_layer_region_flag())
878 synfigapp::PushMode push_mode(get_canvas_interface(),synfigapp::MODE_NORMAL);
880 Layer::Handle layer(get_canvas_interface()->add_layer_to("region",canvas,depth));
883 get_canvas_view()->get_ui_interface()->error(_("Unable to create layer"));
887 layer_selection.push_back(layer);
888 layer->set_description(get_id()+_(" Region"));
889 get_canvas_interface()->signal_layer_new_description()(layer,layer->get_description());
891 layer->set_param("feather",get_feather());
892 get_canvas_interface()->signal_layer_param_changed()(layer,"feather");
894 layer->set_param("invert",get_invert());
895 get_canvas_interface()->signal_layer_param_changed()(layer,"invert");
897 // I don't know if it's safe to reuse the same LayerParamConnect action, so I'm
898 // using 2 separate ones.
900 synfigapp::Action::Handle action(synfigapp::Action::create("LayerParamConnect"));
903 action->set_param("canvas",get_canvas());
904 action->set_param("canvas_interface",get_canvas_interface());
905 action->set_param("layer",layer);
906 if(!action->set_param("param",String("bline")))
907 synfig::error("LayerParamConnect didn't like \"param\"");
908 if(!action->set_param("value_node",ValueNode::Handle(value_node_bline)))
909 synfig::error("LayerParamConnect didn't like \"value_node\"");
911 if(!get_canvas_interface()->get_instance()->perform_action(action))
913 //get_canvas_view()->get_ui_interface()->error(_("Unable to create Region layer"));
915 throw String(_("Unable to create Region layer"));
920 // only link the region's origin parameter if the option is selected and we're creating more than one layer
921 if (get_layer_link_origins_flag() && layers_to_create > 1)
923 synfigapp::Action::Handle action(synfigapp::Action::create("LayerParamConnect"));
926 action->set_param("canvas",get_canvas());
927 action->set_param("canvas_interface",get_canvas_interface());
928 action->set_param("layer",layer);
929 if(!action->set_param("param",String("origin")))
930 synfig::error("LayerParamConnect didn't like \"param\"");
931 if(!action->set_param("value_node",ValueNode::Handle(value_node_origin)))
932 synfig::error("LayerParamConnect didn't like \"value_node\"");
934 if(!get_canvas_interface()->get_instance()->perform_action(action))
936 //get_canvas_view()->get_ui_interface()->error(_("Unable to create Region layer"));
938 throw String(_("Unable to create Region layer"));
944 layer->set_param("origin",origin);
945 get_canvas_interface()->signal_layer_param_changed()(layer,"origin");
949 ///////////////////////////////////////////////////////////////////////////
951 ///////////////////////////////////////////////////////////////////////////
953 if (get_layer_outline_flag())
955 Layer::Handle layer(get_canvas_interface()->add_layer_to("outline",canvas,depth));
958 get_canvas_view()->get_ui_interface()->error(_("Unable to create layer"));
962 layer_selection.push_back(layer);
963 layer->set_description(get_id()+_(" Outline"));
964 get_canvas_interface()->signal_layer_new_description()(layer,layer->get_description());
966 layer->set_param("feather",get_feather());
967 get_canvas_interface()->signal_layer_param_changed()(layer,"feather");
969 layer->set_param("invert",get_invert());
970 get_canvas_interface()->signal_layer_param_changed()(layer,"invert");
973 synfigapp::Action::Handle action(synfigapp::Action::create("LayerParamConnect"));
976 action->set_param("canvas",get_canvas());
977 action->set_param("canvas_interface",get_canvas_interface());
978 action->set_param("layer",layer);
979 if(!action->set_param("param",String("bline")))
980 synfig::error("LayerParamConnect didn't like \"param\"");
981 if(!action->set_param("value_node",ValueNode::Handle(value_node_bline)))
982 synfig::error("LayerParamConnect didn't like \"value_node\"");
984 if(!get_canvas_interface()->get_instance()->perform_action(action))
986 //get_canvas_view()->get_ui_interface()->error(_("Unable to create BLine layer"));
988 throw String(_("Unable to create Outline layer"));
993 // only link the outline's origin parameter if the option is selected and we're creating more than one layer
994 if (get_layer_link_origins_flag() && layers_to_create > 1)
996 synfigapp::Action::Handle action(synfigapp::Action::create("LayerParamConnect"));
999 action->set_param("canvas",get_canvas());
1000 action->set_param("canvas_interface",get_canvas_interface());
1001 action->set_param("layer",layer);
1002 if(!action->set_param("param",String("origin")))
1003 synfig::error("LayerParamConnect didn't like \"param\"");
1004 if(!action->set_param("value_node",ValueNode::Handle(value_node_origin)))
1005 synfig::error("LayerParamConnect didn't like \"value_node\"");
1007 if(!get_canvas_interface()->get_instance()->perform_action(action))
1009 //get_canvas_view()->get_ui_interface()->error(_("Unable to create BLine layer"));
1011 throw String(_("Unable to create Outline layer"));
1017 layer->set_param("origin",origin);
1018 get_canvas_interface()->signal_layer_param_changed()(layer,"origin");
1022 egress_on_selection_change=false;
1023 get_canvas_interface()->get_selection_manager()->clear_selected_layers();
1024 get_canvas_interface()->get_selection_manager()->set_selected_layers(layer_selection);
1025 egress_on_selection_change=true;
1032 StateStar_Context::event_mouse_click_handler(const Smach::event& x)
1034 const EventMouse& event(*reinterpret_cast<const EventMouse*>(&x));
1036 if(event.key==EVENT_WORKAREA_MOUSE_BUTTON_DOWN && event.button==BUTTON_LEFT)
1038 point_holder=get_work_area()->snap_point_to_grid(event.pos);
1039 etl::handle<Duck> duck=new Duck();
1040 duck->set_point(point_holder);
1041 duck->set_name("p1");
1042 duck->set_type(Duck::TYPE_POSITION);
1043 duck->set_editable(false);
1044 get_work_area()->add_duck(duck);
1046 point2_duck=new Duck();
1047 point2_duck->set_point(Vector(0,0));
1048 point2_duck->set_name("radius");
1049 point2_duck->set_origin(duck);
1050 point2_duck->set_radius(true);
1051 point2_duck->set_scalar(-1);
1052 point2_duck->set_type(Duck::TYPE_RADIUS);
1053 point2_duck->set_hover(true);
1054 get_work_area()->add_duck(point2_duck);
1056 return Smach::RESULT_ACCEPT;
1059 if(event.key==EVENT_WORKAREA_MOUSE_BUTTON_DRAG && event.button==BUTTON_LEFT)
1061 if (!point2_duck) return Smach::RESULT_OK;
1062 point2_duck->set_point(point_holder-get_work_area()->snap_point_to_grid(event.pos));
1063 get_work_area()->queue_draw();
1064 return Smach::RESULT_ACCEPT;
1067 if(event.key==EVENT_WORKAREA_MOUSE_BUTTON_UP && event.button==BUTTON_LEFT)
1069 Point point(get_work_area()->snap_point_to_grid(event.pos));
1071 if (App::restrict_radius_ducks)
1073 if ((point[0] - point_holder[0]) < 0) point[0] = point_holder[0];
1074 if ((point[1] - point_holder[1]) < 0) point[1] = point_holder[1];
1077 make_star(point_holder, point);
1078 get_work_area()->clear_ducks();
1079 return Smach::RESULT_ACCEPT;
1082 return Smach::RESULT_OK;
1087 StateStar_Context::refresh_ducks()
1089 get_work_area()->clear_ducks();
1090 get_work_area()->queue_draw();