OpenTTD Source  13.2.1
console_gui.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of OpenTTD.
3  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6  */
7 
10 #include "stdafx.h"
11 #include "textbuf_type.h"
12 #include "window_gui.h"
13 #include "console_gui.h"
14 #include "console_internal.h"
15 #include "guitimer_func.h"
16 #include "window_func.h"
17 #include "string_func.h"
18 #include "strings_func.h"
19 #include "gfx_func.h"
20 #include "settings_type.h"
21 #include "console_func.h"
22 #include "rev.h"
23 #include "video/video_driver.hpp"
24 #include <deque>
25 #include <string>
26 
27 #include "widgets/console_widget.h"
28 
29 #include "table/strings.h"
30 
31 #include "safeguards.h"
32 
33 static const uint ICON_HISTORY_SIZE = 20;
34 static const uint ICON_RIGHT_BORDERWIDTH = 10;
35 static const uint ICON_BOTTOM_BORDERWIDTH = 12;
36 
40 struct IConsoleLine {
41  std::string buffer;
43  uint16 time;
44 
45  IConsoleLine() : buffer(), colour(TC_BEGIN), time(0)
46  {
47 
48  }
49 
56  buffer(std::move(buffer)),
57  colour(colour),
58  time(0)
59  {
60  }
61 
62  ~IConsoleLine()
63  {
64  }
65 };
66 
68 static std::deque<IConsoleLine> _iconsole_buffer;
69 
70 static bool TruncateBuffer();
71 
72 
73 /* ** main console cmd buffer ** */
74 static Textbuf _iconsole_cmdline(ICON_CMDLN_SIZE);
75 static char *_iconsole_history[ICON_HISTORY_SIZE];
76 static int _iconsole_historypos;
77 IConsoleModes _iconsole_mode;
78 
79 /* *************** *
80  * end of header *
81  * *************** */
82 
83 static void IConsoleClearCommand()
84 {
85  memset(_iconsole_cmdline.buf, 0, ICON_CMDLN_SIZE);
86  _iconsole_cmdline.chars = _iconsole_cmdline.bytes = 1; // only terminating zero
87  _iconsole_cmdline.pixels = 0;
88  _iconsole_cmdline.caretpos = 0;
89  _iconsole_cmdline.caretxoffs = 0;
91 }
92 
93 static inline void IConsoleResetHistoryPos()
94 {
95  _iconsole_historypos = -1;
96 }
97 
98 
99 static const char *IConsoleHistoryAdd(const char *cmd);
100 static void IConsoleHistoryNavigate(int direction);
101 
102 static const struct NWidgetPart _nested_console_window_widgets[] = {
103  NWidget(WWT_EMPTY, INVALID_COLOUR, WID_C_BACKGROUND), SetResize(1, 1),
104 };
105 
106 static WindowDesc _console_window_desc(
107  WDP_MANUAL, nullptr, 0, 0,
109  0,
110  _nested_console_window_widgets, lengthof(_nested_console_window_widgets)
111 );
112 
114 {
115  static size_t scroll;
117  int line_offset;
118  GUITimer truncate_timer;
119 
120  IConsoleWindow() : Window(&_console_window_desc)
121  {
122  _iconsole_mode = ICONSOLE_OPENED;
123 
124  this->InitNested(0);
125  this->truncate_timer.SetInterval(3000);
126  ResizeWindow(this, _screen.width, _screen.height / 3);
127  }
128 
129  void OnInit() override
130  {
132  this->line_offset = GetStringBoundingBox("] ").width + WidgetDimensions::scaled.frametext.left;
133  }
134 
135  void Close() override
136  {
137  _iconsole_mode = ICONSOLE_CLOSED;
139  this->Window::Close();
140  }
141 
146  void Scroll(int amount)
147  {
148  if (amount < 0) {
149  size_t namount = (size_t) -amount;
150  IConsoleWindow::scroll = (namount > IConsoleWindow::scroll) ? 0 : IConsoleWindow::scroll - namount;
151  } else {
152  assert(this->height >= 0 && this->line_height > 0);
153  size_t visible_lines = (size_t)(this->height / this->line_height);
154  size_t max_scroll = (visible_lines > _iconsole_buffer.size()) ? 0 : _iconsole_buffer.size() + 1 - visible_lines;
155  IConsoleWindow::scroll = std::min<size_t>(IConsoleWindow::scroll + amount, max_scroll);
156  }
157  this->SetDirty();
158  }
159 
160  void OnPaint() override
161  {
162  const int right = this->width - WidgetDimensions::scaled.frametext.right;
163 
164  GfxFillRect(0, 0, this->width - 1, this->height - 1, PC_BLACK);
165  int ypos = this->height - this->line_height;
166  for (size_t line_index = IConsoleWindow::scroll; line_index < _iconsole_buffer.size(); line_index++) {
167  const IConsoleLine &print = _iconsole_buffer[line_index];
168  SetDParamStr(0, print.buffer);
169  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;
170  if (ypos < 0) break;
171  }
172  /* If the text is longer than the window, don't show the starting ']' */
173  int delta = this->width - this->line_offset - _iconsole_cmdline.pixels - ICON_RIGHT_BORDERWIDTH;
174  if (delta > 0) {
175  DrawString(WidgetDimensions::scaled.frametext.left, right, this->height - this->line_height, "]", (TextColour)CC_COMMAND, SA_LEFT | SA_FORCE);
176  delta = 0;
177  }
178 
179  /* If we have a marked area, draw a background highlight. */
180  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);
181 
182  DrawString(this->line_offset + delta, right, this->height - this->line_height, _iconsole_cmdline.buf, (TextColour)CC_COMMAND, SA_LEFT | SA_FORCE);
183 
184  if (_focused_window == this && _iconsole_cmdline.caret) {
185  DrawString(this->line_offset + delta + _iconsole_cmdline.caretxoffs, right, this->height - this->line_height, "_", TC_WHITE, SA_LEFT | SA_FORCE);
186  }
187  }
188 
189  void OnRealtimeTick(uint delta_ms) override
190  {
191  if (this->truncate_timer.CountElapsed(delta_ms) == 0) return;
192 
193  assert(this->height >= 0 && this->line_height > 0);
194  size_t visible_lines = (size_t)(this->height / this->line_height);
195 
196  if (TruncateBuffer() && IConsoleWindow::scroll + visible_lines > _iconsole_buffer.size()) {
197  size_t max_scroll = (visible_lines > _iconsole_buffer.size()) ? 0 : _iconsole_buffer.size() + 1 - visible_lines;
198  IConsoleWindow::scroll = std::min<size_t>(IConsoleWindow::scroll, max_scroll);
199  this->SetDirty();
200  }
201  }
202 
203  void OnMouseLoop() override
204  {
205  if (_iconsole_cmdline.HandleCaret()) this->SetDirty();
206  }
207 
208  EventState OnKeyPress(WChar key, uint16 keycode) override
209  {
210  if (_focused_window != this) return ES_NOT_HANDLED;
211 
212  const int scroll_height = (this->height / this->line_height) - 1;
213  switch (keycode) {
214  case WKC_UP:
216  this->SetDirty();
217  break;
218 
219  case WKC_DOWN:
221  this->SetDirty();
222  break;
223 
224  case WKC_SHIFT | WKC_PAGEDOWN:
225  this->Scroll(-scroll_height);
226  break;
227 
228  case WKC_SHIFT | WKC_PAGEUP:
229  this->Scroll(scroll_height);
230  break;
231 
232  case WKC_SHIFT | WKC_DOWN:
233  this->Scroll(-1);
234  break;
235 
236  case WKC_SHIFT | WKC_UP:
237  this->Scroll(1);
238  break;
239 
240  case WKC_BACKQUOTE:
241  IConsoleSwitch();
242  break;
243 
244  case WKC_RETURN: case WKC_NUM_ENTER: {
245  /* We always want the ] at the left side; we always force these strings to be left
246  * aligned anyway. So enforce this in all cases by adding a left-to-right marker,
247  * otherwise it will be drawn at the wrong side with right-to-left texts. */
248  IConsolePrint(CC_COMMAND, LRM "] {}", _iconsole_cmdline.buf);
249  const char *cmd = IConsoleHistoryAdd(_iconsole_cmdline.buf);
250  IConsoleClearCommand();
251 
252  if (cmd != nullptr) IConsoleCmdExec(cmd);
253  break;
254  }
255 
256  case WKC_CTRL | WKC_RETURN:
257  _iconsole_mode = (_iconsole_mode == ICONSOLE_FULL) ? ICONSOLE_OPENED : ICONSOLE_FULL;
258  IConsoleResize(this);
260  break;
261 
262  case (WKC_CTRL | 'L'):
263  IConsoleCmdExec("clear");
264  break;
265 
266  default:
267  if (_iconsole_cmdline.HandleKeyPress(key, keycode) != HKPR_NOT_HANDLED) {
268  IConsoleWindow::scroll = 0;
269  IConsoleResetHistoryPos();
270  this->SetDirty();
271  } else {
272  return ES_NOT_HANDLED;
273  }
274  break;
275  }
276  return ES_HANDLED;
277  }
278 
279  void InsertTextString(int wid, const char *str, bool marked, const char *caret, const char *insert_location, const char *replacement_end) override
280  {
281  if (_iconsole_cmdline.InsertString(str, marked, caret, insert_location, replacement_end)) {
282  IConsoleWindow::scroll = 0;
283  IConsoleResetHistoryPos();
284  this->SetDirty();
285  }
286  }
287 
288  const char *GetFocusedText() const override
289  {
290  return _iconsole_cmdline.buf;
291  }
292 
293  const char *GetCaret() const override
294  {
295  return _iconsole_cmdline.buf + _iconsole_cmdline.caretpos;
296  }
297 
298  const char *GetMarkedText(size_t *length) const override
299  {
300  if (_iconsole_cmdline.markend == 0) return nullptr;
301 
302  *length = _iconsole_cmdline.markend - _iconsole_cmdline.markpos;
303  return _iconsole_cmdline.buf + _iconsole_cmdline.markpos;
304  }
305 
306  Point GetCaretPosition() const override
307  {
308  int delta = std::min<int>(this->width - this->line_offset - _iconsole_cmdline.pixels - ICON_RIGHT_BORDERWIDTH, 0);
309  Point pt = {this->line_offset + delta + _iconsole_cmdline.caretxoffs, this->height - this->line_height};
310 
311  return pt;
312  }
313 
314  Rect GetTextBoundingRect(const char *from, const char *to) const override
315  {
316  int delta = std::min<int>(this->width - this->line_offset - _iconsole_cmdline.pixels - ICON_RIGHT_BORDERWIDTH, 0);
317 
318  Point p1 = GetCharPosInString(_iconsole_cmdline.buf, from, FS_NORMAL);
319  Point p2 = from != to ? GetCharPosInString(_iconsole_cmdline.buf, from) : p1;
320 
321  Rect r = {this->line_offset + delta + p1.x, this->height - this->line_height, this->line_offset + delta + p2.x, this->height};
322  return r;
323  }
324 
325  const char *GetTextCharacterAtPosition(const Point &pt) const override
326  {
327  int delta = std::min<int>(this->width - this->line_offset - _iconsole_cmdline.pixels - ICON_RIGHT_BORDERWIDTH, 0);
328 
329  if (!IsInsideMM(pt.y, this->height - this->line_height, this->height)) return nullptr;
330 
331  return GetCharAtPosition(_iconsole_cmdline.buf, pt.x - delta);
332  }
333 
334  void OnMouseWheel(int wheel) override
335  {
336  this->Scroll(-wheel);
337  }
338 
339  void OnFocus() override
340  {
342  }
343 
344  void OnFocusLost() override
345  {
347  }
348 };
349 
350 size_t IConsoleWindow::scroll = 0;
351 
352 void IConsoleGUIInit()
353 {
354  IConsoleResetHistoryPos();
355  _iconsole_mode = ICONSOLE_CLOSED;
356 
357  IConsoleClearBuffer();
358  memset(_iconsole_history, 0, sizeof(_iconsole_history));
359 
360  IConsolePrint(TC_LIGHT_BLUE, "OpenTTD Game Console Revision 7 - {}", _openttd_revision);
361  IConsolePrint(CC_WHITE, "------------------------------------");
362  IConsolePrint(CC_WHITE, "use \"help\" for more information.");
363  IConsolePrint(CC_WHITE, "");
364  IConsoleClearCommand();
365 }
366 
367 void IConsoleClearBuffer()
368 {
369  _iconsole_buffer.clear();
370 }
371 
372 void IConsoleGUIFree()
373 {
374  IConsoleClearBuffer();
375 }
376 
379 {
380  switch (_iconsole_mode) {
381  case ICONSOLE_OPENED:
382  w->height = _screen.height / 3;
383  w->width = _screen.width;
384  break;
385  case ICONSOLE_FULL:
386  w->height = _screen.height - ICON_BOTTOM_BORDERWIDTH;
387  w->width = _screen.width;
388  break;
389  default: return;
390  }
391 
393 }
394 
397 {
398  switch (_iconsole_mode) {
399  case ICONSOLE_CLOSED:
400  new IConsoleWindow();
401  break;
402 
403  case ICONSOLE_OPENED: case ICONSOLE_FULL:
405  break;
406  }
407 
409 }
410 
413 {
414  if (_iconsole_mode == ICONSOLE_OPENED) IConsoleSwitch();
415 }
416 
423 static const char *IConsoleHistoryAdd(const char *cmd)
424 {
425  /* Strip all spaces at the begin */
426  while (IsWhitespace(*cmd)) cmd++;
427 
428  /* Do not put empty command in history */
429  if (StrEmpty(cmd)) return nullptr;
430 
431  /* Do not put in history if command is same as previous */
432  if (_iconsole_history[0] == nullptr || strcmp(_iconsole_history[0], cmd) != 0) {
433  free(_iconsole_history[ICON_HISTORY_SIZE - 1]);
434  memmove(&_iconsole_history[1], &_iconsole_history[0], sizeof(_iconsole_history[0]) * (ICON_HISTORY_SIZE - 1));
435  _iconsole_history[0] = stredup(cmd);
436  }
437 
438  /* Reset the history position */
439  IConsoleResetHistoryPos();
440  return _iconsole_history[0];
441 }
442 
447 static void IConsoleHistoryNavigate(int direction)
448 {
449  if (_iconsole_history[0] == nullptr) return; // Empty history
450  _iconsole_historypos = Clamp(_iconsole_historypos + direction, -1, ICON_HISTORY_SIZE - 1);
451 
452  if (direction > 0 && _iconsole_history[_iconsole_historypos] == nullptr) _iconsole_historypos--;
453 
454  if (_iconsole_historypos == -1) {
455  _iconsole_cmdline.DeleteAll();
456  } else {
457  _iconsole_cmdline.Assign(_iconsole_history[_iconsole_historypos]);
458  }
459 }
460 
470 void IConsoleGUIPrint(TextColour colour_code, char *str)
471 {
472  _iconsole_buffer.push_front(IConsoleLine(str, colour_code));
474 }
475 
483 static bool TruncateBuffer()
484 {
485  bool need_truncation = false;
486  size_t count = 0;
487  for (IConsoleLine &line : _iconsole_buffer) {
488  count++;
489  line.time++;
491  /* Any messages after this are older and need to be truncated */
492  need_truncation = true;
493  break;
494  }
495  }
496 
497  if (need_truncation) {
498  _iconsole_buffer.resize(count - 1);
499  }
500 
501  return need_truncation;
502 }
503 
504 
511 {
512  /* A normal text colour is used. */
513  if (!(c & TC_IS_PALETTE_COLOUR)) return TC_BEGIN <= c && c < TC_END;
514 
515  /* A text colour from the palette is used; must be the company
516  * colour gradient, so it must be one of those. */
517  c &= ~TC_IS_PALETTE_COLOUR;
518  for (uint i = COLOUR_BEGIN; i < COLOUR_END; i++) {
519  if (_colour_gradient[i][4] == c) return true;
520  }
521 
522  return false;
523 }
ES_HANDLED
@ ES_HANDLED
The passed event is handled.
Definition: window_type.h:720
IsInsideMM
static 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:230
IConsoleWindow::GetMarkedText
const char * GetMarkedText(size_t *length) const override
Get the range of the currently marked input text.
Definition: console_gui.cpp:298
ICONSOLE_OPENED
@ ICONSOLE_OPENED
In-game console is opened, upper 1/3 of the screen.
Definition: console_type.h:18
WChar
char32_t WChar
Type for wide characters, i.e.
Definition: string_type.h:36
SetWindowDirty
void SetWindowDirty(WindowClass cls, WindowNumber number)
Mark window as dirty (in need of repainting)
Definition: window.cpp:3156
textbuf_type.h
IConsoleLine
Container for a single line of console output.
Definition: console_gui.cpp:40
_iconsole_buffer
static std::deque< IConsoleLine > _iconsole_buffer
The console backlog buffer.
Definition: console_gui.cpp:68
PC_DARK_RED
static const uint8 PC_DARK_RED
Dark red palette colour.
Definition: gfx_func.h:248
console_widget.h
guitimer_func.h
IConsoleLine::time
uint16 time
The amount of time the line is in the backlog.
Definition: console_gui.cpp:43
ICON_CMDLN_SIZE
static const uint ICON_CMDLN_SIZE
maximum length of a typed in command
Definition: console_internal.h:16
Textbuf::Assign
void Assign(StringID string)
Render a string into the textbuffer.
Definition: textbuf.cpp:396
IConsoleWindow::OnRealtimeTick
void OnRealtimeTick(uint delta_ms) override
Called periodically.
Definition: console_gui.cpp:189
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:423
Textbuf::caretpos
uint16 caretpos
the current position of the caret in the buffer, in bytes
Definition: textbuf_type.h:39
IConsoleWindow::GetCaret
const char * GetCaret() const override
Get the string at the caret if an edit box has the focus.
Definition: console_gui.cpp:293
IConsoleWindow::Scroll
void Scroll(int amount)
Scroll the content of the console.
Definition: console_gui.cpp:146
IConsoleWindow::InsertTextString
void InsertTextString(int wid, const char *str, bool marked, const char *caret, const char *insert_location, const char *replacement_end) override
Insert a text string at the cursor position into the edit box widget.
Definition: console_gui.cpp:279
IConsoleWindow::OnFocus
void OnFocus() override
Called when window gains focus.
Definition: console_gui.cpp:339
TextColour
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
Definition: gfx_type.h:253
Textbuf::caretxoffs
uint16 caretxoffs
the current position of the caret in pixels
Definition: textbuf_type.h:40
SetResize
static NWidgetPart SetResize(int16 dx, int16 dy)
Widget part function for setting the resize step.
Definition: widget_type.h:997
SA_BOTTOM
@ SA_BOTTOM
Bottom align the text.
Definition: gfx_type.h:341
_settings_client
ClientSettings _settings_client
The current settings for this game.
Definition: settings.cpp:53
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:314
DrawString
int DrawString(int left, int right, int top, const char *str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
Definition: gfx.cpp:644
WWT_EMPTY
@ WWT_EMPTY
Empty widget, place holder to reserve space in widget array.
Definition: widget_type.h:46
IConsoleModes
IConsoleModes
Modes of the in-game console.
Definition: console_type.h:16
Textbuf::markpos
uint16 markpos
the start position of the marked area in the buffer, in bytes
Definition: textbuf_type.h:41
IConsoleGUIPrint
void IConsoleGUIPrint(TextColour colour_code, char *str)
Handle the printing of text entered into the console or redirected there by any other means.
Definition: console_gui.cpp:470
_colour_gradient
byte _colour_gradient[COLOUR_END][8]
All 16 colour gradients 8 colours per gradient from darkest (0) to lightest (7)
Definition: gfx.cpp:55
NWidgetPart
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:975
Textbuf::InsertString
bool InsertString(const char *str, bool marked, const char *caret=nullptr, const char *insert_location=nullptr, const char *replacement_end=nullptr)
Insert a string into the text buffer.
Definition: textbuf.cpp:162
GUISettings::console_backlog_timeout
uint16 console_backlog_timeout
the minimum amount of time items should be in the console backlog before they will be removed in ~3 s...
Definition: settings_type.h:180
Textbuf::pixels
uint16 pixels
the current size of the string in pixels
Definition: textbuf_type.h:37
GetStringBoundingBox
Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition: gfx.cpp:890
Textbuf::buf
char *const buf
buffer in which text is saved
Definition: textbuf_type.h:32
DrawStringMultiLine
int DrawStringMultiLine(int left, int right, int top, int bottom, const char *str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly over multiple lines.
Definition: gfx.cpp:789
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:102
window_gui.h
Textbuf::HandleCaret
bool HandleCaret()
Handle the flashing of the caret.
Definition: textbuf.cpp:456
GUITimer
Definition: guitimer_func.h:13
IConsoleWindow::GetFocusedText
const char * GetFocusedText() const override
Get the current input text if an edit box has the focus.
Definition: console_gui.cpp:288
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
WidgetDimensions::hsep_normal
int hsep_normal
Normal horizontal spacing.
Definition: window_gui.h:63
Window::InitNested
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
Definition: window.cpp:1804
GUISettings::console_backlog_length
uint16 console_backlog_length
the minimum amount of items in the console backlog before items will be removed.
Definition: settings_type.h:181
Window::height
int height
Height of the window (number of pixels down in y direction)
Definition: window_gui.h:249
Textbuf::marklength
uint16 marklength
the length of the marked area in pixels
Definition: textbuf_type.h:44
Window::SetDirty
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Definition: window.cpp:1008
console_internal.h
IConsoleHistoryNavigate
static void IConsoleHistoryNavigate(int direction)
Navigate Up/Down in the history of typed commands.
Definition: console_gui.cpp:447
IConsoleWindow::line_height
int line_height
Height of one line of text in the console.
Definition: console_gui.cpp:116
IConsoleWindow::GetCaretPosition
Point GetCaretPosition() const override
Get the current caret position if an edit box has the focus.
Definition: console_gui.cpp:306
ES_NOT_HANDLED
@ ES_NOT_HANDLED
The passed event is not handled.
Definition: window_type.h:721
IConsoleWindow::Close
void Close() override
Hide the window and all its child windows, and mark them for a later deletion.
Definition: console_gui.cpp:135
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:346
GetCharAtPosition
const char * GetCharAtPosition(const char *str, int x, FontSize start_fontsize)
Get the character from a string that is drawn at a specific position.
Definition: gfx.cpp:961
IConsoleWindow::OnMouseLoop
void OnMouseLoop() override
Called for every mouse loop run, which is at least once per (game) tick.
Definition: console_gui.cpp:203
safeguards.h
IConsoleLine::IConsoleLine
IConsoleLine(std::string buffer, TextColour colour)
Initialize the console line.
Definition: console_gui.cpp:55
IConsoleLine::colour
TextColour colour
The colour of the line.
Definition: console_gui.cpp:42
Textbuf::caret
bool caret
is the caret ("_") visible or not
Definition: textbuf_type.h:38
StrEmpty
static bool StrEmpty(const char *s)
Check if a string buffer is empty.
Definition: string_func.h:67
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:378
settings_type.h
Point
Coordinates of a point in 2D.
Definition: geometry_type.hpp:21
stdafx.h
PC_BLACK
static const uint8 PC_BLACK
Black palette colour.
Definition: gfx_func.h:242
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:116
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:202
WC_NONE
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition: window_type.h:38
IConsoleClose
void IConsoleClose()
Close the in-game console.
Definition: console_gui.cpp:412
IConsoleWindow::GetTextCharacterAtPosition
const char * GetTextCharacterAtPosition(const Point &pt) const override
Get the character that is rendered at a position by the focused edit box.
Definition: console_gui.cpp:325
LRM
#define LRM
A left-to-right marker, marks the next character as left-to-right.
Definition: string_type.h:21
IConsoleLine::buffer
std::string buffer
The data to store.
Definition: console_gui.cpp:41
Textbuf::markend
uint16 markend
the end position of the marked area in the buffer, in bytes
Definition: textbuf_type.h:42
string_func.h
Textbuf::bytes
uint16 bytes
the current size of the string in bytes (including terminating '\0')
Definition: textbuf_type.h:35
rev.h
Clamp
static T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
Definition: math_func.hpp:77
strings_func.h
IConsoleWindow::OnMouseWheel
void OnMouseWheel(int wheel) override
The mouse wheel has been turned.
Definition: console_gui.cpp:334
IConsoleWindow
Definition: console_gui.cpp:113
FONT_HEIGHT_NORMAL
#define FONT_HEIGHT_NORMAL
Height of characters in the normal (FS_NORMAL) font.
Definition: gfx_func.h:206
video_driver.hpp
NWidget
static NWidgetPart NWidget(WidgetType tp, Colours col, int16 idx=-1)
Widget part function for starting a new 'real' widget.
Definition: widget_type.h:1229
WC_CONSOLE
@ WC_CONSOLE
Console; Window numbers:
Definition: window_type.h:631
WID_C_BACKGROUND
@ WID_C_BACKGROUND
Background of the console.
Definition: console_widget.h:15
EventState
EventState
State of handling an event.
Definition: window_type.h:719
GUITimer::CountElapsed
uint CountElapsed(uint delta)
Count how many times the interval has elapsed.
Definition: guitimer_func.h:40
stredup
char * stredup(const char *s, const char *last)
Create a duplicate of the given string.
Definition: string.cpp:138
SA_LEFT
@ SA_LEFT
Left align the text.
Definition: gfx_type.h:334
window_func.h
lengthof
#define lengthof(x)
Return the length of an fixed size array.
Definition: stdafx.h:386
Window::width
int width
width of the window (number of pixels to the right in x direction)
Definition: window_gui.h:248
MarkWholeScreenDirty
void MarkWholeScreenDirty()
This function mark the whole screen as dirty.
Definition: gfx.cpp:1767
WDP_MANUAL
@ WDP_MANUAL
Manually align the window (so no automatic location finding)
Definition: window_gui.h:89
CloseWindowById
void CloseWindowById(WindowClass cls, WindowNumber number, bool force)
Close a window by its class and window number (if it is open).
Definition: window.cpp:1191
Textbuf::chars
uint16 chars
the current size of the string in characters (including terminating '\0')
Definition: textbuf_type.h:36
IsWhitespace
static bool IsWhitespace(WChar c)
Check whether UNICODE character is whitespace or not, i.e.
Definition: string_func.h:260
console_gui.h
IConsoleCmdExec
void IConsoleCmdExec(const char *cmdstr, const uint recurse_count)
Execute a given command passed to us.
Definition: console.cpp:303
VideoDriver::EditBoxLostFocus
virtual void EditBoxLostFocus()
An edit box lost the input focus.
Definition: video_driver.hpp:153
Window
Data structure for an opened window.
Definition: window_gui.h:213
IConsoleSwitch
void IConsoleSwitch()
Toggle in-game console between opened and closed.
Definition: console_gui.cpp:396
IConsoleWindow::OnFocusLost
void OnFocusLost() override
Called when window loses focus.
Definition: console_gui.cpp:344
IsValidConsoleColour
bool IsValidConsoleColour(TextColour c)
Check whether the given TextColour is valid for console usage.
Definition: console_gui.cpp:510
WidgetDimensions::frametext
RectPadding frametext
Offsets within a text frame area.
Definition: window_gui.h:48
console_func.h
HKPR_NOT_HANDLED
@ HKPR_NOT_HANDLED
Key does not affect editboxes.
Definition: textbuf_type.h:26
WidgetDimensions::scaled
static WidgetDimensions scaled
Widget dimensions scaled for current zoom level.
Definition: window_gui.h:68
free
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
Definition: stdafx.h:470
IConsoleWindow::OnPaint
void OnPaint() override
The window must be repainted.
Definition: console_gui.cpp:160
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition: geometry_type.hpp:69
IConsoleWindow::OnInit
void OnInit() override
Notification that the nested widget tree gets initialized.
Definition: console_gui.cpp:129
CC_WHITE
static const TextColour CC_WHITE
White console lines for various things such as the welcome.
Definition: console_type.h:30
GetCharPosInString
Point GetCharPosInString(const char *str, const char *ch, FontSize start_fontsize)
Get the leading corner of a character in a single-line string relative to the start of the string.
Definition: gfx.cpp:948
IConsoleWindow::OnKeyPress
EventState OnKeyPress(WChar key, uint16 keycode) override
A key has been pressed.
Definition: console_gui.cpp:208
Textbuf::DeleteAll
void CDECL void DeleteAll()
Delete every character in the textbuffer.
Definition: textbuf.cpp:116
TruncateBuffer
static bool TruncateBuffer()
Remove old lines from the backlog buffer.
Definition: console_gui.cpp:483
SetDParamStr
void SetDParamStr(uint n, const char *str)
This function is used to "bind" a C string to a OpenTTD dparam slot.
Definition: strings.cpp:297
ClientSettings::gui
GUISettings gui
settings related to the GUI
Definition: settings_type.h:604
VideoDriver::EditBoxGainedFocus
virtual void EditBoxGainedFocus()
An edit box gained the input focus.
Definition: video_driver.hpp:158
ResizeWindow
void ResizeWindow(Window *w, int delta_x, int delta_y, bool clamp_to_screen)
Resize the window.
Definition: window.cpp:2088
Textbuf
Helper/buffer for input fields.
Definition: textbuf_type.h:30
Window::Close
virtual void Close()
Hide the window and all its child windows, and mark them for a later deletion.
Definition: window.cpp:1107
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:94
Textbuf::markxoffs
uint16 markxoffs
the start position of the marked area in pixels
Definition: textbuf_type.h:43