Blame synfig-core/src/synfig/target.cpp

Carlos Lopez a09598
/* === S Y N F I G ========================================================= */
Carlos Lopez a09598
/*!	\file target.cpp
Carlos Lopez a09598
**	\brief Target Class Implementation
Carlos Lopez a09598
**
Carlos Lopez a09598
**	$Id$
Carlos Lopez a09598
**
Carlos Lopez a09598
**	\legal
Carlos Lopez a09598
**	Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
Diego Barrios Romero 6202fa
**  Copyright (c) 2010 Diego Barrios Romero
Carlos Lopez a09598
**
Carlos Lopez a09598
**	This package is free software; you can redistribute it and/or
Carlos Lopez a09598
**	modify it under the terms of the GNU General Public License as
Carlos Lopez a09598
**	published by the Free Software Foundation; either version 2 of
Carlos Lopez a09598
**	the License, or (at your option) any later version.
Carlos Lopez a09598
**
Carlos Lopez a09598
**	This package is distributed in the hope that it will be useful,
Carlos Lopez a09598
**	but WITHOUT ANY WARRANTY; without even the implied warranty of
Carlos Lopez a09598
**	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Carlos Lopez a09598
**	General Public License for more details.
Carlos Lopez a09598
**	\endlegal
Carlos Lopez a09598
*/
Carlos Lopez a09598
/* ========================================================================= */
Carlos Lopez a09598
Carlos Lopez a09598
/* === H E A D E R S ======================================================= */
Carlos Lopez a09598
Carlos Lopez a09598
#ifdef HAVE_CONFIG_H
Carlos Lopez a09598
# include <config.h></config.h>
Carlos Lopez a09598
#endif
Carlos Lopez a09598
Carlos Lopez a09598
#include "target.h"
Carlos Lopez a09598
#include "string.h"
Carlos Lopez a09598
#include "canvas.h"
Carlos Lopez a09598
#include "target_null.h"
Carlos Lopez a09598
#include "target_null_tile.h"
Diego Barrios Romero 6202fa
#include "targetparam.h"
Carlos Lopez a09598
Carlos Lopez a09598
using namespace synfig;
Carlos Lopez a09598
using namespace etl;
Carlos Lopez a09598
using namespace std;
Carlos Lopez a09598
Carlos Lopez a09598
synfig::Target::Book* synfig::Target::book_;
Carlos Lopez a09598
synfig::Target::ExtBook* synfig::Target::ext_book_;
Carlos Lopez a09598
Carlos Lopez a09598
/* === P R O C E D U R E S ================================================= */
Carlos Lopez a09598
Carlos Lopez a09598
bool
Carlos Lopez a09598
Target::subsys_init()
Carlos Lopez a09598
{
Carlos Lopez a09598
	book_=new synfig::Target::Book();
Carlos Lopez a09598
	ext_book_=new synfig::Target::ExtBook();
Carlos Lopez a09598
Diego Barrios Romero 5dcab4
	// At least one target must be available.
Diego Barrios Romero 8289fa
	book()["null"].factory =
Diego Barrios Romero 8289fa
		reinterpret_cast<synfig::target::factory>(&Target_Null::create);</synfig::target::factory>
Diego Barrios Romero 6202fa
	book()["null"].filename = "null";
Diego Barrios Romero 6202fa
	book()["null"].target_param = TargetParam();
Carlos Lopez a09598
	ext_book()["null"]="null";
Diego Barrios Romero 8289fa
Diego Barrios Romero 8289fa
	book()["null-tile"].factory =
Diego Barrios Romero 6202fa
		reinterpret_cast<synfig::target::factory>(&Target_Null_Tile::create);</synfig::target::factory>
Diego Barrios Romero 6202fa
	book()["null-tile"].filename = "null-tile";
Diego Barrios Romero 6202fa
	book()["null-tile"].target_param = TargetParam();
Carlos Lopez a09598
	ext_book()["null-tile"]="null-tile";
Carlos Lopez a09598
Carlos Lopez a09598
	return true;
Carlos Lopez a09598
}
Carlos Lopez a09598
Carlos Lopez a09598
bool
Carlos Lopez a09598
Target::subsys_stop()
Carlos Lopez a09598
{
Carlos Lopez a09598
	delete book_;
Carlos Lopez a09598
	delete ext_book_;
Carlos Lopez a09598
	return true;
Carlos Lopez a09598
}
Carlos Lopez a09598
Carlos Lopez a09598
Target::Book&
Carlos Lopez a09598
Target::book()
Carlos Lopez a09598
{
Carlos Lopez a09598
	return *book_;
Carlos Lopez a09598
}
Carlos Lopez a09598
Carlos Lopez a09598
Target::ExtBook&
Carlos Lopez a09598
Target::ext_book()
Carlos Lopez a09598
{
Carlos Lopez a09598
	return *ext_book_;
Carlos Lopez a09598
}
Carlos Lopez a09598
Carlos Lopez a09598
Carlos Lopez a09598
/* === M E T H O D S ======================================================= */
Carlos Lopez a09598
Carlos Lopez a09598
Target::Target():
Carlos Lopez a09598
	quality_(4),
