Remove spaces and tabs at end of lines.
[synfig.git] / synfig-studio / trunk / src / gtkmm / state_draw.cpp
index 1b7e493..9c55193 100644 (file)
@@ -115,7 +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 fill_last_stroke_and_unselect_other_layers();
 
        Smach::event_result new_bline(std::list<synfig::BLinePoint> bline,bool loop_bline_flag,float radius);
 
@@ -377,7 +377,7 @@ StateDraw_Context::increment_id()
                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());
        }
@@ -410,8 +410,8 @@ StateDraw_Context::StateDraw_Context(CanvasView* canvas_view):
        checkbutton_auto_loop(_("Auto Loop")),
        checkbutton_auto_extend(_("Auto Extend")),
        checkbutton_auto_link(_("Auto Link")),
-       checkbutton_region(_("Create Region")),
-       checkbutton_outline(_("Create Outline")),
+       checkbutton_region(_("Create Region BLine")),
+       checkbutton_outline(_("Create Outline BLine")),
        checkbutton_auto_export(_("Auto Export")),
        button_fill_last_stroke(_("Fill Last Stroke")),
        adj_min_pressure(0,0,1,0.01,0.1),
@@ -430,25 +430,25 @@ StateDraw_Context::StateDraw_Context(CanvasView* canvas_view):
 
        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_outline,                                               0, 2,  2,  3, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
+       options_table.attach(checkbutton_region,                                                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);
 
@@ -589,10 +589,6 @@ StateDraw_Context::event_mouse_down_handler(const Smach::event& x)
                        return Smach::RESULT_ACCEPT;
                }
 
-       case BUTTON_RIGHT: // Intercept the right-button click to short-circuit the pop-up menu
-               if (!getenv("SYNFIG_ENABLE_POPUP_MENU_IN_ALL_TOOLS"))
-                       return Smach::RESULT_ACCEPT;
-
        default:
                return Smach::RESULT_OK;
        }
@@ -777,8 +773,8 @@ StateDraw_Context::new_bline(std::list<synfig::BLinePoint> bline,bool loop_bline
        // Create the action group
        synfigapp::Action::PassiveGrouper group(get_canvas_interface()->get_instance().get(),_("Sketch BLine"));
 
-       bool shift_offset = false;
-       Vector shift_offset_vector;
+       bool shift_origin = false;
+       Vector shift_origin_vector;
        bool join_start_no_extend=false,join_finish_no_extend=false;
        synfigapp::ValueDesc start_duck_value_desc,finish_duck_value_desc;
        bool extend_start=false,extend_finish=false,complete_loop=false;
@@ -814,8 +810,8 @@ StateDraw_Context::new_bline(std::list<synfig::BLinePoint> bline,bool loop_bline
                           (start_duck_index==0||start_duck_index==start_duck_value_node_bline->link_count()-1))
                        {
                                extend_start=true;
-                               shift_offset=true;
-                               shift_offset_vector=start_duck->get_origin();
+                               shift_origin=true;
+                               shift_origin_vector=start_duck->get_origin();
                        }
                }while(0);
 
@@ -845,8 +841,8 @@ StateDraw_Context::new_bline(std::list<synfig::BLinePoint> bline,bool loop_bline
                                                complete_loop=extend_finish=true;
                                }else{
                                        extend_finish=true;
-                                       shift_offset=true;
-                                       shift_offset_vector=finish_duck->get_origin();
+                                       shift_origin=true;
+                                       shift_origin_vector=finish_duck->get_origin();
                                }
                        }
                }while(0);
