From: Ricardo Cruz Date: Mon, 26 Apr 2004 14:15:49 +0000 (+0000) Subject: Improved the display_text_file(): moved to text.cpp and made it more independent. X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=8a7ddfdc1401bd7889bb482afd4fda2d3f7ac1e8;p=supertux.git Improved the display_text_file(): moved to text.cpp and made it more independent. I wasn't able to test it, since the game crashes because of: � LispReader: File not found: /home/rick2/.supertux/save/slot1.stsg Error: aborting � SVN-Revision: 747 --- diff --git a/src/setup.cpp b/src/setup.cpp index 4bfd9c30b..3826f3ff0 100644 --- a/src/setup.cpp +++ b/src/setup.cpp @@ -55,8 +55,6 @@ #include "player.h" -void display_text_file(char *filename); - #ifdef WIN32 #define mkdir(dir, mode) mkdir(dir) // on win32 we typically don't want LFS paths @@ -498,7 +496,7 @@ bool process_load_game_menu() if (access(slotfile, F_OK) != 0) { - display_text_file("intro.txt"); + display_text_file("intro.txt", "images/background/arctis2.jpg"); } WorldMapNS::WorldMap worldmap; diff --git a/src/text.cpp b/src/text.cpp index aa5581fa5..0b90e03a6 100644 --- a/src/text.cpp +++ b/src/text.cpp @@ -219,3 +219,147 @@ Text::erasecenteredtext(const char * text, int y, Surface * ptexture, int updat { erasetext(text, screen->w / 2 - (strlen(text) * 8), y, ptexture, update, shadowsize); } + + +/* --- SCROLL TEXT FUNCTION --- */ + +#define MAX_VEL 10 +#define SPEED 1 +#define SCROLL 60 +#define ITEMS_SPACE 4 + +void display_text_file(char *file, char* surface) +{ +Surface* sur = new Surface(datadir + surface, IGNORE_ALPHA); +display_text_file(file, sur); +delete sur; +} + +void display_text_file(char *file, Surface* surface) +{ + int done; + int scroll, speed; + int y; + int length; + FILE* fi; + char temp[1024]; + string_list_type names; + char filename[1024]; + string_list_init(&names); + sprintf(filename,"%s/%s", datadir.c_str(), file); + if((fi = fopen(filename,"r")) != NULL) + { + while(fgets(temp, sizeof(temp), fi) != NULL) + { + temp[strlen(temp)-1]='\0'; + string_list_add_item(&names,temp); + } + fclose(fi); + } + else + { + string_list_add_item(&names,"File was not found!"); + string_list_add_item(&names,filename); + string_list_add_item(&names,"Shame on the guy, who"); + string_list_add_item(&names,"forgot to include it"); + string_list_add_item(&names,"in your SuperTux distribution."); + } + + + scroll = 0; + speed = 2; + done = 0; + + length = names.num_items; + + SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); + + while(done == 0) + { + /* in case of input, exit */ + SDL_Event event; + while(SDL_PollEvent(&event)) + switch(event.type) + { + case SDL_KEYDOWN: + switch(event.key.keysym.sym) + { + case SDLK_UP: + speed -= SPEED; + break; + case SDLK_DOWN: + speed += SPEED; + break; + case SDLK_SPACE: + case SDLK_RETURN: + if(speed >= 0) + scroll += SCROLL; + break; + case SDLK_ESCAPE: + done = 1; + break; + default: + break; + } + break; + case SDL_QUIT: + done = 1; + break; + default: + break; + } + + if(speed > MAX_VEL) + speed = MAX_VEL; + else if(speed < -MAX_VEL) + speed = -MAX_VEL; + + /* draw the credits */ + + surface->draw_bg(); + + if (strcmp(file, "CREDITS") == 0) + white_big_text->drawf("- SuperTux " VERSION " -", + 0, screen->h-scroll, A_HMIDDLE, A_TOP, 2); + + y = 0; + for(int i = 0; i < length; i++) + { + switch(names.item[i][0]) + { + case ' ': + white_small_text->drawf(names.item[i], 0, 60+screen->h+y-scroll, A_HMIDDLE, A_TOP, 1); + y += white_small_text->h+ITEMS_SPACE; + break; + case ' ': + white_text->drawf(names.item[i], 0, 60+screen->h+y-scroll, A_HMIDDLE, A_TOP, 1); + y += white_text->h+ITEMS_SPACE; + break; + case '-': + white_big_text->drawf(names.item[i], 0, 60+screen->h+y-scroll, A_HMIDDLE, A_TOP, 3); + y += white_big_text->h+ITEMS_SPACE; + break; + default: + blue_text->drawf(names.item[i], 0, 60+screen->h+y-scroll, A_HMIDDLE, A_TOP, 1); + y += blue_text->h+ITEMS_SPACE; + break; + } + } + + flipscreen(); + + if(60+screen->h+y-scroll < 0 && 20+60+screen->h+y-scroll < 0) + done = 1; + + scroll += speed; + if(scroll < 0) + scroll = 0; + + SDL_Delay(35); + } + string_list_free(&names); + + SDL_EnableKeyRepeat(0, 0); // disables key repeating + Menu::set_current(main_menu); +} + diff --git a/src/text.h b/src/text.h index c5728cc5d..6a02999b2 100644 --- a/src/text.h +++ b/src/text.h @@ -23,6 +23,8 @@ #include "texture.h" +void display_text_file(char *file, char* surface); +void display_text_file(char *file, Surface* surface); /* Kinds of texts. */ enum { diff --git a/src/title.cpp b/src/title.cpp index 8ac877171..0bc1248ba 100644 --- a/src/title.cpp +++ b/src/title.cpp @@ -62,8 +62,6 @@ static int frame; static unsigned int last_update_time; static unsigned int update_time; -void display_text_file(char *filename); - std::vector contrib_subsets; std::string current_contrib_subset; @@ -315,7 +313,7 @@ void title(void) Menu::set_current(main_menu); break; case MNID_CREDITS: - display_text_file("CREDITS"); + display_text_file("CREDITS", bkg_title); Menu::set_current(main_menu); break; case MNID_QUITMAINMENU: @@ -366,144 +364,3 @@ void title(void) delete logo; } -#define MAX_VEL 10 -#define SPEED 1 -#define SCROLL 60 -#define ITEMS_SPACE 4 - -void display_text_file(char *file) -{ - int done; - int scroll, speed; - int y; - Timer timer; - int length; - FILE* fi; - char temp[1024]; - string_list_type names; - char filename[1024]; - string_list_init(&names); - sprintf(filename,"%s/%s", datadir.c_str(), file); - if((fi = fopen(filename,"r")) != NULL) - { - while(fgets(temp, sizeof(temp), fi) != NULL) - { - temp[strlen(temp)-1]='\0'; - string_list_add_item(&names,temp); - } - fclose(fi); - } - else - { - string_list_add_item(&names,"Credits were not found!"); - string_list_add_item(&names,"Shame on the guy, who"); - string_list_add_item(&names,"forgot to include them"); - string_list_add_item(&names,"in your SuperTux distribution."); - } - - - timer.init(SDL_GetTicks()); - timer.start(50); - - scroll = 0; - speed = 2; - done = 0; - - length = names.num_items; - - SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); - - while(done == 0) - { - /* in case of input, exit */ - SDL_Event event; - while(SDL_PollEvent(&event)) - switch(event.type) - { - case SDL_KEYDOWN: - switch(event.key.keysym.sym) - { - case SDLK_UP: - speed -= SPEED; - break; - case SDLK_DOWN: - speed += SPEED; - break; - case SDLK_SPACE: - case SDLK_RETURN: - if(speed >= 0) - scroll += SCROLL; - break; - case SDLK_ESCAPE: - done = 1; - break; - default: - break; - } - break; - case SDL_QUIT: - done = 1; - break; - default: - break; - } - - if(speed > MAX_VEL) - speed = MAX_VEL; - else if(speed < -MAX_VEL) - speed = -MAX_VEL; - - /* draw the credits */ - - draw_background(); - - if (strcmp(file, "CREDITS") == 0) - white_big_text->drawf("- SuperTux " VERSION " -", - 0, screen->h-scroll, A_HMIDDLE, A_TOP, 2); - - y = 0; - for(int i = 0; i < length; i++) - { - switch(names.item[i][0]) - { - case ' ': - white_small_text->drawf(names.item[i], 0, 60+screen->h+y-scroll, A_HMIDDLE, A_TOP, 1); - y += white_small_text->h+ITEMS_SPACE; - break; - case ' ': - white_text->drawf(names.item[i], 0, 60+screen->h+y-scroll, A_HMIDDLE, A_TOP, 1); - y += white_text->h+ITEMS_SPACE; - break; - case '-': - white_big_text->drawf(names.item[i], 0, 60+screen->h+y-scroll, A_HMIDDLE, A_TOP, 3); - y += white_big_text->h+ITEMS_SPACE; - break; - default: - blue_text->drawf(names.item[i], 0, 60+screen->h+y-scroll, A_HMIDDLE, A_TOP, 1); - y += blue_text->h+ITEMS_SPACE; - break; - } - } - - flipscreen(); - - if(60+screen->h+y-scroll < 0 && 20+60+screen->h+y-scroll < 0) - done = 1; - - scroll += speed; - if(scroll < 0) - scroll = 0; - - SDL_Delay(35); - - if(timer.get_left() < 0) - { - frame++; - timer.start(50); - } - } - string_list_free(&names); - - SDL_EnableKeyRepeat(0, 0); // disables key repeating - Menu::set_current(main_menu); -}