summaryrefslogtreecommitdiff
path: root/network_gui.c
diff options
context:
space:
mode:
authorDarkvater <darkvater@openttd.org>2005-02-21 18:59:54 +0000
committerDarkvater <darkvater@openttd.org>2005-02-21 18:59:54 +0000
commitd865c55007321366d49b9b3d49eb0d61715dfc98 (patch)
treeac473756965e88790f53e13ff4589035499ce9c1 /network_gui.c
parent0d8dcacee2dbd1ae639f8851a2847b3806c7da16 (diff)
downloadopenttd-d865c55007321366d49b9b3d49eb0d61715dfc98.tar.xz
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
- Codechange: Introduction of Textbuf struct which not only holds physical data as length but also pixel-constrains (width) and information about the caret - Codechange: Move Clipboard function to OS specific file. Currently only Windows has clipboard actions - Feature: Editboxes, console and exit screen also accept the numeric-enter as a yes - Feature: Navigation through text with cursor keys is possible, as well as arbitrary insertion (also paste) and deletion; both backspace and del keys. Functions DeleteTextBufferChar, InsertTextBufferChar and InsertTextBufferClipboard handle input and deletion. Navigation is done through MoveTextBufferPos. - Fix: OTTD crash when opening 'add server' editbox - CodeChange: fix up some stringwidth calculations in gfx.c. You can get the width in pixels of a character by calling GetCharacterWidth().
Diffstat (limited to 'network_gui.c')
-rw-r--r--network_gui.c43
1 files changed, 24 insertions, 19 deletions
diff --git a/network_gui.c b/network_gui.c
index d2f1bd345..c749f37c2 100644
--- a/network_gui.c
+++ b/network_gui.c
@@ -449,10 +449,11 @@ void ShowNetworkGameWindow(void)
ttd_strlcpy(_edit_str_buf, _network_player_name, MAX_QUERYSTR_LEN);
w->vscroll.cap = 8;
- WP(w,querystr_d).caret = 1;
- WP(w,querystr_d).maxlen = MAX_QUERYSTR_LEN;
- WP(w,querystr_d).maxwidth = 120;
- WP(w,querystr_d).buf = _edit_str_buf;
+ WP(w, querystr_d).text.caret = true;
+ WP(w, querystr_d).text.maxlength = MAX_QUERYSTR_LEN - 1;
+ WP(w, querystr_d).text.maxwidth = 120;
+ WP(w, querystr_d).text.buf = _edit_str_buf;
+ UpdateTextBufferSize(&WP(w, querystr_d).text);
UpdateNetworkGameWindow(true);
}
@@ -553,7 +554,8 @@ static void NetworkStartServerWindowWndProc(Window *w, WindowEvent *e)
return;
case 13: /* Start game */
_is_network_server = true;
- ttd_strlcpy(_network_server_name, WP(w,querystr_d).buf, sizeof(_network_server_name));
+ ttd_strlcpy(_network_server_name, WP(w, querystr_d).text.buf, sizeof(_network_server_name));
+ UpdateTextBufferSize(&WP(w, querystr_d).text);
if(selected_map==NULL) { // start random new game
DoCommandP(0, Random(), InteractiveRandom(), NULL, CMD_GEN_RANDOM_NEW_GAME);
} else { // load a scenario
@@ -569,7 +571,8 @@ static void NetworkStartServerWindowWndProc(Window *w, WindowEvent *e)
break;
case 14: /* Load game */
_is_network_server = true;
- ttd_strlcpy(_network_server_name, WP(w,querystr_d).buf, sizeof(_network_server_name));
+ ttd_strlcpy(_network_server_name, WP(w, querystr_d).text.buf, sizeof(_network_server_name));
+ UpdateTextBufferSize(&WP(w, querystr_d).text);
snprintf(_network_game_info.map_name, sizeof(_network_game_info.map_name), "Loaded game");
/* XXX - WC_NETWORK_WINDOW should stay, but if it stays, it gets
* copied all the elements of 'load game' and upon closing that, it segfaults */
@@ -670,10 +673,11 @@ static void ShowNetworkStartServerWindow(void)
w->vscroll.cap = 9;
w->vscroll.count = _fios_num+1;
- WP(w,querystr_d).caret = 1;
- WP(w,querystr_d).maxlen = MAX_QUERYSTR_LEN;
- WP(w,querystr_d).maxwidth = 160;
- WP(w,querystr_d).buf = _edit_str_buf;
+ WP(w, querystr_d).text.caret = true;
+ WP(w, querystr_d).text.maxlength = MAX_QUERYSTR_LEN - 1;
+ WP(w, querystr_d).text.maxwidth = 160;
+ WP(w, querystr_d).text.buf = _edit_str_buf;
+ UpdateTextBufferSize(&WP(w, querystr_d).text);
}
static byte NetworkLobbyFindCompanyIndex(byte pos)
@@ -1371,12 +1375,12 @@ static void ChatWindowWndProc(Window *w, WindowEvent *e)
case 3: DeleteWindow(w); break; // Cancel
case 2: // Send
press_ok:;
- if (strcmp(WP(w,querystr_d).buf, WP(w,querystr_d).buf + MAX_QUERYSTR_LEN) == 0) {
+ if (strcmp(WP(w, querystr_d).text.buf, WP(w, querystr_d).text.buf + MAX_QUERYSTR_LEN) == 0) {
DeleteWindow(w);
} else {
- char *buf = WP(w,querystr_d).buf;
- WindowClass wnd_class = WP(w,querystr_d).wnd_class;
- WindowNumber wnd_num = WP(w,querystr_d).wnd_num;
+ char *buf = WP(w, querystr_d).text.buf;
+ WindowClass wnd_class = WP(w, querystr_d).wnd_class;
+ WindowNumber wnd_num = WP(w, querystr_d).wnd_num;
Window *parent;
// Mask the edit-box as closed, so we don't send out a CANCEL
@@ -1458,7 +1462,7 @@ void ShowChatWindow(StringID str, StringID caption, int maxlen, int maxwidth, by
GetString(_orig_edit_str_buf, str);
- _orig_edit_str_buf[maxlen] = 0;
+ _orig_edit_str_buf[maxlen] = '\0';
memcpy(_edit_str_buf, _orig_edit_str_buf, MAX_QUERYSTR_LEN);
@@ -1468,10 +1472,11 @@ void ShowChatWindow(StringID str, StringID caption, int maxlen, int maxwidth, by
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).caret = 0;
- WP(w,querystr_d).maxlen = maxlen;
- WP(w,querystr_d).maxwidth = maxwidth;
- WP(w,querystr_d).buf = _edit_str_buf;
+ WP(w,querystr_d).text.caret = false;
+ WP(w,querystr_d).text.maxlength = maxlen - 1;
+ WP(w,querystr_d).text.maxwidth = maxwidth;
+ WP(w,querystr_d).text.buf = _edit_str_buf;
+ UpdateTextBufferSize(&WP(w, querystr_d).text);
}
#else