Rearrange the drawing tool options a little. Instead of 'region only' have checkboxe...
[synfig.git] / synfig-studio / trunk / src / gtkmm / state_draw.cpp
index 4beb8e7..3814d2a 100644 (file)
@@ -100,6 +100,7 @@ class studio::StateDraw_Context : public sigc::trackable
        SigC::Connection process_queue_connection;
 
        ValueNode_BLine::Handle last_stroke;
+       synfig::String last_stroke_id;
 
        Gtk::Menu menu;
 
@@ -130,7 +131,8 @@ class studio::StateDraw_Context : public sigc::trackable
        Gtk::CheckButton checkbutton_auto_loop;   // whether to loop new strokes which start and end in the same place
        Gtk::CheckButton checkbutton_auto_extend; // whether to extend existing lines
        Gtk::CheckButton checkbutton_auto_link;   // whether to link new ducks to existing ducks
-       Gtk::CheckButton checkbutton_region_only;
+       Gtk::CheckButton checkbutton_region;      // whether to create regions
+       Gtk::CheckButton checkbutton_outline;     // whether to create outlines
        Gtk::CheckButton checkbutton_auto_export;
        Gtk::Button button_fill_last_stroke;
 
@@ -168,8 +170,11 @@ public:
        bool get_auto_link_flag()const { return checkbutton_auto_link.get_active(); }
        void set_auto_link_flag(bool x) { return checkbutton_auto_link.set_active(x); }
 
-       bool get_region_only_flag()const { return checkbutton_region_only.get_active(); }
-       void set_region_only_flag(bool x) { return checkbutton_region_only.set_active(x); }
+       bool get_region_flag()const { return checkbutton_region.get_active(); }
+       void set_region_flag(bool x) { return checkbutton_region.set_active(x); }
+
+       bool get_outline_flag()const { return checkbutton_outline.get_active(); }
+       void set_outline_flag(bool x) { return checkbutton_outline.set_active(x); }
 
        bool get_auto_export_flag()const { return checkbutton_auto_export.get_active(); }
        void set_auto_export_flag(bool x) { return checkbutton_auto_export.set_active(x); }
@@ -274,10 +279,15 @@ StateDraw_Context::load_settings()
        else
                set_auto_link_flag(true);
 
-       if(settings.get_value("draw.region_only",value) && value=="1")
-               set_region_only_flag(true);
+       if(settings.get_value("draw.region",value) && value=="0")
+               set_region_flag(false);
+       else
+               set_region_flag(true);
+
+       if(settings.get_value("draw.outline",value) && value=="0")
+               set_outline_flag(false);
        else
-               set_region_only_flag(false);
+               set_outline_flag(true);
 
        if(settings.get_value("draw.auto_export",value) && value=="1")
                set_auto_export_flag(true);
@@ -329,7 +339,8 @@ StateDraw_Context::save_settings()
        settings.set_value("draw.auto_loop",get_auto_loop_flag()?"1":"0");
        settings.set_value("draw.auto_extend",get_auto_extend_flag()?"1":"0");
        settings.set_value("draw.auto_link",get_auto_link_flag()?"1":"0");
-       settings.set_value("draw.region_only",get_region_only_flag()?"1":"0");
+       settings.set_value("draw.region",get_region_flag()?"1":"0");
+       settings.set_value("draw.outline",get_outline_flag()?"1":"0");
        settings.set_value("draw.auto_export",get_auto_export_flag()?"1":"0");
        settings.set_value("draw.min_pressure",strprintf("%f",get_min_pressure()));
        settings.set_value("draw.feather",strprintf("%f",get_feather()));
@@ -386,14 +397,15 @@ StateDraw_Context::StateDraw_Context(CanvasView* canvas_view):
        canvas_view_(canvas_view),
        is_working(*canvas_view),
        loop_(false),
-       prev_workarea_layer_status_(get_work_area()->allow_layer_clicks),
+       prev_workarea_layer_status_(get_work_area()->get_allow_layer_clicks()),
        settings(synfigapp::Main::get_selected_input_device()->settings()),
        entry_id(),
        checkbutton_pressure_width(_("Pressure Width")),
        checkbutton_auto_loop(_("Auto Loop")),
        checkbutton_auto_extend(_("Auto Extend")),
        checkbutton_auto_link(_("Auto Link")),
-       checkbutton_region_only(_("Create Region Only")),
+       checkbutton_region(_("Create Region")),
+       checkbutton_outline(_("Create Outline")),
        checkbutton_auto_export(_("Auto Export")),
        button_fill_last_stroke(_("Fill Last Stroke")),
        adj_min_pressure(0,0,1,0.01,0.1),
