mirror of https://github.com/OpenTTD/OpenTTD
(svn r24737) -Add: Textbuf::Assign and Textbuf::Print.
parent
f2221e8b89
commit
0ea2152355
|
@ -10,8 +10,11 @@
|
||||||
/** @file textbuf.cpp Textbuffer handling. */
|
/** @file textbuf.cpp Textbuffer handling. */
|
||||||
|
|
||||||
#include "stdafx.h"
|
#include "stdafx.h"
|
||||||
|
#include <stdarg.h>
|
||||||
|
|
||||||
#include "textbuf_type.h"
|
#include "textbuf_type.h"
|
||||||
#include "string_func.h"
|
#include "string_func.h"
|
||||||
|
#include "strings_func.h"
|
||||||
#include "gfx_type.h"
|
#include "gfx_type.h"
|
||||||
#include "gfx_func.h"
|
#include "gfx_func.h"
|
||||||
#include "window_func.h"
|
#include "window_func.h"
|
||||||
|
@ -377,6 +380,39 @@ void Textbuf::Initialize(char *buf, uint16 max_bytes, uint16 max_chars)
|
||||||
this->UpdateSize();
|
this->UpdateSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
* 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.
|
* Get the count of characters in the string as well as the width in pixels.
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
#define TEXTBUF_TYPE_H
|
#define TEXTBUF_TYPE_H
|
||||||
|
|
||||||
#include "string_type.h"
|
#include "string_type.h"
|
||||||
|
#include "strings_type.h"
|
||||||
|
|
||||||
/** Helper/buffer for input fields. */
|
/** Helper/buffer for input fields. */
|
||||||
struct Textbuf {
|
struct Textbuf {
|
||||||
|
@ -29,6 +30,10 @@ struct Textbuf {
|
||||||
void Initialize(char *buf, uint16 max_bytes);
|
void Initialize(char *buf, uint16 max_bytes);
|
||||||
void Initialize(char *buf, uint16 max_bytes, uint16 max_chars);
|
void Initialize(char *buf, uint16 max_bytes, uint16 max_chars);
|
||||||
|
|
||||||
|
void Assign(StringID string);
|
||||||
|
void Assign(const char *text);
|
||||||
|
void CDECL Print(const char *format, ...) WARN_FORMAT(2, 3);
|
||||||
|
|
||||||
void DeleteAll();
|
void DeleteAll();
|
||||||
bool DeleteChar(int delmode);
|
bool DeleteChar(int delmode);
|
||||||
bool InsertChar(uint32 key);
|
bool InsertChar(uint32 key);
|
||||||
|
|
Loading…
Reference in New Issue