OpenTTD Source: src/console_gui.cpp Source File

OpenTTD Source 15.0-beta1

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 "autocompletion.h"
14#include "console_gui.h"
15#include "console_internal.h"
16#include "window_func.h"
17#include "string_func.h"
18#include "strings_func.h"
19#include "gfx_func.h"
20#include "gfx_layout.h"
21#include "settings_type.h"
22#include "console_func.h"
23#include "rev.h"
24#include "video/video_driver.hpp"
25#include "timer/timer.h"
26#include "timer/timer_window.h"
27
28#include "widgets/console_widget.h"
29
30#include "table/strings.h"
31
32#include "safeguards.h"
33
34static const uint ICON_HISTORY_SIZE = 20;
35static const uint ICON_RIGHT_BORDERWIDTH = 10;
36static const uint ICON_BOTTOM_BORDERWIDTH = 12;
37
41 struct IConsoleLine {
42 std::string buffer;
43 TextColour colour;
44 uint16_t time;
45
46 IConsoleLine() : buffer(), colour(TC_BEGIN), time(0)
47 {
48
49 }
50
56 IConsoleLine(std::string buffer, TextColour colour) :
57 buffer(std::move(buffer)),
58 colour(colour),
59 time(0)
60 {
61 }
62
63 ~IConsoleLine()
64 {
65 }
66};
67
69 static std::deque<IConsoleLine> _iconsole_buffer;
70
71static bool TruncateBuffer();
72
73 class ConsoleAutoCompletion final : public AutoCompletion {
74public:
75 using AutoCompletion::AutoCompletion;
76
77private:
78 std::vector<std::string> GetSuggestions(std::string_view prefix, std::string_view query) override
79 {
80 prefix = StrTrimView(prefix);
81 std::vector<std::string> suggestions;
82
83 /* We only suggest commands or aliases, so we only do it for the first token or an argument to help command. */
84 if (!prefix.empty() && prefix != "help") {
85 return suggestions;
86 }
87
88 for (const auto &[_, command] : IConsole::Commands()) {
89 if (command.name.starts_with(query)) {
90 suggestions.push_back(command.name);
91 }
92 }
93 for (const auto &[_, alias] : IConsole::Aliases()) {
94 if (alias.name.starts_with(query)) {
95 suggestions.push_back(alias.name);
96 }
97 }
98
99 return suggestions;
100 }
101
102 void ApplySuggestion(std::string_view prefix, std::string_view suggestion) override
103 {
104 this->textbuf->Assign(fmt::format("{}{} ", prefix, suggestion));
105 }
106};
107
108/* ** main console cmd buffer ** */
109static Textbuf _iconsole_cmdline(ICON_CMDLN_SIZE);
110static ConsoleAutoCompletion _iconsole_tab_completion(&_iconsole_cmdline);
111static std::deque<std::string> _iconsole_history;
112static ptrdiff_t _iconsole_historypos;
113 IConsoleModes _iconsole_mode;
114
115/* *************** *
116 * end of header *
117 * *************** */
118
119static void IConsoleClearCommand()
120{
121 memset(_iconsole_cmdline.buf, 0, ICON_CMDLN_SIZE);
122 _iconsole_cmdline.chars = _iconsole_cmdline.bytes = 1; // only terminating zero
123 _iconsole_cmdline.pixels = 0;
124 _iconsole_cmdline.caretpos = 0;
125 _iconsole_cmdline.caretxoffs = 0;
126 _iconsole_tab_completion.Reset();
127 SetWindowDirty(WC_CONSOLE, 0);
128}
129
130static inline void IConsoleResetHistoryPos()
131{
132 _iconsole_historypos = -1;
133}
134
135
136static const char *IConsoleHistoryAdd(const char *cmd);
137static void IConsoleHistoryNavigate(int direction);
138
139static constexpr NWidgetPart _nested_console_window_widgets[] = {
140 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_C_BACKGROUND), SetResize(1, 1),
141};
142
143static WindowDesc _console_window_desc(
144 WDP_MANUAL, nullptr, 0, 0,
145 WC_CONSOLE, WC_NONE,
146 0,
147 _nested_console_window_widgets
148);
149
150 struct IConsoleWindow : Window
151{
152 static size_t scroll;
153 int line_height;
154 int line_offset;
155 int cursor_width;
156
157 IConsoleWindow() : Window(_console_window_desc)
158 {
159 _iconsole_mode = ICONSOLE_OPENED;
160
161 this->InitNested(0);
162 ResizeWindow(this, _screen.width, _screen.height / 3);
163 }
164
165 void OnInit() override
166 {
167 this->line_height = GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.hsep_normal;
168 this->line_offset = GetStringBoundingBox("] ").width + WidgetDimensions::scaled.frametext.left;
169 this->cursor_width = GetCharacterWidth(FS_NORMAL, '_');
170 }
171
172 void Close([[maybe_unused]] int data = 0) override
173 {
174 _iconsole_mode = ICONSOLE_CLOSED;
175 VideoDriver::GetInstance()->EditBoxLostFocus();
176 this->Window::Close();
177 }
178
183 void Scroll(int amount)
184 {
185 if (amount < 0) {
186 size_t namount = static_cast<size_t>(-amount);
187 IConsoleWindow::scroll = (namount > IConsoleWindow::scroll) ? 0 : IConsoleWindow::scroll - namount;
188 } else {
189 assert(this->height >= 0 && this->line_height > 0);
190 size_t visible_lines = static_cast<size_t>(this->height / this->line_height);
191 size_t max_scroll = (visible_lines > _iconsole_buffer.size()) ? 0 : _iconsole_buffer.size() + 1 - visible_lines;
192 IConsoleWindow::scroll = std::min<size_t>(IConsoleWindow::scroll + amount, max_scroll);
193 }
194 this->SetDirty();
195 }
196
197 void OnPaint() override
198 {
199 const int right = this->width - WidgetDimensions::scaled.frametext.right;
200
201 GfxFillRect(0, 0, this->width - 1, this->height - 1, PC_BLACK);
202 int ypos = this->height - this->line_height - WidgetDimensions::scaled.hsep_normal;
203 for (size_t line_index = IConsoleWindow::scroll; line_index < _iconsole_buffer.size(); line_index++) {
204 const IConsoleLine &print = _iconsole_buffer[line_index];
205 SetDParamStr(0, print.buffer);
206 ypos = DrawStringMultiLine(WidgetDimensions::scaled.frametext.left, right, -this->line_height, ypos, STR_JUST_RAW_STRING, print.colour, SA_LEFT | SA_BOTTOM | SA_FORCE) - WidgetDimensions::scaled.hsep_normal;
207 if (ypos < 0) break;
208 }
209 /* If the text is longer than the window, don't show the starting ']' */
210 int delta = this->width - WidgetDimensions::scaled.frametext.right - cursor_width - this->line_offset - _iconsole_cmdline.pixels - ICON_RIGHT_BORDERWIDTH;
211 if (delta > 0) {
212 DrawString(WidgetDimensions::scaled.frametext.left, right, this->height - this->line_height, "]", (TextColour)CC_COMMAND, SA_LEFT | SA_FORCE);
213 delta = 0;
214 }
215
216 /* If we have a marked area, draw a background highlight. */
217 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);
218
219 DrawString(this->line_offset + delta, right, this->height - this->line_height, _iconsole_cmdline.buf, (TextColour)CC_COMMAND, SA_LEFT | SA_FORCE);
220
221 if (_focused_window == this && _iconsole_cmdline.caret) {
222 DrawString(this->line_offset + delta + _iconsole_cmdline.caretxoffs, right, this->height - this->line_height, "_", TC_WHITE, SA_LEFT | SA_FORCE);
223 }
224 }
225
227 IntervalTimer<TimerWindow> truncate_interval = {std::chrono::seconds(3), [this](auto) {
228 assert(this->height >= 0 && this->line_height > 0);
229 size_t visible_lines = static_cast<size_t>(this->height / this->line_height);
230
231 if (TruncateBuffer() && IConsoleWindow::scroll + visible_lines > _iconsole_buffer.size()) {
232 size_t max_scroll = (visible_lines > _iconsole_buffer.size()) ? 0 : _iconsole_buffer.size() + 1 - visible_lines;
233 IConsoleWindow::scroll = std::min<size_t>(IConsoleWindow::scroll, max_scroll);
234 this->SetDirty();
235 }
236 }};
237
238 void OnMouseLoop() override
239 {
240 if (_iconsole_cmdline.HandleCaret()) this->SetDirty();
241 }
242
243 EventState OnKeyPress([[maybe_unused]] char32_t key, uint16_t keycode) override
244 {
245 if (_focused_window != this) return ES_NOT_HANDLED;
246
247 const int scroll_height = (this->height / this->line_height) - 1;
248 switch (keycode) {
249 case WKC_UP:
250 IConsoleHistoryNavigate(1);
251 this->SetDirty();
252 break;
253
254 case WKC_DOWN:
255 IConsoleHistoryNavigate(-1);
256 this->SetDirty();
257 break;
258
259 case WKC_SHIFT | WKC_PAGEDOWN:
260 this->Scroll(-scroll_height);
261 break;
262
263 case WKC_SHIFT | WKC_PAGEUP:
264 this->Scroll(scroll_height);
265 break;
266
267 case WKC_SHIFT | WKC_DOWN:
268 this->Scroll(-1);
269 break;
270
271 case WKC_SHIFT | WKC_UP:
272 this->Scroll(1);
273 break;
274
275 case WKC_BACKQUOTE:
276 IConsoleSwitch();
277 break;
278
279 case WKC_RETURN: case WKC_NUM_ENTER: {
280 /* We always want the ] at the left side; we always force these strings to be left
281 * aligned anyway. So enforce this in all cases by adding a left-to-right marker,
282 * otherwise it will be drawn at the wrong side with right-to-left texts. */
283 IConsolePrint(CC_COMMAND, LRM "] {}", _iconsole_cmdline.buf);
284 const char *cmd = IConsoleHistoryAdd(_iconsole_cmdline.buf);
285 IConsoleClearCommand();
286
287 if (cmd != nullptr) IConsoleCmdExec(cmd);
288 break;
289 }
290
291 case WKC_CTRL | WKC_RETURN:
292 _iconsole_mode = (_iconsole_mode == ICONSOLE_FULL) ? ICONSOLE_OPENED : ICONSOLE_FULL;
293 IConsoleResize(this);
294 MarkWholeScreenDirty();
295 break;
296
297 case (WKC_CTRL | 'L'):
298 IConsoleCmdExec("clear");
299 break;
300
301 case WKC_TAB:
302 if (_iconsole_tab_completion.AutoComplete()) {
303 this->SetDirty();
304 }
305 break;
306
307 default: {
308 HandleKeyPressResult handle_result = _iconsole_cmdline.HandleKeyPress(key, keycode);
309 if (handle_result != HKPR_NOT_HANDLED) {
310 if (handle_result == HKPR_EDITING) {
311 _iconsole_tab_completion.Reset();
312 }
313 IConsoleWindow::scroll = 0;
314 IConsoleResetHistoryPos();
315 this->SetDirty();
316 } else {
317 return ES_NOT_HANDLED;
318 }
319 break;
320 }
321 }
322 return ES_HANDLED;
323 }
324
325 void InsertTextString(WidgetID, const char *str, bool marked, const char *caret, const char *insert_location, const char *replacement_end) override
326 {
327 if (_iconsole_cmdline.InsertString(str, marked, caret, insert_location, replacement_end)) {
328 _iconsole_tab_completion.Reset();
329 IConsoleWindow::scroll = 0;
330 IConsoleResetHistoryPos();
331 this->SetDirty();
332 }
333 }
334
335 const Textbuf *GetFocusedTextbuf() const override
336 {
337 return &_iconsole_cmdline;
338 }
339
340 Point GetCaretPosition() const override
341 {
342 int delta = std::min<int>(this->width - this->line_offset - _iconsole_cmdline.pixels - ICON_RIGHT_BORDERWIDTH, 0);
343 Point pt = {this->line_offset + delta + _iconsole_cmdline.caretxoffs, this->height - this->line_height};
344
345 return pt;
346 }
347
348 Rect GetTextBoundingRect(const char *from, const char *to) const override
349 {
350 int delta = std::min<int>(this->width - this->line_offset - _iconsole_cmdline.pixels - ICON_RIGHT_BORDERWIDTH, 0);
351
352 const auto p1 = GetCharPosInString(_iconsole_cmdline.buf, from, FS_NORMAL);
353 const auto p2 = from != to ? GetCharPosInString(_iconsole_cmdline.buf, to, FS_NORMAL) : p1;
354
355 Rect r = {this->line_offset + delta + p1.left, this->height - this->line_height, this->line_offset + delta + p2.right, this->height};
356 return r;
357 }
358
359 ptrdiff_t GetTextCharacterAtPosition(const Point &pt) const override
360 {
361 int delta = std::min<int>(this->width - this->line_offset - _iconsole_cmdline.pixels - ICON_RIGHT_BORDERWIDTH, 0);
362
363 if (!IsInsideMM(pt.y, this->height - this->line_height, this->height)) return -1;
364
365 return GetCharAtPosition(_iconsole_cmdline.buf, pt.x - delta);
366 }
367
368 void OnMouseWheel(int wheel) override
369 {
370 this->Scroll(-wheel);
371 }
372
373 void OnFocus() override
374 {
375 VideoDriver::GetInstance()->EditBoxGainedFocus();
376 }
377
378 void OnFocusLost(bool) override
379 {
380 VideoDriver::GetInstance()->EditBoxLostFocus();
381 }
382};
383
384size_t IConsoleWindow::scroll = 0;
385
386void IConsoleGUIInit()
387{
388 IConsoleResetHistoryPos();
389 _iconsole_mode = ICONSOLE_CLOSED;
390
391 IConsoleClearBuffer();
392
393 IConsolePrint(TC_LIGHT_BLUE, "OpenTTD Game Console Revision 7 - {}", _openttd_revision);
394 IConsolePrint(CC_WHITE, "------------------------------------");
395 IConsolePrint(CC_WHITE, "use \"help\" for more information.");
396 IConsolePrint(CC_WHITE, "");
397 IConsoleClearCommand();
398}
399
400void IConsoleClearBuffer()
401{
402 _iconsole_buffer.clear();
403}
404
405void IConsoleGUIFree()
406{
407 IConsoleClearBuffer();
408}
409
411 void IConsoleResize(Window *w)
412{
413 switch (_iconsole_mode) {
414 case ICONSOLE_OPENED:
415 w->height = _screen.height / 3;
416 w->width = _screen.width;
417 break;
418 case ICONSOLE_FULL:
419 w->height = _screen.height - ICON_BOTTOM_BORDERWIDTH;
420 w->width = _screen.width;
421 break;
422 default: return;
423 }
424
425 MarkWholeScreenDirty();
426}
427
429 void IConsoleSwitch()
430{
431 switch (_iconsole_mode) {
432 case ICONSOLE_CLOSED:
433 new IConsoleWindow();
434 break;
435
436 case ICONSOLE_OPENED: case ICONSOLE_FULL:
437 CloseWindowById(WC_CONSOLE, 0);
438 break;
439 }
440
441 MarkWholeScreenDirty();
442}
443
445 void IConsoleClose()
446{
447 if (_iconsole_mode == ICONSOLE_OPENED) IConsoleSwitch();
448}
449
456 static const char *IConsoleHistoryAdd(const char *cmd)
457{
458 /* Strip all spaces at the begin */
459 while (IsWhitespace(*cmd)) cmd++;
460
461 /* Do not put empty command in history */
462 if (StrEmpty(cmd)) return nullptr;
463
464 /* Do not put in history if command is same as previous */
465 if (_iconsole_history.empty() || _iconsole_history.front() != cmd) {
466 _iconsole_history.emplace_front(cmd);
467 while (_iconsole_history.size() > ICON_HISTORY_SIZE) _iconsole_history.pop_back();
468 }
469
470 /* Reset the history position */
471 IConsoleResetHistoryPos();
472 return _iconsole_history.front().c_str();
473}
474
479 static void IConsoleHistoryNavigate(int direction)
480{
481 if (_iconsole_history.empty()) return; // Empty history
482 _iconsole_historypos = Clamp<ptrdiff_t>(_iconsole_historypos + direction, -1, _iconsole_history.size() - 1);
483
484 if (_iconsole_historypos == -1) {
485 _iconsole_cmdline.DeleteAll();
486 } else {
487 _iconsole_cmdline.Assign(_iconsole_history[_iconsole_historypos]);
488 }
489 _iconsole_tab_completion.Reset();
490}
491
501 void IConsoleGUIPrint(TextColour colour_code, const std::string &str)
502{
503 _iconsole_buffer.push_front(IConsoleLine(str, colour_code));
504 SetWindowDirty(WC_CONSOLE, 0);
505}
506
514 static bool TruncateBuffer()
515{
516 bool need_truncation = false;
517 size_t count = 0;
518 for (IConsoleLine &line : _iconsole_buffer) {
519 count++;
520 line.time++;
521 if (line.time > _settings_client.gui.console_backlog_timeout && count > _settings_client.gui.console_backlog_length) {
522 /* Any messages after this are older and need to be truncated */
523 need_truncation = true;
524 break;
525 }
526 }
527
528 if (need_truncation) {
529 _iconsole_buffer.resize(count - 1);
530 }
531
532 return need_truncation;
533}
534
535
541 bool IsValidConsoleColour(TextColour c)
542{
543 /* A normal text colour is used. */
544 if (!(c & TC_IS_PALETTE_COLOUR)) return TC_BEGIN <= c && c < TC_END;
545
546 /* A text colour from the palette is used; must be the company
547 * colour gradient, so it must be one of those. */
548 c &= ~TC_IS_PALETTE_COLOUR;
549 for (Colours i = COLOUR_BEGIN; i < COLOUR_END; i++) {
550 if (GetColourGradient(i, SHADE_NORMAL) == c) return true;
551 }
552
553 return false;
554}
autocompletion.h
Generic auto-completion engine.
AutoCompletion
Definition autocompletion.h:15
AutoCompletion::query
std::string_view query
Last token of the text. This is used to based the suggestions on.
Definition autocompletion.h:23
AutoCompletion::prefix
std::string_view prefix
Prefix of the text before the last space.
Definition autocompletion.h:22
ConsoleAutoCompletion
Definition console_gui.cpp:73
IntervalTimer
An interval timer will fire every interval, and will continue to fire until it is deleted.
Definition timer.h:76
VideoDriver::EditBoxLostFocus
virtual void EditBoxLostFocus()
An edit box lost the input focus.
Definition video_driver.hpp:152
VideoDriver::GetInstance
static VideoDriver * GetInstance()
Get the currently active instance of the video driver.
Definition video_driver.hpp:201
VideoDriver::EditBoxGainedFocus
virtual void EditBoxGainedFocus()
An edit box gained the input focus.
Definition video_driver.hpp:157
WidgetDimensions::frametext
RectPadding frametext
Padding inside frame with text.
Definition window_gui.h:43
WidgetDimensions::scaled
static WidgetDimensions scaled
Widget dimensions scaled for current zoom level.
Definition window_gui.h:28
WidgetDimensions::hsep_normal
int hsep_normal
Normal horizontal spacing.
Definition window_gui.h:63
IConsoleCmdExec
void IConsoleCmdExec(const std::string &command_string, const uint recurse_count)
Execute a given command passed to us.
Definition console.cpp:291
IConsolePrint
void IConsolePrint(TextColour colour_code, const std::string &string)
Handle the printing of text entered into the console or redirected there by any other means.
Definition console.cpp:89
console_func.h
Console functions used outside of the console code.
IConsoleSwitch
void IConsoleSwitch()
Toggle in-game console between opened and closed.
Definition console_gui.cpp:429
IConsoleClose
void IConsoleClose()
Close the in-game console.
Definition console_gui.cpp:445
IsValidConsoleColour
bool IsValidConsoleColour(TextColour c)
Check whether the given TextColour is valid for console usage.
Definition console_gui.cpp:541
TruncateBuffer
static bool TruncateBuffer()
Remove old lines from the backlog buffer.
Definition console_gui.cpp:514
IConsoleGUIPrint
void IConsoleGUIPrint(TextColour colour_code, const std::string &str)
Handle the printing of text entered into the console or redirected there by any other means.
Definition console_gui.cpp:501
_iconsole_buffer
static std::deque< IConsoleLine > _iconsole_buffer
The console backlog buffer.
Definition console_gui.cpp:69
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:411
IConsoleHistoryNavigate
static void IConsoleHistoryNavigate(int direction)
Navigate Up/Down in the history of typed commands.
Definition console_gui.cpp:479
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:456
console_gui.h
GUI related functions in the console.
console_internal.h
Internally used functions for the console.
ICON_CMDLN_SIZE
static const uint ICON_CMDLN_SIZE
maximum length of a typed in command
Definition console_internal.h:15
CC_WHITE
static const TextColour CC_WHITE
White console lines for various things such as the welcome.
Definition console_type.h:30
CC_COMMAND
static const TextColour CC_COMMAND
Colour for the console's commands.
Definition console_type.h:29
IConsoleModes
IConsoleModes
Modes of the in-game console.
Definition console_type.h:16
ICONSOLE_CLOSED
@ ICONSOLE_CLOSED
In-game console is closed.
Definition console_type.h:19
ICONSOLE_OPENED
@ ICONSOLE_OPENED
In-game console is opened, upper 1/3 of the screen.
Definition console_type.h:18
ICONSOLE_FULL
@ ICONSOLE_FULL
In-game console is opened, whole screen.
Definition console_type.h:17
console_widget.h
Types related to the console widgets.
WID_C_BACKGROUND
@ WID_C_BACKGROUND
Background of the console.
Definition console_widget.h:15
GetCharacterHeight
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
Definition fontcache.cpp:77
GetStringBoundingBox
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition gfx.cpp:851
DrawString
int DrawString(int left, int right, int top, std::string_view str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
Definition gfx.cpp:657
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
GetCharacterWidth
uint8_t GetCharacterWidth(FontSize size, char32_t key)
Return width of character glyph.
Definition gfx.cpp:1227
DrawStringMultiLine
int DrawStringMultiLine(int left, int right, int top, int bottom, std::string_view str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly over multiple lines.
Definition gfx.cpp:774
gfx_func.h
Functions related to the gfx engine.
GetCharAtPosition
ptrdiff_t GetCharAtPosition(std::string_view str, int x, FontSize start_fontsize)
Get the character from a string that is drawn at a specific position.
Definition gfx_layout.cpp:438
GetCharPosInString
ParagraphLayouter::Position GetCharPosInString(std::string_view 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_layout.cpp:421
gfx_layout.h
Functions related to laying out the texts.
SA_LEFT
@ SA_LEFT
Left align the text.
Definition gfx_type.h:343
SA_FORCE
@ SA_FORCE
Force the alignment, i.e. don't swap for RTL languages.
Definition gfx_type.h:355
SA_BOTTOM
@ SA_BOTTOM
Bottom align the text.
Definition gfx_type.h:350
FS_NORMAL
@ FS_NORMAL
Index of the normal font in the font tables.
Definition gfx_type.h:209
TextColour
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
Definition gfx_type.h:260
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:283
NWidget
constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx=-1)
Widget part function for starting a new 'real' widget.
Definition widget_type.h:1320
SetResize
constexpr NWidgetPart SetResize(int16_t dx, int16_t dy)
Widget part function for setting the resize step.
Definition widget_type.h:1126
Window::SetDirty
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Definition window.cpp:940
MarkWholeScreenDirty
void MarkWholeScreenDirty()
This function mark the whole screen as dirty.
Definition gfx.cpp:1529
IsInsideMM
constexpr bool IsInsideMM(const T x, const size_t min, const size_t max) noexcept
Checks if a value is in an interval.
Definition math_func.hpp:268
GetColourGradient
uint8_t GetColourGradient(Colours colour, ColourShade shade)
Get colour gradient palette index.
Definition palette.cpp:314
PC_BLACK
static const uint8_t PC_BLACK
Black palette colour.
Definition palette_func.h:67
PC_DARK_RED
static const uint8_t PC_DARK_RED
Dark red palette colour.
Definition palette_func.h:73
rev.h
declaration of OTTD revision dependent variables
safeguards.h
A number of safeguards to prevent using unsafe methods.
_settings_client
ClientSettings _settings_client
The current settings for this game.
Definition settings.cpp:56
settings_type.h
Types related to global configuration settings.
stdafx.h
Definition of base types and functions in a cross-platform compatible way.
string_func.h
Functions related to low-level strings.
StrEmpty
bool StrEmpty(const char *s)
Check if a string buffer is empty.
Definition string_func.h:57
IsWhitespace
bool IsWhitespace(char32_t c)
Check whether UNICODE character is whitespace or not, i.e.
Definition string_func.h:249
LRM
#define LRM
A left-to-right marker, marks the next character as left-to-right.
Definition string_type.h:19
SetDParamStr
void SetDParamStr(size_t n, const char *str)
This function is used to "bind" a C string to a OpenTTD dparam slot.
Definition strings.cpp:371
strings_func.h
Functions related to OTTD's strings.
ClientSettings::gui
GUISettings gui
settings related to the GUI
Definition settings_type.h:610
GUISettings::console_backlog_length
uint16_t console_backlog_length
the minimum amount of items in the console backlog before items will be removed.
Definition settings_type.h:213
GUISettings::console_backlog_timeout
uint16_t 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:212
IConsoleLine
Container for a single line of console output.
Definition console_gui.cpp:41
IConsoleLine::colour
TextColour colour
The colour of the line.
Definition console_gui.cpp:43
IConsoleLine::time
uint16_t time
The amount of time the line is in the backlog.
Definition console_gui.cpp:44
IConsoleLine::buffer
std::string buffer
The data to store.
Definition console_gui.cpp:42
IConsoleLine::IConsoleLine
IConsoleLine(std::string buffer, TextColour colour)
Initialize the console line.
Definition console_gui.cpp:56
IConsoleWindow
Definition console_gui.cpp:151
IConsoleWindow::OnFocusLost
void OnFocusLost(bool) override
The window has lost focus.
Definition console_gui.cpp:378
IConsoleWindow::OnKeyPress
EventState OnKeyPress(char32_t key, uint16_t keycode) override
A key has been pressed.
Definition console_gui.cpp:243
IConsoleWindow::Scroll
void Scroll(int amount)
Scroll the content of the console.
Definition console_gui.cpp:183
IConsoleWindow::InsertTextString
void InsertTextString(WidgetID, 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:325
IConsoleWindow::GetFocusedTextbuf
const Textbuf * GetFocusedTextbuf() const override
Get the current input text buffer.
Definition console_gui.cpp:335
IConsoleWindow::truncate_interval
IntervalTimer< TimerWindow > truncate_interval
Check on a regular interval if the console buffer needs truncating.
Definition console_gui.cpp:227
IConsoleWindow::GetTextCharacterAtPosition
ptrdiff_t GetTextCharacterAtPosition(const Point &pt) const override
Get the character that is rendered at a position by the focused edit box.
Definition console_gui.cpp:359
IConsoleWindow::OnMouseLoop
void OnMouseLoop() override
Called for every mouse loop run, which is at least once per (game) tick.
Definition console_gui.cpp:238
IConsoleWindow::OnInit
void OnInit() override
Notification that the nested widget tree gets initialized.
Definition console_gui.cpp:165
IConsoleWindow::Close
void Close(int data=0) override
Hide the window and all its child windows, and mark them for a later deletion.
Definition console_gui.cpp:172
IConsoleWindow::line_height
int line_height
Height of one line of text in the console.
Definition console_gui.cpp:153
IConsoleWindow::OnPaint
void OnPaint() override
The window must be repainted.
Definition console_gui.cpp:197
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:348
IConsoleWindow::GetCaretPosition
Point GetCaretPosition() const override
Get the current caret position if an edit box has the focus.
Definition console_gui.cpp:340
IConsoleWindow::OnMouseWheel
void OnMouseWheel(int wheel) override
The mouse wheel has been turned.
Definition console_gui.cpp:368
IConsoleWindow::OnFocus
void OnFocus() override
The window has gained focus.
Definition console_gui.cpp:373
NWidgetPart
Partial widget specification to allow NWidgets to be written nested.
Definition widget_type.h:1075
Point
Coordinates of a point in 2D.
Definition geometry_type.hpp:21
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition geometry_type.hpp:75
Textbuf
Helper/buffer for input fields.
Definition textbuf_type.h:30
Textbuf::pixels
uint16_t pixels
the current size of the string in pixels
Definition textbuf_type.h:37
Textbuf::caretpos
uint16_t caretpos
the current position of the caret in the buffer, in bytes
Definition textbuf_type.h:39
Textbuf::markxoffs
uint16_t markxoffs
the start position of the marked area in pixels
Definition textbuf_type.h:43
Textbuf::DeleteAll
void DeleteAll()
Delete every character in the textbuffer.
Definition textbuf.cpp:114
Textbuf::chars
uint16_t chars
the current size of the string in characters (including terminating '\0')
Definition textbuf_type.h:36
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:160
Textbuf::Assign
void Assign(StringID string)
Render a string into the textbuffer.
Definition textbuf.cpp:431
Textbuf::bytes
uint16_t bytes
the current size of the string in bytes (including terminating '\0')
Definition textbuf_type.h:35
Textbuf::caretxoffs
uint16_t caretxoffs
the current position of the caret in pixels
Definition textbuf_type.h:40
Textbuf::marklength
uint16_t marklength
the length of the marked area in pixels
Definition textbuf_type.h:44
Textbuf::caret
bool caret
is the caret ("_") visible or not
Definition textbuf_type.h:38
Textbuf::buf
char *const buf
buffer in which text is saved
Definition textbuf_type.h:32
Textbuf::HandleCaret
bool HandleCaret()
Handle the flashing of the caret.
Definition textbuf.cpp:489
WindowDesc
High level window description.
Definition window_gui.h:159
Window
Data structure for an opened window.
Definition window_gui.h:273
Window::Close
virtual void Close(int data=0)
Hide the window and all its child windows, and mark them for a later deletion.
Definition window.cpp:1047
Window::GetWidget
const NWID * GetWidget(WidgetID widnum) const
Get the nested widget with number widnum from the nested widget tree.
Definition window_gui.h:977
Window::InitNested
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
Definition window.cpp:1746
Window::height
int height
Height of the window (number of pixels down in y direction)
Definition window_gui.h:312
Window::width
int width
width of the window (number of pixels to the right in x direction)
Definition window_gui.h:311
textbuf_type.h
Stuff related to text buffers.
HandleKeyPressResult
HandleKeyPressResult
Return values for Textbuf::HandleKeypress.
Definition textbuf_type.h:21
HKPR_NOT_HANDLED
@ HKPR_NOT_HANDLED
Key does not affect editboxes.
Definition textbuf_type.h:26
HKPR_EDITING
@ HKPR_EDITING
Textbuf content changed.
Definition textbuf_type.h:22
timer.h
Definition of Interval and OneShot timers.
timer_window.h
Definition of the Window system.
video_driver.hpp
Base of all video drivers.
WWT_EMPTY
@ WWT_EMPTY
Empty widget, place holder to reserve space in widget tree.
Definition widget_type.h:48
CloseWindowById
void CloseWindowById(WindowClass cls, WindowNumber number, bool force, int data)
Close a window by its class and window number (if it is open).
Definition window.cpp:1140
ResizeWindow
void ResizeWindow(Window *w, int delta_x, int delta_y, bool clamp_to_screen, bool schedule_resize)
Resize the window.
Definition window.cpp:2022
SetWindowDirty
void SetWindowDirty(WindowClass cls, WindowNumber number)
Mark window as dirty (in need of repainting)
Definition window.cpp:3101
window_func.h
Window functions not directly related to making/drawing windows.
window_gui.h
Functions, definitions and such used only by the GUI.
WDP_MANUAL
@ WDP_MANUAL
Manually align the window (so no automatic location finding)
Definition window_gui.h:146
WidgetID
int WidgetID
Widget ID.
Definition window_type.h:18
EventState
EventState
State of handling an event.
Definition window_type.h:743
ES_HANDLED
@ ES_HANDLED
The passed event is handled.
Definition window_type.h:744
ES_NOT_HANDLED
@ ES_NOT_HANDLED
The passed event is not handled.
Definition window_type.h:745
WC_CONSOLE
@ WC_CONSOLE
Console; Window numbers:
Definition window_type.h:649
WC_NONE
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition window_type.h:45