bool Action::LayerEmbed::is_candidate(const ParamList &x) { if (!candidate_check(get_param_vocab(),x)) return false; Layer::Handle layer=x.find("layer")->second.get_layer(); if(!layer) return false; etl::handle<synfig::Layer_PasteCanvas> layer_pastecanvas = etl::handle<synfig::Layer_PasteCanvas>::cast_dynamic(layer); if (layer_pastecanvas) { Canvas::Handle canvas = layer_pastecanvas->get_sub_canvas();; if (canvas && canvas->is_root()) return true; } Layer::Handle layer_import = layer; if (layer_import->get_param_list().count("filename") != 0) { String filename = layer_import->get_param("filename").get(String()); // TODO: literal "container:" if (!filename.empty() && filename.substr(0, String("#").size()) != "#" && layer_import->dynamic_param_list().count("filename") == 0) return true; } return false; }
bool Action::LayerEmbed::is_candidate(const ParamList &x) { if (!candidate_check(get_param_vocab(),x)) return false; Layer::Handle layer=x.find("layer")->second.get_layer(); if(!layer) return false; etl::handle<synfig::Layer_PasteCanvas> layer_pastecanvas = etl::handle<synfig::Layer_PasteCanvas>::cast_dynamic(layer); if (layer_pastecanvas) { Canvas::Handle canvas = layer_pastecanvas->get_sub_canvas();; if (canvas && canvas->is_root()) return true; } Layer::Handle layer_import = layer; if (layer_import->get_param_list().count("filename") != 0) { String filename = layer_import->get_param("filename").get(String()); if ( !CanvasFileNaming::is_embeded(filename) && !layer_import->dynamic_param_list().count("filename") ) return true; } return false; }
Layer::Handle Layer_Switch::get_current_layer()const { Canvas::Handle canvas = get_sub_canvas(); String n = param_layer_name.get(String()); if (canvas) for(IndependentContext i = canvas->get_independent_context(); *i; i++) if ((*i)->get_description() == n) return *i; return NULL; }
void Action::LayerDuplicate::export_dup_nodes(synfig::Layer::Handle layer, Canvas::Handle canvas, int &index) { // automatically export the Index parameter of Duplicate layers when duplicating if (layer->get_name() == "duplicate") while (true) { String name = strprintf(_("Index %d"), index++); try { canvas->find_value_node(name, true); } catch (Exception::IDNotFound x) { Action::Handle action(Action::create("ValueNodeAdd")); action->set_param("canvas",canvas); action->set_param("canvas_interface",get_canvas_interface()); action->set_param("new",layer->dynamic_param_list().find("index")->second); action->set_param("name",name); add_action_front(action); break; } } else { Layer::ParamList param_list(layer->get_param_list()); for (Layer::ParamList::const_iterator iter(param_list.begin()) ; iter != param_list.end() ; iter++) if (layer->dynamic_param_list().count(iter->first)==0 && iter->second.get_type()==type_canvas) { Canvas::Handle subcanvas(iter->second.get(Canvas::Handle())); if (subcanvas && subcanvas->is_inline()) for (IndependentContext iter = subcanvas->get_independent_context(); iter != subcanvas->end(); iter++) export_dup_nodes(*iter, canvas, index); } for (Layer::DynamicParamList::const_iterator iter(layer->dynamic_param_list().begin()) ; iter != layer->dynamic_param_list().end() ; iter++) if (iter->second->get_type()==type_canvas) { Canvas::Handle canvas((*iter->second)(0).get(Canvas::Handle())); if (canvas->is_inline()) //! \todo do we need to implement this? and if so, shouldn't we check all canvases, not just the one at t=0s? warning("%s:%d not yet implemented - do we need to export duplicate valuenodes in dynamic canvas parameters?", __FILE__, __LINE__); } } }
bool TaskLayerSW::run(RunParams & /* params */) const { synfig::Surface &target = SurfaceSW::Handle::cast_dynamic( target_surface )->get_surface(); // TODO: target_rect RendDesc desc; desc.set_tl(get_source_rect_lt()); desc.set_br(get_source_rect_rb()); desc.set_wh(target.get_w(), target.get_h()); desc.set_antialias(1); Canvas::Handle canvas = Canvas::create(); return layer->accelerated_render(canvas->get_context(ContextParams()), &target, 4, desc, NULL); }
void print_child_canvases(const string& prefix, const Canvas::Handle& canvas) { const Canvas::Children& children(canvas->children()); for (Canvas::Children::const_iterator child_canvas = children.begin(); child_canvas != children.end(); child_canvas++) { cout << prefix.c_str() << ":" << (*child_canvas)->get_id().c_str() << endl; print_child_canvases(prefix + ":" + (*child_canvas)->get_id(), *child_canvas); } }
bool Action::LayerEmbed::set_param(const synfig::String& name, const Action::Param ¶m) { if(name=="layer" && param.get_type()==Param::TYPE_LAYER) { Layer::Handle layer = param.get_layer(); etl::handle<synfig::Layer_PasteCanvas> layer_pastecanvas = etl::handle<synfig::Layer_PasteCanvas>::cast_dynamic(layer); if (layer_pastecanvas) { Canvas::Handle canvas = layer_pastecanvas->get_sub_canvas(); if (canvas && canvas->is_root()) { this->layer_pastecanvas = layer_pastecanvas; return true; } } Layer::Handle layer_import = layer; if (layer_import->get_param_list().count("filename") != 0) { String filename = layer_import->get_param("filename").get(String()); // TODO: literal "container:" if (!filename.empty() && filename.substr(0, String("#").size()) != "#" && layer_import->dynamic_param_list().count("filename") == 0) { this->layer_import = layer_import; return true; } } return false; } return Action::CanvasSpecific::set_param(name,param); }
bool StateBrush_Context::build_transform_stack( Canvas::Handle canvas, Layer::Handle layer, CanvasView::Handle canvas_view, TransformStack& transform_stack ) { int count = 0; for(Canvas::iterator i = canvas->begin(); i != canvas->end() ;++i) { if(*i == layer) return true; if((*i)->active()) { Transform::Handle trans((*i)->get_transform()); if(trans) { transform_stack.push(trans); count++; } } // If this is a paste canvas layer, then we need to // descend into it if(etl::handle<Layer_PasteCanvas> layer_pastecanvas = etl::handle<Layer_PasteCanvas>::cast_dynamic(*i)) { transform_stack.push_back( new Transform_Matrix( layer_pastecanvas->get_guid(), layer_pastecanvas->get_summary_transformation().get_matrix() ) ); if (build_transform_stack(layer_pastecanvas->get_sub_canvas(), layer, canvas_view, transform_stack)) return true; transform_stack.pop(); } } while(count-- > 0) transform_stack.pop(); return false; }
bool Action::LayerEmbed::set_param(const synfig::String& name, const Action::Param ¶m) { if(name=="layer" && param.get_type()==Param::TYPE_LAYER) { Layer::Handle layer = param.get_layer(); etl::handle<synfig::Layer_PasteCanvas> layer_pastecanvas = etl::handle<synfig::Layer_PasteCanvas>::cast_dynamic(layer); if (layer_pastecanvas) { Canvas::Handle canvas = layer_pastecanvas->get_sub_canvas(); if (canvas && canvas->is_root()) { this->layer_pastecanvas = layer_pastecanvas; return true; } } Layer::Handle layer_import = layer; if (layer_import->get_param_list().count("filename") != 0) { String filename = layer_import->get_param("filename").get(String()); if ( !CanvasFileNaming::is_embeded(filename) && !layer_import->dynamic_param_list().count("filename") ) { this->layer_import = layer_import; return true; } } return false; } return Action::CanvasSpecific::set_param(name,param); }
bool Instance::import_external_canvas(Canvas::Handle canvas, std::map<Canvas*, Canvas::Handle> &imported) { etl::handle<CanvasInterface> canvas_interface; for(IndependentContext i = canvas->get_independent_context(); *i; i++) { etl::handle<Layer_PasteCanvas> paste_canvas = etl::handle<Layer_PasteCanvas>::cast_dynamic(*i); if (!paste_canvas) continue; Canvas::Handle sub_canvas = paste_canvas->get_sub_canvas(); if (!sub_canvas) continue; if (!sub_canvas->is_root()) continue; if (imported.count(sub_canvas.get()) != 0) { // link already exported canvas Canvas::Handle new_canvas = imported[sub_canvas.get()]; if (!new_canvas) continue; // Action to link canvas try { Action::Handle action(Action::LayerParamSet::create()); if (!action) continue; canvas_interface = find_canvas_interface(canvas); action->set_param("canvas",canvas); action->set_param("canvas_interface",canvas_interface); action->set_param("layer",Layer::Handle(paste_canvas)); action->set_param("param","canvas"); action->set_param("new_value",ValueBase(new_canvas)); if(!action->is_ready()) continue; if(!perform_action(action)) continue; } catch(...) { continue; } } else { imported[sub_canvas.get()] = NULL; // generate name std::string fname = filename_sans_extension(basename(sub_canvas->get_file_name())); static const char bad_chars[]=" :#@$^&()*"; for(std::string::iterator j = fname.begin(); j != fname.end(); j++) for(const char *k = bad_chars; *k != 0; k++) if (*j == *k) { *j = '_'; break; } if (fname.empty()) fname = "canvas"; if (fname[0]>='0' && fname[0]<='9') fname = "_" + fname; std::string name; bool found = false; for(int j = 1; j < 1000; j++) { name = j == 1 ? fname : strprintf("%s_%d", fname.c_str(), j); if (canvas->value_node_list().count(name) == false) { found = true; for(std::list<Canvas::Handle>::const_iterator iter=canvas->children().begin();iter!=canvas->children().end();iter++) if(name==(*iter)->get_id()) { found = false; break; } if (found) break; } } if (!found) continue; // Action to import canvas try { Action::Handle action(Action::ValueDescExport::create()); if (!action) continue; canvas_interface = find_canvas_interface(canvas); action->set_param("canvas",canvas); action->set_param("canvas_interface",canvas_interface); action->set_param("value_desc",ValueDesc(Layer::Handle(paste_canvas),std::string("canvas"))); action->set_param("name",name); if(!action->is_ready()) continue; if(!perform_action(action)) continue; std::string warnings; imported[sub_canvas.get()] = canvas->find_canvas(name, warnings); } catch(...) { continue; } return true; } } for(std::list<Canvas::Handle>::const_iterator i = canvas->children().begin(); i != canvas->children().end(); i++) if (import_external_canvas(*i, imported)) return true; return false; }
//! \writeme int synfig::waypoint_collect(set<Waypoint, std::less<UniqueID> > &waypoint_set, const Time &time, const etl::handle<Node> &node) { const TimePointSet& timepoint_set(node->get_times()); // Check to see if there is anything in here at the given time if(timepoint_set.find(time)==timepoint_set.end()) return 0; // Check if we are a linkable value node LinkableValueNode::Handle linkable_value_node; linkable_value_node=linkable_value_node.cast_dynamic(node); if(linkable_value_node) { const int link_count(linkable_value_node->link_count()); int i,ret(0); for(i=0;i<link_count;i++) ret+=waypoint_collect(waypoint_set,time,linkable_value_node->get_link(i).get()); return ret; } // Check if we are a layer Layer::Handle layer; layer=layer.cast_dynamic(node); if(layer) { const Layer::DynamicParamList& dyn_param_list(layer->dynamic_param_list()); Layer::DynamicParamList::const_iterator iter; int ret(0); for(iter=dyn_param_list.begin();iter!=dyn_param_list.end();++iter) ret+=waypoint_collect(waypoint_set,time,iter->second); ValueBase canvas_value(layer->get_param("canvas")); if(canvas_value.get_type()==type_canvas) { etl::handle<Layer_PasteCanvas> p = etl::handle<Layer_PasteCanvas>::cast_dynamic(layer); if (p) ret+=waypoint_collect(waypoint_set, time + p->get_time_offset(), Canvas::Handle(canvas_value.get(Canvas::Handle()))); else ret+=waypoint_collect(waypoint_set, time, Canvas::Handle(canvas_value.get(Canvas::Handle()))); } return ret; } // Check if we are a canvas Canvas::Handle canvas; canvas=canvas.cast_dynamic(node); if(canvas) { Canvas::const_iterator iter; int ret(0); for(iter=canvas->begin();iter!=canvas->end();++iter) ret+=waypoint_collect(waypoint_set,time,*iter); return ret; } // Check if we are an animated value node ValueNode_Animated::Handle value_node_animated; value_node_animated=value_node_animated.cast_dynamic(node); if(value_node_animated) { try{ Waypoint waypoint=*value_node_animated->find(time); // If it is already in the waypoint set, then // don't bother adding it again if(waypoint_set.find(waypoint)!=waypoint_set.end()) return 0; waypoint_set.insert(waypoint); return 1; }catch(...) { return 0; } } return 0; }
void print_canvas_info(const Job& job) { const Canvas::Handle canvas(job.canvas); const RendDesc &rend_desc(canvas->rend_desc()); if (job.canvas_info_all || job.canvas_info_time_start) { cout << endl << "# " << _("Start Time") << endl; cout << "time_start" << "=" << rend_desc.get_time_start().get_string().c_str() << endl; } if (job.canvas_info_all || job.canvas_info_time_end) { cout << endl << "# " << _("End Time") << endl; cout << "time_end" << "=" << rend_desc.get_time_end().get_string().c_str() << endl; } if (job.canvas_info_all || job.canvas_info_frame_rate) { cout << endl << "# " << _("Frame Rate") << endl; cout << "frame_rate" << "=" << rend_desc.get_frame_rate() << endl; } if (job.canvas_info_all || job.canvas_info_frame_start) { cout << endl << "# " << _("Start Frame") << endl; cout << "frame_start" << "=" << rend_desc.get_frame_start() << endl; } if (job.canvas_info_all || job.canvas_info_frame_end) { cout << endl << "# " << _("End Frame") << endl; cout << "frame_end" << "=" << rend_desc.get_frame_end() << endl; } if (job.canvas_info_all) cout << endl; if (job.canvas_info_all || job.canvas_info_w) { cout << endl << "# " << _("Width") << endl; cout << "w" << "=" << rend_desc.get_w() << endl; } if (job.canvas_info_all || job.canvas_info_h) { cout << endl << "# " << _("Height") << endl; cout << "h" << "=" << rend_desc.get_h() << endl; } if (job.canvas_info_all || job.canvas_info_image_aspect) { cout << endl << "# " << _("Image Aspect Ratio") << endl; cout << "image_aspect" << "=" << rend_desc.get_image_aspect() << endl; } if (job.canvas_info_all) cout << endl; if (job.canvas_info_all || job.canvas_info_pw) { cout << endl << "# " << _("Pixel Width") << endl; cout << "pw" << "=" << rend_desc.get_pw() << endl; } if (job.canvas_info_all || job.canvas_info_ph) { cout << endl << "# " << _("Pixel Height") << endl; cout << "ph" << "=" << rend_desc.get_ph() << endl; } if (job.canvas_info_all || job.canvas_info_pixel_aspect) { cout << endl << "# " << _("Pixel Aspect Ratio") << endl; cout << "pixel_aspect" << "=" << rend_desc.get_pixel_aspect() << endl; } if (job.canvas_info_all) cout << endl; if (job.canvas_info_all || job.canvas_info_tl) { cout << endl << "# " << _("Top Left") << endl; cout << "tl" << "=" << rend_desc.get_tl()[0] << " " << rend_desc.get_tl()[1] << endl; } if (job.canvas_info_all || job.canvas_info_br) { cout << endl << "# " << _("Bottom Right") << endl; cout << "br" << "=" << rend_desc.get_br()[0] << " " << rend_desc.get_br()[1] << endl; } if (job.canvas_info_all || job.canvas_info_physical_w) { cout << endl << "# " << _("Physical Width") << endl; cout << "physical_w" << "=" << rend_desc.get_physical_w() << endl; } if (job.canvas_info_all || job.canvas_info_physical_h) { cout << endl << "# " << _("Physical Height") << endl; cout << "physical_h" << "=" << rend_desc.get_physical_h() << endl; } if (job.canvas_info_all || job.canvas_info_x_res) { cout << endl << "# " << _("X Resolution") << endl; cout << "x_res" << "=" << rend_desc.get_x_res() << endl; } if (job.canvas_info_all || job.canvas_info_y_res) { cout << endl << "# " << _("Y Resolution") << endl; cout << "y_res" << "=" << rend_desc.get_y_res() << endl; } if (job.canvas_info_all || job.canvas_info_span) { cout << endl << "# " << _("Diagonal Image Span") << endl; cout << "span" << "=" << rend_desc.get_span() << endl; } if (job.canvas_info_all) cout << endl; if (job.canvas_info_all || job.canvas_info_interlaced) { cout << endl << "# " << _("Interlaced") << endl; cout << "interlaced" << "=" << rend_desc.get_interlaced() << endl; } if (job.canvas_info_all || job.canvas_info_antialias) { cout << endl << "# " << _("Antialias") << endl; cout << "antialias" << "=" << rend_desc.get_antialias() << endl; } if (job.canvas_info_all || job.canvas_info_clamp) { cout << endl << "# " << _("Clamp") << endl; cout << "clamp" << "=" << rend_desc.get_clamp() << endl; } if (job.canvas_info_all || job.canvas_info_flags) { cout << endl << "# " << _("Flags") << endl; cout << "flags" << "=" << rend_desc.get_flags() << endl; } if (job.canvas_info_all || job.canvas_info_focus) { cout << endl << "# " << _("Focus") << endl; cout << "focus" << "=" << rend_desc.get_focus()[0] << " " << rend_desc.get_focus()[1] << endl; } if (job.canvas_info_all || job.canvas_info_bg_color) { cout << endl << "# " << _("Background Color") << endl; cout << "bg_color" << "=" << rend_desc.get_bg_color().get_string().c_str() << endl; } if (job.canvas_info_all) cout << endl; if (job.canvas_info_all || job.canvas_info_metadata) { std::list<String> keys(canvas->get_meta_data_keys()); cout << endl << "# " << _("Metadata") << endl; for (std::list<String>::iterator key = keys.begin(); key != keys.end(); key++) cout << (*key).c_str() << "=" << canvas->get_meta_data(*key).c_str()<< endl; } }