diff options
| author | Ray <raysan5@gmail.com> | 2019-05-10 15:19:41 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-05-10 15:19:41 +0200 |
| commit | 2ee3b2576c15bbaabcb09821976e3a341d1a04cd (patch) | |
| tree | f6f6ec907b8244c204943f656bf62ae4836c9e11 /src | |
| parent | a2ed65aa1461addee7093d92ca80615d607e926b (diff) | |
| parent | 509d9411a1f4a608981a84e6d9b80b40e37b602e (diff) | |
| download | raylib-2ee3b2576c15bbaabcb09821976e3a341d1a04cd.tar.gz raylib-2ee3b2576c15bbaabcb09821976e3a341d1a04cd.zip | |
Merge pull request #833 from Demizdor/fix_selection
Fixed DrawTextRecEx() selection when wordwrap is ON
Diffstat (limited to 'src')
| -rw-r--r-- | src/text.c | 10 |
1 files changed, 8 insertions, 2 deletions
@@ -899,7 +899,7 @@ void DrawTextRecEx(Font font, const char *text, Rectangle rec, float fontSize, f int state = wordWrap? MEASURE_STATE : DRAW_STATE; int startLine = -1; // Index where to begin drawing (where a line begins) int endLine = -1; // Index where to stop drawing (where a line ends) - + int lastk = -1; // Holds last value of the character position for (int i = 0, k = 0; i < length; i++, k++) { int glyphWidth = 0; @@ -954,6 +954,11 @@ void DrawTextRecEx(Font font, const char *text, Rectangle rec, float fontSize, f textOffsetX = 0; i = startLine; glyphWidth = 0; + + // Save character position when we switch states + int tmp = lastk; + lastk = k - 1; + k = tmp; } } @@ -981,7 +986,7 @@ void DrawTextRecEx(Font font, const char *text, Rectangle rec, float fontSize, f bool isGlyphSelected = false; if ((selectStart >= 0) && (k >= selectStart) && (k < (selectStart + selectLength))) { - Rectangle strec = {rec.x + textOffsetX-1, rec.y + textOffsetY, glyphWidth, (font.baseSize + font.baseSize/4)*scaleFactor }; + Rectangle strec = {rec.x + textOffsetX-1, rec.y + textOffsetY, glyphWidth, font.baseSize*scaleFactor }; DrawRectangleRec(strec, selectBack); isGlyphSelected = true; } @@ -1005,6 +1010,7 @@ void DrawTextRecEx(Font font, const char *text, Rectangle rec, float fontSize, f startLine = endLine; endLine = -1; glyphWidth = 0; + k = lastk; state = !state; } } |
