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