Skip to content

Commit

Permalink
Fix ghosts synchronization for switch
Browse files Browse the repository at this point in the history
  • Loading branch information
blackwarthog committed Feb 1, 2016
1 parent c4bc157 commit eef6489
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 20 deletions.
61 changes: 43 additions & 18 deletions synfig-core/src/synfig/layer.cpp
Expand Up @@ -181,6 +181,7 @@ synfig::Layer::create(const String &name)
synfig::Layer::~Layer()
{
_LayerCounter::counter--;

while(!dynamic_param_list_.empty())
{
remove_child(dynamic_param_list_.begin()->second.get());
Expand Down Expand Up @@ -296,26 +297,36 @@ Layer::dynamic_param_changed(const String &param)
bool
Layer::connect_dynamic_param(const String& param, etl::loose_handle<ValueNode> value_node)
{
ValueNode::Handle previous(dynamic_param_list_[param]);
if (!value_node) return disconnect_dynamic_param(param);

ValueNode::Handle previous;
DynamicParamList::iterator i = dynamic_param_list_.find(param);
if (i != dynamic_param_list_.end()) previous = i->second;

if(previous==value_node)
if (previous == value_node)
return true;

String param_noref = param;
dynamic_param_list_[param]=ValueNode::Handle(value_node);
dynamic_param_list_connections_[param] =
value_node->signal_changed().connect(
sigc::bind(sigc::mem_fun(*this, &Layer::dynamic_param_changed), param_noref) );

if(previous)
remove_child(previous.get());
if (previous)
{
// 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());
}

add_child(value_node.get());

if(!value_node->is_exported() && get_canvas())
{
value_node->set_parent_canvas(get_canvas());
}

dynamic_param_changed(param);
changed();
Expand All @@ -325,14 +336,14 @@ Layer::connect_dynamic_param(const String& param, etl::loose_handle<ValueNode> v
bool
Layer::disconnect_dynamic_param(const String& param)
{
ValueNode::Handle previous(dynamic_param_list_[param]);
DynamicParamList::iterator i = dynamic_param_list_.find(param);
if (i == dynamic_param_list_.end()) return true;

ValueNode::Handle previous(i->second);
dynamic_param_list_.erase(i);

if(previous)
{
dynamic_param_list_connections_[param].disconnect();
dynamic_param_list_connections_.erase(param);
dynamic_param_list_.erase(param);

// 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
Expand All @@ -344,10 +355,11 @@ Layer::disconnect_dynamic_param(const String& param)
break;
if (iter == dynamic_param_list().end())
remove_child(previous.get());

static_param_changed(param);
changed();
}

static_param_changed(param);
changed();

return true;
}

Expand All @@ -361,6 +373,19 @@ Layer::on_changed()
Node::on_changed();
}

void
Layer::on_child_changed(const Node *x)
{
Node::on_child_changed(x);
for(DynamicParamList::const_iterator i = dynamic_param_list().begin(); i != dynamic_param_list().end();)
{
DynamicParamList::const_iterator j = i;
++i;
if (j->second.get() == x)
dynamic_param_changed(j->first);
}
}

bool
Layer::set_param(const String &param, const ValueBase &value)
{
Expand Down
3 changes: 2 additions & 1 deletion synfig-core/src/synfig/layer.h
Expand Up @@ -297,7 +297,6 @@ class Layer : public Node

//! Map of parameter with animated value nodes
DynamicParamList dynamic_param_list_;
std::map<String, sigc::connection> dynamic_param_list_connections_;

//! A description of what this layer does
String description_;
Expand Down Expand Up @@ -634,6 +633,8 @@ class Layer : public Node
//! This is called whenever a parameter is changed
virtual void on_changed();

virtual void on_child_changed(const Node *x);

//! Called to figure out the animation time information
virtual void get_times_vfunc(Node::time_set &set) const;

Expand Down
15 changes: 14 additions & 1 deletion synfig-core/src/synfig/node.cpp
Expand Up @@ -201,6 +201,12 @@ Node::changed()
on_changed();
}

void
Node::child_changed(const Node *x)
{
on_child_changed(x);
}


//! Gets the GUID for this value node
const synfig::GUID&
Expand Down Expand Up @@ -334,10 +340,17 @@ Node::on_changed()
std::set<Node*>::iterator iter;
for(iter=parent_set.begin();iter!=parent_set.end();++iter)
{
(*iter)->changed();
(*iter)->child_changed(this);
}
}

void
Node::on_child_changed(const Node *x)
{
signal_child_changed()(x);
changed();
}

void
Node::on_guid_changed(synfig::GUID guid)
{
Expand Down
11 changes: 11 additions & 0 deletions synfig-core/src/synfig/node.h
Expand Up @@ -175,6 +175,9 @@ class Node : public etl::rshared_object
//! Node changed signal
sigc::signal<void> signal_changed_;

//! Child node changed signal
sigc::signal<void, const Node*> signal_child_changed_;

//! GUID changed signal
/*! \note The second parameter is the *OLD* guid! */
sigc::signal<void,GUID> signal_guid_changed_;
Expand All @@ -192,6 +195,8 @@ class Node : public etl::rshared_object

sigc::signal<void>& signal_changed() { return signal_changed_; }

sigc::signal<void, const Node*>& signal_child_changed() { return signal_child_changed_; }

//! GUID Changed
/*! \note The second parameter is the *OLD* guid! */
sigc::signal<void,GUID>& signal_guid_changed() { return signal_guid_changed_; }
Expand All @@ -218,6 +223,7 @@ class Node : public etl::rshared_object
public:

void changed();
void child_changed(const Node *x);

//! Gets the GUID for this Node
const GUID& get_guid()const;
Expand Down Expand Up @@ -258,6 +264,11 @@ class Node : public etl::rshared_object
//! the GUI can be connected to.
virtual void on_changed();

//! Used when child node has changed. Calls changed() too.
//! To be overloaded by the derivative classes. Emits a signal where the
//! the GUI can be connected to.
virtual void on_child_changed(const Node *x);

//! Used when the node's GUID has changed.
//! To be overloaded by the derivative classes. Emits a signal where the
//! the GUI can be connected to.
Expand Down
Expand Up @@ -133,6 +133,7 @@ ValueNode_AnimatedFile::ValueNode_AnimatedFile(Type &t):
ValueNode_AnimatedInterfaceConst::set_interpolation(INTERPOLATION_CONSTANT);
ValueNode_AnimatedInterfaceConst::set_type(t);
set_children_vocab(get_children_vocab());
set_link("filename", ValueNode_Const::create(String()));
}

bool
Expand Down

0 comments on commit eef6489

Please sign in to comment.