Corrected issue with GetFontDefault()
Note for me: Replace All is NOT your friend...
This commit is contained in:
parent
d881c73257
commit
103bc7dfc6
@ -923,7 +923,7 @@ RLAPI void ImageResizeCanvas(Image *image, int newWidth, int newHeight, int offs
|
||||
RLAPI void ImageMipmaps(Image *image); // Generate all mipmap levels for a provided image
|
||||
RLAPI void ImageDither(Image *image, int rBpp, int gBpp, int bBpp, int aBpp); // Dither image data to 16bpp or lower (Floyd-Steinberg dithering)
|
||||
RLAPI Image ImageText(const char *text, int fontSize, Color color); // Create an image from text (default font)
|
||||
RLAPI Image ImageTextEx(Font font, const char *text, float fontSize, float spacing, Color tint); // Create an image from text (custom sprite font)
|
||||
RLAPI Image ImageTextEx(Font font, const char *text, float fontSize, float spacing, Color tint); // Create an image from text (custom sprite font)
|
||||
RLAPI void ImageDraw(Image *dst, Image src, Rectangle srcRec, Rectangle dstRec); // Draw a source image within a destination image
|
||||
RLAPI void ImageDrawRectangle(Image *dst, Vector2 position, Rectangle rec, Color color); // Draw rectangle within an image
|
||||
RLAPI void ImageDrawText(Image *dst, Vector2 position, const char *text, int fontSize, Color color); // Draw text (default font) within an image (destination)
|
||||
@ -966,7 +966,7 @@ RLAPI void DrawTexturePro(Texture2D texture, Rectangle sourceRec, Rectangle dest
|
||||
//------------------------------------------------------------------------------------
|
||||
|
||||
// Font loading/unloading functions
|
||||
RLAPI Font GetDefaultFont(void); // Get the default Font
|
||||
RLAPI Font GetFontDefault(void); // Get the default Font
|
||||
RLAPI Font LoadFont(const char *fileName); // Load font from file into GPU memory (VRAM)
|
||||
RLAPI Font LoadFontEx(const char *fileName, int fontSize, int charsCount, int *fontChars); // Load font from file with extended parameters
|
||||
RLAPI CharInfo *LoadFontData(const char *fileName, int fontSize, int *fontChars, int charsCount, bool sdf); // Load font data for further use
|
||||
|
Binary file not shown.
@ -966,7 +966,7 @@ RLAPI void DrawTexturePro(Texture2D texture, Rectangle sourceRec, Rectangle dest
|
||||
//------------------------------------------------------------------------------------
|
||||
|
||||
// Font loading/unloading functions
|
||||
RLAPI Font GetFontDefault()(void); // Get the default Font
|
||||
RLAPI Font GetFontDefault(void); // Get the default Font
|
||||
RLAPI Font LoadFont(const char *fileName); // Load font from file into GPU memory (VRAM)
|
||||
RLAPI Font LoadFontEx(const char *fileName, int fontSize, int charsCount, int *fontChars); // Load font from file with extended parameters
|
||||
RLAPI CharInfo *LoadFontData(const char *fileName, int fontSize, int *fontChars, int charsCount, bool sdf); // Load font data for further use
|
||||
|
36
src/shapes.c
36
src/shapes.c
@ -259,27 +259,27 @@ void DrawRectangleV(Vector2 position, Vector2 size, Color color)
|
||||
#if defined(SUPPORT_QUADS_DRAW_MODE)
|
||||
#if defined(SUPPORT_FONT_TEXTURE)
|
||||
// Draw rectangle using font texture white character
|
||||
rlEnableTexture(GetFontDefault()().texture.id);
|
||||
rlEnableTexture(GetFontDefault().texture.id);
|
||||
|
||||
rlBegin(RL_QUADS);
|
||||
rlColor4ub(color.r, color.g, color.b, color.a);
|
||||
rlNormal3f(0.0f, 0.0f, 1.0f);
|
||||
|
||||
// NOTE: Default raylib font character 95 is a white square
|
||||
rlTexCoord2f((float)GetFontDefault()().chars[95].rec.x/GetFontDefault()().texture.width,
|
||||
(float)GetFontDefault()().chars[95].rec.y/GetFontDefault()().texture.height);
|
||||
rlTexCoord2f((float)GetFontDefault().chars[95].rec.x/GetFontDefault().texture.width,
|
||||
(float)GetFontDefault().chars[95].rec.y/GetFontDefault().texture.height);
|
||||
rlVertex2f(position.x, position.y);
|
||||
|
||||
rlTexCoord2f((float)GetFontDefault()().chars[95].rec.x/GetFontDefault()().texture.width,
|
||||
(float)(GetFontDefault()().chars[95].rec.y + GetFontDefault()().chars[95].rec.height)/GetFontDefault()().texture.height);
|
||||
rlTexCoord2f((float)GetFontDefault().chars[95].rec.x/GetFontDefault().texture.width,
|
||||
(float)(GetFontDefault().chars[95].rec.y + GetFontDefault().chars[95].rec.height)/GetFontDefault().texture.height);
|
||||
rlVertex2f(position.x, position.y + size.y);
|
||||
|
||||
rlTexCoord2f((float)(GetFontDefault()().chars[95].rec.x + GetFontDefault()().chars[95].rec.width)/GetFontDefault()().texture.width,
|
||||
(float)(GetFontDefault()().chars[95].rec.y + GetFontDefault()().chars[95].rec.height)/GetFontDefault()().texture.height);
|
||||
rlTexCoord2f((float)(GetFontDefault().chars[95].rec.x + GetFontDefault().chars[95].rec.width)/GetFontDefault().texture.width,
|
||||
(float)(GetFontDefault().chars[95].rec.y + GetFontDefault().chars[95].rec.height)/GetFontDefault().texture.height);
|
||||
rlVertex2f(position.x + size.x, position.y + size.y);
|
||||
|
||||
rlTexCoord2f((float)(GetFontDefault()().chars[95].rec.x + GetFontDefault()().chars[95].rec.width)/GetFontDefault()().texture.width,
|
||||
(float)GetFontDefault()().chars[95].rec.y/GetFontDefault()().texture.height);
|
||||
rlTexCoord2f((float)(GetFontDefault().chars[95].rec.x + GetFontDefault().chars[95].rec.width)/GetFontDefault().texture.width,
|
||||
(float)GetFontDefault().chars[95].rec.y/GetFontDefault().texture.height);
|
||||
rlVertex2f(position.x + size.x, position.y);
|
||||
rlEnd();
|
||||
|
||||
@ -370,30 +370,30 @@ void DrawRectangleGradientEx(Rectangle rec, Color col1, Color col2, Color col3,
|
||||
{
|
||||
#if defined(SUPPORT_FONT_TEXTURE)
|
||||
// Draw rectangle using font texture white character
|
||||
rlEnableTexture(GetFontDefault()().texture.id);
|
||||
rlEnableTexture(GetFontDefault().texture.id);
|
||||
|
||||
rlBegin(RL_QUADS);
|
||||
rlNormal3f(0.0f, 0.0f, 1.0f);
|
||||
|
||||
// NOTE: Default raylib font character 95 is a white square
|
||||
rlColor4ub(col1.r, col1.g, col1.b, col1.a);
|
||||
rlTexCoord2f(GetFontDefault()().chars[95].rec.x/GetFontDefault()().texture.width,
|
||||
GetFontDefault()().chars[95].rec.y/GetFontDefault()().texture.height);
|
||||
rlTexCoord2f(GetFontDefault().chars[95].rec.x/GetFontDefault().texture.width,
|
||||
GetFontDefault().chars[95].rec.y/GetFontDefault().texture.height);
|
||||
rlVertex2f(rec.x, rec.y);
|
||||
|
||||
rlColor4ub(col2.r, col2.g, col2.b, col2.a);
|
||||
rlTexCoord2f(GetFontDefault()().chars[95].rec.x/GetFontDefault()().texture.width,
|
||||
(GetFontDefault()().chars[95].rec.y + GetFontDefault()().chars[95].rec.height)/GetFontDefault()().texture.height);
|
||||
rlTexCoord2f(GetFontDefault().chars[95].rec.x/GetFontDefault().texture.width,
|
||||
(GetFontDefault().chars[95].rec.y + GetFontDefault().chars[95].rec.height)/GetFontDefault().texture.height);
|
||||
rlVertex2f(rec.x, rec.y + rec.height);
|
||||
|
||||
rlColor4ub(col3.r, col3.g, col3.b, col3.a);
|
||||
rlTexCoord2f((GetFontDefault()().chars[95].rec.x + GetFontDefault()().chars[95].rec.width)/GetFontDefault()().texture.width,
|
||||
(GetFontDefault()().chars[95].rec.y + GetFontDefault()().chars[95].rec.height)/GetFontDefault()().texture.height);
|
||||
rlTexCoord2f((GetFontDefault().chars[95].rec.x + GetFontDefault().chars[95].rec.width)/GetFontDefault().texture.width,
|
||||
(GetFontDefault().chars[95].rec.y + GetFontDefault().chars[95].rec.height)/GetFontDefault().texture.height);
|
||||
rlVertex2f(rec.x + rec.width, rec.y + rec.height);
|
||||
|
||||
rlColor4ub(col4.r, col4.g, col4.b, col4.a);
|
||||
rlTexCoord2f((GetFontDefault()().chars[95].rec.x + GetFontDefault()().chars[95].rec.width)/GetFontDefault()().texture.width,
|
||||
GetFontDefault()().chars[95].rec.y/GetFontDefault()().texture.height);
|
||||
rlTexCoord2f((GetFontDefault().chars[95].rec.x + GetFontDefault().chars[95].rec.width)/GetFontDefault().texture.width,
|
||||
GetFontDefault().chars[95].rec.y/GetFontDefault().texture.height);
|
||||
rlVertex2f(rec.x + rec.width, rec.y);
|
||||
rlEnd();
|
||||
|
||||
|
16
src/text.c
16
src/text.c
@ -258,7 +258,7 @@ extern void UnloadDefaultFont(void)
|
||||
#endif // SUPPORT_DEFAULT_FONT
|
||||
|
||||
// Get the default font, useful to be used with extended parameters
|
||||
Font GetFontDefault()()
|
||||
Font GetFontDefault()
|
||||
{
|
||||
#if defined(SUPPORT_DEFAULT_FONT)
|
||||
return defaultFont;
|
||||
@ -303,7 +303,7 @@ Font LoadFont(const char *fileName)
|
||||
if (font.texture.id == 0)
|
||||
{
|
||||
TraceLog(LOG_WARNING, "[%s] Font could not be loaded, using default font", fileName);
|
||||
font = GetFontDefault()();
|
||||
font = GetFontDefault();
|
||||
}
|
||||
else SetTextureFilter(font.texture, FILTER_POINT); // By default we set point filter (best performance)
|
||||
|
||||
@ -527,7 +527,7 @@ Image GenImageFontAtlas(CharInfo *chars, int charsCount, int fontSize, int paddi
|
||||
void UnloadFont(Font font)
|
||||
{
|
||||
// NOTE: Make sure spriteFont is not default font (fallback)
|
||||
if (font.texture.id != GetFontDefault()().texture.id)
|
||||
if (font.texture.id != GetFontDefault().texture.id)
|
||||
{
|
||||
UnloadTexture(font.texture);
|
||||
free(font.chars);
|
||||
@ -542,7 +542,7 @@ void UnloadFont(Font font)
|
||||
void DrawText(const char *text, int posX, int posY, int fontSize, Color color)
|
||||
{
|
||||
// Check if default font has been loaded
|
||||
if (GetFontDefault()().texture.id != 0)
|
||||
if (GetFontDefault().texture.id != 0)
|
||||
{
|
||||
Vector2 position = { (float)posX, (float)posY };
|
||||
|
||||
@ -550,7 +550,7 @@ void DrawText(const char *text, int posX, int posY, int fontSize, Color color)
|
||||
if (fontSize < defaultFontSize) fontSize = defaultFontSize;
|
||||
int spacing = fontSize/defaultFontSize;
|
||||
|
||||
DrawTextEx(GetFontDefault()(), text, position, (float)fontSize, (float)spacing, color);
|
||||
DrawTextEx(GetFontDefault(), text, position, (float)fontSize, (float)spacing, color);
|
||||
}
|
||||
}
|
||||
|
||||
@ -656,13 +656,13 @@ int MeasureText(const char *text, int fontSize)
|
||||
Vector2 vec = { 0.0f, 0.0f };
|
||||
|
||||
// Check if default font has been loaded
|
||||
if (GetFontDefault()().texture.id != 0)
|
||||
if (GetFontDefault().texture.id != 0)
|
||||
{
|
||||
int defaultFontSize = 10; // Default Font chars height in pixel
|
||||
if (fontSize < defaultFontSize) fontSize = defaultFontSize;
|
||||
int spacing = fontSize/defaultFontSize;
|
||||
|
||||
vec = MeasureTextEx(GetFontDefault()(), text, (float)fontSize, (float)spacing);
|
||||
vec = MeasureTextEx(GetFontDefault(), text, (float)fontSize, (float)spacing);
|
||||
}
|
||||
|
||||
return (int)vec.x;
|
||||
@ -988,7 +988,7 @@ static Font LoadBMFont(const char *fileName)
|
||||
if (font.texture.id == 0)
|
||||
{
|
||||
UnloadFont(font);
|
||||
font = GetFontDefault()();
|
||||
font = GetFontDefault();
|
||||
}
|
||||
else TraceLog(LOG_INFO, "[%s] Font loaded successfully", fileName);
|
||||
|
||||
|
@ -1532,7 +1532,7 @@ Image ImageText(const char *text, int fontSize, Color color)
|
||||
if (fontSize < defaultFontSize) fontSize = defaultFontSize;
|
||||
int spacing = (float)fontSize/defaultFontSize;
|
||||
|
||||
Image imText = ImageTextEx(GetFontDefault()(), text, (float)fontSize, (float)spacing, color);
|
||||
Image imText = ImageTextEx(GetFontDefault(), text, (float)fontSize, (float)spacing, color);
|
||||
|
||||
return imText;
|
||||
}
|
||||
@ -1606,7 +1606,7 @@ Image ImageTextEx(Font font, const char *text, float fontSize, float spacing, Co
|
||||
TraceLog(LOG_INFO, "Image text scaled by factor: %f", scaleFactor);
|
||||
|
||||
// Using nearest-neighbor scaling algorithm for default font
|
||||
if (font.texture.id == GetFontDefault()().texture.id) ImageResizeNN(&imText, (int)(imSize.x*scaleFactor), (int)(imSize.y*scaleFactor));
|
||||
if (font.texture.id == GetFontDefault().texture.id) ImageResizeNN(&imText, (int)(imSize.x*scaleFactor), (int)(imSize.y*scaleFactor));
|
||||
else ImageResize(&imText, (int)(imSize.x*scaleFactor), (int)(imSize.y*scaleFactor));
|
||||
}
|
||||
|
||||
@ -1629,7 +1629,7 @@ void ImageDrawRectangle(Image *dst, Vector2 position, Rectangle rec, Color color
|
||||
void ImageDrawText(Image *dst, Vector2 position, const char *text, int fontSize, Color color)
|
||||
{
|
||||
// NOTE: For default font, sapcing is set to desired font size / default font size (10)
|
||||
ImageDrawTextEx(dst, position, GetFontDefault()(), text, (float)fontSize, (float)fontSize/10, color);
|
||||
ImageDrawTextEx(dst, position, GetFontDefault(), text, (float)fontSize, (float)fontSize/10, color);
|
||||
}
|
||||
|
||||
// Draw text (custom sprite font) within an image (destination)
|
||||
|
Loading…
Reference in New Issue
Block a user