LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-11-2012, 11:50 AM   #1
Xeratul
Senior Member
 
Registered: Jun 2006
Location: UNIX
Distribution: FreeBSD
Posts: 2,657

Rep: Reputation: 255Reputation: 255Reputation: 255
Basic file browser in SDL fullscreen?


Basic file browser in fullscreen

Hi,

I would be pleased if you could tell how to appear the files of pwd on this code if pos.


thx

Code:
/*This source code copyrighted by Lazy Foo' Productions (2004-2009) and may not
  be redestributed without written permission.*/

// How to : 
// clear ; sh run.sh test_solo01.cpp 

// found most help at : http://subversion.assembla.com/svn/7542TallerdeProgramacion/Programitas%20(robados%20-%20SDL)/lesson14%20-%20Actualiza%20la%20pantalla/





//The headers
#include "SDL/SDL.h"
#include "SDL/SDL_image.h"
#include "SDL/SDL_ttf.h"
#include <string>



//Screen attributes
const int SCREEN_WIDTH = 640;
const int SCREEN_HEIGHT = 480;
const int SCREEN_BPP = 32;

//The frames per second
const int FRAMES_PER_SECOND = 20;

//The surfaces
SDL_Surface *background = NULL;
SDL_Surface *message = NULL;
SDL_Surface *messagetwo = NULL;
SDL_Surface *imagethumb = NULL;
SDL_Surface *screen = NULL;

//The event structure
SDL_Event event;

//The font
TTF_Font *font = NULL;

//The color of the font
SDL_Color textColor = { 255, 0, 255 };







bool init()
{
	//Initialize all SDL subsystems
	if( SDL_Init( SDL_INIT_EVERYTHING ) == -1 )
	{	
		return false; 
	}

	//Set up the screen
	//screen = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE );


	screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, 0, SDL_DOUBLEBUF | SDL_ANYFORMAT | SDL_FULLSCREEN);



	//If there was an error in setting up the screen
	if( screen == NULL ) 
	{

		return false;
	}

	//Initialize SDL_ttf
	if( TTF_Init() == -1 )
	{
		return false;
	}

	//Set the window caption
	// this is not the text
	SDL_WM_SetCaption( "Hello World ", NULL );

	//If everything initialized fine
	return true;
}







SDL_Surface *load_image( std::string filename )
{
	//The image that's loaded
	SDL_Surface* loadedImage = NULL;

	//The optimized surface that will be used
	SDL_Surface* optimizedImage = NULL;

	//Load the image
	loadedImage = IMG_Load( filename.c_str() );

	//If the image loaded
	if( loadedImage != NULL )
	{
		//Create an optimized surface
		optimizedImage = SDL_DisplayFormat( loadedImage );

		//Free the old surface
		SDL_FreeSurface( loadedImage );

		//If the surface was optimized
		if( optimizedImage != NULL )
		{
			//Color key surface
			// SDL_SetColorKey( optimizedImage, SDL_SRCCOLORKEY, SDL_MapRGB( optimizedImage->format, 0, 0xFF, 0xFF ) );

			//SDL_SetColorKey( bitmap, SDL_SRCCOLORKEY, SDL_MapRGB(optimizedImage->format, 255, 0, 255) );
			SDL_SetColorKey( optimizedImage, SDL_SRCCOLORKEY, SDL_MapRGB(optimizedImage->format, 155, 100, 100) );
		}
	}




	//Return the optimized surface
	return optimizedImage;
}








bool load_files()
{
	//Load the background image
	background = load_image( "background.png" );


	imagethumb = load_image( "hello.bmp" );


	//Open the font
	font = TTF_OpenFont( "lazy.ttf", 14 );

	//If there was a problem in loading the background
	if( background == NULL )
	{
		return false;
	}

	//If there was an error in loading the font
	if( font == NULL )
	{
		return false;
	}

	//If everything loaded fine
	return true;
}





