Refactor SpriteFont struct

Now it uses CharInfo data, this way, it's better aligned with the future
RRES file format data layout for sprite font characters.
This commit is contained in:
raysan5 2017-02-05 02:59:39 +01:00
parent a08117155d
commit 1a879ba08e
10 changed files with 164 additions and 144 deletions

View file

@ -29,8 +29,8 @@ int main()
Vector2 fontPosition;
fontPosition.x = screenWidth/2 - MeasureTextEx(fontBm, msgBm, fontBm.size, 0).x/2;
fontPosition.y = screenHeight/2 - fontBm.size/2 - 80;
fontPosition.x = screenWidth/2 - MeasureTextEx(fontBm, msgBm, fontBm.baseSize, 0).x/2;
fontPosition.y = screenHeight/2 - fontBm.baseSize/2 - 80;
SetTargetFPS(60);
//--------------------------------------------------------------------------------------
@ -49,8 +49,8 @@ int main()
ClearBackground(RAYWHITE);
DrawTextEx(fontBm, msgBm, fontPosition, fontBm.size, 0, MAROON);
DrawTextEx(fontTtf, msgTtf, (Vector2){ 75.0f, 240.0f }, fontTtf.size*0.8f, 2, LIME);
DrawTextEx(fontBm, msgBm, fontPosition, fontBm.baseSize, 0, MAROON);
DrawTextEx(fontTtf, msgTtf, (Vector2){ 75.0f, 240.0f }, fontTtf.baseSize*0.8f, 2, LIME);
EndDrawing();
//----------------------------------------------------------------------------------

View file

@ -45,10 +45,10 @@ int main()
ClearBackground(RAYWHITE);
DrawText("Font name: PixAntiqua", 40, 50, 20, GRAY);
DrawText(FormatText("Font base size: %i", font.size), 40, 80, 20, GRAY);
DrawText(FormatText("Font chars number: %i", font.numChars), 40, 110, 20, GRAY);
DrawText(FormatText("Font base size: %i", font.baseSize), 40, 80, 20, GRAY);
DrawText(FormatText("Font chars number: %i", font.charsCount), 40, 110, 20, GRAY);
DrawTextEx(font, msg, (Vector2){ 40, 180 }, font.size, 0, MAROON);
DrawTextEx(font, msg, (Vector2){ 40, 180 }, font.baseSize, 0, MAROON);
EndDrawing();
//----------------------------------------------------------------------------------

View file

@ -41,7 +41,7 @@ int main()
const char text[50] = "THIS is THE FONT you SELECTED!"; // Main text
Vector2 textSize = MeasureTextEx(fonts[currentFont], text, fonts[currentFont].size*3, 1);
Vector2 textSize = MeasureTextEx(fonts[currentFont], text, fonts[currentFont].baseSize*3, 1);
Vector2 mousePoint;
@ -118,7 +118,7 @@ int main()
}
// Text measurement for better positioning on screen
textSize = MeasureTextEx(fonts[currentFont], text, fonts[currentFont].size*3, 1);
textSize = MeasureTextEx(fonts[currentFont], text, fonts[currentFont].baseSize*3, 1);
//----------------------------------------------------------------------------------
// Draw
@ -140,7 +140,7 @@ int main()
DrawText("NEXT", 700, positionY + 13, 20, btnNextOutColor);
DrawTextEx(fonts[currentFont], text, (Vector2){ screenWidth/2 - textSize.x/2,
260 + (70 - textSize.y)/2 }, fonts[currentFont].size*3,
260 + (70 - textSize.y)/2 }, fonts[currentFont].baseSize*3,
1, colors[currentFont]);
EndDrawing();

View file

@ -50,8 +50,8 @@ int main()
for (int i = 0; i < 8; i++)
{
positions[i].x = screenWidth/2 - MeasureTextEx(fonts[i], messages[i], fonts[i].size*2, spacings[i]).x/2;
positions[i].y = 60 + fonts[i].size + 50*i;
positions[i].x = screenWidth/2 - MeasureTextEx(fonts[i], messages[i], fonts[i].baseSize*2, spacings[i]).x/2;
positions[i].y = 60 + fonts[i].baseSize + 50*i;
}
Color colors[8] = { MAROON, ORANGE, DARKGREEN, DARKBLUE, DARKPURPLE, LIME, GOLD };
@ -76,7 +76,7 @@ int main()
for (int i = 0; i < 8; i++)
{
DrawTextEx(fonts[i], messages[i], positions[i], fonts[i].size*2, spacings[i], colors[i]);
DrawTextEx(fonts[i], messages[i], positions[i], fonts[i].baseSize*2, spacings[i], colors[i]);
}
EndDrawing();

View file

@ -31,14 +31,14 @@ int main()
Vector2 fontPosition1, fontPosition2, fontPosition3;
fontPosition1.x = screenWidth/2 - MeasureTextEx(font1, msg1, font1.size, -3).x/2;
fontPosition1.y = screenHeight/2 - font1.size/2 - 80;
fontPosition1.x = screenWidth/2 - MeasureTextEx(font1, msg1, font1.baseSize, -3).x/2;
fontPosition1.y = screenHeight/2 - font1.baseSize/2 - 80;
fontPosition2.x = screenWidth/2 - MeasureTextEx(font2, msg2, font2.size, -2).x/2;
fontPosition2.y = screenHeight/2 - font2.size/2 - 10;
fontPosition2.x = screenWidth/2 - MeasureTextEx(font2, msg2, font2.baseSize, -2).x/2;
fontPosition2.y = screenHeight/2 - font2.baseSize/2 - 10;
fontPosition3.x = screenWidth/2 - MeasureTextEx(font3, msg3, font3.size, 2).x/2;
fontPosition3.y = screenHeight/2 - font3.size/2 + 50;
fontPosition3.x = screenWidth/2 - MeasureTextEx(font3, msg3, font3.baseSize, 2).x/2;
fontPosition3.y = screenHeight/2 - font3.baseSize/2 + 50;
//--------------------------------------------------------------------------------------
@ -56,9 +56,9 @@ int main()
ClearBackground(RAYWHITE);
DrawTextEx(font1, msg1, fontPosition1, font1.size, -3, WHITE);
DrawTextEx(font2, msg2, fontPosition2, font2.size, -2, WHITE);
DrawTextEx(font3, msg3, fontPosition3, font3.size, 2, WHITE);
DrawTextEx(font1, msg1, fontPosition1, font1.baseSize, -3, WHITE);
DrawTextEx(font2, msg2, fontPosition2, font2.baseSize, -2, WHITE);
DrawTextEx(font3, msg3, fontPosition3, font3.baseSize, 2, WHITE);
EndDrawing();
//----------------------------------------------------------------------------------

View file

@ -31,7 +31,7 @@ int main()
// NOTE: On 2D drawing it won't be noticeable, it looks like FILTER_BILINEAR
GenTextureMipmaps(&font.texture);
float fontSize = font.size;
float fontSize = font.baseSize;
Vector2 fontPosition = { 40, screenHeight/2 + 50 };
Vector2 textSize;