Example #1
0
void PixiePVTMain()
	{
	ImageFormat_PNG::Register();
	ImageFormat_JPG::Register();
	ImageFormat_GIF::Register();
	ImageFormat_TGA::Register();

	Platform::GetPlatform_Screen()->SetFullscreen(false);

	ResourceManager resourceManager;
	InputManager inputManager;
	inputManager.HideCursor();

	CommandLine cmd;
	
	StringId filename=cmd.GetCommandLineString(0);

	if (Platform::GetPlatform_FileSystem())
		{	
		Platform_FileSystem_File* file=Platform::GetPlatform_FileSystem()->CreateFileObject(filename.GetString());
		if (!file->Exists())
			{
			return;
			}
		delete file;
		}
	else
		{
		return;
		}

	if (!VerifyFilename(filename.GetString()))
		{
		return;
		}

	bool fullscreen=false;
	int screenWidth=Platform::GetPlatform_Screen()->GetWidth();
	int screenHeight=Platform::GetPlatform_Screen()->GetHeight();
	Array<StringId> files;
	StringId path=GetPath(filename);
	StringId filenameOnly=GetFilename(filename);
	Platform_FileSystem_Directory* directory=Platform::GetPlatform_FileSystem()->CreateDirectoryObject(path.GetString());
	int fileIndex=0;
	for (int i=0; i<directory->GetFileCount(); i++)
		{
		const char* name=directory->GetFile(i);
		if (VerifyFilename(name))
			{
			char buffer[4096];
			SNPrintF(buffer,4096,"%s/%s",path.GetString(),name);	
			files.Add(StringId(buffer));
			if (filenameOnly==StringId(name))
				{
				fileIndex=i;
				}
			}
		}
	delete directory;

	float cel=0;

	Resource_BitmapStrip bitmap;
	Screen* screen=LoadImage(0,filename, bitmap, fullscreen);

	FrameTime frameTime;

	bool exitFlag=false;
	while (!exitFlag)
		{
		cel+=frameTime.Update()*5;
		DrawBackground(screen->GetBackBuffer());
		int x=(screen->GetBackBuffer().GetWidth()-bitmap.GetWidth((int)cel))/2;
		int y=(screen->GetBackBuffer().GetHeight()-bitmap.GetHeight((int)cel))/2;
		if (x>0 || y>0)
			{
			int w=screen->GetBackBuffer().GetWidth();
			int h=screen->GetBackBuffer().GetHeight();
			screen->GetBackBuffer().Fill(0,0,x,h,0);
			screen->GetBackBuffer().Fill(w-x,0,w,h,0);
			screen->GetBackBuffer().Fill(x,0,w-x,y,0);
			screen->GetBackBuffer().Fill(x,h-y,w-x,h,0);
			}
		bitmap.Blit((int)cel,screen->GetBackBuffer(),x,y);
		screen->Present();

		inputManager.Update();
		if (inputManager.WasKeyPressed(KEY_ESCAPE))
			{
			exitFlag=true;
			}
		if (inputManager.WasKeyPressed(KEY_SPACE))
			{
			fileIndex++;
			if (fileIndex>=files.GetItemCount())
				{
				fileIndex=0;
				}
			
			screen=LoadImage(screen, files.Get(fileIndex),bitmap, fullscreen);
			cel=0;
			}
		if (inputManager.WasKeyPressed(KEY_BACK))
			{
			fileIndex--;
			if (fileIndex<0)
				{
				fileIndex=files.GetItemCount()-1;
				}
			screen=LoadImage(screen,files.Get(fileIndex),bitmap,fullscreen);
			cel=0;
			}

		// Toggle between fullscreen and windowed mode on Alt+Enter
		if (inputManager.IsKeyDown(KEY_MENU) && inputManager.WasKeyPressed(KEY_RETURN))
			{
			fullscreen=!fullscreen;
			delete screen;
			screen=new Screen(screenWidth,screenHeight);
			screen->SetFullscreen(fullscreen);
			screen->SetInterpolationMode(false);
			screen=LoadImage(screen, files.Get(fileIndex),bitmap, fullscreen);
			inputManager.RestoreCursor();
			}

		
		if (Platform::GetPlatform_OS())
			{
			Platform::GetPlatform_OS()->OsYield();
			if (Platform::GetPlatform_OS()->ExitRequested())
				{
				exitFlag=true;
				}
			}

		}

	delete screen;
	}