Tidying. No functional change.
[synfig.git] / synfig-core / trunk / src / synfig / canvas.cpp
index c0763b5..59d54af 100644 (file)
@@ -69,8 +69,9 @@ int _CanvasCounter::counter(0);
 
 /* === M E T H O D S ======================================================= */
 
-Canvas::Canvas(const string &id):
+Canvas::Canvas(const String &id):
        id_                     (id),
+       version_        (CURRENT_CANVAS_VERSION),
        cur_time_       (0),
        is_inline_      (false),
        is_dirty_       (true),
@@ -91,7 +92,6 @@ Canvas::~Canvas()
 {
        //if(is_inline() && parent_) assert(0);
        _CanvasCounter::counter--;
-       //DEBUGPOINT();
        clear();
        begin_delete();
 }
@@ -412,7 +412,6 @@ Canvas::add_value_node(ValueNode::Handle x, const String &id)
                return parent_->add_value_node(x,id);
 //             throw runtime_error("You cannot add a ValueNode to an inline Canvas");
 
-       //DEBUGPOINT();
        if(x->is_exported())
                throw runtime_error("ValueNode is already exported");
 
@@ -424,16 +423,13 @@ Canvas::add_value_node(ValueNode::Handle x, const String &id)
 
        try
        {
-               //DEBUGPOINT();
                if(PlaceholderValueNode::Handle::cast_dynamic(value_node_list_.find(id)))
                        throw Exception::IDNotFound("add_value_node()");
 
-               //DEBUGPOINT();
                throw Exception::IDAlreadyExists(id);
        }
        catch(Exception::IDNotFound)
        {
-               //DEBUGPOINT();
                x->set_id(id);
 
                x->set_parent_canvas(this);
@@ -443,7 +439,6 @@ Canvas::add_value_node(ValueNode::Handle x, const String &id)
                        synfig::error("Unable to add ValueNode");
                        throw std::runtime_error("Unable to add ValueNode");
                }
-               //DEBUGPOINT();
 
                return;
        }
