diff options
| author | Ray <raysan5@gmail.com> | 2016-10-09 13:09:08 +0200 |
|---|---|---|
| committer | Ray <raysan5@gmail.com> | 2016-10-09 13:09:08 +0200 |
| commit | efa286a550115ebcb8dfb4e84ea6a719d110fd27 (patch) | |
| tree | 0904c8656f98510fe89c8e72f992e1ddb22153f9 /src/text.c | |
| parent | b4a3f294bfe8c2c854b45ff56d971c3995b71f62 (diff) | |
| download | raylib-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.c | 28 |
1 files changed, 18 insertions, 10 deletions
@@ -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; } |
