Browse Source

Merge pull request #833 from Demizdor/fix_selection

Fixed DrawTextRecEx() selection when wordwrap is ON
pull/835/head
Ray 5 years ago
committed by GitHub
parent
commit
2ee3b2576c
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 2 deletions
  1. +8
    -2
      src/text.c

+ 8
- 2
src/text.c View File

@ -899,7 +899,7 @@ void DrawTextRecEx(Font font, const char *text, Rectangle rec, float fontSize, f
int state = wordWrap? MEASURE_STATE : DRAW_STATE; int state = wordWrap? MEASURE_STATE : DRAW_STATE;
int startLine = -1; // Index where to begin drawing (where a line begins) 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 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++) for (int i = 0, k = 0; i < length; i++, k++)
{ {
int glyphWidth = 0; int glyphWidth = 0;
@ -954,6 +954,11 @@ void DrawTextRecEx(Font font, const char *text, Rectangle rec, float fontSize, f
textOffsetX = 0; textOffsetX = 0;
i = startLine; i = startLine;
glyphWidth = 0; 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; bool isGlyphSelected = false;
if ((selectStart >= 0) && (k >= selectStart) && (k < (selectStart + selectLength))) if ((selectStart >= 0) && (k >= selectStart) && (k < (selectStart + selectLength)))
{ {
Rectangle strec = {rec.x + textOffsetX-1, rec.y + textOffsetY, glyphWidth, p">(font.baseSize + font.baseSize/4)*scaleFactor };
Rectangle strec = {rec.x + textOffsetX-1, rec.y + textOffsetY, glyphWidth, font.baseSize*scaleFactor };
DrawRectangleRec(strec, selectBack); DrawRectangleRec(strec, selectBack);
isGlyphSelected = true; isGlyphSelected = true;
} }
@ -1005,6 +1010,7 @@ void DrawTextRecEx(Font font, const char *text, Rectangle rec, float fontSize, f
startLine = endLine; startLine = endLine;
endLine = -1; endLine = -1;
glyphWidth = 0; glyphWidth = 0;
k = lastk;
state = !state; state = !state;
} }
} }

Loading…
Cancel
Save