1313********************************************************************************************/
1414
1515#include < vector>
16+ #include < array>
1617
1718#include " raylib-cpp.hpp"
1819
@@ -29,7 +30,7 @@ int main() {
2930 raylib::Color textColor (DARKGRAY);
3031
3132 // NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
32- raylib::Font fonts[ MAX_FONTS] = {
33+ std::array< raylib::Font, MAX_FONTS> fonts = {
3334 raylib::Font (" resources/fonts/alagard.png" ),
3435 raylib::Font (" resources/fonts/pixelplay.png" ),
3536 raylib::Font (" resources/fonts/mecha.png" ),
@@ -40,22 +41,25 @@ int main() {
4041 raylib::Font (" resources/fonts/jupiter_crash.png" )
4142 };
4243
43- std::string messages[MAX_FONTS] = { " ALAGARD FONT designed by Hewett Tsoi" ,
44- " PIXELPLAY FONT designed by Aleksander Shevchuk" ,
45- " MECHA FONT designed by Captain Falcon" ,
46- " SETBACK FONT designed by Brian Kent (AEnigma)" ,
47- " ROMULUS FONT designed by Hewett Tsoi" ,
48- " PIXANTIQUA FONT designed by Gerhard Grossmann" ,
49- " ALPHA_BETA FONT designed by Brian Kent (AEnigma)" ,
50- " JUPITER_CRASH FONT designed by Brian Kent (AEnigma)" };
44+ std::array<std::string, MAX_FONTS> messages = {
45+ " ALAGARD FONT designed by Hewett Tsoi" ,
46+ " PIXELPLAY FONT designed by Aleksander Shevchuk" ,
47+ " MECHA FONT designed by Captain Falcon" ,
48+ " SETBACK FONT designed by Brian Kent (AEnigma)" ,
49+ " ROMULUS FONT designed by Hewett Tsoi" ,
50+ " PIXANTIQUA FONT designed by Gerhard Grossmann" ,
51+ " ALPHA_BETA FONT designed by Brian Kent (AEnigma)" ,
52+ " JUPITER_CRASH FONT designed by Brian Kent (AEnigma)"
53+ };
5154
52- const int spacings[ MAX_FONTS] = { 2 , 4 , 8 , 4 , 3 , 4 , 4 , 1 };
55+ std::array< int , MAX_FONTS> spacings = { 2 , 4 , 8 , 4 , 3 , 4 , 4 , 1 };
5356
54- Vector2 positions[ MAX_FONTS] ;
57+ std::array<raylib:: Vector2, MAX_FONTS> positions ;
5558
56- for (int i = 0 ; i < MAX_FONTS ; i++)
59+ for (int i = 0 ; i < fonts. size () ; i++)
5760 {
58- positions[i].x = screenWidth/2 - MeasureTextEx (fonts[i], messages[i].c_str (), fonts[i].baseSize *2 , spacings[i]).x /2 ;
61+ auto size = fonts[i].MeasureText (messages[i], fonts[i].baseSize * 2 , spacings[i]);
62+ positions[i].x = screenWidth/2 - size.x /2 ;
5963 positions[i].y = 60 + fonts[i].baseSize + 45 *i;
6064 }
6165
@@ -64,7 +68,7 @@ int main() {
6468 positions[4 ].y += 2 ;
6569 positions[7 ].y -= 8 ;
6670
67- raylib::Color colors[ MAX_FONTS] = { MAROON, ORANGE, DARKGREEN, DARKBLUE, DARKPURPLE, LIME, GOLD, RED };
71+ std::array< raylib::Color, MAX_FONTS> colors = { MAROON, ORANGE, DARKGREEN, DARKBLUE, DARKPURPLE, LIME, GOLD, RED };
6872 // --------------------------------------------------------------------------------------
6973
7074 // Main game loop
@@ -84,15 +88,14 @@ int main() {
8488 textColor.DrawText (" free fonts included with raylib" , 250 , 20 , 20 );
8589 textColor.DrawLine (220 , 50 , 590 , 50 );
8690
87- for (int i = 0 ; i < MAX_FONTS ; i++)
91+ for (int i = 0 ; i < fonts. size () ; i++)
8892 {
89- fonts[i].DrawText (messages[i]. c_str () , positions[i], fonts[i].baseSize *2 , spacings[i], colors[i]);
93+ fonts[i].DrawText (messages[i], positions[i], fonts[i].baseSize *2 , spacings[i], colors[i]);
9094 }
9195
9296 EndDrawing ();
9397 // ----------------------------------------------------------------------------------
9498 }
95- // --------------------------------------------------------------------------------------
9699
97100 return 0 ;
98101}
0 commit comments