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