Add new functions, update C sources

This commit is contained in:
Milan Nikolic 2017-03-10 15:01:42 +01:00
parent 1aabddd935
commit 732563d5c2
19 changed files with 541 additions and 647 deletions

View file

@ -1,14 +1,22 @@
/**********************************************************************************************
*
* raylib.text
* raylib.text - Basic functions to load SpriteFonts and draw Text
*
* Basic functions to load SpriteFonts and draw Text
* CONFIGURATION:
*
* External libs:
* #define SUPPORT_FILEFORMAT_FNT
* #define SUPPORT_FILEFORMAT_TTF / INCLUDE_STB_TRUETYPE
* #define SUPPORT_FILEFORMAT_IMAGE_FONT
* Selected desired fileformats to be supported for loading. Some of those formats are
* supported by default, to remove support, just comment unrequired #define in this module
*
* #define INCLUDE_DEFAULT_FONT / SUPPORT_DEFAULT_FONT
*
* DEPENDENCIES:
* stb_truetype - Load TTF file and rasterize characters data
*
* Module Configuration Flags:
* ...
*
* LICENSE: zlib/libpng
*
* Copyright (c) 2014-2016 Ramon Santamaria (@raysan5)
*
@ -262,30 +270,28 @@ SpriteFont LoadSpriteFont(const char *fileName)
else if (strcmp(GetExtension(fileName),"rres") == 0)
{
// TODO: Read multiple resource blocks from file (RRES_FONT_IMAGE, RRES_FONT_CHARDATA)
RRESData rres = LoadResource(fileName);
RRES rres = LoadResource(fileName, 0);
// Load sprite font texture
/*
if (rres.type == RRES_FONT_IMAGE)
if (rres[0].type == RRES_TYPE_FONT_IMAGE)
{
// NOTE: Parameters for RRES_FONT_IMAGE type are: width, height, format, mipmaps
Image image = LoadImagePro(rres.data, rres.param1, rres.param2, rres.param3);
Image image = LoadImagePro(rres[0].data, rres[0].param1, rres[0].param2, rres[0].param3);
spriteFont.texture = LoadTextureFromImage(image);
UnloadImage(image);
}
// Load sprite characters data
if (rres.type == RRES_FONT_CHARDATA)
if (rres[1].type == RRES_TYPE_FONT_CHARDATA)
{
// NOTE: Parameters for RRES_FONT_CHARDATA type are: fontSize, charsCount
spriteFont.baseSize = rres.param1;
spriteFont.charsCount = rres.param2;
spriteFont.chars = rres.data;
spriteFont.baseSize = rres[1].param1;
spriteFont.charsCount = rres[1].param2;
spriteFont.chars = rres[1].data;
}
*/
// TODO: Do not free rres.data memory (chars info data!)
UnloadResource(rres);
//UnloadResource(rres[0]);
}
else
{
@ -525,8 +531,22 @@ Vector2 MeasureTextEx(SpriteFont spriteFont, const char *text, float fontSize, i
// NOTE: Uses default font
void DrawFPS(int posX, int posY)
{
// NOTE: We are rendering fps every second for better viewing on high framerates
static int fps = 0;
static int counter = 0;
static int refreshRate = 20;
if (counter < refreshRate) counter++;
else
{
fps = GetFPS();
refreshRate = fps;
counter = 0;
}
// NOTE: We have rounding errors every frame, so it oscillates a lot
DrawText(FormatText("%2i FPS", GetFPS()), posX, posY, 20, LIME);
DrawText(FormatText("%2i FPS", fps), posX, posY, 20, LIME);
}
//----------------------------------------------------------------------------------