mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r24738) -Codechange: Remove Textbuf::Initialize in favour of a constructor.
This commit is contained in:
parent
0ea2152355
commit
f6d4200f86
|
@ -1031,11 +1031,9 @@ struct AIDebugWindow : public QueryStringBaseWindow {
|
|||
this->last_vscroll_pos = 0;
|
||||
this->autoscroll = true;
|
||||
this->highlight_row = -1;
|
||||
this->text.Initialize(this->edit_str_buf, this->edit_str_size);
|
||||
|
||||
/* Restore the break string value from static variable */
|
||||
strecpy(this->edit_str_buf, this->break_string, this->edit_str_buf + MAX_BREAK_STR_STRING_LENGTH);
|
||||
this->text.UpdateSize();
|
||||
this->text.Assign(this->break_string);
|
||||
|
||||
/* Restore button state from static class variables */
|
||||
if (ai_debug_company == OWNER_DEITY) {
|
||||
|
|
|
@ -126,7 +126,7 @@ struct IConsoleLine {
|
|||
|
||||
|
||||
/* ** main console cmd buffer ** */
|
||||
static Textbuf _iconsole_cmdline;
|
||||
static Textbuf _iconsole_cmdline(ICON_CMDLN_SIZE);
|
||||
static char *_iconsole_history[ICON_HISTORY_SIZE];
|
||||
static int _iconsole_historypos;
|
||||
IConsoleModes _iconsole_mode;
|
||||
|
@ -356,10 +356,6 @@ void IConsoleGUIInit()
|
|||
IConsoleLine::Reset();
|
||||
memset(_iconsole_history, 0, sizeof(_iconsole_history));
|
||||
|
||||
_iconsole_cmdline.buf = CallocT<char>(ICON_CMDLN_SIZE); // create buffer and zero it
|
||||
_iconsole_cmdline.max_bytes = ICON_CMDLN_SIZE;
|
||||
_iconsole_cmdline.max_chars = ICON_CMDLN_SIZE;
|
||||
|
||||
IConsolePrintF(CC_WARNING, "OpenTTD Game Console Revision 7 - %s", _openttd_revision);
|
||||
IConsolePrint(CC_WHITE, "------------------------------------");
|
||||
IConsolePrint(CC_WHITE, "use \"help\" for more information");
|
||||
|
@ -374,7 +370,6 @@ void IConsoleClearBuffer()
|
|||
|
||||
void IConsoleGUIFree()
|
||||
{
|
||||
free(_iconsole_cmdline.buf);
|
||||
IConsoleClearBuffer();
|
||||
}
|
||||
|
||||
|
|
|
@ -239,6 +239,7 @@ public:
|
|||
void GenerateFileName()
|
||||
{
|
||||
GenerateDefaultSaveName(this->edit_str_buf, &this->edit_str_buf[this->edit_str_size - 1]);
|
||||
this->text.UpdateSize();
|
||||
}
|
||||
|
||||
SaveLoadWindow(const WindowDesc *desc, SaveLoadDialogMode mode) : QueryStringBaseWindow(64)
|
||||
|
@ -258,13 +259,12 @@ public:
|
|||
switch (mode) {
|
||||
case SLD_SAVE_GAME: this->GenerateFileName(); break;
|
||||
case SLD_SAVE_HEIGHTMAP:
|
||||
case SLD_SAVE_SCENARIO: strecpy(this->edit_str_buf, "UNNAMED", &this->edit_str_buf[edit_str_size - 1]); break;
|
||||
case SLD_SAVE_SCENARIO: this->text.Assign("UNNAMED"); break;
|
||||
default: break;
|
||||
}
|
||||
|
||||
this->ok_button = WID_SL_SAVE_GAME;
|
||||
this->afilter = CS_ALPHANUMERAL;
|
||||
this->text.Initialize(this->edit_str_buf, this->edit_str_size);
|
||||
|
||||
this->CreateNestedTree(desc, true);
|
||||
if (mode == SLD_LOAD_GAME) this->GetWidget<NWidgetStacked>(WID_SL_CONTENT_DOWNLOAD_SEL)->SetDisplayedPlane(SZSP_HORIZONTAL);
|
||||
|
@ -639,8 +639,6 @@ public:
|
|||
/* Reset file name to current date on successful delete */
|
||||
if (_saveload_mode == SLD_SAVE_GAME) GenerateFileName();
|
||||
}
|
||||
|
||||
this->text.UpdateSize();
|
||||
} else if (this->IsWidgetLowered(WID_SL_SAVE_GAME)) { // Save button clicked
|
||||
if (_saveload_mode == SLD_SAVE_GAME || _saveload_mode == SLD_SAVE_SCENARIO) {
|
||||
_switch_mode = SM_SAVE_GAME;
|
||||
|
|
|
@ -316,9 +316,7 @@ struct GenerateLandscapeWindow : public QueryStringBaseWindow {
|
|||
|
||||
this->LowerWidget(_settings_newgame.game_creation.landscape + WID_GL_TEMPERATE);
|
||||
|
||||
/* snprintf() always outputs trailing '\0', so whole buffer can be used */
|
||||
snprintf(this->edit_str_buf, this->edit_str_size, "%u", _settings_newgame.game_creation.generation_seed);
|
||||
this->text.Initialize(this->edit_str_buf, this->edit_str_size);
|
||||
this->text.Print("%u", _settings_newgame.game_creation.generation_seed);
|
||||
this->caption = STR_NULL;
|
||||
this->afilter = CS_NUMERAL;
|
||||
|
||||
|
|
|
@ -828,6 +828,8 @@ struct QueryStringWindow : public QueryStringBaseWindow
|
|||
*Utf8PrevChar(this->edit_str_buf + strlen(this->edit_str_buf)) = '\0';
|
||||
}
|
||||
|
||||
this->text.UpdateSize();
|
||||
|
||||
if ((flags & QSF_ACCEPT_UNCHANGED) == 0) this->orig = strdup(this->edit_str_buf);
|
||||
|
||||
this->caption = caption;
|
||||
|
@ -835,7 +837,6 @@ struct QueryStringWindow : public QueryStringBaseWindow
|
|||
this->ok_button = WID_QS_OK;
|
||||
this->afilter = afilter;
|
||||
this->flags = flags;
|
||||
this->text.Initialize(this->edit_str_buf, max_bytes, max_chars);
|
||||
|
||||
this->InitNested(desc, WN_QUERY_STRING);
|
||||
|
||||
|
|
|
@ -302,7 +302,6 @@ struct NetworkChatWindow : public QueryStringBaseWindow {
|
|||
this->cancel_button = WID_NC_CLOSE;
|
||||
this->ok_button = WID_NC_SENDBUTTON;
|
||||
this->afilter = CS_ALPHANUMERAL;
|
||||
this->text.Initialize(this->edit_str_buf, this->edit_str_size);
|
||||
|
||||
static const StringID chat_captions[] = {
|
||||
STR_NETWORK_CHAT_ALL_CAPTION,
|
||||
|
|
|
@ -417,7 +417,6 @@ public:
|
|||
this->GetWidget<NWidgetStacked>(WID_NCL_SEL_ALL_UPDATE)->SetDisplayedPlane(select_all);
|
||||
|
||||
this->afilter = CS_ALPHANUMERAL;
|
||||
this->text.Initialize(this->edit_str_buf, this->edit_str_size);
|
||||
this->SetFocusedWidget(WID_NCL_FILTER);
|
||||
|
||||
_network_content_client.AddCallback(this);
|
||||
|
|
|
@ -444,9 +444,8 @@ public:
|
|||
this->vscroll = this->GetScrollbar(WID_NG_SCROLLBAR);
|
||||
this->FinishInitNested(desc, WN_NETWORK_WINDOW_GAME);
|
||||
|
||||
ttd_strlcpy(this->edit_str_buf, _settings_client.network.client_name, this->edit_str_size);
|
||||
this->text.Assign(_settings_client.network.client_name);
|
||||
this->afilter = CS_ALPHANUMERAL;
|
||||
this->text.Initialize(this->edit_str_buf, this->edit_str_size);
|
||||
this->SetFocusedWidget(WID_NG_CLIENT);
|
||||
|
||||
this->last_joined = NetworkGameListAddItem(NetworkAddress(_settings_client.network.last_host, _settings_client.network.last_port));
|
||||
|
@ -1006,10 +1005,9 @@ struct NetworkStartServerWindow : public QueryStringBaseWindow {
|
|||
{
|
||||
this->InitNested(desc, WN_NETWORK_WINDOW_START);
|
||||
|
||||
ttd_strlcpy(this->edit_str_buf, _settings_client.network.server_name, this->edit_str_size);
|
||||
this->text.Assign(_settings_client.network.server_name);
|
||||
|
||||
this->afilter = CS_ALPHANUMERAL;
|
||||
this->text.Initialize(this->edit_str_buf, this->edit_str_size);
|
||||
this->SetFocusedWidget(WID_NSS_GAMENAME);
|
||||
}
|
||||
|
||||
|
@ -2112,7 +2110,6 @@ struct NetworkCompanyPasswordWindow : public QueryStringBaseWindow {
|
|||
this->cancel_button = WID_NCP_CANCEL;
|
||||
this->ok_button = WID_NCP_OK;
|
||||
this->afilter = CS_ALPHANUMERAL;
|
||||
this->text.Initialize(this->edit_str_buf, this->edit_str_size);
|
||||
this->SetFocusedWidget(WID_NCP_PASSWORD);
|
||||
}
|
||||
|
||||
|
|
|
@ -637,7 +637,6 @@ struct NewGRFWindow : public QueryStringBaseWindow, NewGRFScanCallback {
|
|||
this->GetWidget<NWidgetStacked>(WID_NS_SHOW_APPLY)->SetDisplayedPlane(this->editable ? 0 : this->show_params ? 1 : SZSP_HORIZONTAL);
|
||||
this->FinishInitNested(desc, WN_GAME_OPTIONS_NEWGRF_STATE);
|
||||
|
||||
this->text.Initialize(this->edit_str_buf, this->edit_str_size);
|
||||
this->SetFocusedWidget(WID_NS_FILTER);
|
||||
|
||||
this->avails.SetListing(this->last_sorting);
|
||||
|
|
|
@ -40,9 +40,11 @@ struct QueryString {
|
|||
bool handled;
|
||||
|
||||
/**
|
||||
* Make sure everything gets initialized properly.
|
||||
* Initialize string.
|
||||
* @param size Maximum size in bytes.
|
||||
* @param chars Maximum size in chars.
|
||||
*/
|
||||
QueryString() : ok_button(-1), cancel_button(-1), orig(NULL)
|
||||
QueryString(uint16 size, uint16 chars = UINT16_MAX) : ok_button(-1), cancel_button(-1), text(size, chars), orig(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -67,16 +69,10 @@ struct QueryStringBaseWindow : public Window, public QueryString {
|
|||
const uint16 edit_str_size; ///< Maximum length of string (in bytes), including terminating '\0'.
|
||||
const uint16 max_chars; ///< Maximum length of string (in characters), including terminating '\0'.
|
||||
|
||||
QueryStringBaseWindow(uint16 size, uint16 chars = UINT16_MAX) : Window(), edit_str_size(size), max_chars(chars == UINT16_MAX ? size : chars)
|
||||
QueryStringBaseWindow(uint16 size, uint16 chars = UINT16_MAX) : Window(), QueryString(size, chars), edit_str_buf(text.buf), edit_str_size(text.max_bytes), max_chars(text.max_chars)
|
||||
{
|
||||
assert(size != 0);
|
||||
this->edit_str_buf = CallocT<char>(size);
|
||||
}
|
||||
|
||||
~QueryStringBaseWindow()
|
||||
{
|
||||
free(this->edit_str_buf);
|
||||
}
|
||||
};
|
||||
|
||||
void ShowOnScreenKeyboard(QueryStringBaseWindow *parent, int button);
|
||||
|
|
|
@ -2002,7 +2002,6 @@ struct GameSettingsWindow : QueryStringBaseWindow {
|
|||
this->vscroll = this->GetScrollbar(WID_GS_SCROLLBAR);
|
||||
this->FinishInitNested(desc, WN_GAME_OPTIONS_GAME_SETTINGS);
|
||||
|
||||
this->text.Initialize(this->edit_str_buf, this->edit_str_size);
|
||||
this->SetFocusedWidget(WID_GS_FILTER);
|
||||
|
||||
this->InvalidateData();
|
||||
|
|
|
@ -159,8 +159,6 @@ struct SignListWindow : QueryStringBaseWindow, SignList {
|
|||
this->ok_button = WID_SIL_FILTER_ENTER_BTN;
|
||||
this->cancel_button = WID_SIL_FILTER_CLEAR_BTN;
|
||||
this->afilter = CS_ALPHANUMERAL;
|
||||
this->text.Initialize(this->edit_str_buf, MAX_LENGTH_SIGN_NAME_CHARS * MAX_CHAR_LENGTH, MAX_LENGTH_SIGN_NAME_CHARS);
|
||||
ClearFilterTextWidget();
|
||||
|
||||
/* Initialize the filtering variables */
|
||||
this->SetFilterString("");
|
||||
|
@ -450,19 +448,15 @@ struct SignWindow : QueryStringBaseWindow, SignList {
|
|||
|
||||
void UpdateSignEditWindow(const Sign *si)
|
||||
{
|
||||
char *last_of = &this->edit_str_buf[this->edit_str_size - 1]; // points to terminating '\0'
|
||||
|
||||
/* Display an empty string when the sign hasnt been edited yet */
|
||||
if (si->name != NULL) {
|
||||
SetDParam(0, si->index);
|
||||
GetString(this->edit_str_buf, STR_SIGN_NAME, last_of);
|
||||
this->text.Assign(STR_SIGN_NAME);
|
||||
} else {
|
||||
GetString(this->edit_str_buf, STR_EMPTY, last_of);
|
||||
this->text.DeleteAll();
|
||||
}
|
||||
*last_of = '\0';
|
||||
|
||||
this->cur_sign = si->index;
|
||||
this->text.Initialize(this->edit_str_buf, this->edit_str_size, this->max_chars);
|
||||
|
||||
this->SetWidgetDirty(WID_QES_TEXT);
|
||||
this->SetFocusedWidget(WID_QES_TEXT);
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#include "gfx_type.h"
|
||||
#include "gfx_func.h"
|
||||
#include "window_func.h"
|
||||
#include "core/alloc_func.hpp"
|
||||
|
||||
/**
|
||||
* Try to retrive the current clipboard contents.
|
||||
|
@ -350,17 +351,6 @@ bool Textbuf::MovePos(int navmode)
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the textbuffer by supplying it the buffer to write into
|
||||
* and the maximum length of this buffer
|
||||
* @param buf the buffer that will be holding the data for input
|
||||
* @param max_bytes maximum size in bytes, including terminating '\0'
|
||||
*/
|
||||
void Textbuf::Initialize(char *buf, uint16 max_bytes)
|
||||
{
|
||||
this->Initialize(buf, max_bytes, max_bytes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the textbuffer by supplying it the buffer to write into
|
||||
* and the maximum length of this buffer
|
||||
|
@ -368,16 +358,21 @@ void Textbuf::Initialize(char *buf, uint16 max_bytes)
|
|||
* @param max_bytes maximum size in bytes, including terminating '\0'
|
||||
* @param max_chars maximum size in chars, including terminating '\0'
|
||||
*/
|
||||
void Textbuf::Initialize(char *buf, uint16 max_bytes, uint16 max_chars)
|
||||
Textbuf::Textbuf(uint16 max_bytes, uint16 max_chars)
|
||||
: buf(MallocT<char>(max_bytes))
|
||||
{
|
||||
assert(max_bytes != 0);
|
||||
assert(max_chars != 0);
|
||||
|
||||
this->buf = buf;
|
||||
this->max_bytes = max_bytes;
|
||||
this->max_chars = max_chars;
|
||||
this->max_chars = max_chars == UINT16_MAX ? max_bytes : max_chars;
|
||||
this->caret = true;
|
||||
this->UpdateSize();
|
||||
this->DeleteAll();
|
||||
}
|
||||
|
||||
Textbuf::~Textbuf()
|
||||
{
|
||||
free(this->buf);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
|
||||
/** Helper/buffer for input fields. */
|
||||
struct Textbuf {
|
||||
char *buf; ///< buffer in which text is saved
|
||||
char * const buf; ///< buffer in which text is saved
|
||||
uint16 max_bytes; ///< the maximum size of the buffer in bytes (including terminating '\0')
|
||||
uint16 max_chars; ///< the maximum size of the buffer in characters (including terminating '\0')
|
||||
uint16 bytes; ///< the current size of the string in bytes (including terminating '\0')
|
||||
|
@ -27,8 +27,8 @@ struct Textbuf {
|
|||
uint16 caretpos; ///< the current position of the caret in the buffer, in bytes
|
||||
uint16 caretxoffs; ///< the current position of the caret in pixels
|
||||
|
||||
void Initialize(char *buf, uint16 max_bytes);
|
||||
void Initialize(char *buf, uint16 max_bytes, uint16 max_chars);
|
||||
explicit Textbuf(uint16 max_bytes, uint16 max_chars = UINT16_MAX);
|
||||
~Textbuf();
|
||||
|
||||
void Assign(StringID string);
|
||||
void Assign(const char *text);
|
||||
|
|
|
@ -995,7 +995,6 @@ public:
|
|||
params(_settings_game.game_creation.town_name)
|
||||
{
|
||||
this->InitNested(desc, window_number);
|
||||
this->text.Initialize(this->edit_str_buf, this->edit_str_size, this->max_chars);
|
||||
this->RandomTownName();
|
||||
this->UpdateButtons(true);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue