[Super-tux-commit] supertux/src setup.cpp,1.59,1.60 text.cpp,1.11,1.12 text.h,1.12,1.13 title.cpp,1.
Brought to you by:
wkendrick
From: Ricardo C. <rm...@us...> - 2004-04-26 14:15:59
|
Update of /cvsroot/super-tux/supertux/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21547/src Modified Files: setup.cpp text.cpp text.h title.cpp Log Message: 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 » Index: text.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/text.cpp,v retrieving revision 1.11 retrieving revision 1.12 diff -u -d -r1.11 -r1.12 --- text.cpp 25 Apr 2004 21:55:39 -0000 1.11 +++ text.cpp 26 Apr 2004 14:15:48 -0000 1.12 @@ -219,3 +219,147 @@ { 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); +} + Index: title.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/title.cpp,v retrieving revision 1.62 retrieving revision 1.63 diff -u -d -r1.62 -r1.63 --- title.cpp 26 Apr 2004 13:00:56 -0000 1.62 +++ title.cpp 26 Apr 2004 14:15:49 -0000 1.63 @@ -62,8 +62,6 @@ static unsigned int last_update_time; static unsigned int update_time; -void display_text_file(char *filename); - std::vector<st_subset> contrib_subsets; std::string current_contrib_subset; @@ -315,7 +313,7 @@ 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 @@ 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); -} Index: setup.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/setup.cpp,v retrieving revision 1.59 retrieving revision 1.60 diff -u -d -r1.59 -r1.60 --- setup.cpp 26 Apr 2004 12:21:22 -0000 1.59 +++ setup.cpp 26 Apr 2004 14:15:48 -0000 1.60 @@ -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 @@ if (access(slotfile, F_OK) != 0) { - display_text_file("intro.txt"); + display_text_file("intro.txt", "images/background/arctis2.jpg"); } WorldMapNS::WorldMap worldmap; Index: text.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/text.h,v retrieving revision 1.12 retrieving revision 1.13 diff -u -d -r1.12 -r1.13 --- text.h 20 Apr 2004 11:09:34 -0000 1.12 +++ text.h 26 Apr 2004 14:15:48 -0000 1.13 @@ -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 { |