X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=synfig-core%2Ftrunk%2Fsrc%2Fsynfig%2Fkeyframe.cpp;fp=synfig-core%2Ftrunk%2Fsrc%2Fsynfig%2Fkeyframe.cpp;h=b776a3ec98dff03a20ea5f9bccb75a94db6c5bb3;hb=e3acc0b267b14fda5db3c7bbb2f218b993ef84b3;hp=0000000000000000000000000000000000000000;hpb=ced68168d8518aac837f20e73bcd1e84a6bd6178;p=synfig.git diff --git a/synfig-core/trunk/src/synfig/keyframe.cpp b/synfig-core/trunk/src/synfig/keyframe.cpp new file mode 100644 index 0000000..b776a3e --- /dev/null +++ b/synfig-core/trunk/src/synfig/keyframe.cpp @@ -0,0 +1,236 @@ +/* === S I N F G =========================================================== */ +/*! \file keyframe.cpp +** \brief Template File +** +** $Id: keyframe.cpp,v 1.1.1.1 2005/01/04 01:23:14 darco Exp $ +** +** \legal +** Copyright (c) 2002 Robert B. Quattlebaum Jr. +** +** This software and associated documentation +** are CONFIDENTIAL and PROPRIETARY property of +** the above-mentioned copyright holder. +** +** You may not copy, print, publish, or in any +** other way distribute this software without +** a prior written agreement with +** the copyright holder. +** \endlegal +*/ +/* ========================================================================= */ + +/* === H E A D E R S ======================================================= */ + +#ifdef USING_PCH +# include "pch.h" +#else +#ifdef HAVE_CONFIG_H +# include +#endif + +#include + +#include + +#include "keyframe.h" +#include "exception.h" +#include "general.h" +#include + +#endif + +/* === U S I N G =========================================================== */ + +using namespace std; +using namespace etl; +using namespace sinfg; + +/* === M A C R O S ========================================================= */ + +/* === G L O B A L S ======================================================= */ + +/* === P R O C E D U R E S ================================================= */ + +/* === M E T H O D S ======================================================= */ + +Keyframe::Keyframe(): + time_(0) +{ +} + +Keyframe::Keyframe(const Time &time): + time_(time) +{ +} + +Keyframe::~Keyframe() +{ +} + +void +KeyframeList::dump()const +{ + const_iterator iter; + int i; + sinfg::info(">>>>>>>>BEGIN KEYFRAME DUMP"); + for(iter=begin(),i=0;iter!=end();++iter,i++) + { + sinfg::info("#%d, time: %s, desc: %s",i,iter->get_time().get_string().c_str(),iter->get_description().c_str()); + } + sinfg::info("<<<<<<<::erase(find(x)); +} + +KeyframeList::iterator +KeyframeList::find(const Time &x) +{ + KeyframeList::iterator iter; + iter=binary_find(begin(),end(),x); + if(iter!=end() && iter->get_time().is_equal(x)) + return iter; +/* iter++; + if(iter!=end() && iter->get_time().is_equal(x)) + return iter; +*/ + throw Exception::NotFound(strprintf("KeyframeList::find(): Can't find Keyframe %s",x.get_string().c_str())); +} + +KeyframeList::iterator +KeyframeList::find_next(const Time &x) +{ + KeyframeList::iterator iter(binary_find(begin(),end(),x)); + + if(iter!=end()) + { + if(iter->get_time().is_more_than(x)) + return iter; + ++iter; + if(iter!=end()) + { + if(iter->get_time().is_more_than(x)) + return iter; +/* ++iter; + if(iter!=end() && iter->get_time().is_more_than(x)) + return iter; +*/ + } + } + + throw Exception::NotFound(strprintf("KeyframeList::find(): Can't find next Keyframe %s",x.get_string().c_str())); +} + + +KeyframeList::iterator +KeyframeList::find_prev(const Time &x) +{ + KeyframeList::iterator iter(binary_find(begin(),end(),x)); + + if(iter!=end()) + { + if(iter->get_time()+Time::epsilon()get_time()+Time::epsilon()(this)->find(x); +} + + +KeyframeList::const_iterator +KeyframeList::find_next(const Time &x)const +{ + return const_cast(this)->find_next(x); + +} + + +KeyframeList::const_iterator +KeyframeList::find_prev(const Time &x)const +{ + return const_cast(this)->find_prev(x); + +} + +void +KeyframeList::find_prev_next(const Time& time, Time &prev, Time &next)const +{ + try { prev=find_prev(time)->get_time(); } + catch(...) { prev=Time::begin(); } + try { next=find_next(time)->get_time(); } + catch(...) { next=Time::end(); } +} + +void +KeyframeList::insert_time(const Time& location, const Time& delta) +{ +// sinfg::info("KeyframeList::insert_time(): loc=%s, delta=%s",location.get_string().c_str(),delta.get_string().c_str()); + if(!delta) + return; + try + { + iterator iter(find_next(location)); + for(;iter!=end();++iter) + { + iter->set_time(iter->get_time()+delta); + } + sync(); + } + catch(Exception::NotFound) { } +}