(svn r6937) -Codechange: Add an InitializeTextBuffer() function that handles setting up the

textbuffer instead of typing it out each and every time.
This commit is contained in:
Darkvater 2006-10-24 22:57:44 +00:00
parent 3760fe9a40
commit b63d946898
4 changed files with 26 additions and 31 deletions

View File

@ -513,13 +513,9 @@ static void _ShowGenerateLandscape(glwp_modes mode)
ttd_strlcpy(_edit_str_buf, str_fmt("%u", _patches_newgame.generation_seed), lengthof(_edit_str_buf));
querystr->text.caret = true;
querystr->text.maxlength = lengthof(_edit_str_buf);
querystr->text.maxwidth = 120;
querystr->text.buf = _edit_str_buf;
InitializeTextBuffer(&querystr->text, _edit_str_buf, lengthof(_edit_str_buf), 120);
querystr->caption = STR_NULL;
querystr->afilter = CS_NUMERAL;
UpdateTextBufferSize(&querystr->text);
InvalidateWindow(WC_GENERATE_LANDSCAPE, mode);
}

1
gui.h
View File

@ -112,6 +112,7 @@ bool DeleteTextBufferChar(Textbuf *tb, int delmode);
bool InsertTextBufferChar(Textbuf *tb, byte key);
bool InsertTextBufferClipboard(Textbuf *tb);
bool MoveTextBufferPos(Textbuf *tb, int navmode);
void InitializeTextBuffer(Textbuf *tb, const char *buf, uint16 maxlength, uint16 maxwidth);
void UpdateTextBufferSize(Textbuf *tb);
void BuildFileList(void);

View File

@ -879,6 +879,23 @@ bool MoveTextBufferPos(Textbuf *tb, int navmode)
return false;
}
/**
* Initialize the textbuffer by supplying it the buffer to write into
* and the maximum length of this buffer
* @param tb @Textbuf type which is getting initialized
* @param buf the buffer that will be holding the data for input
* @param maxlength maximum length in characters of this buffer
* @param maxwidth maximum length in pixels of this buffer. If reached, buffer
* cannot grow, even if maxlength would allow because there is space */
void InitializeTextBuffer(Textbuf *tb, const char *buf, uint16 maxlength, uint16 maxwidth)
{
tb->buf = (char*)buf;
tb->maxlength = maxlength;
tb->maxwidth = maxwidth;
tb->caret = true;
UpdateTextBufferSize(tb);
}
/**
* 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.
@ -1090,12 +1107,8 @@ void ShowQueryString(StringID str, StringID caption, uint maxlen, uint maxwidth,
WP(w, querystr_d).caption = caption;
WP(w, querystr_d).wnd_class = window_class;
WP(w, querystr_d).wnd_num = window_number;
WP(w, querystr_d).text.caret = false;
WP(w, querystr_d).text.maxlength = realmaxlen;
WP(w, querystr_d).text.maxwidth = maxwidth;
WP(w, querystr_d).text.buf = _edit_str_buf;
WP(w, querystr_d).afilter = afilter;
UpdateTextBufferSize(&WP(w, querystr_d).text);
InitializeTextBuffer(&WP(w, querystr_d).text, _edit_str_buf, realmaxlen, maxwidth);
}
static void QueryWndProc(Window *w, WindowEvent *e)
@ -1576,12 +1589,9 @@ void ShowSaveLoadDialog(int mode)
w->resize.step_height = 10;
w->resize.height = w->height - 14 * 10; // Minimum of 10 items
LowerWindowWidget(w, 7);
WP(w,querystr_d).text.caret = false;
WP(w,querystr_d).text.maxlength = lengthof(_edit_str_buf);
WP(w,querystr_d).text.maxwidth = 240;
WP(w,querystr_d).text.buf = _edit_str_buf;
WP(w,querystr_d).afilter = CS_ALPHANUMERAL;
UpdateTextBufferSize(&WP(w, querystr_d).text);
WP(w, querystr_d).afilter = CS_ALPHANUMERAL;
InitializeTextBuffer(&WP(w, querystr_d).text, _edit_str_buf, lengthof(_edit_str_buf), 240);
// pause is only used in single-player, non-editor mode, non-menu mode. It
// will be unpaused in the WE_DESTROY event handler.

View File

@ -563,12 +563,8 @@ void ShowNetworkGameWindow(void)
ttd_strlcpy(_edit_str_buf, _network_player_name, lengthof(_edit_str_buf));
w->vscroll.cap = 12;
querystr->text.caret = true;
querystr->text.maxlength = lengthof(_edit_str_buf);
querystr->text.maxwidth = 120;
querystr->text.buf = _edit_str_buf;
querystr->afilter = CS_ALPHANUMERAL;
UpdateTextBufferSize(&querystr->text);
InitializeTextBuffer(&querystr->text, _edit_str_buf, lengthof(_edit_str_buf), 120);
UpdateNetworkGameWindow(true);
}
@ -781,12 +777,8 @@ static void ShowNetworkStartServerWindow(void)
w->vscroll.cap = 12;
w->vscroll.count = _fios_num+1;
WP(w, network_ql_d).q.text.caret = true;
WP(w, network_ql_d).q.text.maxlength = lengthof(_edit_str_buf);
WP(w, network_ql_d).q.text.maxwidth = 160;
WP(w, network_ql_d).q.text.buf = _edit_str_buf;
WP(w, network_ql_d).q.afilter = CS_ALPHANUMERAL;
UpdateTextBufferSize(&WP(w, network_ql_d).q.text);
InitializeTextBuffer(&WP(w, network_ql_d).q.text, _edit_str_buf, lengthof(_edit_str_buf), 160);
}
static byte NetworkLobbyFindCompanyIndex(byte pos)
@ -1716,11 +1708,7 @@ void ShowNetworkChatQueryWindow(DestType type, byte dest)
WP(w,querystr_d).wnd_class = WC_MAIN_TOOLBAR;
WP(w,querystr_d).wnd_num = 0;
WP(w,querystr_d).afilter = CS_ALPHANUMERAL;
WP(w,querystr_d).text.caret = false;
WP(w,querystr_d).text.maxlength = lengthof(_edit_str_buf);
WP(w,querystr_d).text.maxwidth = w->widget[2].right - w->widget[2].left - 2; // widget[1] is the "text box"
WP(w,querystr_d).text.buf = _edit_str_buf;
UpdateTextBufferSize(&WP(w, querystr_d).text);
InitializeTextBuffer(&WP(w, querystr_d).text, _edit_str_buf, lengthof(_edit_str_buf), w->widget[2].right - w->widget[2].left);
}
#endif /* ENABLE_NETWORK */