From e9539e9373947b7424df8bbb34d8ae30e49a591f Mon Sep 17 00:00:00 2001 From: jussi Date: Thu, 13 Jun 2024 14:52:56 +0300 Subject: DrawTextBoxed uses lineSpacing. GetTextLineSpacing. --- src/text.c | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) (limited to 'src/text.c') diff --git a/src/text.c b/src/text.c index a9402d4..2a4ec1d 100644 --- a/src/text.c +++ b/src/text.c @@ -12,14 +12,14 @@ void unloadGlyphInfo( GlyphInfo* glyph ) { // Draw text using font inside rectangle limits static int DrawTextBoxed( Font font, const char* text, Rectangle rec, float fontSize, float spacing, -bool wordWrap, Color* tints, int tintCount, Color* backTints, int backTintCount ) -{ +bool wordWrap, Color* tints, int tintCount, Color* backTints, int backTintCount ) { int length = TextLength(text); // Total length in bytes of the text, scanned by codepoints in loop float textOffsetY = 0; // Offset between lines (on line break '\n') float textOffsetX = 0.0f; // Offset X to next character to draw float scaleFactor = fontSize/(float)font.baseSize; // Character rectangle scaling factor + int lineSpacing = state->lineSpacing; // Word/character wrapping mechanism variables enum { MEASURE_STATE = 0, DRAW_STATE = 1 }; @@ -103,7 +103,8 @@ bool wordWrap, Color* tints, int tintCount, Color* backTints, int backTintCount { if (!wordWrap) { - textOffsetY += (font.baseSize + font.baseSize/2)*scaleFactor; + // textOffsetY += (font.baseSize + font.baseSize/2)*scaleFactor; + textOffsetY += lineSpacing; textOffsetX = 0; } } @@ -111,7 +112,8 @@ bool wordWrap, Color* tints, int tintCount, Color* backTints, int backTintCount { if (!wordWrap && ((textOffsetX + glyphWidth) > rec.width)) { - textOffsetY += (font.baseSize + font.baseSize/2)*scaleFactor; + // textOffsetY += (font.baseSize + font.baseSize/2)*scaleFactor; + textOffsetY += lineSpacing; textOffsetX = 0; } @@ -144,7 +146,8 @@ bool wordWrap, Color* tints, int tintCount, Color* backTints, int backTintCount if (wordWrap && (i == endLine)) { - textOffsetY += (font.baseSize + font.baseSize/2)*scaleFactor; + // textOffsetY += (font.baseSize + font.baseSize/2)*scaleFactor; + textOffsetY += lineSpacing; textOffsetX = 0; startLine = endLine; endLine = -1; @@ -606,7 +609,7 @@ int ltextDrawTextBoxed( lua_State* L ) { } /* -> mouseCharId = RL.DrawTextBoxedTinted( Font font, string text, Rectangle rec, float fontSize, float spacing, bool wordWrap, Color tints, Color backTints ) +> mouseCharId = RL.DrawTextBoxedTinted( Font font, string text, Rectangle rec, float fontSize, float spacing, bool wordWrap, Color tints{}, Color backTints{} ) Draw text using font inside rectangle limits with support for tint and background tint for each character. Return character id from mouse position (default -1) @@ -653,16 +656,28 @@ int ltextDrawTextBoxedTinted( lua_State* L ) { */ /* -> size = RL.SetTextLineSpacing( int spacing ) +> RL.SetTextLineSpacing( int spacing ) Set vertical line spacing when drawing with line-breaks */ int ltextSetTextLineSpacing( lua_State* L ) { int spacing = luaL_checkinteger( L, 1 ); + state->lineSpacing = spacing; SetTextLineSpacing( spacing ); } +/* +> spacing = RL.GetTextLineSpacing() + +Get vertical line spacing when drawing with line-breaks + +- Success return int +*/ +int ltextGetTextLineSpacing( lua_State* L ) { + lua_pushinteger( L, state->lineSpacing ); +} + /* > width = RL.MeasureText( string text, int fontSize ) -- cgit v1.2.3