OpenTTD Source: src/osk_gui.cpp Source File

OpenTTD Source 14.0-RC3

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