dc451c
	alpha_mode(TARGET_ALPHA_MODE_KEEP),
Carlos Lopez 4a0029
	avoid_time_sync_(false),
Carlos Lopez 4a0029
	curr_frame_(0)
Carlos Lopez a09598
{
Carlos Lopez a09598
}
Carlos Lopez a09598
Carlos Lopez a09598
void
Carlos Lopez a09598
synfig::Target::set_canvas(etl::handle<canvas> c)</canvas>
Carlos Lopez a09598
{
Carlos Lopez a09598
	canvas=c;
Carlos Lopez a09598
	RendDesc desc=canvas->rend_desc();
Carlos Lopez a09598
	set_rend_desc(&desc);
Carlos Lopez a09598
}
Carlos Lopez a09598
Carlos Lopez a09598
Carlos Lopez a09598
Target::Handle
Diego Barrios Romero 6202fa
Target::create(const String &name, const String &filename,
Diego Barrios Romero 6202fa
			   synfig::TargetParam params)
Carlos Lopez a09598
{
Carlos Lopez a09598
	if(!book().count(name))
Carlos Lopez a09598
		return handle<target>();</target>
Carlos Lopez a09598
Diego Barrios Romero 6202fa
	return Target::Handle(book()[name].factory(filename.c_str(), params));
Carlos Lopez a09598
}
Carlos Lopez 4a0029
Carlos Lopez 4a0029
int
Carlos Lopez 4a0029
Target::next_frame(Time& time)
Carlos Lopez 4a0029
{
Carlos Lopez 4a0029
	int
Carlos Lopez 4a0029
	total_frames(1),
Carlos Lopez 4a0029
	frame_start(0),
Carlos Lopez 4a0029
	frame_end(0);
Carlos Lopez 4a0029
	Time
Carlos Lopez 4a0029
	time_start(0),
Carlos Lopez 4a0029
	time_end(0);
Carlos Lopez 4fdecc
		
Carlos Lopez 4a0029
	frame_start=desc.get_frame_start();
Carlos Lopez 4a0029
	frame_end=desc.get_frame_end();
Carlos Lopez 4a0029
	time_start=desc.get_time_start();
Carlos Lopez 4a0029
	time_end=desc.get_time_end();
Carlos Lopez 4fdecc
	// TODO: Add option to exclude last frame
Carlos Lopez 4fdecc
	// If user wants to recover the last buggy behavior then 
Carlos Lopez 4fdecc
	// expose this option to the interface using the target params.
Carlos Lopez 4fdecc
	// At the moment it is set to false.
Carlos Lopez 4fdecc
	bool exclude_last_frame(false);
Carlos Lopez 4a0029
	// Calculate the number of frames
Carlos Lopez 4fdecc
	total_frames=frame_end-frame_start+(exclude_last_frame?0:1);
Carlos Lopez 4a0029
	if(total_frames<=0)total_frames=1;
Carlos Lopez 4fdecc
Carlos Lopez 4fdecc
	if(total_frames == 1)
Carlos Lopez 4fdecc
	{
Carlos Lopez 4fdecc
		time=time_start;
Carlos Lopez 4fdecc
	}
Carlos Lopez 4fdecc
	else
Carlos Lopez 4fdecc
	{
Carlos Lopez 4fdecc
		time=(time_end-time_start)*curr_frame_/(total_frames-(exclude_last_frame?0:1))+time_start;
Carlos Lopez 4fdecc
	}
Carlos Lopez 4fdecc
Carlos Lopez 4fdecc
//	synfig::info("before curr_frame_: %d",curr_frame_);
Carlos Lopez 4a0029
	curr_frame_++;
Carlos Lopez 4a0029
	
Carlos Lopez 4fdecc
//	synfig::info("before curr_frame_: %d",curr_frame_);
Carlos Lopez 4fdecc
//	synfig::info("total_frames: %d",total_frames);
Carlos Lopez 4fdecc
//	synfig::info("time_end: %s",time_end.get_string().c_str());
Carlos Lopez 4fdecc
//	synfig::info("time_start: %s",time_start.get_string().c_str());
Carlos Lopez 4fdecc
//	synfig::info("time: %s",time.get_string().c_str());
Carlos Lopez 4fdecc
//	synfig::info("remaining frames %d", total_frames-curr_frame_);
Carlos Lopez 4fdecc
Carlos Lopez 4fdecc
	return total_frames- curr_frame_;
Carlos Lopez 4a0029
}
Carlos Lopez 4a0029