From: Carlos Lopez Date: Wed, 25 Aug 2010 15:15:59 +0000 (+0200) Subject: New Stroboscope layer. Patch from Ray Frederikson X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=b0ac91cb13525f4c1b5da03605dc0c8d82f35b7c;p=synfig.git New Stroboscope layer. Patch from Ray Frederikson --- diff --git a/synfig-core/po/POTFILES.in b/synfig-core/po/POTFILES.in index 65c7398..342fec3 100644 --- a/synfig-core/po/POTFILES.in +++ b/synfig-core/po/POTFILES.in @@ -32,6 +32,8 @@ src/modules/lyr_std/sphere_distort.cpp src/modules/lyr_std/sphere_distort.h src/modules/lyr_std/stretch.cpp src/modules/lyr_std/stretch.h +src/modules/lyr_std/stroboscope.cpp +src/modules/lyr_std/stroboscope.h src/modules/lyr_std/supersample.cpp src/modules/lyr_std/supersample.h src/modules/lyr_std/timeloop.cpp diff --git a/synfig-core/src/modules/lyr_std/Makefile.am b/synfig-core/src/modules/lyr_std/Makefile.am index 786d76d..8dc51b1 100644 --- a/synfig-core/src/modules/lyr_std/Makefile.am +++ b/synfig-core/src/modules/lyr_std/Makefile.am @@ -51,7 +51,9 @@ liblyr_std_la_SOURCES = \ sphere_distort.h \ sphere_distort.cpp \ curvewarp.cpp \ - curvewarp.h + curvewarp.h \ + stroboscope.cpp \ + stroboscope.h liblyr_std_la_CXXFLAGS = \ @SYNFIG_CFLAGS@ diff --git a/synfig-core/src/modules/lyr_std/main.cpp b/synfig-core/src/modules/lyr_std/main.cpp index faa0d7a..27c7000 100644 --- a/synfig-core/src/modules/lyr_std/main.cpp +++ b/synfig-core/src/modules/lyr_std/main.cpp @@ -67,6 +67,7 @@ #include "warp.h" #include "timeloop.h" #include "curvewarp.h" +#include "stroboscope.h" #endif @@ -98,6 +99,7 @@ MODULE_INVENTORY_BEGIN(liblyr_std) LAYER(Layer_Shade) LAYER(Layer_Bevel) LAYER(Layer_TimeLoop) + LAYER(Layer_Stroboscope) LAYER(Layer_SphereDistort) LAYER(CurveWarp) END_LAYERS diff --git a/synfig-core/src/modules/lyr_std/stroboscope.cpp b/synfig-core/src/modules/lyr_std/stroboscope.cpp new file mode 100644 index 0000000..5fa7fde --- /dev/null +++ b/synfig-core/src/modules/lyr_std/stroboscope.cpp @@ -0,0 +1,133 @@ +/* === S Y N F I G ========================================================= */ +/*! \file stroboscope.cpp +** \brief Implementation of the "Stroboscope" layer +** +** $Id$ +** +** \legal +** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley +** Copyright (c) 2007, 2008 Chris Moore +** Copyright (c) 2009 Ray Frederikson +** +** 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. +** +** 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 +** +** === N O T E S =========================================================== +** +** ========================================================================= */ + +/* === H E A D E R S ======================================================= */ + +#ifdef USING_PCH +# include "pch.h" +#else +#ifdef HAVE_CONFIG_H +# include +#endif + +#include "stroboscope.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#endif + +using namespace synfig; +using namespace std; +using namespace etl; + +/* === M A C R O S ========================================================= */ + +/* === G L O B A L S ======================================================= */ + +SYNFIG_LAYER_INIT(Layer_Stroboscope); +SYNFIG_LAYER_SET_NAME(Layer_Stroboscope,"stroboscope"); +SYNFIG_LAYER_SET_LOCAL_NAME(Layer_Stroboscope,N_("Stroboscope")); +SYNFIG_LAYER_SET_CATEGORY(Layer_Stroboscope,N_("Other")); +SYNFIG_LAYER_SET_VERSION(Layer_Stroboscope,"0.1"); +SYNFIG_LAYER_SET_CVS_ID(Layer_Stroboscope,"$Id$"); + +/* === P R O C E D U R E S ================================================= */ + +/* === M E T H O D S ======================================================= */ + +Layer_Stroboscope::Layer_Stroboscope() +{ + ratio=2; +} + +Layer_Stroboscope::~Layer_Stroboscope() +{ +} + +bool +Layer_Stroboscope::set_param(const String & param, const ValueBase &value) +{ + IMPORT(ratio); + + return Layer::set_param(param,value); +} + +ValueBase +Layer_Stroboscope::get_param(const String & param)const +{ + EXPORT(ratio); + EXPORT_NAME(); + EXPORT_VERSION(); + + return Layer::get_param(param); +} + +Layer::Vocab +Layer_Stroboscope::get_param_vocab()const +{ + Layer::Vocab ret(Layer::get_param_vocab()); + + ret.push_back(ParamDesc("ratio") + .set_local_name(_("Ratio")) + ); + + return ret; +} + +void +Layer_Stroboscope::set_time(Context context, Time t)const +{ + if (ratio != 0) + { + float fps = 24.0; + Canvas::LooseHandle canvas(get_canvas()); + if(canvas) + fps = canvas->rend_desc().get_frame_rate(); //not works :( + float frame = floor((t*fps)/ratio)*ratio; + t = Time(1)*(frame/fps); + } + + context.set_time(t); +} + +Color +Layer_Stroboscope::get_color(Context context, const Point &pos)const +{ + return context.get_color(pos); +} + +bool +Layer_Stroboscope::accelerated_render(Context context,Surface *surface,int quality, const RendDesc &renddesc, ProgressCallback *cb)const +{ + return context.accelerated_render(surface,quality,renddesc,cb); +} diff --git a/synfig-core/src/modules/lyr_std/stroboscope.h b/synfig-core/src/modules/lyr_std/stroboscope.h new file mode 100644 index 0000000..2e6c768 --- /dev/null +++ b/synfig-core/src/modules/lyr_std/stroboscope.h @@ -0,0 +1,69 @@ +/* === S Y N F I G ========================================================= */ +/*! \file stroboscope.h +** \brief Header file for implementation of the "Stroboscope" layer +** +** $Id$ +** +** \legal +** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley +** Copyright (c) 2008 Chris Moore +** Copyright (c) 2009 Ray Frederikson +** +** 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. +** +** 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 +*/ +/* ========================================================================= */ + +/* === S T A R T =========================================================== */ + +#ifndef __SYNFIG_STROBOSCOPE_H +#define __SYNFIG_STROBOSCOPE_H + +/* === H E A D E R S ======================================================= */ + +#include +#include +#include +#include + +/* === M A C R O S ========================================================= */ + +/* === T Y P E D E F S ===================================================== */ + +/* === C L A S S E S & S T R U C T S ======================================= */ + +class Layer_Stroboscope : public synfig::Layer +{ + SYNFIG_LAYER_MODULE_EXT + +private: + float ratio; + +protected: + Layer_Stroboscope(); + +public: + ~Layer_Stroboscope(); + + virtual bool set_param(const synfig::String & param, const synfig::ValueBase &value); + + virtual synfig::ValueBase get_param(const synfig::String & param)const; + + virtual Vocab get_param_vocab()const; + virtual synfig::Color get_color(synfig::Context context, const synfig::Point &pos)const; + + virtual void set_time(synfig::Context context, synfig::Time time)const; + virtual bool accelerated_render(synfig::Context context,synfig::Surface *surface,int quality, const synfig::RendDesc &renddesc, synfig::ProgressCallback *cb)const; +}; + +/* === E N D =============================================================== */ + +#endif diff --git a/synfig-core/src/synfig/context.cpp b/synfig-core/src/synfig/context.cpp index 28d8e41..4da071e 100644 --- a/synfig-core/src/synfig/context.cpp +++ b/synfig-core/src/synfig/context.cpp @@ -321,11 +321,13 @@ Context::set_time(Time time)const while(!(context)->empty()) { // If this layer is active, and - // it either isn't already set to the given time or - // it's a time loop layer, + // it either isn't already set to the given time + // or it's a stroboscope layer, + // or it's a time loop layer, // then break out of the loop and set its time if((*context)->active() && (!(*context)->dirty_time_.is_equal(time) || + (*context)->get_name() == "stroboscope" || (*context)->get_name() == "timeloop")) break;