X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;ds=sidebyside;f=synfig-core%2Ftrunk%2Fsrc%2Fmodules%2Flyr_std%2Ftimeloop.cpp;h=63cffcf51842310d04ad356aa10cf311e3204fd1;hb=871b0608eba89af3704ff665b7822b2cf59d7a97;hp=fc6d982724c9c62e1d3c844d4859f616ce9c99c7;hpb=21bfc670b83d4c45da9ed1b95063b7e6a007168c;p=synfig.git diff --git a/synfig-core/trunk/src/modules/lyr_std/timeloop.cpp b/synfig-core/trunk/src/modules/lyr_std/timeloop.cpp index fc6d982..63cffcf 100644 --- a/synfig-core/trunk/src/modules/lyr_std/timeloop.cpp +++ b/synfig-core/trunk/src/modules/lyr_std/timeloop.cpp @@ -1,9 +1,12 @@ -/*! ======================================================================== -** Synfig -** Image Layer_TimeLoop Layer Implementation -** $Id: timeloop.cpp,v 1.1.1.1 2005/01/04 01:23:10 darco Exp $ +/* === S Y N F I G ========================================================= */ +/*! \file timeloop.cpp +** \brief Implementation of the "Time Loop" layer ** +** $Id$ +** +** \legal ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley +** Copyright (c) 2007 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 @@ -14,6 +17,7 @@ ** 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 ** ** === N O T E S =========================================================== ** @@ -29,6 +33,9 @@ #endif #include "timeloop.h" +#include +#include +#include #include #include #include @@ -47,10 +54,10 @@ using namespace etl; SYNFIG_LAYER_INIT(Layer_TimeLoop); SYNFIG_LAYER_SET_NAME(Layer_TimeLoop,"timeloop"); -SYNFIG_LAYER_SET_LOCAL_NAME(Layer_TimeLoop,_("TimeLoop")); -SYNFIG_LAYER_SET_CATEGORY(Layer_TimeLoop,_("Other")); -SYNFIG_LAYER_SET_VERSION(Layer_TimeLoop,"0.1"); -SYNFIG_LAYER_SET_CVS_ID(Layer_TimeLoop,"$Id: timeloop.cpp,v 1.1.1.1 2005/01/04 01:23:10 darco Exp $"); +SYNFIG_LAYER_SET_LOCAL_NAME(Layer_TimeLoop,N_("Time Loop")); +SYNFIG_LAYER_SET_CATEGORY(Layer_TimeLoop,N_("Other")); +SYNFIG_LAYER_SET_VERSION(Layer_TimeLoop,"0.2"); +SYNFIG_LAYER_SET_CVS_ID(Layer_TimeLoop,"$Id$"); /* === P R O C E D U R E S ================================================= */ @@ -58,8 +65,9 @@ SYNFIG_LAYER_SET_CVS_ID(Layer_TimeLoop,"$Id: timeloop.cpp,v 1.1.1.1 2005/01/04 0 Layer_TimeLoop::Layer_TimeLoop() { - start_time=0; - end_time=1; + link_time=0; + local_time=0; + duration=1; } Layer_TimeLoop::~Layer_TimeLoop() @@ -69,16 +77,27 @@ Layer_TimeLoop::~Layer_TimeLoop() bool Layer_TimeLoop::set_param(const String & param, const ValueBase &value) { - IMPORT(start_time); - IMPORT(end_time); + if(old_version) + { + IMPORT(start_time); + IMPORT(end_time); + } + else + { + IMPORT(local_time); + IMPORT(link_time); + IMPORT(duration); + } + return Layer::set_param(param,value); } ValueBase Layer_TimeLoop::get_param(const String & param)const { - EXPORT(start_time); - EXPORT(end_time); + EXPORT(link_time); + EXPORT(local_time); + EXPORT(duration); EXPORT_NAME(); EXPORT_VERSION(); @@ -89,25 +108,109 @@ Layer::Vocab Layer_TimeLoop::get_param_vocab()const { Layer::Vocab ret(Layer::get_param_vocab()); - - ret.push_back(ParamDesc("start_time") - .set_local_name(_("Start Time")) + + ret.push_back(ParamDesc("link_time") + .set_local_name(_("Link Time")) + ); + + ret.push_back(ParamDesc("local_time") + .set_local_name(_("Local Time")) ); - ret.push_back(ParamDesc("end_time") - .set_local_name(_("End Time")) + ret.push_back(ParamDesc("duration") + .set_local_name(_("Duration")) ); - + return ret; } +bool +Layer_TimeLoop::set_version(const String &ver) +{ + if (ver=="0.1") + old_version = true; + + return true; +} + +void +Layer_TimeLoop::reset_version() +{ + // if we're not converting from an old version of the layer, there's nothing to do + if (!old_version) + return; + + old_version = false; + + // these are the conversions to go from 0.1 to 0.2: + // + // local_time = start_time + // duration = end_time - start_time + // if (time < start_time) + // link_time = -duration : if we want to reproduce the old behaviour - do we? + // else + // link_time = 0 + + // convert the static parameters + local_time = start_time; + duration = end_time - start_time; + //! \todo layer version 0.1 acted differently before start_time was reached - possibly due to a bug + link_time = 0; + + // convert the dynamic parameters + const DynamicParamList &dpl = dynamic_param_list(); + + // if neither start_time nor end_time are dynamic, there's nothing more to do + if (dpl.count("start_time") == 0 && dpl.count("end_time") == 0) + return; + + etl::rhandle start_time_value_node, end_time_value_node; + LinkableValueNode* duration_value_node; + + if (dpl.count("start_time")) + { + start_time_value_node = dpl.find("start_time")->second; + disconnect_dynamic_param("start_time"); + } + else + start_time_value_node = ValueNode_Const::create(start_time); + + if (dpl.count("end_time")) + { + end_time_value_node = dpl.find("end_time")->second; + disconnect_dynamic_param("end_time"); + } + else + end_time_value_node = ValueNode_Const::create(end_time); + + duration_value_node = ValueNode_Subtract::create(Time(0)); + duration_value_node->set_link("lhs", end_time_value_node); + duration_value_node->set_link("rhs", start_time_value_node); + + connect_dynamic_param("local_time", start_time_value_node); + connect_dynamic_param("duration", duration_value_node); + connect_dynamic_param("link_time", ValueNode_Const::create(Time(0))); +} + void -Layer_TimeLoop::set_time(Context context, Time time)const +Layer_TimeLoop::set_time(Context context, Time t)const { - Real diff(end_time-start_time); - if(diff>0) - time-=int(Real(time-start_time)/diff)*diff+start_time; - context.set_time(time); + if (duration == 0) + t = link_time; + else if (duration > 0) + { + t -= local_time; + t -= floor(t / duration) * duration; + t = link_time + t; + } + else + { + t -= local_time; + t -= floor(t / -duration) * -duration; + t = link_time - t; + } + + context.set_time(t); } Color