**
** \legal
** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
+** Copyright (c) 2007, 2008 Chris Moore
**
** This package is free software; you can redistribute it and/or
** modify it under the terms of the GNU General Public License as
#include "onemoment.h"
+#include "general.h"
+
#endif
/* === U S I N G =========================================================== */
grid_snap(false),
guide_snap(false),
grid_size(1.0/4.0,1.0/4.0),
- show_persistant_strokes(true)
+ show_persistent_strokes(true)
{
axis_lock=false;
drag_offset_=Point(0,0);
Duckmatic::~Duckmatic()
{
clear_ducks();
- //synfig::info("Duckmatic::~Duckmatic(): Deleted. Duck Count=%d",Duck::duck_count);
+
+ if (Duck::duck_count)
+ synfig::error("%d ducks not yet deleted!", Duck::duck_count);
+
+ if (getenv("SYNFIG_DEBUG_DESTRUCTORS"))
+ synfig::info("Duckmatic::~Duckmatic(): Deleted");
+}
+
+void
+Duckmatic::set_flip_x(bool flip_x)
+{
+ flip_x_ = flip_x;
+}
+
+void
+Duckmatic::set_flip_y(bool flip_y)
+{
+ flip_y_ = flip_y;
}
void
bezier_list_.clear();
stroke_list_.clear();
- if(show_persistant_strokes)
- stroke_list_=persistant_stroke_list_;
+ if(show_persistent_strokes)
+ stroke_list_=persistent_stroke_list_;
}
//! Returns \a true if the given duck is currently selected
}
}
-
-
Duckmatic::GuideList::iterator
Duckmatic::find_guide_x(synfig::Point pos, float radius)
{
{
const Type type(get_type_mask());
- if(( x->get_type() && (!(type & x->get_type())) ) )
- {
+ if(( x->get_type() && (!(type & x->get_type())) || !x->get_editable() ) )
return false;
- }
+
if(x->get_value_desc().parent_is_layer_param() && type & Duck::TYPE_POSITION)
{
Layer::Handle layer(x->get_value_desc().get_layer());
String layer_name(layer->get_name());
- if(
- layer_name=="outline" ||
- layer_name=="region" ||
- layer_name=="polygon" ||
- layer_name=="curve_gradient"
- )
+
+ if (layer_name == "outline" || layer_name == "region" || layer_name == "plant" ||
+ layer_name == "polygon" || layer_name == "curve_gradient")
return false;
+
if((layer_name=="PasteCanvas"|| layer_name=="paste_canvas") &&
!layer->get_param("children_lock").get(bool()))
return false;
select_duck(duck);
}
-
void
Duckmatic::translate_selected_ducks(const synfig::Vector& vector)
{
}
Point
-Duckmatic::snap_point_to_grid(const Point& x, float radius)const
+Duckmatic::snap_point_to_grid(const synfig::Point& x, float radius)const
{
Point ret(x);
for(i=0,iter=selected_ducks.begin();iter!=selected_ducks.end();++iter,i++)
{
- if((*iter)->get_type()!=Duck::TYPE_VERTEX&&(*iter)->get_type()!=Duck::TYPE_POSITION)continue;
+ if((*iter)->get_type()!=Duck::TYPE_VERTEX &&
+ (*iter)->get_type()!=Duck::TYPE_POSITION)
+ continue;
(*iter)->set_trans_point(positions[i]+vect);
}
for(i=0,iter=selected_ducks.begin();iter!=selected_ducks.end();++iter,i++)
{
- if((*iter)->get_type()==Duck::TYPE_VERTEX||(*iter)->get_type()==Duck::TYPE_POSITION)continue;
+ if((*iter)->get_type()==Duck::TYPE_VERTEX ||
+ (*iter)->get_type()==Duck::TYPE_POSITION)
+ continue;
(*iter)->set_trans_point(positions[i]+vect);
}
last_translate_=vect;
}
-
-
-
-
-
-
-
-
-
void
Duckmatic::signal_edited_selected_ducks()
{
// Go ahead and call everyone's signals
for(iter=ducks.begin();iter!=ducks.end();++iter)
{
- if(!(*iter)->signal_edited()((*iter)->get_point()))
+ if ((*iter)->get_type() == Duck::TYPE_ANGLE)
+ {
+ if(!(*iter)->signal_edited_angle()((*iter)->get_rotations()))
+ {
+ selected_ducks=old_set;
+ throw String("Bad edit");
+ }
+ }
+ else if (App::restrict_radius_ducks &&
+ (*iter)->is_radius())
+ {
+ Point point((*iter)->get_point());
+ bool changed = false;
+
+ if (point[0] * (flip_x_ ? -1 : 1) < 0)
+ {
+ point[0] = 0;
+ changed = true;
+ }
+ if (point[1] * (flip_y_ ? -1 : 1) < 0)
+ {
+ point[1] = 0;
+ changed = true;
+ }
+
+ if (changed) (*iter)->set_point(point);
+
+ if(!(*iter)->signal_edited()(point))
+ {
+ selected_ducks=old_set;
+ throw String("Bad edit");
+ }
+ }
+ else
{
- selected_ducks=old_set;
- throw String("Bad edit");
+ if(!(*iter)->signal_edited()((*iter)->get_point()))
+ {
+ selected_ducks=old_set;
+ throw String("Bad edit");
+ }
}
}
selected_ducks=old_set;
}
}
-
-
-
-
void
Duckmatic::add_duck(const etl::handle<Duck> &duck)
{
}
void
-Duckmatic::add_persistant_stroke(etl::smart_ptr<std::list<synfig::Point> > stroke_point_list, const synfig::Color& color)
+Duckmatic::add_persistent_stroke(etl::smart_ptr<std::list<synfig::Point> > stroke_point_list, const synfig::Color& color)
{
add_stroke(stroke_point_list,color);
- persistant_stroke_list_.push_back(stroke_list_.back());
+ persistent_stroke_list_.push_back(stroke_list_.back());
}
void
-Duckmatic::clear_persistant_strokes()
+Duckmatic::clear_persistent_strokes()
{
- persistant_stroke_list_.clear();
+ persistent_stroke_list_.clear();
}
void
-Duckmatic::set_show_persistant_strokes(bool x)
+Duckmatic::set_show_persistent_strokes(bool x)
{
- if(x!=show_persistant_strokes)
+ if(x!=show_persistent_strokes)
{
- show_persistant_strokes=x;
+ show_persistent_strokes=x;
if(x)
- stroke_list_=persistant_stroke_list_;
+ stroke_list_=persistent_stroke_list_;
else
stroke_list_.clear();
}
return bezier_list_.back();
}
-
etl::handle<Duckmatic::Duck>
Duckmatic::find_duck(synfig::Point point, synfig::Real radius, Duck::Type type)
{
{
const Duck::Handle& duck(iter->second);
- if(!duck->get_editable())
+ if(duck->get_ignore())
continue;
Real dist((duck->get_trans_point()-point).mag_squared());
if(duck->get_type()&Duck::TYPE_VERTEX)
dist*=1.0001;
+ else if(duck->get_type()&Duck::TYPE_RADIUS)
+ dist*=0.9999;
if(dist<=closest && !( duck->get_type() && (!(type & duck->get_type())) ) )
{
return 0;
}
-
-
bool
Duckmatic::save_sketch(const synfig::String& filename)const
{
+ ChangeLocale change_locale(LC_NUMERIC, "C");
std::ofstream file(filename.c_str());
if(!file)return false;
std::list<etl::handle<Stroke> >::const_iterator iter;
- for(iter=persistant_stroke_list_.begin();iter!=persistant_stroke_list_.end();++iter)
+ for(iter=persistent_stroke_list_.begin();iter!=persistent_stroke_list_.end();++iter)
{
file<<"C "
<<(*iter)->color.get_r()<<' '
bool
Duckmatic::load_sketch(const synfig::String& filename)
{
+ ChangeLocale change_locale(LC_NUMERIC, "C");
std::ifstream file(filename.c_str());
if(!file)
return false;
}
-
etl::smart_ptr<std::list<synfig::Point> > stroke_data;
while(file)
synfig::warning("Bad color line \"%s\"",line.c_str());
r=0;g=0;b=0;
}
- add_persistant_stroke(stroke_data, synfig::Color(r,g,b));
+ add_persistent_stroke(stroke_data, synfig::Color(r,g,b));
}
break;
case 'V':
if(!stroke_data)
{
stroke_data.spawn();
- add_persistant_stroke(stroke_data, synfig::Color(0,0,0));
+ add_persistent_stroke(stroke_data, synfig::Color(0,0,0));
}
float x,y;
if(!strscanf(line,"V %f %f",&x, &y))
return true;
}
-
-
-
-
-
-
-
Duckmatic::Push::Push(Duckmatic *duckmatic_):
duckmatic_(duckmatic_)
{
needs_restore=false;
}
-
-
-
-
-
-
-
-
inline String guid_string(const synfigapp::ValueDesc& x)
{
if(x.parent_is_layer_param())
duck->set_radius(true);
duck->set_type(Duck::TYPE_RADIUS);
- duck->set_point(Point(value_desc.get_value(get_time()).get(Real()),0));
+ // put the duck on the right hand side of the center, whether the display is flipped or not
+ duck->set_point(Point(value_desc.get_value(get_time()).get(Real()) * (flip_x_ ? -1 : 1), 0));
duck->set_name(guid_string(value_desc));
if(value_desc.is_value_node())
{
duck->set_scalar(param_desc->get_scalar());
}
- duck->signal_edited().clear();
+ duck->signal_edited().clear(); // value_desc.get_value_type() == ValueBase::TYPE_REAL:
duck->signal_edited().connect(
sigc::bind(
sigc::mem_fun(
duck->set_scalar(param_desc->get_scalar());
}
- duck->signal_edited().clear();
- duck->signal_edited().connect(
+ duck->signal_edited().clear(); // value_desc.get_value_type() == ValueBase::TYPE_ANGLE:
+ duck->signal_edited_angle().clear();
+ duck->signal_edited_angle().connect(
sigc::bind(
sigc::mem_fun(
*canvas_view,
- &studio::CanvasView::on_duck_changed
+ &studio::CanvasView::on_duck_angle_changed
),
value_desc
)
else
duck->set_type(Duck::TYPE_POSITION);
-
- duck->signal_edited().clear();
+ duck->signal_edited().clear(); // value_desc.get_value_type() == ValueBase::TYPE_VECTOR:
duck->signal_edited().connect(
sigc::bind(
sigc::mem_fun(
bezier->c1->set_scalar(TANGENT_BEZIER_SCALE);
bezier->c1->set_tangent(true);
-
if(!add_to_ducks(synfigapp::ValueDesc(value_node,2),canvas_view,transform_stack))
return false;
bezier->p2=last_duck();
ValueNode_Composite::Handle value_node;
value_node=ValueNode_Composite::Handle::cast_dynamic(value_desc.get_value_node());
-
if(!add_to_ducks(synfigapp::ValueDesc(value_node,0),canvas_view,transform_stack))
return false;
etl::handle<Duck> vertex_duck(last_duck());
return true;
}
-
break;
default:
break;