@@ -156,9 +156,13 @@ bool graphicsLib::initGraphics()
156
156
return false ;
157
157
} else {
158
158
font = TTF_OpenFontRW (fileRW, 1 , FONT_SIZE);
159
+ // outline-font
160
+ outline_font = TTF_OpenFontRW (fileRW, 1 , FONT_SIZE);
161
+ TTF_SetFontOutline (outline_font, 1 );
159
162
}
160
163
delete[] buffer;
161
164
165
+
162
166
printf (" >> WII.DEBUG.INIT_GRAPHICS #3 <<\n " );
163
167
fflush (stdout);
164
168
@@ -937,27 +941,70 @@ void graphicsLib::draw_text(short x, short y, string text, st_color color)
937
941
if (text.length () <= 0 ) {
938
942
return ;
939
943
}
944
+
945
+ render_text (x, y, text, color, gameScreen, false );
946
+ }
947
+
948
+
949
+ void graphicsLib::draw_text (short x, short y, string text, graphicsLib_gSurface &surface)
950
+ {
951
+ render_text (x, y, text, st_color (255 , 255 , 255 ), surface, false );
952
+ }
953
+
954
+ void graphicsLib::draw_centered_text (short y, string text, st_color font_color)
955
+ {
956
+ draw_centered_text (y, text, gameScreen, font_color);
957
+ }
958
+
959
+ void graphicsLib::draw_centered_text (short y, string text)
960
+ {
961
+ draw_centered_text (y, text, gameScreen, st_color (TEXT_DEFAUL_COLOR_VALUE, TEXT_DEFAUL_COLOR_VALUE, TEXT_DEFAUL_COLOR_VALUE));
962
+ }
963
+
964
+ void graphicsLib::draw_centered_text (short y, string text, graphicsLib_gSurface &surface, st_color temp_font_color)
965
+ {
966
+ render_text (0 , y, text, temp_font_color, surface, true );
967
+ }
968
+
969
+ void graphicsLib::render_text (short x, short y, string text, st_color color, graphicsLib_gSurface &surface, bool centered)
970
+ {
971
+ SDL_Rect text_pos={x, y, 0 , 0 };
940
972
SDL_Color font_color = SDL_Color ();
941
973
font_color.r = color.r ;
942
974
font_color.g = color.g ;
943
975
font_color.b = color.b ;
944
976
x += _screen_resolution_adjust.x ;
945
977
y += _screen_resolution_adjust.y ;
946
- SDL_Rect text_pos={x, y, 0 , 0 };
978
+
947
979
if (!font) {
948
980
printf (" graphicsLib::draw_text - TTF_OpenFont: %s\n " , TTF_GetError ());
949
981
show_debug_msg (" EXIT #10" );
950
982
exception_manager::throw_file_not_found_exception (std::string (" graphicsLib::draw_text, fount is NULL" ), std::string (TTF_GetError ()));
951
983
// handle error
952
984
}
953
985
954
- // std::cout << "RENDER #1[" << text << "]" << std::endl;
955
- /*
956
- if (text.length() == 1) {
957
- std::cout << "DEBUG #9" << std::endl;
986
+ if (outline_font) {
987
+ SDL_Color black = {0 , 0 , 0 };
988
+ SDL_Surface* text_outlineSF = TTF_RenderUTF8_Solid (outline_font, text.c_str (), black);
989
+
990
+ if (text_outlineSF) {
991
+ SDL_Surface* text_outlineSF_format = SDL_DisplayFormat (text_outlineSF);
992
+ SDL_FreeSurface (text_outlineSF);
993
+
994
+ if (text_outlineSF_format) {
995
+ if (centered == true && text.size () > 0 ) {
996
+ text_pos.x = RES_W/2 - text_outlineSF_format->w /2 ;
997
+ }
998
+ SDL_BlitSurface (text_outlineSF_format, 0 , game_screen, &text_pos);
999
+ SDL_FreeSurface (text_outlineSF_format);
1000
+ }
1001
+ }
1002
+
958
1003
}
959
- */
960
1004
SDL_Surface* textSF = TTF_RenderUTF8_Solid (font, text.c_str (), font_color);
1005
+ if (centered == true && text.size () > 0 ) {
1006
+ text_pos.x = RES_W/2 - textSF->w /2 ;
1007
+ }
961
1008
962
1009
if (!textSF) {
963
1010
return ;
@@ -973,68 +1020,6 @@ void graphicsLib::draw_text(short x, short y, string text, st_color color)
973
1020
}
974
1021
975
1022
976
- void graphicsLib::draw_text (short x, short y, string text, graphicsLib_gSurface &surface)
977
- {
978
- SDL_Color font_color;
979
- font_color.r = 255 ;
980
- font_color.g = 255 ;
981
- font_color.b = 255 ;
982
- SDL_Rect text_pos={x, y, 0 , 0 };
983
- if (!font) {
984
- printf (" graphicsLib::draw_text - TTF_OpenFont: %s\n " , TTF_GetError ());
985
- show_debug_msg (" EXIT #11" );
986
- exception_manager::throw_file_not_found_exception (std::string (" graphicsLib::draw_text #2, fount is NULL" ), std::string (TTF_GetError ()));
987
- // handle error
988
- }
989
- text_pos.x += _screen_resolution_adjust.x ;
990
- text_pos.y += _screen_resolution_adjust.y ;
991
- // std::cout << "RENDER #2[" << text << "]" << std::endl;
992
- SDL_Surface* textSF = TTF_RenderUTF8_Solid (font, text.c_str (), font_color);
993
- SDL_Surface* textSF_format = SDL_DisplayFormat (textSF);
994
- SDL_FreeSurface (textSF);
995
- SDL_BlitSurface (textSF_format, 0 , surface.get_surface (), &text_pos);
996
- SDL_FreeSurface (textSF_format);
997
- }
998
-
999
- void graphicsLib::draw_centered_text (short y, string text, st_color font_color)
1000
- {
1001
- draw_centered_text (y, text, gameScreen, font_color);
1002
- }
1003
-
1004
- void graphicsLib::draw_centered_text (short y, string text)
1005
- {
1006
- draw_centered_text (y, text, gameScreen, st_color (TEXT_DEFAUL_COLOR_VALUE, TEXT_DEFAUL_COLOR_VALUE, TEXT_DEFAUL_COLOR_VALUE));
1007
- }
1008
-
1009
- void graphicsLib::draw_centered_text (short y, string text, graphicsLib_gSurface &surface, st_color temp_font_color)
1010
- {
1011
- SDL_Color font_color;
1012
- font_color.r = temp_font_color.r ;
1013
- font_color.g = temp_font_color.g ;
1014
- font_color.b = temp_font_color.b ;
1015
- SDL_Rect text_pos={0 , y, 0 , 0 };
1016
- if (!font) {
1017
- printf (" graphicsLib::draw_centered_text - TTF_OpenFont: %s\n " , TTF_GetError ());
1018
- show_debug_msg (" EXIT #12" );
1019
- exception_manager::throw_file_not_found_exception (std::string (" graphicsLib::draw_centered_text, fount is NULL" ), std::string (TTF_GetError ()));
1020
- }
1021
- SDL_Surface* textSF = TTF_RenderUTF8_Solid (font, text.c_str (), font_color);
1022
- if (textSF == NULL ) {
1023
- return ;
1024
- }
1025
- if (text.size () > 0 ) {
1026
- text_pos.x = RES_W/2 - textSF->w /2 ;
1027
- }
1028
- text_pos.y = y;
1029
- text_pos.x += _screen_resolution_adjust.x ;
1030
- text_pos.y += _screen_resolution_adjust.y ;
1031
- SDL_Surface* textSF_format = SDL_DisplayFormat (textSF);
1032
- SDL_FreeSurface (textSF);
1033
- SDL_BlitSurface (textSF_format, 0 , surface.get_surface (), &text_pos);
1034
- SDL_FreeSurface (textSF_format);
1035
- }
1036
-
1037
-
1038
1023
1039
1024
Uint8 graphicsLib::getColorNumber (Uint8 r, Uint8 g, Uint8 b) {
1040
1025
if (game_screen == NULL || game_screen->format == NULL ) {
0 commit comments