OpenTTD Source: src/console_gui.cpp Source File

OpenTTD Source 15.3

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