From b62f7c3057cdfefacb9dc46e3096ea377a7f05a6 Mon Sep 17 00:00:00 2001 From: raysan5 Date: Wed, 9 Dec 2015 20:21:58 +0100 Subject: [PATCH 1/3] Corrected bug --- src/text.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/text.c b/src/text.c index c62704aae..081a84916 100644 --- a/src/text.c +++ b/src/text.c @@ -256,7 +256,7 @@ SpriteFont LoadSpriteFont(const char *fileName) } else { - TraceLog(WARNING, "[%s] SpriteFont could not be loaded, using default font", fileName, numChars); + TraceLog(WARNING, "[%s] SpriteFont could not be loaded, using default font", fileName); spriteFont = GetDefaultFont(); } From 2bd72455080409f1d9ecc6c5576f58c1ff093c3f Mon Sep 17 00:00:00 2001 From: raysan5 Date: Wed, 9 Dec 2015 20:22:42 +0100 Subject: [PATCH 2/3] DrawTextureRec() function review to allow flipped rectangle --- src/textures.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/textures.c b/src/textures.c index 27046b613..f97812dad 100644 --- a/src/textures.c +++ b/src/textures.c @@ -1206,7 +1206,7 @@ void DrawTextureEx(Texture2D texture, Vector2 position, float rotation, float sc // Draw a part of a texture (defined by a rectangle) void DrawTextureRec(Texture2D texture, Rectangle sourceRec, Vector2 position, Color tint) { - Rectangle destRec = { (int)position.x, (int)position.y, sourceRec.width, sourceRec.height }; + Rectangle destRec = { (int)position.x, (int)position.y, abs(sourceRec.width), abs(sourceRec.height) }; Vector2 origin = { 0, 0 }; DrawTexturePro(texture, sourceRec, destRec, origin, 0.0f, tint); From f144b6bae43465a62a45f8e45ab2099f215664dc Mon Sep 17 00:00:00 2001 From: raysan5 Date: Wed, 9 Dec 2015 20:57:50 +0100 Subject: [PATCH 3/3] MeasureTextEx() - Added support for multi-line size measure --- src/text.c | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/src/text.c b/src/text.c index 081a84916..d24ff9725 100644 --- a/src/text.c +++ b/src/text.c @@ -378,20 +378,42 @@ int MeasureText(const char *text, int fontSize) Vector2 MeasureTextEx(SpriteFont spriteFont, const char *text, int fontSize, int spacing) { int len = strlen(text); + int tempLen = 0; // Used to count longer text line num chars + int lenCounter = 0; + int textWidth = 0; + int tempTextWidth = 0; // Used to count longer text line width + + int textHeight = spriteFont.size; float scaleFactor; for (int i = 0; i < len; i++) { - if (text[i] != '\n') textWidth += spriteFont.charRecs[(int)text[i] - FONT_FIRST_CHAR].width; + lenCounter++; + + if (text[i] != '\n') + { + textWidth += spriteFont.charRecs[(int)text[i] - FONT_FIRST_CHAR].width; + } + else + { + if (tempTextWidth < textWidth) tempTextWidth = textWidth; + lenCounter = 0; + textWidth = 0; + textHeight += (spriteFont.size + spriteFont.size/2); + } + + if (tempLen < lenCounter) tempLen = lenCounter; } + + if (tempTextWidth < textWidth) tempTextWidth = textWidth; - if (fontSize <= spriteFont.charRecs[0].height) scaleFactor = 1.0f; - else scaleFactor = (float)fontSize / spriteFont.charRecs[0].height; + if (fontSize <= spriteFont.size) scaleFactor = 1.0f; + else scaleFactor = (float)fontSize/spriteFont.size; Vector2 vec; - vec.x = (float)textWidth * scaleFactor + (len - 1) * spacing; // Adds chars spacing to measure - vec.y = (float)spriteFont.charRecs[0].height * scaleFactor; + vec.x = (float)tempTextWidth*scaleFactor + (tempLen - 1)*spacing; // Adds chars spacing to measure + vec.y = (float)textHeight*scaleFactor; return vec; }