X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=synfig-studio%2Ftrunk%2Fsrc%2Fsynfigapp%2Fcanvasinterface.cpp;h=ce817d85585a8fb7b3983fa20096111a76e34bd2;hb=756c0d29ac1742f231e6615f9a577e574e35a4af;hp=6d7e61ad2ad6db7be1c013419e63f5e7d5321317;hpb=02252941b29de64037116f4d37991a38d9ff0d94;p=synfig.git diff --git a/synfig-studio/trunk/src/synfigapp/canvasinterface.cpp b/synfig-studio/trunk/src/synfigapp/canvasinterface.cpp index 6d7e61a..ce817d8 100644 --- a/synfig-studio/trunk/src/synfigapp/canvasinterface.cpp +++ b/synfig-studio/trunk/src/synfigapp/canvasinterface.cpp @@ -2,19 +2,21 @@ /*! \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 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 */ /* ========================================================================= */ @@ -58,6 +60,8 @@ #include +#include "general.h" + #endif /* === U S I N G =========================================================== */ @@ -75,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()), @@ -87,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 @@ -102,19 +107,26 @@ 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()(); } - + synfig::Time CanvasInterface::get_time()const { return cur_time_; } -void +void CanvasInterface::refresh_current_values() { get_canvas()->set_time(cur_time_); @@ -123,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); @@ -137,20 +149,20 @@ CanvasInterface::set_mode(Mode x) Action::Handle action(Action::EditModeSet::create()); assert(action); - + action->set_param("canvas",get_canvas()); action->set_param("canvas_interface",etl::loose_handle(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); @@ -165,14 +177,14 @@ 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")); Layer::Handle layer(Layer::create(name)); - + assert(layer); - + if(!layer) return 0; @@ -182,8 +194,24 @@ 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 if(layer->set_param("fg",synfigapp::Main::get_foreground_color())) layer->set_param("bg",synfigapp::Main::get_background_color()); @@ -197,20 +225,20 @@ 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) { 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); } @@ -222,80 +250,82 @@ CanvasInterface::add_layer_to(String name, Canvas::Handle canvas, int depth) assert(action); if(!action) return 0; - + action->set_param("canvas",canvas); action->set_param("canvas_interface",etl::loose_handle(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; } - synfig::info("DEPTH=%d",depth); + // synfig::info("DEPTH=%d",depth); + // Action to move the layer (if necessary) 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(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(this)); action->set_param("value_desc",value_desc); action->set_param("type",type); - + action->set_param("time",get_time()); + 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; } @@ -307,28 +337,28 @@ CanvasInterface::add_value_node(synfig::ValueNode::Handle value_node, synfig::St 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(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; } @@ -344,12 +374,23 @@ CanvasInterface::generate_param_list(const ValueDesc &value_desc) 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()); + { + // 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()) { @@ -365,7 +406,7 @@ CanvasInterface::generate_param_list(const ValueDesc &value_desc) param_list.add("dest",value_desc); param_list.add("src",children_list.front().get_value_node()); } - } + } return param_list; } @@ -383,7 +424,7 @@ CanvasInterface::generate_param_list(const std::list &valu 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()); } } @@ -399,17 +440,17 @@ CanvasInterface::set_rend_desc(const synfig::RendDesc &rend_desc) assert(action); if(!action) return; - + action->set_param("canvas",get_canvas()); action->set_param("canvas_interface",etl::loose_handle(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); @@ -418,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); @@ -426,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); @@ -462,33 +503,33 @@ CanvasInterface::jump_to_prev_keyframe() } 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(); @@ -506,9 +547,7 @@ CanvasInterface::import(const synfig::String &filename, bool copy) 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); @@ -533,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))) @@ -558,8 +597,8 @@ CanvasInterface::import(const synfig::String &filename, bool copy) layer->set_description(basename(filename)); signal_layer_new_description()(layer,filename); - - return true; + + return true; } catch(...) { @@ -573,50 +612,60 @@ 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); 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(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 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); 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. @@ -628,24 +677,24 @@ CanvasInterface::auto_export(ValueNode::Handle value_node) 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(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; @@ -655,16 +704,16 @@ CanvasInterface::auto_export(const ValueDesc& value_desc) 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(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 } @@ -674,18 +723,18 @@ CanvasInterface::change_value(synfigapp::ValueDesc value_desc,synfig::ValueBase // 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=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); @@ -693,13 +742,13 @@ CanvasInterface::change_value(synfigapp::ValueDesc value_desc,synfig::ValueBase 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(this)); action->set_param("time",get_time()); @@ -730,7 +779,7 @@ _process_value_desc(const synfigapp::ValueDesc& value_desc,std::vectorget_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)) @@ -747,13 +796,13 @@ _process_value_desc(const synfigapp::ValueDesc& value_desc,std::vectorlink_count();i++) + for(i=0;ilink_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)) @@ -762,7 +811,7 @@ _process_value_desc(const synfigapp::ValueDesc& value_desc,std::vectoris_inline()) { ValueNodeList::const_iterator iter; - + for( iter=canvas->value_node_list().begin(); iter!=canvas->value_node_list().end(); @@ -782,11 +831,11 @@ CanvasInterface::find_important_value_descs(synfig::Canvas::Handle canvas,std::v } 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(); @@ -800,7 +849,7 @@ CanvasInterface::find_important_value_descs(synfig::Canvas::Handle canvas,std::v if(value.is_valid()) ret+=_process_value_desc(ValueDesc(layer,"canvas"),out,guid_set); } - + return ret; } @@ -820,10 +869,10 @@ CanvasInterface::seek_frame(int frames) 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); } @@ -832,7 +881,7 @@ CanvasInterface::seek_time(synfig::Time time) { if(!time) return; - + float fps(get_canvas()->rend_desc().get_frame_rate()); if(time>=synfig::Time::end()) @@ -842,10 +891,10 @@ CanvasInterface::seek_time(synfig::Time time) } 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);