OpenTTD Source  14.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 "console_gui.h"
14 #include "console_internal.h"
15 #include "window_func.h"
16 #include "string_func.h"
17 #include "strings_func.h"
18 #include "gfx_func.h"
19 #include "settings_type.h"
20 #include "console_func.h"
21 #include "rev.h"
22 #include "video/video_driver.hpp"
23 #include "timer/timer.h"
24 #include "timer/timer_window.h"
25 
26 #include "widgets/console_widget.h"
27 
28 #include "table/strings.h"
29 
30 #include "safeguards.h"
31 
32 static const uint ICON_HISTORY_SIZE = 20;
33 static const uint ICON_RIGHT_BORDERWIDTH = 10;
34 static const uint ICON_BOTTOM_BORDERWIDTH = 12;
35 
39 struct IConsoleLine {
40  std::string buffer;
42  uint16_t time;
43 
44  IConsoleLine() : buffer(), colour(TC_BEGIN), time(0)
45  {
46 
47  }
48 
55  buffer(std::move(buffer)),
56  colour(colour),
57  time(0)
58  {
59  }
60 
61  ~IConsoleLine()
62  {
63  }
64 };
65 
67 static std::deque<IConsoleLine> _iconsole_buffer;
68 
69 static bool TruncateBuffer();
70 
71 
72 /* ** main console cmd buffer ** */
73 static Textbuf _iconsole_cmdline(ICON_CMDLN_SIZE);
74 static std::deque<std::string> _iconsole_history;
75 static ptrdiff_t _iconsole_historypos;
76 IConsoleModes _iconsole_mode;
77 
78 /* *************** *
79  * end of header *
80  * *************** */
81 
82 static void IConsoleClearCommand()
83 {
84  memset(_iconsole_cmdline.buf, 0, ICON_CMDLN_SIZE);
85  _iconsole_cmdline.chars = _iconsole_cmdline.bytes = 1; // only terminating zero
86  _iconsole_cmdline.pixels = 0;
87  _iconsole_cmdline.caretpos = 0;
88  _iconsole_cmdline.caretxoffs = 0;
90 }
91 
92 static inline void IConsoleResetHistoryPos()
93 {
94  _iconsole_historypos = -1;
95 }
96 
97 
98 static const char *IConsoleHistoryAdd(const char *cmd);
99 static void IConsoleHistoryNavigate(int direction);
100 
101 static constexpr NWidgetPart _nested_console_window_widgets[] = {
102  NWidget(WWT_EMPTY, INVALID_COLOUR, WID_C_BACKGROUND), SetResize(1, 1),
103 };
104 
105 static WindowDesc _console_window_desc(__FILE__, __LINE__,
106  WDP_MANUAL, nullptr, 0, 0,
108  0,
109  std::begin(_nested_console_window_widgets), std::end(_nested_console_window_widgets)
110 );
111 
113 {
114  static size_t scroll;
116  int line_offset;
117 
118  IConsoleWindow() : Window(&_console_window_desc)
119  {
120  _iconsole_mode = ICONSOLE_OPENED;
121 
122  this->InitNested(0);
123  ResizeWindow(this, _screen.width, _screen.height / 3);
124  }
125 
126  void OnInit() override
127  {
129  this->line_offset = GetStringBoundingBox("] ").width + WidgetDimensions::scaled.frametext.left;
130  }
131 
132  void Close([[maybe_unused]] int data = 0) override
133  {
134  _iconsole_mode = ICONSOLE_CLOSED;
136  this->Window::Close();
137  }
138 
143  void Scroll(int amount)
144  {
145  if (amount < 0) {
146  size_t namount = (size_t) -amount;
147  IConsoleWindow::scroll = (namount > IConsoleWindow::scroll) ? 0 : IConsoleWindow::scroll - namount;
148  } else {
149  assert(this->height >= 0 && this->line_height > 0);
150  size_t visible_lines = (size_t)(this->height / this->line_height);
151  size_t max_scroll = (visible_lines > _iconsole_buffer.size()) ? 0 : _iconsole_buffer.size() + 1 - visible_lines;
152  IConsoleWindow::scroll = std::min<size_t>(IConsoleWindow::scroll + amount, max_scroll);
153  }
154  this->SetDirty();
155  }
156 
157  void OnPaint() override
158  {
159  const int right = this->width - WidgetDimensions::scaled.frametext.right;
160 
161  GfxFillRect(0, 0, this->width - 1, this->height - 1, PC_BLACK);
162  int ypos = this->height - this->line_height;
163  for (size_t line_index = IConsoleWindow::scroll; line_index < _iconsole_buffer.size(); line_index++) {
164  const IConsoleLine &print = _iconsole_buffer[line_index];
165  SetDParamStr(0, print.buffer);
166  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;
167  if (ypos < 0) break;
168  }
169  /* If the text is longer than the window, don't show the starting ']' */
170  int delta = this->width - this->line_offset - _iconsole_cmdline.pixels - ICON_RIGHT_BORDERWIDTH;
171  if (delta > 0) {
172  DrawString(WidgetDimensions::scaled.frametext.left, right, this->height - this->line_height, "]", (TextColour)CC_COMMAND, SA_LEFT | SA_FORCE);
173  delta = 0;
174  }
175 
176  /* If we have a marked area, draw a background highlight. */
177  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);
178 
179  DrawString(this->line_offset + delta, right, this->height - this->line_height, _iconsole_cmdline.buf, (TextColour)CC_COMMAND, SA_LEFT | SA_FORCE);
180 
181  if (_focused_window == this && _iconsole_cmdline.caret) {
182  DrawString(this->line_offset + delta + _iconsole_cmdline.caretxoffs, right, this->height - this->line_height, "_", TC_WHITE, SA_LEFT | SA_FORCE);
183  }
184  }
185 
187  IntervalTimer<TimerWindow> truncate_interval = {std::chrono::seconds(3), [this](auto) {
188  assert(this->height >= 0 && this->line_height > 0);
189  size_t visible_lines = (size_t)(this->height / this->line_height);
190 
191  if (TruncateBuffer() && IConsoleWindow::scroll + visible_lines > _iconsole_buffer.size()) {
192  size_t max_scroll = (visible_lines > _iconsole_buffer.size()) ? 0 : _iconsole_buffer.size() + 1 - visible_lines;
193  IConsoleWindow::scroll = std::min<size_t>(IConsoleWindow::scroll, max_scroll);
194  this->SetDirty();
195  }
196  }};
197 
198  void OnMouseLoop() override
199  {
200  if (_iconsole_cmdline.HandleCaret()) this->SetDirty();
201  }
202 
203  EventState OnKeyPress([[maybe_unused]] char32_t key, uint16_t keycode) override
204  {
205  if (_focused_window != this) return ES_NOT_HANDLED;
206 
207  const int scroll_height = (this->height / this->line_height) - 1;
208  switch (keycode) {
209  case WKC_UP:
211  this->SetDirty();
212  break;
213 
214  case WKC_DOWN:
216  this->SetDirty();
217  break;
218 
219  case WKC_SHIFT | WKC_PAGEDOWN:
220  this->Scroll(-scroll_height);
221  break;
222 
223  case WKC_SHIFT | WKC_PAGEUP:
224  this->Scroll(scroll_height);
225  break;
226 
227  case WKC_SHIFT | WKC_DOWN:
228  this->Scroll(-1);
229  break;
230 
231  case WKC_SHIFT | WKC_UP:
232  this->Scroll(1);
233  break;
234 
235  case WKC_BACKQUOTE:
236  IConsoleSwitch();
237  break;
238 
239  case WKC_RETURN: case WKC_NUM_ENTER: {
240  /* We always want the ] at the left side; we always force these strings to be left
241  * aligned anyway. So enforce this in all cases by adding a left-to-right marker,
242  * otherwise it will be drawn at the wrong side with right-to-left texts. */
243  IConsolePrint(CC_COMMAND, LRM "] {}", _iconsole_cmdline.buf);
244  const char *cmd = IConsoleHistoryAdd(_iconsole_cmdline.buf);
245  IConsoleClearCommand();
246 
247  if (cmd != nullptr) IConsoleCmdExec(cmd);
248  break;
249  }
250 
251  case WKC_CTRL | WKC_RETURN:
252  _iconsole_mode = (_iconsole_mode == ICONSOLE_FULL) ? ICONSOLE_OPENED : ICONSOLE_FULL;
253  IConsoleResize(this);
255  break;
256 
257  case (WKC_CTRL | 'L'):
258  IConsoleCmdExec("clear");
259  break;
260 
261  default:
262  if (_iconsole_cmdline.HandleKeyPress(key, keycode) != HKPR_NOT_HANDLED) {
263  IConsoleWindow::scroll = 0;
264  IConsoleResetHistoryPos();
265  this->SetDirty();
266  } else {
267  return ES_NOT_HANDLED;
268  }
269  break;
270  }
271  return ES_HANDLED;
272  }
273 
274  void InsertTextString(WidgetID, const char *str, bool marked, const char *caret, const char *insert_location, const char *replacement_end) override
275  {
276  if (_iconsole_cmdline.InsertString(str, marked, caret, insert_location, replacement_end)) {
277  IConsoleWindow::scroll = 0;
278  IConsoleResetHistoryPos();
279  this->SetDirty();
280  }
281  }
282 
283  Textbuf *GetFocusedTextbuf() const override
284  {
285  return &_iconsole_cmdline;
286  }
287 
288  Point GetCaretPosition() const override
289  {
290  int delta = std::min<int>(this->width - this->line_offset - _iconsole_cmdline.pixels - ICON_RIGHT_BORDERWIDTH, 0);
291  Point pt = {this->line_offset + delta + _iconsole_cmdline.caretxoffs, this->height - this->line_height};
292 
293  return pt;
294  }
295 
296  Rect GetTextBoundingRect(const char *from, const char *to) const override
297  {
298  int delta = std::min<int>(this->width - this->line_offset - _iconsole_cmdline.pixels - ICON_RIGHT_BORDERWIDTH, 0);
299 
300  Point p1 = GetCharPosInString(_iconsole_cmdline.buf, from, FS_NORMAL);
301  Point p2 = from != to ? GetCharPosInString(_iconsole_cmdline.buf, to, FS_NORMAL) : p1;
302 
303  Rect r = {this->line_offset + delta + p1.x, this->height - this->line_height, this->line_offset + delta + p2.x, this->height};
304  return r;
305  }
306 
307  ptrdiff_t GetTextCharacterAtPosition(const Point &pt) const override
308  {
309  int delta = std::min<int>(this->width - this->line_offset - _iconsole_cmdline.pixels - ICON_RIGHT_BORDERWIDTH, 0);
310 
311  if (!IsInsideMM(pt.y, this->height - this->line_height, this->height)) return -1;
312 
313  return GetCharAtPosition(_iconsole_cmdline.buf, pt.x - delta);
314  }
315 
316  void OnMouseWheel(int wheel) override
317  {
318  this->Scroll(-wheel);
319  }
320 
321  void OnFocus() override
322  {
324  }
325 
326  void OnFocusLost(bool) override
327  {
329  }
330 };
331 
332 size_t IConsoleWindow::scroll = 0;
333 
334 void IConsoleGUIInit()
335 {
336  IConsoleResetHistoryPos();
337  _iconsole_mode = ICONSOLE_CLOSED;
338 
339  IConsoleClearBuffer();
340 
341  IConsolePrint(TC_LIGHT_BLUE, "OpenTTD Game Console Revision 7 - {}", _openttd_revision);
342  IConsolePrint(CC_WHITE, "------------------------------------");
343  IConsolePrint(CC_WHITE, "use \"help\" for more information.");
344  IConsolePrint(CC_WHITE, "");
345  IConsoleClearCommand();
346 }
347 
348 void IConsoleClearBuffer()
349 {
350  _iconsole_buffer.clear();
351 }
352 
353 void IConsoleGUIFree()
354 {
355  IConsoleClearBuffer();
356 }
357 
360 {
361  switch (_iconsole_mode) {
362  case ICONSOLE_OPENED:
363  w->height = _screen.height / 3;
364  w->width = _screen.width;
365  break;
366  case ICONSOLE_FULL:
367  w->height = _screen.height - ICON_BOTTOM_BORDERWIDTH;
368  w->width = _screen.width;
369  break;
370  default: return;
371  }
372 
374 }
375 
378 {
379  switch (_iconsole_mode) {
380  case ICONSOLE_CLOSED:
381  new IConsoleWindow();
382  break;
383 
384  case ICONSOLE_OPENED: case ICONSOLE_FULL:
386  break;
387  }
388 
390 }
391 
394 {
395  if (_iconsole_mode == ICONSOLE_OPENED) IConsoleSwitch();
396 }
397 
404 static const char *IConsoleHistoryAdd(const char *cmd)
405 {
406  /* Strip all spaces at the begin */
407  while (IsWhitespace(*cmd)) cmd++;
408 
409  /* Do not put empty command in history */
410  if (StrEmpty(cmd)) return nullptr;
411 
412  /* Do not put in history if command is same as previous */
413  if (_iconsole_history.empty() || _iconsole_history.front() != cmd) {
414  _iconsole_history.emplace_front(cmd);
415  while (_iconsole_history.size() > ICON_HISTORY_SIZE) _iconsole_history.pop_back();
416  }
417 
418  /* Reset the history position */
419  IConsoleResetHistoryPos();
420  return _iconsole_history.front().c_str();
421 }
422 
427 static void IConsoleHistoryNavigate(int direction)
428 {
429  if (_iconsole_history.empty()) return; // Empty history
430  _iconsole_historypos = Clamp<ptrdiff_t>(_iconsole_historypos + direction, -1, _iconsole_history.size() - 1);
431 
432  if (_iconsole_historypos == -1) {
433  _iconsole_cmdline.DeleteAll();
434  } else {
435  _iconsole_cmdline.Assign(_iconsole_history[_iconsole_historypos]);
436  }
437 }
438 
448 void IConsoleGUIPrint(TextColour colour_code, const std::string &str)
449 {
450  _iconsole_buffer.push_front(IConsoleLine(str, colour_code));
452 }
453 
461 static bool TruncateBuffer()
462 {
463  bool need_truncation = false;
464  size_t count = 0;
465  for (IConsoleLine &line : _iconsole_buffer) {
466  count++;
467  line.time++;
469  /* Any messages after this are older and need to be truncated */
470  need_truncation = true;
471  break;
472  }
473  }
474 
475  if (need_truncation) {
476  _iconsole_buffer.resize(count - 1);
477  }
478 
479  return need_truncation;
480 }
481 
482 
489 {
490  /* A normal text colour is used. */
491  if (!(c & TC_IS_PALETTE_COLOUR)) return TC_BEGIN <= c && c < TC_END;
492 
493  /* A text colour from the palette is used; must be the company
494  * colour gradient, so it must be one of those. */
495  c &= ~TC_IS_PALETTE_COLOUR;
496  for (uint i = COLOUR_BEGIN; i < COLOUR_END; i++) {
497  if (_colour_gradient[i][4] == c) return true;
498  }
499 
500  return false;
501 }
ES_HANDLED
@ ES_HANDLED
The passed event is handled.
Definition: window_type.h:739
ICONSOLE_OPENED
@ ICONSOLE_OPENED
In-game console is opened, upper 1/3 of the screen.
Definition: console_type.h:18
SetWindowDirty
void SetWindowDirty(WindowClass cls, WindowNumber number)
Mark window as dirty (in need of repainting)
Definition: window.cpp:3082
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:204
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
WidgetDimensions::scaled
static WidgetDimensions scaled
Widget dimensions scaled for current zoom level.
Definition: window_gui.h:68
textbuf_type.h
IConsoleLine
Container for a single line of console output.
Definition: console_gui.cpp:39
_iconsole_buffer
static std::deque< IConsoleLine > _iconsole_buffer
The console backlog buffer.
Definition: console_gui.cpp:67
console_widget.h
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:405
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:1141
IntervalTimer< TimerWindow >
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:404
Textbuf::pixels
uint16_t pixels
the current size of the string in pixels
Definition: textbuf_type.h:37
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:1048
IConsoleWindow::Scroll
void Scroll(int amount)
Scroll the content of the console.
Definition: console_gui.cpp:143
IConsoleWindow::OnFocus
void OnFocus() override
The window has gained focus.
Definition: console_gui.cpp:321
TextColour
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
Definition: gfx_type.h:253
SA_BOTTOM
@ SA_BOTTOM
Bottom align the text.
Definition: gfx_type.h:345
_settings_client
ClientSettings _settings_client
The current settings for this game.
Definition: settings.cpp:54
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:296
WWT_EMPTY
@ WWT_EMPTY
Empty widget, place holder to reserve space in widget tree.
Definition: widget_type.h:50
Textbuf::caretpos
uint16_t caretpos
the current position of the caret in the buffer, in bytes
Definition: textbuf_type.h:39
IConsoleModes
IConsoleModes
Modes of the in-game console.
Definition: console_type.h:16
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:274
StrEmpty
bool StrEmpty(const char *s)
Check if a string buffer is empty.
Definition: string_func.h:56
NWidgetPart
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:1038
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:159
_colour_gradient
byte _colour_gradient[COLOUR_END][8]
All 16 colour gradients 8 colours per gradient from darkest (0) to lightest (7)
Definition: palette.cpp:26
Textbuf::buf
char *const buf
buffer in which text is saved
Definition: textbuf_type.h:32
IConsoleWindow::OnFocusLost
void OnFocusLost(bool) override
The window has lost focus.
Definition: console_gui.cpp:326
gfx_func.h
ICONSOLE_FULL
@ ICONSOLE_FULL
In-game console is opened, whole screen.
Definition: console_type.h:17
WindowDesc
High level window description.
Definition: window_gui.h:153
WidgetID
int WidgetID
Widget ID.
Definition: window_type.h:18
window_gui.h
Textbuf::HandleCaret
bool HandleCaret()
Handle the flashing of the caret.
Definition: textbuf.cpp:461
SetResize
constexpr NWidgetPart SetResize(int16_t dx, int16_t dy)
Widget part function for setting the resize step.
Definition: widget_type.h:1086
Textbuf::markxoffs
uint16_t markxoffs
the start position of the marked area in pixels
Definition: textbuf_type.h:43
ICONSOLE_CLOSED
@ ICONSOLE_CLOSED
In-game console is closed.
Definition: console_type.h:19
FS_NORMAL
@ FS_NORMAL
Index of the normal font in the font tables.
Definition: gfx_type.h:203
Window::InitNested
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
Definition: window.cpp:1747
Window::height
int height
Height of the window (number of pixels down in y direction)
Definition: window_gui.h:306
Window::SetDirty
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Definition: window.cpp:941
console_internal.h
Textbuf::bytes
uint16_t bytes
the current size of the string in bytes (including terminating '\0')
Definition: textbuf_type.h:35
IConsoleHistoryNavigate
static void IConsoleHistoryNavigate(int direction)
Navigate Up/Down in the history of typed commands.
Definition: console_gui.cpp:427
IConsoleWindow::line_height
int line_height
Height of one line of text in the console.
Definition: console_gui.cpp:115
IConsoleCmdExec
void IConsoleCmdExec(const std::string &command_string, const uint recurse_count)
Execute a given command passed to us.
Definition: console.cpp:293
IConsoleWindow::GetCaretPosition
Point GetCaretPosition() const override
Get the current caret position if an edit box has the focus.
Definition: console_gui.cpp:288
ES_NOT_HANDLED
@ ES_NOT_HANDLED
The passed event is not handled.
Definition: window_type.h:740
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:276
SA_FORCE
@ SA_FORCE
Force the alignment, i.e. don't swap for RTL languages.
Definition: gfx_type.h:350
NWidget
constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx=-1)
Widget part function for starting a new 'real' widget.
Definition: widget_type.h:1258
IConsoleWindow::OnMouseLoop
void OnMouseLoop() override
Called for every mouse loop run, which is at least once per (game) tick.
Definition: console_gui.cpp:198
safeguards.h
IConsoleLine::IConsoleLine
IConsoleLine(std::string buffer, TextColour colour)
Initialize the console line.
Definition: console_gui.cpp:54
IConsoleLine::colour
TextColour colour
The colour of the line.
Definition: console_gui.cpp:41
timer.h
Textbuf::caret
bool caret
is the caret ("_") visible or not
Definition: textbuf_type.h:38
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:359
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:448
settings_type.h
Point
Coordinates of a point in 2D.
Definition: geometry_type.hpp:21
stdafx.h
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:113
CC_COMMAND
static const TextColour CC_COMMAND
Colour for the console's commands.
Definition: console_type.h:29
VideoDriver::GetInstance
static VideoDriver * GetInstance()
Get the currently active instance of the video driver.
Definition: video_driver.hpp:200
WC_NONE
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition: window_type.h:45
IConsoleClose
void IConsoleClose()
Close the in-game console.
Definition: console_gui.cpp:393
LRM
#define LRM
A left-to-right marker, marks the next character as left-to-right.
Definition: string_type.h:19
IConsoleLine::buffer
std::string buffer
The data to store.
Definition: console_gui.cpp:40
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:307
string_func.h
IConsoleWindow::GetFocusedTextbuf
Textbuf * GetFocusedTextbuf() const override
Get the current input text buffer.
Definition: console_gui.cpp:283
WID_C_BACKGROUND
@ WID_C_BACKGROUND
Background of the console.
Definition: console_widget.h:15
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:775
rev.h
PC_DARK_RED
static const uint8_t PC_DARK_RED
Dark red palette colour.
Definition: palette_func.h:61
strings_func.h
IConsoleWindow
Definition: console_gui.cpp:112
video_driver.hpp
WC_CONSOLE
@ WC_CONSOLE
Console; Window numbers:
Definition: window_type.h:644
Textbuf::marklength
uint16_t marklength
the length of the marked area in pixels
Definition: textbuf_type.h:44
EventState
EventState
State of handling an event.
Definition: window_type.h:738
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:205
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:352
PC_BLACK
static const uint8_t PC_BLACK
Black palette colour.
Definition: palette_func.h:55
IsWhitespace
bool IsWhitespace(char32_t c)
Check whether UNICODE character is whitespace or not, i.e.
Definition: string_func.h:248
SA_LEFT
@ SA_LEFT
Left align the text.
Definition: gfx_type.h:338
Textbuf::chars
uint16_t chars
the current size of the string in characters (including terminating '\0')
Definition: textbuf_type.h:36
window_func.h
IConsoleLine::time
uint16_t time
The amount of time the line is in the backlog.
Definition: console_gui.cpp:42
GetCharacterHeight
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
Definition: fontcache.cpp:78
Window::width
int width
width of the window (number of pixels to the right in x direction)
Definition: window_gui.h:305
MarkWholeScreenDirty
void MarkWholeScreenDirty()
This function mark the whole screen as dirty.
Definition: gfx.cpp:1552
WDP_MANUAL
@ WDP_MANUAL
Manually align the window (so no automatic location finding)
Definition: window_gui.h:140
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:658
timer_window.h
IConsoleWindow::truncate_interval
IntervalTimer< TimerWindow > truncate_interval
Check on a regular interval if the console buffer needs truncating.
Definition: console_gui.cpp:187
console_gui.h
GetCharPosInString
Point 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.cpp:892
WidgetDimensions::frametext
RectPadding frametext
Padding inside frame with text.
Definition: window_gui.h:43
VideoDriver::EditBoxLostFocus
virtual void EditBoxLostFocus()
An edit box lost the input focus.
Definition: video_driver.hpp:151
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.cpp:909
Window
Data structure for an opened window.
Definition: window_gui.h:267
IConsoleSwitch
void IConsoleSwitch()
Toggle in-game console between opened and closed.
Definition: console_gui.cpp:377
IsValidConsoleColour
bool IsValidConsoleColour(TextColour c)
Check whether the given TextColour is valid for console usage.
Definition: console_gui.cpp:488
console_func.h
HKPR_NOT_HANDLED
@ HKPR_NOT_HANDLED
Key does not affect editboxes.
Definition: textbuf_type.h:26
IConsoleWindow::OnPaint
void OnPaint() override
The window must be repainted.
Definition: console_gui.cpp:157
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition: geometry_type.hpp:75
Textbuf::caretxoffs
uint16_t caretxoffs
the current position of the caret in pixels
Definition: textbuf_type.h:40
IConsoleWindow::OnInit
void OnInit() override
Notification that the nested widget tree gets initialized.
Definition: console_gui.cpp:126
CC_WHITE
static const TextColour CC_WHITE
White console lines for various things such as the welcome.
Definition: console_type.h:30
WidgetDimensions::hsep_normal
int hsep_normal
Normal horizontal spacing.
Definition: window_gui.h:63
Textbuf::DeleteAll
void DeleteAll()
Delete every character in the textbuffer.
Definition: textbuf.cpp:113
TruncateBuffer
static bool TruncateBuffer()
Remove old lines from the backlog buffer.
Definition: console_gui.cpp:461
GetStringBoundingBox
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition: gfx.cpp:852
ClientSettings::gui
GUISettings gui
settings related to the GUI
Definition: settings_type.h:636
VideoDriver::EditBoxGainedFocus
virtual void EditBoxGainedFocus()
An edit box gained the input focus.
Definition: video_driver.hpp:156
ResizeWindow
void ResizeWindow(Window *w, int delta_x, int delta_y, bool clamp_to_screen)
Resize the window.
Definition: window.cpp:2027
Textbuf
Helper/buffer for input fields.
Definition: textbuf_type.h:30
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:91