#include <gtkmm/scale.h>
#include <sigc++/connection.h>
+#include "general.h"
+
#endif
/* === U S I N G =========================================================== */
bool prev_workarea_layer_status_;
int nested;
- SigC::Connection process_queue_connection;
+ sigc::connection process_queue_connection;
ValueNode_BLine::Handle last_stroke;
synfig::String last_stroke_id;
Duckmatic::Type old_duckmask;
- void fill_last_stroke(int depth_offset);
+ void fill_last_stroke();
+ 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);
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());
}
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),
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_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);
- button_fill_last_stroke.signal_pressed().connect(sigc::bind(sigc::mem_fun(*this,&StateDraw_Context::fill_last_stroke), 0));
+ button_fill_last_stroke.signal_pressed().connect(sigc::mem_fun(*this,&StateDraw_Context::fill_last_stroke));
check_localerror.signal_toggled().connect(sigc::mem_fun(*this,&StateDraw_Context::UpdateErrorBox));
options_table.show_all();
Gtk::StockID("synfig-fill"),
_("Fill Last Stroke")
)->signal_clicked().connect(
- sigc::bind(
- sigc::mem_fun(
- *this,
- &StateDraw_Context::fill_last_stroke),
- 0));
+ sigc::mem_fun(
+ *this,
+ &StateDraw_Context::fill_last_stroke));
}
Smach::event_result
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;
}
}
// 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();
}
// 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);
Smach::event_result
StateDraw_Context::new_bline(std::list<synfig::BLinePoint> 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"));
- 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;
(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);
// 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
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);
// if the new line's start didn't extend an existing line,
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)
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)
) -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);
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;
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 */
// increment_id();
// return Smach::RESULT_ERROR;
}
- }
- // Create the layer
+ last_stroke=value_node;
+ last_stroke_id=get_id();
+
{
+ // Create the layer(s)
Layer::Handle layer;
Canvas::Handle canvas(get_canvas_view()->get_canvas());
int depth(0);
depth=layer->get_depth();
canvas=layer->get_canvas();
}
- get_canvas_interface()->get_selection_manager()->clear_selected_layers();
+
+ // fill_last_stroke() will take care of clearing the selection if we're calling it
+ if(get_outline_flag() && get_region_flag())
+ {
+ 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();
//int number(synfig::UniqueID().get_uid());
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"));
}
//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"));
//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();
}
- last_stroke=value_node;
- last_stroke_id=get_id();
-
- if(get_outline_flag() && get_region_flag())
- fill_last_stroke(1);
-
increment_id();
return Smach::RESULT_ACCEPT;
}
{
if (started) printf(", "); else started = true;
if (start != -1)
+ {
if (dir != 0)
printf("%d--%d", start, prev);
else
printf("%d", start);
+ }
printf(")");
}
printf("\n");
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
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
{
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;
if(value_prev.get_parent_value_node()==value_next.get_parent_value_node() &&
value_prev.get_parent_value_node()!=value_desc.get_parent_value_node())
{
- DEBUGPOINT();
vertex_list.erase(iter);
done=false;
break;
// if(value_prev.get_value_node()==value_desc.get_value_node() ||
// value_desc.get_value_node()==value_next.get_value_node())
// {
- // // DEBUGPOINT();
// vertex_list.erase(iter);
// done=false;
// printf("erased node - i = %d\n", i);
// // if previous is the same as next, remove previous? or next?
// if(value_prev.get_value_node()==value_next.get_value_node())
// {
- // // DEBUGPOINT();
// vertex_list.erase(next);
// // vertex_list.erase(prev);
// done=false;
// strprintf("same parent, different points this %d < next-1 %d",
// value_desc.get_index(), ((value_next.get_index()-1))),
// current);
- // // DEBUGPOINT();
// for (int index = value_desc.get_index()+1; index < value_next.get_index(); index++)
// {
// printf("inserting up %d\n", index);
// strprintf("same parent, different points next %d < this-1 %d",
// value_next.get_index(), ((value_desc.get_index()-1))),
// current);
- // // DEBUGPOINT();
// for (int index = value_desc.get_index()-1; index > value_next.get_index(); index--)
// {
// printf("inserting down %d\n", index);
if((vertex.get_vertex()-vertex_next.get_vertex()).mag_squared()<radius*radius)
{
printf("in one - it's close\n");
- // DEBUGPOINT();
ValueNode_Composite::Handle value_node;
ValueNode_Composite::Handle value_node_next;
value_node=ValueNode_Composite::Handle::cast_dynamic(value_desc.get_value_node().clone());
synfig::info(__FILE__":%d: Unable to properly connect blines.",__LINE__);
continue;
}
- // DEBUGPOINT();
// \todo if next isn't split, don't we want to copy its 'Tangent 1' instead?
value_node->set_link(5,value_node_next->get_link(5)); // Tangent 2
value_node->set_link(3,ValueNode_Const::create(true)); // Split Tangents
else if (value_prev.parent_is_value_node())
{
printf("in two - it's far\n");
- // DEBUGPOINT();
// \todo this only makes sense if prev is on the same bline
printf("this is index %d\n", value_desc.get_index());
printf("prev is index %d\n", value_prev.get_index());
if (value_desc.get_index()<LinkableValueNode::Handle::cast_static(value_desc.get_parent_value_node())->link_count()-1)
{
printf("in two - b\n");
- // DEBUGPOINT();
printf("inserting node with index %d\n", value_desc.get_index()+1);
vertex_list.insert(next,
synfigapp::ValueDesc(value_desc.get_parent_value_node(),
if(value_desc.get_index()>0)
{
printf("in two - a\n");
- // DEBUGPOINT();
printf("inserting node on this line with index %d\n",
value_desc.get_index()-1);
vertex_list.insert(next,
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())
{
}
}
-void
-StateDraw_Context::fill_last_stroke(int depth_offset)
+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"));
layer=get_canvas_view()->get_selection_manager()->get_selected_layer();
if(layer)
{
- depth=layer->get_depth() + depth_offset;
+ depth=layer->get_depth();
canvas=layer->get_canvas();
}
+ 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"));
{
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
+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);
}