/* here it is for the background green   */
void apply_surface( int x, int y, SDL_Surface* source, SDL_Surface* destination, SDL_Rect* clip = NULL )
{
	//Holds offsets
	SDL_Rect offset;

	//Get offsets
	offset.x = x;
	offset.y = y;

	//Blit
	SDL_BlitSurface( source, clip, destination, &offset );
}




void clean_up()
{
	//Free the surfaces
	SDL_FreeSurface( background );
	SDL_FreeSurface( message );
	SDL_FreeSurface( messagetwo );
	SDL_FreeSurface( imagethumb );

	//Close the font
	TTF_CloseFont( font );

	//Quit SDL_ttf
	TTF_Quit();

	//Quit SDL
	SDL_Quit();
}







int main( int argc, char* args[] )
{

	SDL_Event event;
	int game_score,game_done;


	//Quit flag
	bool quit = false;

	//Keep track of the current frame
	int frame = 0;

	//Whether or not to cap the frame rate
	bool cap = true;




	//Initialize
	if( init() == false )
	{
		return 1;
	}

	//Load the files
	if( load_files() == false )
	{
		return 1;
	}

	//Generate the message surface
	message = TTF_RenderText_Solid( font, "Hello World", textColor );







	//Apply the background
	apply_surface( 10, 0, background, screen );

	//Apply the message
	// apply_surface( ( SCREEN_WIDTH - message->w ) / 2, ( ( SCREEN_HEIGHT + message->h * 2 ) / FRAMES_PER_SECOND ) * ( frame % FRAMES_PER_SECOND ) - message->h, message, screen );

	apply_surface( 50,100,message,screen);
	apply_surface( 50,150,message,screen);

	//Update the screen
	if( SDL_Flip( screen ) == -1 )
	{
		return 1;
	}













	/* Main menu loop. */
	game_done = 0;
	while (! game_done) {

		/* Poll for user input. */
		if (SDL_PollEvent(&event) == 1) {
			switch(event.type) {
				case SDL_QUIT:
					game_done = 1;
					break;

				case SDL_KEYDOWN:
					switch (event.key.keysym.sym) {
						case SDLK_q:
							game_done = 1;
							break;




						case SDLK_w:
							messagetwo = TTF_RenderText_Solid( font, "Monsieur ", textColor );
							apply_surface( 50,350,messagetwo,screen);
							//Update the screen
							if( SDL_Flip( screen ) == -1 )
							{
								return 1;
							}
							break;


						case SDLK_i:
							apply_surface( 0, 240, imagethumb, screen );
							//Update the screen
							if( SDL_Flip( screen ) == -1 )
							{
								return 1;
							}
							break; 




						case SDLK_m:
							messagetwo = TTF_RenderText_Solid( font, "Monsieur Atari", textColor );
							apply_surface( 50,350,messagetwo,screen);
							//Update the screen
							if( SDL_Flip( screen ) == -1 )
							{
								return 1;
							}
							break;


						case SDLK_r:
							//Free the surfaces
							//SDL_FreeSurface( imagethumb );
							//Update the screen
							if( SDL_Flip( screen ) == -1 )
							{
								return 1;
							}
							break;




						case SDLK_s:
							apply_surface( 50,250,message,screen);
							//Update the screen
							if( SDL_Flip( screen ) == -1 )
							{
								return 1;
							}
							break;




						default:
							break;
					}
					break;

				default:
					continue;
			}
		}
	}








	//Clean up
	clean_up();

	return 0;
}



// fin
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
can't get fullscreen for sdl games mark_alfred Linux - Games 1 01-16-2012 04:31 PM
Games fullscreen is distorted, but video fullscreen is fine - older laptop xmrkite Linux - Software 7 07-20-2009 11:40 AM
Trying to program an SDL application but cannot find the SDL.h file:SuSE 9.2&KDevelop pujolasdf Linux - Newbie 4 03-13-2005 07:50 AM
fullscreen (SDL?) problems (stretchy/blurry fading/blank) taids Linux - Software 4 11-08-2004 01:59 AM
SDL-Quake, Segmentation fault, Fullscreen and LAN-problems... Jonthebest Linux - Software 0 09-13-2003 10:45 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:50 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration