OpenTTD Source 20260621-master-g720d10536d
osk_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 <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
9
10#include "stdafx.h"
11#include "string_func.h"
12#include "strings_func.h"
13#include "debug.h"
14#include "window_func.h"
15#include "gfx_func.h"
16#include "querystring_gui.h"
18#include "zoom_func.h"
20
21#include "widgets/osk_widget.h"
22
23#include "table/sprites.h"
24#include "table/strings.h"
25
26#include "safeguards.h"
27
28std::string _keyboard_opt[2];
29static char32_t _keyboard[2][OSK_KEYBOARD_ENTRIES];
30
32enum class KeyState : uint8_t {
35};
36
38
39struct OskWindow : public Window {
41 QueryString *qs = nullptr;
43 Textbuf *text = nullptr;
44 std::string orig_str{};
45 bool shift = false;
46
48 static inline KeyStates keystate{};
49
50 OskWindow(WindowDesc &desc, Window *parent, WidgetID button) : Window(desc)
51 {
52 this->parent = parent;
53 assert(parent != nullptr);
54
55 NWidgetCore *par_wid = parent->GetWidget<NWidgetCore>(button);
56 assert(par_wid != nullptr);
57
58 assert(parent->querystrings.count(button) != 0);
59 this->qs = parent->querystrings.find(button)->second;
60 this->caption = (par_wid->GetString() != STR_NULL) ? par_wid->GetString() : this->qs->caption;
61 this->text_btn = button;
62 this->text = &this->qs->text;
63 this->querystrings[WID_OSK_TEXT] = this->qs;
64
65 /* make a copy in case we need to reset later */
66 this->orig_str = this->qs->text.GetText();
67
68 this->InitNested(0);
70
71 /* Not needed by default. */
73
74 this->UpdateOskState();
75 }
76
83 {
85
86 for (uint i = 0; i < OSK_KEYBOARD_ENTRIES; i++) {
88 !IsValidChar(_keyboard[this->shift][i], this->qs->text.afilter) || _keyboard[this->shift][i] == ' ');
89 }
90 this->SetWidgetDisabledState(WID_OSK_SPACE, !IsValidChar(' ', this->qs->text.afilter));
91
94 }
95
96 std::string GetWidgetString(WidgetID widget, StringID stringid) const override
97 {
98 if (widget == WID_OSK_CAPTION) return GetString(this->caption);
99
100 return this->Window::GetWidgetString(widget, stringid);
101 }
102
103 void DrawWidget(const Rect &r, WidgetID widget) const override
104 {
105 if (widget < WID_OSK_LETTERS) return;
106
107 widget -= WID_OSK_LETTERS;
108 DrawCharCentered(_keyboard[this->shift][widget], r, TextColour::Black);
109 }
110
111 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
112 {
113 /* clicked a letter */
114 if (widget >= WID_OSK_LETTERS) {
115 char32_t c = _keyboard[this->shift][widget - WID_OSK_LETTERS];
116
117 if (!IsValidChar(c, this->qs->text.afilter)) return;
118
119 if (this->qs->text.InsertChar(c)) this->OnEditboxChanged(WID_OSK_TEXT);
120
123 this->UpdateOskState();
124 this->SetDirty();
125 }
126 return;
127 }
128
129 switch (widget) {
131 if (this->qs->text.DeleteChar(WKC_BACKSPACE)) this->OnEditboxChanged(WID_OSK_TEXT);
132 break;
133
134 case WID_OSK_SPECIAL:
135 /*
136 * Anything device specific can go here.
137 * The button itself is hidden by default, and when you need it you
138 * can not hide it in the create event.
139 */
140 break;
141
142 case WID_OSK_CAPS:
144 this->UpdateOskState();
145 this->SetDirty();
146 break;
147
148 case WID_OSK_SHIFT:
150 this->UpdateOskState();
151 this->SetDirty();
152 break;
153
154 case WID_OSK_SPACE:
155 if (this->qs->text.InsertChar(' ')) this->OnEditboxChanged(WID_OSK_TEXT);
156 break;
157
158 case WID_OSK_LEFT:
159 if (this->qs->text.MovePos(WKC_LEFT)) this->InvalidateData();
160 break;
161
162 case WID_OSK_RIGHT:
163 if (this->qs->text.MovePos(WKC_RIGHT)) this->InvalidateData();
164 break;
165
166 case WID_OSK_OK:
167 if (!this->qs->orig.has_value() || this->qs->text.GetText() != this->qs->orig) {
168 /* pass information by simulating a button press on parent window */
169 if (this->qs->ok_button >= 0) {
170 this->parent->OnClick(pt, this->qs->ok_button, 1);
171 /* Window gets deleted when the parent window removes itself. */
172 return;
173 }
174 }
175 this->Close();
176 break;
177
178 case WID_OSK_CANCEL:
179 if (this->qs->cancel_button >= 0) { // pass a cancel event to the parent window
180 this->parent->OnClick(pt, this->qs->cancel_button, 1);
181 /* Window gets deleted when the parent window removes itself. */
182 return;
183 } else { // or reset to original string
184 qs->text.Assign(this->orig_str);
185 qs->text.MovePos(WKC_END);
187 this->Close();
188 }
189 break;
190 }
191 }
192
193 void OnEditboxChanged(WidgetID widget) override
194 {
195 if (widget == WID_OSK_TEXT) {
197 this->parent->OnEditboxChanged(this->text_btn);
198 this->parent->SetWidgetDirty(this->text_btn);
199 }
200 }
201
202 void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
203 {
204 if (!gui_scope) return;
206 this->parent->SetWidgetDirty(this->text_btn);
207 }
208
209 void OnFocusLost(bool closing) override
210 {
212 if (!closing) this->Close();
213 }
214};
215
216static const int HALF_KEY_WIDTH = 7;
217static const int INTER_KEY_SPACE = 2;
218
219static const int TOP_KEY_PADDING = 2;
220static const int KEY_PADDING = 6;
221
232static void AddKey(std::unique_ptr<NWidgetHorizontal> &hor, int pad_y, int num_half, WidgetType widtype, WidgetID widnum, const WidgetData &widdata)
233{
234 int key_width = HALF_KEY_WIDTH + (INTER_KEY_SPACE + HALF_KEY_WIDTH) * (num_half - 1);
235
236 if (widtype == NWID_SPACER) {
237 auto spc = std::make_unique<NWidgetSpacer>(key_width, 0);
238 spc->SetMinimalTextLines(1, pad_y, FontSize::Normal);
239 hor->Add(std::move(spc));
240 } else {
241 auto leaf = std::make_unique<NWidgetLeaf>(widtype, Colours::Grey, widnum, widdata, STR_NULL);
242 leaf->SetMinimalSize(key_width, 0);
243 leaf->SetMinimalTextLines(1, pad_y, FontSize::Normal);
244 hor->Add(std::move(leaf));
245 }
246}
247
249static std::unique_ptr<NWidgetBase> MakeTopKeys()
250{
251 auto hor = std::make_unique<NWidgetHorizontal>();
252 hor->SetPIP(0, INTER_KEY_SPACE, 0);
253
254 AddKey(hor, TOP_KEY_PADDING, 6 * 2, WWT_TEXTBTN, WID_OSK_CANCEL, WidgetData{.string = STR_BUTTON_CANCEL});
255 AddKey(hor, TOP_KEY_PADDING, 6 * 2, WWT_TEXTBTN, WID_OSK_OK, WidgetData{.string = STR_BUTTON_OK});
256 AddKey(hor, TOP_KEY_PADDING, 2 * 2, WWT_PUSHIMGBTN, WID_OSK_BACKSPACE, WidgetData{.sprite = SPR_OSK_BACKSPACE});
257 return hor;
258}
259
261static std::unique_ptr<NWidgetBase> MakeNumberKeys()
262{
263 std::unique_ptr<NWidgetHorizontal> hor = std::make_unique<NWidgetHorizontalLTR>();
264 hor->SetPIP(0, INTER_KEY_SPACE, 0);
265
266 for (WidgetID widnum = WID_OSK_NUMBERS_FIRST; widnum <= WID_OSK_NUMBERS_LAST; widnum++) {
267 AddKey(hor, KEY_PADDING, 2, WWT_PUSHBTN, widnum, {});
268 }
269 return hor;
270}
271
273static std::unique_ptr<NWidgetBase> MakeQwertyKeys()
274{
275 std::unique_ptr<NWidgetHorizontal> hor = std::make_unique<NWidgetHorizontalLTR>();
276 hor->SetPIP(0, INTER_KEY_SPACE, 0);
277
278 AddKey(hor, KEY_PADDING, 3, WWT_PUSHIMGBTN, WID_OSK_SPECIAL, WidgetData{.sprite = SPR_OSK_SPECIAL});
279 for (WidgetID widnum = WID_OSK_QWERTY_FIRST; widnum <= WID_OSK_QWERTY_LAST; widnum++) {
280 AddKey(hor, KEY_PADDING, 2, WWT_PUSHBTN, widnum, {});
281 }
282 AddKey(hor, KEY_PADDING, 1, NWID_SPACER, 0, {});
283 return hor;
284}
285
287static std::unique_ptr<NWidgetBase> MakeAsdfgKeys()
288{
289 std::unique_ptr<NWidgetHorizontal> hor = std::make_unique<NWidgetHorizontalLTR>();
290 hor->SetPIP(0, INTER_KEY_SPACE, 0);
291
292 AddKey(hor, KEY_PADDING, 4, WWT_IMGBTN, WID_OSK_CAPS, WidgetData{.sprite = SPR_OSK_CAPS});
293 for (WidgetID widnum = WID_OSK_ASDFG_FIRST; widnum <= WID_OSK_ASDFG_LAST; widnum++) {
294 AddKey(hor, KEY_PADDING, 2, WWT_PUSHBTN, widnum, {});
295 }
296 return hor;
297}
298
300static std::unique_ptr<NWidgetBase> MakeZxcvbKeys()
301{
302 std::unique_ptr<NWidgetHorizontal> hor = std::make_unique<NWidgetHorizontalLTR>();
303 hor->SetPIP(0, INTER_KEY_SPACE, 0);
304
305 AddKey(hor, KEY_PADDING, 3, WWT_IMGBTN, WID_OSK_SHIFT, WidgetData{.sprite = SPR_OSK_SHIFT});
306 for (WidgetID widnum = WID_OSK_ZXCVB_FIRST; widnum <= WID_OSK_ZXCVB_LAST; widnum++) {
307 AddKey(hor, KEY_PADDING, 2, WWT_PUSHBTN, widnum, {});
308 }
309 AddKey(hor, KEY_PADDING, 1, NWID_SPACER, 0, {});
310 return hor;
311}
312
314static std::unique_ptr<NWidgetBase> MakeSpacebarKeys()
315{
316 auto hor = std::make_unique<NWidgetHorizontal>();
317 hor->SetPIP(0, INTER_KEY_SPACE, 0);
318
319 AddKey(hor, KEY_PADDING, 8, NWID_SPACER, 0, {});
320 AddKey(hor, KEY_PADDING, 13, WWT_PUSHTXTBTN, WID_OSK_SPACE, WidgetData{.string = STR_EMPTY});
321 AddKey(hor, KEY_PADDING, 3, NWID_SPACER, 0, {});
322 AddKey(hor, KEY_PADDING, 2, WWT_PUSHIMGBTN, WID_OSK_LEFT, WidgetData{.sprite = SPR_OSK_LEFT});
323 AddKey(hor, KEY_PADDING, 2, WWT_PUSHIMGBTN, WID_OSK_RIGHT, WidgetData{.sprite = SPR_OSK_RIGHT});
324 return hor;
325}
326
327
328static constexpr std::initializer_list<NWidgetPart> _nested_osk_widgets = {
332 EndContainer(),
341 EndContainer(),
342 EndContainer(),
343};
344
347 WindowPosition::Center, {}, 0, 0,
348 WindowClass::OnScreenKeyboard, WindowClass::None,
349 {},
350 _nested_osk_widgets
351);
352
358{
359 std::string keyboard[2];
360 std::string errormark[2]; // used for marking invalid chars
361 bool has_error = false; // true when an invalid char is detected
362
363 keyboard[0] = _keyboard_opt[0].empty() ? GetString(STR_OSK_KEYBOARD_LAYOUT) : _keyboard_opt[0];
364 keyboard[1] = _keyboard_opt[1].empty() ? GetString(STR_OSK_KEYBOARD_LAYOUT_CAPS) : _keyboard_opt[1];
365
366 for (uint j = 0; j < 2; j++) {
367 StringConsumer consumer(keyboard[j]);
368 for (uint i = 0; i < OSK_KEYBOARD_ENTRIES; i++) {
369 /* Be lenient when the last characters are missing (is quite normal) */
370 _keyboard[j][i] = consumer.AnyBytesLeft() ? consumer.ReadUtf8() : ' ';
371
372 if (IsPrintable(_keyboard[j][i])) {
373 errormark[j] += ' ';
374 } else {
375 has_error = true;
376 errormark[j] += '^';
377 _keyboard[j][i] = ' ';
378 }
379 }
380 }
381
382 if (has_error) {
383 ShowInfo("The keyboard layout you selected contains invalid chars. Please check those chars marked with ^.");
384 ShowInfo("Normal keyboard: {}", keyboard[0]);
385 ShowInfo(" {}", errormark[0]);
386 ShowInfo("Caps Lock: {}", keyboard[1]);
387 ShowInfo(" {}", errormark[1]);
388 }
389}
390
397{
398 CloseWindowById(WindowClass::OnScreenKeyboard, 0);
399
401 new OskWindow(_osk_desc, parent, button);
402}
403
411void UpdateOSKOriginalText(const Window *parent, WidgetID button)
412{
413 OskWindow *osk = dynamic_cast<OskWindow *>(FindWindowById(WindowClass::OnScreenKeyboard, 0));
414 if (osk == nullptr || osk->parent != parent || osk->text_btn != button) return;
415
416 osk->orig_str = osk->qs->text.GetText();
417
418 osk->SetDirty();
419}
420
427bool IsOSKOpenedFor(const Window *w, WidgetID button)
428{
429 OskWindow *osk = dynamic_cast<OskWindow *>(FindWindowById(WindowClass::OnScreenKeyboard, 0));
430 return osk != nullptr && osk->parent == w && osk->text_btn == button;
431}
Enum-as-bit-set wrapper.
Base class for a 'real' widget.
StringID GetString() const
Get the string that has been set for this nested widget.
Definition widget.cpp:1281
Parse data from a string / buffer.
char32_t ReadUtf8(char32_t def='?')
Read UTF-8 character, and advance reader.
bool AnyBytesLeft() const noexcept
Check whether any bytes left to read.
virtual void EditBoxLostFocus()
An edit box lost the input focus.
static VideoDriver * GetInstance()
Get the currently active instance of the video driver.
Functions related to debugging.
void DrawCharCentered(char32_t c, const Rect &r, TextColour colour)
Draw single character horizontally centered around (x,y).
Definition gfx.cpp:954
Functions related to the gfx engine.
@ Normal
Index of the normal font in the font tables.
Definition gfx_type.h:249
@ Grey
Grey.
Definition gfx_type.h:300
@ White
White colour.
Definition gfx_type.h:331
@ Black
Black colour.
Definition gfx_type.h:335
constexpr NWidgetPart NWidgetFunction(NWidgetFunctionType *func_ptr)
Obtain a nested widget (sub)tree from an external source.
constexpr NWidgetPart SetPIP(uint8_t pre, uint8_t inter, uint8_t post)
Widget part function for setting a pre/inter/post spaces.
constexpr NWidgetPart SetPadding(uint8_t top, uint8_t right, uint8_t bottom, uint8_t left)
Widget part function for setting additional space around a widget.
constexpr NWidgetPart SetMinimalSize(int16_t x, int16_t y)
Widget part function for setting the minimal size.
constexpr NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
constexpr NWidgetPart SetTextStyle(TextColour colour, FontSize size=FontSize::Normal)
Widget part function for setting the text style.
constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx=INVALID_WIDGET)
Widget part function for starting a new 'real' widget.
void SetDirty() const
Mark entire window as dirty (in need of re-paint).
Definition window.cpp:972
#define Point
Macro that prevents name conflicts between included headers.
static void AddKey(std::unique_ptr< NWidgetHorizontal > &hor, int pad_y, int num_half, WidgetType widtype, WidgetID widnum, const WidgetData &widdata)
Add a key widget to a row of the keyboard.
Definition osk_gui.cpp:232
static const int TOP_KEY_PADDING
Vertical padding for the top row of keys.
Definition osk_gui.cpp:219
static std::unique_ptr< NWidgetBase > MakeZxcvbKeys()
Construct the zxcvb row keys.
Definition osk_gui.cpp:300
static const int INTER_KEY_SPACE
Number of pixels between two keys.
Definition osk_gui.cpp:217
static const int HALF_KEY_WIDTH
Width of 1/2 key in pixels.
Definition osk_gui.cpp:216
void ShowOnScreenKeyboard(Window *parent, WidgetID button)
Show the on-screen keyboard (osk) associated with a given textbox.
Definition osk_gui.cpp:396
std::string _keyboard_opt[2]
The number of characters has to be OSK_KEYBOARD_ENTRIES.
Definition osk_gui.cpp:28
KeyState
Keys that modify the behaviour/visuals of the keyboard.
Definition osk_gui.cpp:32
@ Shift
Shift key.
Definition osk_gui.cpp:33
@ Capslock
Capslock key.
Definition osk_gui.cpp:34
static std::unique_ptr< NWidgetBase > MakeNumberKeys()
Construct the row containing the digit keys.
Definition osk_gui.cpp:261
EnumBitSet< KeyState, uint8_t > KeyStates
Bitset of KeyState elements.
Definition osk_gui.cpp:37
static const int KEY_PADDING
Vertical padding for remaining key rows.
Definition osk_gui.cpp:220
static std::unique_ptr< NWidgetBase > MakeAsdfgKeys()
Construct the asdfg row keys.
Definition osk_gui.cpp:287
static std::unique_ptr< NWidgetBase > MakeTopKeys()
Construct the top row keys (cancel, ok, backspace).
Definition osk_gui.cpp:249
void GetKeyboardLayout()
Retrieve keyboard layout from language string or (if set) config file.
Definition osk_gui.cpp:357
static std::unique_ptr< NWidgetBase > MakeSpacebarKeys()
Construct the spacebar row keys.
Definition osk_gui.cpp:314
bool IsOSKOpenedFor(const Window *w, WidgetID button)
Check whether the OSK is opened for a specific editbox.
Definition osk_gui.cpp:427
void UpdateOSKOriginalText(const Window *parent, WidgetID button)
Updates the original text of the OSK so when the 'parent' changes the original and you press on cance...
Definition osk_gui.cpp:411
static std::unique_ptr< NWidgetBase > MakeQwertyKeys()
Construct the qwerty row keys.
Definition osk_gui.cpp:273
static WindowDesc _osk_desc(WindowPosition::Center, {}, 0, 0, WindowClass::OnScreenKeyboard, WindowClass::None, {}, _nested_osk_widgets)
Window definition for the on screen keyboard window.
Types related to the osk widgets.
@ WID_OSK_CAPTION
Caption of window.
Definition osk_widget.h:15
@ WID_OSK_QWERTY_FIRST
First widget of the qwerty row.
Definition osk_widget.h:31
@ WID_OSK_BACKSPACE
Backspace key.
Definition osk_widget.h:19
@ WID_OSK_SPACE
Space bar.
Definition osk_widget.h:23
@ WID_OSK_TEXT
Edit box.
Definition osk_widget.h:16
@ WID_OSK_QWERTY_LAST
Last widget of the qwerty row.
Definition osk_widget.h:32
@ WID_OSK_CANCEL
Cancel key.
Definition osk_widget.h:17
@ WID_OSK_LEFT
Cursor left key.
Definition osk_widget.h:24
@ WID_OSK_RIGHT
Cursor right key.
Definition osk_widget.h:25
@ WID_OSK_NUMBERS_FIRST
First widget of the numbers row.
Definition osk_widget.h:28
@ WID_OSK_SPECIAL
Special key (at keyboards often used for tab key).
Definition osk_widget.h:20
@ WID_OSK_CAPS
Capslock key.
Definition osk_widget.h:21
@ WID_OSK_OK
Ok key.
Definition osk_widget.h:18
@ WID_OSK_ASDFG_LAST
Last widget of the asdfg row.
Definition osk_widget.h:35
@ WID_OSK_ZXCVB_FIRST
First widget of the zxcvb row.
Definition osk_widget.h:37
@ WID_OSK_LETTERS
First widget of the 'normal' keys.
Definition osk_widget.h:26
@ WID_OSK_ASDFG_FIRST
First widget of the asdfg row.
Definition osk_widget.h:34
@ WID_OSK_SHIFT
Shift(lock) key.
Definition osk_widget.h:22
@ WID_OSK_ZXCVB_LAST
Last widget of the zxcvb row.
Definition osk_widget.h:38
@ WID_OSK_NUMBERS_LAST
Last widget of the numbers row.
Definition osk_widget.h:29
Base for the GUIs that have an edit box in them.
A number of safeguards to prevent using unsafe methods.
This file contains all sprite-related enums and defines.
Definition of base types and functions in a cross-platform compatible way.
bool IsValidChar(char32_t key, CharSetFilter afilter)
Only allow certain keys.
Definition string.cpp:375
Parse strings.
Functions related to low-level strings.
std::string GetString(StringID string)
Resolve the given StringID into a std::string with formatting but no parameters.
Definition strings.cpp:424
Functions related to OTTD's strings.
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
StringID caption
the caption for this window.
Definition osk_gui.cpp:40
WidgetID text_btn
widget number of parent's text field
Definition osk_gui.cpp:42
bool shift
Is the shift effectively pressed?
Definition osk_gui.cpp:45
static KeyStates keystate
States of the keys of the on screen window.
Definition osk_gui.cpp:48
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
Definition osk_gui.cpp:103
void OnEditboxChanged(WidgetID widget) override
The text in an editbox has been edited.
Definition osk_gui.cpp:193
void OnFocusLost(bool closing) override
The window has lost focus.
Definition osk_gui.cpp:209
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition osk_gui.cpp:202
QueryString * qs
text-input
Definition osk_gui.cpp:41
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
Definition osk_gui.cpp:111
std::string orig_str
Original string.
Definition osk_gui.cpp:44
std::string GetWidgetString(WidgetID widget, StringID stringid) const override
Get the raw string for a widget.
Definition osk_gui.cpp:96
Textbuf * text
pointer to parent's textbuffer (to update caret position)
Definition osk_gui.cpp:43
void UpdateOskState()
Only show valid characters; do not show characters that would only insert a space when we have a spac...
Definition osk_gui.cpp:82
Data stored about a string that can be modified in the GUI.
int ok_button
Widget button of parent window to simulate when pressing OK in OSK.
int cancel_button
Widget button of parent window to simulate when pressing CANCEL in OSK.
Specification of a rectangle with absolute coordinates of all edges.
Helper/buffer for input fields.
bool MovePos(uint16_t keycode)
Handle text navigation with arrow keys left/right.
Definition textbuf.cpp:363
bool DeleteChar(uint16_t keycode)
Delete a character from a textbuffer, either with 'Delete' or 'Backspace' The character is delete fro...
Definition textbuf.cpp:51
std::string_view GetText() const
Get the current text.
Definition textbuf.cpp:284
CharSetFilter afilter
Allowed characters.
bool InsertChar(char32_t key)
Insert a character to a textbuffer.
Definition textbuf.cpp:128
Container with the data associated to a single widget.
High level window description.
Definition window_gui.h:172
Data structure for an opened window.
Definition window_gui.h:273
virtual void Close(int data=0)
Hide the window and all its child windows, and mark them for a later deletion.
Definition window.cpp:1109
std::map< WidgetID, QueryString * > querystrings
QueryString associated to WWT_EDITBOX widgets.
Definition window_gui.h:320
void InvalidateData(int data=0, bool gui_scope=true)
Mark this window's data as invalid (in need of re-computing).
Definition window.cpp:3255
Window * parent
Parent window.
Definition window_gui.h:328
void SetWidgetDirty(WidgetID widget_index) const
Invalidate a widget, i.e.
Definition window.cpp:562
virtual std::string GetWidgetString(WidgetID widget, StringID stringid) const
Get the raw string for a widget.
Definition window.cpp:510
void DisableWidget(WidgetID widget_index)
Sets a widget to disabled.
Definition window_gui.h:391
bool SetFocusedWidget(WidgetID widget_index)
Set focus within this window to the given widget.
Definition window.cpp:491
void SetWidgetLoweredState(WidgetID widget_index, bool lowered_stat)
Sets the lowered/raised status of a widget.
Definition window_gui.h:441
virtual void OnEditboxChanged(WidgetID widget)
The text in an editbox has been edited.
Definition window_gui.h:783
virtual void OnClick(Point pt, WidgetID widget, int click_count)
A click with the left mouse button has been made on the window.
Definition window_gui.h:671
Window(WindowDesc &desc)
Empty constructor, initialization has been moved to InitNested() called from the constructor of the d...
Definition window.cpp:1838
const NWID * GetWidget(WidgetID widnum) const
Get the nested widget with number widnum from the nested widget tree.
Definition window_gui.h:989
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
Definition window.cpp:1828
void SetWidgetDisabledState(WidgetID widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
Definition window_gui.h:381
static const uint OSK_KEYBOARD_ENTRIES
The number of 'characters' on the on-screen keyboard.
Definition textbuf_gui.h:36
Base of all video drivers.
WidgetType
Window widget types, nested widget types, and nested widget part types.
Definition widget_type.h:35
@ WWT_PUSHTXTBTN
Normal push-button (no toggle button) with text caption.
@ WWT_IMGBTN
(Toggle) Button with image
Definition widget_type.h:41
@ WWT_PUSHBTN
Normal push-button (no toggle button) with custom drawing.
@ WWT_PUSHIMGBTN
Normal push-button (no toggle button) with image caption.
@ NWID_SPACER
Invisible widget that takes some space.
Definition widget_type.h:70
@ WWT_EDITBOX
a textbox for typing
Definition widget_type.h:62
@ WWT_TEXTBTN
(Toggle) Button with text
Definition widget_type.h:44
@ WWT_PANEL
Simple depressed panel.
Definition widget_type.h:39
@ WWT_CAPTION
Window caption (window title between closebox and stickybox).
Definition widget_type.h:52
@ NWID_VERTICAL
Vertical container.
Definition widget_type.h:68
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:1201
Window * FindWindowById(WindowClass cls, WindowNumber number)
Find a window by its class and window number.
Definition window.cpp:1158
Window functions not directly related to making/drawing windows.
@ Center
Center the window.
Definition window_gui.h:147
int WidgetID
Widget ID.
Definition window_type.h:21
Functions related to zooming.