OpenTTD
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 
24 #include "widgets/console_widget.h"
25 
26 #include "table/strings.h"
27 
28 #include "safeguards.h"
29 
30 static const uint ICON_HISTORY_SIZE = 20;
31 static const uint ICON_LINE_SPACING = 2;
32 static const uint ICON_RIGHT_BORDERWIDTH = 10;
33 static const uint ICON_BOTTOM_BORDERWIDTH = 12;
34 
38 struct IConsoleLine {
39  static IConsoleLine *front;
40  static int size;
41 
43  char *buffer;
45  uint16 time;
46 
52  IConsoleLine(char *buffer, TextColour colour) :
53  previous(IConsoleLine::front),
54  buffer(buffer),
55  colour(colour),
56  time(0)
57  {
58  IConsoleLine::front = this;
60  }
61 
66  {
68  free(buffer);
69 
70  delete previous;
71  }
72 
76  static const IConsoleLine *Get(uint index)
77  {
78  const IConsoleLine *item = IConsoleLine::front;
79  while (index != 0 && item != nullptr) {
80  index--;
81  item = item->previous;
82  }
83 
84  return item;
85  }
86 
94  static bool Truncate()
95  {
97  if (cur == nullptr) return false;
98 
99  int count = 1;
100  for (IConsoleLine *item = cur->previous; item != nullptr; count++, cur = item, item = item->previous) {
101  if (item->time > _settings_client.gui.console_backlog_timeout &&
103  delete item;
104  cur->previous = nullptr;
105  return true;
106  }
107 
108  if (item->time != MAX_UVALUE(uint16)) item->time++;
109  }
110 
111  return false;
112  }
113 
117  static void Reset()
118  {
119  delete IConsoleLine::front;
120  IConsoleLine::front = nullptr;
121  IConsoleLine::size = 0;
122  }
123 };
124 
125 /* static */ IConsoleLine *IConsoleLine::front = nullptr;
126 /* static */ int IConsoleLine::size = 0;
127 
128 
129 /* ** main console cmd buffer ** */
130 static Textbuf _iconsole_cmdline(ICON_CMDLN_SIZE);
131 static char *_iconsole_history[ICON_HISTORY_SIZE];
132 static int _iconsole_historypos;
133 IConsoleModes _iconsole_mode;
134 
135 /* *************** *
136  * end of header *
137  * *************** */
138 
139 static void IConsoleClearCommand()
140 {
141  memset(_iconsole_cmdline.buf, 0, ICON_CMDLN_SIZE);
142  _iconsole_cmdline.chars = _iconsole_cmdline.bytes = 1; // only terminating zero
143  _iconsole_cmdline.pixels = 0;
144  _iconsole_cmdline.caretpos = 0;
145  _iconsole_cmdline.caretxoffs = 0;
147 }
148 
149 static inline void IConsoleResetHistoryPos()
150 {
151  _iconsole_historypos = -1;
152 }
153 
154 
155 static const char *IConsoleHistoryAdd(const char *cmd);
156 static void IConsoleHistoryNavigate(int direction);
157 
158 static const struct NWidgetPart _nested_console_window_widgets[] = {
159  NWidget(WWT_EMPTY, INVALID_COLOUR, WID_C_BACKGROUND), SetResize(1, 1),
160 };
161 
162 static WindowDesc _console_window_desc(
163  WDP_MANUAL, nullptr, 0, 0,
165  0,
166  _nested_console_window_widgets, lengthof(_nested_console_window_widgets)
167 );
168 
170 {
171  static int scroll;
173  int line_offset;
174 
175  IConsoleWindow() : Window(&_console_window_desc)
176  {
177  _iconsole_mode = ICONSOLE_OPENED;
178  this->line_height = FONT_HEIGHT_NORMAL + ICON_LINE_SPACING;
179  this->line_offset = GetStringBoundingBox("] ").width + 5;
180 
181  this->InitNested(0);
182  ResizeWindow(this, _screen.width, _screen.height / 3);
183  }
184 
185  ~IConsoleWindow()
186  {
187  _iconsole_mode = ICONSOLE_CLOSED;
189  }
190 
195  void Scroll(int amount)
196  {
197  int max_scroll = max<int>(0, IConsoleLine::size + 1 - this->height / this->line_height);
198  IConsoleWindow::scroll = Clamp<int>(IConsoleWindow::scroll + amount, 0, max_scroll);
199  this->SetDirty();
200  }
201 
202  void OnPaint() override
203  {
204  const int right = this->width - 5;
205 
206  GfxFillRect(0, 0, this->width - 1, this->height - 1, PC_BLACK);
207  int ypos = this->height - this->line_height;
208  for (const IConsoleLine *print = IConsoleLine::Get(IConsoleWindow::scroll); print != nullptr; print = print->previous) {
209  SetDParamStr(0, print->buffer);
210  ypos = DrawStringMultiLine(5, right, -this->line_height, ypos, STR_JUST_RAW_STRING, print->colour, SA_LEFT | SA_BOTTOM | SA_FORCE) - ICON_LINE_SPACING;
211  if (ypos < 0) break;
212  }
213  /* If the text is longer than the window, don't show the starting ']' */
214  int delta = this->width - this->line_offset - _iconsole_cmdline.pixels - ICON_RIGHT_BORDERWIDTH;
215  if (delta > 0) {
216  DrawString(5, right, this->height - this->line_height, "]", (TextColour)CC_COMMAND, SA_LEFT | SA_FORCE);
217  delta = 0;
218  }
219 
220  /* If we have a marked area, draw a background highlight. */
221  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);
222 
223  DrawString(this->line_offset + delta, right, this->height - this->line_height, _iconsole_cmdline.buf, (TextColour)CC_COMMAND, SA_LEFT | SA_FORCE);
224 
225  if (_focused_window == this && _iconsole_cmdline.caret) {
226  DrawString(this->line_offset + delta + _iconsole_cmdline.caretxoffs, right, this->height - this->line_height, "_", TC_WHITE, SA_LEFT | SA_FORCE);
227  }
228  }
229 
230  void OnHundredthTick() override
231  {
232  if (IConsoleLine::Truncate() &&
233  (IConsoleWindow::scroll > IConsoleLine::size)) {
234  IConsoleWindow::scroll = max(0, IConsoleLine::size - (this->height / this->line_height) + 1);
235  this->SetDirty();
236  }
237  }
238 
239  void OnMouseLoop() override
240  {
241  if (_iconsole_cmdline.HandleCaret()) this->SetDirty();
242  }
243 
244  EventState OnKeyPress(WChar key, uint16 keycode) override
245  {
246  if (_focused_window != this) return ES_NOT_HANDLED;
247 
248  const int scroll_height = (this->height / this->line_height) - 1;
249  switch (keycode) {
250  case WKC_UP:
252  this->SetDirty();
253  break;
254 
255  case WKC_DOWN:
257  this->SetDirty();
258  break;
259 
260  case WKC_SHIFT | WKC_PAGEDOWN:
261  this->Scroll(-scroll_height);
262  break;
263 
264  case WKC_SHIFT | WKC_PAGEUP:
265  this->Scroll(scroll_height);
266  break;
267 
268  case WKC_SHIFT | WKC_DOWN:
269  this->Scroll(-1);
270  break;
271 
272  case WKC_SHIFT | WKC_UP:
273  this->Scroll(1);
274  break;
275 
276  case WKC_BACKQUOTE:
277  IConsoleSwitch();
278  break;
279 
280  case WKC_RETURN: case WKC_NUM_ENTER: {
281  /* We always want the ] at the left side; we always force these strings to be left
282  * aligned anyway. So enforce this in all cases by adding a left-to-right marker,
283  * otherwise it will be drawn at the wrong side with right-to-left texts. */
284  IConsolePrintF(CC_COMMAND, LRM "] %s", _iconsole_cmdline.buf);
285  const char *cmd = IConsoleHistoryAdd(_iconsole_cmdline.buf);
286  IConsoleClearCommand();
287 
288  if (cmd != nullptr) IConsoleCmdExec(cmd);
289  break;
290  }
291 
292  case WKC_CTRL | WKC_RETURN:
293  _iconsole_mode = (_iconsole_mode == ICONSOLE_FULL) ? ICONSOLE_OPENED : ICONSOLE_FULL;
294  IConsoleResize(this);
296  break;
297 
298  case (WKC_CTRL | 'L'):
299  IConsoleCmdExec("clear");
300  break;
301 
302  default:
303  if (_iconsole_cmdline.HandleKeyPress(key, keycode) != HKPR_NOT_HANDLED) {
304  IConsoleWindow::scroll = 0;
305  IConsoleResetHistoryPos();
306  this->SetDirty();
307  } else {
308  return ES_NOT_HANDLED;
309  }
310  break;
311  }
312  return ES_HANDLED;
313  }
314 
315  void InsertTextString(int wid, const char *str, bool marked, const char *caret, const char *insert_location, const char *replacement_end) override
316  {
317  if (_iconsole_cmdline.InsertString(str, marked, caret, insert_location, replacement_end)) {
318  IConsoleWindow::scroll = 0;
319  IConsoleResetHistoryPos();
320  this->SetDirty();
321  }
322  }
323 
324  const char *GetFocusedText() const override
325  {
326  return _iconsole_cmdline.buf;
327  }
328 
329  const char *GetCaret() const override
330  {
331  return _iconsole_cmdline.buf + _iconsole_cmdline.caretpos;
332  }
333 
334  const char *GetMarkedText(size_t *length) const override
335  {
336  if (_iconsole_cmdline.markend == 0) return nullptr;
337 
338  *length = _iconsole_cmdline.markend - _iconsole_cmdline.markpos;
339  return _iconsole_cmdline.buf + _iconsole_cmdline.markpos;
340  }
341 
342  Point GetCaretPosition() const override
343  {
344  int delta = min(this->width - this->line_offset - _iconsole_cmdline.pixels - ICON_RIGHT_BORDERWIDTH, 0);
345  Point pt = {this->line_offset + delta + _iconsole_cmdline.caretxoffs, this->height - this->line_height};
346 
347  return pt;
348  }
349 
350  Rect GetTextBoundingRect(const char *from, const char *to) const override
351  {
352  int delta = min(this->width - this->line_offset - _iconsole_cmdline.pixels - ICON_RIGHT_BORDERWIDTH, 0);
353 
354  Point p1 = GetCharPosInString(_iconsole_cmdline.buf, from, FS_NORMAL);
355  Point p2 = from != to ? GetCharPosInString(_iconsole_cmdline.buf, from) : p1;
356 
357  Rect r = {this->line_offset + delta + p1.x, this->height - this->line_height, this->line_offset + delta + p2.x, this->height};
358  return r;
359  }
360 
361  const char *GetTextCharacterAtPosition(const Point &pt) const override
362  {
363  int delta = min(this->width - this->line_offset - _iconsole_cmdline.pixels - ICON_RIGHT_BORDERWIDTH, 0);
364 
365  if (!IsInsideMM(pt.y, this->height - this->line_height, this->height)) return nullptr;
366 
367  return GetCharAtPosition(_iconsole_cmdline.buf, pt.x - delta);
368  }
369 
370  void OnMouseWheel(int wheel) override
371  {
372  this->Scroll(-wheel);
373  }
374 
375  void OnFocus() override
376  {
378  }
379 
380  void OnFocusLost() override
381  {
383  }
384 };
385 
386 int IConsoleWindow::scroll = 0;
387 
388 void IConsoleGUIInit()
389 {
390  IConsoleResetHistoryPos();
391  _iconsole_mode = ICONSOLE_CLOSED;
392 
394  memset(_iconsole_history, 0, sizeof(_iconsole_history));
395 
396  IConsolePrintF(CC_WARNING, "OpenTTD Game Console Revision 7 - %s", _openttd_revision);
397  IConsolePrint(CC_WHITE, "------------------------------------");
398  IConsolePrint(CC_WHITE, "use \"help\" for more information");
399  IConsolePrint(CC_WHITE, "");
400  IConsoleClearCommand();
401 }
402 
403 void IConsoleClearBuffer()
404 {
406 }
407 
408 void IConsoleGUIFree()
409 {
410  IConsoleClearBuffer();
411 }
412 
415 {
416  switch (_iconsole_mode) {
417  case ICONSOLE_OPENED:
418  w->height = _screen.height / 3;
419  w->width = _screen.width;
420  break;
421  case ICONSOLE_FULL:
422  w->height = _screen.height - ICON_BOTTOM_BORDERWIDTH;
423  w->width = _screen.width;
424  break;
425  default: return;
426  }
427 
429 }
430 
433 {
434  switch (_iconsole_mode) {
435  case ICONSOLE_CLOSED:
436  new IConsoleWindow();
437  break;
438 
439  case ICONSOLE_OPENED: case ICONSOLE_FULL:
441  break;
442  }
443 
445 }
446 
449 {
450  if (_iconsole_mode == ICONSOLE_OPENED) IConsoleSwitch();
451 }
452 
459 static const char *IConsoleHistoryAdd(const char *cmd)
460 {
461  /* Strip all spaces at the begin */
462  while (IsWhitespace(*cmd)) cmd++;
463 
464  /* Do not put empty command in history */
465  if (StrEmpty(cmd)) return nullptr;
466 
467  /* Do not put in history if command is same as previous */
468  if (_iconsole_history[0] == nullptr || strcmp(_iconsole_history[0], cmd) != 0) {
469  free(_iconsole_history[ICON_HISTORY_SIZE - 1]);
470  memmove(&_iconsole_history[1], &_iconsole_history[0], sizeof(_iconsole_history[0]) * (ICON_HISTORY_SIZE - 1));
471  _iconsole_history[0] = stredup(cmd);
472  }
473 
474  /* Reset the history position */
475  IConsoleResetHistoryPos();
476  return _iconsole_history[0];
477 }
478 
483 static void IConsoleHistoryNavigate(int direction)
484 {
485  if (_iconsole_history[0] == nullptr) return; // Empty history
486  _iconsole_historypos = Clamp(_iconsole_historypos + direction, -1, ICON_HISTORY_SIZE - 1);
487 
488  if (direction > 0 && _iconsole_history[_iconsole_historypos] == nullptr) _iconsole_historypos--;
489 
490  if (_iconsole_historypos == -1) {
491  _iconsole_cmdline.DeleteAll();
492  } else {
493  _iconsole_cmdline.Assign(_iconsole_history[_iconsole_historypos]);
494  }
495 }
496 
506 void IConsoleGUIPrint(TextColour colour_code, char *str)
507 {
508  new IConsoleLine(str, colour_code);
510 }
511 
512 
519 {
520  /* A normal text colour is used. */
521  if (!(c & TC_IS_PALETTE_COLOUR)) return TC_BEGIN <= c && c < TC_END;
522 
523  /* A text colour from the palette is used; must be the company
524  * colour gradient, so it must be one of those. */
525  c &= ~TC_IS_PALETTE_COLOUR;
526  for (uint i = COLOUR_BEGIN; i < COLOUR_END; i++) {
527  if (_colour_gradient[i][4] == c) return true;
528  }
529 
530  return false;
531 }
EventState
State of handling an event.
Definition: window_type.h:711
Functions related to OTTD&#39;s strings.
Empty widget, place holder to reserve space in widget array.
Definition: widget_type.h:46
uint16 markend
the end position of the marked area in the buffer, in bytes
Definition: textbuf_type.h:42
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:162
static NWidgetPart SetResize(int16 dx, int16 dy)
Widget part function for setting the resize step.
Definition: widget_type.h:928
uint16 chars
the current size of the string in characters (including terminating &#39;\0&#39;)
Definition: textbuf_type.h:36
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:110
void SetWindowDirty(WindowClass cls, WindowNumber number)
Mark window as dirty (in need of repainting)
Definition: window.cpp:3215
High level window description.
Definition: window_gui.h:166
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.
virtual void EditBoxGainedFocus()
An edit box gained the input focus.
The passed event is not handled.
Definition: window_type.h:713
byte _colour_gradient[COLOUR_END][8]
All 16 colour gradients 8 colours per gradient from darkest (0) to lightest (7)
Definition: gfx.cpp:52
Stuff related to text buffers.
static bool IsWhitespace(WChar c)
Check whether UNICODE character is whitespace or not, i.e.
Definition: string_func.h:240
void CDECL void DeleteAll()
Delete every character in the textbuffer.
Definition: textbuf.cpp:116
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:43
IConsoleModes
Modes of the in-game console.
Definition: console_type.h:16
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:30
uint16 bytes
the current size of the string in bytes (including terminating &#39;\0&#39;)
Definition: textbuf_type.h:35
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:24
In-game console is opened, whole screen.
Definition: console_type.h:19
Functions, definitions and such used only by the GUI.
In-game console is closed.
Definition: console_type.h:17
Console; Window numbers:
Definition: window_type.h:631
Force the alignment, i.e. don&#39;t swap for RTL languages.
Definition: gfx_func.h:106
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:908
Data structure for an opened window.
Definition: window_gui.h:276
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:264
void SetDParamStr(uint n, const char *str)
This function is used to "bind" a C string to a OpenTTD dparam slot.
Definition: strings.cpp:279
Functions related to low-level strings.
bool caret
is the caret ("_") visible or not
Definition: textbuf_type.h:38
Container for a single line of console output.
Definition: console_gui.cpp:38
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:43
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:84
uint16 pixels
the current size of the string in pixels
Definition: textbuf_type.h:37
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:176
void IConsoleCmdExec(const char *cmdstr)
Execute a given command passed to us.
Definition: console.cpp:401
Functions related to the gfx engine.
ClientSettings _settings_client
The current settings for this game.
Definition: settings.cpp:78
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:124
Definition of base types and functions in a cross-platform compatible way.
Bottom align the text.
Definition: gfx_func.h:101
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:245
void Scroll(int amount)
Scroll the content of the console.
~IConsoleLine()
Clear this console line and any further ones.
Definition: console_gui.cpp:65
static void Reset()
Reset the complete console line backlog.
Key does not affect editboxes.
Definition: textbuf_type.h:26
static int size
The amount of items in the backlog.
Definition: console_gui.cpp:40
char * stredup(const char *s, const char *last)
Create a duplicate of the given string.
Definition: string.cpp:136
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:44
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:728
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:1112
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:498
#define lengthof(x)
Return the length of an fixed size array.
Definition: depend.cpp:40
static T min(const T a, const T b)
Returns the minimum of two values.
Definition: math_func.hpp:40
#define MAX_UVALUE(type)
The largest value that can be entered in a variable.
Definition: stdafx.h:469
uint16 caretpos
the current position of the caret in the buffer, in bytes
Definition: textbuf_type.h:39
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:39
static const uint8 PC_BLACK
Black palette colour.
Definition: gfx_func.h:203
static const IConsoleLine * Get(uint index)
Get the index-ed item in the list.
Definition: console_gui.cpp:76
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:28
static T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
Definition: math_func.hpp:137
void Assign(StringID string)
Render a string into the textbuffer.
Definition: textbuf.cpp:396
Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition: gfx.cpp:700
No window, redirects to WC_MAIN_WINDOW.
Definition: window_type.h:38
void DeleteWindowById(WindowClass cls, WindowNumber number, bool force)
Delete a window by its class and window number (if it is open).
Definition: window.cpp:1162
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:209
IConsoleLine(char *buffer, TextColour colour)
Initialize the console line.
Definition: console_gui.cpp:52
char *const buf
buffer in which text is saved
Definition: textbuf_type.h:32
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:45
static bool Truncate()
Truncate the list removing everything older than/more than the amount as specified in the config file...
Definition: console_gui.cpp:94
bool HandleCaret()
Handle the flashing of the caret.
Definition: textbuf.cpp:456
static bool StrEmpty(const char *s)
Check if a string buffer is empty.
Definition: string_func.h:57
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:40
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:202
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:268
#define LRM
A left-to-right marker, marks the next character as left-to-right.
Definition: string_type.h:21
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
Definition: depend.cpp:129
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:319
IConsoleLine * previous
The previous console message.
Definition: console_gui.cpp:42
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:712
bool IsValidConsoleColour(TextColour c)
Check whether the given TextColour is valid for console usage.
Left align the text.
Definition: gfx_func.h:94
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:741
Window functions not directly related to making/drawing windows.
Manually align the window (so no automatic location finding)
Definition: window_gui.h:153
uint16 marklength
the length of the marked area in pixels
Definition: textbuf_type.h:44
In-game console is opened, upper 1/3 of the screen.
Definition: console_type.h:18
uint32 WChar
Type for wide characters, i.e.
Definition: string_type.h:35
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:2142
static const TextColour CC_WARNING
Colour for warning lines.
Definition: console_type.h:25
void OnFocus() override
Called when window gains focus.
static const TextColour CC_WHITE
White console lines for various things such as the welcome.
Definition: console_type.h:29
uint16 markpos
the start position of the marked area in the buffer, in bytes
Definition: textbuf_type.h:41
Types related to the console widgets.
void OnFocusLost() override
Called when window loses focus.
int height
Height of the window (number of pixels down in y direction)
Definition: window_gui.h:320
void MarkWholeScreenDirty()
This function mark the whole screen as dirty.
Definition: gfx.cpp:1462
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:621