/*! \file canvasinterface.cpp
** \brief Template File
**
-** $Id: canvasinterface.cpp,v 1.1.1.1 2005/01/07 03:34:37 darco Exp $
+** $Id$
**
** \legal
** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
+** Copyright (c) 2007 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 <synfig/gradient.h>
+#include "general.h"
+
#endif
/* === U S I N G =========================================================== */
/* === M E T H O D S ======================================================= */
-CanvasInterface::CanvasInterface(loose_handle<Instance> instance,handle<Canvas> canvas):
+CanvasInterface::CanvasInterface(etl::loose_handle<Instance> instance,etl::handle<synfig::Canvas> canvas):
instance_(instance),
canvas_(canvas),
cur_time_(canvas->rend_desc().get_frame_start()),
}
if(cur_time_.is_equal(x))
return;
- cur_time_=x;
-
+ get_canvas()->set_time(cur_time_=x);
+
+ // update the time in all the child canvases
+ Canvas::Children children = get_canvas()->get_root()->children();
+ handle<CanvasInterface> interface;
+ for (Canvas::Children::iterator iter = children.begin(); iter != children.end(); iter++)
+ if ((interface = get_instance()->find_canvas_interface(*iter)) != this)
+ interface->set_time(interface->get_canvas()->get_time());
+
signal_time_changed()();
signal_dirty_preview()();
}
-
+
synfig::Time
CanvasInterface::get_time()const
{
return cur_time_;
}
-void
+void
CanvasInterface::refresh_current_values()
{
get_canvas()->set_time(cur_time_);
}
etl::handle<CanvasInterface>
-CanvasInterface::create(loose_handle<Instance> instance,handle<Canvas> canvas)
+CanvasInterface::create(etl::loose_handle<Instance> instance, etl::handle<synfig::Canvas> canvas)
{
etl::handle<CanvasInterface> intrfc;
intrfc=new CanvasInterface(instance,canvas);
Action::Handle action(Action::EditModeSet::create());
assert(action);
-
+
action->set_param("canvas",get_canvas());
action->set_param("canvas_interface",etl::loose_handle<CanvasInterface>(this));
action->set_param("edit_mode",x);
-
+
if(!action->is_ready())
{
get_ui_interface()->error(_("Action Not Ready, unable to change mode"));
assert(0);
return;
}
-
+
if(!get_instance()->perform_action(action))
- get_ui_interface()->error(_("Unable to change mode"));
+ get_ui_interface()->error(_("Unable to change mode"));
// mode_=x;
// signal_mode_changed_(x);
Layer::Handle
-CanvasInterface::add_layer_to(String name, Canvas::Handle canvas, int depth)
+CanvasInterface::add_layer_to(synfig::String name, synfig::Canvas::Handle canvas, int depth)
{
synfigapp::Action::PassiveGrouper group(get_instance().get(),_("Add Layer To"));
Layer::Handle layer(Layer::create(name));
-
+
assert(layer);
-
+
if(!layer)
return 0;
}
layer->set_canvas(canvas);
-
+
// Apply some defaults
if(layer->set_param("fg",synfigapp::Main::get_foreground_color()))
layer->set_param("bg",synfigapp::Main::get_background_color());
layer->set_param("blend_method",synfigapp::Main::get_blend_method());
{
- // Grab the layer's list pf parameters
+ // Grab the layer's list of parameters
Layer::ParamList paramlist=layer->get_param_list();
Layer::ParamList::iterator iter;
for(iter=paramlist.begin();iter!=paramlist.end();++iter)
{
ValueNode::Handle value_node;
-
+
if(iter->second.get_type()==ValueBase::TYPE_LIST)
value_node=LinkableValueNode::create("dynamic_list",iter->second);
else if(LinkableValueNode::check_type("composite",iter->second.get_type()) &&
(iter->second.get_type()!=ValueBase::TYPE_COLOR && iter->second.get_type()!=ValueBase::TYPE_VECTOR)
)
value_node=LinkableValueNode::create("composite",iter->second);
-
+
if(value_node)
layer->connect_dynamic_param(iter->first,value_node);
}
assert(action);
if(!action)
return 0;
-
+
action->set_param("canvas",canvas);
action->set_param("canvas_interface",etl::loose_handle<CanvasInterface>(this));
action->set_param("new",layer);
-
+
if(!action->is_ready())
{
- get_ui_interface()->error(_("Action Not Ready"));
+ get_ui_interface()->error(_("Action Not Ready"));
return 0;
}
-
+
if(!get_instance()->perform_action(action))
{
- get_ui_interface()->error(_("Action Failed."));
+ get_ui_interface()->error(_("Action Failed."));
return 0;
}
if(depth>0)
{
Action::Handle action(Action::create("layer_move"));
-
+
assert(action);
if(!action)
return 0;
-
+
action->set_param("canvas",canvas);
action->set_param("canvas_interface",etl::loose_handle<CanvasInterface>(this));
action->set_param("layer",layer);
action->set_param("new_index",depth);
-
+
if(!action->is_ready())
{
- get_ui_interface()->error(_("Move Action Not Ready"));
+ get_ui_interface()->error(_("Move Action Not Ready"));
return 0;
}
-
+
if(!get_instance()->perform_action(action))
{
- get_ui_interface()->error(_("Move Action Failed."));
+ get_ui_interface()->error(_("Move Action Failed."));
return 0;
}
- }
-
-
+ }
+
+
return layer;
}
bool
-CanvasInterface::convert(ValueDesc value_desc, String type)
+CanvasInterface::convert(ValueDesc value_desc, synfig::String type)
{
Action::Handle action(Action::ValueDescConvert::create());
assert(action);
if(!action)
return 0;
-
+
action->set_param("canvas",get_canvas());
action->set_param("canvas_interface",etl::loose_handle<CanvasInterface>(this));
action->set_param("value_desc",value_desc);
action->set_param("type",type);
-
+
if(!action->is_ready())
{
- get_ui_interface()->error(_("Action Not Ready"));
+ get_ui_interface()->error(_("Action Not Ready"));
return 0;
}
-
+
if(get_instance()->perform_action(action))
return true;
-
- get_ui_interface()->error(_("Action Failed."));
+
+ get_ui_interface()->error(_("Action Failed."));
return false;
}
get_ui_interface()->error(_("Empty name!"));
return false;
}
-
+
Action::Handle action(Action::ValueNodeAdd::create());
assert(action);
if(!action)
return 0;
-
+
action->set_param("canvas",get_canvas());
action->set_param("canvas_interface",etl::loose_handle<CanvasInterface>(this));
action->set_param("new",value_node);
action->set_param("name",name);
-
+
if(!action->is_ready())
{
- get_ui_interface()->error(_("Action Not Ready"));
+ get_ui_interface()->error(_("Action Not Ready"));
return 0;
}
-
+
if(get_instance()->perform_action(action))
return true;
-
- get_ui_interface()->error(_("Action Failed."));
+
+ get_ui_interface()->error(_("Action Failed."));
return false;
}
if(value_desc.parent_is_value_node())
param_list.add("parent_value_node",value_desc.get_parent_value_node());
-
+
if(value_desc.is_value_node())
param_list.add("value_node",value_desc.get_value_node());
-
+
if(value_desc.is_const())
param_list.add("value",value_desc.get_value());
param_list.add("dest",value_desc);
param_list.add("src",children_list.front().get_value_node());
}
- }
+ }
return param_list;
}
param_list.add("value_desc",*iter);
if(iter->is_value_node())
{
- param_list.add("value_node",iter->get_value_node());
+ param_list.add("value_node",iter->get_value_node());
}
}
assert(action);
if(!action)
return;
-
+
action->set_param("canvas",get_canvas());
action->set_param("canvas_interface",etl::loose_handle<CanvasInterface>(this));
action->set_param("rend_desc",rend_desc);
-
+
if(!get_instance()->perform_action(action))
- get_ui_interface()->error(_("Action Failed."));
+ get_ui_interface()->error(_("Action Failed."));
}
bool
-CanvasInterface::set_name(const String &x)
+CanvasInterface::set_name(const synfig::String &x)
{
//! \todo This needs to be converted into an action
get_canvas()->set_name(x);
}
bool
-CanvasInterface::set_description(const String &x)
+CanvasInterface::set_description(const synfig::String &x)
{
//! \todo This needs to be converted into an action
get_canvas()->set_description(x);
}
bool
-CanvasInterface::set_id(const String &x)
+CanvasInterface::set_id(const synfig::String &x)
{
//! \todo This needs to be converted into an action
get_canvas()->set_id(x);
}
bool
-CanvasInterface::import(const synfig::String &filename, bool copy)
+CanvasInterface::import(const synfig::String &filename, bool /*copy*/)
{
Action::PassiveGrouper group(get_instance().get(),_("Import Image"));
-
- synfig::info("Attempting to import "+filename);
+ synfig::info("Attempting to import "+filename);
- if(find(filename.begin(),filename.end(),'.')==filename.end())
+ if (filename_extension(filename) == "")
{
- get_ui_interface()->error("Filename must have an extension!");
+ get_ui_interface()->error(_("Filename must have an extension!"));
return false;
}
- String ext(String(filename.begin()+filename.find_last_of('.')+1,filename.end()));
+ String ext(filename_extension(filename));
+ if (ext.size()) ext = ext.substr(1); // skip initial '.'
std::transform(ext.begin(),ext.end(),ext.begin(),&::tolower);
// If this is a SIF file, then we need to do things slightly differently
if(ext=="sif" || ext=="sifz")try
{
-
+
Canvas::Handle outside_canvas(synfig::open_canvas(filename));
if(!outside_canvas)
throw String(_("Unable to open this composition"));
Layer::Handle layer(add_layer_to("PasteCanvas",get_canvas()));
if(!layer)
- throw String(_("Unable to create \"PasteCanvas\" layer"));
+ throw String(_("Unable to create \"Paste Canvas\" layer"));
if(!layer->set_param("canvas",ValueBase(outside_canvas)))
throw int();
get_ui_interface()->error(_("Uncaught exception when attempting\nto open this composition -- ")+filename);
return false;
}
-
-
-
+
if(!Importer::book().count(ext))
{
get_ui_interface()->error(_("I don't know how to open images of this type -- ")+ext);
layer->set_description(basename(filename));
signal_layer_new_description()(layer,filename);
-
- return true;
+
+ return true;
}
catch(...)
{
assert(action);
if(!action)
return;
-
+
waypoint.make_unique();
waypoint.set_time(get_time());
ValueNode::Handle value_node(value_desc.get_value_node());
-
+
action->set_param("canvas",get_canvas());
action->set_param("canvas_interface",etl::loose_handle<CanvasInterface>(this));
action->set_param("waypoint",waypoint);
action->set_param("time",get_time());
action->set_param("value_node",value_node);
-
+
if(!get_instance()->perform_action(action))
- get_ui_interface()->error(_("Action Failed."));
+ get_ui_interface()->error(_("Action Failed."));
}
void
assert(action);
if(!action)
return;
-
+
ValueNode::Handle value_node(value_desc.get_value_node());
-
+
action->set_param("canvas",get_canvas());
action->set_param("canvas_interface",etl::loose_handle<CanvasInterface>(this));
action->set_param("waypoint",waypoint);
action->set_param("value_node",value_node);
-
+
if(!get_instance()->perform_action(action))
- get_ui_interface()->error(_("Action Failed."));
+ get_ui_interface()->error(_("Action Failed."));
}
void
-CanvasInterface::auto_export(ValueNode::Handle value_node)
+CanvasInterface::auto_export(synfig::ValueNode::Handle /*value_node*/)
{
/*
// Check to see if we are already exported.
assert(action);
if(!action)
return;
-
+
String name(strprintf(_("Unnamed%08d"),synfig::UniqueID().get_uid()));
-
+
action->set_param("canvas",get_canvas());
action->set_param("canvas_interface",etl::loose_handle<CanvasInterface>(this));
action->set_param("new",value_node);
action->set_param("name",name);
-
+
if(!get_instance()->perform_action(action))
- get_ui_interface()->error(_("Action Failed."));
+ get_ui_interface()->error(_("Action Failed."));
*/
}
void
-CanvasInterface::auto_export(const ValueDesc& value_desc)
-{
+CanvasInterface::auto_export(const ValueDesc& /*value_desc*/)
+{
// THIS FUNCTION IS DEPRECATED, AND IS NOW A STUB.
-#if 0
+#if 0
// Check to see if we are already exported.
if(value_desc.is_exported())
return;
assert(action);
if(!action)
return;
-
+
String name(strprintf(_("Unnamed%08d"),synfig::UniqueID().get_uid()));
-
+
action->set_param("canvas",get_canvas());
action->set_param("canvas_interface",etl::loose_handle<CanvasInterface>(this));
action->set_param("value_desc",value_desc);
action->set_param("name",name);
-
+
if(!get_instance()->perform_action(action))
- get_ui_interface()->error(_("Action Failed."));
+ get_ui_interface()->error(_("Action Failed."));
#endif
}
// If this isn't really a change, then don't bother
if(new_value==value_desc.get_value(get_time()))
return true;
-
+
// If this change needs to take place elsewhere, then so be it.
if(value_desc.get_canvas() && value_desc.get_canvas()->get_root()!=get_canvas()->get_root())do
{
etl::handle<Instance> instance;
instance=find_instance(value_desc.get_canvas()->get_root());
-
+
if(instance)
return instance->find_canvas_interface(value_desc.get_canvas())->change_value(value_desc,new_value);
else
{
- get_ui_interface()->error(_("The value you are trying to edit is in a composition\nwhich doesn't seem to be open. Open that composition and you\nshould be able to edit this value as normal."));
+ get_ui_interface()->error(_("The value you are trying to edit is in a composition\nwhich doesn't seem to be open. Open that composition and you\nshould be able to edit this value as normal."));
return false;
}
}while(0);
else
{ synfig::warning("Can't get canvas from value desc...?"); }
#endif
-
+
synfigapp::Action::Handle action(synfigapp::Action::create("value_desc_set"));
if(!action)
{
return false;
}
-
+
action->set_param("canvas",get_canvas());
action->set_param("canvas_interface",etl::loose_handle<CanvasInterface>(this));
action->set_param("time",get_time());
return ret;
ret+=CanvasInterface::find_important_value_descs(canvas,out,guid_set);
}
-
+
if(value_desc.is_value_node())
{
ValueNode::Handle value_node(value_desc.get_value_node());
if(guid_set.count(value_node->get_guid()))
return ret;
guid_set.insert(value_node->get_guid());
-
+
if(LinkableValueNode::Handle::cast_dynamic(value_node))
{
if(ValueNode_DynamicList::Handle::cast_dynamic(value_node))
ret++;
}
// Process the linkable ValueNode's children
- LinkableValueNode::Handle value_node(LinkableValueNode::Handle::cast_dynamic(value_node));
+ LinkableValueNode::Handle value_node_copy(LinkableValueNode::Handle::cast_dynamic(value_node));
int i;
- for(i=0;i<value_node->link_count();i++)
+ for(i=0;i<value_node_copy->link_count();i++)
{
- ValueNode::Handle link(value_node->get_link(i));
+ ValueNode::Handle link(value_node_copy->get_link(i));
if(!link->is_exported())
- ret+=_process_value_desc(ValueDesc(value_node,i),out,guid_set);
+ ret+=_process_value_desc(ValueDesc(value_node_copy,i),out,guid_set);
}
}
else if(ValueNode_Animated::Handle::cast_dynamic(value_node))
ret++;
}
}
-
+
return ret;
}
if(!canvas->is_inline())
{
ValueNodeList::const_iterator iter;
-
+
for(
iter=canvas->value_node_list().begin();
iter!=canvas->value_node_list().end();
}
Canvas::const_iterator iter;
-
+
for(iter=canvas->begin();iter!=canvas->end();++iter)
{
Layer::Handle layer(*iter);
-
+
Layer::DynamicParamList::const_iterator iter;
for(
iter=layer->dynamic_param_list().begin();
if(value.is_valid())
ret+=_process_value_desc(ValueDesc(layer,"canvas"),out,guid_set);
}
-
+
return ret;
}
Time newtime(get_time()+(float)frames/fps);
newtime=newtime.round(fps);
- if(newtime<=get_canvas()->rend_desc().get_frame_start())
- newtime=get_canvas()->rend_desc().get_frame_start();
- if(newtime>=get_canvas()->rend_desc().get_frame_end())
- newtime=get_canvas()->rend_desc().get_frame_end();
+ if(newtime<=get_canvas()->rend_desc().get_time_start())
+ newtime=get_canvas()->rend_desc().get_time_start();
+ if(newtime>=get_canvas()->rend_desc().get_time_end())
+ newtime=get_canvas()->rend_desc().get_time_end();
set_time(newtime);
}
{
if(!time)
return;
-
+
float fps(get_canvas()->rend_desc().get_frame_rate());
if(time>=synfig::Time::end())
}
if(time<=synfig::Time::begin())
{
- set_time(get_canvas()->rend_desc().get_time_end());
+ set_time(get_canvas()->rend_desc().get_time_start());
return;
}
-
+
Time newtime(get_time()+time);
newtime=newtime.round(fps);