X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=synfig-core%2Ftrunk%2Fsrc%2Fsynfig%2Flayer.cpp;h=8fcbfbff9843dcfffd41611292315f7bc5ea43ce;hb=9459638ad6797b8139f1e9f0715c96076dbf0890;hp=24597cf75917bbda5f448b9ebc2ab84044bb3499;hpb=e3acc0b267b14fda5db3c7bbb2f218b993ef84b3;p=synfig.git diff --git a/synfig-core/trunk/src/synfig/layer.cpp b/synfig-core/trunk/src/synfig/layer.cpp index 24597cf..8fcbfbf 100644 --- a/synfig-core/trunk/src/synfig/layer.cpp +++ b/synfig-core/trunk/src/synfig/layer.cpp @@ -1,27 +1,29 @@ -/* === S I N F G =========================================================== */ +/* === S Y N F I G ========================================================= */ /*! \file layer.cpp ** \brief Layer class implementation ** -** $Id: layer.cpp,v 1.2 2005/01/24 03:08:17 darco Exp $ +** $Id$ ** ** \legal -** Copyright (c) 2002 Robert B. Quattlebaum Jr. +** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley +** Copyright (c) 2007, 2008 Chris Moore ** -** This software and associated documentation -** are CONFIDENTIAL and PROPRIETARY property of -** the above-mentioned copyright holder. +** This package is free software; you can redistribute it and/or +** modify it under the terms of the GNU General Public License as +** published by the Free Software Foundation; either version 2 of +** the License, or (at your option) any later version. ** -** You may not copy, print, publish, or in any -** other way distribute this software without -** a prior written agreement with -** the copyright holder. +** This package is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +** General Public License for more details. ** \endlegal */ /* ========================================================================= */ /* === H E A D E R S ======================================================= */ -#define SINFG_NO_ANGLE +#define SYNFIG_NO_ANGLE #ifdef USING_PCH # include "pch.h" @@ -43,6 +45,7 @@ #include "layer_polygon.h" #include "layer_pastecanvas.h" #include "layer_motionblur.h" +#include "layer_duplicate.h" #include "valuenode_const.h" @@ -57,7 +60,7 @@ using namespace etl; using namespace std; -using namespace sinfg; +using namespace synfig; /* === G L O B A L S ======================================================= */ @@ -69,7 +72,7 @@ struct _LayerCounter ~_LayerCounter() { if(counter) - sinfg::error("%d layers not yet deleted!",counter); + synfig::error("%d layers not yet deleted!",counter); } } _layer_counter; @@ -94,14 +97,29 @@ Layer::subsys_init() { _layer_book=new Book(); -#define INCLUDE_LAYER(class) sinfg::Layer::book()[sinfg::String(class::name__)]=BookEntry(class::create,class::name__,class::local_name__,class::category__,class::cvs_id__,class::version__) -#define LAYER_ALIAS(class,alias) sinfg::Layer::book()[sinfg::String(alias)]=sinfg::Layer::BookEntry(class::create,alias,alias,_("Do Not Use"),class::cvs_id__,class::version__); - - INCLUDE_LAYER(Layer_SolidColor); - INCLUDE_LAYER(Layer_PasteCanvas); - INCLUDE_LAYER(Layer_Polygon); - LAYER_ALIAS(Layer_Polygon,"Polygon"); - INCLUDE_LAYER(Layer_MotionBlur); +#define INCLUDE_LAYER(class) \ + synfig::Layer::book() [synfig::String(class::name__)] = \ + BookEntry(class::create, \ + class::name__, \ + dgettext("synfig", class::local_name__), \ + class::category__, \ + class::cvs_id__, \ + class::version__) + +#define LAYER_ALIAS(class,alias) \ + synfig::Layer::book()[synfig::String(alias)] = \ + BookEntry(class::create, \ + alias, \ + alias, \ + CATEGORY_DO_NOT_USE, \ + class::cvs_id__, \ + class::version__) + + INCLUDE_LAYER(Layer_SolidColor); LAYER_ALIAS(Layer_SolidColor, "solid_color"); + INCLUDE_LAYER(Layer_PasteCanvas); LAYER_ALIAS(Layer_PasteCanvas, "paste_canvas"); + INCLUDE_LAYER(Layer_Polygon); LAYER_ALIAS(Layer_Polygon, "Polygon"); + INCLUDE_LAYER(Layer_MotionBlur); LAYER_ALIAS(Layer_MotionBlur, "motion_blur"); + INCLUDE_LAYER(Layer_Duplicate); #undef INCLUDE_LAYER @@ -126,18 +144,18 @@ Layer::Layer(): } Layer::LooseHandle -sinfg::Layer::create(const String &name) +synfig::Layer::create(const String &name) { if(!book().count(name)) { return Layer::LooseHandle(new Layer_Mime(name)); } - + Layer* layer(book()[name].factory()); return Layer::LooseHandle(layer); } -sinfg::Layer::~Layer() +synfig::Layer::~Layer() { _LayerCounter::counter--; while(!dynamic_param_list_.empty()) @@ -145,15 +163,15 @@ sinfg::Layer::~Layer() remove_child(dynamic_param_list_.begin()->second.get()); dynamic_param_list_.erase(dynamic_param_list_.begin()); } - + remove_from_all_groups(); - + parent_death_connect_.disconnect(); begin_delete(); } void -sinfg::Layer::set_canvas(etl::loose_handle x) +synfig::Layer::set_canvas(etl::loose_handle x) { if(canvas_!=x) { @@ -167,7 +185,7 @@ sinfg::Layer::set_canvas(etl::loose_handle x) *this, &Layer::set_canvas ), - etl::loose_handle(0) + etl::loose_handle(0) ) ); } @@ -176,12 +194,12 @@ sinfg::Layer::set_canvas(etl::loose_handle x) } void -sinfg::Layer::on_canvas_set() +synfig::Layer::on_canvas_set() { } -etl::loose_handle -sinfg::Layer::get_canvas()const +etl::loose_handle +synfig::Layer::get_canvas()const { return canvas_; } @@ -191,7 +209,7 @@ Layer::get_depth()const { if(!get_canvas()) return -1; - return get_canvas()->get_depth(const_cast(this)); + return get_canvas()->get_depth(const_cast(this)); } void @@ -212,7 +230,7 @@ Layer::set_description(const String& x) if(description_!=x) { description_=x; - signal_description_changed_(); + signal_description_changed_(); } } @@ -223,19 +241,19 @@ Layer::connect_dynamic_param(const String& param, etl::loose_handle v if(previous==value_node) return true; - + dynamic_param_list_[param]=ValueNode::Handle(value_node); - + if(previous) remove_child(previous.get()); - + add_child(value_node.get()); - + if(!value_node->is_exported() && get_canvas()) { value_node->set_parent_canvas(get_canvas()); } - + changed(); return true; } @@ -248,7 +266,19 @@ Layer::disconnect_dynamic_param(const String& param) if(previous) { dynamic_param_list_.erase(param); - remove_child(previous.get()); + + // fix 2353284: if two parameters in the same layer are + // connected to the same valuenode and we disconnect one of + // them, the parent-child relationship for the remaining + // connection was being deleted. now we search the parameter + // list to see if another parameter uses the same valuenode + DynamicParamList::const_iterator iter; + for (iter = dynamic_param_list().begin(); iter != dynamic_param_list().end(); iter++) + if (iter->second == previous) + break; + if (iter == dynamic_param_list().end()) + remove_child(previous.get()); + changed(); } return true; @@ -258,14 +288,13 @@ void Layer::on_changed() { dirty_time_=Time::end(); - if(active()) - Node::on_changed(); + Node::on_changed(); } bool Layer::set_param(const String ¶m, const ValueBase &value) { - if(param=="z_depth" && value.same_as(z_depth_)) + if(param=="z_depth" && value.same_type_as(z_depth_)) { z_depth_=value.get(z_depth_); return true; @@ -280,21 +309,25 @@ Layer::get_transform()const } float -Layer::get_z_depth(const sinfg::Time& t)const +Layer::get_z_depth(const synfig::Time& t)const { if(!dynamic_param_list().count("z_depth")) return z_depth_; return (*dynamic_param_list().find("z_depth")->second)(t).get(Real()); } -Layer* +Layer::Handle Layer::simple_clone()const { if(!book().count(get_name())) return 0; - Layer *ret = create(get_name()).get(); - ret->set_canvas(get_canvas()); + Handle ret = create(get_name()).get(); + ret->group_=group_; + //ret->set_canvas(get_canvas()); ret->set_description(get_description()); + ret->set_active(active()); ret->set_param_list(get_param_list()); + for(DynamicParamList::const_iterator iter=dynamic_param_list().begin();iter!=dynamic_param_list().end();++iter) + ret->connect_dynamic_param(iter->first, iter->second); return ret; } @@ -302,47 +335,46 @@ Layer::Handle Layer::clone(const GUID& deriv_guid) const { if(!book().count(get_name())) return 0; - + //Layer *ret = book()[get_name()].factory();//create(get_name()).get(); Handle ret = create(get_name()).get(); - + ret->group_=group_; //ret->set_canvas(get_canvas()); ret->set_description(get_description()); ret->set_active(active()); ret->set_guid(get_guid()^deriv_guid); - + //ret->set_param_list(get_param_list()); - // Process the parameter list sothat - // we can duplicate any inlinecanvases + // Process the parameter list so that + // we can duplicate any inline canvases ParamList param_list(get_param_list()); for(ParamList::const_iterator iter(param_list.begin()); iter != param_list.end(); ++iter) { if(dynamic_param_list().count(iter->first)==0 && iter->second.get_type()==ValueBase::TYPE_CANVAS) { - // This parameter is a canvas. We need a close look. Canvas::Handle canvas(iter->second.get(Canvas::Handle())); - if(canvas->is_inline()) + if(canvas && canvas->is_inline()) { - // This parameter is an inlinecanvas! we need to clone it - // before we set it as aparameter. + // This parameter is an inline canvas! we need to clone it + // before we set it as a parameter. Canvas::Handle new_canvas(canvas->clone(deriv_guid)); ValueBase value(new_canvas); ret->set_param(iter->first, value); continue; } } - + // This is a normal parameter,go ahead and set it. ret->set_param(iter->first, iter->second); } - + // Duplicate the dynamic paramlist, but only the exported data nodes DynamicParamList::const_iterator iter; for(iter=dynamic_param_list().begin();iter!=dynamic_param_list().end();++iter) { - // Make sure we clone inlinecanvases + // Make sure we clone inline canvases if(iter->second->get_type()==ValueBase::TYPE_CANVAS) { Canvas::Handle canvas((*iter->second)(0).get(Canvas::Handle())); @@ -354,7 +386,7 @@ Layer::clone(const GUID& deriv_guid) const continue; } } - + if(iter->second->is_exported()) ret->connect_dynamic_param(iter->first,iter->second); else @@ -362,10 +394,16 @@ Layer::clone(const GUID& deriv_guid) const } //ret->set_canvas(0); - + return ret; } +bool +Layer::reads_context() const +{ + return false; +} + Rect Layer::get_full_bounding_rect(Context context)const { @@ -425,7 +463,7 @@ Layer::get_version()const } bool -Layer::set_version(const String &ver) +Layer::set_version(const String &/*ver*/) { return false; } @@ -456,8 +494,8 @@ Layer::get_color(Context context, const Point &pos)const return context.get_color(pos); } -sinfg::Layer::Handle -Layer::hit_check(sinfg::Context context, const sinfg::Point &pos)const +synfig::Layer::Handle +Layer::hit_check(synfig::Context context, const synfig::Point &pos)const { return context.hit_check(pos); } @@ -466,7 +504,7 @@ Layer::hit_check(sinfg::Context context, const sinfg::Point &pos)const ** is anything but accelerated... */ bool -Layer::accelerated_render(Context context,Surface *surface,int quality, const RendDesc &renddesc, ProgressCallback *cb) const +Layer::accelerated_render(Context context,Surface *surface,int /*quality*/, const RendDesc &renddesc, ProgressCallback *cb) const { handle target=surface_target(surface); if(!target) @@ -521,10 +559,10 @@ Layer::get_times_vfunc(Node::time_set &set) const { DynamicParamList::const_iterator i = dynamic_param_list_.begin(), end = dynamic_param_list_.end(); - + for(; i != end; ++i) { - const Node::time_set &tset = i->second->get_times(); + const Node::time_set &tset = i->second->get_times(); set.insert(tset.begin(),tset.end()); } } @@ -540,14 +578,14 @@ Layer::add_to_group(const String&x) group_=x; signal_added_to_group()(group_); } - + void Layer::remove_from_group(const String&x) { if(group_==x) remove_from_all_groups(); } - + void Layer::remove_from_all_groups() { @@ -556,9 +594,20 @@ Layer::remove_from_all_groups() signal_removed_from_group()(group_); group_.clear(); } - + String Layer::get_group()const { return group_; } + +const String +Layer::get_param_local_name(const String ¶m_name)const +{ + ParamVocab vocab = get_param_vocab(); + // loop to find the parameter in the parameter vocab - this gives us its local name + for (ParamVocab::iterator iter = vocab.begin(); iter != vocab.end(); iter++) + if (iter->get_name() == param_name) + return iter->get_local_name(); + return String(); +}