X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=synfig-studio%2Ftrunk%2Fsrc%2Fsynfigapp%2Fcanvasinterface.cpp;h=ce817d85585a8fb7b3983fa20096111a76e34bd2;hb=756c0d29ac1742f231e6615f9a577e574e35a4af;hp=4521c0172bedf89971de9ede2775ce7b57d3ad86;hpb=c3ad95144d148602f672e95ddda1f18fc35502f8;p=synfig.git diff --git a/synfig-studio/trunk/src/synfigapp/canvasinterface.cpp b/synfig-studio/trunk/src/synfigapp/canvasinterface.cpp index 4521c01..ce817d8 100644 --- a/synfig-studio/trunk/src/synfigapp/canvasinterface.cpp +++ b/synfig-studio/trunk/src/synfigapp/canvasinterface.cpp @@ -6,6 +6,7 @@ ** ** \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 @@ -59,6 +60,8 @@ #include +#include "general.h" + #endif /* === U S I N G =========================================================== */ @@ -76,7 +79,7 @@ using namespace synfigapp; /* === M E T H O D S ======================================================= */ -CanvasInterface::CanvasInterface(loose_handle instance,handle canvas): +CanvasInterface::CanvasInterface(etl::loose_handle instance,etl::handle canvas): instance_(instance), canvas_(canvas), cur_time_(canvas->rend_desc().get_frame_start()), @@ -88,7 +91,8 @@ CanvasInterface::CanvasInterface(loose_handle instance,handle CanvasInterface::~CanvasInterface() { - synfig::info("synfigapp::CanvasInterface::~CanvasInterface(): Deleted"); + if (getenv("SYNFIG_DEBUG_DESTRUCTORS")) + synfig::info("CanvasInterface::~CanvasInterface(): Deleted"); } void @@ -103,7 +107,14 @@ CanvasInterface::set_time(synfig::Time x) } 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 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()(); @@ -124,7 +135,7 @@ CanvasInterface::refresh_current_values() } etl::handle -CanvasInterface::create(loose_handle instance,handle canvas) +CanvasInterface::create(etl::loose_handle instance, etl::handle canvas) { etl::handle intrfc; intrfc=new CanvasInterface(instance,canvas); @@ -166,7 +177,7 @@ CanvasInterface::get_mode()const 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")); @@ -183,6 +194,22 @@ CanvasInterface::add_layer_to(String name, Canvas::Handle canvas, int depth) return 0; } + // automatically export the Index parameter of new Duplicate layers + if (name == "duplicate") + for (int i = 1; ; i++) + { + String name = strprintf(_("Index %d"), i); + try + { + canvas->find_value_node(name); + } + catch (Exception::IDNotFound x) + { + add_value_node(layer->dynamic_param_list().find("index")->second, name); + break; + } + } + layer->set_canvas(canvas); // Apply some defaults @@ -198,7 +225,7 @@ CanvasInterface::add_layer_to(String name, Canvas::Handle canvas, int depth) 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) @@ -240,7 +267,8 @@ CanvasInterface::add_layer_to(String name, Canvas::Handle canvas, int depth) return 0; } - synfig::info("DEPTH=%d",depth); + // synfig::info("DEPTH=%d",depth); + // Action to move the layer (if necessary) if(depth>0) { @@ -274,7 +302,7 @@ CanvasInterface::add_layer_to(String name, Canvas::Handle canvas, int depth) bool -CanvasInterface::convert(ValueDesc value_desc, String type) +CanvasInterface::convert(ValueDesc value_desc, synfig::String type) { Action::Handle action(Action::ValueDescConvert::create()); @@ -286,6 +314,7 @@ CanvasInterface::convert(ValueDesc value_desc, String type) action->set_param("canvas_interface",etl::loose_handle(this)); action->set_param("value_desc",value_desc); action->set_param("type",type); + action->set_param("time",get_time()); if(!action->is_ready()) { @@ -350,7 +379,18 @@ CanvasInterface::generate_param_list(const ValueDesc &value_desc) param_list.add("value_node",value_desc.get_value_node()); if(value_desc.is_const()) - param_list.add("value",value_desc.get_value()); + { + // Fix 1868911: if we put a ValueBase holding a Canvas handle + // into the param_list and then export the canvas, the handle + // will miss out of having its reference count reduced, + // because by the time the handle is destructed the canvas + // will no longer be inline. So let's not propogate that + // ValueBase any further than here. + if (value_desc.get_value_type() == ValueBase::TYPE_CANVAS) + param_list.add("value",Canvas::LooseHandle(value_desc.get_value().get(Canvas::LooseHandle()))); + else + param_list.add("value",value_desc.get_value()); + } if(value_desc.parent_is_layer_param()) { @@ -410,7 +450,7 @@ CanvasInterface::set_rend_desc(const synfig::RendDesc &rend_desc) } 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); @@ -419,7 +459,7 @@ CanvasInterface::set_name(const String &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); @@ -427,7 +467,7 @@ CanvasInterface::set_description(const String &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); @@ -469,14 +509,14 @@ CanvasInterface::import(const synfig::String &filename, bool /*copy*/) 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 @@ -487,7 +527,7 @@ CanvasInterface::import(const synfig::String &filename, bool /*copy*/) if(!outside_canvas) throw String(_("Unable to open this composition")); - Layer::Handle layer(add_layer_to("paste_canvas",get_canvas())); + Layer::Handle layer(add_layer_to("PasteCanvas",get_canvas())); if(!layer) throw String(_("Unable to create \"Paste Canvas\" layer")); if(!layer->set_param("canvas",ValueBase(outside_canvas))) @@ -508,8 +548,6 @@ CanvasInterface::import(const synfig::String &filename, bool /*copy*/) return false; } - - if(!Importer::book().count(ext)) { get_ui_interface()->error(_("I don't know how to open images of this type -- ")+ext); @@ -534,14 +572,14 @@ CanvasInterface::import(const synfig::String &filename, bool /*copy*/) { x[0]=size[0]; x[1]=size[0]/w*h; - if(size[0]<0 ^ size[1]<0) + if((size[0]<0) ^ (size[1]<0)) x[1]=-x[1]; } else { x[1]=size[1]; x[0]=size[1]/h*w; - if(size[0]<0 ^ size[1]<0) + if((size[0]<0) ^ (size[1]<0)) x[0]=-x[0]; } if(!layer->set_param("tl",ValueBase(-x/2))) @@ -574,6 +612,13 @@ CanvasInterface::import(const synfig::String &filename, bool /*copy*/) void CanvasInterface::waypoint_duplicate(synfigapp::ValueDesc value_desc,synfig::Waypoint waypoint) { + ValueNode::Handle value_node(); + waypoint_duplicate(value_desc.get_value_node(), waypoint); +} + +void +CanvasInterface::waypoint_duplicate(ValueNode::Handle value_node,synfig::Waypoint waypoint) +{ Action::Handle action(Action::create("waypoint_set_smart")); assert(action); @@ -583,8 +628,6 @@ CanvasInterface::waypoint_duplicate(synfigapp::ValueDesc value_desc,synfig::Wayp 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(this)); action->set_param("waypoint",waypoint); @@ -598,14 +641,19 @@ CanvasInterface::waypoint_duplicate(synfigapp::ValueDesc value_desc,synfig::Wayp void CanvasInterface::waypoint_remove(synfigapp::ValueDesc value_desc,synfig::Waypoint waypoint) { + ValueNode::Handle value_node(); + waypoint_remove(value_desc.get_value_node(), waypoint); +} + +void +CanvasInterface::waypoint_remove(ValueNode::Handle value_node,synfig::Waypoint waypoint) +{ Action::Handle action(Action::create("waypoint_remove")); 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(this)); action->set_param("waypoint",waypoint); @@ -617,7 +665,7 @@ CanvasInterface::waypoint_remove(synfigapp::ValueDesc value_desc,synfig::Waypoin void -CanvasInterface::auto_export(ValueNode::Handle /*value_node*/) +CanvasInterface::auto_export(synfig::ValueNode::Handle /*value_node*/) { /* // Check to see if we are already exported.