Review DrawTextRecEx() formatting
This commit is contained in:
parent
01ace743d0
commit
5755c5e310
2 changed files with 22 additions and 19 deletions
|
@ -1135,7 +1135,7 @@ RLAPI void DrawText(const char *text, int posX, int posY, int fontSize, Color co
|
||||||
RLAPI void DrawTextEx(Font font, const char *text, Vector2 position, float fontSize, float spacing, Color tint); // Draw text using font and additional parameters
|
RLAPI void DrawTextEx(Font font, const char *text, Vector2 position, float fontSize, float spacing, Color tint); // Draw text using font and additional parameters
|
||||||
RLAPI void DrawTextRec(Font font, const char *text, Rectangle rec, float fontSize, float spacing, bool wordWrap, Color tint); // Draw text using font inside rectangle limits
|
RLAPI void DrawTextRec(Font font, const char *text, Rectangle rec, float fontSize, float spacing, bool wordWrap, Color tint); // Draw text using font inside rectangle limits
|
||||||
RLAPI void DrawTextRecEx(Font font, const char *text, Rectangle rec, float fontSize, float spacing, bool wordWrap, Color tint,
|
RLAPI void DrawTextRecEx(Font font, const char *text, Rectangle rec, float fontSize, float spacing, bool wordWrap, Color tint,
|
||||||
int selectStart, int selectLength, Color selectText, Color selectBG); // Draw text using font inside rectangle limits with support for text selection
|
int selectStart, int selectLength, Color selectText, Color selectBack); // Draw text using font inside rectangle limits with support for text selection
|
||||||
|
|
||||||
// Text misc. functions
|
// Text misc. functions
|
||||||
RLAPI int MeasureText(const char *text, int fontSize); // Measure string width for default font
|
RLAPI int MeasureText(const char *text, int fontSize); // Measure string width for default font
|
||||||
|
|
35
src/text.c
35
src/text.c
|
@ -787,7 +787,7 @@ void DrawTextRec(Font font, const char *text, Rectangle rec, float fontSize, flo
|
||||||
|
|
||||||
// Draw text using font inside rectangle limits with support for text selection
|
// Draw text using font inside rectangle limits with support for text selection
|
||||||
void DrawTextRecEx(Font font, const char *text, Rectangle rec, float fontSize, float spacing, bool wordWrap, Color tint,
|
void DrawTextRecEx(Font font, const char *text, Rectangle rec, float fontSize, float spacing, bool wordWrap, Color tint,
|
||||||
int selectStart, int selectLength, Color selectText, Color selectBG)
|
int selectStart, int selectLength, Color selectText, Color selectBack)
|
||||||
{
|
{
|
||||||
int length = strlen(text);
|
int length = strlen(text);
|
||||||
int textOffsetX = 0; // Offset between characters
|
int textOffsetX = 0; // Offset between characters
|
||||||
|
@ -800,7 +800,7 @@ void DrawTextRecEx(Font font, const char *text, Rectangle rec, float fontSize, f
|
||||||
scaleFactor = fontSize/font.baseSize;
|
scaleFactor = fontSize/font.baseSize;
|
||||||
|
|
||||||
enum { MEASURE_STATE = 0, DRAW_STATE = 1 };
|
enum { MEASURE_STATE = 0, DRAW_STATE = 1 };
|
||||||
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)
|
||||||
|
|
||||||
|
@ -842,26 +842,27 @@ void DrawTextRecEx(Font font, const char *text, Rectangle rec, float fontSize, f
|
||||||
// the container.
|
// the container.
|
||||||
if (state == MEASURE_STATE)
|
if (state == MEASURE_STATE)
|
||||||
{
|
{
|
||||||
if((letter == ' ') || (letter == '\t') || (letter == '\n')) endLine = i;
|
if ((letter == ' ') || (letter == '\t') || (letter == '\n')) endLine = i;
|
||||||
|
|
||||||
if(textOffsetX + glyphWidth + 1 >= rec.width)
|
if ((textOffsetX + glyphWidth + 1) >= rec.width)
|
||||||
{
|
{
|
||||||
endLine = (endLine < 1) ? i : endLine;
|
endLine = (endLine < 1) ? i : endLine;
|
||||||
if(i == endLine) endLine -= 1;
|
if (i == endLine) endLine -= 1;
|
||||||
if(startLine + 1 == endLine ) endLine = i - 1;
|
if ((startLine + 1) == endLine) endLine = i - 1;
|
||||||
state = !state;
|
state = !state;
|
||||||
}
|
}
|
||||||
else if(i + 1 == length)
|
else if ((i + 1) == length)
|
||||||
{
|
{
|
||||||
endLine = i;
|
endLine = i;
|
||||||
state = !state;
|
state = !state;
|
||||||
}
|
}
|
||||||
else if(letter == '\n')
|
else if (letter == '\n')
|
||||||
{
|
{
|
||||||
state = !state;
|
state = !state;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(state == DRAW_STATE) {
|
if (state == DRAW_STATE)
|
||||||
|
{
|
||||||
textOffsetX = 0;
|
textOffsetX = 0;
|
||||||
i = startLine;
|
i = startLine;
|
||||||
glyphWidth = 0;
|
glyphWidth = 0;
|
||||||
|
@ -872,14 +873,16 @@ void DrawTextRecEx(Font font, const char *text, Rectangle rec, float fontSize, f
|
||||||
{
|
{
|
||||||
if (letter == '\n')
|
if (letter == '\n')
|
||||||
{
|
{
|
||||||
if(!wordWrap){
|
if (!wordWrap)
|
||||||
|
{
|
||||||
textOffsetY += (int)((font.baseSize + font.baseSize/2)*scaleFactor);
|
textOffsetY += (int)((font.baseSize + font.baseSize/2)*scaleFactor);
|
||||||
textOffsetX = 0;
|
textOffsetX = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if(!wordWrap && textOffsetX + glyphWidth + 1 >= rec.width) {
|
if (!wordWrap && ((textOffsetX + glyphWidth + 1) >= rec.width))
|
||||||
|
{
|
||||||
textOffsetY += (int)((font.baseSize + font.baseSize/2)*scaleFactor);
|
textOffsetY += (int)((font.baseSize + font.baseSize/2)*scaleFactor);
|
||||||
textOffsetX = 0;
|
textOffsetX = 0;
|
||||||
}
|
}
|
||||||
|
@ -888,10 +891,10 @@ void DrawTextRecEx(Font font, const char *text, Rectangle rec, float fontSize, f
|
||||||
|
|
||||||
//draw selected
|
//draw selected
|
||||||
bool isGlyphSelected = false;
|
bool isGlyphSelected = false;
|
||||||
if(selectStart >= 0 && i >= selectStart && i < selectStart + selectLength) {
|
if ((selectStart >= 0) && (i >= selectStart) && (i < (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 + font.baseSize/4)*scaleFactor };
|
||||||
DrawRectangleRec(strec, selectBG);
|
DrawRectangleRec(strec, selectBack);
|
||||||
isGlyphSelected = true;
|
isGlyphSelected = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -907,7 +910,7 @@ void DrawTextRecEx(Font font, const char *text, Rectangle rec, float fontSize, f
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (wordWrap && i == endLine)
|
if (wordWrap && (i == endLine))
|
||||||
{
|
{
|
||||||
textOffsetY += (int)((font.baseSize + font.baseSize/2)*scaleFactor);
|
textOffsetY += (int)((font.baseSize + font.baseSize/2)*scaleFactor);
|
||||||
textOffsetX = 0;
|
textOffsetX = 0;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue