[text] Consider characters padding -WIP- #1432
This commit is contained in:
parent
c222e231f0
commit
55dc8171f8
2 changed files with 12 additions and 1 deletions
|
@ -277,6 +277,7 @@ typedef struct CharInfo {
|
||||||
typedef struct Font {
|
typedef struct Font {
|
||||||
int baseSize; // Base size (default chars height)
|
int baseSize; // Base size (default chars height)
|
||||||
int charsCount; // Number of characters
|
int charsCount; // Number of characters
|
||||||
|
//int charsPadding; // Padding around the chars
|
||||||
Texture2D texture; // Characters texture atlas
|
Texture2D texture; // Characters texture atlas
|
||||||
Rectangle *recs; // Characters rectangles in texture
|
Rectangle *recs; // Characters rectangles in texture
|
||||||
CharInfo *chars; // Characters info data
|
CharInfo *chars; // Characters info data
|
||||||
|
|
12
src/text.c
12
src/text.c
|
@ -302,6 +302,9 @@ Font LoadFont(const char *fileName)
|
||||||
#ifndef FONT_TTF_DEFAULT_FIRST_CHAR
|
#ifndef FONT_TTF_DEFAULT_FIRST_CHAR
|
||||||
#define FONT_TTF_DEFAULT_FIRST_CHAR 32 // TTF font generation default first char for image sprite font (32-Space)
|
#define FONT_TTF_DEFAULT_FIRST_CHAR 32 // TTF font generation default first char for image sprite font (32-Space)
|
||||||
#endif
|
#endif
|
||||||
|
#ifndef FONT_TTF_DEFAULT_CHARS_PADDING
|
||||||
|
#define FONT_TTF_DEFAULT_CHARS_PADDING 4 // TTF font generation default chars padding
|
||||||
|
#endif
|
||||||
|
|
||||||
Font font = { 0 };
|
Font font = { 0 };
|
||||||
|
|
||||||
|
@ -492,7 +495,9 @@ Font LoadFontFromMemory(const char *fileType, const unsigned char *fileData, int
|
||||||
|
|
||||||
if (font.chars != NULL)
|
if (font.chars != NULL)
|
||||||
{
|
{
|
||||||
Image atlas = GenImageFontAtlas(font.chars, &font.recs, font.charsCount, font.baseSize, 2, 0);
|
font.charsPadding = FONT_TTF_DEFAULT_CHARS_PADDING;
|
||||||
|
|
||||||
|
Image atlas = GenImageFontAtlas(font.chars, &font.recs, font.charsCount, font.baseSize, FONT_TTF_DEFAULT_CHARS_PADDING, 0);
|
||||||
font.texture = LoadTextureFromImage(atlas);
|
font.texture = LoadTextureFromImage(atlas);
|
||||||
|
|
||||||
// Update chars[i].image to use alpha, required to be used on ImageDrawText()
|
// Update chars[i].image to use alpha, required to be used on ImageDrawText()
|
||||||
|
@ -876,6 +881,11 @@ void DrawTextEx(Font font, const char *text, Vector2 position, float fontSize, f
|
||||||
font.recs[index].width*scaleFactor,
|
font.recs[index].width*scaleFactor,
|
||||||
font.recs[index].height*scaleFactor };
|
font.recs[index].height*scaleFactor };
|
||||||
|
|
||||||
|
// TODO: Consider chars padding
|
||||||
|
// NOTE: It could be required for outline/glow shader effects
|
||||||
|
//Rectangle charRec = { font.recs[index].x - (float)font.charsPadding, font.recs[index].y - (float)font.charsPadding,
|
||||||
|
// font.recs[index].width + 2.0f*font.charsPadding, font.recs[index].height + 2.0f*font.charsPadding };
|
||||||
|
|
||||||
DrawTexturePro(font.texture, font.recs[index], rec, (Vector2){ 0, 0 }, 0.0f, tint);
|
DrawTexturePro(font.texture, font.recs[index], rec, (Vector2){ 0, 0 }, 0.0f, tint);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue