summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--genworld_gui.c6
-rw-r--r--gui.h1
-rw-r--r--misc_gui.c32
-rw-r--r--network_gui.c18
4 files changed, 26 insertions, 31 deletions
diff --git a/genworld_gui.c b/genworld_gui.c
index 4d7e7c2a0..ee18fb227 100644
--- a/genworld_gui.c
+++ b/genworld_gui.c
@@ -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);
}
diff --git a/gui.h b/gui.h
index 46f0c3996..ddb9d8edd 100644
--- a/gui.h
+++ b/gui.h
@@ -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);
diff --git a/misc_gui.c b/misc_gui.c
index adbce4d56..854ad7bec 100644
--- a/misc_gui.c
+++ b/misc_gui.c
@@ -880,6 +880,23 @@ bool MoveTextBufferPos(Textbuf *tb, int navmode)
}
/**
+ * 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.
* Useful when copying in a larger amount of text at once
@@ -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.
diff --git a/network_gui.c b/network_gui.c
index 63e995721..d2ed26e52 100644
--- a/network_gui.c
+++ b/network_gui.c
@@ -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 */