⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 transition.cpp

📁 彩信浏览器
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// This file is part of Ambulant Player, www.ambulantplayer.org.//// Copyright (C) 2003-2007 Stichting CWI, // Kruislaan 413, 1098 SJ Amsterdam, The Netherlands.//// Ambulant Player is free software; you can redistribute it and/or modify// it under the terms of the GNU Lesser General Public License as published by// the Free Software Foundation; either version 2.1 of the License, or// (at your option) any later version.//// Ambulant Player 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 Lesser General Public License for more details.//// You should have received a copy of the GNU Lesser General Public License// along with Ambulant Player; if not, write to the Free Software// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA/*  * @$Id: transition.cpp,v 1.35 2007/02/12 14:15:23 jackjansen Exp $  */#include "ambulant/lib/logger.h"#include "ambulant/lib/node.h"#include "ambulant/common/layout.h"#include "ambulant/smil2/transition.h"#include <math.h>#define round(x) ((int)((x)+0.5))// It seems M_PI isn't defined for VC++#ifndef M_PI#define M_PI 3.1415926#endif//#define AM_DBG#ifndef AM_DBG#define AM_DBG if(0)#endif#define MATRIX_HSTEPS 8#define MATRIX_VSTEPS 8using namespace ambulant;using namespace smil2;transition_engine::transition_engine():	m_dst(NULL),	m_info(NULL),	m_begin_time(0),	m_stepcount(0),	m_progress(0),	m_old_progress(0),	m_progress_per_milli(0){	AM_DBG lib::logger::get_logger()->debug("transition_engine::transition_engine()");}transition_engine::~transition_engine(){	AM_DBG lib::logger::get_logger()->debug("transition_engine::~transition_engine()");}voidtransition_engine::init(common::surface *dst, bool outtrans, const lib::transition_info *info){	m_dst = dst;	m_outtrans = outtrans;	m_info = info;	AM_DBG lib::logger::get_logger()->debug("transition_engine::init()");	m_progress = m_info->m_startProgress;	lib::transition_info::time_type dur = m_info->m_dur;	if (dur <= 0) {		lib::logger::get_logger()->trace("transition: duration %f, should be greater than zero", float(dur));		dur = 1;	}	m_progress_per_milli = (m_info->m_endProgress - m_info->m_startProgress) / dur;}voidtransition_engine::begin(lib::transition_info::time_type now){	AM_DBG lib::logger::get_logger()->debug("transition_engine::begin(%d)", now);	assert(m_info);	m_begin_time = now;}voidtransition_engine::end(){	AM_DBG lib::logger::get_logger()->debug("transition_engine::end()");	assert(m_info);}voidtransition_engine::step(lib::transition_info::time_type now){	AM_DBG lib::logger::get_logger()->debug("transition_engine::step(%d)", now);	assert(m_info);	m_progress = (now-m_begin_time) * m_progress_per_milli + m_info->m_startProgress;	if (m_progress <= m_old_progress)		m_progress = m_old_progress;	else		m_old_progress = m_progress;	if (m_progress > m_info->m_endProgress) m_progress = 1.0;	AM_DBG lib::logger::get_logger()->debug("transition_engine::step: delta_t=%d, progress=%f%%", now-m_begin_time, m_progress*100);	compute();	update();}booltransition_engine::is_done(){	assert(m_info);	return m_progress >= m_info->m_endProgress;}lib::transition_info::time_typetransition_engine::next_step_delay(){	assert(m_info);	if (m_stepcount) {		double dt = m_info->m_dur / m_stepcount;		AM_DBG lib::logger::get_logger()->debug("transition_engine::next_step_delay: m_stepcount=%d, dt=%f", m_stepcount, dt);		return (lib::transition_info::time_type)dt;	}	return 20; // Show something 50 times per second}// **********************// Series 1: edge wipesvoidtransition_engine_barwipe::compute(){	// XXX Only does horizontal left-to-right at the moment	lib::rect dstrect = m_dst->get_rect();	int wcur = round(m_progress*dstrect.width());	m_stepcount = dstrect.width();//	int ycur = dstrect.top() + round(m_progress*(dstrect.bottom() - dstrect.top()));	m_newrect = lib::rect(dstrect.left_top(), lib::size(wcur, dstrect.height()));}voidtransition_engine_boxwipe::compute(){	// XXX Only does box from topleft right now	lib::rect dstrect = m_dst->get_rect();	int wcur = round(m_progress*dstrect.width());	int hcur = round(m_progress*dstrect.height());	m_stepcount = dstrect.width();	m_newrect = lib::rect(dstrect.left_top(), lib::size(wcur, hcur));}voidtransition_engine_fourboxwipe::compute(){	lib::rect dstrect = m_dst->get_rect();	int xmid = (dstrect.left() + dstrect.right())/2;	int ymid = (dstrect.top() + dstrect.bottom())/2;	int half_width = round(m_progress*(xmid - dstrect.left()));	int half_height = round(m_progress*(ymid - dstrect.top()));	lib::size half_size(half_width, half_height);	m_stepcount = (dstrect.width())/2;	clear();	m_newrectlist.push_back(lib::rect(		dstrect.left_top(),		half_size));	m_newrectlist.push_back(lib::rect(		lib::point(dstrect.right()-half_width, dstrect.top()),		half_size));	m_newrectlist.push_back(lib::rect(		lib::point(dstrect.left(), dstrect.bottom()-half_height),		half_size));	m_newrectlist.push_back(lib::rect(		lib::point(dstrect.right()-half_width, dstrect.bottom()-half_height),		half_size));}voidtransition_engine_barndoorwipe::compute(){	// XXX Only does horizontal right now	lib::rect dstrect = m_dst->get_rect();	int xmid = (dstrect.left() + dstrect.right())/2;//	int ymid = (dstrect.top() + dstrect.bottom())/2;	int half_width = round(m_progress*(xmid - dstrect.left()));//	int half_height = round(m_progress*(ymid - dstrect.top()));	m_stepcount = (dstrect.width())/2;	m_newrect = lib::rect(		lib::point(xmid-half_width, dstrect.top()),		lib::size(2*half_width, dstrect.height()));}voidtransition_engine_diagonalwipe::compute(){	lib::rect dstrect = m_dst->get_rect();	int xmin = dstrect.left() - 2*dstrect.width();	int xcur = xmin + (int)(m_progress*2*dstrect.width());	clear();	m_stepcount = 2*dstrect.width();		m_newpolygon.push_back(lib::point(xcur, dstrect.top()));	m_newpolygon.push_back(lib::point(xcur+2*dstrect.width(), dstrect.top()));	m_newpolygon.push_back(lib::point(xcur+dstrect.width(), dstrect.bottom()));	m_newpolygon.push_back(lib::point(xcur, dstrect.bottom()));}voidtransition_engine_miscdiagonalwipe::compute(){	lib::rect dstrect = m_dst->get_rect();	lib::logger::get_logger()->trace("transitiontype miscDiagonalWipe not yet implemented");}voidtransition_engine_veewipe::compute(){	lib::rect dstrect = m_dst->get_rect();	lib::logger::get_logger()->trace("transitiontype veeWipe not yet implemented");}voidtransition_engine_barnveewipe::compute(){	lib::rect dstrect = m_dst->get_rect();	lib::logger::get_logger()->trace("transitiontype barnVeeWipe not yet implemented");}voidtransition_engine_zigzagwipe::compute(){	lib::rect dstrect = m_dst->get_rect();	lib::logger::get_logger()->trace("transitiontype zigZagWipe not yet implemented");}voidtransition_engine_barnzigzagwipe::compute(){	lib::rect dstrect = m_dst->get_rect();	lib::logger::get_logger()->trace("transitiontype barnZigZagWipe not yet implemented");}voidtransition_engine_bowtiewipe::compute(){	lib::rect dstrect = m_dst->get_rect();	int x0 = dstrect.left();	int y0 = dstrect.top();	int x1 = dstrect.right();	int y1 = dstrect.bottom();	int xmid = (x0 + x1)/2;	int ymid = (y0 + y1)/2;	int width = x1 - x0;	int height = y1 - y0;		if (m_progress <= 0.5) {		int xleft, xright, ytop, ybot;		std::vector<lib::point> poly;		double deltax = m_progress*width;		xleft  = static_cast<int>(round(xmid - deltax));		xright = static_cast<int>(round(xmid + deltax));		double deltay = m_progress*height;		ytop   = static_cast<int>(round(y0   + deltay));		ybot   = static_cast<int>(round(y1   - deltay));		poly.push_back(lib::point(xleft,  y0));		poly.push_back(lib::point(xright, y0));		poly.push_back(lib::point(xmid,   ytop));		m_newpolygonlist.push_back(poly);		poly.clear();		poly.push_back(lib::point(xleft,  y1));		poly.push_back(lib::point(xright, y1));		poly.push_back(lib::point(xmid,   ybot));		m_newpolygonlist.push_back(poly);	} else {		lib::transition_info::progress_type value = m_progress - 0.5;		int xleft, xright, ytop, ybot;		std::vector<lib::point> poly;		double deltax = value*width;		xleft  = static_cast<int>(round(xmid - deltax));		xright = static_cast<int>(round(xmid + deltax));		double deltay = value*width;		ytop   = static_cast<int>(round(y0   + deltay));		ybot   = static_cast<int>(round(y1   - deltay));		poly.push_back(lib::point(x0,  y0));		poly.push_back(lib::point(x0,  ytop));		poly.push_back(lib::point(xleft, ymid));		poly.push_back(lib::point(x0,  ybot));		poly.push_back(lib::point(x0,  y1));		poly.push_back(lib::point(x1,  y1));		poly.push_back(lib::point(x1,  ybot));		poly.push_back(lib::point(xright, ymid));		poly.push_back(lib::point(x1,  ytop));		poly.push_back(lib::point(x1,  y0));		m_newpolygonlist.push_back(poly);	}}// series 2: iris wipesvoidtransition_engine__iris::compute(){	lib::rect dstrect = m_dst->get_rect();	int pointcount;	lib::dpoint *pointp = get_template(&pointcount);	clear();	m_stepcount = dstrect.width()/2;	double radius = sqrt( 		(0.5*dstrect.width())*(0.5*dstrect.width()) + 		(0.5*dstrect.height())*(0.5*dstrect.height()));	while (pointcount--) {		lib::dpoint rel_point(pointp->x * m_progress, pointp->y * m_progress);		lib::point abs_point(			(int)(rel_point.x * radius + (dstrect.left() + dstrect.right())/2.0 ),			(int)(rel_point.y * radius + (dstrect.top() + dstrect.bottom())/2.0 ));		m_newpolygon.push_back(abs_point);		pointp++;	}}lib::dpoint ambulant::smil2::transition_engine_iriswipe::m_template[] = {	lib::dpoint(-1, -1),	lib::dpoint(1, -1),	lib::dpoint(1, 1),	lib::dpoint(-1, 1)};lib::dpoint *transition_engine_iriswipe::get_template(int *size){	*size = sizeof(m_template) / sizeof(m_template[0]);	return m_template;}lib::dpoint ambulant::smil2::transition_engine_pentagonwipe::m_template[] = {	lib::dpoint(0.000000, -1.236068),	lib::dpoint(1.175571, -0.381966),	lib::dpoint(0.726543, 1.000000),	lib::dpoint(-0.726543, 1.000000),	lib::dpoint(-1.175571, -0.381966)};lib::dpoint *transition_engine_pentagonwipe::get_template(int *size){	*size = sizeof(m_template) / sizeof(m_template[0]);	return m_template;}lib::dpoint ambulant::smil2::transition_engine_arrowheadwipe::m_template[] = {	lib::dpoint(0.000000, 0.500000),	lib::dpoint(1.732051, 1.000000),	lib::dpoint(0.000000, -2.000000),	lib::dpoint(-1.732051, 1.000000)};lib::dpoint *transition_engine_arrowheadwipe::get_template(int *size){	*size = sizeof(m_template) / sizeof(m_template[0]);	return m_template;}lib::dpoint ambulant::smil2::transition_engine_trianglewipe::m_template[] = {	lib::dpoint(0.000000, -2.000000),	lib::dpoint(1.732051, 1.000000),	lib::dpoint(-1.732051, 1.000000)};lib::dpoint *transition_engine_trianglewipe::get_template(int *size){	*size = sizeof(m_template) / sizeof(m_template[0]);	return m_template;}lib::dpoint ambulant::smil2::transition_engine_hexagonwipe::m_template[] = {	lib::dpoint(0.000000, 1.154701),	lib::dpoint(1.000000, 0.577350),	lib::dpoint(1.000000, -0.577350),	lib::dpoint(0.000000, -1.154701),	lib::dpoint(-1.000000, -0.577350),	lib::dpoint(-1.000000, 0.577350)};lib::dpoint *transition_engine_hexagonwipe::get_template(int *size){	*size = sizeof(m_template) / sizeof(m_template[0]);	return m_template;}lib::dpoint ambulant::smil2::transition_engine_eyewipe::m_template[] = {	lib::dpoint(-1, -1),	lib::dpoint(1, -1),	lib::dpoint(1, 1),	lib::dpoint(1, 1)};lib::dpoint *transition_engine_eyewipe::get_template(int *size){	*size = sizeof(m_template) / sizeof(m_template[0]);	return m_template;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -