aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorraysan5 <raysan5@gmail.com>2015-12-30 13:33:26 +0100
committerraysan5 <raysan5@gmail.com>2015-12-30 13:33:26 +0100
commitda28cff0f62b5f14e1f557e17587e964ad0f79fd (patch)
tree5f5abdc9b96f1622fdc4e5780f75feee8e827134 /src
parent5dbb93dbb476c35d8f8aab24d9c3507640b171e8 (diff)
downloadraylib-da28cff0f62b5f14e1f557e17587e964ad0f79fd.tar.gz
raylib-da28cff0f62b5f14e1f557e17587e964ad0f79fd.zip
Added function: SubText()
Useful to get a piece of text, could be used for text typing animations
Diffstat (limited to 'src')
-rw-r--r--src/text.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/text.c b/src/text.c
index d24ff972..0930b779 100644
--- a/src/text.c
+++ b/src/text.c
@@ -44,6 +44,7 @@
#define FONT_FIRST_CHAR 32
#define MAX_FONTCHARS 128
#define MAX_FORMATTEXT_LENGTH 64
+#define MAX_SUBTEXT_LENGTH 64
#define BIT_CHECK(a,b) ((a) & (1<<(b)))
@@ -360,6 +361,31 @@ const char *FormatText(const char *text, ...)
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
int MeasureText(const char *text, int fontSize)
{