@@ -860,10 +856,10 @@ StateDraw_Context::new_bline(std::list<synfig::BLinePoint> bline,bool loop_bline
                                start_duck_value_desc=synfigapp::ValueDesc(LinkableValueNode::Handle::cast_dynamic(start_duck_value_desc.get_value_node()),0);
                                // fall through
                        case synfig::ValueBase::TYPE_VECTOR:
-                               if (shift_offset && shift_offset_vector != start_duck->get_origin())
+                               if (shift_origin && shift_origin_vector != start_duck->get_origin())
                                        break;
-                               shift_offset = true;
-                               shift_offset_vector = start_duck->get_origin();
+                               shift_origin = true;
+                               shift_origin_vector = start_duck->get_origin();
                                get_canvas_interface()->auto_export(start_duck_value_desc);
                                if (extend_finish)
                                        if(start_duck_value_node_bline&&start_duck_value_node_bline==finish_duck_value_node_bline)
@@ -885,10 +881,10 @@ StateDraw_Context::new_bline(std::list<synfig::BLinePoint> bline,bool loop_bline
                                finish_duck_value_desc=synfigapp::ValueDesc(LinkableValueNode::Handle::cast_dynamic(finish_duck_value_desc.get_value_node()),0);
                                // fall through
                        case synfig::ValueBase::TYPE_VECTOR:
-                               if (shift_offset && shift_offset_vector != finish_duck->get_origin())
+                               if (shift_origin && shift_origin_vector != finish_duck->get_origin())
                                        break;
-                               shift_offset = true;
-                               shift_offset_vector = finish_duck->get_origin();
+                               shift_origin = true;
+                               shift_origin_vector = finish_duck->get_origin();
                                get_canvas_interface()->auto_export(finish_duck_value_desc);
                                if(extend_start)
                                        if(finish_duck_value_node_bline&&start_duck_value_node_bline==finish_duck_value_node_bline)
@@ -926,8 +922,8 @@ StateDraw_Context::new_bline(std::list<synfig::BLinePoint> bline,bool loop_bline
                                ) -new_vertex
                        );
 
-                       if (shift_offset)
-                               new_vertex=new_vertex-shift_offset_vector;
+                       if (shift_origin)
+                               new_vertex=new_vertex-shift_origin_vector;
 
                        bline_point.set_vertex(new_vertex);
 
@@ -1038,7 +1034,15 @@ StateDraw_Context::new_bline(std::list<synfig::BLinePoint> 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_and_unselect_other_layers();
+               {
+                       if (fill_last_stroke_and_unselect_other_layers() == Smach::RESULT_ERROR)
+                       {
+                               get_canvas_view()->get_selection_manager()->set_selected_layers(layer_list);
+                               get_canvas_view()->get_ui_interface()->error(_("Unable to create layer"));
+                               group.cancel();
+                               return Smach::RESULT_ERROR;
+                       }
+               }
                else
                        get_canvas_interface()->get_selection_manager()->clear_selected_layers();
 
@@ -1050,11 +1054,25 @@ StateDraw_Context::new_bline(std::list<synfig::BLinePoint> bline,bool loop_bline
                if(get_outline_flag())
                {
                        layer=get_canvas_interface()->add_layer_to("outline",canvas,depth);
+                       if (!layer)
+                       {
+                               get_canvas_view()->get_selection_manager()->set_selected_layers(layer_list);
+                               get_canvas_view()->get_ui_interface()->error(_("Unable to create layer"));
+                               group.cancel();
+                               return Smach::RESULT_ERROR;
+                       }
                        layer->set_description(get_id()+_(" Outline"));
                }
                else
                {
                        layer=get_canvas_interface()->add_layer_to("region",canvas,depth);
+                       if (!layer)
+                       {
+                               get_canvas_view()->get_selection_manager()->set_selected_layers(layer_list);
+                               get_canvas_view()->get_ui_interface()->error(_("Unable to create layer"));
+                               group.cancel();
+                               return Smach::RESULT_ERROR;
+                       }
                        layer->set_description(get_id()+_(" Region"));
                }
 
@@ -1067,11 +1085,11 @@ StateDraw_Context::new_bline(std::list<synfig::BLinePoint> bline,bool loop_bline
                //layer->set_description(strprintf("Stroke %d",number));
                //get_canvas_interface()->signal_layer_new_description()(layer,layer->get_description());
 
-               if (shift_offset)
+               if (shift_origin)
                        get_canvas_interface()->
-                         change_value(synfigapp::ValueDesc(layer,"offset"),shift_offset_vector);
+                         change_value(synfigapp::ValueDesc(layer,"origin"),shift_origin_vector);
 
-               synfigapp::Action::Handle action(synfigapp::Action::create("layer_param_connect"));
+               synfigapp::Action::Handle action(synfigapp::Action::create("LayerParamConnect"));
 
                assert(action);
 
@@ -1273,7 +1291,7 @@ StateDraw_Context::new_region(std::list<synfig::BLinePoint> bline, synfig::Real
 
        std::list<synfigapp::ValueDesc> vertex_list;
 
-       printf("new_region with %d bline points\n", bline.size());
+       printf("new_region with %zd bline points\n", bline.size());
 
        // First we need to come up with a rough list of
        // BLinePoints that we are going to be using to
@@ -1316,7 +1334,7 @@ StateDraw_Context::new_region(std::list<synfig::BLinePoint> bline, synfig::Real
 
        assert(vertex_list.back().is_valid());
 
-       printf("vertex list with %d bline points\n", vertex_list.size());
+       printf("vertex list with %zd bline points\n", vertex_list.size());
 
        // Remove any duplicates
        {
@@ -1537,7 +1555,7 @@ StateDraw_Context::new_region(std::list<synfig::BLinePoint> bline, synfig::Real
                                // synfig::info(__FILE__":%d: value_prev 0x%08X:%d",__LINE__,value_prev.get_parent_value_node().get(),value_prev.get_index());
                                // synfig::info(__FILE__":%d: value_desc 0x%08X:%d",__LINE__,value_desc.get_parent_value_node().get(),value_desc.get_index());
                                // synfig::info(__FILE__":%d: value_next 0x%08X:%d",__LINE__,value_next.get_parent_value_node().get(),value_next.get_index());
-                                               
+
                                /*
                                  if(value_prev.parent_is_value_node() && value_desc.parent_is_value_node() && value_next.parent_is_value_node())
                                  {
@@ -1587,7 +1605,7 @@ StateDraw_Context::new_region(std::list<synfig::BLinePoint> bline, synfig::Real
                                                //                 (*(value_desc.get_parent_value_node()))(get_time()).get_loop()
                                                //                 // value_desc.get_value_node().get_loop(),
                                                //              );
-                                               // 
+                                               //
                                                //      // Fill in missing vertices
                                                //      // \todo take loops into account: seeing (15, 2, 3, 4) probably means that (0, 1) is missing, not 14 through 3
                                                //      if(value_desc.get_index()<value_next.get_index()-1)
@@ -1774,7 +1792,12 @@ StateDraw_Context::new_region(std::list<synfig::BLinePoint> bline, synfig::Real
                synfigapp::PushMode push_mode(get_canvas_interface(),synfigapp::MODE_NORMAL);
 
                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 Smach::RESULT_ERROR;
+               }
                layer->set_param("color",synfigapp::Main::get_background_color());
                if(get_feather())
                {
@@ -1783,7 +1806,7 @@ StateDraw_Context::new_region(std::list<synfig::BLinePoint> bline, synfig::Real
                }
                get_canvas_interface()->signal_layer_param_changed()(layer,"color");
 
-               synfigapp::Action::Handle action(synfigapp::Action::create("layer_param_connect"));
+               synfigapp::Action::Handle action(synfigapp::Action::create("LayerParamConnect"));
 
                assert(action);
 
@@ -1835,7 +1858,7 @@ StateDraw_Context::extend_bline_from_begin(ValueNode_BLine::Handle value_node,st
 
        if (complete_loop)
        {
-               synfigapp::Action::Handle action(synfigapp::Action::create("value_node_dynamic_list_loop"));
+               synfigapp::Action::Handle action(synfigapp::Action::create("ValueNodeDynamicListLoop"));
                assert(action);
 
                action->set_param("canvas",get_canvas());
@@ -1855,7 +1878,7 @@ StateDraw_Context::extend_bline_from_begin(ValueNode_BLine::Handle value_node,st
        {
                ValueNode_Composite::Handle composite(ValueNode_Composite::create(*iter));
 
-               synfigapp::Action::Handle action(synfigapp::Action::create("value_node_dynamic_list_insert"));
+               synfigapp::Action::Handle action(synfigapp::Action::create("ValueNodeDynamicListInsert"));
 
                assert(action);
                synfigapp::ValueDesc value_desc(value_node,0);
@@ -1886,7 +1909,7 @@ StateDraw_Context::extend_bline_from_end(ValueNode_BLine::Handle value_node,std:
 
        if (complete_loop)
        {
-               synfigapp::Action::Handle action(synfigapp::Action::create("value_node_dynamic_list_loop"));
+               synfigapp::Action::Handle action(synfigapp::Action::create("ValueNodeDynamicListLoop"));
                assert(action);
 
                action->set_param("canvas",get_canvas());
@@ -1906,7 +1929,7 @@ StateDraw_Context::extend_bline_from_end(ValueNode_BLine::Handle value_node,std:
        {
                ValueNode_Composite::Handle composite(ValueNode_Composite::create(*iter));
 
-               synfigapp::Action::Handle action(synfigapp::Action::create("value_node_dynamic_list_insert"));
+               synfigapp::Action::Handle action(synfigapp::Action::create("ValueNodeDynamicListInsert"));
 
                assert(action);
                synfigapp::ValueDesc value_desc(value_node,value_node->link_count());
@@ -1946,11 +1969,11 @@ StateDraw_Context::reverse_bline(std::list<synfig::BLinePoint> &bline)
        }
 }
 
-void
+Smach::event_result
 StateDraw_Context::fill_last_stroke_and_unselect_other_layers()
 {
        if(!last_stroke)
-               return;
+               return Smach::RESULT_OK;
 
        synfigapp::Action::PassiveGrouper group(get_canvas_interface()->get_instance().get(),_("Fill Stroke"));
 
@@ -1972,11 +1995,11 @@ StateDraw_Context::fill_last_stroke_and_unselect_other_layers()
 
        get_canvas_interface()->get_selection_manager()->clear_selected_layers();
        layer=get_canvas_interface()->add_layer_to("region", canvas, depth);
-       assert(layer);
+       if (!layer) return Smach::RESULT_ERROR;
        layer->set_param("color",synfigapp::Main::get_background_color());
        layer->set_description(last_stroke_id + _(" Region"));
 
-       synfigapp::Action::Handle action(synfigapp::Action::create("layer_param_connect"));
+       synfigapp::Action::Handle action(synfigapp::Action::create("LayerParamConnect"));
 
        assert(action);
 
@@ -1992,9 +2015,10 @@ StateDraw_Context::fill_last_stroke_and_unselect_other_layers()
        {
                get_canvas_view()->get_ui_interface()->error(_("Unable to create Region layer"));
                group.cancel();
-               return;
+               return Smach::RESULT_OK;
        }
        get_canvas_view()->get_selection_manager()->set_selected_layer(layer);
+       return Smach::RESULT_OK;
 }
 
 void