// -------------------------------------------------------------------- //
// FILE 		: TransitionX.cpp										//
// DATE 		: 15/03/2004											//
// AUTOR		: Aymeric							//
// DESCRIPTION  : class TransitionX										//
// -------------------------------------------------------------------- //


#include <vcl.h>
#include <math.h>
#include <time.h>
#include "TransitionX.h"


// -------------------------------------------------------------------- //
// TTransitionX() constructor											//
// in  : the form and the bitmap										//
// out : nothing														//
// -------------------------------------------------------------------- //

TTransitionX::TTransitionX(TForm *DestForm, Graphics::TBitmap *DestBitMap) : TTransition(DestForm,DestBitMap)
{
	// -- nothing to do
}


// -------------------------------------------------------------------- //
// Cutout() the bitmap appears in several bands	(cutout effect)			//
// in  : resolution and te time between 2 frames						//
// out : nothing														//
// -------------------------------------------------------------------- //

void TTransitionX::Cutout(int Resolution, int FrameDelay)
{
	time_t t;
	srand((unsigned) time(&t));
	int j;
	int *Arr;

	int RangeUpper = mpDestBitMap->Width;

	// -- RangeUpper is the number of bands to complete the bitmap
	RangeUpper = ceil((float)RangeUpper / (float)Resolution);

	Arr=new int[RangeUpper];

	for (int i=0; i < RangeUpper; i++)
	{
		j=rand()%mpDestBitMap->Width;
		Application->ProcessMessages();

		while ( (j%Resolution) != 0 ) j=rand()%mpDestBitMap->Width;

		for (int search=0; search != i; search++)
		{
			Application->ProcessMessages();
			if (Arr[search] == j)
			{
				j=rand()%mpDestBitMap->Width;
				while ( (j%Resolution) != 0 ) j=rand()%mpDestBitMap->Width;
				search=-1;
			}
		}
		Arr[i]=j;
	}

	for (int i=0; i < RangeUpper; i++)
	{
		mrectBitMapSize=Rect(Arr[i],0,Arr[i]+Resolution,mpDestBitMap->Height);
		mrectScreenArea=Rect(Arr[i],0,Arr[i]+Resolution,mpDestBitMap->Height);
		mpDestForm->Canvas->CopyRect(mrectScreenArea,mpDestBitMap->Canvas,mrectBitMapSize);
		Application->ProcessMessages();
		Sleep(FrameDelay);
	}

	delete [] Arr;
}

