summaryrefslogtreecommitdiff
path: root/src/textbuf.cpp
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2012-11-14 22:50:11 +0000
committerfrosch <frosch@openttd.org>2012-11-14 22:50:11 +0000
commit0ea21523556a345d38933ee2dd6dcdca0ec08514 (patch)
tree455c685cff6735215cbaba335c3e142cfe3da493 /src/textbuf.cpp
parentf2221e8b89d0e3030679a36bfaaa75c64951aed3 (diff)
downloadopenttd-0ea21523556a345d38933ee2dd6dcdca0ec08514.tar.xz
(svn r24737) -Add: Textbuf::Assign and Textbuf::Print.
Diffstat (limited to 'src/textbuf.cpp')
-rw-r--r--src/textbuf.cpp36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/textbuf.cpp b/src/textbuf.cpp
index 9c8753d89..0816c5dcf 100644
--- a/src/textbuf.cpp
+++ b/src/textbuf.cpp
@@ -10,8 +10,11 @@
/** @file textbuf.cpp Textbuffer handling. */
#include "stdafx.h"
+#include <stdarg.h>
+
#include "textbuf_type.h"
#include "string_func.h"
+#include "strings_func.h"
#include "gfx_type.h"
#include "gfx_func.h"
#include "window_func.h"
@@ -378,6 +381,39 @@ void Textbuf::Initialize(char *buf, uint16 max_bytes, uint16 max_chars)
}
/**
+ * Render a string into the textbuffer.
+ * @param string String
+ */
+void Textbuf::Assign(StringID string)
+{
+ GetString(this->buf, string, &this->buf[this->max_bytes - 1]);
+ this->UpdateSize();
+}
+
+/**
+ * Copy a string into the textbuffer.
+ * @param text Source.
+ */
+void Textbuf::Assign(const char *text)
+{
+ ttd_strlcpy(this->buf, text, this->max_bytes);
+ this->UpdateSize();
+}
+
+/**
+ * Print a formatted string into the textbuffer.
+ */
+void Textbuf::Print(const char *format, ...)
+{
+ va_list va;
+ va_start(va, format);
+ vsnprintf(this->buf, this->max_bytes, format, va);
+ va_end(va);
+ this->UpdateSize();
+}
+
+
+/**
* Update Textbuf type with its actual physical character and screenlength
* Get the count of characters in the string as well as the width in pixels.
* Useful when copying in a larger amount of text at once