OpenTTD Source: src/osk_gui.cpp Source File

OpenTTD Source 15.3

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
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"
17#include "video/video_driver.hpp"
18#include "zoom_func.h"
19#include "core/string_consumer.hpp"
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
31enum KeyStateBits : uint8_t {
32 KEYS_NONE,
33 KEYS_SHIFT,
34 KEYS_CAPS
35};
36static uint8_t _keystate = KEYS_NONE;
37
38 struct OskWindow : public Window {
39 StringID caption{};
40 QueryString *qs = nullptr;
41 WidgetID text_btn{};
42 Textbuf *text = nullptr;
43 std::string orig_str{};
44 bool shift = false;
45
46 OskWindow(WindowDesc &desc, Window *parent, WidgetID button) : Window(desc)
47 {
48 this->parent = parent;
49 assert(parent != nullptr);
50
51 NWidgetCore *par_wid = parent->GetWidget<NWidgetCore>(button);
52 assert(par_wid != nullptr);
53
54 assert(parent->querystrings.count(button) != 0);
55 this->qs = parent->querystrings.find(button)->second;
56 this->caption = (par_wid->GetString() != STR_NULL) ? par_wid->GetString() : this->qs->caption;
57 this->text_btn = button;
58 this->text = &this->qs->text;
59 this->querystrings[WID_OSK_TEXT] = this->qs;
60
61 /* make a copy in case we need to reset later */
62 this->orig_str = this->qs->text.GetText();
63
64 this->InitNested(0);
65 this->SetFocusedWidget(WID_OSK_TEXT);
66
67 /* Not needed by default. */
68 this->DisableWidget(WID_OSK_SPECIAL);
69
70 this->UpdateOskState();
71 }
72
78 void UpdateOskState()
79 {
80 this->shift = HasBit(_keystate, KEYS_CAPS) ^ HasBit(_keystate, KEYS_SHIFT);
81
82 for (uint i = 0; i < OSK_KEYBOARD_ENTRIES; i++) {
83 this->SetWidgetDisabledState(WID_OSK_LETTERS + i,
84 !IsValidChar(_keyboard[this->shift][i], this->qs->text.afilter) || _keyboard[this->shift][i] == ' ');
85 }
86 this->SetWidgetDisabledState(WID_OSK_SPACE, !IsValidChar(' ', this->qs->text.afilter));
87
88 this->SetWidgetLoweredState(WID_OSK_SHIFT, HasBit(_keystate, KEYS_SHIFT));
89 this->SetWidgetLoweredState(WID_OSK_CAPS, HasBit(_keystate, KEYS_CAPS));
90 }
91
92 std::string GetWidgetString(WidgetID widget, StringID stringid) const override
93 {
94 if (widget == WID_OSK_CAPTION) return GetString(this->caption);
95
96 return this->Window::GetWidgetString(widget, stringid);
97 }
98
99 void DrawWidget(const Rect &r, WidgetID widget) const override
100 {
101 if (widget < WID_OSK_LETTERS) return;
102
103 widget -= WID_OSK_LETTERS;
104 DrawCharCentered(_keyboard[this->shift][widget], r, TC_BLACK);
105 }
106
107 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
108 {
109 /* clicked a letter */
110 if (widget >= WID_OSK_LETTERS) {
111 char32_t c = _keyboard[this->shift][widget - WID_OSK_LETTERS];
112
113 if (!IsValidChar(c, this->qs->text.afilter)) return;
114
115 if (this->qs->text.InsertChar(c)) this->OnEditboxChanged(WID_OSK_TEXT);
116
117 if (HasBit(_keystate, KEYS_SHIFT)) {
118 ToggleBit(_keystate, KEYS_SHIFT);
119 this->UpdateOskState();
120 this->SetDirty();
121 }
122 return;
123 }
124
125 switch (widget) {
126 case WID_OSK_BACKSPACE:
127 if (this->qs->text.DeleteChar(WKC_BACKSPACE)) this->OnEditboxChanged(WID_OSK_TEXT);
128 break;
129
130 case WID_OSK_SPECIAL:
131 /*
132 * Anything device specific can go here.
133 * The button itself is hidden by default, and when you need it you
134 * can not hide it in the create event.
135 */
136 break;
137
138 case WID_OSK_CAPS:
139 ToggleBit(_keystate, KEYS_CAPS);
140 this->UpdateOskState();
141 this->SetDirty();
142 break;
143
144 case WID_OSK_SHIFT:
145 ToggleBit(_keystate, KEYS_SHIFT);
146 this->UpdateOskState();
147 this->SetDirty();
148 break;
149
150 case WID_OSK_SPACE:
151 if (this->qs->text.InsertChar(' ')) this->OnEditboxChanged(WID_OSK_TEXT);
152 break;
153
154 case WID_OSK_LEFT:
155 if (this->qs->text.MovePos(WKC_LEFT)) this->InvalidateData();
156 break;
157
158 case WID_OSK_RIGHT:
159 if (this->qs->text.MovePos(WKC_RIGHT)) this->InvalidateData();
160 break;
161
162 case WID_OSK_OK:
163 if (!this->qs->orig.has_value() || this->qs->text.GetText() != this->qs->orig) {
164 /* pass information by simulating a button press on parent window */
165 if (this->qs->ok_button >= 0) {
166 this->parent->OnClick(pt, this->qs->ok_button, 1);
167 /* Window gets deleted when the parent window removes itself. */
168 return;
169 }
170 }
171 this->Close();
172 break;
173
174 case WID_OSK_CANCEL:
175 if (this->qs->cancel_button >= 0) { // pass a cancel event to the parent window
176 this->parent->OnClick(pt, this->qs->cancel_button, 1);
177 /* Window gets deleted when the parent window removes itself. */
178 return;
179 } else { // or reset to original string
180 qs->text.Assign(this->orig_str);
181 qs->text.MovePos(WKC_END);
182 this->OnEditboxChanged(WID_OSK_TEXT);
183 this->Close();
184 }
185 break;
186 }
187 }
188
189 void OnEditboxChanged(WidgetID widget) override
190 {
191 if (widget == WID_OSK_TEXT) {
192 this->SetWidgetDirty(WID_OSK_TEXT);
193 this->parent->OnEditboxChanged(this->text_btn);
194 this->parent->SetWidgetDirty(this->text_btn);
195 }
196 }
197
198 void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
199 {
200 if (!gui_scope) return;
201 this->SetWidgetDirty(WID_OSK_TEXT);
202 this->parent->SetWidgetDirty(this->text_btn);
203 }
204
205 void OnFocusLost(bool closing) override
206 {
207 VideoDriver::GetInstance()->EditBoxLostFocus();
208 if (!closing) this->Close();
209 }
210};
211
212static const int HALF_KEY_WIDTH = 7; // Width of 1/2 key in pixels.
213static const int INTER_KEY_SPACE = 2; // Number of pixels between two keys.
214
215static const int TOP_KEY_PADDING = 2; // Vertical padding for the top row of keys.
216static const int KEY_PADDING = 6; // Vertical padding for remaining key rows.
217
228 static void AddKey(std::unique_ptr<NWidgetHorizontal> &hor, int pad_y, int num_half, WidgetType widtype, WidgetID widnum, const WidgetData &widdata)
229{
230 int key_width = HALF_KEY_WIDTH + (INTER_KEY_SPACE + HALF_KEY_WIDTH) * (num_half - 1);
231
232 if (widtype == NWID_SPACER) {
233 auto spc = std::make_unique<NWidgetSpacer>(key_width, 0);
234 spc->SetMinimalTextLines(1, pad_y, FS_NORMAL);
235 hor->Add(std::move(spc));
236 } else {
237 auto leaf = std::make_unique<NWidgetLeaf>(widtype, COLOUR_GREY, widnum, widdata, STR_NULL);
238 leaf->SetMinimalSize(key_width, 0);
239 leaf->SetMinimalTextLines(1, pad_y, FS_NORMAL);
240 hor->Add(std::move(leaf));
241 }
242}
243
245 static std::unique_ptr<NWidgetBase> MakeTopKeys()
246{
247 auto hor = std::make_unique<NWidgetHorizontal>();
248 hor->SetPIP(0, INTER_KEY_SPACE, 0);
249
250 AddKey(hor, TOP_KEY_PADDING, 6 * 2, WWT_TEXTBTN, WID_OSK_CANCEL, WidgetData{.string = STR_BUTTON_CANCEL});
251 AddKey(hor, TOP_KEY_PADDING, 6 * 2, WWT_TEXTBTN, WID_OSK_OK, WidgetData{.string = STR_BUTTON_OK});
252 AddKey(hor, TOP_KEY_PADDING, 2 * 2, WWT_PUSHIMGBTN, WID_OSK_BACKSPACE, WidgetData{.sprite = SPR_OSK_BACKSPACE});
253 return hor;
254}
255
257 static std::unique_ptr<NWidgetBase> MakeNumberKeys()
258{
259 std::unique_ptr<NWidgetHorizontal> hor = std::make_unique<NWidgetHorizontalLTR>();
260 hor->SetPIP(0, INTER_KEY_SPACE, 0);
261
262 for (WidgetID widnum = WID_OSK_NUMBERS_FIRST; widnum <= WID_OSK_NUMBERS_LAST; widnum++) {
263 AddKey(hor, KEY_PADDING, 2, WWT_PUSHBTN, widnum, {});
264 }
265 return hor;
266}
267
269 static std::unique_ptr<NWidgetBase> MakeQwertyKeys()
270{
271 std::unique_ptr<NWidgetHorizontal> hor = std::make_unique<NWidgetHorizontalLTR>();
272 hor->SetPIP(0, INTER_KEY_SPACE, 0);
273
274 AddKey(hor, KEY_PADDING, 3, WWT_PUSHIMGBTN, WID_OSK_SPECIAL, WidgetData{.sprite = SPR_OSK_SPECIAL});
275 for (WidgetID widnum = WID_OSK_QWERTY_FIRST; widnum <= WID_OSK_QWERTY_LAST; widnum++) {
276 AddKey(hor, KEY_PADDING, 2, WWT_PUSHBTN, widnum, {});
277 }
278 AddKey(hor, KEY_PADDING, 1, NWID_SPACER, 0, {});
279 return hor;
280}
281
283 static std::unique_ptr<NWidgetBase> MakeAsdfgKeys()
284{
285 std::unique_ptr<NWidgetHorizontal> hor = std::make_unique<NWidgetHorizontalLTR>();
286 hor->SetPIP(0, INTER_KEY_SPACE, 0);
287
288 AddKey(hor, KEY_PADDING, 4, WWT_IMGBTN, WID_OSK_CAPS, WidgetData{.sprite = SPR_OSK_CAPS});
289 for (WidgetID widnum = WID_OSK_ASDFG_FIRST; widnum <= WID_OSK_ASDFG_LAST; widnum++) {
290 AddKey(hor, KEY_PADDING, 2, WWT_PUSHBTN, widnum, {});
291 }
292 return hor;
293}
294
296 static std::unique_ptr<NWidgetBase> MakeZxcvbKeys()
297{
298 std::unique_ptr<NWidgetHorizontal> hor = std::make_unique<NWidgetHorizontalLTR>();
299 hor->SetPIP(0, INTER_KEY_SPACE, 0);
300
301 AddKey(hor, KEY_PADDING, 3, WWT_IMGBTN, WID_OSK_SHIFT, WidgetData{.sprite = SPR_OSK_SHIFT});
302 for (WidgetID widnum = WID_OSK_ZXCVB_FIRST; widnum <= WID_OSK_ZXCVB_LAST; widnum++) {
303 AddKey(hor, KEY_PADDING, 2, WWT_PUSHBTN, widnum, {});
304 }
305 AddKey(hor, KEY_PADDING, 1, NWID_SPACER, 0, {});
306 return hor;
307}
308
310 static std::unique_ptr<NWidgetBase> MakeSpacebarKeys()
311{
312 auto hor = std::make_unique<NWidgetHorizontal>();
313 hor->SetPIP(0, INTER_KEY_SPACE, 0);
314
315 AddKey(hor, KEY_PADDING, 8, NWID_SPACER, 0, {});
316 AddKey(hor, KEY_PADDING, 13, WWT_PUSHTXTBTN, WID_OSK_SPACE, WidgetData{.string = STR_EMPTY});
317 AddKey(hor, KEY_PADDING, 3, NWID_SPACER, 0, {});
318 AddKey(hor, KEY_PADDING, 2, WWT_PUSHIMGBTN, WID_OSK_LEFT, WidgetData{.sprite = SPR_OSK_LEFT});
319 AddKey(hor, KEY_PADDING, 2, WWT_PUSHIMGBTN, WID_OSK_RIGHT, WidgetData{.sprite = SPR_OSK_RIGHT});
320 return hor;
321}
322
323
324static constexpr std::initializer_list<NWidgetPart> _nested_osk_widgets = {
325 NWidget(WWT_CAPTION, COLOUR_GREY, WID_OSK_CAPTION), SetTextStyle(TC_WHITE),
326 NWidget(WWT_PANEL, COLOUR_GREY),
327 NWidget(WWT_EDITBOX, COLOUR_GREY, WID_OSK_TEXT), SetMinimalSize(252, 0), SetPadding(2, 2, 2, 2),
328 EndContainer(),
329 NWidget(WWT_PANEL, COLOUR_GREY),
330 NWidget(NWID_VERTICAL), SetPadding(3), SetPIP(0, INTER_KEY_SPACE, 0),
331 NWidgetFunction(MakeTopKeys),
332 NWidgetFunction(MakeNumberKeys),
333 NWidgetFunction(MakeQwertyKeys),
334 NWidgetFunction(MakeAsdfgKeys),
335 NWidgetFunction(MakeZxcvbKeys),
336 NWidgetFunction(MakeSpacebarKeys),
337 EndContainer(),
338 EndContainer(),
339};
340
341static WindowDesc _osk_desc(
342 WDP_CENTER, {}, 0, 0,
343 WC_OSK, WC_NONE,
344 {},
345 _nested_osk_widgets
346);
347
352 void GetKeyboardLayout()
353{
354 std::string keyboard[2];
355 std::string errormark[2]; // used for marking invalid chars
356 bool has_error = false; // true when an invalid char is detected
357
358 keyboard[0] = _keyboard_opt[0].empty() ? GetString(STR_OSK_KEYBOARD_LAYOUT) : _keyboard_opt[0];
359 keyboard[1] = _keyboard_opt[1].empty() ? GetString(STR_OSK_KEYBOARD_LAYOUT_CAPS) : _keyboard_opt[1];
360
361 for (uint j = 0; j < 2; j++) {
362 StringConsumer consumer(keyboard[j]);
363 for (uint i = 0; i < OSK_KEYBOARD_ENTRIES; i++) {
364 /* Be lenient when the last characters are missing (is quite normal) */
365 _keyboard[j][i] = consumer.AnyBytesLeft() ? consumer.ReadUtf8() : ' ';
366
367 if (IsPrintable(_keyboard[j][i])) {
368 errormark[j] += ' ';
369 } else {
370 has_error = true;
371 errormark[j] += '^';
372 _keyboard[j][i] = ' ';
373 }
374 }
375 }
376
377 if (has_error) {
378 ShowInfo("The keyboard layout you selected contains invalid chars. Please check those chars marked with ^.");
379 ShowInfo("Normal keyboard: {}", keyboard[0]);
380 ShowInfo(" {}", errormark[0]);
381 ShowInfo("Caps Lock: {}", keyboard[1]);
382 ShowInfo(" {}", errormark[1]);
383 }
384}
385
391 void ShowOnScreenKeyboard(Window *parent, WidgetID button)
392{
393 CloseWindowById(WC_OSK, 0);
394
395 GetKeyboardLayout();
396 new OskWindow(_osk_desc, parent, button);
397}
398
406 void UpdateOSKOriginalText(const Window *parent, WidgetID button)
407{
408 OskWindow *osk = dynamic_cast<OskWindow *>(FindWindowById(WC_OSK, 0));
409 if (osk == nullptr || osk->parent != parent || osk->text_btn != button) return;
410
411 osk->orig_str = osk->qs->text.GetText();
412
413 osk->SetDirty();
414}
415
422 bool IsOSKOpenedFor(const Window *w, WidgetID button)
423{
424 OskWindow *osk = dynamic_cast<OskWindow *>(FindWindowById(WC_OSK, 0));
425 return osk != nullptr && osk->parent == w && osk->text_btn == button;
426}
HasBit
constexpr bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
Definition bitmath_func.hpp:103
ToggleBit
constexpr T ToggleBit(T &x, const uint8_t y)
Toggles a bit in a variable.
Definition bitmath_func.hpp:157
NWidgetCore
Base class for a 'real' widget.
Definition widget_type.h:371
NWidgetCore::GetString
StringID GetString() const
Get the string that has been set for this nested widget.
Definition widget.cpp:1279
StringConsumer
Parse data from a string / buffer.
Definition string_consumer.hpp:27
StringConsumer::ReadUtf8
char32_t ReadUtf8(char32_t def='?')
Read UTF-8 character, and advance reader.
Definition string_consumer.hpp:425
StringConsumer::AnyBytesLeft
bool AnyBytesLeft() const noexcept
Check whether any bytes left to read.
Definition string_consumer.hpp:70
VideoDriver::EditBoxLostFocus
virtual void EditBoxLostFocus()
An edit box lost the input focus.
Definition video_driver.hpp:153
VideoDriver::GetInstance
static VideoDriver * GetInstance()
Get the currently active instance of the video driver.
Definition video_driver.hpp:192
debug.h
Functions related to debugging.
DrawCharCentered
void DrawCharCentered(char32_t c, const Rect &r, TextColour colour)
Draw single character horizontally centered around (x,y)
Definition gfx.cpp:951
gfx_func.h
Functions related to the gfx engine.
FS_NORMAL
@ FS_NORMAL
Index of the normal font in the font tables.
Definition gfx_type.h:249
NWidgetFunction
constexpr NWidgetPart NWidgetFunction(NWidgetFunctionType *func_ptr)
Obtain a nested widget (sub)tree from an external source.
Definition widget_type.h:1448
SetPIP
constexpr NWidgetPart SetPIP(uint8_t pre, uint8_t inter, uint8_t post)
Widget part function for setting a pre/inter/post spaces.
Definition widget_type.h:1378
SetPadding
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.
Definition widget_type.h:1335
SetTextStyle
constexpr NWidgetPart SetTextStyle(TextColour colour, FontSize size=FS_NORMAL)
Widget part function for setting the text style.
Definition widget_type.h:1201
SetMinimalSize
constexpr NWidgetPart SetMinimalSize(int16_t x, int16_t y)
Widget part function for setting the minimal size.
Definition widget_type.h:1159
EndContainer
constexpr NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
Definition widget_type.h:1232
NWidget
constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx=INVALID_WIDGET)
Widget part function for starting a new 'real' widget.
Definition widget_type.h:1427
Window::SetDirty
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Definition window.cpp:968
AddKey
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:228
MakeZxcvbKeys
static std::unique_ptr< NWidgetBase > MakeZxcvbKeys()
Construct the zxcvb row keys.
Definition osk_gui.cpp:296
ShowOnScreenKeyboard
void ShowOnScreenKeyboard(Window *parent, WidgetID button)
Show the on-screen keyboard (osk) associated with a given textbox.
Definition osk_gui.cpp:391
_keyboard_opt
std::string _keyboard_opt[2]
The number of characters has to be OSK_KEYBOARD_ENTRIES.
Definition osk_gui.cpp:28
MakeNumberKeys
static std::unique_ptr< NWidgetBase > MakeNumberKeys()
Construct the row containing the digit keys.
Definition osk_gui.cpp:257
MakeAsdfgKeys
static std::unique_ptr< NWidgetBase > MakeAsdfgKeys()
Construct the asdfg row keys.
Definition osk_gui.cpp:283
MakeTopKeys
static std::unique_ptr< NWidgetBase > MakeTopKeys()
Construct the top row keys (cancel, ok, backspace).
Definition osk_gui.cpp:245
GetKeyboardLayout
void GetKeyboardLayout()
Retrieve keyboard layout from language string or (if set) config file.
Definition osk_gui.cpp:352
MakeSpacebarKeys
static std::unique_ptr< NWidgetBase > MakeSpacebarKeys()
Construct the spacebar row keys.
Definition osk_gui.cpp:310
IsOSKOpenedFor
bool IsOSKOpenedFor(const Window *w, WidgetID button)
Check whether the OSK is opened for a specific editbox.
Definition osk_gui.cpp:422
UpdateOSKOriginalText
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:406
MakeQwertyKeys
static std::unique_ptr< NWidgetBase > MakeQwertyKeys()
Construct the qwerty row keys.
Definition osk_gui.cpp:269
osk_widget.h
Types related to the osk widgets.
WID_OSK_CAPTION
@ WID_OSK_CAPTION
Caption of window.
Definition osk_widget.h:15
WID_OSK_QWERTY_FIRST
@ WID_OSK_QWERTY_FIRST
First widget of the qwerty row.
Definition osk_widget.h:31
WID_OSK_BACKSPACE
@ WID_OSK_BACKSPACE
Backspace key.
Definition osk_widget.h:19
WID_OSK_SPACE
@ WID_OSK_SPACE
Space bar.
Definition osk_widget.h:23
WID_OSK_TEXT
@ WID_OSK_TEXT
Edit box.
Definition osk_widget.h:16
WID_OSK_QWERTY_LAST
@ WID_OSK_QWERTY_LAST
Last widget of the qwerty row.
Definition osk_widget.h:32
WID_OSK_CANCEL
@ WID_OSK_CANCEL
Cancel key.
Definition osk_widget.h:17
WID_OSK_LEFT
@ WID_OSK_LEFT
Cursor left key.
Definition osk_widget.h:24
WID_OSK_RIGHT
@ WID_OSK_RIGHT
Cursor right key.
Definition osk_widget.h:25
WID_OSK_NUMBERS_FIRST
@ WID_OSK_NUMBERS_FIRST
First widget of the numbers row.
Definition osk_widget.h:28
WID_OSK_SPECIAL
@ WID_OSK_SPECIAL
Special key (at keyboards often used for tab key).
Definition osk_widget.h:20
WID_OSK_CAPS
@ WID_OSK_CAPS
Capslock key.
Definition osk_widget.h:21
WID_OSK_OK
@ WID_OSK_OK
Ok key.
Definition osk_widget.h:18
WID_OSK_ASDFG_LAST
@ WID_OSK_ASDFG_LAST
Last widget of the asdfg row.
Definition osk_widget.h:35
WID_OSK_ZXCVB_FIRST
@ WID_OSK_ZXCVB_FIRST
First widget of the zxcvb row.
Definition osk_widget.h:37
WID_OSK_LETTERS
@ WID_OSK_LETTERS
First widget of the 'normal' keys.
Definition osk_widget.h:26
WID_OSK_ASDFG_FIRST
@ WID_OSK_ASDFG_FIRST
First widget of the asdfg row.
Definition osk_widget.h:34
WID_OSK_SHIFT
@ WID_OSK_SHIFT
Shift(lock) key.
Definition osk_widget.h:22
WID_OSK_ZXCVB_LAST
@ WID_OSK_ZXCVB_LAST
Last widget of the zxcvb row.
Definition osk_widget.h:38
WID_OSK_NUMBERS_LAST
@ WID_OSK_NUMBERS_LAST
Last widget of the numbers row.
Definition osk_widget.h:29
querystring_gui.h
Base for the GUIs that have an edit box in them.
safeguards.h
A number of safeguards to prevent using unsafe methods.
sprites.h
This file contains all sprite-related enums and defines.
stdafx.h
Definition of base types and functions in a cross-platform compatible way.
IsValidChar
bool IsValidChar(char32_t key, CharSetFilter afilter)
Only allow certain keys.
Definition string.cpp:373
string_consumer.hpp
Parse strings.
string_func.h
Functions related to low-level strings.
GetString
std::string GetString(StringID string)
Resolve the given StringID into a std::string with formatting but no parameters.
Definition strings.cpp:424
strings_func.h
Functions related to OTTD's strings.
StringID
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Definition strings_type.h:19
Coord2D< int >
OskWindow
Definition osk_gui.cpp:38
OskWindow::caption
StringID caption
the caption for this window.
Definition osk_gui.cpp:39
OskWindow::text_btn
WidgetID text_btn
widget number of parent's text field
Definition osk_gui.cpp:41
OskWindow::shift
bool shift
Is the shift effectively pressed?
Definition osk_gui.cpp:44
OskWindow::DrawWidget
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
Definition osk_gui.cpp:99
OskWindow::OnEditboxChanged
void OnEditboxChanged(WidgetID widget) override
The text in an editbox has been edited.
Definition osk_gui.cpp:189
OskWindow::OnFocusLost
void OnFocusLost(bool closing) override
The window has lost focus.
Definition osk_gui.cpp:205
OskWindow::OnInvalidateData
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition osk_gui.cpp:198
OskWindow::qs
QueryString * qs
text-input
Definition osk_gui.cpp:40
OskWindow::OnClick
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:107
OskWindow::orig_str
std::string orig_str
Original string.
Definition osk_gui.cpp:43
OskWindow::GetWidgetString
std::string GetWidgetString(WidgetID widget, StringID stringid) const override
Get the raw string for a widget.
Definition osk_gui.cpp:92
OskWindow::text
Textbuf * text
pointer to parent's textbuffer (to update caret position)
Definition osk_gui.cpp:42
OskWindow::UpdateOskState
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:78
QueryString
Data stored about a string that can be modified in the GUI.
Definition querystring_gui.h:20
QueryString::ok_button
int ok_button
Widget button of parent window to simulate when pressing OK in OSK.
Definition querystring_gui.h:27
QueryString::cancel_button
int cancel_button
Widget button of parent window to simulate when pressing CANCEL in OSK.
Definition querystring_gui.h:28
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition geometry_type.hpp:101
Textbuf
Helper/buffer for input fields.
Definition textbuf_type.h:30
Textbuf::MovePos
bool MovePos(uint16_t keycode)
Handle text navigation with arrow keys left/right.
Definition textbuf.cpp:363
Textbuf::DeleteChar
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
Textbuf::GetText
std::string_view GetText() const
Get the current text.
Definition textbuf.cpp:284
Textbuf::Assign
void Assign(std::string_view text)
Copy a string into the textbuffer.
Definition textbuf.cpp:420
Textbuf::afilter
CharSetFilter afilter
Allowed characters.
Definition textbuf_type.h:31
Textbuf::InsertChar
bool InsertChar(char32_t key)
Insert a character to a textbuffer.
Definition textbuf.cpp:128
WidgetData
Container with the data associated to a single widget.
Definition widget_type.h:358
WindowDesc
High level window description.
Definition window_gui.h:168
Window
Data structure for an opened window.
Definition window_gui.h:274
Window::Close
virtual void Close(int data=0)
Hide the window and all its child windows, and mark them for a later deletion.
Definition window.cpp:1104
Window::querystrings
std::map< WidgetID, QueryString * > querystrings
QueryString associated to WWT_EDITBOX widgets.
Definition window_gui.h:321
Window::InvalidateData
void InvalidateData(int data=0, bool gui_scope=true)
Mark this window's data as invalid (in need of re-computing)
Definition window.cpp:3237
Window::parent
Window * parent
Parent window.
Definition window_gui.h:329
Window::SetWidgetDirty
void SetWidgetDirty(WidgetID widget_index) const
Invalidate a widget, i.e.
Definition window.cpp:558
Window::GetWidgetString
virtual std::string GetWidgetString(WidgetID widget, StringID stringid) const
Get the raw string for a widget.
Definition window.cpp:506
Window::DisableWidget
void DisableWidget(WidgetID widget_index)
Sets a widget to disabled.
Definition window_gui.h:392
Window::SetFocusedWidget
bool SetFocusedWidget(WidgetID widget_index)
Set focus within this window to the given widget.
Definition window.cpp:487
Window::SetWidgetLoweredState
void SetWidgetLoweredState(WidgetID widget_index, bool lowered_stat)
Sets the lowered/raised status of a widget.
Definition window_gui.h:442
Window::OnEditboxChanged
virtual void OnEditboxChanged(WidgetID widget)
The text in an editbox has been edited.
Definition window_gui.h:778
Window::OnClick
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:669
Window::GetWidget
const NWID * GetWidget(WidgetID widnum) const
Get the nested widget with number widnum from the nested widget tree.
Definition window_gui.h:983
Window::InitNested
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
Definition window.cpp:1823
Window::SetWidgetDisabledState
void SetWidgetDisabledState(WidgetID widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
Definition window_gui.h:382
OSK_KEYBOARD_ENTRIES
static const uint OSK_KEYBOARD_ENTRIES
The number of 'characters' on the on-screen keyboard.
Definition textbuf_gui.h:34
video_driver.hpp
Base of all video drivers.
WidgetType
WidgetType
Window widget types, nested widget types, and nested widget part types.
Definition widget_type.h:35
WWT_PUSHTXTBTN
@ WWT_PUSHTXTBTN
Normal push-button (no toggle button) with text caption.
Definition widget_type.h:105
WWT_IMGBTN
@ WWT_IMGBTN
(Toggle) Button with image
Definition widget_type.h:41
WWT_PUSHBTN
@ WWT_PUSHBTN
Normal push-button (no toggle button) with custom drawing.
Definition widget_type.h:104
WWT_PUSHIMGBTN
@ WWT_PUSHIMGBTN
Normal push-button (no toggle button) with image caption.
Definition widget_type.h:106
NWID_SPACER
@ NWID_SPACER
Invisible widget that takes some space.
Definition widget_type.h:70
WWT_EDITBOX
@ WWT_EDITBOX
a textbox for typing
Definition widget_type.h:62
WWT_TEXTBTN
@ WWT_TEXTBTN
(Toggle) Button with text
Definition widget_type.h:44
WWT_PANEL
@ WWT_PANEL
Simple depressed panel.
Definition widget_type.h:39
WWT_CAPTION
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition widget_type.h:52
NWID_VERTICAL
@ NWID_VERTICAL
Vertical container.
Definition widget_type.h:68
CloseWindowById
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:1195
FindWindowById
Window * FindWindowById(WindowClass cls, WindowNumber number)
Find a window by its class and window number.
Definition window.cpp:1153
window_func.h
Window functions not directly related to making/drawing windows.
WDP_CENTER
@ WDP_CENTER
Center the window.
Definition window_gui.h:145
WidgetID
int WidgetID
Widget ID.
Definition window_type.h:20
WC_OSK
@ WC_OSK
On Screen Keyboard; Window numbers:
Definition window_type.h:167
WC_NONE
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition window_type.h:50
zoom_func.h
Functions related to zooming.