|
|
@ -901,10 +901,10 @@ void DrawTextRecEx(Font font, const char *text, Rectangle rec, float fontSize, f |
|
|
|
{ |
|
|
|
int length = TextLength(text); // Total length in bytes of the text, scanned by codepoints in loop |
|
|
|
|
|
|
|
int textOffsetY = 0; // Offset between lines (on line break '\n') |
|
|
|
float textOffsetY = 0; // Offset between lines (on line break '\n') |
|
|
|
float textOffsetX = 0.0f; // Offset X to next character to draw |
|
|
|
|
|
|
|
float scaleFactor = fontSize/font.baseSize; // Character quad scaling factor |
|
|
|
float scaleFactor = fontSize/p">(float)font.baseSize; // Character quad scaling factor |
|
|
|
|
|
|
|
// Word/character wrapping mechanism variables |
|
|
|
enum { MEASURE_STATE = 0, DRAW_STATE = 1 }; |
|
|
@ -926,12 +926,13 @@ void DrawTextRecEx(Font font, const char *text, Rectangle rec, float fontSize, f |
|
|
|
if (codepoint == 0x3f) codepointByteCount = 1; |
|
|
|
i += (codepointByteCount - 1); |
|
|
|
|
|
|
|
int glyphWidth = 0; |
|
|
|
float glyphWidth = 0; |
|
|
|
if (codepoint != '\n') |
|
|
|
{ |
|
|
|
glyphWidth = (font.chars[index].advanceX == 0)? |
|
|
|
(int)(font.recs[index].width*scaleFactor + spacing): |
|
|
|
(int)(font.chars[index].advanceX*scaleFactor + spacing); |
|
|
|
glyphWidth = (font.chars[index].advanceX == 0) ? font.recs[index].width * scaleFactor : font.chars[index].advanceX * scaleFactor; |
|
|
|
|
|
|
|
if (i + 1 < length) |
|
|
|
glyphWidth = glyphWidth + spacing; |
|
|
|
} |
|
|
|
|
|
|
|
// NOTE: When wordWrap is ON we first measure how much of the text we can draw before going outside of the rec container |
|
|
@ -945,7 +946,7 @@ void DrawTextRecEx(Font font, const char *text, Rectangle rec, float fontSize, f |
|
|
|
// Ref: http://jkorpela.fi/chars/spaces.html |
|
|
|
if ((codepoint == ' ') || (codepoint == '\t') || (codepoint == '\n')) endLine = i; |
|
|
|
|
|
|
|
if ((textOffsetX + glyphWidth + 1) >= rec.width) |
|
|
|
if ((textOffsetX + glyphWidth) > rec.width) |
|
|
|
{ |
|
|
|
endLine = (endLine < 1)? i : endLine; |
|
|
|
if (i == endLine) endLine -= codepointByteCount; |
|
|
@ -956,7 +957,6 @@ void DrawTextRecEx(Font font, const char *text, Rectangle rec, float fontSize, f |
|
|
|
else if ((i + 1) == length) |
|
|
|
{ |
|
|
|
endLine = i; |
|
|
|
|
|
|
|
state = !state; |
|
|
|
} |
|
|
|
else if (codepoint == '\n') state = !state; |
|
|
@ -979,26 +979,26 @@ void DrawTextRecEx(Font font, const char *text, Rectangle rec, float fontSize, f |
|
|
|
{ |
|
|
|
if (!wordWrap) |
|
|
|
{ |
|
|
|
textOffsetY += (kt">int)((font.baseSize + font.baseSize/2)*scaleFactor); |
|
|
|
textOffsetY += (font.baseSize + font.baseSize / 2) * scaleFactor; |
|
|
|
textOffsetX = 0; |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
if (!wordWrap && ((textOffsetX + glyphWidth + 1) >= rec.width)) |
|
|
|
if (!wordWrap && ((textOffsetX + glyphWidth) > rec.width)) |
|
|
|
{ |
|
|
|
textOffsetY += (kt">int)((font.baseSize + font.baseSize/2)*scaleFactor); |
|
|
|
textOffsetY += (font.baseSize + font.baseSize / 2) * scaleFactor; |
|
|
|
textOffsetX = 0; |
|
|
|
} |
|
|
|
|
|
|
|
// When text overflows rectangle height limit, just stop drawing |
|
|
|
if ((textOffsetY + p">(int)(font.baseSize*scaleFactor)) > rec.height) break; |
|
|
|
if ((textOffsetY + font.baseSize*scaleFactor) > rec.height) break; |
|
|
|
|
|
|
|
// Draw selection background |
|
|
|
bool isGlyphSelected = false; |
|
|
|
if ((selectStart >= 0) && (k >= selectStart) && (k < (selectStart + selectLength))) |
|
|
|
{ |
|
|
|
DrawRectangleRec((Rectangle){ rec.x + textOffsetX - 1, rec.y + textOffsetY, p">(float)glyphWidth, (float)font.baseSize*scaleFactor }, selectBackTint); |
|
|
|
DrawRectangleRec((Rectangle){ rec.x + textOffsetX - 1, rec.y + textOffsetY, glyphWidth, (float)font.baseSize * scaleFactor }, selectBackTint); |
|
|
|
isGlyphSelected = true; |
|
|
|
} |
|
|
|
|
|
|
@ -1011,7 +1011,7 @@ void DrawTextRecEx(Font font, const char *text, Rectangle rec, float fontSize, f |
|
|
|
|
|
|
|
if (wordWrap && (i == endLine)) |
|
|
|
{ |
|
|
|
textOffsetY += (kt">int)((font.baseSize + font.baseSize/2)*scaleFactor); |
|
|
|
textOffsetY += (font.baseSize + font.baseSize / 2) * scaleFactor; |
|
|
|
textOffsetX = 0; |
|
|
|
startLine = endLine; |
|
|
|
endLine = -1; |
|
|
|