@@ -415,23 +427,24 @@ 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_pressure_width,0, 2, 2, 3, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
-       options_table.attach(checkbutton_auto_loop,             0, 2, 3, 4, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
-       options_table.attach(checkbutton_auto_extend,   0, 2, 4, 5, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
-       options_table.attach(checkbutton_auto_link,             0, 2, 5, 6, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
-       options_table.attach(checkbutton_region_only,   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(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, 2, 8, 9, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
-       options_table.attach(spin_min_pressure,                 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(*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(_("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(check_localerror,                  0, 2, 11, 12, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
-       options_table.attach(*manage(new Gtk::Label(_("Smooth"))), 0, 1, 12, 13, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
-       options_table.attach(spin_globalthres,                  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);
 
@@ -448,10 +461,10 @@ StateDraw_Context::StateDraw_Context(CanvasView* canvas_view):
        get_work_area()->set_type_mask(Duck::TYPE_ALL-Duck::TYPE_TANGENT-Duck::TYPE_WIDTH);
 
        // Turn off layer clicking
-       get_work_area()->allow_layer_clicks=false;
+       get_work_area()->set_allow_layer_clicks(false);
 
        // Turn off duck clicking
-       get_work_area()->allow_duck_clicks=false;
+       get_work_area()->set_allow_duck_clicks(false);
 
        // clear out the ducks
        //get_work_area()->clear_ducks();
@@ -532,10 +545,10 @@ StateDraw_Context::~StateDraw_Context()
        get_canvas_view()->work_area->reset_cursor();
 
        // Restore layer clicking
-       get_work_area()->allow_layer_clicks=prev_workarea_layer_status_;
+       get_work_area()->set_allow_layer_clicks(prev_workarea_layer_status_);
 
        // Restore duck clicking
-       get_work_area()->allow_duck_clicks=true;
+       get_work_area()->set_allow_duck_clicks(true);
 
        // Enable the time bar
        get_canvas_view()->set_sensitive_timebar(true);
@@ -575,7 +588,7 @@ StateDraw_Context::event_mouse_down_handler(const Smach::event& x)
                        return Smach::RESULT_ACCEPT;
                }
 
-       case BUTTON_RIGHT: // Intercept the right-button click to short-circut the pop-up menu
+       case BUTTON_RIGHT: // Intercept the right-button click to short-circuit the pop-up menu
                return Smach::RESULT_ACCEPT;
 
        default:
@@ -758,7 +771,7 @@ StateDraw_Context::new_bline(std::list<synfig::BLinePoint> bline,bool loop_bline
        bool extend_start=false,extend_finish=false,complete_loop=false;
        bool extend_start_join_same=false,extend_start_join_different=false;
        bool extend_finish_join_same=false,extend_finish_join_different=false;
-       int start_duck_index = 0,finish_duck_index = 0; // initialised to keep the compiler happy; shouldn't be needed though
+       int start_duck_index = 0,finish_duck_index = 0; // initialized to keep the compiler happy; shouldn't be needed though
        ValueNode_BLine::Handle start_duck_value_node_bline=NULL,finish_duck_value_node_bline=NULL;
 
        // Find any ducks at the start or end that we might attach to
@@ -1006,15 +1019,16 @@ StateDraw_Context::new_bline(std::list<synfig::BLinePoint> bline,bool loop_bline
 
                synfigapp::PushMode push_mode(get_canvas_interface(),synfigapp::MODE_NORMAL);
 
-               if(get_region_only_flag())
+               // if they're both defined, we'll add the region later
+               if(get_outline_flag())
                {
-                       layer=get_canvas_interface()->add_layer_to("region",canvas,depth);
-                       layer->set_description(get_id()+_(" Region"));
+                       layer=get_canvas_interface()->add_layer_to("outline",canvas,depth);
+                       layer->set_description(get_id()+_(" Outline"));
                }
                else
                {
-                       layer=get_canvas_interface()->add_layer_to("outline",canvas,depth);
-                       layer->set_description(get_id()+_(" Outline"));
+                       layer=get_canvas_interface()->add_layer_to("region",canvas,depth);
+                       layer->set_description(get_id()+_(" Region"));
                }
 
                if(get_feather())
@@ -1054,8 +1068,13 @@ StateDraw_Context::new_bline(std::list<synfig::BLinePoint> bline,bool loop_bline
                //refresh_ducks();
        }
 
-       increment_id();
        last_stroke=value_node;
+       last_stroke_id=get_id();
+
+       if(get_outline_flag() && get_region_flag())
+               fill_last_stroke();
+
+       increment_id();
        return Smach::RESULT_ACCEPT;
 }
 
@@ -1525,6 +1544,7 @@ StateDraw_Context::fill_last_stroke()
        layer=get_canvas_interface()->add_layer("region");
        assert(layer);
        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"));
 
@@ -1533,7 +1553,7 @@ StateDraw_Context::fill_last_stroke()
        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("segment_list")))
+       if(!action->set_param("param",String("bline")))
                synfig::error("LayerParamConnect didn't like \"param\"");
        if(!action->set_param("value_node",ValueNode::Handle(last_stroke)))
                synfig::error("LayerParamConnect didn't like \"value_node\"");