X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=synfig-core%2Ftrunk%2Fsrc%2Fsynfig%2Fvaluenode_animated.cpp;h=b211da04aadd618ae97305f53117303797fbdfb0;hb=5ddcf36f04cfbd10fabda4e3c5633cb27cdd4c0a;hp=85ee4284db02c8ffac6168568045b4424f3b73f9;hpb=e3acc0b267b14fda5db3c7bbb2f218b993ef84b3;p=synfig.git diff --git a/synfig-core/trunk/src/synfig/valuenode_animated.cpp b/synfig-core/trunk/src/synfig/valuenode_animated.cpp index 85ee428..b211da0 100644 --- a/synfig-core/trunk/src/synfig/valuenode_animated.cpp +++ b/synfig-core/trunk/src/synfig/valuenode_animated.cpp @@ -1,20 +1,21 @@ -/* === S I N F G =========================================================== */ +/* === S Y N F I G ========================================================= */ /*! \file valuenode_animated.cpp ** \brief Template File ** ** $Id: valuenode_animated.cpp,v 1.1.1.1 2005/01/04 01:23:15 darco Exp $ ** ** \legal -** Copyright (c) 2002 Robert B. Quattlebaum Jr. +** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley ** -** 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 */ /* ========================================================================= */ @@ -56,7 +57,7 @@ using namespace std; using namespace etl; -using namespace sinfg; +using namespace synfig; /* === M A C R O S ========================================================= */ @@ -66,11 +67,11 @@ template inline I binary_find(I begin, I end, const T& value) { I iter(begin+(end-begin)/2); - + while(end-begin>1 && !(*iter==value)) { ((*iter /* === C L A S S E S ======================================================= */ template -class _Hermite : public sinfg::ValueNode_Animated +class _Hermite : public synfig::ValueNode_Animated { public: typedef T value_type; @@ -186,21 +187,21 @@ private: { is_angle_type is_angle; subtractor subtract_func; - + mutable hermite first; mutable hermite second; WaypointList::iterator start; WaypointList::iterator end; - + value_type resolve(const Time &t)const { bool start_static(start->is_static()); bool end_static(end->is_static()); - + if(!start_static || !end_static) { //if(!start_static) - second.p1()=start->get_value(t).get(value_type()); + second.p1()=start->get_value(t).get(value_type()); if(start->get_after()==INTERPOLATION_CONSTANT || end->get_before()==INTERPOLATION_CONSTANT) return second.p1(); //if(!end_static) @@ -210,7 +211,7 @@ private: // that we support is linear. second.t1()= second.t2()=subtract_func(second.p2(),second.p1()); - + second.sync(); } @@ -228,10 +229,10 @@ private: > curve_list_type; curve_list_type curve_list; - + // Bounds of this curve Time r,s; - + public: ValueNode* clone(const GUID& deriv_guid)const { @@ -253,23 +254,23 @@ public: // Make sure we are getting data of the correct type //if(data.type!=type) // return waypoint_list_type::iterator(); - + try { find(t); throw Exception::BadTime(_("A waypoint already exists at this point in time")); } catch(Exception::NotFound) { }; Waypoint waypoint(value,t); waypoint.set_parent_value_node(this); - + waypoint_list_.push_back(waypoint); WaypointList::iterator ret=waypoint_list_.end(); --ret; - + if(is_angle()) { ret->set_before(INTERPOLATION_LINEAR); ret->set_after(INTERPOLATION_LINEAR); } - + changed(); - + return ret; } @@ -279,10 +280,10 @@ public: //if(data.type!=type) // return waypoint_list_type::iterator(); try { find(t); throw Exception::BadTime(_("A waypoint already exists at this point in time")); } catch(Exception::NotFound) { }; - + Waypoint waypoint(value_node,t); waypoint.set_parent_value_node(this); - + waypoint_list_.push_back(waypoint); WaypointList::iterator ret=waypoint_list_.end(); --ret; @@ -294,14 +295,14 @@ public: } changed(); - + return ret; } - + virtual void on_changed() { ValueNode_Animated::on_changed(); - + if(waypoint_list_.size()<=1) return; std::sort(waypoint_list_.begin(),waypoint_list_.end()); @@ -309,12 +310,12 @@ public: r=waypoint_list_.front().get_time(); s=waypoint_list_.back().get_time(); - + curve_list.clear(); - + WaypointList::iterator prev,iter,next=waypoint_list_.begin(); int i=0; - + for(iter=next++;iter!=waypoint_list_.end() && next!=waypoint_list_.end();prev=iter,iter=next++,i++) { typename curve_list_type::value_type curve; @@ -323,16 +324,16 @@ public: curve.start=iter; curve.end=next; - + // Set up the positions curve.first.set_rs(iter->get_time(), next->get_time()); curve.second.set_rs(iter->get_time(), next->get_time()); - + Waypoint::Interpolation iter_get_after(iter->get_after()); Waypoint::Interpolation next_get_after(next->get_after()); Waypoint::Interpolation iter_get_before(iter->get_before()); Waypoint::Interpolation next_get_before(next->get_before()); - + if(is_angle()) { if(iter_get_after==INTERPOLATION_TCB) @@ -344,7 +345,7 @@ public: if(next_get_before==INTERPOLATION_TCB) next_get_before=INTERPOLATION_LINEAR; } - + if(iter->is_static() && next->is_static()) { curve.second.p1()=iter->get_value().get(T()); @@ -377,29 +378,29 @@ public: const Real& t(iter->get_tension()); // Tension const Real& c(iter->get_continuity()); // Continuity const Real& b(iter->get_bias()); // Bias - + // The folloing line works where the previous line fails. value_type Pp; Pp=curve_list.back().second.p1(); // P_{i-1} - + const value_type& Pc(curve.second.p1()); // P_i const value_type& Pn(curve.second.p2()); // P_{i+1} - + // TCB value_type vect(static_cast(subtract_func(Pc,Pp)*(((1.0-t)*(1.0+c)*(1.0+b))/2.0)+(Pn-Pc)*(((1.0-t)*(1.0-c)*(1.0-b))/2.0))); - + // Tension Only //value_type vect=(value_type)((Pn-Pp)*(1.0-t)); - + // Linear //value_type vect=(value_type)(Pn-Pc); // Debugging stuff - //sinfg::info("%d:t1: %s",i,tangent_info(Pp,Pn,vect).c_str()); - + //synfig::info("%d:t1: %s",i,tangent_info(Pp,Pn,vect).c_str()); + // Adjust for time //vect=value_type(vect*(curve.second.get_dt()*2.0)/(curve.second.get_dt()+curve_list.back().second.get_dt())); //vect=value_type(vect*(curve.second.get_dt())/(curve_list.back().second.get_dt())); - + curve.second.t1()=vect; } } @@ -416,7 +417,7 @@ public: curve_list.back().second.sync(); } - + if(next_get_before==INTERPOLATION_TCB && after_next!=waypoint_list_.end() && !is_angle()) { const Real &t(next->get_tension()); // Tension @@ -425,18 +426,18 @@ public: const value_type &Pp(curve.second.p1()); // P_{i-1} const value_type &Pc(curve.second.p2()); // P_i value_type Pn; Pn=after_next->get_value().get(T()); // P_{i+1} - + // TCB value_type vect(static_cast(subtract_func(Pc,Pp)*(((1.0-t)*(1.0-c)*(1.0+b))/2.0)+(Pn-Pc)*(((1.0-t)*(1.0+c)*(1.0-b))/2.0))); // Tension Only //value_type vect((value_type)((Pn-Pp)*(1.0-t))); - + // Linear //value_type vect=(value_type)(Pc-Pp); // Debugging stuff - //sinfg::info("%d:t2: %s",i,tangent_info(Pp,Pn,vect).c_str()); + //synfig::info("%d:t2: %s",i,tangent_info(Pp,Pn,vect).c_str()); // Adjust for time //vect=value_type(vect*(curve.second.get_dt()*2.0)/(curve.second.get_dt()+(after_next->get_time()-next->get_time()))); @@ -453,7 +454,7 @@ public: // Adjust for time const float timeadjust(0.5); - + if(!curve_list.empty()) curve.second.t1()*=(curve.second.get_dt()*(timeadjust+1))/(curve.second.get_dt()*timeadjust+curve_list.back().second.get_dt()); if(after_next!=waypoint_list_.end()) @@ -461,9 +462,9 @@ public: if(iter_get_after==INTERPOLATION_HALT) curve.second.t1()*=0; - + if(next_get_before==INTERPOLATION_HALT) - curve.second.t2()*=0; + curve.second.t2()*=0; } } @@ -481,7 +482,7 @@ public: curve_list.push_back(curve); } } - + virtual ValueBase operator()(Time t)const { if(waypoint_list_.empty()) @@ -492,7 +493,7 @@ public: return waypoint_list_.front().get_value(t); if(t>=s) return waypoint_list_.back().get_value(t); - + typename curve_list_type::const_iterator iter; // This next line will set iter to the @@ -502,12 +503,12 @@ public: if(iter==curve_list.end()) return waypoint_list_.back().get_value(t); return iter->resolve(t); - } -}; + } +}; template -class _Constant : public sinfg::ValueNode_Animated +class _Constant : public synfig::ValueNode_Animated { public: typedef T value_type; @@ -539,10 +540,10 @@ public: //if(data.type!=type) // return waypoint_list_type::iterator(); try { find(t); throw Exception::BadTime(_("A waypoint already exists at this point in time")); } catch(Exception::NotFound) { }; - + Waypoint waypoint(value,t); waypoint.set_parent_value_node(this); - + waypoint_list_.push_back(waypoint); WaypointList::iterator ret=waypoint_list_.end(); --ret; @@ -560,7 +561,7 @@ public: Waypoint waypoint(value_node,t); waypoint.set_parent_value_node(this); - + waypoint_list_.push_back(waypoint); WaypointList::iterator ret=waypoint_list_.end(); --ret; @@ -572,7 +573,7 @@ public: virtual void on_changed() { ValueNode_Animated::on_changed(); - + if(waypoint_list_.size()<=1) return; std::sort(waypoint_list_.begin(),waypoint_list_.end()); @@ -605,7 +606,7 @@ public: } }; -class _AnimBool : public sinfg::ValueNode_Animated +class _AnimBool : public synfig::ValueNode_Animated { public: typedef bool value_type; @@ -638,10 +639,10 @@ public: // return waypoint_list_type::iterator(); try { find(t); throw Exception::BadTime(_("A waypoint already exists at this point in time")); } catch(Exception::NotFound) { }; - + Waypoint waypoint(value,t); waypoint.set_parent_value_node(this); - + waypoint_list_.push_back(waypoint); WaypointList::iterator ret=waypoint_list_.end(); --ret; @@ -659,7 +660,7 @@ public: Waypoint waypoint(value_node,t); waypoint.set_parent_value_node(this); - + waypoint_list_.push_back(waypoint); WaypointList::iterator ret=waypoint_list_.end(); --ret; @@ -671,7 +672,7 @@ public: virtual void on_changed() { ValueNode_Animated::on_changed(); - + if(waypoint_list_.size()<=1) return; std::sort(waypoint_list_.begin(),waypoint_list_.end()); @@ -703,7 +704,7 @@ public: if(iter->get_time()==t) return iter->get_value(t); - + if(next!=waypoint_list_.end()) return iter->get_value(t).get(bool()) || next->get_value(t).get(bool()); return iter->get_value(t); @@ -722,7 +723,7 @@ ValueNode_Animated::find(const Time& begin,const Time& end,std::vectorset_time(old_2_new(selected.back()->get_time())); selected.pop_back(); } - - + + while(!selected.empty()) { selected.back()->set_time(old_2_new(selected.back()->get_time())); selected.pop_back(); } - + changed(); } #undef old_2_new @@ -804,7 +805,7 @@ ValueNode_Animated::new_waypoint_at_time(const Time& time)const waypoint.make_unique(); } catch(...) - { + { if(waypoint_list().empty()) { waypoint.set_value((*this)(time)); @@ -815,10 +816,10 @@ ValueNode_Animated::new_waypoint_at_time(const Time& time)const WaypointList::const_iterator next; bool has_prev(false), has_next(false); - + try { prev=find_prev(time); has_prev=true; } catch(...) { } try { next=find_next(time); has_next=true; } catch(...) { } - + /* WaypointList::const_iterator closest; @@ -830,7 +831,7 @@ ValueNode_Animated::new_waypoint_at_time(const Time& time)const closest=prev; else closest=next; - + for(iter=waypoint_list().begin();iter!=waypoint_list().end();++iter) { const Real dist(abs(iter->get_time()-time)); @@ -838,14 +839,14 @@ ValueNode_Animated::new_waypoint_at_time(const Time& time)const closest=iter; } */ - + if(has_prev && !prev->is_static()) waypoint.set_value_node(prev->get_value_node()); if(has_next && !next->is_static()) waypoint.set_value_node(next->get_value_node()); else waypoint.set_value((*this)(time)); - + /*if(has_prev) waypoint.set_after(prev->get_before()); if(has_next) @@ -855,9 +856,9 @@ ValueNode_Animated::new_waypoint_at_time(const Time& time)const } waypoint.set_time(time); waypoint.set_parent_value_node(const_cast(this)); -// sinfg::info("waypoint.get_after()=set to %d",waypoint.get_after()); -// sinfg::info("waypoint.get_before()=set to %d",waypoint.get_before()); - +// synfig::info("waypoint.get_after()=set to %d",waypoint.get_after()); +// synfig::info("waypoint.get_before()=set to %d",waypoint.get_before()); + return waypoint; } @@ -922,7 +923,7 @@ ValueNode_Animated::find_next(const Time &x) if(iter!=waypoint_list().end() && iter->get_time().is_more_than(x)) return iter; } - + throw Exception::NotFound(strprintf("ValueNode_Animated::find_next(): Can't find Waypoint after %s",x.get_string().c_str())); } @@ -941,7 +942,7 @@ ValueNode_Animated::find_next(const Time &x)const if(iter!=waypoint_list().end() && iter->get_time()-Time::epsilon()>x) return iter; } - + throw Exception::NotFound(strprintf("ValueNode_Animated::find_next(): Can't find Waypoint after %s",x.get_string().c_str())); */ } @@ -958,7 +959,7 @@ ValueNode_Animated::find_prev(const Time &x) if(iter!=waypoint_list().begin() && (--iter)->get_time().is_less_than(x)) return iter; } - + throw Exception::NotFound(strprintf("ValueNode_Animated::find_prev(): Can't find Waypoint after %s",x.get_string().c_str())); } @@ -1006,7 +1007,7 @@ ValueNode_Animated::set_type(ValueBase::Type t) } ValueNode_Animated::Handle -sinfg::ValueNode_Animated::create(ValueBase::Type type) +synfig::ValueNode_Animated::create(ValueBase::Type type) { switch(type) { @@ -1022,7 +1023,7 @@ sinfg::ValueNode_Animated::create(ValueBase::Type type) return ValueNode_Animated::Handle(new _Hermite); case ValueBase::TYPE_COLOR: return ValueNode_Animated::Handle(new _Hermite); - + case ValueBase::TYPE_STRING: return ValueNode_Animated::Handle(new _Constant); case ValueBase::TYPE_GRADIENT: @@ -1033,7 +1034,7 @@ sinfg::ValueNode_Animated::create(ValueBase::Type type) return ValueNode_Animated::Handle(new _Constant); default: throw - Exception::BadType(strprintf(_("%s: You cannot use a %s in an animated ValueNode"),"sinfg::ValueNode_Animated::create()", + Exception::BadType(strprintf(_("%s: You cannot use a %s in an animated ValueNode"),"synfig::ValueNode_Animated::create()", ValueBase::type_name(type).c_str()) ); break; @@ -1074,7 +1075,7 @@ ValueNode_Animated::get_local_name()const void ValueNode_Animated::get_times_vfunc(Node::time_set &set) const { //add all the way point times to the value node... - + WaypointList::const_iterator i = waypoint_list().begin(), end = waypoint_list().end(); @@ -1091,68 +1092,68 @@ void ValueNode_Animated::get_times_vfunc(Node::time_set &set) const struct timecmp { Time t; - + timecmp(const Time &c) :t(c) {} - + bool operator()(const Waypoint &rhs) const { return t.is_equal(rhs.get_time()); } }; - + ValueNode_Animated::findresult ValueNode_Animated::find_uid(const UniqueID &x) { findresult f; f.second = false; - + //search for it... and set the bool part of the return value to true if we found it! f.first = std::find(waypoint_list_.begin(), waypoint_list_.end(), x); if(f.first != waypoint_list_.end()) f.second = true; - + return f; } - + ValueNode_Animated::const_findresult ValueNode_Animated::find_uid(const UniqueID &x)const { const_findresult f; f.second = false; - + //search for it... and set the bool part of the return value to true if we found it! f.first = std::find(waypoint_list_.begin(), waypoint_list_.end(), x); if(f.first != waypoint_list_.end()) f.second = true; - + return f; } - - ValueNode_Animated::findresult + + ValueNode_Animated::findresult ValueNode_Animated::find_time(const Time &x) { findresult f; f.second = false; - + //search for it... and set the bool part of the return value to true if we found it! f.first = std::find_if(waypoint_list_.begin(), waypoint_list_.end(), timecmp(x)); if(f.first != waypoint_list_.end()) f.second = true; - + return f; } - + ValueNode_Animated::const_findresult ValueNode_Animated::find_time(const Time &x)const { const_findresult f; f.second = false; - + //search for it... and set the bool part of the return value to true if we found it! f.first = std::find_if(waypoint_list_.begin(), waypoint_list_.end(), timecmp(x)); if(f.first != waypoint_list_.end()) f.second = true; - + return f; }