OpenTTD Source: src/console_gui.cpp Source File

OpenTTD Source 1.11.0-RC1

console_gui.cpp
Go to the documentation of this file.
1 /*
2 * This file is part of OpenTTD.
3 * 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.
4 * 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.
5 * 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/>.
6 */
7
10 #include "stdafx.h"
11 #include "textbuf_type.h"
12 #include "window_gui.h"
13 #include "console_gui.h"
14 #include "console_internal.h"
15 #include "guitimer_func.h"
16 #include "window_func.h"
17 #include "string_func.h"
18 #include "strings_func.h"
19 #include "gfx_func.h"
20 #include "settings_type.h"
21 #include "console_func.h"
22 #include "rev.h"
23 #include "video/video_driver.hpp"
24
25 #include "widgets/console_widget.h"
26
27 #include "table/strings.h"
28
29 #include "safeguards.h"
30
31 static const uint ICON_HISTORY_SIZE = 20;
32 static const uint ICON_LINE_SPACING = 2;
33 static const uint ICON_RIGHT_BORDERWIDTH = 10;
34 static const uint ICON_BOTTOM_BORDERWIDTH = 12;
35
39 struct IConsoleLine {
40 static IConsoleLine *front;
41 static int size;
42
43 IConsoleLine *previous;
44 char *buffer;
45 TextColour colour;
46 uint16 time;
47
53 IConsoleLine(char *buffer, TextColour colour) :
54 previous(IConsoleLine::front),
55 buffer(buffer),
56 colour(colour),
57 time(0)
58 {
59 IConsoleLine::front = this;
60 IConsoleLine::size++;
61 }
62
66 ~IConsoleLine()
67 {
68 IConsoleLine::size--;
69 free(buffer);
70
71 delete previous;
72 }
73
77 static const IConsoleLine *Get(uint index)
78 {
79 const IConsoleLine *item = IConsoleLine::front;
80 while (index != 0 && item != nullptr) {
81 index--;
82 item = item->previous;
83 }
84
85 return item;
86 }
87
95 static bool Truncate()
96 {
97 IConsoleLine *cur = IConsoleLine::front;
98 if (cur == nullptr) return false;
99
100 int count = 1;
101 for (IConsoleLine *item = cur->previous; item != nullptr; count++, cur = item, item = item->previous) {
102 if (item->time > _settings_client.gui.console_backlog_timeout &&
103 count > _settings_client.gui.console_backlog_length) {
104 delete item;
105 cur->previous = nullptr;
106 return true;
107 }
108
109 if (item->time != MAX_UVALUE(uint16)) item->time++;
110 }
111
112 return false;
113 }
114
118 static void Reset()
119 {
120 delete IConsoleLine::front;
121 IConsoleLine::front = nullptr;
122 IConsoleLine::size = 0;
123 }
124 };
125
126 /* static */ IConsoleLine *IConsoleLine::front = nullptr;
127 /* static */ int IConsoleLine::size = 0;
128
129
130 /* ** main console cmd buffer ** */
131 static Textbuf _iconsole_cmdline(ICON_CMDLN_SIZE);
132 static char *_iconsole_history[ICON_HISTORY_SIZE];
133 static int _iconsole_historypos;
134 IConsoleModes _iconsole_mode;
135
136 /* *************** *
137 * end of header *
138 * *************** */
139
140 static void IConsoleClearCommand()
141 {
142 memset(_iconsole_cmdline.buf, 0, ICON_CMDLN_SIZE);
143 _iconsole_cmdline.chars = _iconsole_cmdline.bytes = 1; // only terminating zero
144 _iconsole_cmdline.pixels = 0;
145 _iconsole_cmdline.caretpos = 0;
146 _iconsole_cmdline.caretxoffs = 0;
147 SetWindowDirty(WC_CONSOLE, 0);
148 }
149
150 static inline void IConsoleResetHistoryPos()
151 {
152 _iconsole_historypos = -1;
153 }
154
155
156 static const char *IConsoleHistoryAdd(const char *cmd);
157 static void IConsoleHistoryNavigate(int direction);
158
159 static const struct NWidgetPart _nested_console_window_widgets[] = {
160 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_C_BACKGROUND), SetResize(1, 1),
161 };
162
163 static WindowDesc _console_window_desc(
164 WDP_MANUAL, nullptr, 0, 0,
165 WC_CONSOLE, WC_NONE,
166 0,
167 _nested_console_window_widgets, lengthof(_nested_console_window_widgets)
168 );
169
170 struct IConsoleWindow : Window
171 {
172 static int scroll;
173 int line_height;
174 int line_offset;
175 GUITimer truncate_timer;
176
177 IConsoleWindow() : Window(&_console_window_desc)
178 {
179 _iconsole_mode = ICONSOLE_OPENED;
180 this->line_height = FONT_HEIGHT_NORMAL + ICON_LINE_SPACING;
181 this->line_offset = GetStringBoundingBox("] ").width + 5;
182
183 this->InitNested(0);
184 this->truncate_timer.SetInterval(3000);
185 ResizeWindow(this, _screen.width, _screen.height / 3);
186 }
187
188 ~IConsoleWindow()
189 {
190 _iconsole_mode = ICONSOLE_CLOSED;
191 VideoDriver::GetInstance()->EditBoxLostFocus();
192 }
193
198 void Scroll(int amount)
199 {
200 int max_scroll = std::max(0, IConsoleLine::size + 1 - this->height / this->line_height);
201 IConsoleWindow::scroll = Clamp<int>(IConsoleWindow::scroll + amount, 0, max_scroll);
202 this->SetDirty();
203 }
204
205 void OnPaint() override
206 {
207 const int right = this->width - 5;
208
209 GfxFillRect(0, 0, this->width - 1, this->height - 1, PC_BLACK);
210 int ypos = this->height - this->line_height;
211 for (const IConsoleLine *print = IConsoleLine::Get(IConsoleWindow::scroll); print != nullptr; print = print->previous) {
212 SetDParamStr(0, print->buffer);
213 ypos = DrawStringMultiLine(5, right, -this->line_height, ypos, STR_JUST_RAW_STRING, print->colour, SA_LEFT | SA_BOTTOM | SA_FORCE) - ICON_LINE_SPACING;
214 if (ypos < 0) break;
215 }
216 /* If the text is longer than the window, don't show the starting ']' */
217 int delta = this->width - this->line_offset - _iconsole_cmdline.pixels - ICON_RIGHT_BORDERWIDTH;
218 if (delta > 0) {
219 DrawString(5, right, this->height - this->line_height, "]", (TextColour)CC_COMMAND, SA_LEFT | SA_FORCE);
220 delta = 0;
221 }
222
223 /* If we have a marked area, draw a background highlight. */
224 if (_iconsole_cmdline.marklength != 0) GfxFillRect(this->line_offset + delta + _iconsole_cmdline.markxoffs, this->height - this->line_height, this->line_offset + delta + _iconsole_cmdline.markxoffs + _iconsole_cmdline.marklength, this->height - 1, PC_DARK_RED);
225
226 DrawString(this->line_offset + delta, right, this->height - this->line_height, _iconsole_cmdline.buf, (TextColour)CC_COMMAND, SA_LEFT | SA_FORCE);
227
228 if (_focused_window == this && _iconsole_cmdline.caret) {
229 DrawString(this->line_offset + delta + _iconsole_cmdline.caretxoffs, right, this->height - this->line_height, "_", TC_WHITE, SA_LEFT | SA_FORCE);
230 }
231 }
232
233 void OnRealtimeTick(uint delta_ms) override
234 {
235 if (this->truncate_timer.CountElapsed(delta_ms) == 0) return;
236
237 if (IConsoleLine::Truncate() &&
238 (IConsoleWindow::scroll > IConsoleLine::size)) {
239 IConsoleWindow::scroll = std::max(0, IConsoleLine::size - (this->height / this->line_height) + 1);
240 this->SetDirty();
241 }
242 }
243
244 void OnMouseLoop() override
245 {
246 if (_iconsole_cmdline.HandleCaret()) this->SetDirty();
247 }
248
249 EventState OnKeyPress(WChar key, uint16 keycode) override
250 {
251 if (_focused_window != this) return ES_NOT_HANDLED;
252
253 const int scroll_height = (this->height / this->line_height) - 1;
254 switch (keycode) {
255 case WKC_UP:
256 IConsoleHistoryNavigate(1);
257 this->SetDirty();
258 break;
259
260 case WKC_DOWN:
261 IConsoleHistoryNavigate(-1);
262 this->SetDirty();
263 break;
264
265 case WKC_SHIFT | WKC_PAGEDOWN:
266 this->Scroll(-scroll_height);
267 break;
268
269 case WKC_SHIFT | WKC_PAGEUP:
270 this->Scroll(scroll_height);
271 break;
272
273 case WKC_SHIFT | WKC_DOWN:
274 this->Scroll(-1);
275 break;
276
277 case WKC_SHIFT | WKC_UP:
278 this->Scroll(1);
279 break;
280
281 case WKC_BACKQUOTE:
282 IConsoleSwitch();
283 break;
284
285 case WKC_RETURN: case WKC_NUM_ENTER: {
286 /* We always want the ] at the left side; we always force these strings to be left
287 * aligned anyway. So enforce this in all cases by adding a left-to-right marker,
288 * otherwise it will be drawn at the wrong side with right-to-left texts. */
289 IConsolePrintF(CC_COMMAND, LRM "] %s", _iconsole_cmdline.buf);
290 const char *cmd = IConsoleHistoryAdd(_iconsole_cmdline.buf);
291 IConsoleClearCommand();
292
293 if (cmd != nullptr) IConsoleCmdExec(cmd);
294 break;
295 }
296
297 case WKC_CTRL | WKC_RETURN:
298 _iconsole_mode = (_iconsole_mode == ICONSOLE_FULL) ? ICONSOLE_OPENED : ICONSOLE_FULL;
299 IConsoleResize(this);
300 MarkWholeScreenDirty();
301 break;
302
303 case (WKC_CTRL | 'L'):
304 IConsoleCmdExec("clear");
305 break;
306
307 default:
308 if (_iconsole_cmdline.HandleKeyPress(key, keycode) != HKPR_NOT_HANDLED) {
309 IConsoleWindow::scroll = 0;
310 IConsoleResetHistoryPos();
311 this->SetDirty();
312 } else {
313 return ES_NOT_HANDLED;
314 }
315 break;
316 }
317 return ES_HANDLED;
318 }
319
320 void InsertTextString(int wid, const char *str, bool marked, const char *caret, const char *insert_location, const char *replacement_end) override
321 {
322 if (_iconsole_cmdline.InsertString(str, marked, caret, insert_location, replacement_end)) {
323 IConsoleWindow::scroll = 0;
324 IConsoleResetHistoryPos();
325 this->SetDirty();
326 }
327 }
328
329 const char *GetFocusedText() const override
330 {
331 return _iconsole_cmdline.buf;
332 }
333
334 const char *GetCaret() const override
335 {
336 return _iconsole_cmdline.buf + _iconsole_cmdline.caretpos;
337 }
338
339 const char *GetMarkedText(size_t *length) const override
340 {
341 if (_iconsole_cmdline.markend == 0) return nullptr;
342
343 *length = _iconsole_cmdline.markend - _iconsole_cmdline.markpos;
344 return _iconsole_cmdline.buf + _iconsole_cmdline.markpos;
345 }
346
347 Point GetCaretPosition() const override
348 {
349 int delta = std::min<int>(this->width - this->line_offset - _iconsole_cmdline.pixels - ICON_RIGHT_BORDERWIDTH, 0);
350 Point pt = {this->line_offset + delta + _iconsole_cmdline.caretxoffs, this->height - this->line_height};
351
352 return pt;
353 }
354
355 Rect GetTextBoundingRect(const char *from, const char *to) const override
356 {
357 int delta = std::min<int>(this->width - this->line_offset - _iconsole_cmdline.pixels - ICON_RIGHT_BORDERWIDTH, 0);
358
359 Point p1 = GetCharPosInString(_iconsole_cmdline.buf, from, FS_NORMAL);
360 Point p2 = from != to ? GetCharPosInString(_iconsole_cmdline.buf, from) : p1;
361
362 Rect r = {this->line_offset + delta + p1.x, this->height - this->line_height, this->line_offset + delta + p2.x, this->height};
363 return r;
364 }
365
366 const char *GetTextCharacterAtPosition(const Point &pt) const override
367 {
368 int delta = std::min<int>(this->width - this->line_offset - _iconsole_cmdline.pixels - ICON_RIGHT_BORDERWIDTH, 0);
369
370 if (!IsInsideMM(pt.y, this->height - this->line_height, this->height)) return nullptr;
371
372 return GetCharAtPosition(_iconsole_cmdline.buf, pt.x - delta);
373 }
374
375 void OnMouseWheel(int wheel) override
376 {
377 this->Scroll(-wheel);
378 }
379
380 void OnFocus() override
381 {
382 VideoDriver::GetInstance()->EditBoxGainedFocus();
383 }
384
385 void OnFocusLost() override
386 {
387 VideoDriver::GetInstance()->EditBoxLostFocus();
388 }
389 };
390
391 int IConsoleWindow::scroll = 0;
392
393 void IConsoleGUIInit()
394 {
395 IConsoleResetHistoryPos();
396 _iconsole_mode = ICONSOLE_CLOSED;
397
398 IConsoleLine::Reset();
399 memset(_iconsole_history, 0, sizeof(_iconsole_history));
400
401 IConsolePrintF(CC_WARNING, "OpenTTD Game Console Revision 7 - %s", _openttd_revision);
402 IConsolePrint(CC_WHITE, "------------------------------------");
403 IConsolePrint(CC_WHITE, "use \"help\" for more information");
404 IConsolePrint(CC_WHITE, "");
405 IConsoleClearCommand();
406 }
407
408 void IConsoleClearBuffer()
409 {
410 IConsoleLine::Reset();
411 }
412
413 void IConsoleGUIFree()
414 {
415 IConsoleClearBuffer();
416 }
417
419 void IConsoleResize(Window *w)
420 {
421 switch (_iconsole_mode) {
422 case ICONSOLE_OPENED:
423 w->height = _screen.height / 3;
424 w->width = _screen.width;
425 break;
426 case ICONSOLE_FULL:
427 w->height = _screen.height - ICON_BOTTOM_BORDERWIDTH;
428 w->width = _screen.width;
429 break;
430 default: return;
431 }
432
433 MarkWholeScreenDirty();
434 }
435
437 void IConsoleSwitch()
438 {
439 switch (_iconsole_mode) {
440 case ICONSOLE_CLOSED:
441 new IConsoleWindow();
442 break;
443
444 case ICONSOLE_OPENED: case ICONSOLE_FULL:
445 DeleteWindowById(WC_CONSOLE, 0);
446 break;
447 }
448
449 MarkWholeScreenDirty();
450 }
451
453 void IConsoleClose()
454 {
455 if (_iconsole_mode == ICONSOLE_OPENED) IConsoleSwitch();
456 }
457
464 static const char *IConsoleHistoryAdd(const char *cmd)
465 {
466 /* Strip all spaces at the begin */
467 while (IsWhitespace(*cmd)) cmd++;
468
469 /* Do not put empty command in history */
470 if (StrEmpty(cmd)) return nullptr;
471
472 /* Do not put in history if command is same as previous */
473 if (_iconsole_history[0] == nullptr || strcmp(_iconsole_history[0], cmd) != 0) {
474 free(_iconsole_history[ICON_HISTORY_SIZE - 1]);
475 memmove(&_iconsole_history[1], &_iconsole_history[0], sizeof(_iconsole_history[0]) * (ICON_HISTORY_SIZE - 1));
476 _iconsole_history[0] = stredup(cmd);
477 }
478
479 /* Reset the history position */
480 IConsoleResetHistoryPos();
481 return _iconsole_history[0];
482 }
483
488 static void IConsoleHistoryNavigate(int direction)
489 {
490 if (_iconsole_history[0] == nullptr) return; // Empty history
491 _iconsole_historypos = Clamp(_iconsole_historypos + direction, -1, ICON_HISTORY_SIZE - 1);
492
493 if (direction > 0 && _iconsole_history[_iconsole_historypos] == nullptr) _iconsole_historypos--;
494
495 if (_iconsole_historypos == -1) {
496 _iconsole_cmdline.DeleteAll();
497 } else {
498 _iconsole_cmdline.Assign(_iconsole_history[_iconsole_historypos]);
499 }
500 }
501
511 void IConsoleGUIPrint(TextColour colour_code, char *str)
512 {
513 new IConsoleLine(str, colour_code);
514 SetWindowDirty(WC_CONSOLE, 0);
515 }
516
517
523 bool IsValidConsoleColour(TextColour c)
524 {
525 /* A normal text colour is used. */
526 if (!(c & TC_IS_PALETTE_COLOUR)) return TC_BEGIN <= c && c < TC_END;
527
528 /* A text colour from the palette is used; must be the company
529 * colour gradient, so it must be one of those. */
530 c &= ~TC_IS_PALETTE_COLOUR;
531 for (uint i = COLOUR_BEGIN; i < COLOUR_END; i++) {
532 if (_colour_gradient[i][4] == c) return true;
533 }
534
535 return false;
536 }
ES_HANDLED
@ ES_HANDLED
The passed event is handled.
Definition: window_type.h:718
IConsoleWindow::GetMarkedText
const char * GetMarkedText(size_t *length) const override
Get the range of the currently marked input text.
Definition: console_gui.cpp:339
ICONSOLE_OPENED
@ ICONSOLE_OPENED
In-game console is opened, upper 1/3 of the screen.
Definition: console_type.h:18
IConsoleLine::Reset
static void Reset()
Reset the complete console line backlog.
Definition: console_gui.cpp:118
WChar
char32_t WChar
Type for wide characters, i.e.
Definition: string_type.h:35
SetWindowDirty
void SetWindowDirty(WindowClass cls, WindowNumber number)
Mark window as dirty (in need of repainting)
Definition: window.cpp:3220
IConsoleLine::front
static IConsoleLine * front
The front of the console backlog buffer.
Definition: console_gui.cpp:40
IConsoleLine::size
static int size
The amount of items in the backlog.
Definition: console_gui.cpp:41
textbuf_type.h
IConsoleLine
Container for a single line of console output.
Definition: console_gui.cpp:39
PC_DARK_RED
static const uint8 PC_DARK_RED
Dark red palette colour.
Definition: gfx_func.h:212
console_widget.h
guitimer_func.h
IConsoleLine::time
uint16 time
The amount of time the line is in the backlog.
Definition: console_gui.cpp:46
ICON_CMDLN_SIZE
static const uint ICON_CMDLN_SIZE
maximum length of a typed in command
Definition: console_internal.h:15
Textbuf::Assign
void Assign(StringID string)
Render a string into the textbuffer.
Definition: textbuf.cpp:396
IConsoleWindow::OnRealtimeTick
void OnRealtimeTick(uint delta_ms) override
Called periodically.
Definition: console_gui.cpp:233
IConsoleLine::buffer
char * buffer
The data to store.
Definition: console_gui.cpp:44
SA_LEFT
@ SA_LEFT
Left align the text.
Definition: gfx_func.h:96
IConsoleHistoryAdd
static const char * IConsoleHistoryAdd(const char *cmd)
Add the entered line into the history so you can look it back scroll, etc.
Definition: console_gui.cpp:464
Textbuf::caretpos
uint16 caretpos
the current position of the caret in the buffer, in bytes
Definition: textbuf_type.h:39
IConsoleWindow::GetCaret
const char * GetCaret() const override
Get the string at the caret if an edit box has the focus.
Definition: console_gui.cpp:334
IConsoleWindow::Scroll
void Scroll(int amount)
Scroll the content of the console.
Definition: console_gui.cpp:198
IConsoleWindow::InsertTextString
void InsertTextString(int wid, const char *str, bool marked, const char *caret, const char *insert_location, const char *replacement_end) override
Insert a text string at the cursor position into the edit box widget.
Definition: console_gui.cpp:320
IConsoleWindow::OnFocus
void OnFocus() override
Called when window gains focus.
Definition: console_gui.cpp:380
TextColour
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
Definition: gfx_type.h:250
Textbuf::caretxoffs
uint16 caretxoffs
the current position of the caret in pixels
Definition: textbuf_type.h:40
SetResize
static NWidgetPart SetResize(int16 dx, int16 dy)
Widget part function for setting the resize step.
Definition: widget_type.h:929
_settings_client
ClientSettings _settings_client
The current settings for this game.
Definition: settings.cpp:79
IConsoleWindow::GetTextBoundingRect
Rect GetTextBoundingRect(const char *from, const char *to) const override
Get the bounding rectangle for a text range if an edit box has the focus.
Definition: console_gui.cpp:355
DrawString
int DrawString(int left, int right, int top, const char *str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
Definition: gfx.cpp:640
WWT_EMPTY
@ WWT_EMPTY
Empty widget, place holder to reserve space in widget array.
Definition: widget_type.h:46
IConsoleModes
IConsoleModes
Modes of the in-game console.
Definition: console_type.h:16
Textbuf::markpos
uint16 markpos
the start position of the marked area in the buffer, in bytes
Definition: textbuf_type.h:41
SA_BOTTOM
@ SA_BOTTOM
Bottom align the text.
Definition: gfx_func.h:103
SA_FORCE
@ SA_FORCE
Force the alignment, i.e. don't swap for RTL languages.
Definition: gfx_func.h:108
IConsoleGUIPrint
void IConsoleGUIPrint(TextColour colour_code, char *str)
Handle the printing of text entered into the console or redirected there by any other means.
Definition: console_gui.cpp:511
_colour_gradient
byte _colour_gradient[COLOUR_END][8]
All 16 colour gradients 8 colours per gradient from darkest (0) to lightest (7)
Definition: gfx.cpp:52
NWidgetPart
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:909
Textbuf::InsertString
bool InsertString(const char *str, bool marked, const char *caret=nullptr, const char *insert_location=nullptr, const char *replacement_end=nullptr)
Insert a string into the text buffer.
Definition: textbuf.cpp:162
GUISettings::console_backlog_timeout
uint16 console_backlog_timeout
the minimum amount of time items should be in the console backlog before they will be removed in ~3 s...
Definition: settings_type.h:163
Textbuf::pixels
uint16 pixels
the current size of the string in pixels
Definition: textbuf_type.h:37
GetStringBoundingBox
Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition: gfx.cpp:842
Textbuf::buf
char *const buf
buffer in which text is saved
Definition: textbuf_type.h:32
IConsoleLine::Truncate
static bool Truncate()
Truncate the list removing everything older than/more than the amount as specified in the config file...
Definition: console_gui.cpp:95
DrawStringMultiLine
int DrawStringMultiLine(int left, int right, int top, int bottom, const char *str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly over multiple lines.
Definition: gfx.cpp:763
IsInsideMM
static bool IsInsideMM(const T x, const size_t min, const size_t max)
Checks if a value is in an interval.
Definition: math_func.hpp:204
gfx_func.h
ICONSOLE_FULL
@ ICONSOLE_FULL
In-game console is closed.
Definition: console_type.h:17
WindowDesc
High level window description.
Definition: window_gui.h:166
window_gui.h
Textbuf::HandleCaret
bool HandleCaret()
Handle the flashing of the caret.
Definition: textbuf.cpp:456
GUITimer
Definition: guitimer_func.h:13
IConsoleWindow::GetFocusedText
const char * GetFocusedText() const override
Get the current input text if an edit box has the focus.
Definition: console_gui.cpp:329
ICONSOLE_CLOSED
@ ICONSOLE_CLOSED
In-game console is opened, whole screen.
Definition: console_type.h:19
FS_NORMAL
@ FS_NORMAL
Index of the normal font in the font tables.
Definition: gfx_type.h:207
Window::InitNested
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
Definition: window.cpp:1861
GUISettings::console_backlog_length
uint16 console_backlog_length
the minimum amount of items in the console backlog before items will be removed.
Definition: settings_type.h:164
Window::height
int height
Height of the window (number of pixels down in y direction)
Definition: window_gui.h:320
Textbuf::marklength
uint16 marklength
the length of the marked area in pixels
Definition: textbuf_type.h:44
Window::SetDirty
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Definition: window.cpp:984
console_internal.h
IConsoleHistoryNavigate
static void IConsoleHistoryNavigate(int direction)
Navigate Up/Down in the history of typed commands.
Definition: console_gui.cpp:488
IConsoleWindow::line_height
int line_height
Height of one line of text in the console.
Definition: console_gui.cpp:173
IConsoleWindow::GetCaretPosition
Point GetCaretPosition() const override
Get the current caret position if an edit box has the focus.
Definition: console_gui.cpp:347
ES_NOT_HANDLED
@ ES_NOT_HANDLED
The passed event is not handled.
Definition: window_type.h:719
TC_IS_PALETTE_COLOUR
@ TC_IS_PALETTE_COLOUR
Colour value is already a real palette colour index, not an index of a StringColour.
Definition: gfx_type.h:273
GetCharAtPosition
const char * GetCharAtPosition(const char *str, int x, FontSize start_fontsize)
Get the character from a string that is drawn at a specific position.
Definition: gfx.cpp:883
IConsoleWindow::OnMouseLoop
void OnMouseLoop() override
Called for every mouse loop run, which is at least once per (game) tick.
Definition: console_gui.cpp:244
safeguards.h
IConsoleLine::colour
TextColour colour
The colour of the line.
Definition: console_gui.cpp:45
Textbuf::caret
bool caret
is the caret ("_") visible or not
Definition: textbuf_type.h:38
StrEmpty
static bool StrEmpty(const char *s)
Check if a string buffer is empty.
Definition: string_func.h:60
IConsoleResize
void IConsoleResize(Window *w)
Change the size of the in-game console window after the screen size changed, or the window state chan...
Definition: console_gui.cpp:419
IConsoleLine::~IConsoleLine
~IConsoleLine()
Clear this console line and any further ones.
Definition: console_gui.cpp:66
settings_type.h
Point
Coordinates of a point in 2D.
Definition: geometry_type.hpp:21
IConsoleLine::Get
static const IConsoleLine * Get(uint index)
Get the index-ed item in the list.
Definition: console_gui.cpp:77
stdafx.h
PC_BLACK
static const uint8 PC_BLACK
Black palette colour.
Definition: gfx_func.h:206
IConsolePrint
void IConsolePrint(TextColour colour_code, const char *string)
Handle the printing of text entered into the console or redirected there by any other means.
Definition: console.cpp:85
GfxFillRect
void GfxFillRect(int left, int top, int right, int bottom, int colour, FillRectMode mode)
Applies a certain FillRectMode-operation to a rectangle [left, right] x [top, bottom] on the screen.
Definition: gfx.cpp:114
CC_COMMAND
static const TextColour CC_COMMAND
Colour for the console's commands.
Definition: console_type.h:28
VideoDriver::GetInstance
static VideoDriver * GetInstance()
Get the currently active instance of the video driver.
Definition: video_driver.hpp:187
WC_NONE
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition: window_type.h:38
IConsoleClose
void IConsoleClose()
Close the in-game console.
Definition: console_gui.cpp:453
IConsoleWindow::GetTextCharacterAtPosition
const char * GetTextCharacterAtPosition(const Point &pt) const override
Get the character that is rendered at a position by the focused edit box.
Definition: console_gui.cpp:366
LRM
#define LRM
A left-to-right marker, marks the next character as left-to-right.
Definition: string_type.h:21
Textbuf::markend
uint16 markend
the end position of the marked area in the buffer, in bytes
Definition: textbuf_type.h:42
string_func.h
Textbuf::bytes
uint16 bytes
the current size of the string in bytes (including terminating '\0')
Definition: textbuf_type.h:35
rev.h
Clamp
static T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
Definition: math_func.hpp:77
strings_func.h
DeleteWindowById
void DeleteWindowById(WindowClass cls, WindowNumber number, bool force)
Delete a window by its class and window number (if it is open).
Definition: window.cpp:1165
IConsoleWindow::OnMouseWheel
void OnMouseWheel(int wheel) override
The mouse wheel has been turned.
Definition: console_gui.cpp:375
IConsoleWindow
Definition: console_gui.cpp:170
FONT_HEIGHT_NORMAL
#define FONT_HEIGHT_NORMAL
Height of characters in the normal (FS_NORMAL) font.
Definition: gfx_func.h:179
video_driver.hpp
NWidget
static NWidgetPart NWidget(WidgetType tp, Colours col, int16 idx=-1)
Widget part function for starting a new 'real' widget.
Definition: widget_type.h:1113
IConsoleLine::IConsoleLine
IConsoleLine(char *buffer, TextColour colour)
Initialize the console line.
Definition: console_gui.cpp:53
WC_CONSOLE
@ WC_CONSOLE
Console; Window numbers:
Definition: window_type.h:631
IConsoleLine::previous
IConsoleLine * previous
The previous console message.
Definition: console_gui.cpp:43
WID_C_BACKGROUND
@ WID_C_BACKGROUND
Background of the console.
Definition: console_widget.h:15
EventState
EventState
State of handling an event.
Definition: window_type.h:717
MAX_UVALUE
#define MAX_UVALUE(type)
The largest value that can be entered in a variable.
Definition: stdafx.h:463
GUITimer::CountElapsed
uint CountElapsed(uint delta)
Count how many times the interval has elapsed.
Definition: guitimer_func.h:40
stredup
char * stredup(const char *s, const char *last)
Create a duplicate of the given string.
Definition: string.cpp:137
window_func.h
lengthof
#define lengthof(x)
Return the length of an fixed size array.
Definition: stdafx.h:367
Window::width
int width
width of the window (number of pixels to the right in x direction)
Definition: window_gui.h:319
MarkWholeScreenDirty
void MarkWholeScreenDirty()
This function mark the whole screen as dirty.
Definition: gfx.cpp:1597
WDP_MANUAL
@ WDP_MANUAL
Manually align the window (so no automatic location finding)
Definition: window_gui.h:153
Textbuf::chars
uint16 chars
the current size of the string in characters (including terminating '\0')
Definition: textbuf_type.h:36
IsWhitespace
static bool IsWhitespace(WChar c)
Check whether UNICODE character is whitespace or not, i.e.
Definition: string_func.h:252
console_gui.h
IConsoleCmdExec
void IConsoleCmdExec(const char *cmdstr, const uint recurse_count)
Execute a given command passed to us.
Definition: console.cpp:407
VideoDriver::EditBoxLostFocus
virtual void EditBoxLostFocus()
An edit box lost the input focus.
Definition: video_driver.hpp:145
Window
Data structure for an opened window.
Definition: window_gui.h:276
IConsoleSwitch
void IConsoleSwitch()
Toggle in-game console between opened and closed.
Definition: console_gui.cpp:437
IConsoleWindow::OnFocusLost
void OnFocusLost() override
Called when window loses focus.
Definition: console_gui.cpp:385
IsValidConsoleColour
bool IsValidConsoleColour(TextColour c)
Check whether the given TextColour is valid for console usage.
Definition: console_gui.cpp:523
console_func.h
HKPR_NOT_HANDLED
@ HKPR_NOT_HANDLED
Key does not affect editboxes.
Definition: textbuf_type.h:26
CC_WARNING
static const TextColour CC_WARNING
Colour for warning lines.
Definition: console_type.h:25
free
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
Definition: stdafx.h:454
IConsoleWindow::OnPaint
void OnPaint() override
The window must be repainted.
Definition: console_gui.cpp:205
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition: geometry_type.hpp:47
CC_WHITE
static const TextColour CC_WHITE
White console lines for various things such as the welcome.
Definition: console_type.h:29
GetCharPosInString
Point GetCharPosInString(const char *str, const char *ch, FontSize start_fontsize)
Get the leading corner of a character in a single-line string relative to the start of the string.
Definition: gfx.cpp:870
IConsoleWindow::OnKeyPress
EventState OnKeyPress(WChar key, uint16 keycode) override
A key has been pressed.
Definition: console_gui.cpp:249
Textbuf::DeleteAll
void CDECL void DeleteAll()
Delete every character in the textbuffer.
Definition: textbuf.cpp:116
IConsolePrintF
void CDECL IConsolePrintF(TextColour colour_code, const char *format,...)
Handle the printing of text entered into the console or redirected there by any other means.
Definition: console.cpp:125
SetDParamStr
void SetDParamStr(uint n, const char *str)
This function is used to "bind" a C string to a OpenTTD dparam slot.
Definition: strings.cpp:286
ClientSettings::gui
GUISettings gui
settings related to the GUI
Definition: settings_type.h:577
VideoDriver::EditBoxGainedFocus
virtual void EditBoxGainedFocus()
An edit box gained the input focus.
Definition: video_driver.hpp:150
ResizeWindow
void ResizeWindow(Window *w, int delta_x, int delta_y, bool clamp_to_screen)
Resize the window.
Definition: window.cpp:2153
Textbuf
Helper/buffer for input fields.
Definition: textbuf_type.h:30
Textbuf::markxoffs
uint16 markxoffs
the start position of the marked area in pixels
Definition: textbuf_type.h:43