All pastes #213951 Raw Edit

Stuff

public cpp v1 · immutable
#213951 ·published 2006-10-21 18:59 UTC
rendered paste body
#include "PhotoBox.h"#include "PhotoStrip.h"PhotoStrip::PhotoStrip(PhotoBox *pBox){	mpBox = pBox;	mdxCurrPhoto = 0;	mNumPhotos = 0;	mpPhotoSurface = NULL;	Uint32 rmask, gmask, bmask, amask;	#if SDL_BYTEORDER == SDL_BIG_ENDIAN		rmask = 0x00ff0000;		gmask = 0x0000ff00;		bmask = 0xff000000;		amask = 0x000000ff;	#else		rmask = 0x00ff0000;	    gmask = 0x0000ff00;	    bmask = 0x000000ff;		amask = 0xff000000;	#endif		_mpTween = new Tween(0.0, 100.0, 700);	}PhotoStrip::~PhotoStrip(){}bool PhotoStrip::Init(){	mNumPhotos = GetPhotosFromDir(".\\", mPhotos);	NextPhoto();	return (true);}int PhotoStrip::GetPhotosFromDir(std::string fromDir, std::vector<Photo> &resultList){	StringList list;	String tmp;	int n_found = 0;		File *p_file	= new File(fromDir) ;	list			= p_file->getFileList();	// Walk through the found files, and extract	// the .png images.	for (unsigned i = 0; i < list.size(); i++) 	{		tmp = list[i];				File p_tmp_file = ".\\" +tmp;			if (p_tmp_file.getExtension() == "png")		{			struct Photo photo;			photo.mFileName = tmp;			photo.mX = 0;			photo.mY = 0;			photo.mWidth = 0;			photo.mHeight = 0;			resultList.push_back(photo);			n_found++;		}	}	return n_found;}/** * Show the next photo in the photo strip.  */bool PhotoStrip::NextPhoto(){	int dx_new = 0;		// No photos..	if (mPhotos.size() <= 0)		return (false);	// First photo	if (mdxCurrPhoto == 0)		dx_new = 0;	// Last photo	if ( mdxCurrPhoto == (mPhotos.size()-1) || mpPhotoSurface == NULL)		dx_new = 0; 	else		dx_new = ++mdxCurrPhoto;		mdxCurrPhoto = dx_new;	mCurrPhoto = mPhotos[mdxCurrPhoto];	// Get the photo data (width / height) data is not used..	if (!mpBox->GetPNGImageSize(mCurrPhoto.mFileName.c_str(), &mCurrPhoto.mWidth, &mCurrPhoto.mHeight))		return (false);		if (!LoadCurrPhotoOntoSurface())		return (false);	_mpTween->SetBegin(0);	_mpTween->SetFinish(400);	_mpTween->SetStartTime(this->mpBox->mpTimer->GetTime());	return (true);}// Just load the current photo onto the photo surface.bool PhotoStrip::LoadCurrPhotoOntoSurface(){	// Here we set the current photo. We need to following DLL files:	// - jpeg.dll	// - libpng12.dll	// - libtiff.dll	// - zlib1.dll	SDL_RWops *rwop;	rwop = SDL_RWFromFile(mCurrPhoto.mFileName.c_str(), "rb");	mpPhotoSurface = IMG_LoadPNG_RW(rwop);		if (!mpPhotoSurface)	{		return (false);	}	return (true);}void PhotoStrip::RenderPhoto(){	if (!mpBox->mpScreen)	return ;	// Draw the image to the screen	SDL_Rect dstrect;		//mpPhotoSurface->pixels = mpPhotoPixels;	mCurrPhoto.mX += 2;	int x = mCurrPhoto.mX;	// show message	/*	String msg = "PhotoStrip::RenderPhoto() new x: ";	char buf[10];	itoa(x,buf, 10);	msg.append(buf);	mpBox->Debug(msg);	*/	String msg = "Timer: ";	int time = mpBox->mpTimer->GetTime();	struct TweenInfo ti = _mpTween->TweenLinear(this->mpBox->mpTimer->GetTime());	time = ti.mPos;	char buf[20];	itoa(time, buf, 10);	msg.append(buf);	mpBox->Debug(msg);	// tmp blit whole screen	SDL_Rect rect;	rect.x = 0;	rect.y = 0;	rect.w = 500;	rect.h = 500;	SDL_FillRect(mpBox->mpScreen,&rect, 0x00000000);	// end tmp blit screen.	//dstrect.x = (mpBox->mpScreen->w - mpPhotoSurface->w)/2 + ti.mPos;	dstrect.x = ti.mPos;	dstrect.y = (mpBox->mpScreen->h - mpPhotoSurface->h)/2;	dstrect.w = mpPhotoSurface->w;	dstrect.h = mpPhotoSurface->h;	if ( SDL_BlitSurface(mpPhotoSurface, NULL, mpBox->mpScreen, &dstrect) < 0 ) {	    SDL_FreeSurface(mpPhotoSurface);	}}