aboutsummaryrefslogtreecommitdiff
path: root/src/text.c
diff options
context:
space:
mode:
authorRay <raysan5@gmail.com>2016-10-09 13:09:08 +0200
committerRay <raysan5@gmail.com>2016-10-09 13:09:08 +0200
commitefa286a550115ebcb8dfb4e84ea6a719d110fd27 (patch)
tree0904c8656f98510fe89c8e72f992e1ddb22153f9 /src/text.c
parentb4a3f294bfe8c2c854b45ff56d971c3995b71f62 (diff)
downloadraylib-efa286a550115ebcb8dfb4e84ea6a719d110fd27.tar.gz
raylib-efa286a550115ebcb8dfb4e84ea6a719d110fd27.zip
Allow no default font loading
Useful if text module is not required...
Diffstat (limited to 'src/text.c')
-rw-r--r--src/text.c28
1 files changed, 18 insertions, 10 deletions
diff --git a/src/text.c b/src/text.c
index c538ea56..d1d7602f 100644
--- a/src/text.c
+++ b/src/text.c
@@ -293,13 +293,17 @@ void UnloadSpriteFont(SpriteFont spriteFont)
// NOTE: chars spacing is proportional to fontSize
void DrawText(const char *text, int posX, int posY, int fontSize, Color color)
{
- Vector2 position = { (float)posX, (float)posY };
+ // Check if default font has been loaded
+ if (defaultFont.texture.id != 0)
+ {
+ Vector2 position = { (float)posX, (float)posY };
- int defaultFontSize = 10; // Default Font chars height in pixel
- if (fontSize < defaultFontSize) fontSize = defaultFontSize;
- int spacing = fontSize/defaultFontSize;
+ int defaultFontSize = 10; // Default Font chars height in pixel
+ if (fontSize < defaultFontSize) fontSize = defaultFontSize;
+ int spacing = fontSize/defaultFontSize;
- DrawTextEx(defaultFont, text, position, (float)fontSize, spacing, color);
+ DrawTextEx(GetDefaultFont(), text, position, (float)fontSize, spacing, color);
+ }
}
// Draw text using SpriteFont
@@ -404,13 +408,17 @@ const char *SubText(const char *text, int position, int length)
// Measure string width for default font
int MeasureText(const char *text, int fontSize)
{
- Vector2 vec;
+ Vector2 vec = { 0.0f, 0.0f };
- int defaultFontSize = 10; // Default Font chars height in pixel
- if (fontSize < defaultFontSize) fontSize = defaultFontSize;
- int spacing = fontSize/defaultFontSize;
+ // Check if default font has been loaded
+ if (defaultFont.texture.id != 0)
+ {
+ int defaultFontSize = 10; // Default Font chars height in pixel
+ if (fontSize < defaultFontSize) fontSize = defaultFontSize;
+ int spacing = fontSize/defaultFontSize;
- vec = MeasureTextEx(defaultFont, text, fontSize, spacing);
+ vec = MeasureTextEx(GetDefaultFont(), text, fontSize, spacing);
+ }
return (int)vec.x;
}