@@ -663,7 +658,6 @@ Canvas::create()
 void
 Canvas::push_back(etl::handle<Layer> x)
 {
-//     DEBUGPOINT();
 //     int i(x->count());
        insert(end(),x);
        //if(x->count()!=i+1)synfig::info("push_back before %d, after %d",i,x->count());
@@ -672,7 +666,6 @@ Canvas::push_back(etl::handle<Layer> x)
 void
 Canvas::push_front(etl::handle<Layer> x)
 {
-//     DEBUGPOINT();
 //     int i(x->count());
        insert(begin(),x);
        //if(x->count()!=i+1)synfig::error("push_front before %d, after %d",i,x->count());
@@ -734,7 +727,7 @@ Canvas::push_back_simple(etl::handle<Layer> x)
 }
 
 void
-Canvas::erase(Canvas::iterator iter)
+Canvas::erase(iterator iter)
 {
        if(!(*iter)->get_group().empty())
                remove_group_pair((*iter)->get_group(),(*iter));
@@ -1017,6 +1010,11 @@ Canvas::get_meta_data_keys()const
        return ret;
 }
 
+/* note - the "Motion Blur" and "Duplicate" layers need the dynamic
+                 parameters of any PasteCanvas layers they loop over to be
+                 maintained.  When the variables in the following function
+                 refer to "motion blur", they mean either of these two
+                 layers. */
 void
 synfig::optimize_layers(Context context, Canvas::Handle op_canvas, bool seen_motion_blur_in_parent)
 {
@@ -1045,7 +1043,7 @@ synfig::optimize_layers(Context context, Canvas::Handle op_canvas, bool seen_mot
                        if(value.get_type()==ValueBase::TYPE_REAL && value.get(Real())==0)
                                continue;
 
-                       if(layer->get_name()=="MotionBlur")
+                       if(layer->get_name()=="MotionBlur" || layer->get_name()=="duplicate")
                        {
                                float z_depth(layer->get_z_depth()*1.0001+i);
 
@@ -1119,36 +1117,43 @@ synfig::optimize_layers(Context context, Canvas::Handle op_canvas, bool seen_mot
 
 #ifdef SYNFIG_OPTIMIZE_PASTE_CANVAS
                        Canvas::iterator sub_iter;
-                       // Determine if we can just remove the paste canvas
-                       // altogether
-                       if(paste_canvas->get_blend_method()==Color::BLEND_COMPOSITE && paste_canvas->get_amount()==1.0f && paste_canvas->get_zoom()==0 && paste_canvas->get_time_offset()==0 && paste_canvas->get_origin()==Point(0,0))
-                       try{
-                               for(sub_iter=sub_canvas->begin();sub_iter!=sub_canvas->end();++sub_iter)
-                               {
-                                       Layer* layer=sub_iter->get();
 
-                                       // any layers that deform end up breaking things
-                                       // so do things the old way if we run into anything like this
-                                       if(!dynamic_cast<Layer_NoDeform*>(layer))
-                                               throw int();
+                       // Determine if we can just remove the paste canvas altogether
+                       if (paste_canvas->get_blend_method()    == Color::BLEND_COMPOSITE       &&
+                               paste_canvas->get_amount()                      == 1.0f                                         &&
+                               paste_canvas->get_zoom()                        == 0                                            &&
+                               paste_canvas->get_time_offset()         == 0                                            &&
+                               paste_canvas->get_origin()                      == Point(0,0)                           )
+                               try {
+                                       for(sub_iter=sub_canvas->begin();sub_iter!=sub_canvas->end();++sub_iter)
+                                       {
+                                               Layer* layer=sub_iter->get();
 
-                                       ValueBase value(layer->get_param("blend_method"));
-                                       if(value.get_type()!=ValueBase::TYPE_INTEGER || value.get(int())!=(int)Color::BLEND_COMPOSITE)
-                                               throw int();
-                               }
+                                               // any layers that deform end up breaking things
+                                               // so do things the old way if we run into anything like this
+                                               if(!dynamic_cast<Layer_NoDeform*>(layer))
+                                                       throw int();
 
-                               // It has turned out that we don't need a paste canvas
-                               // layer, so just go ahead and add all the layers onto
-                               // the current stack and be done with it
-                               while(sub_canvas->size())
-                               {
-                                       sort_list.push_back(std::pair<float,Layer::Handle>(z_depth,sub_canvas->front()));
-                                       //op_canvas->push_back_simple(sub_canvas->front());
-                                       sub_canvas->pop_front();
+                                               ValueBase value(layer->get_param("blend_method"));
+                                               if(value.get_type()!=ValueBase::TYPE_INTEGER || value.get(int())!=(int)Color::BLEND_COMPOSITE)
+                                                       throw int();
+                                       }
+
+                                       // It has turned out that we don't need a paste canvas
+                                       // layer, so just go ahead and add all the layers onto
+                                       // the current stack and be done with it
+                                       while(sub_canvas->size())
+                                       {
+                                               sort_list.push_back(std::pair<float,Layer::Handle>(z_depth,sub_canvas->front()));
+                                               //op_canvas->push_back_simple(sub_canvas->front());
+                                               sub_canvas->pop_front();
+                                       }
+                                       continue;
                                }
-                               continue;
-                       }catch(int) { }
-#endif
+                               catch(int)
+                               { }
+#endif // SYNFIG_OPTIMIZE_PASTE_CANVAS
+
                        Layer::Handle new_layer(Layer::create("PasteCanvas"));
                        dynamic_cast<Layer_PasteCanvas*>(new_layer.get())->set_muck_with_time(false);
                        if (motion_blurred)
@@ -1258,13 +1263,13 @@ Canvas::remove_group_pair(String group, etl::handle<Layer> layer)
 }
 
 void
-Canvas::add_connection(Layer::LooseHandle layer, sigc::connection connection)
+Canvas::add_connection(etl::loose_handle<Layer> layer, sigc::connection connection)
 {
        connections_[layer].push_back(connection);
 }
 
 void
-Canvas::disconnect_connections(Layer::LooseHandle layer)
+Canvas::disconnect_connections(etl::loose_handle<Layer> layer)
 {
        std::vector<sigc::connection>::iterator iter;
        for(iter=connections_[layer].begin();iter!=connections_[layer].end();++iter)