X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=synfig-studio%2Ftrunk%2Fsrc%2Fgtkmm%2Fstate_draw.cpp;h=913d7260a18474f8485c576226e1b2cc6894790d;hb=924d45497fce48981c5aec677028c67d2c047864;hp=8bda933e37e12976d31ccb771bff5ab111791b2d;hpb=63e709f66d50c124cc0ece2325f4773ac4ae7b20;p=synfig.git diff --git a/synfig-studio/trunk/src/gtkmm/state_draw.cpp b/synfig-studio/trunk/src/gtkmm/state_draw.cpp index 8bda933..913d726 100644 --- a/synfig-studio/trunk/src/gtkmm/state_draw.cpp +++ b/synfig-studio/trunk/src/gtkmm/state_draw.cpp @@ -115,6 +115,7 @@ class studio::StateDraw_Context : public sigc::trackable Duckmatic::Type old_duckmask; void fill_last_stroke(); + void fill_last_stroke_and_unselect_other_layers(); Smach::event_result new_bline(std::list bline,bool loop_bline_flag,float radius); @@ -368,12 +369,15 @@ StateDraw_Context::increment_id() if(id[id.size()-1]<='9' && id[id.size()-1]>='0') { // figure out how many digits it is - for(digits=0;(int)id.size()-1>=digits && id[id.size()-1-digits]<='9' && id[id.size()-1-digits]>='0';digits++)while(false); + for (digits = 0; + (int)id.size()-1 >= digits && id[id.size()-1-digits] <= '9' && id[id.size()-1-digits] >= '0'; + digits++) + ; String str_number; str_number=String(id,id.size()-digits,id.size()); id=String(id,0,id.size()-digits); - synfig::info("---------------- \"%s\"",str_number.c_str()); + // synfig::info("---------------- \"%s\"",str_number.c_str()); number=atoi(str_number.c_str()); } @@ -421,32 +425,30 @@ StateDraw_Context::StateDraw_Context(CanvasView* canvas_view): check_localerror(_("LocalError")) { - synfig::info("STATE SKETCH: entering state"); - nested=0; load_settings(); UpdateErrorBox(); - //options_table.attach(*manage(new Gtk::Label(_("Draw 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(checkbutton_region, 0, 2, 2, 3, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0); - options_table.attach(checkbutton_outline, 0, 2, 3, 4, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0); - options_table.attach(checkbutton_auto_loop, 0, 2, 4, 5, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0); - options_table.attach(checkbutton_auto_extend, 0, 2, 5, 6, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0); - options_table.attach(checkbutton_auto_link, 0, 2, 6, 7, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0); - options_table.attach(checkbutton_auto_export, 0, 2, 7, 8, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0); - options_table.attach(checkbutton_pressure_width, 0, 2, 8, 9, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0); - options_table.attach(check_localerror, 0, 2, 9, 10, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0); + options_table.attach(*manage(new Gtk::Label(_("Draw 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(checkbutton_region, 0, 2, 2, 3, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0); + options_table.attach(checkbutton_outline, 0, 2, 3, 4, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0); + options_table.attach(checkbutton_auto_loop, 0, 2, 4, 5, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0); + options_table.attach(checkbutton_auto_extend, 0, 2, 5, 6, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0); + options_table.attach(checkbutton_auto_link, 0, 2, 6, 7, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0); + options_table.attach(checkbutton_auto_export, 0, 2, 7, 8, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0); + options_table.attach(checkbutton_pressure_width, 0, 2, 8, 9, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0); + options_table.attach(check_localerror, 0, 2, 9, 10, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0); - options_table.attach(check_min_pressure, 0, 1, 10, 11, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0); - options_table.attach(spin_min_pressure, 1, 2, 10, 11, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0); + options_table.attach(check_min_pressure, 0, 1, 10, 11, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0); + options_table.attach(spin_min_pressure, 1, 2, 10, 11, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0); - options_table.attach(*manage(new Gtk::Label(_("Smooth"))), 0, 1, 11, 12, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0); - options_table.attach(spin_globalthres, 1, 2, 11, 12, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0); + options_table.attach(*manage(new Gtk::Label(_("Smooth"))), 0, 1, 11, 12, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0); + options_table.attach(spin_globalthres, 1, 2, 11, 12, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0); - options_table.attach(*manage(new Gtk::Label(_("Feather"))), 0, 1, 12, 13, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0); - options_table.attach(spin_feather, 1, 2, 12, 13, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0); + options_table.attach(*manage(new Gtk::Label(_("Feather"))), 0, 1, 12, 13, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0); + options_table.attach(spin_feather, 1, 2, 12, 13, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0); //options_table.attach(button_fill_last_stroke, 0, 2, 13, 14, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0); @@ -712,14 +714,16 @@ StateDraw_Context::process_stroke(StrokeData stroke_data, WidthData width_data, } // If the start and end points are similar, then make them the same point - if(get_auto_loop_flag() && - bline.size()>2&&(bline.front().get_vertex()-bline.back().get_vertex()).mag()<=radius) + if (get_auto_loop_flag() && + bline.size() > 2 && + (bline.front().get_vertex() - bline.back().get_vertex()).mag() <= radius) { loop_bline_flag=true; Vector tangent; Real width(0); - while(bline.size()>2&&(bline.front().get_vertex()-bline.back().get_vertex()).mag()<=radius) + while (bline.size() > 2 && + (bline.front().get_vertex() - bline.back().get_vertex()).mag() <= radius) { tangent=bline.back().get_tangent1(); width=bline.back().get_width(); @@ -749,8 +753,15 @@ StateDraw_Context::process_stroke(StrokeData stroke_data, WidthData width_data, } // If the bline only has one blinepoint, then there is nothing to do. - if(bline.size()<=1) + if(bline.size() < 2) + { + // hide the 'stroke' line we were drawing, unless the user + // explicitly requests that they are kept + if (!getenv("SYNFIG_KEEP_ABORTED_DRAW_LINES")) + refresh_ducks(); + return Smach::RESULT_OK; + } if(region_flag) return new_region(bline,radius); @@ -761,6 +772,8 @@ StateDraw_Context::process_stroke(StrokeData stroke_data, WidthData width_data, Smach::event_result StateDraw_Context::new_bline(std::list bline,bool loop_bline_flag,float radius) { + synfigapp::SelectionManager::LayerList layer_list = get_canvas_view()->get_selection_manager()->get_selected_layers(); + // Create the action group synfigapp::Action::PassiveGrouper group(get_canvas_interface()->get_instance().get(),_("Sketch BLine")); @@ -822,6 +835,7 @@ StateDraw_Context::new_bline(std::list bline,bool loop_bline // don't extend looped blines if(finish_duck_value_node_bline&&!finish_duck_value_node_bline->get_loop()&& (finish_duck_index==0||finish_duck_index==finish_duck_value_node_bline->link_count()-1)) + { if(extend_start) { // we've started and finished drawing at the end of a bline. we can't @@ -834,6 +848,7 @@ StateDraw_Context::new_bline(std::list bline,bool loop_bline shift_offset=true; shift_offset_vector=finish_duck->get_origin(); } + } }while(0); // if the new line's start didn't extend an existing line, @@ -919,6 +934,11 @@ StateDraw_Context::new_bline(std::list bline,bool loop_bline trans_bline.push_back(bline_point); } value_node=ValueNode_BLine::create(synfig::ValueBase(trans_bline,loop_bline_flag)); + + Canvas::Handle canvas(get_canvas_view()->get_canvas()); + Layer::Handle layer(get_canvas_view()->get_selection_manager()->get_selected_layer()); + if (layer) canvas=layer->get_canvas(); + value_node->set_member_canvas(canvas); } Smach::event_result result; @@ -989,8 +1009,7 @@ StateDraw_Context::new_bline(std::list bline,bool loop_bline LinkableValueNode::Handle::cast_dynamic(value_node->list.back().value_node)-> set_link(0,finish_duck_value_desc.get_value_node()); - if(get_auto_export_flag()) { - printf("this is where we would export the new line\n"); + if(get_auto_export_flag()) if (!get_canvas_interface()->add_value_node(value_node,get_id())) { /* it's no big deal, is it? let's keep the shape anyway */ @@ -999,7 +1018,6 @@ StateDraw_Context::new_bline(std::list bline,bool loop_bline // increment_id(); // return Smach::RESULT_ERROR; } - } last_stroke=value_node; last_stroke_id=get_id(); @@ -1020,7 +1038,7 @@ StateDraw_Context::new_bline(std::list bline,bool loop_bline // fill_last_stroke() will take care of clearing the selection if we're calling it if(get_outline_flag() && get_region_flag()) - fill_last_stroke(); + fill_last_stroke_and_unselect_other_layers(); else get_canvas_interface()->get_selection_manager()->clear_selected_layers(); @@ -1073,7 +1091,8 @@ StateDraw_Context::new_bline(std::list bline,bool loop_bline //refresh_ducks(); return Smach::RESULT_ERROR; } - get_canvas_view()->get_selection_manager()->set_selected_layer(layer); + layer_list.push_back(layer); + get_canvas_view()->get_selection_manager()->set_selected_layers(layer_list); //refresh_ducks(); } @@ -1232,10 +1251,12 @@ debug_show_vertex_list(int iteration, std::list& vertex_li { if (started) printf(", "); else started = true; if (start != -1) + { if (dir != 0) printf("%d--%d", start, prev); else printf("%d", start); + } printf(")"); } printf("\n"); @@ -1388,12 +1409,14 @@ StateDraw_Context::new_region(std::list bline, synfig::Real this_index = iter->get_index(); // printf("index went from %d to %d\n", last_index, this_index); if (looped) + { if (this_index - last_index > points_in_line/2) while (this_index - last_index > points_in_line/2) this_index -= points_in_line; else if (last_index - this_index > points_in_line/2) while (last_index - this_index > points_in_line/2) this_index += points_in_line; + } if (this_index < min_index) min_index = this_index; if (this_index > max_index) max_index = this_index; @@ -1924,7 +1947,7 @@ StateDraw_Context::reverse_bline(std::list &bline) } void -StateDraw_Context::fill_last_stroke() +StateDraw_Context::fill_last_stroke_and_unselect_other_layers() { if(!last_stroke) return; @@ -1973,3 +1996,14 @@ StateDraw_Context::fill_last_stroke() } get_canvas_view()->get_selection_manager()->set_selected_layer(layer); } + +void +StateDraw_Context::fill_last_stroke() +{ + if(!last_stroke) + return; + + synfigapp::SelectionManager::LayerList layer_list = get_canvas_view()->get_selection_manager()->get_selected_layers(); + fill_last_stroke_and_unselect_other_layers(); + get_canvas_view()->get_selection_manager()->set_selected_layers(layer_list); +}