mirror of
https://github.com/raysan5/raylib.git
synced 2025-09-06 03:18:14 +00:00
Added function: SubText()
Useful to get a piece of text, could be used for text typing animations
This commit is contained in:
26
src/text.c
26
src/text.c
@@ -44,6 +44,7 @@
|
|||||||
#define FONT_FIRST_CHAR 32
|
#define FONT_FIRST_CHAR 32
|
||||||
#define MAX_FONTCHARS 128
|
#define MAX_FONTCHARS 128
|
||||||
#define MAX_FORMATTEXT_LENGTH 64
|
#define MAX_FORMATTEXT_LENGTH 64
|
||||||
|
#define MAX_SUBTEXT_LENGTH 64
|
||||||
|
|
||||||
#define BIT_CHECK(a,b) ((a) & (1<<(b)))
|
#define BIT_CHECK(a,b) ((a) & (1<<(b)))
|
||||||
|
|
||||||
@@ -360,6 +361,31 @@ const char *FormatText(const char *text, ...)
|
|||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get a piece of a text string
|
||||||
|
const char *SubText(const char *text, int position, int length)
|
||||||
|
{
|
||||||
|
static char buffer[MAX_SUBTEXT_LENGTH];
|
||||||
|
int textLength = strlen(text);
|
||||||
|
|
||||||
|
if (position >= textLength)
|
||||||
|
{
|
||||||
|
position = textLength - 1;
|
||||||
|
length = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (length >= textLength) length = textLength;
|
||||||
|
|
||||||
|
for (int c = 0 ; c < length ; c++)
|
||||||
|
{
|
||||||
|
*(buffer+c) = *(text+position);
|
||||||
|
text++;
|
||||||
|
}
|
||||||
|
|
||||||
|
*(buffer+length) = '\0';
|
||||||
|
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
|
|
||||||
// Measure string width for default font
|
// Measure string width for default font
|
||||||
int MeasureText(const char *text, int fontSize)
|
int MeasureText(const char *text, int fontSize)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user