From: Ingo Ruhnke Date: Tue, 13 Apr 2004 12:25:22 +0000 (+0000) Subject: - converted text_type into a class X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=9e082fc66762cb43a25955a971082a0a5aab0840;p=supertux.git - converted text_type into a class SVN-Revision: 516 --- diff --git a/src/button.cpp b/src/button.cpp index 604229282..500471cca 100644 --- a/src/button.cpp +++ b/src/button.cpp @@ -105,13 +105,13 @@ void Button::draw() char str[80]; int i = -32; - if(0 > rect.x - (int)strlen(info.c_str()) * white_small_text.w) - i = rect.w + strlen(info.c_str()) * white_small_text.w; + if(0 > rect.x - (int)strlen(info.c_str()) * white_small_text->w) + i = rect.w + strlen(info.c_str()) * white_small_text->w; if(!info.empty()) - text_draw(&white_small_text, info.c_str(), i + rect.x - strlen(info.c_str()) * white_small_text.w, rect.y, 1); + white_small_text->draw(info.c_str(), i + rect.x - strlen(info.c_str()) * white_small_text->w, rect.y, 1); sprintf(str,"(%s)", SDL_GetKeyName(shortcut)); - text_draw(&white_small_text, str, i + rect.x - strlen(str) * white_small_text.w, rect.y + white_small_text.h+2, 1); + white_small_text->draw(str, i + rect.x - strlen(str) * white_small_text->w, rect.y + white_small_text->h+2, 1); } if(state == BUTTON_PRESSED) fillrect(rect.x,rect.y,rect.w,rect.h,75,75,75,200); diff --git a/src/gameloop.cpp b/src/gameloop.cpp index 8f637f4e6..e7113347b 100644 --- a/src/gameloop.cpp +++ b/src/gameloop.cpp @@ -137,16 +137,16 @@ GameSession::levelintro(void) clearscreen(0, 0, 0); sprintf(str, "LEVEL %d", levelnb); - text_drawf(&blue_text, str, 0, 200, A_HMIDDLE, A_TOP, 1); + blue_text->drawf(str, 0, 200, A_HMIDDLE, A_TOP, 1); sprintf(str, "%s", world->get_level()->name.c_str()); - text_drawf(&gold_text, str, 0, 224, A_HMIDDLE, A_TOP, 1); + gold_text->drawf(str, 0, 224, A_HMIDDLE, A_TOP, 1); sprintf(str, "by %s", world->get_level()->author.c_str()); - text_drawf(&gold_text, str, 0, 256, A_HMIDDLE, A_TOP, 1); + gold_text->drawf(str, 0, 256, A_HMIDDLE, A_TOP, 1); sprintf(str, "TUX x %d", tux.lives); - text_drawf(&white_text, str, 0, 288, A_HMIDDLE, A_TOP, 1); + white_text->drawf(str, 0, 288, A_HMIDDLE, A_TOP, 1); flipscreen(); @@ -449,7 +449,7 @@ GameSession::draw() fillrect(i % 2 ? (pause_menu_frame * i)%screen->w : -((pause_menu_frame * i)%screen->w) ,(i*20+pause_menu_frame)%screen->h,screen->w,10,20,20,20, rand() % 20 + 1); } fillrect(0,0,screen->w,screen->h,rand() % 50, rand() % 50, rand() % 50, 128); - text_drawf(&blue_text, "PAUSE - Press 'P' To Play", 0, 230, A_HMIDDLE, A_TOP, 1); + blue_text->drawf("PAUSE - Press 'P' To Play", 0, 230, A_HMIDDLE, A_TOP, 1); } if(show_menu) @@ -662,38 +662,38 @@ GameSession::drawstatus() char str[60]; sprintf(str, "%d", player_status.score); - text_draw(&white_text, "SCORE", 0, 0, 1); - text_draw(&gold_text, str, 96, 0, 1); + white_text->draw("SCORE", 0, 0, 1); + gold_text->draw(str, 96, 0, 1); if(st_gl_mode != ST_GL_TEST) { sprintf(str, "%d", hs_score); - text_draw(&white_text, "HIGH", 0, 20, 1); - text_draw(&gold_text, str, 96, 20, 1); + white_text->draw("HIGH", 0, 20, 1); + gold_text->draw(str, 96, 20, 1); } else { - text_draw(&white_text,"Press ESC To Return",0,20,1); + white_text->draw("Press ESC To Return",0,20,1); } if (time_left.get_left() > TIME_WARNING || (global_frame_counter % 10) < 5) { sprintf(str, "%d", time_left.get_left() / 1000 ); - text_draw(&white_text, "TIME", 224, 0, 1); - text_draw(&gold_text, str, 304, 0, 1); + white_text->draw("TIME", 224, 0, 1); + gold_text->draw(str, 304, 0, 1); } sprintf(str, "%d", player_status.distros); - text_draw(&white_text, "DISTROS", screen->h, 0, 1); - text_draw(&gold_text, str, 608, 0, 1); + white_text->draw("DISTROS", screen->h, 0, 1); + gold_text->draw(str, 608, 0, 1); - text_draw(&white_text, "LIVES", screen->h, 20, 1); + white_text->draw("LIVES", screen->h, 20, 1); if(show_fps) { sprintf(str, "%2.1f", fps_fps); - text_draw(&white_text, "FPS", screen->h, 40, 1); - text_draw(&gold_text, str, screen->h + 60, 40, 1); + white_text->draw("FPS", screen->h, 40, 1); + gold_text->draw(str, screen->h + 60, 40, 1); } for(int i= 0; i < tux.lives; ++i) @@ -709,13 +709,13 @@ GameSession::drawendscreen() clearscreen(0, 0, 0); - text_drawf(&blue_text, "GAMEOVER", 0, 200, A_HMIDDLE, A_TOP, 1); + blue_text->drawf("GAMEOVER", 0, 200, A_HMIDDLE, A_TOP, 1); sprintf(str, "SCORE: %d", player_status.score); - text_drawf(&gold_text, str, 0, 224, A_HMIDDLE, A_TOP, 1); + gold_text->drawf(str, 0, 224, A_HMIDDLE, A_TOP, 1); sprintf(str, "DISTROS: %d", player_status.distros); - text_drawf(&gold_text, str, 0, 256, A_HMIDDLE, A_TOP, 1); + gold_text->drawf(str, 0, 256, A_HMIDDLE, A_TOP, 1); flipscreen(); @@ -730,13 +730,13 @@ GameSession::drawresultscreen(void) clearscreen(0, 0, 0); - text_drawf(&blue_text, "Result:", 0, 200, A_HMIDDLE, A_TOP, 1); + blue_text->drawf("Result:", 0, 200, A_HMIDDLE, A_TOP, 1); sprintf(str, "SCORE: %d", player_status.score); - text_drawf(&gold_text, str, 0, 224, A_HMIDDLE, A_TOP, 1); + gold_text->drawf(str, 0, 224, A_HMIDDLE, A_TOP, 1); sprintf(str, "DISTROS: %d", player_status.distros); - text_drawf(&gold_text, str, 0, 256, A_HMIDDLE, A_TOP, 1); + gold_text->drawf(str, 0, 256, A_HMIDDLE, A_TOP, 1); flipscreen(); diff --git a/src/gameobjs.cpp b/src/gameobjs.cpp index f37bc2270..828c89fdb 100644 --- a/src/gameobjs.cpp +++ b/src/gameobjs.cpp @@ -177,7 +177,7 @@ FloatingScore::draw() { char str[10]; sprintf(str, "%d", value); - text_draw(&gold_text, str, (int)base.x + 16 - strlen(str) * 8, (int)base.y, 1); + gold_text->draw(str, (int)base.x + 16 - strlen(str) * 8, (int)base.y, 1); } /* EOF */ diff --git a/src/gameobjs.h b/src/gameobjs.h index 886589194..12fafaf81 100644 --- a/src/gameobjs.h +++ b/src/gameobjs.h @@ -87,4 +87,4 @@ class FloatingScore /* Local Variables: */ /* mode:c++ */ -/* End */ +/* End: */ diff --git a/src/globals.cpp b/src/globals.cpp index 335a0ee1e..cab93076d 100644 --- a/src/globals.cpp +++ b/src/globals.cpp @@ -16,7 +16,14 @@ std::string datadir; SDL_Surface * screen; -text_type black_text, gold_text, blue_text, red_text, yellow_nums, white_text, white_small_text, white_big_text; +Text* black_text; +Text* gold_text; +Text* blue_text; +Text* red_text; +Text* yellow_nums; +Text* white_text; +Text* white_small_text; +Text* white_big_text; MouseCursor * mouse_cursor; diff --git a/src/globals.h b/src/globals.h index 6ee3240bd..e205c5bf4 100644 --- a/src/globals.h +++ b/src/globals.h @@ -23,14 +23,14 @@ extern std::string datadir; extern SDL_Surface * screen; -extern text_type black_text; -extern text_type gold_text; -extern text_type white_text; -extern text_type white_small_text; -extern text_type white_big_text; -extern text_type blue_text; -extern text_type red_text; -extern text_type yellow_nums; +extern Text* black_text; +extern Text* gold_text; +extern Text* white_text; +extern Text* white_small_text; +extern Text* white_big_text; +extern Text* blue_text; +extern Text* red_text; +extern Text* yellow_nums; extern MouseCursor * mouse_cursor; diff --git a/src/high_scores.cpp b/src/high_scores.cpp index 27c011e75..73c339208 100644 --- a/src/high_scores.cpp +++ b/src/high_scores.cpp @@ -104,10 +104,10 @@ void save_hs(int score) { bkgd->draw_bg(); - text_drawf(&blue_text, "Congratulations", 0, 130, A_HMIDDLE, A_TOP, 2, NO_UPDATE); - text_draw(&blue_text, "Your score:", 150, 180, 1, NO_UPDATE); + blue_text->drawf("Congratulations", 0, 130, A_HMIDDLE, A_TOP, 2, NO_UPDATE); + blue_text->draw("Your score:", 150, 180, 1, NO_UPDATE); sprintf(str, "%d", hs_score); - text_draw(&yellow_nums, str, 350, 170, 1, NO_UPDATE); + yellow_nums->draw(str, 350, 170, 1, NO_UPDATE); menu_process_current(); flipscreen(); diff --git a/src/leveleditor.cpp b/src/leveleditor.cpp index 1db3721f8..e18011ddf 100644 --- a/src/leveleditor.cpp +++ b/src/leveleditor.cpp @@ -671,16 +671,16 @@ void le_drawinterface() le_tilemap_panel->draw(); sprintf(str, "%d/%d", le_level,le_level_subset.levels); - text_drawf(&white_text, str, -10, 16, A_RIGHT, A_TOP, 0); + white_text->drawf(str, -10, 16, A_RIGHT, A_TOP, 0); - text_draw(&white_small_text, "F1 for Help", 10, 430, 1); + white_small_text->draw("F1 for Help", 10, 430, 1); } else { if(show_menu == false) - text_draw(&white_small_text, "No Level Subset loaded - Press ESC and choose one in the menu", 10, 430, 1); + white_small_text->draw("No Level Subset loaded - Press ESC and choose one in the menu", 10, 430, 1); else - text_draw(&white_small_text, "No Level Subset loaded", 10, 430, 1); + white_small_text->draw("No Level Subset loaded", 10, 430, 1); } } @@ -949,9 +949,9 @@ void le_checkevents() char str[1024]; int d = 0; sprintf(str,"Level %d doesn't exist.",le_level+1); - text_drawf(&white_text,str,0,-18,A_HMIDDLE,A_VMIDDLE,2); - text_drawf(&white_text,"Do you want to create it?",0,0,A_HMIDDLE,A_VMIDDLE,2); - text_drawf(&red_text,"(Y)es/(N)o",0,20,A_HMIDDLE,A_VMIDDLE,2); + white_text->drawf(str,0,-18,A_HMIDDLE,A_VMIDDLE,2); + white_text->drawf("Do you want to create it?",0,0,A_HMIDDLE,A_VMIDDLE,2); + red_text->drawf("(Y)es/(N)o",0,20,A_HMIDDLE,A_VMIDDLE,2); flipscreen(); while(d == 0) { @@ -1246,12 +1246,12 @@ void le_showhelp() }; - text_drawf(&blue_text, "- Help -", 0, 30, A_HMIDDLE, A_TOP, 2); + blue_text->drawf("- Help -", 0, 30, A_HMIDDLE, A_TOP, 2); for(i = 0; i < sizeof(text)/sizeof(char *); i++) - text_draw(&white_text, text[i], 5, 80+(i*18), 1); + white_text->draw(text[i], 5, 80+(i*18), 1); - text_drawf(&gold_text, "Press Any Key to Continue", 0, 440, A_HMIDDLE, A_TOP, 1); + gold_text->drawf("Press Any Key to Continue", 0, 440, A_HMIDDLE, A_TOP, 1); flipscreen(); diff --git a/src/menu.cpp b/src/menu.cpp index 5a4900174..276f49fcf 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -359,7 +359,7 @@ Menu::draw_item(int index, // Position of the current item in the menu int text_width = strlen(pitem.text) * font_width; int input_width = strlen(pitem.input) * font_width; int list_width = strlen(string_list_active(pitem.list)) * font_width; - text_type* text_font = &white_text; + Text* text_font = white_text; if (arrange_left) x_pos += 24 - menu_width/2 + (text_width + input_width + list_width)/2; @@ -367,16 +367,16 @@ Menu::draw_item(int index, // Position of the current item in the menu if(index == active_item) { shadow_size = 3; - text_font = &blue_text; + text_font = blue_text; } switch (pitem.kind) { case MN_DEACTIVE: { - text_draw_align(&black_text, pitem.text, - x_pos, y_pos, - A_HMIDDLE, A_VMIDDLE, 2); + black_text->draw_align(pitem.text, + x_pos, y_pos, + A_HMIDDLE, A_VMIDDLE, 2); break; } @@ -395,9 +395,9 @@ Menu::draw_item(int index, // Position of the current item in the menu } case MN_LABEL: { - text_draw_align(&white_big_text, pitem.text, - x_pos, y_pos, - A_HMIDDLE, A_VMIDDLE, 2); + white_big_text->draw_align(pitem.text, + x_pos, y_pos, + A_HMIDDLE, A_VMIDDLE, 2); break; } case MN_TEXTFIELD: @@ -414,13 +414,13 @@ Menu::draw_item(int index, // Position of the current item in the menu input_width + font_width, 18, 0,0,0,128); - text_draw_align(&gold_text, pitem.input, - x_pos + text_pos, y_pos, - A_HMIDDLE, A_VMIDDLE, 2); + gold_text->draw_align(pitem.input, + x_pos + text_pos, y_pos, + A_HMIDDLE, A_VMIDDLE, 2); - text_draw_align(text_font, pitem.text, - x_pos - (input_width + font_width)/2, y_pos, - A_HMIDDLE, A_VMIDDLE, shadow_size); + text_font->draw_align(pitem.text, + x_pos - (input_width + font_width)/2, y_pos, + A_HMIDDLE, A_VMIDDLE, shadow_size); break; } case MN_STRINGSELECT: @@ -441,25 +441,25 @@ Menu::draw_item(int index, // Position of the current item in the menu list_pos_2, 18, 0,0,0,128); - text_draw_align(&gold_text, string_list_active(pitem.list), + gold_text->draw_align(string_list_active(pitem.list), x_pos + text_pos, y_pos, A_HMIDDLE, A_VMIDDLE,2); - text_draw_align(text_font, pitem.text, + text_font->draw_align(pitem.text, x_pos - list_pos_2/2, y_pos, A_HMIDDLE, A_VMIDDLE, shadow_size); break; } case MN_BACK: { - text_draw_align(text_font, pitem.text, x_pos, y_pos, A_HMIDDLE, A_VMIDDLE, shadow_size); + text_font->draw_align(pitem.text, x_pos, y_pos, A_HMIDDLE, A_VMIDDLE, shadow_size); back->draw( x_pos + text_width/2 + font_width, y_pos - 8); break; } case MN_TOGGLE: { - text_draw_align(text_font, pitem.text, x_pos, y_pos, A_HMIDDLE, A_VMIDDLE, shadow_size); + text_font->draw_align(pitem.text, x_pos, y_pos, A_HMIDDLE, A_VMIDDLE, shadow_size); if(pitem.toggled) checkbox_checked->draw( @@ -472,11 +472,11 @@ Menu::draw_item(int index, // Position of the current item in the menu break; } case MN_ACTION: - text_draw_align(text_font, pitem.text, x_pos, y_pos, A_HMIDDLE, A_VMIDDLE, shadow_size); + text_font->draw_align(pitem.text, x_pos, y_pos, A_HMIDDLE, A_VMIDDLE, shadow_size); break; case MN_GOTO: - text_draw_align(text_font, pitem.text, x_pos, y_pos, A_HMIDDLE, A_VMIDDLE, shadow_size); + text_font->draw_align(pitem.text, x_pos, y_pos, A_HMIDDLE, A_VMIDDLE, shadow_size); break; } } diff --git a/src/menu.h b/src/menu.h index 50d459d71..e8baf7018 100644 --- a/src/menu.h +++ b/src/menu.h @@ -142,4 +142,4 @@ void menu_process_current(void); /* Local Variables: */ /* mode: c++ */ -/* End */ +/* End: */ diff --git a/src/player.cpp b/src/player.cpp index 817c5ea4b..3b8400b54 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -729,7 +729,7 @@ Player::draw() } if(dying) - text_drawf(&gold_text,"Penguins can fly !:",0,0,A_HMIDDLE,A_VMIDDLE,1); + gold_text->drawf("Penguins can fly !:",0,0,A_HMIDDLE,A_VMIDDLE,1); if (debug_mode) fillrect(base.x - scroll_x, base.y, 32, 32, 75,75,75, 150); diff --git a/src/setup.cpp b/src/setup.cpp index 7751d23ca..bdfb2a4c3 100644 --- a/src/setup.cpp +++ b/src/setup.cpp @@ -573,14 +573,14 @@ void st_general_setup(void) /* Load global images: */ - text_load(&black_text, datadir + "/images/status/letters-black.png", TEXT_TEXT, 16,18); - text_load(&gold_text,datadir + "/images/status/letters-gold.png", TEXT_TEXT, 16,18); - text_load(&blue_text,datadir + "/images/status/letters-blue.png", TEXT_TEXT, 16,18); - text_load(&red_text,datadir + "/images/status/letters-red.png", TEXT_TEXT, 16,18); - text_load(&white_text,datadir + "/images/status/letters-white.png", TEXT_TEXT, 16,18); - text_load(&white_small_text,datadir + "/images/status/letters-white-small.png", TEXT_TEXT, 8,9); - text_load(&white_big_text,datadir + "/images/status/letters-white-big.png", TEXT_TEXT, 20,23); - text_load(&yellow_nums,datadir + "/images/status/numbers.png", TEXT_NUM, 32,32); + black_text = new Text(datadir + "/images/status/letters-black.png", TEXT_TEXT, 16,18); + gold_text = new Text(datadir + "/images/status/letters-gold.png", TEXT_TEXT, 16,18); + blue_text = new Text(datadir + "/images/status/letters-blue.png", TEXT_TEXT, 16,18); + red_text = new Text(datadir + "/images/status/letters-red.png", TEXT_TEXT, 16,18); + white_text = new Text(datadir + "/images/status/letters-white.png", TEXT_TEXT, 16,18); + white_small_text = new Text(datadir + "/images/status/letters-white-small.png", TEXT_TEXT, 8,9); + white_big_text = new Text(datadir + "/images/status/letters-white-big.png", TEXT_TEXT, 20,23); + yellow_nums = new Text(datadir + "/images/status/numbers.png", TEXT_NUM, 32,32); /* Load GUI/menu images: */ checkbox = new Surface(datadir + "/images/status/checkbox.png", USE_ALPHA); @@ -599,13 +599,13 @@ void st_general_free(void) /* Free global images: */ - text_free(&black_text); - text_free(&gold_text); - text_free(&white_text); - text_free(&blue_text); - text_free(&red_text); - text_free(&white_small_text); - text_free(&white_big_text); + delete black_text; + delete gold_text; + delete white_text; + delete blue_text; + delete red_text; + delete white_small_text; + delete white_big_text; /* Free GUI/menu images: */ delete checkbox; diff --git a/src/sprite.h b/src/sprite.h index 6b0254844..214b03656 100644 --- a/src/sprite.h +++ b/src/sprite.h @@ -57,4 +57,4 @@ class Sprite /* Local Variables: */ /* mode:c++ */ -/* End */ +/* End: */ diff --git a/src/text.cpp b/src/text.cpp index f095ab59b..ed873674a 100644 --- a/src/text.cpp +++ b/src/text.cpp @@ -17,8 +17,12 @@ #include "screen.h" #include "text.h" -void text_load(text_type* ptext, const std::string& file, int kind, int w, int h) +Text::Text(const std::string& file, int kind_, int w_, int h_) { + kind = kind_; + w = w_; + h = h_; + int mx, my; SDL_Surface *conv; int pixels; @@ -39,14 +43,11 @@ void text_load(text_type* ptext, const std::string& file, int kind, int w, int h mx = 0; my = 0; } - ptext->kind = kind; - ptext->w = w; - ptext->h = h; - ptext->chars = new Surface(file, USE_ALPHA); + chars = new Surface(file, USE_ALPHA); /* Load shadow font. */ - conv = SDL_DisplayFormatAlpha(ptext->chars->impl->sdl_surface); + conv = SDL_DisplayFormatAlpha(chars->impl->sdl_surface); pixels = conv->w * conv->h; SDL_LockSurface(conv); for(i = 0; i < pixels; ++i) @@ -56,51 +57,52 @@ void text_load(text_type* ptext, const std::string& file, int kind, int w, int h } SDL_UnlockSurface(conv); SDL_SetAlpha(conv, SDL_SRCALPHA, 128); - ptext->shadow_chars = new Surface(conv, USE_ALPHA); + shadow_chars = new Surface(conv, USE_ALPHA); SDL_FreeSurface(conv); } -void text_draw(text_type* ptext,const char* text, int x, int y, int shadowsize, int update) +void +Text::draw(const char* text, int x, int y, int shadowsize, int update) { if(text != NULL) { if(shadowsize != 0) - text_draw_chars(ptext, ptext->shadow_chars, text,x+shadowsize,y+shadowsize, update); + draw_chars(shadow_chars, text,x+shadowsize,y+shadowsize, update); - text_draw_chars(ptext, ptext->chars, text,x,y, update); + draw_chars(chars, text,x,y, update); } } -void text_draw_chars(text_type* ptext, Surface* pchars,const char* text, int x, int y, int update) +void +Text::draw_chars(Surface* pchars,const char* text, int x, int y, int update) { int i,j,len; - int w, h; len = strlen(text); - w = ptext->w; - h = ptext->h; + int w = this->w; + int h = this->h; - if(ptext->kind == TEXT_TEXT) + if(kind == TEXT_TEXT) { for( i = 0, j = 0; i < len; ++i,++j) { if( text[i] >= 'A' && text[i] <= 'Z') - pchars->draw_part((int)(text[i] - 'A')*w, 0, x+(j*w), y, ptext->w, ptext->h, 255, update); + pchars->draw_part((int)(text[i] - 'A')*w, 0, x+(j*w), y, w, h, 255, update); else if( text[i] >= 'a' && text[i] <= 'z') - pchars->draw_part((int)(text[i] - 'a')*w, h, x+(j*w), y, ptext->w, ptext->h, 255, update); + pchars->draw_part((int)(text[i] - 'a')*w, h, x+(j*w), y, w, h, 255, update); else if ( text[i] >= '!' && text[i] <= '9') - pchars->draw_part((int)(text[i] - '!')*w, h*2, x+(j*w), y, ptext->w, ptext->h, 255, update); + pchars->draw_part((int)(text[i] - '!')*w, h*2, x+(j*w), y, w, h, 255, update); else if ( text[i] == '?') - pchars->draw_part(25*w, h*2, x+(j*w), y, ptext->w, ptext->h, 255, update); + pchars->draw_part(25*w, h*2, x+(j*w), y, w, h, 255, update); else if ( text[i] == '\n') { - y += ptext->h + 2; + y += h + 2; j = 0; } } } - else if(ptext->kind == TEXT_NUM) + else if(kind == TEXT_NUM) { for( i = 0, j = 0; i < len; ++i, ++j) { @@ -108,25 +110,26 @@ void text_draw_chars(text_type* ptext, Surface* pchars,const char* text, int x, pchars->draw_part((int)(text[i] - '0')*w, 0, x+(j*w), y, w, h, 255, update); else if ( text[i] == '\n') { - y += ptext->h + 2; + y += h + 2; j = 0; } } } } -void text_draw_align(text_type* ptext, const char* text, int x, int y, - TextHAlign halign, TextVAlign valign, int shadowsize, int update) +void +Text::draw_align(const char* text, int x, int y, + TextHAlign halign, TextVAlign valign, int shadowsize, int update) { if(text != NULL) { switch (halign) { case A_RIGHT: - x += -(strlen(text)*ptext->w); + x += -(strlen(text)*w); break; case A_HMIDDLE: - x += -((strlen(text)*ptext->w)/2); + x += -((strlen(text)*w)/2); break; case A_LEFT: // default @@ -136,58 +139,60 @@ void text_draw_align(text_type* ptext, const char* text, int x, int y, switch (valign) { case A_BOTTOM: - y -= ptext->h; + y -= h; break; case A_VMIDDLE: - y -= ptext->h/2; + y -= h/2; case A_TOP: // default break; } - text_draw(ptext, text, x, y, shadowsize, update); + draw(text, x, y, shadowsize, update); } } -void text_drawf(text_type* ptext,const char* text, int x, int y, TextHAlign halign, TextVAlign valign, int shadowsize, int update) +void +Text::drawf(const char* text, int x, int y, + TextHAlign halign, TextVAlign valign, int shadowsize, int update) { if(text != NULL) { if(halign == A_RIGHT) /* FIXME: this doesn't work correctly for strings with newlines.*/ - x += screen->w - (strlen(text)*ptext->w); + x += screen->w - (strlen(text)*w); else if(halign == A_HMIDDLE) - x += screen->w/2 - ((strlen(text)*ptext->w)/2); + x += screen->w/2 - ((strlen(text)*w)/2); if(valign == A_BOTTOM) - y += screen->h - ptext->h; + y += screen->h - h; else if(valign == A_VMIDDLE) - y += screen->h/2 - ptext->h/2; + y += screen->h/2 - h/2; - text_draw(ptext,text,x,y,shadowsize, update); + draw(text,x,y,shadowsize, update); } } -void text_free(text_type* ptext) +Text::~Text() { - if(ptext->kind == TEXT_TEXT) - delete ptext->chars; - else if(ptext->kind == TEXT_NUM) - delete ptext->chars; + if(kind == TEXT_TEXT) + delete chars; + else if(kind == TEXT_NUM) + delete chars; } /* --- ERASE TEXT: --- */ -void erasetext(text_type* ptext,const char * text, int x, int y, Surface * ptexture, int update, int shadowsize) +void +Text::erasetext(const char * text, int x, int y, Surface * ptexture, int update, int shadowsize) { SDL_Rect dest; - dest.x = x; dest.y = y; - dest.w = strlen(text) * ptext->w + shadowsize; - dest.h = ptext->h; + dest.w = strlen(text) * w + shadowsize; + dest.h = h; if (dest.w > screen->w) dest.w = screen->w; @@ -201,7 +206,8 @@ void erasetext(text_type* ptext,const char * text, int x, int y, Surface * ptex /* --- ERASE CENTERED TEXT: --- */ -void erasecenteredtext(text_type* ptext,const char * text, int y, Surface * ptexture, int update, int shadowsize) +void +Text::erasecenteredtext(const char * text, int y, Surface * ptexture, int update, int shadowsize) { - erasetext(ptext, text, screen->w / 2 - (strlen(text) * 8), y, ptexture, update, shadowsize); + erasetext(text, screen->w / 2 - (strlen(text) * 8), y, ptexture, update, shadowsize); } diff --git a/src/text.h b/src/text.h index d6f52e1b0..fd4fde87b 100644 --- a/src/text.h +++ b/src/text.h @@ -15,15 +15,6 @@ #include "texture.h" -/* Text type */ -struct text_type -{ - Surface* chars; - Surface* shadow_chars; - int kind; - int w; - int h; -}; /* Kinds of texts. */ enum { @@ -43,14 +34,26 @@ enum TextVAlign { A_BOTTOM, }; -void text_load(text_type* ptext, const std::string& file, int kind, int w, int h); -void text_draw(text_type* ptext, const char* text, int x, int y, int shadowsize, int update = NO_UPDATE); -void text_draw_chars(text_type* ptext, Surface* pchars, const char* text, int x, int y, int update = NO_UPDATE); -void text_drawf(text_type* ptext, const char* text, int x, int y, TextHAlign halign, TextVAlign valign, int shadowsize, int update = NO_UPDATE); -void text_draw_align(text_type* ptext, const char* text, int x, int y, TextHAlign halign, TextVAlign valign, int shadowsize, int update = NO_UPDATE); -void text_free(text_type* ptext); -void erasetext(text_type* ptext, const char * text, int x, int y, Surface* surf, int update, int shadowsize); -void erasecenteredtext(text_type* ptext, const char * text, int y, Surface* surf, int update, int shadowsize); +/* Text type */ +class Text +{ + public: + Surface* chars; + Surface* shadow_chars; + int kind; + int w; + int h; + public: + Text(const std::string& file, int kind, int w, int h); + ~Text(); + + void draw(const char* text, int x, int y, int shadowsize, int update = NO_UPDATE); + void draw_chars(Surface* pchars, const char* text, int x, int y, int update = NO_UPDATE); + void drawf(const char* text, int x, int y, TextHAlign halign, TextVAlign valign, int shadowsize, int update = NO_UPDATE); + void draw_align(const char* text, int x, int y, TextHAlign halign, TextVAlign valign, int shadowsize, int update = NO_UPDATE); + void erasetext(const char * text, int x, int y, Surface* surf, int update, int shadowsize); + void erasecenteredtext(const char * text, int y, Surface* surf, int update, int shadowsize); +}; #endif /*SUPERTUX_TEXT_H*/ diff --git a/src/texture.h b/src/texture.h index 36567f5e3..cfac52e2e 100644 --- a/src/texture.h +++ b/src/texture.h @@ -95,4 +95,4 @@ private: /* Local Variables: */ /* mode: c++ */ -/* End */ +/* End: */ diff --git a/src/timer.h b/src/timer.h index b5cbf2c0a..1c450ba66 100644 --- a/src/timer.h +++ b/src/timer.h @@ -55,4 +55,4 @@ class Timer /* Local Variables: */ /* mode:c++ */ -/* End */ +/* End: */ diff --git a/src/title.cpp b/src/title.cpp index 0a8e2a2b2..01dacb0b6 100644 --- a/src/title.cpp +++ b/src/title.cpp @@ -300,7 +300,7 @@ bool title(void) if (current_menu == main_menu) logo->draw( 160, 30); - text_draw(&white_small_text, + white_small_text->draw( " SuperTux " VERSION "\n" "Copyright (c) 2003 SuperTux Devel Team\n" "This game comes with ABSOLUTELY NO WARRANTY. This is free software, and you\n" @@ -566,7 +566,7 @@ void display_credits() draw_background(); - text_drawf(&white_big_text, "- Credits -", 0, screen->h-scroll, A_HMIDDLE, A_TOP, 2); + white_big_text->drawf("- Credits -", 0, screen->h-scroll, A_HMIDDLE, A_TOP, 2); for(i = 0, n = 0, d = 0; i < length; i++,n++,d++) { @@ -575,13 +575,13 @@ void display_credits() else { if(names.item[i][0] == ' ') - text_drawf(&white_small_text, names.item[i], 0, 60+screen->h+(n*18)+(d*18)-scroll-10, A_HMIDDLE, A_TOP, 1); + white_small_text->drawf(names.item[i], 0, 60+screen->h+(n*18)+(d*18)-scroll-10, A_HMIDDLE, A_TOP, 1); else if(names.item[i][0] == ' ') - text_drawf(&white_text, names.item[i], 0, 60+screen->h+(n*18)+(d*18)-scroll, A_HMIDDLE, A_TOP, 1); + white_text->drawf(names.item[i], 0, 60+screen->h+(n*18)+(d*18)-scroll, A_HMIDDLE, A_TOP, 1); else if(names.item[i+1][0] == '-' || names.item[i][0] == '-') - text_drawf(&white_big_text, names.item[i], 0, 60+screen->h+(n*18)+(d*18)-scroll, A_HMIDDLE, A_TOP, 3); + white_big_text->drawf(names.item[i], 0, 60+screen->h+(n*18)+(d*18)-scroll, A_HMIDDLE, A_TOP, 3); else - text_drawf(&blue_text, names.item[i], 0, 60+screen->h+(n*18)+(d*18)-scroll, A_HMIDDLE, A_TOP, 1); + blue_text->drawf(names.item[i], 0, 60+screen->h+(n*18)+(d*18)-scroll, A_HMIDDLE, A_TOP, 1); } } diff --git a/src/world.h b/src/world.h index 5aa2700d8..a0d0b1934 100644 --- a/src/world.h +++ b/src/world.h @@ -117,5 +117,5 @@ extern World global_world; /* Local Variables: */ /* mode:c++ */ -/* End */ +/* End: */ diff --git a/src/worldmap.h b/src/worldmap.h index 2e728bb16..0dfc037e6 100644 --- a/src/worldmap.h +++ b/src/worldmap.h @@ -174,4 +174,4 @@ void worldmap_run(); /* Local Variables: */ /* mode:c++ */ -/* End */ +/* End: */