annotate src/console_gui.cpp @ 17564:d5ff867052a5 draft

(svn r22328) -Add: a flag to GroundVehicles to disable insertion and removal of automatic orders until the next real order is reached.
author frosch <frosch@openttd.org>
date Sat, 16 Apr 2011 16:45:35 +0000 (2011-04-16)
parents d4e5d46b857a
children 2b51d78fc404
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9339
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
1 /* $Id$ */
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
2
12778
bc7926153e19 (svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents: 12582
diff changeset
3 /*
bc7926153e19 (svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents: 12582
diff changeset
4 * This file is part of OpenTTD.
bc7926153e19 (svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents: 12582
diff changeset
5 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
bc7926153e19 (svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents: 12582
diff changeset
6 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
bc7926153e19 (svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents: 12582
diff changeset
7 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
bc7926153e19 (svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents: 12582
diff changeset
8 */
bc7926153e19 (svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents: 12582
diff changeset
9
10238
12805d675e85 (svn r14466) -Doc: remove some obsolete parameters, fix a few parameter names in comments and add a little more doxygen documentation.
rubidium <rubidium@openttd.org>
parents: 10207
diff changeset
10 /** @file console_gui.cpp Handling the GUI of the in-game console. */
9339
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
11
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
12 #include "stdafx.h"
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
13 #include "textbuf_gui.h"
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
14 #include "window_gui.h"
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
15 #include "console_gui.h"
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
16 #include "console_internal.h"
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
17 #include "window_func.h"
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
18 #include "string_func.h"
15403
a20225598fa5 (svn r20046) -Feature [FS#3816]: Wrap console lines when they are too long.
alberth <alberth@openttd.org>
parents: 15379
diff changeset
19 #include "strings_func.h"
9339
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
20 #include "gfx_func.h"
9906
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
21 #include "settings_type.h"
14258
a899d4e5ee1a (svn r18809) -Codechange/Cleanup: remove unneeded headers from some files, if a header require a header make it include that header
rubidium <rubidium@openttd.org>
parents: 14084
diff changeset
22 #include "console_func.h"
9339
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
23 #include "rev.h"
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
24
15403
a20225598fa5 (svn r20046) -Feature [FS#3816]: Wrap console lines when they are too long.
alberth <alberth@openttd.org>
parents: 15379
diff changeset
25 #include "table/strings.h"
a20225598fa5 (svn r20046) -Feature [FS#3816]: Wrap console lines when they are too long.
alberth <alberth@openttd.org>
parents: 15379
diff changeset
26
15185
418c3a29b00b (svn r19814) -Codechange: give some more unnamed enums a name, in case they consisted of unrelated values use static const (u)int
rubidium <rubidium@openttd.org>
parents: 14258
diff changeset
27 static const uint ICON_HISTORY_SIZE = 20;
418c3a29b00b (svn r19814) -Codechange: give some more unnamed enums a name, in case they consisted of unrelated values use static const (u)int
rubidium <rubidium@openttd.org>
parents: 14258
diff changeset
28 static const uint ICON_LINE_SPACING = 2;
418c3a29b00b (svn r19814) -Codechange: give some more unnamed enums a name, in case they consisted of unrelated values use static const (u)int
rubidium <rubidium@openttd.org>
parents: 14258
diff changeset
29 static const uint ICON_RIGHT_BORDERWIDTH = 10;
418c3a29b00b (svn r19814) -Codechange: give some more unnamed enums a name, in case they consisted of unrelated values use static const (u)int
rubidium <rubidium@openttd.org>
parents: 14258
diff changeset
30 static const uint ICON_BOTTOM_BORDERWIDTH = 12;
9906
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
31
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
32 /**
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
33 * Container for a single line of console output
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
34 */
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
35 struct IConsoleLine {
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
36 static IConsoleLine *front; ///< The front of the console backlog buffer
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
37 static int size; ///< The amount of items in the backlog
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
38
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
39 IConsoleLine *previous; ///< The previous console message.
11082
9ec1f7eac0a0 (svn r15425) -Codechange: some color->colour changes and type safety.
rubidium <rubidium@openttd.org>
parents: 11081
diff changeset
40 char *buffer; ///< The data to store.
9ec1f7eac0a0 (svn r15425) -Codechange: some color->colour changes and type safety.
rubidium <rubidium@openttd.org>
parents: 11081
diff changeset
41 TextColour colour; ///< The colour of the line.
9ec1f7eac0a0 (svn r15425) -Codechange: some color->colour changes and type safety.
rubidium <rubidium@openttd.org>
parents: 11081
diff changeset
42 uint16 time; ///< The amount of time the line is in the backlog.
9906
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
43
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
44 /**
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
45 * Initialize the console line.
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
46 * @param buffer the data to print.
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
47 * @param colour the colour of the line.
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
48 */
11082
9ec1f7eac0a0 (svn r15425) -Codechange: some color->colour changes and type safety.
rubidium <rubidium@openttd.org>
parents: 11081
diff changeset
49 IConsoleLine(char *buffer, TextColour colour) :
9906
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
50 previous(IConsoleLine::front),
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
51 buffer(buffer),
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
52 colour(colour),
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
53 time(0)
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
54 {
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
55 IConsoleLine::front = this;
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
56 IConsoleLine::size++;
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
57 }
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
58
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
59 /**
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
60 * Clear this console line and any further ones.
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
61 */
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
62 ~IConsoleLine()
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
63 {
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
64 IConsoleLine::size--;
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
65 free(buffer);
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
66
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
67 delete previous;
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
68 }
9339
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
69
9906
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
70 /**
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
71 * Get the index-ed item in the list.
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
72 */
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
73 static const IConsoleLine *Get(uint index)
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
74 {
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
75 const IConsoleLine *item = IConsoleLine::front;
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
76 while (index != 0 && item != NULL) {
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
77 index--;
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
78 item = item->previous;
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
79 }
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
80
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
81 return item;
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
82 }
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
83
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
84 /**
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
85 * Truncate the list removing everything older than/more than the amount
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
86 * as specified in the config file.
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
87 * As a side effect also increase the time the other lines have been in
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
88 * the list.
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
89 * @return true if and only if items got removed.
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
90 */
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
91 static bool Truncate()
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
92 {
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
93 IConsoleLine *cur = IConsoleLine::front;
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
94 if (cur == NULL) return false;
9339
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
95
9906
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
96 int count = 1;
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
97 for (IConsoleLine *item = cur->previous; item != NULL; count++, cur = item, item = item->previous) {
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
98 if (item->time > _settings_client.gui.console_backlog_timeout &&
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
99 count > _settings_client.gui.console_backlog_length) {
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
100 delete item;
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
101 cur->previous = NULL;
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
102 return true;
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
103 }
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
104
9915
f0cea4aa2bf6 (svn r14068) -Fix (r14056): MSVC doesn't support typeof.
rubidium <rubidium@openttd.org>
parents: 9906
diff changeset
105 if (item->time != MAX_UVALUE(uint16)) item->time++;
9906
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
106 }
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
107
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
108 return false;
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
109 }
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
110
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
111 /**
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
112 * Reset the complete console line backlog.
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
113 */
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
114 static void Reset()
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
115 {
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
116 delete IConsoleLine::front;
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
117 IConsoleLine::front = NULL;
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
118 IConsoleLine::size = 0;
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
119 }
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
120 };
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
121
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
122 /* static */ IConsoleLine *IConsoleLine::front = NULL;
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
123 /* static */ int IConsoleLine::size = 0;
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
124
9339
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
125
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
126 /* ** main console cmd buffer ** */
9906
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
127 static Textbuf _iconsole_cmdline;
9339
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
128 static char *_iconsole_history[ICON_HISTORY_SIZE];
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
129 static byte _iconsole_historypos;
9906
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
130 IConsoleModes _iconsole_mode;
9339
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
131
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
132 /* *************** *
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
133 * end of header *
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
134 * *************** */
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
135
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
136 static void IConsoleClearCommand()
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
137 {
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
138 memset(_iconsole_cmdline.buf, 0, ICON_CMDLN_SIZE);
16676
00850d1ba2f2 (svn r21407) -Codechange: prepare the text buffer code for limiting on number of characters besides the number of bytes
rubidium <rubidium@openttd.org>
parents: 16675
diff changeset
139 _iconsole_cmdline.chars = _iconsole_cmdline.bytes = 1; // only terminating zero
16675
4df98a0bd2ce (svn r21406) -Codechange: rename some textbuf related names to make them a bit more descriptive
rubidium <rubidium@openttd.org>
parents: 16296
diff changeset
140 _iconsole_cmdline.pixels = 0;
9339
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
141 _iconsole_cmdline.caretpos = 0;
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
142 _iconsole_cmdline.caretxoffs = 0;
13034
6eb3f749890a (svn r17532) -Codechange: Rename several Invalidate functions to SetDirty for more consistency and distinguishability.
frosch <frosch@openttd.org>
parents: 13027
diff changeset
143 SetWindowDirty(WC_CONSOLE, 0);
9339
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
144 }
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
145
15376
9c8bdca196f7 (svn r20019) -Codechange: Apply function code style to a few small functions.
alberth <alberth@openttd.org>
parents: 15185
diff changeset
146 static inline void IConsoleResetHistoryPos()
9c8bdca196f7 (svn r20019) -Codechange: Apply function code style to a few small functions.
alberth <alberth@openttd.org>
parents: 15185
diff changeset
147 {
9c8bdca196f7 (svn r20019) -Codechange: Apply function code style to a few small functions.
alberth <alberth@openttd.org>
parents: 15185
diff changeset
148 _iconsole_historypos = ICON_HISTORY_SIZE - 1;
9c8bdca196f7 (svn r20019) -Codechange: Apply function code style to a few small functions.
alberth <alberth@openttd.org>
parents: 15185
diff changeset
149 }
9339
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
150
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
151
14084
fb4726ae5f67 (svn r18631) -Fix [FS#3419]: when making a screenshot from the console the currently executed command would be shown twice
rubidium <rubidium@openttd.org>
parents: 13796
diff changeset
152 static const char *IConsoleHistoryAdd(const char *cmd);
9339
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
153 static void IConsoleHistoryNavigate(int direction);
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
154
12582
e4e3a1de73b5 (svn r17022) -Codechange: Use nested widgets for the console window.
alberth <alberth@openttd.org>
parents: 12003
diff changeset
155 /** Widgets of the console window. */
e4e3a1de73b5 (svn r17022) -Codechange: Use nested widgets for the console window.
alberth <alberth@openttd.org>
parents: 12003
diff changeset
156 enum ConsoleWidgets {
e4e3a1de73b5 (svn r17022) -Codechange: Use nested widgets for the console window.
alberth <alberth@openttd.org>
parents: 12003
diff changeset
157 CW_BACKGROUND, ///< Background of the console
e4e3a1de73b5 (svn r17022) -Codechange: Use nested widgets for the console window.
alberth <alberth@openttd.org>
parents: 12003
diff changeset
158 };
e4e3a1de73b5 (svn r17022) -Codechange: Use nested widgets for the console window.
alberth <alberth@openttd.org>
parents: 12003
diff changeset
159
e4e3a1de73b5 (svn r17022) -Codechange: Use nested widgets for the console window.
alberth <alberth@openttd.org>
parents: 12003
diff changeset
160 static const struct NWidgetPart _nested_console_window_widgets[] = {
e4e3a1de73b5 (svn r17022) -Codechange: Use nested widgets for the console window.
alberth <alberth@openttd.org>
parents: 12003
diff changeset
161 NWidget(WWT_EMPTY, INVALID_COLOUR, CW_BACKGROUND), SetResize(1, 1),
e4e3a1de73b5 (svn r17022) -Codechange: Use nested widgets for the console window.
alberth <alberth@openttd.org>
parents: 12003
diff changeset
162 };
e4e3a1de73b5 (svn r17022) -Codechange: Use nested widgets for the console window.
alberth <alberth@openttd.org>
parents: 12003
diff changeset
163
e4e3a1de73b5 (svn r17022) -Codechange: Use nested widgets for the console window.
alberth <alberth@openttd.org>
parents: 12003
diff changeset
164 static const WindowDesc _console_window_desc(
13796
3e68f07eb821 (svn r18322) -Codechange: remove the WDP duplication; no need to tell the same twice.
rubidium <rubidium@openttd.org>
parents: 13792
diff changeset
165 WDP_MANUAL, 0, 0,
12582
e4e3a1de73b5 (svn r17022) -Codechange: Use nested widgets for the console window.
alberth <alberth@openttd.org>
parents: 12003
diff changeset
166 WC_CONSOLE, WC_NONE,
e4e3a1de73b5 (svn r17022) -Codechange: Use nested widgets for the console window.
alberth <alberth@openttd.org>
parents: 12003
diff changeset
167 0,
13564
bae287664b02 (svn r18086) -Codechange: remove 'widget' from WindowDesc
rubidium <rubidium@openttd.org>
parents: 13509
diff changeset
168 _nested_console_window_widgets, lengthof(_nested_console_window_widgets)
12582
e4e3a1de73b5 (svn r17022) -Codechange: Use nested widgets for the console window.
alberth <alberth@openttd.org>
parents: 12003
diff changeset
169 );
e4e3a1de73b5 (svn r17022) -Codechange: Use nested widgets for the console window.
alberth <alberth@openttd.org>
parents: 12003
diff changeset
170
9339
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
171 struct IConsoleWindow : Window
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
172 {
9906
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
173 static int scroll;
15379
46202127b446 (svn r20022) -Doc: Add some doxygen comments.
alberth <alberth@openttd.org>
parents: 15376
diff changeset
174 int line_height; ///< Height of one line of text in the console.
11641
f4e14efa6fdf (svn r16021) -Codechange: Offset current console output by (width of "] ")+5 pixels instead of 5+5 pixels.
peter1138 <peter1138@openttd.org>
parents: 11640
diff changeset
175 int line_offset;
9339
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
176
12582
e4e3a1de73b5 (svn r17022) -Codechange: Use nested widgets for the console window.
alberth <alberth@openttd.org>
parents: 12003
diff changeset
177 IConsoleWindow() : Window()
9339
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
178 {
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
179 _iconsole_mode = ICONSOLE_OPENED;
17239
8beedf93c8b2 (svn r21979) -Fix: Scrolling of the console in pages used wrong line height and scrolled too much.
frosch <frosch@openttd.org>
parents: 17238
diff changeset
180 this->line_height = FONT_HEIGHT_NORMAL + ICON_LINE_SPACING;
11641
f4e14efa6fdf (svn r16021) -Codechange: Offset current console output by (width of "] ")+5 pixels instead of 5+5 pixels.
peter1138 <peter1138@openttd.org>
parents: 11640
diff changeset
181 this->line_offset = GetStringBoundingBox("] ").width + 5;
12582
e4e3a1de73b5 (svn r17022) -Codechange: Use nested widgets for the console window.
alberth <alberth@openttd.org>
parents: 12003
diff changeset
182
e4e3a1de73b5 (svn r17022) -Codechange: Use nested widgets for the console window.
alberth <alberth@openttd.org>
parents: 12003
diff changeset
183 this->InitNested(&_console_window_desc, 0);
e4e3a1de73b5 (svn r17022) -Codechange: Use nested widgets for the console window.
alberth <alberth@openttd.org>
parents: 12003
diff changeset
184 ResizeWindow(this, _screen.width, _screen.height / 3);
9339
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
185 }
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
186
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
187 ~IConsoleWindow()
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
188 {
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
189 _iconsole_mode = ICONSOLE_CLOSED;
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
190 }
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
191
17241
93cee045fcfb (svn r21981) -Codechange: Deduplicate the code and unify the bounds of console scrolling.
frosch <frosch@openttd.org>
parents: 17240
diff changeset
192 /**
93cee045fcfb (svn r21981) -Codechange: Deduplicate the code and unify the bounds of console scrolling.
frosch <frosch@openttd.org>
parents: 17240
diff changeset
193 * Scroll the content of the console.
93cee045fcfb (svn r21981) -Codechange: Deduplicate the code and unify the bounds of console scrolling.
frosch <frosch@openttd.org>
parents: 17240
diff changeset
194 * @param amount Number of lines to scroll back.
93cee045fcfb (svn r21981) -Codechange: Deduplicate the code and unify the bounds of console scrolling.
frosch <frosch@openttd.org>
parents: 17240
diff changeset
195 */
93cee045fcfb (svn r21981) -Codechange: Deduplicate the code and unify the bounds of console scrolling.
frosch <frosch@openttd.org>
parents: 17240
diff changeset
196 void Scroll(int amount)
93cee045fcfb (svn r21981) -Codechange: Deduplicate the code and unify the bounds of console scrolling.
frosch <frosch@openttd.org>
parents: 17240
diff changeset
197 {
93cee045fcfb (svn r21981) -Codechange: Deduplicate the code and unify the bounds of console scrolling.
frosch <frosch@openttd.org>
parents: 17240
diff changeset
198 int max_scroll = max<int>(0, IConsoleLine::size + 1 - this->height / this->line_height);
93cee045fcfb (svn r21981) -Codechange: Deduplicate the code and unify the bounds of console scrolling.
frosch <frosch@openttd.org>
parents: 17240
diff changeset
199 IConsoleWindow::scroll = Clamp<int>(IConsoleWindow::scroll + amount, 0, max_scroll);
93cee045fcfb (svn r21981) -Codechange: Deduplicate the code and unify the bounds of console scrolling.
frosch <frosch@openttd.org>
parents: 17240
diff changeset
200 this->SetDirty();
93cee045fcfb (svn r21981) -Codechange: Deduplicate the code and unify the bounds of console scrolling.
frosch <frosch@openttd.org>
parents: 17240
diff changeset
201 }
93cee045fcfb (svn r21981) -Codechange: Deduplicate the code and unify the bounds of console scrolling.
frosch <frosch@openttd.org>
parents: 17240
diff changeset
202
9339
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
203 virtual void OnPaint()
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
204 {
11483
f45b22901ffa (svn r15844) -Codechange: allow text alignment to be forced so the console and ai debug output don't get swapped (those are untranslateable anyways)
rubidium <rubidium@openttd.org>
parents: 11436
diff changeset
205 const int right = this->width - 5;
11436
caf4456fbbf3 (svn r15794) -Codechange: remove the DoDrawString part of the old text drawing API
rubidium <rubidium@openttd.org>
parents: 11373
diff changeset
206
17238
1c89caffa68d (svn r21978) -Codechange/Fix: Remove usage of Window::top and left from IConsoleWindow::OnPaint(). Drawing is done relative to the window position. But as the position is (0,0) anyway, it was not noticeable.
frosch <frosch@openttd.org>
parents: 17159
diff changeset
207 GfxFillRect(0, 0, this->width - 1, this->height - 1, 0);
17239
8beedf93c8b2 (svn r21979) -Fix: Scrolling of the console in pages used wrong line height and scrolled too much.
frosch <frosch@openttd.org>
parents: 17238
diff changeset
208 int ypos = this->height - this->line_height;
15403
a20225598fa5 (svn r20046) -Feature [FS#3816]: Wrap console lines when they are too long.
alberth <alberth@openttd.org>
parents: 15379
diff changeset
209 for (const IConsoleLine *print = IConsoleLine::Get(IConsoleWindow::scroll); print != NULL; print = print->previous) {
a20225598fa5 (svn r20046) -Feature [FS#3816]: Wrap console lines when they are too long.
alberth <alberth@openttd.org>
parents: 15379
diff changeset
210 SetDParamStr(0, print->buffer);
17240
b62138a80b9a (svn r21980) -Codechange: Draw one line more at the top of the console, i.e. clip the top-most line if there is not enough room instead of not drawing it at all.
frosch <frosch@openttd.org>
parents: 17239
diff changeset
211 ypos = DrawStringMultiLine(5, right, -this->line_height, ypos, STR_JUST_RAW_STRING, print->colour, SA_LEFT | SA_BOTTOM | SA_FORCE) - ICON_LINE_SPACING;
b62138a80b9a (svn r21980) -Codechange: Draw one line more at the top of the console, i.e. clip the top-most line if there is not enough room instead of not drawing it at all.
frosch <frosch@openttd.org>
parents: 17239
diff changeset
212 if (ypos < 0) break;
9339
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
213 }
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
214 /* If the text is longer than the window, don't show the starting ']' */
16675
4df98a0bd2ce (svn r21406) -Codechange: rename some textbuf related names to make them a bit more descriptive
rubidium <rubidium@openttd.org>
parents: 16296
diff changeset
215 int delta = this->width - this->line_offset - _iconsole_cmdline.pixels - ICON_RIGHT_BORDERWIDTH;
9339
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
216 if (delta > 0) {
11640
46a1311409f3 (svn r16020) -Codechange: Use actual font height for console output instead of fixed value.
peter1138 <peter1138@openttd.org>
parents: 11533
diff changeset
217 DrawString(5, right, this->height - this->line_height, "]", (TextColour)CC_COMMAND, SA_LEFT | SA_FORCE);
9339
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
218 delta = 0;
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
219 }
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
220
11641
f4e14efa6fdf (svn r16021) -Codechange: Offset current console output by (width of "] ")+5 pixels instead of 5+5 pixels.
peter1138 <peter1138@openttd.org>
parents: 11640
diff changeset
221 DrawString(this->line_offset + delta, right, this->height - this->line_height, _iconsole_cmdline.buf, (TextColour)CC_COMMAND, SA_LEFT | SA_FORCE);
9339
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
222
11081
0a26df8849a2 (svn r15424) -Codechange: make it possible to have multiple windows with edit box open simultaniously (Zuu).
rubidium <rubidium@openttd.org>
parents: 10960
diff changeset
223 if (_focused_window == this && _iconsole_cmdline.caret) {
11641
f4e14efa6fdf (svn r16021) -Codechange: Offset current console output by (width of "] ")+5 pixels instead of 5+5 pixels.
peter1138 <peter1138@openttd.org>
parents: 11640
diff changeset
224 DrawString(this->line_offset + delta + _iconsole_cmdline.caretxoffs, right, this->height - this->line_height, "_", TC_WHITE, SA_LEFT | SA_FORCE);
9339
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
225 }
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
226 }
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
227
9906
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
228 virtual void OnHundredthTick()
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
229 {
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
230 if (IConsoleLine::Truncate() &&
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
231 (IConsoleWindow::scroll > IConsoleLine::size)) {
11640
46a1311409f3 (svn r16020) -Codechange: Use actual font height for console output instead of fixed value.
peter1138 <peter1138@openttd.org>
parents: 11533
diff changeset
232 IConsoleWindow::scroll = max(0, IConsoleLine::size - (this->height / this->line_height) + 1);
9906
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
233 this->SetDirty();
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
234 }
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
235 }
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
236
9339
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
237 virtual void OnMouseLoop()
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
238 {
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
239 if (HandleCaret(&_iconsole_cmdline)) this->SetDirty();
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
240 }
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
241
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
242 virtual EventState OnKeyPress(uint16 key, uint16 keycode)
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
243 {
11081
0a26df8849a2 (svn r15424) -Codechange: make it possible to have multiple windows with edit box open simultaniously (Zuu).
rubidium <rubidium@openttd.org>
parents: 10960
diff changeset
244 if (_focused_window != this) return ES_NOT_HANDLED;
0a26df8849a2 (svn r15424) -Codechange: make it possible to have multiple windows with edit box open simultaniously (Zuu).
rubidium <rubidium@openttd.org>
parents: 10960
diff changeset
245
11640
46a1311409f3 (svn r16020) -Codechange: Use actual font height for console output instead of fixed value.
peter1138 <peter1138@openttd.org>
parents: 11533
diff changeset
246 const int scroll_height = (this->height / this->line_height) - 1;
9339
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
247 switch (keycode) {
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
248 case WKC_UP:
11361
02313cc6114e (svn r15711) -Codechange: lots of whitespace cleanup/fixes
rubidium <rubidium@openttd.org>
parents: 11085
diff changeset
249 IConsoleHistoryNavigate(1);
9339
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
250 this->SetDirty();
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
251 break;
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
252
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
253 case WKC_DOWN:
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
254 IConsoleHistoryNavigate(-1);
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
255 this->SetDirty();
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
256 break;
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
257
9906
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
258 case WKC_SHIFT | WKC_PAGEDOWN:
17241
93cee045fcfb (svn r21981) -Codechange: Deduplicate the code and unify the bounds of console scrolling.
frosch <frosch@openttd.org>
parents: 17240
diff changeset
259 this->Scroll(-scroll_height);
9339
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
260 break;
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
261
9906
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
262 case WKC_SHIFT | WKC_PAGEUP:
17241
93cee045fcfb (svn r21981) -Codechange: Deduplicate the code and unify the bounds of console scrolling.
frosch <frosch@openttd.org>
parents: 17240
diff changeset
263 this->Scroll(scroll_height);
9339
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
264 break;
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
265
9906
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
266 case WKC_SHIFT | WKC_DOWN:
17241
93cee045fcfb (svn r21981) -Codechange: Deduplicate the code and unify the bounds of console scrolling.
frosch <frosch@openttd.org>
parents: 17240
diff changeset
267 this->Scroll(-1);
9339
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
268 break;
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
269
9906
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
270 case WKC_SHIFT | WKC_UP:
17241
93cee045fcfb (svn r21981) -Codechange: Deduplicate the code and unify the bounds of console scrolling.
frosch <frosch@openttd.org>
parents: 17240
diff changeset
271 this->Scroll(1);
9339
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
272 break;
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
273
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
274 case WKC_BACKQUOTE:
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
275 IConsoleSwitch();
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
276 break;
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
277
14084
fb4726ae5f67 (svn r18631) -Fix [FS#3419]: when making a screenshot from the console the currently executed command would be shown twice
rubidium <rubidium@openttd.org>
parents: 13796
diff changeset
278 case WKC_RETURN: case WKC_NUM_ENTER: {
16296
f5af9ed0a445 (svn r21004) -Fix [FS#3746]: chat/console messages got sometimes messed up due to LTR names in RTL translations and vice-versa
rubidium <rubidium@openttd.org>
parents: 15627
diff changeset
279 /* We always want the ] at the left side; we always force these strings to be left
f5af9ed0a445 (svn r21004) -Fix [FS#3746]: chat/console messages got sometimes messed up due to LTR names in RTL translations and vice-versa
rubidium <rubidium@openttd.org>
parents: 15627
diff changeset
280 * aligned anyway. So enforce this in all cases by addding a left-to-right marker,
f5af9ed0a445 (svn r21004) -Fix [FS#3746]: chat/console messages got sometimes messed up due to LTR names in RTL translations and vice-versa
rubidium <rubidium@openttd.org>
parents: 15627
diff changeset
281 * otherwise it will be drawn at the wrong side with right-to-left texts. */
f5af9ed0a445 (svn r21004) -Fix [FS#3746]: chat/console messages got sometimes messed up due to LTR names in RTL translations and vice-versa
rubidium <rubidium@openttd.org>
parents: 15627
diff changeset
282 IConsolePrintF(CC_COMMAND, LRM "] %s", _iconsole_cmdline.buf);
14084
fb4726ae5f67 (svn r18631) -Fix [FS#3419]: when making a screenshot from the console the currently executed command would be shown twice
rubidium <rubidium@openttd.org>
parents: 13796
diff changeset
283 const char *cmd = IConsoleHistoryAdd(_iconsole_cmdline.buf);
fb4726ae5f67 (svn r18631) -Fix [FS#3419]: when making a screenshot from the console the currently executed command would be shown twice
rubidium <rubidium@openttd.org>
parents: 13796
diff changeset
284 IConsoleClearCommand();
9339
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
285
14084
fb4726ae5f67 (svn r18631) -Fix [FS#3419]: when making a screenshot from the console the currently executed command would be shown twice
rubidium <rubidium@openttd.org>
parents: 13796
diff changeset
286 if (cmd != NULL) IConsoleCmdExec(cmd);
15618
e4640748f223 (svn r20281) -Codechange: unify case scope closure + break coding style
rubidium <rubidium@openttd.org>
parents: 15403
diff changeset
287 break;
e4640748f223 (svn r20281) -Codechange: unify case scope closure + break coding style
rubidium <rubidium@openttd.org>
parents: 15403
diff changeset
288 }
9339
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
289
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
290 case WKC_CTRL | WKC_RETURN:
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
291 _iconsole_mode = (_iconsole_mode == ICONSOLE_FULL) ? ICONSOLE_OPENED : ICONSOLE_FULL;
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
292 IConsoleResize(this);
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
293 MarkWholeScreenDirty();
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
294 break;
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
295
13201
4ebcd304709f (svn r17708) -Feature [FS#2053]: [OSX] Implement clipboard support for OS X.
michi_cc <michi_cc@openttd.org>
parents: 13186
diff changeset
296 #ifdef WITH_COCOA
4ebcd304709f (svn r17708) -Feature [FS#2053]: [OSX] Implement clipboard support for OS X.
michi_cc <michi_cc@openttd.org>
parents: 13186
diff changeset
297 case (WKC_META | 'V'):
4ebcd304709f (svn r17708) -Feature [FS#2053]: [OSX] Implement clipboard support for OS X.
michi_cc <michi_cc@openttd.org>
parents: 13186
diff changeset
298 #endif
9339
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
299 case (WKC_CTRL | 'V'):
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
300 if (InsertTextBufferClipboard(&_iconsole_cmdline)) {
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
301 IConsoleResetHistoryPos();
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
302 this->SetDirty();
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
303 }
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
304 break;
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
305
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
306 case (WKC_CTRL | 'L'):
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
307 IConsoleCmdExec("clear");
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
308 break;
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
309
13201
4ebcd304709f (svn r17708) -Feature [FS#2053]: [OSX] Implement clipboard support for OS X.
michi_cc <michi_cc@openttd.org>
parents: 13186
diff changeset
310 #ifdef WITH_COCOA
4ebcd304709f (svn r17708) -Feature [FS#2053]: [OSX] Implement clipboard support for OS X.
michi_cc <michi_cc@openttd.org>
parents: 13186
diff changeset
311 case (WKC_META | 'U'):
4ebcd304709f (svn r17708) -Feature [FS#2053]: [OSX] Implement clipboard support for OS X.
michi_cc <michi_cc@openttd.org>
parents: 13186
diff changeset
312 #endif
9339
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
313 case (WKC_CTRL | 'U'):
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
314 DeleteTextBufferAll(&_iconsole_cmdline);
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
315 this->SetDirty();
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
316 break;
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
317
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
318 case WKC_BACKSPACE: case WKC_DELETE:
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
319 if (DeleteTextBufferChar(&_iconsole_cmdline, keycode)) {
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
320 IConsoleResetHistoryPos();
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
321 this->SetDirty();
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
322 }
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
323 break;
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
324
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
325 case WKC_LEFT: case WKC_RIGHT: case WKC_END: case WKC_HOME:
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
326 if (MoveTextBufferPos(&_iconsole_cmdline, keycode)) {
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
327 IConsoleResetHistoryPos();
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
328 this->SetDirty();
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
329 }
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
330 break;
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
331
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
332 default:
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
333 if (IsValidChar(key, CS_ALPHANUMERAL)) {
9906
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
334 IConsoleWindow::scroll = 0;
9339
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
335 InsertTextBufferChar(&_iconsole_cmdline, key);
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
336 IConsoleResetHistoryPos();
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
337 this->SetDirty();
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
338 } else {
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
339 return ES_NOT_HANDLED;
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
340 }
15627
60dd850a47d6 (svn r20290) -Codechange: Add missing 'break' statements.
alberth <alberth@openttd.org>
parents: 15618
diff changeset
341 break;
9339
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
342 }
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
343 return ES_HANDLED;
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
344 }
17242
d4e5d46b857a (svn r21982) -Add: Wheel scrolling to console.
frosch <frosch@openttd.org>
parents: 17241
diff changeset
345
d4e5d46b857a (svn r21982) -Add: Wheel scrolling to console.
frosch <frosch@openttd.org>
parents: 17241
diff changeset
346 virtual void OnMouseWheel(int wheel)
d4e5d46b857a (svn r21982) -Add: Wheel scrolling to console.
frosch <frosch@openttd.org>
parents: 17241
diff changeset
347 {
d4e5d46b857a (svn r21982) -Add: Wheel scrolling to console.
frosch <frosch@openttd.org>
parents: 17241
diff changeset
348 this->Scroll(-wheel);
d4e5d46b857a (svn r21982) -Add: Wheel scrolling to console.
frosch <frosch@openttd.org>
parents: 17241
diff changeset
349 }
9339
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
350 };
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
351
9906
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
352 int IConsoleWindow::scroll = 0;
9339
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
353
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
354 void IConsoleGUIInit()
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
355 {
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
356 _iconsole_historypos = ICON_HISTORY_SIZE - 1;
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
357 _iconsole_mode = ICONSOLE_CLOSED;
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
358
9906
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
359 IConsoleLine::Reset();
9339
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
360 memset(_iconsole_history, 0, sizeof(_iconsole_history));
9906
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
361
9339
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
362 _iconsole_cmdline.buf = CallocT<char>(ICON_CMDLN_SIZE); // create buffer and zero it
16675
4df98a0bd2ce (svn r21406) -Codechange: rename some textbuf related names to make them a bit more descriptive
rubidium <rubidium@openttd.org>
parents: 16296
diff changeset
363 _iconsole_cmdline.max_bytes = ICON_CMDLN_SIZE;
16676
00850d1ba2f2 (svn r21407) -Codechange: prepare the text buffer code for limiting on number of characters besides the number of bytes
rubidium <rubidium@openttd.org>
parents: 16675
diff changeset
364 _iconsole_cmdline.max_chars = ICON_CMDLN_SIZE;
9339
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
365
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
366 IConsolePrintF(CC_WARNING, "OpenTTD Game Console Revision 7 - %s", _openttd_revision);
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
367 IConsolePrint(CC_WHITE, "------------------------------------");
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
368 IConsolePrint(CC_WHITE, "use \"help\" for more information");
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
369 IConsolePrint(CC_WHITE, "");
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
370 IConsoleClearCommand();
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
371 }
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
372
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
373 void IConsoleClearBuffer()
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
374 {
9906
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
375 IConsoleLine::Reset();
9339
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
376 }
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
377
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
378 void IConsoleGUIFree()
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
379 {
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
380 free(_iconsole_cmdline.buf);
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
381 IConsoleClearBuffer();
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
382 }
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
383
15379
46202127b446 (svn r20022) -Doc: Add some doxygen comments.
alberth <alberth@openttd.org>
parents: 15376
diff changeset
384 /** Change the size of the in-game console window after the screen size changed, or the window state changed. */
9339
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
385 void IConsoleResize(Window *w)
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
386 {
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
387 switch (_iconsole_mode) {
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
388 case ICONSOLE_OPENED:
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
389 w->height = _screen.height / 3;
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
390 w->width = _screen.width;
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
391 break;
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
392 case ICONSOLE_FULL:
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
393 w->height = _screen.height - ICON_BOTTOM_BORDERWIDTH;
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
394 w->width = _screen.width;
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
395 break;
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
396 default: return;
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
397 }
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
398
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
399 MarkWholeScreenDirty();
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
400 }
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
401
15379
46202127b446 (svn r20022) -Doc: Add some doxygen comments.
alberth <alberth@openttd.org>
parents: 15376
diff changeset
402 /** Toggle in-game console between opened and closed. */
9339
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
403 void IConsoleSwitch()
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
404 {
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
405 switch (_iconsole_mode) {
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
406 case ICONSOLE_CLOSED:
11533
80379bc12cb3 (svn r15894) -Codechange: remove console widget array (it was empty anyway) and window desc
glx <glx@openttd.org>
parents: 11483
diff changeset
407 new IConsoleWindow();
9339
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
408 break;
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
409
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
410 case ICONSOLE_OPENED: case ICONSOLE_FULL:
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
411 DeleteWindowById(WC_CONSOLE, 0);
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
412 break;
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
413 }
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
414
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
415 MarkWholeScreenDirty();
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
416 }
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
417
15376
9c8bdca196f7 (svn r20019) -Codechange: Apply function code style to a few small functions.
alberth <alberth@openttd.org>
parents: 15185
diff changeset
418 /** Close the in-game console. */
9c8bdca196f7 (svn r20019) -Codechange: Apply function code style to a few small functions.
alberth <alberth@openttd.org>
parents: 15185
diff changeset
419 void IConsoleClose()
9c8bdca196f7 (svn r20019) -Codechange: Apply function code style to a few small functions.
alberth <alberth@openttd.org>
parents: 15185
diff changeset
420 {
9c8bdca196f7 (svn r20019) -Codechange: Apply function code style to a few small functions.
alberth <alberth@openttd.org>
parents: 15185
diff changeset
421 if (_iconsole_mode == ICONSOLE_OPENED) IConsoleSwitch();
9c8bdca196f7 (svn r20019) -Codechange: Apply function code style to a few small functions.
alberth <alberth@openttd.org>
parents: 15185
diff changeset
422 }
9339
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
423
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
424 /**
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
425 * Add the entered line into the history so you can look it back
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
426 * scroll, etc. Put it to the beginning as it is the latest text
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
427 * @param cmd Text to be entered into the 'history'
14084
fb4726ae5f67 (svn r18631) -Fix [FS#3419]: when making a screenshot from the console the currently executed command would be shown twice
rubidium <rubidium@openttd.org>
parents: 13796
diff changeset
428 * @return the command to execute
9339
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
429 */
14084
fb4726ae5f67 (svn r18631) -Fix [FS#3419]: when making a screenshot from the console the currently executed command would be shown twice
rubidium <rubidium@openttd.org>
parents: 13796
diff changeset
430 static const char *IConsoleHistoryAdd(const char *cmd)
9339
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
431 {
12003
dae3a822e71b (svn r16409) -Change: don't add empty lines/duplicates of the previous command to the console's history
rubidium <rubidium@openttd.org>
parents: 11641
diff changeset
432 /* Strip all spaces at the begin */
dae3a822e71b (svn r16409) -Change: don't add empty lines/duplicates of the previous command to the console's history
rubidium <rubidium@openttd.org>
parents: 11641
diff changeset
433 while (IsWhitespace(*cmd)) cmd++;
dae3a822e71b (svn r16409) -Change: don't add empty lines/duplicates of the previous command to the console's history
rubidium <rubidium@openttd.org>
parents: 11641
diff changeset
434
dae3a822e71b (svn r16409) -Change: don't add empty lines/duplicates of the previous command to the console's history
rubidium <rubidium@openttd.org>
parents: 11641
diff changeset
435 /* Do not put empty command in history */
14084
fb4726ae5f67 (svn r18631) -Fix [FS#3419]: when making a screenshot from the console the currently executed command would be shown twice
rubidium <rubidium@openttd.org>
parents: 13796
diff changeset
436 if (StrEmpty(cmd)) return NULL;
9339
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
437
12003
dae3a822e71b (svn r16409) -Change: don't add empty lines/duplicates of the previous command to the console's history
rubidium <rubidium@openttd.org>
parents: 11641
diff changeset
438 /* Do not put in history if command is same as previous */
dae3a822e71b (svn r16409) -Change: don't add empty lines/duplicates of the previous command to the console's history
rubidium <rubidium@openttd.org>
parents: 11641
diff changeset
439 if (_iconsole_history[0] == NULL || strcmp(_iconsole_history[0], cmd) != 0) {
dae3a822e71b (svn r16409) -Change: don't add empty lines/duplicates of the previous command to the console's history
rubidium <rubidium@openttd.org>
parents: 11641
diff changeset
440 free(_iconsole_history[ICON_HISTORY_SIZE - 1]);
dae3a822e71b (svn r16409) -Change: don't add empty lines/duplicates of the previous command to the console's history
rubidium <rubidium@openttd.org>
parents: 11641
diff changeset
441 memmove(&_iconsole_history[1], &_iconsole_history[0], sizeof(_iconsole_history[0]) * (ICON_HISTORY_SIZE - 1));
dae3a822e71b (svn r16409) -Change: don't add empty lines/duplicates of the previous command to the console's history
rubidium <rubidium@openttd.org>
parents: 11641
diff changeset
442 _iconsole_history[0] = strdup(cmd);
dae3a822e71b (svn r16409) -Change: don't add empty lines/duplicates of the previous command to the console's history
rubidium <rubidium@openttd.org>
parents: 11641
diff changeset
443 }
dae3a822e71b (svn r16409) -Change: don't add empty lines/duplicates of the previous command to the console's history
rubidium <rubidium@openttd.org>
parents: 11641
diff changeset
444
dae3a822e71b (svn r16409) -Change: don't add empty lines/duplicates of the previous command to the console's history
rubidium <rubidium@openttd.org>
parents: 11641
diff changeset
445 /* Reset the history position */
9339
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
446 IConsoleResetHistoryPos();
14084
fb4726ae5f67 (svn r18631) -Fix [FS#3419]: when making a screenshot from the console the currently executed command would be shown twice
rubidium <rubidium@openttd.org>
parents: 13796
diff changeset
447 return _iconsole_history[0];
9339
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
448 }
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
449
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
450 /**
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
451 * Navigate Up/Down in the history of typed commands
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
452 * @param direction Go further back in history (+1), go to recently typed commands (-1)
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
453 */
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
454 static void IConsoleHistoryNavigate(int direction)
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
455 {
12003
dae3a822e71b (svn r16409) -Change: don't add empty lines/duplicates of the previous command to the console's history
rubidium <rubidium@openttd.org>
parents: 11641
diff changeset
456 if (_iconsole_history[0] == NULL) return; // Empty history
9339
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
457 int i = _iconsole_historypos + direction;
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
458
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
459 /* watch out for overflows, just wrap around */
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
460 if (i < 0) i = ICON_HISTORY_SIZE - 1;
15185
418c3a29b00b (svn r19814) -Codechange: give some more unnamed enums a name, in case they consisted of unrelated values use static const (u)int
rubidium <rubidium@openttd.org>
parents: 14258
diff changeset
461 if ((uint)i >= ICON_HISTORY_SIZE) i = 0;
9339
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
462
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
463 if (direction > 0) {
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
464 if (_iconsole_history[i] == NULL) i = 0;
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
465 }
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
466
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
467 if (direction < 0) {
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
468 while (i > 0 && _iconsole_history[i] == NULL) i--;
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
469 }
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
470
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
471 _iconsole_historypos = i;
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
472 IConsoleClearCommand();
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
473 /* copy history to 'command prompt / bash' */
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
474 assert(_iconsole_history[i] != NULL && IsInsideMM(i, 0, ICON_HISTORY_SIZE));
16675
4df98a0bd2ce (svn r21406) -Codechange: rename some textbuf related names to make them a bit more descriptive
rubidium <rubidium@openttd.org>
parents: 16296
diff changeset
475 ttd_strlcpy(_iconsole_cmdline.buf, _iconsole_history[i], _iconsole_cmdline.max_bytes);
9339
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
476 UpdateTextBufferSize(&_iconsole_cmdline);
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
477 }
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
478
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
479 /**
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
480 * Handle the printing of text entered into the console or redirected there
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 9915
diff changeset
481 * by any other means. Text can be redirected to other clients in a network game
9339
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
482 * as well as to a logfile. If the network server is a dedicated server, all activities
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
483 * are also logged. All lines to print are added to a temporary buffer which can be
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
484 * used as a history to print them onscreen
11085
8da1855e9f14 (svn r15428) -Codechange: consistently use colour instead of having both color and colour.
rubidium <rubidium@openttd.org>
parents: 11082
diff changeset
485 * @param colour_code the colour of the command. Red in case of errors, etc.
13070
1c4c4ae8d716 (svn r17570) -Fix: a number of Doxygen warnings about missing parameters, which were sometimes missing and sometimes just typos
rubidium <rubidium@openttd.org>
parents: 13034
diff changeset
486 * @param str the message entered or output on the console (notice, error, etc.)
9339
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
487 */
16965
db80544f73f9 (svn r21701) -Codechange: ConsoleColour = TextColour, so make it that way and remove some unneeded casts
rubidium <rubidium@openttd.org>
parents: 16676
diff changeset
488 void IConsoleGUIPrint(TextColour colour_code, char *str)
9339
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
489 {
16965
db80544f73f9 (svn r21701) -Codechange: ConsoleColour = TextColour, so make it that way and remove some unneeded casts
rubidium <rubidium@openttd.org>
parents: 16676
diff changeset
490 new IConsoleLine(str, colour_code);
13034
6eb3f749890a (svn r17532) -Codechange: Rename several Invalidate functions to SetDirty for more consistency and distinguishability.
frosch <frosch@openttd.org>
parents: 13027
diff changeset
491 SetWindowDirty(WC_CONSOLE, 0);
9339
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
492 }
16971
b0999e3c9d93 (svn r21707) -Fix [FS#4371]: bit too strict assertion on validness of console colours
rubidium <rubidium@openttd.org>
parents: 16965
diff changeset
493
b0999e3c9d93 (svn r21707) -Fix [FS#4371]: bit too strict assertion on validness of console colours
rubidium <rubidium@openttd.org>
parents: 16965
diff changeset
494
b0999e3c9d93 (svn r21707) -Fix [FS#4371]: bit too strict assertion on validness of console colours
rubidium <rubidium@openttd.org>
parents: 16965
diff changeset
495 /**
b0999e3c9d93 (svn r21707) -Fix [FS#4371]: bit too strict assertion on validness of console colours
rubidium <rubidium@openttd.org>
parents: 16965
diff changeset
496 * Check whether the given TextColour is valid for console usage.
b0999e3c9d93 (svn r21707) -Fix [FS#4371]: bit too strict assertion on validness of console colours
rubidium <rubidium@openttd.org>
parents: 16965
diff changeset
497 * @param c The text colour to compare to.
b0999e3c9d93 (svn r21707) -Fix [FS#4371]: bit too strict assertion on validness of console colours
rubidium <rubidium@openttd.org>
parents: 16965
diff changeset
498 * @return true iff the TextColour is valid for console usage.
b0999e3c9d93 (svn r21707) -Fix [FS#4371]: bit too strict assertion on validness of console colours
rubidium <rubidium@openttd.org>
parents: 16965
diff changeset
499 */
b0999e3c9d93 (svn r21707) -Fix [FS#4371]: bit too strict assertion on validness of console colours
rubidium <rubidium@openttd.org>
parents: 16965
diff changeset
500 bool IsValidConsoleColour(TextColour c)
b0999e3c9d93 (svn r21707) -Fix [FS#4371]: bit too strict assertion on validness of console colours
rubidium <rubidium@openttd.org>
parents: 16965
diff changeset
501 {
b0999e3c9d93 (svn r21707) -Fix [FS#4371]: bit too strict assertion on validness of console colours
rubidium <rubidium@openttd.org>
parents: 16965
diff changeset
502 /* A normal text colour is used. */
b0999e3c9d93 (svn r21707) -Fix [FS#4371]: bit too strict assertion on validness of console colours
rubidium <rubidium@openttd.org>
parents: 16965
diff changeset
503 if (!(c & TC_IS_PALETTE_COLOUR)) return TC_BEGIN <= c && c < TC_END;
b0999e3c9d93 (svn r21707) -Fix [FS#4371]: bit too strict assertion on validness of console colours
rubidium <rubidium@openttd.org>
parents: 16965
diff changeset
504
b0999e3c9d93 (svn r21707) -Fix [FS#4371]: bit too strict assertion on validness of console colours
rubidium <rubidium@openttd.org>
parents: 16965
diff changeset
505 /* A text colour from the palette is used; must be the company
b0999e3c9d93 (svn r21707) -Fix [FS#4371]: bit too strict assertion on validness of console colours
rubidium <rubidium@openttd.org>
parents: 16965
diff changeset
506 * colour gradient, so it must be one of those. */
b0999e3c9d93 (svn r21707) -Fix [FS#4371]: bit too strict assertion on validness of console colours
rubidium <rubidium@openttd.org>
parents: 16965
diff changeset
507 c &= ~TC_IS_PALETTE_COLOUR;
17159
9b1a3a21da0a (svn r21897) -Fix (21707): Kenobi visited IsValidConsoleColour shortly
rubidium <rubidium@openttd.org>
parents: 16971
diff changeset
508 for (uint i = COLOUR_BEGIN; i < COLOUR_END; i++) {
16971
b0999e3c9d93 (svn r21707) -Fix [FS#4371]: bit too strict assertion on validness of console colours
rubidium <rubidium@openttd.org>
parents: 16965
diff changeset
509 if (_colour_gradient[i][4] == c) return true;
b0999e3c9d93 (svn r21707) -Fix [FS#4371]: bit too strict assertion on validness of console colours
rubidium <rubidium@openttd.org>
parents: 16965
diff changeset
510 }
b0999e3c9d93 (svn r21707) -Fix [FS#4371]: bit too strict assertion on validness of console colours
rubidium <rubidium@openttd.org>
parents: 16965
diff changeset
511
b0999e3c9d93 (svn r21707) -Fix [FS#4371]: bit too strict assertion on validness of console colours
rubidium <rubidium@openttd.org>
parents: 16965
diff changeset
512 return false;
b0999e3c9d93 (svn r21707) -Fix [FS#4371]: bit too strict assertion on validness of console colours
rubidium <rubidium@openttd.org>
parents: 16965
diff changeset
513 }