X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=synfig-studio%2Ftrunk%2Fsrc%2Fgtkmm%2Fstate_star.cpp;h=8b5c14f8dfba56c4b81e24b9efee766c8fd19915;hb=b3153cc6f4b90adc7fd2041daf2a553edc4ba1eb;hp=ed8c75ec1507d6db228e563f43bc488634b0f861;hpb=7804217852f753ac7239eff6e53f626751b57920;p=synfig.git diff --git a/synfig-studio/trunk/src/gtkmm/state_star.cpp b/synfig-studio/trunk/src/gtkmm/state_star.cpp index ed8c75e..8b5c14f 100644 --- a/synfig-studio/trunk/src/gtkmm/state_star.cpp +++ b/synfig-studio/trunk/src/gtkmm/state_star.cpp @@ -127,6 +127,7 @@ public: int layers_to_create()const { return + get_layer_star_flag() + get_layer_region_flag() + get_layer_outline_flag() + get_layer_curve_gradient_flag() + @@ -433,7 +434,7 @@ StateStar_Context::StateStar_Context(CanvasView* canvas_view): checkbutton_layer_outline(_("Create Outline BLine")), checkbutton_layer_curve_gradient(_("Create Curve Gradient BLine")), checkbutton_layer_plant(_("Create Plant BLine")), - checkbutton_layer_link_origins(_("Link BLine Origins")) + checkbutton_layer_link_origins(_("Link Origins")) { egress_on_selection_change=true; @@ -442,30 +443,30 @@ StateStar_Context::StateStar_Context(CanvasView* canvas_view): // Set up the tool options dialog options_table.attach(*manage(new Gtk::Label(_("Star Tool"))), 0, 2, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0); options_table.attach(entry_id, 0, 2, 1, 2, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0); - options_table.attach(*manage(new Gtk::Label(_("Feather:"))), 0, 1, 2, 3, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0); - options_table.attach(spin_feather, 1, 2, 2, 3, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0); - options_table.attach(checkbutton_invert, 0, 2, 5, 6, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0); - options_table.attach(checkbutton_regular_polygon, 0, 2, 6, 7, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0); - options_table.attach(checkbutton_layer_star, 0, 2, 7, 8, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0); - options_table.attach(checkbutton_layer_outline, 0, 2, 8, 9, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0); - options_table.attach(checkbutton_layer_region, 0, 2, 9, 10, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0); - options_table.attach(checkbutton_layer_plant, 0, 2, 10, 11, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0); - options_table.attach(checkbutton_layer_curve_gradient, 0, 2, 11, 12, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0); - options_table.attach(checkbutton_layer_link_origins, 0, 2, 12, 13, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0); - options_table.attach(*manage(new Gtk::Label(_("Number of Points:"))), 0, 1, 13, 14, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0); - options_table.attach(spin_number_of_points, 1, 2, 13, 14, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0); - options_table.attach(*manage(new Gtk::Label(_("Inner Tangent:"))), 0, 1, 14, 15, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0); - options_table.attach(spin_inner_tangent, 1, 2, 14, 15, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0); - options_table.attach(*manage(new Gtk::Label(_("Outer Tangent:"))), 0, 1, 15, 16, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0); - options_table.attach(spin_outer_tangent, 1, 2, 15, 16, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0); - options_table.attach(*manage(new Gtk::Label(_("Inner Width:"))), 0, 1, 16, 17, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0); - options_table.attach(spin_inner_width, 1, 2, 16, 17, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0); - options_table.attach(*manage(new Gtk::Label(_("Outer Width:"))), 0, 1, 17, 18, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0); - options_table.attach(spin_outer_width, 1, 2, 17, 18, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0); - options_table.attach(*manage(new Gtk::Label(_("Radius Ratio:"))), 0, 1, 18, 19, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0); - options_table.attach(spin_radius_ratio, 1, 2, 18, 19, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0); - options_table.attach(*manage(new Gtk::Label(_("Angle Offset:"))), 0, 1, 19, 20, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0); - options_table.attach(spin_angle_offset, 1, 2, 19, 20, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0); + options_table.attach(checkbutton_layer_star, 0, 2, 2, 3, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0); + options_table.attach(checkbutton_layer_outline, 0, 2, 3, 4, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0); + options_table.attach(checkbutton_layer_region, 0, 2, 4, 5, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0); + options_table.attach(checkbutton_layer_plant, 0, 2, 5, 6, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0); + options_table.attach(checkbutton_layer_curve_gradient, 0, 2, 6, 7, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0); + options_table.attach(checkbutton_layer_link_origins, 0, 2, 7, 8, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0); + options_table.attach(checkbutton_invert, 0, 2, 8, 9, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0); + options_table.attach(checkbutton_regular_polygon, 0, 2, 9, 10, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0); + options_table.attach(*manage(new Gtk::Label(_("Feather:"))), 0, 1, 10, 11, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0); + options_table.attach(spin_feather, 1, 2, 10, 11, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0); + options_table.attach(*manage(new Gtk::Label(_("Number of Points:"))), 0, 1, 11, 12, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0); + options_table.attach(spin_number_of_points, 1, 2, 11, 12, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0); + options_table.attach(*manage(new Gtk::Label(_("Inner Tangent:"))), 0, 1, 12, 13, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0); + options_table.attach(spin_inner_tangent, 1, 2, 12, 13, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0); + options_table.attach(*manage(new Gtk::Label(_("Outer Tangent:"))), 0, 1, 13, 14, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0); + options_table.attach(spin_outer_tangent, 1, 2, 13, 14, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0); + options_table.attach(*manage(new Gtk::Label(_("Inner Width:"))), 0, 1, 14, 15, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0); + options_table.attach(spin_inner_width, 1, 2, 14, 15, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0); + options_table.attach(*manage(new Gtk::Label(_("Outer Width:"))), 0, 1, 15, 16, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0); + options_table.attach(spin_outer_width, 1, 2, 15, 16, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0); + options_table.attach(*manage(new Gtk::Label(_("Radius Ratio:"))), 0, 1, 16, 17, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0); + options_table.attach(spin_radius_ratio, 1, 2, 16, 17, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0); + options_table.attach(*manage(new Gtk::Label(_("Angle Offset:"))), 0, 1, 17, 18, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0); + options_table.attach(spin_angle_offset, 1, 2, 17, 18, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0); options_table.show_all(); @@ -586,7 +587,6 @@ StateStar_Context::make_star(const Point& _p1, const Point& _p2) Angle::deg offset(get_angle_offset()); bool regular(get_regular_polygon()); Angle::deg angle(360.0/points); - Real x(p1[0]), y(p1[1]); std::vector new_list; int point(0); @@ -594,8 +594,8 @@ StateStar_Context::make_star(const Point& _p1, const Point& _p2) { new_list.push_back(*(new BLinePoint)); new_list[point].set_width(outer_width); - new_list[point].set_vertex(Point(radius1*Angle::cos(angle*i + offset).get() + x, - radius1*Angle::sin(angle*i + offset).get() + y)); + new_list[point].set_vertex(Point(radius1*Angle::cos(angle*i + offset).get(), + radius1*Angle::sin(angle*i + offset).get())); new_list[point++].set_tangent(Point(-Angle::sin(angle*i + offset).get(), Angle::cos(angle*i + offset).get()) * outer_tangent); @@ -603,8 +603,8 @@ StateStar_Context::make_star(const Point& _p1, const Point& _p2) { new_list.push_back(*(new BLinePoint)); new_list[point].set_width(inner_width); - new_list[point].set_vertex(Point(radius2*Angle::cos(angle*i + angle/2 + offset).get() + x, - radius2*Angle::sin(angle*i + angle/2 + offset).get() + y)); + new_list[point].set_vertex(Point(radius2*Angle::cos(angle*i + angle/2 + offset).get(), + radius2*Angle::sin(angle*i + angle/2 + offset).get())); new_list[point++].set_tangent(Point(-Angle::sin(angle*i + angle/2 + offset).get(), Angle::cos(angle*i + angle/2 + offset).get()) * inner_tangent); } @@ -613,7 +613,7 @@ StateStar_Context::make_star(const Point& _p1, const Point& _p2) ValueNode_BLine::Handle value_node_bline(ValueNode_BLine::create(new_list)); assert(value_node_bline); - ValueNode_Const::Handle value_node_origin(ValueNode_Const::create(Vector())); + ValueNode_Const::Handle value_node_origin(ValueNode_Const::create(p1)); assert(value_node_origin); // Set the looping flag @@ -634,15 +634,21 @@ StateStar_Context::make_star(const Point& _p1, const Point& _p2) if (get_layer_star_flag()) { layer=get_canvas_interface()->add_layer_to("star",canvas,depth); + if (!layer) + { + get_canvas_view()->get_ui_interface()->error(_("Unable to create layer")); + group.cancel(); + return; + } layer_selection.push_back(layer); layer->set_param("origin",p1); get_canvas_interface()->signal_layer_param_changed()(layer,"origin"); - layer->set_param("radius1",(p2-p1).mag()); + layer->set_param("radius1",radius1); get_canvas_interface()->signal_layer_param_changed()(layer,"radius1"); - layer->set_param("radius2",(p2-p1).mag()/2); + layer->set_param("radius2",radius2); get_canvas_interface()->signal_layer_param_changed()(layer,"radius2"); layer->set_param("angle",offset); @@ -668,6 +674,34 @@ StateStar_Context::make_star(const Point& _p1, const Point& _p2) layer->set_param("color",synfigapp::Main::get_background_color()); get_canvas_interface()->signal_layer_param_changed()(layer,"color"); } + + // only link the star's origin parameter if the option is selected and we're creating more than one layer + if (get_layer_link_origins_flag() && layers_to_create > 1) + { + synfigapp::Action::Handle action(synfigapp::Action::create("layer_param_connect")); + assert(action); + + action->set_param("canvas",get_canvas()); + action->set_param("canvas_interface",get_canvas_interface()); + action->set_param("layer",layer); + if(!action->set_param("param",String("origin"))) + synfig::error("LayerParamConnect didn't like \"param\""); + if(!action->set_param("value_node",ValueNode::Handle(value_node_origin))) + synfig::error("LayerParamConnect didn't like \"value_node\""); + + if(!get_canvas_interface()->get_instance()->perform_action(action)) + { + //get_canvas_view()->get_ui_interface()->error(_("Unable to create Star layer")); + group.cancel(); + throw String(_("Unable to create Star layer")); + return; + } + } + else + { + layer->set_param("origin",p1); + get_canvas_interface()->signal_layer_param_changed()(layer,"origin"); + } } /////////////////////////////////////////////////////////////////////////// @@ -679,7 +713,12 @@ StateStar_Context::make_star(const Point& _p1, const Point& _p2) synfigapp::PushMode push_mode(get_canvas_interface(),synfigapp::MODE_NORMAL); Layer::Handle layer(get_canvas_interface()->add_layer_to("curve_gradient",canvas,depth)); - assert(layer); + if (!layer) + { + get_canvas_view()->get_ui_interface()->error(_("Unable to create layer")); + group.cancel(); + return; + } layer_selection.push_back(layer); layer->set_description(get_id()+_(" Gradient")); get_canvas_interface()->signal_layer_new_description()(layer,layer->get_description()); @@ -727,6 +766,11 @@ StateStar_Context::make_star(const Point& _p1, const Point& _p2) return; } } + else + { + layer->set_param("origin",p1); + get_canvas_interface()->signal_layer_param_changed()(layer,"origin"); + } } /////////////////////////////////////////////////////////////////////////// @@ -738,7 +782,12 @@ StateStar_Context::make_star(const Point& _p1, const Point& _p2) synfigapp::PushMode push_mode(get_canvas_interface(),synfigapp::MODE_NORMAL); Layer::Handle layer(get_canvas_interface()->add_layer_to("plant",canvas,depth)); - assert(layer); + if (!layer) + { + get_canvas_view()->get_ui_interface()->error(_("Unable to create layer")); + group.cancel(); + return; + } layer_selection.push_back(layer); layer->set_description(get_id()+_(" Plant")); get_canvas_interface()->signal_layer_new_description()(layer,layer->get_description()); @@ -786,6 +835,11 @@ StateStar_Context::make_star(const Point& _p1, const Point& _p2) return; } } + else + { + layer->set_param("origin",p1); + get_canvas_interface()->signal_layer_param_changed()(layer,"origin"); + } } /////////////////////////////////////////////////////////////////////////// @@ -797,7 +851,12 @@ StateStar_Context::make_star(const Point& _p1, const Point& _p2) synfigapp::PushMode push_mode(get_canvas_interface(),synfigapp::MODE_NORMAL); Layer::Handle layer(get_canvas_interface()->add_layer_to("region",canvas,depth)); - assert(layer); + if (!layer) + { + get_canvas_view()->get_ui_interface()->error(_("Unable to create layer")); + group.cancel(); + return; + } layer_selection.push_back(layer); layer->set_description(get_id()+_(" Region")); get_canvas_interface()->signal_layer_new_description()(layer,layer->get_description()); @@ -856,6 +915,11 @@ StateStar_Context::make_star(const Point& _p1, const Point& _p2) return; } } + else + { + layer->set_param("origin",p1); + get_canvas_interface()->signal_layer_param_changed()(layer,"origin"); + } } /////////////////////////////////////////////////////////////////////////// @@ -865,7 +929,12 @@ StateStar_Context::make_star(const Point& _p1, const Point& _p2) if (get_layer_outline_flag()) { Layer::Handle layer(get_canvas_interface()->add_layer_to("outline",canvas,depth)); - assert(layer); + if (!layer) + { + get_canvas_view()->get_ui_interface()->error(_("Unable to create layer")); + group.cancel(); + return; + } layer_selection.push_back(layer); layer->set_description(get_id()+_(" Outline")); get_canvas_interface()->signal_layer_new_description()(layer,layer->get_description()); @@ -919,6 +988,11 @@ StateStar_Context::make_star(const Point& _p1, const Point& _p2) return; } } + else + { + layer->set_param("origin",p1); + get_canvas_interface()->signal_layer_param_changed()(layer,"origin"); + } } egress_on_selection_change=false;