aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRay San <raysan5@gmail.com>2015-10-21 18:24:44 +0200
committerRay San <raysan5@gmail.com>2015-10-21 18:24:44 +0200
commitf13b30d6060ce7541a7ef7f3074966c623128090 (patch)
tree8d7526723978d503989796019feac8ff9f49b644 /src
parent165b3dd215502435aaed455e48af0886897da1b2 (diff)
downloadraylib-f13b30d6060ce7541a7ef7f3074966c623128090.tar.gz
raylib-f13b30d6060ce7541a7ef7f3074966c623128090.zip
Feature: Line-break support for text
Diffstat (limited to 'src')
-rw-r--r--src/text.c19
1 files changed, 16 insertions, 3 deletions
diff --git a/src/text.c b/src/text.c
index 65650956..381aa052 100644
--- a/src/text.c
+++ b/src/text.c
@@ -293,6 +293,7 @@ void DrawTextEx(SpriteFont spriteFont, const char *text, Vector2 position, int f
{
int length = strlen(text);
int offsetX = 0;
+ int offsetY = 0; // Line break!
float scaleFactor;
unsigned char letter;
@@ -323,11 +324,23 @@ void DrawTextEx(SpriteFont spriteFont, const char *text, Vector2 position, int f
rec = spriteFont.charRecs[letter - FONT_FIRST_CHAR + 64];
i++;
}
- else rec = spriteFont.charRecs[(int)text[i] - FONT_FIRST_CHAR];
+ else
+ {
+ if ((unsigned char)text[i] == '\n')
+ {
+ offsetY += ((spriteFont.size + spriteFont.size/2)*scaleFactor);
+ offsetX = 0;
+ rec.x = -1;
+ }
+ else rec = spriteFont.charRecs[(int)text[i] - FONT_FIRST_CHAR];
+ }
- DrawTexturePro(spriteFont.texture, rec, (Rectangle){ position.x + offsetX, position.y, rec.width*scaleFactor, rec.height*scaleFactor} , (Vector2){ 0, 0 }, 0.0f, tint);
+ if (rec.x > 0)
+ {
+ DrawTexturePro(spriteFont.texture, rec, (Rectangle){ position.x + offsetX, position.y + offsetY, rec.width*scaleFactor, rec.height*scaleFactor} , (Vector2){ 0, 0 }, 0.0f, tint);
- offsetX += (rec.width*scaleFactor + spacing);
+ offsetX += (rec.width*scaleFactor + spacing);
+ }
}
}