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
Welcome to
LinuxQuestions.org , a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free.
Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please
contact us . If you need to reset your password,
click here .
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a
virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month.
Click here for more info.
08-11-2012, 11:50 AM
#1
Senior Member
Registered: Jun 2006
Location: UNIX
Distribution: FreeBSD
Posts: 2,657
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
All times are GMT -5. The time now is 07:50 AM .
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know .
Latest Threads
LQ News